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

version» Context lines:

pike.git/src/modules/_Roxen/roxen.c:39:   struct header_buf   {    char headers[8192];    char *pnt;    ptrdiff_t left;   };      static void f_hp_feed( INT32 args )   {    struct pike_string *str = Pike_sp[-1].u.string; -  int slash_n = 0, cnt, num; +  int tot_slash_n=0, slash_n = 0, spc = 0, cnt, num;    char *pp,*ep;    struct svalue *tmp;    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->len >= THP->left )    Pike_error("Too many headers\n");       MEMCPY( THP->pnt, str->str, str->len ); -  +  pop_n_elems( args );    -  for( ep=(THP->pnt+str->len), -  pp=MAXIMUM(THP->headers,THP->pnt-3); -  pp<ep && slash_n<2; -  pp++ ) -  if( *pp == '\n' ) -  slash_n++; -  else if( *pp != '\r' ) -  slash_n=0; +  for( ep=(THP->pnt+str->len),pp=MAXIMUM(THP->headers,THP->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;       THP->left -= str->len;    THP->pnt += str->len;    THP->pnt[0] = 0; -  pop_n_elems( args ); +     if( slash_n != 2 )    { -  /* check for HTTP/0.9? */ +  /* one newline, but less than 2 space, +  * --> HTTP/0.9 or broken request +  */ +  if( (spc < 2) && tot_slash_n ) +  { +  push_text( "" ); +  /* This includes (all eventual) \r\n etc. */ +  push_text( THP->headers ); +  f_aggregate_mapping( 0 ); +  f_aggregate( 3 ); +  return; +  }    push_int( 0 );    return;    }       push_string( make_shared_binary_string( pp, THP->pnt - pp ) ); /*leftovers*/    headers = allocate_mapping( 5 );    in = THP->headers;    l = pp - THP->headers;       /* find first line here */
pike.git/src/modules/_Roxen/roxen.c:102:    {    if(in[i] > 64 && in[i] < 91) in[i]+=32;    else if( in[i] == ':' )    {    /* in[os..i-1] == the header */    push_string(make_shared_binary_string((char*)in+os,i-os));    os = i+1;    while(in[os]==' ') os++;    for(j=os;j<l;j++)    if( in[j] == '\n' || in[j]=='\r') -  { +     break; -  } +     push_string(make_shared_binary_string((char*)in+os,j-os));       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);
pike.git/src/modules/_Roxen/roxen.c:132:    }    }    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, headers */ +  f_aggregate( 3 ); /* data, firstline, headers */   }      static void f_hp_create( INT32 args )   {    THP->pnt = THP->headers;    THP->left = 8192;   }   /**** END CLASS HeaderParser */      static void f_make_http_headers( INT32 args )