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) */ {