pike.git
/
src
/
modules
/
_Roxen
/
roxen.c
version
»
Context lines:
10
20
40
80
file
none
3
pike.git/src/modules/_Roxen/roxen.c:66:
struct mapping *headers; ptrdiff_t os=0, i, j, l; unsigned char *in; if( Pike_sp[-1].type != PIKE_T_STRING ) Pike_error("Wrong type of argument to feed()\n"); if( str->size_shift ) Pike_error("Wide string headers not supported\n"); while( str->len >= hp->left ) {
+
char *buf;
if( THP->hsize > 512 * 1024 ) Pike_error("Too many headers\n"); THP->hsize += 8192;
-
+
buf = THP->headers;
THP->headers = realloc( THP->headers, THP->hsize ); if( !THP->headers ) {
-
+
free(buf);
THP->hsize = 0; THP->left = 0; Pike_error("Running out of memory in header parser\n"); }
-
THP->left
+= 8192;
+
THP->left += 8192;
THP->pnt = (THP->headers + THP->hsize - THP->left); } MEMCPY( hp->pnt, str->str, str->len ); pop_n_elems( args );
-
+
/* FIXME: The below does not support lines terminated with just \r. */
for( ep=(hp->pnt+str->len),pp=MAXIMUM(hp->headers,hp->pnt-3); pp<ep && slash_n<2; pp++ ) if( *pp == ' ' ) spc++; else if( *pp == '\n' ) slash_n++, tot_slash_n++; else if( *pp != '\r' ) slash_n=0; hp->slash_n = tot_slash_n; hp->spc = spc; hp->left -= str->len;
pike.git/src/modules/_Roxen/roxen.c:121:
return; } push_string( make_shared_binary_string( pp, hp->pnt - pp ) ); /*leftovers*/ headers = allocate_mapping( 5 ); in = hp->headers; l = pp - hp->headers; /* find first line here */ for( i = 0; i < l; i++ )
-
if(
in[i] == '\n' )
+
if(
(
in[i] == '\n'
)
|| (in[i] == '\r'
)
)
break;
-
if
( in[i
-1
]
!
= '\r'
)
+
push_string
(
make_shared_binary_string(
in
, i ) );
+
+
if((in
[i] =
=
'\r'
)
&& (in[i+1] == '\n'
)
)
i++;
-
+
i++;
-
push_string( make_shared_binary_string( in, i-1 ) );
+
in += i; l -= i;
-
if( *in == '\n' ) (in++),(l--);
+
-
+
/* Parse headers. */
for(i = 0; i < l; i++) {
-
if(in[i] > 64 && in[i] < 91) in[i]+=32;
+
if(in[i] > 64 && in[i] < 91) in[i]+=32;
/* lower_case */
else if( in[i] == ':' ) {
-
+
/* FIXME: Does not support white space before the colon. */
/* in[os..i-1] == the header */
-
+
int val_cnt = 0;
push_string(make_shared_binary_string((char*)in+os,i-os));
-
+
+
/* Skip the colon and initial white space. */
os = i+1;
-
while(in[os]==' ') os++;
-
for(j=os;j<l;j++)
+
while(
(
in[os]==' ')
|| (in[os]=='\t'))
os++;
+
+
/* NOTE: We need to support MIME header continuation lines
+
* (Opera uses this...).
+
*/
+
do {
+
for(j=os;j<l;j++)
/* Find end of line */
if( in[j] == '\n' || in[j]=='\r') break; push_string(make_shared_binary_string((char*)in+os,j-os));
-
+
val_cnt++;
-
+
if((in[j] == '\r') && (in[j+1] == '\n')) j++;
+
os = j+1;
+
i = j;
+
/* Check for continuation line. */
+
} while ((os < l) && ((in[os] == ' ') || (in[os] == '\t')));
+
+
if (val_cnt > 1) {
+
/* Join partial header values. */
+
f_add(val_cnt);
+
}
+
if((tmp = low_mapping_lookup(headers, Pike_sp-2))) { f_aggregate( 1 ); if( tmp->type == PIKE_T_ARRAY ) { tmp->u.array->refs++; push_array(tmp->u.array); map_delete(headers, Pike_sp-3); f_add(2); } else { tmp->u.string->refs++; push_string(tmp->u.string); f_aggregate(1); map_delete(headers, Pike_sp-3); f_add(2); } } mapping_insert(headers, Pike_sp-2, Pike_sp-1);
-
+
pop_n_elems(2);
-
if( in[j+1] == '\n' ) j++;
-
os = j+1;
-
i = j;
+
} } push_mapping( headers ); f_aggregate( 3 ); /* data, firstline, headers */ } static void f_hp_create( INT32 args ) /*! @decl void create(void) */ { THP->headers = malloc( 8192 ); THP->pnt = THP->headers; THP->hsize = 8192; THP->left = 8192; THP->spc = THP->slash_n = 0; pop_n_elems(args); push_int(0); }
-
+
/*! @endclass
+
*/
+
static void f_make_http_headers( INT32 args ) /*! @decl string @ *! make_http_headers(mapping(string:string|array(string)) headers) */ { int total_len = 0, e; char *pnt; struct mapping *m; struct keypair *k; struct pike_string *res; if( Pike_sp[-1].type != PIKE_T_MAPPING ) Pike_error("Wrong argument type to make_http_headers(mapping heads)\n"); m = Pike_sp[-1].u.mapping; /* loop to check len */ NEW_MAPPING_LOOP( m->data ) { if( k->ind.type != PIKE_T_STRING || k->ind.u.string->size_shift ) Pike_error("Wrong argument type to make_http_headers(" "mapping(string(8bit):string(8bit)|array(string(8bit))) heads)\n");
-
if( k->val.type == PIKE_T_STRING
&& !k->val.u.string->size_shift )
+
if( k->val.type == PIKE_T_STRING && !k->val.u.string->size_shift )
total_len += k->val.u.string->len + 2 + k->ind.u.string->len + 2; else if( k->val.type == PIKE_T_ARRAY ) { struct array *a = k->val.u.array; ptrdiff_t i, kl = k->ind.u.string->len + 2 ; for( i = 0; i<a->size; i++ ) if( a->item[i].type != PIKE_T_STRING||a->item[i].u.string->size_shift ) Pike_error("Wrong argument type to make_http_headers(" "mapping(string(8bit):string(8bit)|" "array(string(8bit))) heads)\n");
pike.git/src/modules/_Roxen/roxen.c:300:
else *foo=0; bar+=3; } else { *foo=*(bar++); } pop_n_elems(args); push_string(end_shared_string(newstr)); } static void f_html_encode_string( INT32 args )
+
/*! @decl string html_encode_string(mixed in)
+
*!
+
*! Encodes the @[in] data as an HTML safe string.
+
*/
{ struct pike_string *str; int newlen; if( args != 1 ) Pike_error("Wrong number of arguments to html_encode_string\n" ); switch( Pike_sp[-1].type ) { struct pike_string *s;