pike.git
/
src
/
modules
/
_Roxen
/
roxen.c
version
»
Context lines:
10
20
40
80
file
none
3
pike.git/src/modules/_Roxen/roxen.c:1:
/* || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information.
-
|| $Id: roxen.c,v 1.
54
2009/07/
17
14
:
33
:
51
grubba
Exp $
+
|| $Id: roxen.c,v 1.
55
2009/07/
29
15
:
48
:
47
nilsson
Exp $
*/ #define NO_PIKE_SHORTHAND #include "global.h" #include "config.h" #include "machine.h"
pike.git/src/modules/_Roxen/roxen.c:46:
*! Class for parsing HTTP-requests. */ #define THP ((struct header_buf *)Pike_fp->current_storage) struct header_buf { unsigned char *headers; unsigned char *pnt; ptrdiff_t hsize, left; int slash_n, tslash_n, spc;
+
int mode;
}; static void f_hp_init( struct object *o ) { THP->headers = NULL; THP->pnt = NULL; THP->hsize = 0; THP->left = 0; THP->spc = THP->slash_n = THP->tslash_n = 0;
-
+
THP->mode = 0;
} static void f_hp_exit( struct object *o ) { if( THP->headers ) free( THP->headers ); THP->headers = NULL; THP->pnt = NULL; THP->hsize = 0; }
pike.git/src/modules/_Roxen/roxen.c:186:
if((in[i] == '\r') && (in[i+1] == '\n')) i++; i++; in += i; l -= i; /* Parse headers. */ for(i = 0; i < l; i++) {
-
if(in[i] > 64 && in[i] < 91) in[i]+=32; /* lower_case */
+
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]==' ') || (in[os]=='\t')) os++;
pike.git/src/modules/_Roxen/roxen.c:240:
ref_push_string(tmp->u.string); stack_swap(); map_delete(headers, Pike_sp-3); f_aggregate(2); } } mapping_insert(headers, Pike_sp-2, Pike_sp-1); pop_n_elems(2); }
+
else if( in[i]=='\r' || in[i]=='\n' )
+
{
+
if( THP->mode == 1 )
+
{
+
/* FIXME: Reset stack so that backtrace shows faulty header. */
+
Pike_error("Malformed HTTP header.\n");
}
-
+
else
+
os = i+1;
+
}
+
}
push_mapping( headers ); f_aggregate( 3 ); /* data, firstline, headers */ } static void f_hp_create( INT32 args )
-
/*! @decl void create(
void
)
+
/*! @decl void create(
int throw_errors
)
*/ { if (THP->headers) { free(THP->headers); THP->headers = NULL; }
-
+
+
get_all_args("create",args,".%i",&THP->mode);
+
THP->headers = xalloc( 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
pike.git/src/modules/_Roxen/roxen.c:589:
tFunc(tStr,tStr), 0 ); ADD_FUNCTION("html_encode_string", f_html_encode_string, tFunc(tMix,tStr), 0 ); start_new_program(); ADD_STORAGE( struct header_buf ); set_init_callback( f_hp_init ); set_exit_callback( f_hp_exit ); ADD_FUNCTION( "feed", f_hp_feed, tFunc(tStr,tArr(tOr(tStr,tMapping))), 0 );
-
ADD_FUNCTION( "create", f_hp_create, tFunc(
tNone
,tVoid), ID_PROTECTED );
+
ADD_FUNCTION( "create", f_hp_create, tFunc(
tOr(tInt
,tVoid),
tVoid),
ID_PROTECTED );
end_class( "HeaderParser", 0 ); } PIKE_MODULE_EXIT { }