Roxen.git / server / modules / tags / accessed.pike

version» Context lines:

Roxen.git/server/modules/tags/accessed.pike:1:   // This is a roxen module. Copyright © 1996 - 2009, Roxen IS.   //      #include <module.h>      inherit "module";    - constant cvs_version = "$Id: accessed.pike,v 1.61 2010/02/18 17:30:16 mast Exp $"; + constant cvs_version = "$Id$";   constant thread_safe = 1;   constant module_type = MODULE_TAG | MODULE_LOGGER;   constant module_name = "Tags: Accessed counter";   constant module_doc = "This module provides access counters, through the "   "<tt>&lt;accessed&gt;</tt> tag and the <tt>&amp;page.accessed;</tt> entity.";    -  + int fail_count = 0, fail_count_report_next = 0; + int fail_last_report = 0; +    string status()   {    string backend = query("backend");    string res = "<b>Backend:</b> " + backend + "<br />\n";       if (backend == "SQL database")    res += "<b>Database:</b> " + query("db") + "<br />\n";    -  +  if (fail_count > 0) +  res += "<b>Count failures to due database connection failure:</b> " + +  fail_count + "<br />\n"; +     int entries;    if ( mixed err = catch {    entries = counter->size();    })    {    return res + "<font color='red'>Unable to connect to database</font>";    }       return res +    "<b>Entries:</b> " + entries + " entries in the accessed "
Roxen.git/server/modules/tags/accessed.pike:262:       int cnum=0;    mapping fton=([]);       int size() {    return sizeof(fton);    }       Stdio.File database, names_file;    +  // NB: The parse_accessed_database() efun is deprecated. + #pragma no_deprecation_warnings    void create() {    if(olf != module::query("Accesslog"))    {    olf = module::query("Accesslog");    mkdirhier(module::query("Accesslog"));    if(names_file=open(olf+".names", "wrca"))    {    cnum=0;    array tmp=parse_accessed_database(names_file->read(0x7ffffff));    fton=tmp[0];    cnum=tmp[1];    names_file = 0;    }    }    } -  + #pragma deprecation_warnings       protected string olf; // Used to avoid reparsing of the accessed index file...    protected mixed names_file_callout_id;    inline void open_names_file()    {    if(objectp(names_file)) return;    remove_call_out(names_file_callout_id);    names_file=open(module::query("Accesslog")+".names", "wrca");    names_file_callout_id = call_out(destruct, 1, names_file);    }
Roxen.git/server/modules/tags/accessed.pike:464:    private string fix_file(string file)    {    if(sizeof(file)>255)    file="//"+MIME.encode_base64(Crypto.MD5()->update(file)->digest(),1);    return file;    }       void add(string file, int count)    {    create_entry(file); +  if (catch +  {    sql_query("UPDATE &hits; SET hits=hits+"+(count||1)+" WHERE path=%s",    fix_file( file ) ); -  +  }) +  { +  fail_count += count || 1; +  if (fail_count > fail_count_report_next) +  { +  fail_count_report_next = 100 + (5 * fail_count) / 4; +  werror("ACCESS LOGGING FAILED, FAIL COUNT: %d\n", fail_count);    } -  +  } +  }       int query(string file)    { -  array x=sql_query("SELECT hits FROM &hits; WHERE path=%s", +  array x; +  if (catch +  { +  x = sql_query("SELECT hits FROM &hits; WHERE path=%s",    fix_file( file ) ); -  +  }) +  { +  if (fail_last_report+30 < time()) +  { +  fail_last_report = time(); +  werror("ACCESS LOG QUERY FAILED.\n"); +  } +  return 0; +  }    return x && sizeof(x) && (int)(x[0]->hits);    }       void reset(string file)    {    create_entry(file);    sql_query("UPDATE &hits; SET hits=0 WHERE path=%s", fix_file(file) );    }       int size()