Main Page | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

countm_mod.h

Go to the documentation of this file.
00001 #ifndef COUNTM_MOD_H
00002 #define COUNTM_MOD_H
00003 
00013 /* ********** DEFINITIONS ******************/
00019 #define COUNTM_BDB_MAX_ENV 32
00020 
00027 #define COUNTM_BDB_MAX_DB 32
00028 
00036 #define MODULE_URI_PATH_STRING "/countm"
00037 /* #define MODULE_URI_PATH_STRING "/mycounter" */
00038 
00044 #define MODULE_URI_PATH_FONTS_STRING MODULE_URI_PATH_STRING "/fonts"
00045 
00052 #define MODULE_HANDLER_ID_STRING "mod-countm"
00053 
00060 /*#define USE_PNG_IF_ACCEPTABLE*/
00061 
00071 #define INSERT_BUFFER_SIZE 1024
00072 
00078 #define DEFAULT_IMAGE_TYPE img_jpeg
00079 
00084 #define MAX_QSTRING 1024
00085 
00086 #define STRING_EYES_X(x) #x
00087 #define STRING_EYES(x) STRING_EYES_X(x)
00088 
00092 #define DISPLAY_STR_DB "Edb"
00093 #define DISPLAY_STR_NOLINK "ENoLnk"
00094 #define DISPLAY_STR_LINK "ELink"
00095 #define DISPLAY_STR_CDELETE "CDel"
00096 #define DISPLAY_STR_ADELETE "ADel"
00097 #define DISPLAY_STR_CADD "Cadd"
00098 #define DISPLAY_STR_STRING "Estr"
00099 #define DISPLAY_STR_OVERFLOW "Eovr"
00100 #define DISPLAY_STR_PARAM "EParm"
00101 #define DISPLAY_STR_FILE "EFile"
00102 
00103 #define ERROR_API 2
00104 #define ERROR_LIBGD 3
00105 #define ERROR_IMAGE_SIZE 5
00106 
00113 #define RETURN_IMAGE_PADDING 10
00114 
00120 #define COUNTM_FORCE_HOSTNAMELOOKUPS 0
00121 /* #define COUNTM_FORCE_HOSTNAMELOOKUPS 1 */
00122 
00130 #ifndef COUNTM_FORCE_LIBGD_THREADSAFE
00131 #define COUNTM_FORCE_LIBGD_THREADSAFE 1
00132 #endif
00133 
00138 #define MAX_POST_QUERY_STRING 1024
00139 
00147 #define COUNTM_FOLLOW_LINKS APR_FINFO_LINK
00148 
00153 #define COUNTM_PARAMETER_RESET "reset"
00154 
00159 #define COUNTM_PARAMETER_INIT "init"
00160 
00165 #define COUNTM_MYSQL_CONFIG_PARAMS 8
00166 
00171 #define COUNTM_STATS_BDB_JOIN 0
00172 
00177 #define COUNTM_STATS_BDB_CLOSE 1
00178 
00183 #define COUNTM_STATS_BDB_RECOVER 2
00184 
00189 #define COUNTM_STATS_BDB_DELETE 3
00190 
00195 #define COUNTM_STATS_BDB_CREATE 4
00196 
00197 /* ****** STRUCTURES ************** */
00198 
00199 /* *********************** */
00200 #if defined(COUNTM_BDB)
00201 /* BDB STRUCTURES */
00202 /* *********************** */
00203 
00208 typedef struct countm_env_lockfile_data {
00209   apr_file_t * fp; 
00210   int cnt; 
00211 } countm_env_lockfile_data_t, * p_countm_env_lockfile_data_t;
00212 
00217 typedef struct countm_bdb {
00218   countm_bdb_env_t env[COUNTM_BDB_MAX_ENV]; 
00219   countm_bdb_db_t db[COUNTM_BDB_MAX_DB]; 
00220 } countm_bdb_t, * p_countm_bdb_t;
00221 
00222 /* *********************** */
00223 #elif defined(COUNTM_MYSQL)
00224 /* MYSQL STRUCTURES */
00225 /* *********************** */
00226 #endif
00227 
00228 /* *********************** */
00229 /* COMMON STRUCTURES */
00230 /* *********************** */
00231 
00236 typedef struct countm_cleanup_data {
00237   apr_pool_t * p; 
00238   int bSS; 
00239   server_rec * s; 
00240 } countm_cleanup_data_t, * p_countm_cleanup_data_t;
00241 
00250 typedef struct countm_dir_config {
00251   char * dir; 
00252   enum countm_state bAllowFontsQuery; 
00253   enum countm_state bAllowReset; 
00254   enum countm_state bDBPriority; 
00255 } countm_dir_config_t, * p_countm_dir_config_t;
00256 
00257 #define INITIALIZE_COUNTM_DIR_CONFIG \
00258 {\
00259   .dir =  NULL,\
00260   .bAllowFontsQuery = countm_state_notdef,\
00261   .bAllowReset = countm_state_notdef,\
00262   .bDBPriority = countm_state_notdef\
00263 }
00264 
00271 typedef struct countm_config {
00272   /* values specified in config file */
00273   char * sza_fontdir; 
00274   char * sza_font; 
00275   char * sza_bgfile_dir; 
00276   enum countm_state bActivate; 
00277   /* values specified in config file, and later ignored. */
00278   char * sza_lockfile; 
00280 #if defined(COUNTM_BDB)
00281   char * sza_home; 
00282   char * sza_file; 
00283   /* BDB data used by this server.*/
00284   int db_index; 
00285   int env_index; 
00286   countm_bdb_state_e db_state;
00287   countm_bdb_state_e env_state;
00288 #elif defined(COUNTM_MYSQL)
00289   char * sza_host; 
00290   char * sza_user; 
00291   char * sza_passwd; 
00292   char * sza_db; 
00293   unsigned int port; 
00294   char * sza_unix_socket; 
00295   char * sza_opt_group; 
00296   char * sza_opt_file; 
00297 #endif /* COUNTM_MYSQL */
00298 } countm_config_t, * p_countm_config_t; /* struct countm_config */
00299 
00307 typedef struct countent {
00308   const char * ce_link; 
00309   dbcounter_data_t ce_cmd_data; 
00310   int ce_ignore; 
00311   int ce_insert; 
00312   char ce_insert_buffer[INSERT_BUFFER_SIZE]; 
00313   enum resettype ce_reset; 
00314   const char * ce_hostname; 
00315   const char * ce_ipaddr; 
00316   int ce_hostname_is_ipaddr; 
00318   char * ce_string; 
00319   int ce_string_is_number; 
00320   int ce_link_in_dbcounter; 
00321   int ce_link_in_dbaccess; 
00322   int ce_dbcounter_insert; 
00323   dbcounter_data_t ce_dbcounter_data; 
00324   p_countm_dir_config_t ce_cdc; 
00325   p_countm_config_t ce_cc; 
00326   request_rec * ce_r; 
00327   const char * ce_qs; 
00328 #if defined(COUNTM_BDB)
00329   /* link db4 locking info */
00330   DB_LOCK link_lock; 
00331   u_int32_t lockid; 
00332   int ce_bLlock; 
00333   DB_TXN * tid; 
00334 #elif defined(COUNTM_MYSQL)
00335   /*
00336    *This may be a per thread variable because no need to manage connections
00337    * on a per server or per process basis.
00338    */
00339   MYSQL * mysql; /* The MySQL connection. */
00340 #endif
00341 } countent_t, * p_countent_t;
00342 
00343 #if defined(COUNTM_BDB)
00344 /* The initial values prior to parsing command line */
00345 #define INITIALIZE_COUNTENT {\
00346     .ce_link = NULL,\
00347     .ce_cmd_data=INITIALIZE_DBCOUNTER_DATA,\
00348     .ce_ignore=0,\
00349     .ce_insert=0,\
00350     .ce_insert_buffer="\0\0",\
00351     .ce_reset = reset_notdef,\
00352     .ce_hostname=NULL,\
00353     .ce_ipaddr=NULL,\
00354     .ce_hostname_is_ipaddr=0,\
00355     .ce_string=NULL,\
00356     .ce_string_is_number=0,\
00357     .ce_link_in_dbcounter=0,\
00358     .ce_link_in_dbaccess=0,\
00359     .ce_dbcounter_insert=1,\
00360     .ce_dbcounter_data=INITIALIZE_DBCOUNTER_DATA,\
00361     .ce_cdc=NULL,\
00362     .ce_cc=NULL,\
00363     .ce_r=NULL,\
00364     .ce_qs=NULL,\
00365     .ce_bLlock=0\
00366 }
00367 #elif defined(COUNTM_MYSQL)
00368 #define INITIALIZE_COUNTENT {\
00369     .ce_link = NULL,\
00370     .ce_cmd_data=INITIALIZE_DBCOUNTER_DATA,\
00371     .ce_ignore=0,\
00372     .ce_insert=0,\
00373     .ce_insert_buffer="\0\0",\
00374     .ce_reset = reset_notdef,\
00375     .ce_hostname=NULL,\
00376     .ce_ipaddr=NULL,\
00377     .ce_hostname_is_ipaddr=0,\
00378     .ce_string=NULL,\
00379     .ce_string_is_number=0,\
00380     .ce_link_in_dbcounter=0,\
00381     .ce_link_in_dbaccess=0,\
00382     .ce_dbcounter_insert=1,\
00383     .ce_dbcounter_data=INITIALIZE_DBCOUNTER_DATA,\
00384     .ce_cdc=NULL,\
00385     .ce_cc=NULL,\
00386     .ce_r=NULL,\
00387     .ce_qs=NULL,\
00388     .mysql=NULL\
00389 }
00390 #endif
00391 
00396 typedef struct countm_listdirs_data {
00397   regex_t * preg; 
00398   int bFontDir; 
00399 } countm_listdirs_data_t, * p_countm_listdirs_data_t;
00400 
00401 #if defined (MOD_CACHEM)
00402 
00406 typedef struct countm_cachem_data {
00407   unsigned long ulTotal; 
00408   unsigned long ulCurrent; 
00409   char last[APR_CTIME_LEN+1]; 
00410 } countm_cachem_data_t, * p_countm_cachem_data_t;
00411 #endif /* MOD_CACHEM */
00412 
00413 #if defined (COUNTM_BDB)
00414 
00415 #if defined (MOD_CACHEM)
00416 
00421 typedef struct countm_cachem_bdb_data {
00422   unsigned int flags; 
00423   unsigned int pid; 
00424 } countm_cachem_bdb_data_t, * p_countm_cachem_bdb_data_t;
00425 #endif /* MOD_CACHEM */
00426 #endif /* COUNTM_BDB */
00427 
00428 /* *********** GLOBALS ************** */
00440 /* ********************* */
00441 #if defined(COUNTM_BDB)
00442 /*  BDB GLOBALS */
00443 /* ********************* */
00455 static countm_bdb_t bdb;
00456 
00462 static const db_lockmode_t bdb_lockmode=DB_LOCK_READ;
00463 
00464 /* ********************* */
00465 #elif defined(COUNTM_MYSQL)
00466 /*  MYSQL GLOBALS */
00467 /* ********************* */
00468 
00472 const char countm_mysql_config[COUNTM_MYSQL_CONFIG_PARAMS][32]={
00473   "-host=","-user=","-passwd=","-db=", "-port=", "-unix_socket=",
00474   "-opt_group=", "-opt_file="};
00475 
00476 #endif
00477 
00478 /* ********************* */
00479 /*  COMMON GLOBALS */
00480 /* ********************* */
00481 /* A global mutex. */
00482 /* Must bring into child process with child_init */
00483 static apr_global_mutex_t * global_lock;
00484 
00485 /*
00486  * The library serialization lock, if threads are used.
00487  * For the parent process, it is created and assigned to this global in
00488  *  post_config. Then cleaned up in post_config_cleanup.
00489  * If forking, then one is created for each process in child_init 
00490  *  and assigned to this global value, then
00491  *  cleaned up in child_init_cleanup.
00492  */
00493 #if APR_HAS_THREADS
00494 static apr_thread_mutex_t * lib_lock=NULL;
00495 #endif /* APR_HAS_THREADS */
00496 
00497 #if defined (MOD_CACHEM)
00498 
00501 static cachem_id_t countm_cachem_id=CACHEM_INVALID_ID;
00502 static m_index_t countm_cachem_index=CACHEM_INVALID_INDEX;
00503 #if defined (COUNTM_BDB)
00504 static cachem_id_t countm_cachem_id_bdb=CACHEM_INVALID_ID;
00505 #endif /* COUNTM_BDB */
00506 #endif /* MOD_CACHEM */
00507 
00508 /* ******** COMMON PROTOTYPES *************** */
00509 static void * countm_per_server_config(apr_pool_t *p, server_rec *s);
00510 static void * countm_merge_per_server_config(apr_pool_t *p, void * base, void * virt);
00511 static void * countm_per_dir_config(apr_pool_t * p, char * dir);
00512 static void * countm_merge_per_dir_config(apr_pool_t *p, void * basev,
00513                                           void * newv);
00514 static int countm_hook_post_config(apr_pool_t *pconf, apr_pool_t * plog, apr_pool_t *ptemp, server_rec *s);
00515 static apr_status_t countm_pool_post_config_cleanup(void * data);
00516 static void countm_process_init();
00517 static void countm_hook_child_init(apr_pool_t *p, server_rec *s);
00518 static apr_status_t countm_pool_child_init_cleanup(void * parm);
00519 static void countm_process_cleanup(apr_pool_t * p, int bSS);
00520 static void countm_register_hooks(apr_pool_t *p);
00521 static int countm_method_handler(request_rec *r);
00522 static const char * countm_set_fontdir(cmd_parms *parms, void *dummy,
00523                                         const char *arg);
00524 static const char * countm_set_font(cmd_parms *parms, void *dummy,
00525                                     const char *arg);
00526 static const char * countm_set_db_lockfile(cmd_parms *parms, void *dummy,
00527                                            const char *arg);
00528 static const char * countm_set_bgfile_dir(cmd_parms *parms, void *dummy,
00529                                            const char *arg);
00530 static const char * countm_set_activate(cmd_parms *parms, void *dummy,
00531                                         int bool);
00532 static const char * countm_set_allow_fonts_query(cmd_parms *parms,
00533                                                  void *dummy, const int arg);
00534 static const char * countm_set_allow_reset(cmd_parms *parms,
00535                                            void *dummy, const int arg);
00536 static const char * countm_set_db_priority(cmd_parms *parms,
00537                                            void *dummy, const int arg);
00538 static int countm_strcmp(const char * s1, const char * s2);
00539 static apr_status_t countm_listfonts(p_countent_t p_ce);
00540 static apr_status_t countm_listdirs(request_rec * r, char * dir, char * rel_dir, p_countm_listdirs_data_t p_ldd);
00541 char * countm_next_fontdir(apr_pool_t * p, const char * fontdirs, unsigned int * pos);
00542 static int countm_get_querystring(p_countent_t p_ce);
00543 static int countm_parse_cmdline(p_countent_t p_ce);
00544 static int countm_verify_bgfile(p_countent_t p_ce, char * fn, enum imagetype * img);
00545 static apr_status_t countm_unescape_url(apr_pool_t * p, char * s, apr_status_t * sNorm, apr_status_t * sKeep2f);
00546 static int countm_mergeinfo_cmdpriority(p_countent_t p_ce);
00547 static int countm_mergeinfo_dbpriority(p_countent_t p_ce);
00548 static apr_status_t countm_process_command(p_countent_t p_ce, int * bDisplay);
00549 static apr_status_t countm_reset_value(p_countent_t p_ce, int * bDisplay);
00550 static int countm_reset_delete(p_countent_t p_ce, int * bDisplay);
00551 static int countm_reset_access(p_countent_t p_ce, int * bDisplay);
00552 static int countm_reset_init(p_countent_t p_ce, int * bDisplay);
00553 static int countm_update_counter(p_countent_t p_ce, int * bDisplay);
00554 static apr_status_t countm_dbcounter_get(p_countent_t p_ce, int * bDisplay);
00555 static apr_status_t countm_dbcounter_put(p_countent_t p_ce, int * bDisplay);
00556 static apr_status_t countm_dbcounter_del(p_countent_t p_ce, int * bDisplay);
00557 static apr_status_t countm_dbaccess_put(p_countent_t p_ce, const char * p_value, int * bPresent);
00558 static int countm_dbaccess_del(p_countent_t p_ce, int * bDisplay);
00559 static int countm_setdefaults(p_countent_t p_ce);
00560 static void countm_rgb_color(const char *hexnum, p_rgb_t rgb);
00561 static int countm_display_string(p_countent_t p_ce);
00562 static int countm_match_extension(request_rec * r, const char * fname, const char * pattern);
00563 static int countm_misc_dza_strcat( char * const buf, char const * const szstr,
00564                                    const int bsize);
00565 static void countm_adjust_string_width(p_countent_t p_ce);
00566 static apr_status_t countm_listdirs(request_rec * r, char * dir, char * rel_dir, p_countm_listdirs_data_t p_ldd);
00567 static apr_status_t countm_filter_flush(apr_bucket_brigade * bb, void * ctx);
00568 static void countm_adjust_string_width(p_countent_t p_ce);
00569 static int countm_version_check(apr_pool_t * p);
00570 static int countm_set_atime(p_dbcounter_data_t p_dbcr, request_rec * r);
00571 static int countm_absolute_path(const char * path);
00572 static int countm_check_filename(const char * file);
00573 
00574 /* *********************************** */
00575 #if defined(COUNTM_BDB)
00576 /* BDB PROTOTYPES */
00577 /* *********************************** */
00578 static int countm_bdb_linklock_get(p_countent_t p_ce, int * bDisplay);
00579 static int countm_bdb_linklock_free(p_countent_t p_ce);
00580 static int countm_bdb_packet_make(request_rec * r, p_dbcounter_data_t p_dbcr, void ** pkt, int * pkt_len);
00581 static int countm_bdb_packet_split(request_rec * r, p_dbcounter_data_t p_dbcr, void * pkt, int pkt_len);
00582 static int countm_bdb_env_open(const char * env_name, int env_index, apr_pool_t * p, apr_pool_t * pconf);
00583 static int countm_bdb_env_close(int env_index, apr_pool_t * p);
00584 static countm_bdb_state_e countm_bdb_process_env(const char * env_name, int * index, apr_pool_t * p, apr_pool_t * pconf);
00585 static int countm_bdb_env_recover(const char * env_name, apr_pool_t * p);
00586 static int countm_bdb_open_db(const char * db_name, int env_index, int db_index, apr_pool_t * p, apr_pool_t * pconf);
00587 static countm_bdb_state_e countm_bdb_process_db(const char * db_name, int env_index, int * db_index, apr_pool_t * p, apr_pool_t * pconf);
00588 static int countm_bdb_db_close(int db_index, apr_pool_t * p);
00589 static apr_status_t countm_bdb_open(p_countent_t p_ce, int * bDisplay);
00590 static int countm_env_lockfile_lock(const char * env_home, p_countm_env_lockfile_data_t p_ld, apr_pool_t * p);
00591 static int countm_env_lockfile_unlock(p_countm_env_lockfile_data_t p_ld, apr_pool_t * p);
00592 static int countm_env_lockfile_unlock_inc(p_countm_env_lockfile_data_t p_ld, apr_pool_t * p);
00593 static int countm_env_lockfile_unlock_dec(const char * env_home, p_countm_env_lockfile_data_t p_ld, apr_pool_t * p);
00594 static const char * countm_set_bdb_environment_home(cmd_parms *parms,
00595                                                     void *dummy,
00596                                                     const char *arg);
00597 static const char * countm_set_bdb_file(cmd_parms *parms, void *dummy,
00598                                         const char *arg);
00599 /* *********************************** */
00600 #elif defined(COUNTM_MYSQL)
00601 /* MYSQL PROTOTYPES */
00602 /* *********************************** */
00603 static apr_status_t countm_mysql_open(p_countent_t p_ce, int * bDisplay);
00604 static int countm_mysql_close(p_countent_t p_ce);
00605 static apr_status_t countm_mysql_dbcounter_table_process(p_countent_t p_ce, countm_mysql_dbcounter_table_e t, const char * val);
00606 static apr_status_t countm_mysql_dbcounter_table_process_finalize(p_countent_t p_ce);
00607 static apr_status_t countm_mysql_dbcounter_table_qstring(p_countent_t p_ce, char ** str);
00608 static int countm_mysql_masterlock_get(p_countent_t p_ce);
00609 static int countm_mysql_masterlock_put(p_countent_t p_ce);
00610 static const char * countm_set_mysql_config(cmd_parms *parms, void *dummy, const char *arg);
00611 #endif
00612 void countm_initialize_config(p_countm_config_t p);
00613 
00614 #if defined (MOD_CACHEM)
00615 static int countm_ext_status_hook(request_rec *r, int flags);
00616 static int countm_hook_pre_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp);
00617 int countm_cachem_handler_init(request_rec * r);
00618 #endif /* MOD_CACHEM */
00619 
00620 #endif /* COUNTM_MOD_H */

Generated on Sat Jan 7 15:48:39 2006 for mod_countm by  doxygen 1.4.2