Changeset 600

Show
Ignore:
Timestamp:
04/23/02 22:06:26
Author:
miyagawa
Message:

0.07: Apache2 compatible

Files:

Legend:

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

    r598 r600  
    1 2002-04-19  Tatsuhiko Miyagawa  <miyagawa@bulknews.net> 
     12002-04-23  IKEBE Tomohiro <ikechin@0xfa.com> 
     2 
     3        * mod_log_sqlite.c: 
     4          now this module works on Apache 2.x 
     5 
     62002-04-19 
    27 
    38        * mod_log_sqlite.c: 
     
    510          LogSQLiteAutoChown takes On|Off only 
    611 
    7 2002-04-15  Tatsuhiko Miyagawa  <miyagawa@bulknews.net
     122002-04-15  IKEBE Tomohiro <ikechin@0xfa.com
    813 
    914        * mod_log_sqlite.c: 
     
    1116          added LogSQLiteAutoChown directive 
    1217          creates table on demand 
    13           (Thanks to IKEBE Tomohiro) 
    1418         
    15192002-04-08  Tatsuhiko Miyagawa  <miyagawa@bulknews.net> 
  • mod_log_sqlite/trunk/README

    r595 r600  
    5858Tatsuhiko Miyagawa <miyagawa@bulknews.net> 
    5959IKEBE Tomohiro     <ikechin@0xfa.com> 
    60  
    61  
    62  
  • mod_log_sqlite/trunk/mod_log_sqlite.c

    r597 r600  
    1616#include "sqlite.h" 
    1717 
    18 #define LOG_SQLITE_VERSION 0.06 
     18#ifdef STANDARD20_MODULE_STUFF /* Apache 2.x compatible */ 
     19#define APACHE2 
     20#include "ap_compat.h" 
     21#include "apr_pools.h" 
     22#include "apr_strings.h" 
     23#include "apr_tables.h" 
     24#include "unixd.h" 
     25 
     26typedef apr_pool_t pool; 
     27typedef apr_array_header_t array_header; 
     28typedef apr_table_t table; 
     29typedef apr_table_entry_t table_entry; 
     30#endif 
     31 
     32#ifdef APACHE2 
     33#define LOG_ERROR_ERR(s, args...) \ 
     34ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, s, args) 
     35#define LOG_ERROR_INFO(s, args...) \ 
     36ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_INFO, 0, s, args) 
     37#define LOG_RERROR_INFO(r, args...) \ 
     38ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_INFO, 0, r, args) 
     39#else 
     40#define LOG_ERROR_ERR(s, args...) \ 
     41ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, s, args) 
     42#define LOG_ERROR_INFO(s, args...) \ 
     43ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_INFO, s, args) 
     44#define LOG_RERROR_INFO(r, args...) \ 
     45ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_INFO, r, args) 
     46#endif 
     47 
     48#define LOG_SQLITE_VERSION 0.07 
    1949#define SQL_TIMEOUT 30000 
    2050 
     
    112142    int ret; 
    113143    char *log_dir; 
     144#ifdef APACHE2 
     145    uid_t s_uid = unixd_config.user_id; 
     146    gid_t s_gid = unixd_config.group_id; 
     147#else 
     148    uid_t s_uid = s->server_uid; 
     149    gid_t s_gid = s->server_gid; 
     150#endif 
    114151    if (!conf->db_file) { 
    115152        return; 
    116153    } 
    117154    db_path  = ap_server_root_relative(p, conf->db_file); 
    118     /* DEBUG */ 
    119     ap_log_error(APLOG_MARK, APLOG_NOERRNO | APLOG_DEBUG, s,  
    120                  "%s: db file %s", s->server_hostname, db_path); 
     155 
    121156    if (conf->auto_chown){ 
    122157        log_dir = ap_make_dirstr_parent(p, db_path); 
    123         ret = chown(log_dir, s->server_uid, s->server_gid); 
     158        ret = chown(log_dir, s_uid, s_gid); 
    124159        if (ret != 0) 
    125             ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, s, "sqlite chown failed: %s", log_dir); 
    126         ret = chown(db_path, s->server_uid, s->server_gid);  
     160            LOG_ERROR_ERR(s,"sqlite chown failed: %s", log_dir); 
     161        ret = chown(db_path, s_uid, s_gid);  
    127162        if (ret != 0) 
    128             ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, s, "sqlite chown failed: %s", db_path); 
     163            LOG_ERROR_ERR(s, "sqlite chown failed: %s", db_path); 
    129164    } 
    130165 
    131166    conf->db = sqlite_open(db_path, 0600, &sqliteErr); 
     167    LOG_ERROR_INFO(s, "sqlite open for %s", s->server_hostname); 
    132168    if ((conf->db == 0) && sqliteErr) { 
    133         ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, s, "sqlite open error: %s", sqliteErr); 
     169        LOG_ERROR_ERR(s, "sqlite open error: %s", sqliteErr); 
    134170        free(sqliteErr); 
    135171    } 
     
    142178            ); 
    143179        if (ret != SQLITE_OK){ 
    144             ap_log_error(APLOG_MARK, APLOG_INFO|APLOG_NOERRNO, s, "sqlite exec error: %s", sqliteErr); 
     180            LOG_ERROR_INFO(s, "sqlite exec error: %s", sqliteErr); 
    145181            free(sqliteErr); 
    146182        } 
     
    150186 
    151187/* open logdb file */ 
     188#ifdef APACHE2 
     189static int init_log_sqlite(pool *pc, pool *p, pool *pt, server_rec *s) 
     190#else 
    152191static void init_log_sqlite(server_rec* s, pool *p) 
     192#endif 
    153193{ 
    154194    log_sqlite_open(s, p); 
     
    156196        log_sqlite_open(s, p); 
    157197    } 
     198#ifdef APACHE2 
     199    return OK; 
     200#else 
    158201    return; 
     202#endif 
    159203} 
    160204 
     
    165209  char *sqliteErr; 
    166210  int  ret; 
     211#ifdef APACHE2 
     212  char *user = ap_pstrdup(r->pool, r->user); 
     213  time_t time_stamp = atoi(ap_ht_time(r->pool, r->request_time, "%s", 0)); 
     214  char *remote_host = ap_pstrdup(r->pool, ap_get_remote_host(r->connection, r->per_dir_config, REMOTE_NAME, NULL)); 
     215#else 
     216  char *user = ap_pstrdup(r->pool, r->connection->user); 
     217  time_t time_stamp = r->request_time; 
     218  char *remote_host = ap_pstrdup(r->pool, ap_get_remote_host(r->connection, r->per_dir_config, REMOTE_NAME)); 
     219#endif 
    167220 
    168221  if (conf->db == 0) { 
     
    172225  /* sets timeout handler */ 
    173226  sqlite_busy_timeout(conf->db, SQL_TIMEOUT); 
    174    
     227 
    175228  /* using '%q' would lead to '(NULL)', thus I use my own quote() function */ 
    176229  ret = sqlite_exec_printf( 
     
    181234    NULL, NULL, &sqliteErr, 
    182235    conf->table, 
    183     quote(r, ap_get_remote_host(r->connection, r->per_dir_config, REMOTE_NAME)), 
    184     quote(r, r->connection->user), 
     236    quote(r, remote_host), 
     237    quote(r, user), 
    185238    quote(r, r->uri), 
    186239    quote(r, r->hostname), 
    187     r->request_time
     240    time_stamp
    188241    r->status, 
    189242    r->bytes_sent, 
     
    196249 
    197250  if (ret != SQLITE_OK) { 
    198     ap_log_rerror(APLOG_MARK, APLOG_INFO|APLOG_NOERRNO, r, "sqlite exec error: %s", sqliteErr); 
    199     free(sqliteErr); 
     251      LOG_RERROR_INFO(r, "sqlite exec error: %s", sqliteErr); 
     252      free(sqliteErr); 
    200253  } 
    201254 
     
    206259{ 
    207260    log_sqlite_config_rec *conf = (log_sqlite_config_rec *) ap_get_module_config(s->module_config, &log_sqlite_module); 
     261    LOG_ERROR_INFO(s, "close db for %s", s->server_hostname); 
    208262    if (conf->db != 0) 
    209263        sqlite_close(conf->db); 
     
    212266 
    213267/* close logdb on child exit */ 
     268#ifdef APACHE2 
     269static apr_status_t cleanup_log_sqlite(void *data) 
     270#else 
    214271static void cleanup_log_sqlite(server_rec *s, pool *p) 
    215 
     272#endif 
     273
     274#ifdef APACHE2 
     275    server_rec *s = (server_rec *)data; 
     276    pool *p = s->process->pool; 
     277#endif 
    216278    log_sqlite_close(s, p); 
    217279    for (s = s->next; s; s = s->next){ 
    218280        log_sqlite_close(s, p); 
    219281    } 
     282#ifdef APACHE2 
     283    return APR_SUCCESS; 
     284#else 
    220285    return; 
     286#endif 
    221287} 
    222288 
    223289/* setup commands */ 
    224290static const command_rec log_sqlite_cmds[] = { 
    225   {"LogSQLiteDBFile", set_sqlite_db_file,  
     291  {"LogSQLiteDBFile", (void *)set_sqlite_db_file,  
    226292   NULL, RSRC_CONF, TAKE1, "sqlite log database file name"}, 
    227   {"LogSQLiteTable", set_sqlite_table,  
     293  {"LogSQLiteTable", (void *)set_sqlite_table,  
    228294   NULL, RSRC_CONF, TAKE1, "sqlite log table name"}, 
    229   {"LogSQLiteAutoChown", set_sqlite_auto_chown,  
     295  {"LogSQLiteAutoChown", (void *)set_sqlite_auto_chown,  
    230296   NULL, RSRC_CONF, FLAG, "sqlite log file auto chown"}, 
    231297  {NULL}, 
    232298}; 
    233299 
     300#ifdef APACHE2 
     301 
     302static void log_sqlite_init_child(pool *p, server_rec *s) 
     303{ 
     304    apr_pool_cleanup_register(p, s, cleanup_log_sqlite, cleanup_log_sqlite); 
     305} 
     306 
     307static void log_sqlite_register_hooks(pool *p) 
     308{ 
     309    ap_hook_open_logs(init_log_sqlite, NULL, NULL, APR_HOOK_MIDDLE); 
     310    ap_hook_log_transaction(log_sqlite_handler, NULL, NULL, APR_HOOK_MIDDLE); 
     311    ap_hook_child_init(log_sqlite_init_child, NULL, NULL, APR_HOOK_MIDDLE); 
     312} 
     313 
     314module AP_MODULE_DECLARE_DATA log_sqlite_module = 
     315{ 
     316    STANDARD20_MODULE_STUFF, 
     317    NULL,     /* dir config creater */ 
     318    NULL,      /* dir merger --- default is to override */ 
     319    create_log_sqlite_config,  /* create per-server config structure */ 
     320    NULL,                       /* merge server config */ 
     321    log_sqlite_cmds,                  /* command apr_table_t */ 
     322    log_sqlite_register_hooks         /* register hooks */ 
     323}; 
     324 
     325#else 
    234326/* Dispatch list for API hooks */ 
    235327module MODULE_VAR_EXPORT log_sqlite_module = { 
     
    254346    NULL                   /* [#0] post read-request              */ 
    255347}; 
    256  
     348#endif