pike.git / src / modules / _Roxen / roxen.c

version» Context lines:

pike.git/src/modules/_Roxen/roxen.c:32:         /*! @module _Roxen    */      /*! @class HeaderParser    *!    *! Class for parsing HTTP-requests.    */    + #define FLAG_THROW_ERROR 1 + #define FLAG_KEEP_CASE 2 +    #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;   };   
pike.git/src/modules/_Roxen/roxen.c:83:    *! @elem string 0    *! Trailing data.    *! @elem string 1    *! First line of request.    *! @elem mapping(string:string|array(string)) 2    *! Headers.    *! @endarray    */   {    struct pike_string *str = Pike_sp[-args].u.string; -  int keep_case = 0; +     struct header_buf *hp = THP; -  +  int keep_case = hp->mode & FLAG_KEEP_CASE;    int str_len;    int tot_slash_n=hp->slash_n, slash_n = hp->tslash_n, spc = hp->spc;    unsigned char *pp,*ep;    struct svalue *tmp;    struct mapping *headers;    ptrdiff_t os=0, i, j, l;    unsigned char *in;       if( !( args == 1 || args == 2 ) )    Pike_error("Bad number of arguments to feed().\n");    if( TYPEOF(Pike_sp[-args]) != PIKE_T_STRING )    Pike_error("Wrong type of argument to feed()\n");    if( args == 2 )    { -  +  /* It doesn't make sense to allow each different feed call to +  handle case sensitivity differently. Deprecate this when we +  rewrite the HTTP module. */    if( TYPEOF(Pike_sp[-args+1]) == PIKE_T_INT ) -  keep_case = Pike_sp[-args+1].u.integer & 1; +  keep_case = Pike_sp[-args+1].u.integer;    else    Pike_error("Wrong type of argument to feed()\n");    }    if( str->size_shift )    Pike_error("Wide string headers not supported\n");    str_len = str->len;    while( str_len >= hp->left )    {    unsigned char *buf;    if( hp->hsize > 512 * 1024 )
pike.git/src/modules/_Roxen/roxen.c:255:    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 ) +  if( THP->mode & FLAG_THROW_ERROR )    {    /* 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(int throw_errors) + /*! @decl void create(void|int throw_errors, void|int keep_case)    */   { -  +  INT_TYPE throw_errors = 0; +  INT_TYPE keep_case = 0; +  get_all_args("create",args,".%i%i", &throw_errors, &keep_case); +     if (THP->headers) {    free(THP->headers);    THP->headers = NULL;    }       THP->mode = 0; -  get_all_args("create",args,".%i",&THP->mode); +  if(throw_errors) THP->mode |= FLAG_THROW_ERROR; +  if(keep_case) THP->mode |= FLAG_KEEP_CASE;       THP->headers = xalloc( 8192 );    THP->pnt = THP->headers;    THP->hsize = 8192;    THP->left = 8192;    THP->spc = THP->slash_n = 0;   }      /*! @endclass    */
pike.git/src/modules/_Roxen/roxen.c:652:       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 tOr(tInt01,tVoid),tArr(tOr(tStr,tMapping))), 0); -  ADD_FUNCTION( "create", f_hp_create, tFunc(tOr(tInt,tVoid),tVoid), ID_PROTECTED ); +  ADD_FUNCTION( "create", f_hp_create, tFunc(tOr(tInt,tVoid) tOr(tInt,tVoid),tVoid), ID_PROTECTED );    end_class( "HeaderParser", 0 );   }      PIKE_MODULE_EXIT   {   }