Roxen.git / server / base_server / configuration.pike

version» Context lines:

Roxen.git/server/base_server/configuration.pike:1:   // This file is part of Roxen WebServer.   // Copyright © 1996 - 2004, Roxen IS.   //      // @appears Configuration   //! A site's main configuration    - constant cvs_version = "$Id: configuration.pike,v 1.620 2006/10/05 12:49:53 anders Exp $"; + constant cvs_version = "$Id: configuration.pike,v 1.621 2006/10/13 17:12:32 mast Exp $";   #include <module.h>   #include <module_constants.h>   #include <roxen.h>   #include <request_trace.h>   #include <timers.h>      #define CATCH(P,X) do{mixed e;if(e=catch{X;})report_error("While "+P+"\n"+describe_backtrace(e));}while(0)      // --- Locale defines ---   //<locale-token project="roxen_start"> LOC_S </locale-token>
Roxen.git/server/base_server/configuration.pike:212:   // It's nice to have the name when the rest of __INIT executes.   string name = roxen->bootstrap_info->get();      // Trivial cache (actually, it's more or less identical to the 200+   // lines of C in HTTPLoop. But it does not have to bother with the   // fact that more than one thread can be active in it at once. Also,   // it does not have to delay free until all current connections using   // the cache entry are done...)   class DataCache   { -  mapping(string:array(string|mapping(string:mixed))) cache = ([]); +  mapping(string: +  array(string|mapping(string:mixed))|string| +  function(string, RequestID:string)) cache = ([]);       int current_size;    int max_size;    int max_file_size;       int hits, misses;       void flush()    {   #ifndef RAM_CACHE_NO_RELOAD_FLUSH    current_size = 0;    cache = ([]);   #endif    }       static void low_expire_entry(string key_prefix, array(string) keys)    {    if (!key_prefix) return; -  int found; -  do { -  found = 0; +     foreach(keys; int ind; string key) {    if (!key) continue;    if (has_prefix(key, key_prefix)) { -  found = 1; +     if (arrayp(cache[key])) {    current_size -= sizeof(cache[key][0]);    }    m_delete(cache, key);    keys[ind] = 0;    }    } -  key_prefix = "\0" + key_prefix; -  } while (found); +     }       void expire_entry(string key_prefix, RequestID|void id)    {    if (!id) {    low_expire_entry(key_prefix, indices(cache));    return;    }    string url = key_prefix; -  if ((url != "") && !url[0]) { -  sscanf(url, "%*[\0]%[^\0]", url); -  } +  sscanf(url, "%[^\0]", url);    while(1) {    array(string|mapping(string:mixed))|string|    function(string, RequestID:string) val;    if (arrayp(val = cache[key_prefix])) {    current_size -= sizeof(val[0]);    m_delete(cache, key_prefix);    return;    }    if (!val) {    return;    }       string|array(string) key_frag;    if (stringp(val)) {    key_frag = id->request_headers[val];    } else {    key_frag = val(url, id);    } -  if (arrayp(key_frag)) key_frag *= ", "; -  // NOTE: The prepended NUL is for spoof protection. -  key_prefix = "\0" + key_prefix + "\0" + (key_frag || ""); +  if (key_frag) +  // Avoid spoofing if key_frag happens to contain "\0\0". +  key_frag = replace (key_frag, "\0", "\0\1"); +  else key_frag = ""; +  key_prefix += "\0\0" + key_frag;    }    }       static void clear_some_cache()    { -  +  // FIXME: Use random(cache) instead to avoid the indices() call.    array(string) q = indices(cache);    if(!sizeof(q))    {    current_size=0;    return;    }    for(int i = 0; i < sizeof(q)/10; i++)    low_expire_entry(q[random(sizeof(q))], q);    }   
Roxen.git/server/base_server/configuration.pike:317:    expire_entry(key);    }    cache[key] = vary_cb;       string|array(string) key_frag;    if (stringp(vary_cb)) {    key_frag = id->request_headers[vary_cb];    } else {    key_frag = vary_cb(url, id);    } -  if (arrayp(key_frag)) key_frag *= ", "; -  // NOTE: The prepended NUL is for spoof protection. -  key = "\0" + key + "\0" + (key_frag || ""); +  if (key_frag) +  // Avoid spoofing if key_frag happens to contain "\0\0". +  key_frag = replace (key_frag, "\0", "\0\1"); +  else key_frag = ""; +  key += "\0\0" + key_frag;    }       array(string|mapping(string:mixed))|string|    function(string, RequestID:string) old = cache[key];    if (old) {    // FIXME: Warn?    expire_entry(key);    }       current_size += strlen( data );    cache[key] = ({ data, meta });       // Only the actual cache entry is expired. -  +  // FIXME: This could lead to lots and lots of call outs.. :P    call_out(low_expire_entry, expire, key, ({ key }));    int n;    while( (current_size > max_size) && (n++<10))    clear_some_cache();    }       array(string|mapping(string:mixed)) get(string url, RequestID id)    {    array(string|mapping(string:mixed))|string|    function(string, RequestID:string) res;
Roxen.git/server/base_server/configuration.pike:361:    misses++;    return UNDEFINED;    }       string|array(string) key_frag;    if (stringp(res)) {    key_frag = id->request_headers[res];    } else {    key_frag = res(url, id);    } -  if (arrayp(key_frag)) key_frag *= ", "; -  // NOTE: The prepended NUL is for spoof protection. -  key = "\0" + key + "\0" + (key_frag || ""); +  if (key_frag) +  // Avoid spoofing if key_frag happens to contain "\0\0". +  key_frag = replace (key_frag, "\0", "\0\1"); +  else key_frag = ""; +  key += "\0\0" + key_frag;    };    }       void init_from_variables( )    {    max_size = query( "data_cache_size" ) * 1024;    max_file_size = query( "data_cache_file_max_size" ) * 1024;    if( max_size < max_file_size )    max_size += max_file_size;    int n;