Roxen.git / server / base_server / roxen.pike

version» Context lines:

Roxen.git/server/base_server/roxen.pike:1:   // This file is part of Roxen WebServer.   // Copyright © 1996 - 2004, Roxen IS.   //   // The Roxen WebServer main program.   //   // Per Hedbor, Henrik Grubbström, Pontus Hagland, David Hedbor and others.   // ABS and suicide systems contributed freely by Francesco Chemolli    - constant cvs_version="$Id: roxen.pike,v 1.924 2006/05/22 08:25:50 grubba Exp $"; + constant cvs_version="$Id: roxen.pike,v 1.925 2006/05/22 15:34:16 grubba Exp $";      //! @appears roxen   //!   //! The Roxen WebServer main program.      // The argument cache. Used by the image cache.   ArgCache argcache;      // Some headerfiles   #define IN_ROXEN
Roxen.git/server/base_server/roxen.pike:5466:    void log( function do_write, RequestID id, mapping file );    static void do_async_write( string host, string data, string ip, function c )    {    if( c )    c( replace( data, "\4711", (host||ip) ) );    }   }      static mapping(string:function) compiled_formats = ([ ]);    + #define LOG_FLAG_ASYNC 1 + #define LOG_FLAG_NEED_COOKIES 2 +    constant formats =   ({    ({ "ip_number", "%s", "(string)request_id->remoteaddr",0 }),    ({ "bin-ip_number","%s", "host_ip_to_int(request_id->remoteaddr)",0 }),    ({ "cern_date", "%s", "Roxen.cern_http_date( time( 1 ) )",0 }),    ({ "bin-date", "%4c", "time(1)",0 }),    ({ "method", "%s", "(string)request_id->method",0 }),    ({ "resource", "%s", "(string)(request_id->raw_url||request_id->not_query)", 0 }),    ({ "full_resource","%s", "(string)(request_id->raw_url||request_id->not_query)",0 }),    ({ "protocol", "%s", "(string)request_id->prot",0 }),
Roxen.git/server/base_server/roxen.pike:5493:    ({ "user_agent_raw", "%s",    "request_id->client?request_id->client*\" \":\"-\"", 0 }),    ({ "user_agent", "%s",    "request_id->client?request_id->client*\"%20\":\"-\"", 0 }),    ({ "user_id", "%s",    "(request_id->cookies&&request_id->cookies->RoxenUserID)||"    "(request_id->misc->moreheads&&"    " request_id->misc->moreheads[\"Set-Cookie\"]&&"    " request_id->parse_cookies&&"    " request_id->parse_cookies(request_id->misc->moreheads[\"Set-Cookie\"])" -  " ->RoxenUserID)||\"0\"",0 }), +  " ->RoxenUserID)||\"0\"", LOG_FLAG_NEED_COOKIES }),    ({ "user", "%s", "extract_user( request_id->realauth )",0 }),    ({ "request-time","%1.2f", "time(request_id->time )",0 }), -  ({ "host", "\4711", 0, 1 }), // unlikely to occur normally +  ({ "host", "\4711", // unlikely to occur normally +  0, LOG_FLAG_ASYNC }),    ({ "cache-status","%s", ("sizeof(request_id->cache_status||({}))?"    "indices(request_id->cache_status)*\",\":"    "\"nocache\""), 0 }),    ({ "protcache-cost", "%d", "request_id->misc->protcache_cost", 0 }),   });      void run_log_format( string fmt, function c, RequestID id, mapping file )   {    (compiled_formats[ fmt ] || compile_log_format( fmt ))(c,id,file);   }
Roxen.git/server/base_server/roxen.pike:5534:    decode_value( tmp[0]->enc, master()->MyCodec() )()->log;    };   // #ifdef DEBUG    report_error("Decoding of dumped log format failed:\n%s",    describe_backtrace(err));   // #endif    }    array parts = fmt/"$";    string format = parts[0];    array args = ({}); -  int do_it_async = 0; +  int log_flags = 0;    int add_nl = 1;       string sr( string s ) { return s[1..strlen(s)-2]; };    // sr(replace(sprintf("%O", X), "%", "%%"))      #define DO_ES(X) replace(X, ({"\\n", "\\r", "\\t", }), ({ "\n", "\r", "\t" }) )       foreach( parts[1..], string part )    {    int c, processed;    foreach( formats, array q )    if( part[..strlen(q[0])-1] == q[0])    {    format += q[1] + DO_ES(part[ strlen(q[0]) .. ]);    if( q[2] ) args += ({ q[2] }); -  if( q[3] ) do_it_async = 1; +  log_flags |= q[3];    processed=1;    break;    }    if( processed )    continue;    if( sscanf( part, "char(%d)%s", c, part ) )    format += sprintf( "%"+(c<0?"-":"")+"c", abs( c ) )+DO_ES(part);    else if( sscanf( part, "wchar(%d)%s", c, part ) )    format += sprintf( "%"+(c<0?"-":"")+"2c", abs( c ) )+DO_ES(part);    else if( sscanf( part, "int(%d)%s", c, part ) )    format += sprintf( "%"+(c<0?"-":"")+"4c", abs( c ) )+DO_ES(part);    else if( part[0] == '^' )    {    format += DO_ES(part[1..]);    add_nl = 0;    } else    format += "$"+part;    }    if( add_nl ) format += "\n";    -  string code = sprintf( - #" +  string code = #"    inherit ___LogFormat;    void log( function callback, RequestID request_id, mapping file )    { -  if(!callback) return; -  string data = sprintf( %O %{, %s%} ); - ", format, args ); +  if(!callback) return;";    -  if( do_it_async ) +  if (log_flags & LOG_FLAG_NEED_COOKIES) { +  code += #" +  id->init_cookies();"; +  } +  +  code += sprintf(#" +  string data = sprintf( %O %{, %s%} );", format, args ); +  +  if (log_flags & LOG_FLAG_ASYNC)    { -  code += - #" +  code += #"    roxen.ip_to_host(request_id->remoteaddr,do_async_write, -  data, request_id->remoteaddr, callback ); +  data, request_id->remoteaddr, callback );"; +  } else { +  code += #" +  callback( data );";    } - "; -  } else -  code += - #" -  callback( data ); +  code += #"    }   ";       program res = compile_string(code);    string enc = encode_value(res, master()->MyCodec(res));    object con = dbm_cached_get("local");       con->query("REPLACE INTO compiled_formats (md5,full,enc) VALUES (%s,%s,%s)",    kmd5, fmt, enc);    con = 0;