Roxen.git / server / plugins / protocols / http.pike

version» Context lines:

Roxen.git/server/plugins/protocols/http.pike:1:   // This is a ChiliMoon protocol module.   // Modified by Francesco Chemolli to add throttling capabilities.   // Copyright © 1996 - 2001, Roxen IS.    - constant cvs_version = "$Id: http.pike,v 1.406 2004/06/03 02:52:07 _cvs_stephen Exp $"; + constant cvs_version = "$Id: http.pike,v 1.407 2004/06/04 08:29:30 _cvs_stephen Exp $";   //#define REQUEST_DEBUG   //#define CONNECTION_DEBUG   #define MAGIC_ERROR   #define HTTPTIMEOUT 90      // HTTP protocol module.   #include <config.h>   #define TIMER_PREFIX "http:"   #include <timers.h>   #include <stat.h>
Roxen.git/server/plugins/protocols/http.pike:239:    conf->connection_add( this, pipe );   }         void send(string|object what, int|void len, int|void start)   {    if(!what) return;    if(!pipe) setup_pipe();    if( len>0 && port_obj && port_obj->minimum_byterate )    call_out( end, len / port_obj->minimum_byterate ); -  pipe->add_source(what,start,len||strlen(what)); +  pipe->add_source(what,start,len||sizeof(what));   }      void start_sender( )   {   #ifdef FD_DEBUG    call_out(timer, 30, predef::time(1)); // Update FD with time...   #endif    if( throttler || conf->throttler )    pipe->set_throttler( throttler || conf->throttler );    pipe->set_done_callback( do_log );
Roxen.git/server/plugins/protocols/http.pike:270:    {    string v, a, b;       foreach(query / "&", v)    if(sscanf(v, "%s=%s", a, b) == 2)    {    a = http_decode_string(replace(a, "+", " "));    b = http_decode_string(replace(b, "+", " "));    real_variables[ a ] += ({ b });    } else -  if(strlen( rest_query )) +  if(sizeof( rest_query ))    rest_query += "&" + http_decode_string( v );    else    rest_query = http_decode_string( v );    rest_query=replace(rest_query, "+", "\000"); /* IDIOTIC STUPID STANDARD */    }    return f;   }      #define OLD_RXML_CONFIG   
Roxen.git/server/plugins/protocols/http.pike:359:    foreach(((contents/";") - ({""})), string c)    {    string name, value;    while(sizeof(c) && c[0]==' ') c=c[1..];    if(sscanf(c, "%s=%s", name, value) == 2)    {    value=http_decode_string(value);    name=http_decode_string(name);    cookies[ name ]=value;   #ifdef OLD_RXML_CONFIG -  if( (name == "RoxenConfig") && strlen(value) ) +  if( (name == "RoxenConfig") && sizeof(value) )    config = mkmultiset( value/"," );   #endif    }    }    return cookies;   }      int things_to_do_when_not_sending_from_cache( )   {   #ifdef OLD_RXML_CONFIG
Roxen.git/server/plugins/protocols/http.pike:411:    string f = raw_url;          f = scan_for_query( f );    f = http_decode_string( f );       // f is sent to Unix API's that take NUL-terminated strings...    if( has_value(f, "\0") )    sscanf(f, "%s\0", f);    -  if( strlen( f ) > 5 ) +  if( sizeof( f ) > 5 )    {    string a;    switch( f[1] )    {   #ifdef OLD_RXML_CONFIG    case '<':    if (sscanf(f, "/<%s>/%s", a, f)==2)    {    config_in_url = 1;    mod_config = (a/",");    f = "/"+f;    }   #endif    // intentional fall-through    case '(': -  if(strlen(f) && sscanf(f, "/(%s)/%s", a, f)==2) +  if(sizeof(f) && sscanf(f, "/(%s)/%s", a, f)==2)    {    prestate = (multiset)( a/","-({""}) );    f = "/"+f;    }    }    }       not_query = Roxen.simplify_path(f);   #ifndef DISABLE_SUPPORTS    if( !supports )
Roxen.git/server/plugins/protocols/http.pike:490: Inside #if defined(OLD_RXML_CONFIG)
   if(config_in_url) {    //REQUEST_WERR("HTTP: parse_got(): config_in_url");    really_set_config( mod_config );    return 1;    }   #endif    if(!supports->cookies)    config = prestate;    else    if( port_obj->set_cookie -  && !cookies->ChiliMoonUserID && strlen(not_query) +  && !cookies->ChiliMoonUserID && sizeof(not_query)    && not_query[0]=='/' && method!="PUT")    {    if (!(port_obj->set_cookie_only_once &&    cache_lookup("hosts_for_cookie",remoteaddr)))    misc->moreheads = ([ "Set-Cookie":Roxen.http_roxen_id_cookie(), ]);    if (port_obj->set_cookie_only_once)    cache_set("hosts_for_cookie",remoteaddr,1);    }       if( mixed q = real_variables->magic_roxen_automatic_charset_variable )
Roxen.git/server/plugins/protocols/http.pike:594:    misc->no_proto_cache = 1;    break;       case 0:    /* Not reached */    break;    }    TIMER_END(parse_got_2_parse_line);    REQUEST_WERR(sprintf("HTTP: request line %O", line));    REQUEST_WERR(sprintf("HTTP: headers %O", request_headers)); -  REQUEST_WERR(sprintf("HTTP: data (length %d) %O", strlen(data),data)); +  REQUEST_WERR(sprintf("HTTP: data (length %d) %O", sizeof(data),data));    raw_url = f;    time = predef::time(1);    // if(!data) data = "";    //REQUEST_WERR(sprintf("HTTP: raw_url %O", raw_url));       if(!remoteaddr)    {    if(my_fd) {    remoteaddr = my_fd->query_address();    if(remoteaddr)
Roxen.git/server/plugins/protocols/http.pike:701:    break;    }    }    TIMER_END(parse_got_2_parse_headers);    TIMER_START(parse_got_2_more_data);    if(misc->len)    {    if(!data) data="";    int l = misc->len;    wanted_data=l; -  have_data=strlen(data); +  have_data=sizeof(data);    -  if(strlen(data) < l) +  if(sizeof(data) < l)    {    REQUEST_WERR(sprintf("HTTP: More data needed in %s.", method));    ready_to_receive();    TIMER_END(parse_got_2);    return 0;    }    leftovers = data[l+2..];    data = data[..l+1];       switch(method) {
Roxen.git/server/plugins/protocols/http.pike:727:    default:    // Normal form data.    string v;       // Ok.. This might seem somewhat odd, but IE seems to add a    // (spurious) \r\n to the end of the data, and some versions of    // opera seem to add (spurious) \r\n to the start of the data.    //    // Oh, the joy of supporting all webbrowsers is endless.    data = String.trim_all_whites( data ); -  l = misc->len = strlen(data); +  l = misc->len = sizeof(data);       if(l < 200000)    foreach(replace(data,"+"," ")/"&", v)    if(sscanf(v, "%s=%s", a, b) == 2)    {    a = http_decode_string( a );    b = http_decode_string( b );    real_variables[ a ] += ({ b });    }    break;
Roxen.git/server/plugins/protocols/http.pike:1175: Inside #if defined(FD_DEBUG)
     #ifdef FD_DEBUG   void timer(int start)   {    if(pipe) {    // FIXME: Disconnect if no data has been sent for a long while    // (30min?)    MARK_FD(sprintf("HTTP piping %d %d %d %d (%s)",    pipe->sent,    stringp(pipe->current_input) ? -  strlen(pipe->current_input) : -1, +  sizeof(pipe->current_input) : -1,    pipe->last_called,    predef::time(1) - start,    not_query));    } else {    MARK_FD("HTTP piping, but no pipe for "+not_query);    }    call_out(timer, 30, start);   }   #endif   
Roxen.git/server/plugins/protocols/http.pike:1266:    heads["Content-Type"] = "multipart/byteranges; boundary=" BOUND;    ranges = _ranges;    int clen;    foreach(ranges, array range)    {    int rlen = 1+ range[1] - range[0];    string sep = sprintf("\r\n--" BOUND "\r\nContent-Type: %s\r\n"    "Content-Range: bytes %d-%d/%d\r\n\r\n",    type||"application/octet-stream",    @range, len); -  clen += rlen + strlen(sep); +  clen += rlen + sizeof(sep);    range_info += ({ ({ rlen, sep }) });    } -  clen += strlen(BOUND) + 8; // End boundary length. +  clen += sizeof(BOUND) + 8; // End boundary length.    _file->len = clen;    }       string read(int num_bytes)    {    string out = stored_data;    int rlen, total = num_bytes; -  num_bytes -= strlen(out); +  num_bytes -= sizeof(out);    stored_data = "";    foreach(ranges, array range)    {    rlen = range_info[0][0] - current_pos;    if(separator != 1) {    // New range, write new separator.    // write("Initiating new range %d -> %d.\n", @range);    out += range_info[0][1]; -  num_bytes -= strlen(range_info[0][1]); +  num_bytes -= sizeof(range_info[0][1]);    file->seek(range[0]);    separator = 1;    }    if(num_bytes > 0) {    if(rlen <= num_bytes)    // Entire range fits.    {    out += file->read(rlen);    num_bytes -= rlen;    current_pos = separator = 0;
Roxen.git/server/plugins/protocols/http.pike:1314:    }    if(num_bytes <= 0)    break; // Return data    }    if(!sizeof(ranges) && separator != 2) {    // End boundary. Only write once and only when    // no more ranges remain.    separator = 2;    out += "\r\n--" BOUND "--\r\n";    } -  if(strlen(out) > total) +  if(sizeof(out) > total)    {    // Oops. too much data again. Write and store. Write and store.    stored_data = out[total..];    return out[..total-1];    }    return out ; // We are finally done.    }       mixed `->(string what)    {
Roxen.git/server/plugins/protocols/http.pike:1636:    } )    error("Illegal value in headers array! "    "Expected string or array(string)\n");    }    head_string += "\r\n";    }       if (sscanf (heads["Content-Type"], "; charset=%s", string charset) ||    String.width( head_string ) > 8 )    head_string = output_encode( head_string, 0, charset )[1]; -  conf->hsent += strlen(head_string); +  conf->hsent += sizeof(head_string);    }    else    if(!file->type) file->type="text/plain";   #if 0    REQUEST_WERR(sprintf("HTTP: Sending result for prot:%O, method:%O, file:%O",    prot, method, file));   #endif    MARK_FD("HTTP handled");       if( (method!="HEAD") && (file->error!=204) )    // No data for these two...    {   #ifdef RAM_CACHE    if( (misc->cacheable > 0) && (file->data || file->file) &&    (prot != "HTTP/0.9") && !misc->no_proto_cache)    {    if( file->len>0 && // known length. -  ((file->len + strlen( head_string )) < +  ((file->len + sizeof( head_string )) <    conf->datacache->max_file_size)    && misc->cachekey )    {    string data = "";    if( file->file ) data += file->file->read();    if( file->data ) data += file->data;    MY_TRACE_ENTER (sprintf ("Storing in ram cache, entry: %O", raw_url), 0);    MY_TRACE_LEAVE ("");    conf->datacache->set( raw_url, data,    ([
Roxen.git/server/plugins/protocols/http.pike:1678: Inside #if defined(RAM_CACHE)
   "etag":misc->etag,    "callbacks":misc->_cachecallbacks,    "len":file->len,    // fix non-keep-alive when sending from cache    "raw":file->raw,    "error":file->error,    "mtime":(file->stat && file->stat[ST_MTIME]),    "rf":realfile,    ]),    misc->cacheable ); -  file = ([ "data":data, "raw":file->raw, "len":strlen(data) ]); +  file = ([ "data":data, "raw":file->raw, "len":sizeof(data) ]);    }    }   #endif    if(!kept_alive &&    (file->len > 0) &&    ((sizeof(head_string) + file->len) < (HTTP_BLOCKING_SIZE_THRESHOLD)))    {    // The first time we get a request, the output buffers will    // be empty. We can thus just do a single blocking write()    // if the data will fit in the output buffer (usually 4KB).
Roxen.git/server/plugins/protocols/http.pike:1711: Inside #if defined(CONNECTION_DEBUG)
   ({"\\r\\n", "\\n", "\\t"}),    ({"\n", "\n", "\t"})));   #else    REQUEST_WERR (sprintf ("HTTP: Send blocking %O", data));   #endif    s = my_fd->write(data);    TIMER_END(blocking_write);    end(1);    return;    } -  if(strlen(head_string)) send(head_string); -  if(file->data && strlen(file->data)) send(file->data, file->len); +  if(sizeof(head_string)) send(head_string); +  if(file->data && sizeof(file->data)) send(file->data, file->len);    if(file->file) send(file->file, file->len);    }    else    { -  if( strlen( head_string ) < (HTTP_BLOCKING_SIZE_THRESHOLD)) +  if( sizeof( head_string ) < (HTTP_BLOCKING_SIZE_THRESHOLD))    {   #ifdef CONNECTION_DEBUG    werror ("HTTP: Response =================================================\n"    "%s\n",    replace (sprintf ("%O", head_string),    ({"\\r\\n", "\\n", "\\t"}),    ({"\n", "\n", "\t"})));   #else    REQUEST_WERR (sprintf ("HTTP: Send headers blocking %O", head_string));   #endif
Roxen.git/server/plugins/protocols/http.pike:1869: Inside #if defined(CONNECTION_DEBUG)
   replace (sprintf ("%O", s),    ({"\\r\\n", "\\n", "\\t"}),    ({"\n", "\n", "\t"})));   #else    REQUEST_WERR(sprintf("HTTP: Got %O", s));   #endif       if(wanted_data)    {    // NOTE: No need to make a data buffer if it's a small request. -  if(strlen(s) + have_data < wanted_data) +  if(sizeof(s) + have_data < wanted_data)    {    if(!data_buffer) {    // The 16384 is some reasonable extra padding to    // avoid having to realloc.    data_buffer = String.Buffer(wanted_data + 16384);    data_buffer->add(data);    data = "";    }    data_buffer->add(s); -  have_data += strlen(s); +  have_data += sizeof(s);       // Reset timeout.    remove_call_out(do_timeout);    call_out(do_timeout, HTTPTIMEOUT);    REQUEST_WERR("HTTP: We want more data.");    return;    }    if(data_buffer) {    data_buffer->add(s);    data = (string)data_buffer;
Roxen.git/server/plugins/protocols/http.pike:1984:    "":(":"+port_obj->port)) +    raw_url, this);    } else {    conf =    port_obj->find_configuration_for_url(port_obj->name +    "://*:" + port_obj->port +    raw_url, this);    }    }    } -  else if( strlen(path) ) +  else if( sizeof(path) )    adjust_for_config_path( path );       TIMER_END(find_conf);       if (rawauth)    {    /* Need to authenticate with the configuration */    misc->no_proto_cache = 1;    array(string) y = rawauth / " ";    realauth = 0;
Roxen.git/server/plugins/protocols/http.pike:2019:    {    // misc->proxyauth[1] = MIME.decode_base64(misc->proxyauth[1]);    if (conf->auth_module)    misc->proxyauth    = conf->auth_module->auth(misc->proxyauth, this);    }    }    if( conf )    {    conf->connection_add( this, ([]) ); -  conf->received += strlen(raw); +  conf->received += sizeof(raw);    conf->requests++;    }    CHECK_FD_SAFE_USE;    my_fd->set_close_callback(0);    my_fd->set_read_callback(0);    if (my_fd->set_accept_callback) my_fd->set_accept_callback(0);    processed=1;       remove_call_out(do_timeout);   #ifdef RAM_CACHE
Roxen.git/server/plugins/protocols/http.pike:2099: Inside #if defined(RAM_CACHE)
   {    string fix_date( string headers )    {    string a, b;    if( sscanf( headers, "%sDate: %*s\n%s", a, b ) == 3 )    return a+"Date: "+Roxen.http_date( predef::time(1) ) +"\r\n"+b;    return headers;    };       MY_TRACE_LEAVE ("Using entry from ram cache"); -  conf->hsent += strlen(file->hs); +  conf->hsent += sizeof(file->hs);    cache_status["protcache"] = 1; -  if( strlen( d ) < (HTTP_BLOCKING_SIZE_THRESHOLD) ) +  if( sizeof( d ) < (HTTP_BLOCKING_SIZE_THRESHOLD) )    {    TIMER_END(cache_lookup);    }    else    {    TIMER_END(cache_lookup);    send( fix_date(file->hs)+d );    start_sender( );    }    return;
Roxen.git/server/plugins/protocols/http.pike:2235:   void chain( object f, object c, string le )   {    my_fd = f;    f->set_nonblocking(0, f->query_write_callback(), end);    port_obj = c;    processed = 0;    do_not_disconnect=-1; // Block destruction until we return.    MARK_FD("HTTP kept alive");    time = predef::time();    -  if ( le && strlen( le ) ) +  if ( le && sizeof( le ) )    got_data( 0,le );    else    {    // If no pipelined data is available, call out...    remove_call_out(do_timeout);    call_out(do_timeout, HTTPTIMEOUT);    }       if(!my_fd)    {