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 - 2001, 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.837 2003/11/10 14:35:11 anders Exp $"; + constant cvs_version="$Id: roxen.pike,v 1.838 2004/02/09 16:50:57 wellhard 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:2874:    }       static void store_data( string id, string data, mapping meta )    {    if(!stringp(data)) return;   #ifdef ARG_CACHE_DEBUG    werror("store %O (%d bytes)\n", id, strlen(data) );   #endif    meta_cache_insert( id, meta );    string meta_data = encode_value( meta ); -  if( catch { -  QUERY( "UPDATE "+name+" SET size=%d, atime=%d, meta=%s, " -  "data=%s WHERE id=%s", -  strlen(data)+strlen(meta_data), time(1), meta_data, data, id ); +    #ifdef ARG_CACHE_DEBUG -  werror("updated entry for %O, existed before\n", id ); +  werror("Replacing entry for %O\n", id );   #endif -  } ) -  { - #ifdef ARG_CACHE_DEBUG -  werror("new entry for %O\n", id ); - #endif -  QUERY("INSERT INTO "+name+ -  " (id,size,atime,meta,data) VALUES (%s,%d,%d,%s,%s)", -  id, strlen(data)+strlen(meta_data), time(1), meta_data, data ); +  QUERY("REPLACE INTO "+name+ +  " (id,size,atime,meta,data) VALUES (%s,%d,UNIX_TIMESTAMP(),%s,%s)", +  id, strlen(data)+strlen(meta_data), meta_data, data );    } -  } +        static mapping restore_meta( string id, RequestID rid )    {    if( meta_cache[ id ] )    {    meta_cache[ id ][ 1 ] = time(1); // Update cached atime.    return meta_cache[ id ][ 0 ];    }      #ifdef ARG_CACHE_DEBUG
Roxen.git/server/base_server/roxen.pike:3116:   #endif    if(! (res=restore( na,id )) )    {    mixed err;    if (nodraw || (err = catch {    if (mapping res = draw( na, id ))    return res;    })) {    // File not found.    if(arrayp(err) && sizeof(err) && stringp(err[0]) && -  err[0][0..21] == "Requesting unknown key") -  report_debug("Requesting unknown key %O from %O\n", +  sscanf(err[0], "Requesting unknown key %s\n", string message) == 1) +  { +  report_debug("Requesting unknown key %s %O from %O\n", +  message,    id->not_query,    (sizeof(id->referer)?id->referer[0]:"unknown page")); -  +  }    else    report_debug("Error in draw: %s\n", describe_backtrace(err));    return 0;    }    if( !(res = restore( na,id )) )    error("Draw callback did not generate any data\n");    }    res->stat = ({ 0, 0, 0, 900000000, 0, 0, 0, 0, 0 });       // Setting the cacheable flag is done in order to get headers sent which
Roxen.git/server/base_server/roxen.pike:3209:    error("Expected mapping as the first element of the argument array\n");    update_args( data[0] );    ci = map( map( data, tomapp ), argcache->store )*"$";    } else    ci = data;    update_args = 0; // To avoid garbage.       if( zero_type( uid_cache[ ci ] ) )    {    uid_cache[ci] = user; -  if( catch(QUERY( "UPDATE "+name+" SET uid=%s WHERE id=%s", -  user||"", ci )) ) -  QUERY("INSERT INTO "+name+" (id,uid,atime) VALUES (%s,%s,%d)", -  ci, user||"", time(1) ); +  if( catch(QUERY("INSERT INTO "+name+" " +  "(id,uid,atime) VALUES (%s,%s,UNIX_TIMESTAMP())", +  ci, user||"")) ) +  QUERY( "UPDATE "+name+" SET uid=%s WHERE id=%s", +  user||"", ci );    }      #ifndef NO_ARG_CACHE_SB_REPLICATE    if(id->misc->persistent_cache_crawler) {    // Force an update of atime for the requested arg cache id.    foreach(ci/"$", string key) {   #if REPLICATE_DEBUG    werror("Request for id %O from prefetch crawler.\n", key);   #endif /* REPLICATE_DEBUG */    argcache->refresh_arg(key);
Roxen.git/server/base_server/roxen.pike:3569:    return id;    }       mapping lookup( string id )    //! Recall a mapping stored in the cache.    {    if( cache[id] )    return cache[id]+([]);    array i = decode_id( id );    if( !i ) -  error("Requesting unknown key\n"); +  error("Requesting unknown key (decode failed)\n");    array a = low_lookup( i[0] );    array b = low_lookup( i[1] );    if (!arrayp (a) || !arrayp (b) || sizeof (a) != sizeof (b)) -  +  {    // Got lookup with ids from an old cache which has been zapped,    // and the entries are now used for something else. -  error("Requesting unknown key\n"); + #ifdef ARG_CACHE_DEBUG +  werror("lookup(%O) a: %O, b: %O\n", id, a, b); + #endif +  error("Requesting unknown key (size missmatch)\n"); +  }    return (cache[id] = mkmapping( a, b ))+([]);    }       array low_lookup( int id )    {    mixed v;    if( v = cache[id] )    return v;    string q = read_args( id );    if( !q ) -  error("Requesting unknown key\n"); +  error("Requesting unknown key (not found in db)\n");    mixed data = decode_value(q);    string hl = Crypto.md5()->update( q )->digest();    cache[ hl ] = id;    cache[ id ] = data;    return data;    }       void delete( string id )    //! Remove the data element stored under the key 'id'.    {
Roxen.git/server/base_server/roxen.pike:3692:    }    if(s != "EOF")    return "Missing data in argcache file\n";    return 0;    }       void refresh_arg(string id)    {    array i = decode_id( id );    if( !i ) -  error("Requesting unknown key\n"); +  error("Requesting unknown key (decode failed)\n");    LOCK();    QUERY("UPDATE "+name+" SET atime='"+time(1)+"' WHERE id="+i[0]);    QUERY("UPDATE "+name+" SET atime='"+time(1)+"' WHERE id="+i[1]);    }   }      mapping cached_decoders = ([]);   string decode_charset( string charset, string data )   {    // FIXME: This code is probably not thread-safe!