Changeset 595

Show
Ignore:
Timestamp:
04/15/02 21:25:27
Author:
miyagawa
Message:

0.05

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • mod_log_sqlite/trunk/ChangeLog

    r580 r595  
     12002-04-15  Tatsuhiko Miyagawa  <miyagawa@bulknews.net> 
     2 
     3        - 0.05 release 
     4        * VirtualHost support 
     5        * LogSQLiteAutoChown directive 
     6        * creates table on demand 
     7          (Thanks to IKEBE Tomohiro) 
     8         
     92002-04-08  Tatsuhiko Miyagawa  <miyagawa@bulknews.net> 
     10 
     11        - 0.04 release 
     12        * Added NULL entry to command_rec 
     13 
    1142002-04-07  Tatsuhiko Miyagawa  <miyagawa@bulknews.net> 
    215 
  • mod_log_sqlite/trunk/MANIFEST

    r577 r595  
    11ChangeLog 
    22README 
    3 Makefile 
    43create_table.sql 
    54mod_log_sqlite.c 
  • mod_log_sqlite/trunk/Makefile

    r580 r595  
    77APXS=apxs 
    88APACHECTL=apachectl 
    9 VER=0.03 
    109 
    1110#   additional user defines, includes and libraries 
     
    4544        $(APACHECTL) stop 
    4645 
     46#   update MANIFEST 
     47manifest: 
     48        @perl -MExtUtils::Manifest=mkmanifest -e "mkmanifest" 
    4749 
    4850#   make the distribution 
  • mod_log_sqlite/trunk/README

    r574 r595  
    99  % make clean 
    1010 
    11 CONFIGURATION (sample): 
     11CONFIGURATION (summary): 
     12 
     131. install sqlite from http://www.hwaci.com/sw/sqlite/ 
     142. Add following lines to your httpd.conf 
     15 
     16    LogSQLiteDBFile sqlite-logs/sqlite_log 
     17    LogSQLiteAutoChown On  
     18 
     19CONFIGURATION (details): 
    1220 
    1321First you should install sqlite module manually. See 
    1422http://www.hwaci.com/sw/sqlite/ for details. 
    1523 
    16 Then you should initialize access_log database. Note that the database 
    17 file and the directory can be writable by httpd running user (nobody 
    18 by default). 
     24Then you should initialize access_log database (from 0.05, this is 
     25optional). Note that the database file and the directory should be 
     26writable by httpd running user ("nobody" by default). 
    1927 
    2028  # mkdir /usr/local/apache/sqlite-logs 
     
    2230  % sudo -u nobody sqlite /usr/local/apache/sqlite-logs/sqlite_log < create_table.sql 
    2331 
    24 "create_table.sql" is bundled with this module. 
     32"create_table.sql" is bundled with this module. Note that this module 
     33automatically creates log table if there's not one, from 0.05. You can 
     34let this moule do chown() automatically, by adding directive: 
     35 
     36  LogSQLiteAutoChown On 
    2537 
    2638Finally, simply add the following line to your httpd.conf: 
     
    3345  LogSQLiteTable wwwlog 
    3446 
     47From 0.05, this module supports separate database files per 
     48VirtualHosts, which means you can even do: 
     49 
     50  <VirtualHost x.x.x.x> 
     51  ServerName vh.example.com 
     52  LogSQLiteDBFile /home/vh.example.com/logs/sqlite_log 
     53  </VirtualHost> 
    3554 
    3655That's all! Enjoy querying your access_log via VIEWs and/or sub-querys. 
     
    3857-- 
    3958Tatsuhiko Miyagawa <miyagawa@bulknews.net> 
     59IKEBE Tomohiro     <ikechin@0xfa.com> 
    4060 
    4161 
    4262 
    43  
  • mod_log_sqlite/trunk/mod_log_sqlite.c

    r580 r595  
    44** 
    55**  Tatsuhiko Miyagawa <miyagawa@bulklnews.net> 
     6**  IKEBE Tomohiro <ikechin@0xfa.com> 
    67** 
    78*/  
     
    1516#include "sqlite.h" 
    1617 
    17 #define LOG_SQLITE_VERSION 0.03 
     18#define LOG_SQLITE_VERSION 0.05 
    1819#define SQL_TIMEOUT 30000 
    1920 
     21#define WATCHPOINT printf("WATCHPOINT %s %d\n", __FILE__, __LINE__) 
     22 
     23#define LOG_SQLITE_CREATE "CREATE TABLE %s (" \ 
     24"    remote_host       varchar(50)," \ 
     25"    remote_user       varchar(50)," \ 
     26"    request_uri       varchar(50)," \ 
     27"    virtual_host      varchar(50)," \ 
     28"    time_stamp        integer unsigned not null," \ 
     29"    status            smallint(6)," \ 
     30"    bytes_sent        integer," \ 
     31"    referer           varchar(255)," \ 
     32"    agent             varchar(255)," \ 
     33"    request_method    varchar(6)," \ 
     34"    request_protocol  varchar(10)" \ 
     35")" 
     36 
    2037typedef struct { 
    21   char   *db_file; 
    22   char   *table; 
     38  char *db_file; 
     39  char *table; 
     40  int auto_chown; 
    2341  sqlite *db; 
    2442} log_sqlite_config_rec; 
     
    5977  conf->table   = "access_log"; 
    6078  conf->db      = 0; 
    61  
     79  conf->auto_chown = 0; 
    6280  return (void *)conf; 
    6381} 
     
    8098} 
    8199 
     100static const char *set_sqlite_auto_chown(cmd_parms *cmd, void *mconfig, char *param) 
     101{ 
     102  log_sqlite_config_rec *conf = (log_sqlite_config_rec *) ap_get_module_config(cmd->server->module_config, &log_sqlite_module); 
     103  if (strncasecmp(param, "On", 2) == 0) 
     104      conf->auto_chown = 1; 
     105  else 
     106      conf->auto_chown = 0; 
     107  return NULL; 
     108} 
     109 
     110static void log_sqlite_open(server_rec *s, pool *p) 
     111{ 
     112    log_sqlite_config_rec *conf = (log_sqlite_config_rec *) ap_get_module_config(s->module_config, &log_sqlite_module); 
     113    char *db_path; 
     114    char *sqliteErr; 
     115    int ret; 
     116    char *log_dir; 
     117    if (!conf->db_file) { 
     118        return; 
     119    } 
     120    db_path  = ap_server_root_relative(p, conf->db_file); 
     121    /* DEBUG */ 
     122    ap_log_error(APLOG_MARK, APLOG_NOERRNO | APLOG_DEBUG, s,  
     123                 "%s: db file %s", s->server_hostname, db_path); 
     124    if (conf->auto_chown){ 
     125        log_dir = ap_make_dirstr_parent(p, db_path); 
     126        ret = chown(log_dir, s->server_uid, s->server_gid); 
     127        if (ret != 0) 
     128            ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, s, "sqlite chown failed: %s", log_dir); 
     129        ret = chown(db_path, s->server_uid, s->server_gid);  
     130        if (ret != 0) 
     131            ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, s, "sqlite chown failed: %s", db_path); 
     132    } 
     133 
     134    conf->db = sqlite_open(db_path, 0600, &sqliteErr); 
     135    if ((conf->db == 0) && sqliteErr) { 
     136        ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, s, "sqlite open error: %s", sqliteErr); 
     137        free(sqliteErr); 
     138    } 
     139    else { 
     140        ret = sqlite_exec_printf( 
     141            conf->db, 
     142            LOG_SQLITE_CREATE, 
     143            NULL, NULL, &sqliteErr, 
     144            conf->table 
     145            ); 
     146        if (ret != SQLITE_OK){ 
     147            ap_log_error(APLOG_MARK, APLOG_INFO|APLOG_NOERRNO, s, "sqlite exec error: %s", sqliteErr); 
     148            free(sqliteErr); 
     149        } 
     150    } 
     151    return; 
     152} 
     153 
    82154/* open logdb file */ 
    83155static void init_log_sqlite(server_rec* s, pool *p) 
    84156{ 
    85   log_sqlite_config_rec *conf = (log_sqlite_config_rec *) ap_get_module_config(s->module_config, &log_sqlite_module); 
    86  
    87   char *db_path; 
    88   char *sqliteErr; 
    89  
    90   if (!conf->db_file) { 
     157    log_sqlite_open(s, p); 
     158    for (s = s->next; s; s = s->next){ 
     159        log_sqlite_open(s, p); 
     160    } 
    91161    return; 
    92   } 
    93    
    94   db_path  = ap_server_root_relative(p, conf->db_file); 
    95   conf->db = sqlite_open(db_path, 0600, &sqliteErr); 
    96  
    97   if ((conf->db == 0) && sqliteErr) { 
    98     ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, s, "sqlite open error: %s", sqliteErr); 
    99     free(sqliteErr); 
    100   } 
    101    
    102   return; 
    103162} 
    104163 
     
    109168  char *sqliteErr; 
    110169  int  ret; 
    111    
     170 
    112171  if (conf->db == 0) { 
    113172    return DECLINED; 
     
    140199 
    141200  if (ret != SQLITE_OK) { 
    142     ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, r, "sqlite exec error: %s", sqliteErr); 
     201    ap_log_rerror(APLOG_MARK, APLOG_INFO|APLOG_NOERRNO, r, "sqlite exec error: %s", sqliteErr); 
    143202    free(sqliteErr); 
    144203  } 
     
    157216/* setup commands */ 
    158217static const command_rec log_sqlite_cmds[] = { 
    159   {"LogSQLiteDBFile", set_sqlite_db_file, NULL, RSRC_CONF, TAKE1, "sqlite log database file name"}, 
    160   {"LogSQLiteTable", set_sqlite_table, NULL, RSRC_CONF, TAKE1, "sqlite log table name"}, 
     218  {"LogSQLiteDBFile", set_sqlite_db_file,  
     219   NULL, RSRC_CONF, TAKE1, "sqlite log database file name"}, 
     220  {"LogSQLiteTable", set_sqlite_table,  
     221   NULL, RSRC_CONF, TAKE1, "sqlite log table name"}, 
     222  {"LogSQLiteAutoChown", set_sqlite_auto_chown,  
     223   NULL, RSRC_CONF, TAKE1, "sqlite log file auto chown"}, 
     224  {NULL}, 
    161225}; 
    162226