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

countm_util.h

Go to the documentation of this file.
00001 #ifndef COUNTM_UTIL_H
00002 #define COUNTM_UTIL_H
00003 
00013 /*
00014  *@def HAVE_FCNTL_H
00015  *@brief Define if your Apache Installation defines this.
00016  *A shortcut to avoid yet another configuration option.
00017  *Now an autoconf variable.
00018  *However, the automatic setting of these config options assumes that
00019  *  the Apache2 build process automatically set them in the same manner.
00020  */
00021 /*#define HAVE_FCNTL_H*/
00022 
00023 /*
00024  *@def HAVE_SYS_FILE_H
00025  *@brief Define if your Apache Installation defines this.
00026  *A shortcut to avoid yet another configuration option.
00027  *Now an autoconf variable.
00028  *However, the automatic setting of these config options assumes that
00029  *  the Apache2 build process automatically set them in the same manner.
00030  */
00031 /*#define HAVE_SYS_FILE_H*/
00032 
00043 #define COUNTM_MYSQL_SELECT_ROWS 0
00044 
00048 #define CM_SUCCESS          0
00049 #define CM_NO_LINK          1
00050 #define CM_DB               2
00051 #define CM_PARAM_INVALID    3
00052 #define CM_PARAM_DUP        4
00053 #define CM_NO_HOST          5
00054 #define CM_FILE             6
00055 #define CM_SYNTAX           7
00056 #define CM_LINK             8
00057 #define CM_MEMORY           9
00058 #define CM_OVERFLOW        10 /* see COUNTM_MYSQL_QUERY_BUFF_SIZE */
00059 
00060 typedef enum cm_param {
00061   cm_param_dba=0,
00062   cm_param_start=cm_param_dba,
00063   cm_param_dbc,
00064   cm_param_l,
00065   cm_param_h,
00066   cm_param_x,
00067   cm_param_f,
00068   cm_param_list,
00069   cm_param_insert,
00070   cm_param_delete,
00071   cm_param_v,
00072   cm_param_help,
00073 #if defined(COUNTM_BDB)
00074   cm_param_dbenv,
00075   cm_param_dbfile,
00076 #elif defined(COUNTM_MYSQL)
00077   cm_param_host,
00078   cm_param_user,
00079   cm_param_passwd,
00080   cm_param_db,
00081   cm_param_port,
00082   cm_param_unix_socket,
00083   cm_param_opt_group,
00084   cm_param_opt_file,
00085 #else
00086 #error Unsupported Database.
00087 #endif
00088   cm_param_total
00089 } cm_param_e, * p_cm_param_e;
00090 
00091 #if defined (COUNTM_BDB)
00092 
00096 typedef struct countm_env_lockfile_data {
00097   int fd; 
00098   int cnt; 
00099 } countm_env_lockfile_data_t, * p_countm_env_lockfile_data_t;
00100 #endif
00101 
00102 #if defined (COUNTM_MYSQL)
00103 
00106 const enum enum_field_types
00107 countm_dbaccess_field_types[countm_mysql_dbaccess_table_total]={
00108   FIELD_TYPE_VAR_STRING,
00109   FIELD_TYPE_VAR_STRING
00110 };
00111 
00115 const enum enum_field_types
00116 countm_dbcounter_field_types[countm_mysql_dbcounter_table_total]={
00117   FIELD_TYPE_VAR_STRING, /* link */
00118   FIELD_TYPE_BLOB, /* font */
00119   FIELD_TYPE_LONG, /* width */
00120   FIELD_TYPE_LONG,  /* point */
00121   FIELD_TYPE_BLOB, /* bgcolor */
00122   FIELD_TYPE_ENUM, /* bgfile_type */
00123   FIELD_TYPE_VAR_STRING, /* text */
00124   FIELD_TYPE_ENUM, /* image */
00125   FIELD_TYPE_LONGLONG, /* cnt */
00126   FIELD_TYPE_ENUM, /* random */
00127   FIELD_TYPE_ENUM, /* count */
00128   FIELD_TYPE_DATE /* atime */
00129 };
00130 
00131 #endif /* if defined(COUNTM_MYSQL) */
00132 
00137 typedef struct options_record {
00138   int cmd; 
00139   int bParam[cm_param_total]; 
00140   int nParam; 
00141   char * linkname; 
00142   char * hostname; 
00143   char * filename; 
00144 #if defined (COUNTM_BDB)
00145   char * dbenv; 
00146   char * dbfile; 
00147 #elif defined(COUNTM_MYSQL)
00148   char * host; 
00149   char * user; 
00150   char * passwd; 
00151   char * db; 
00152   unsigned int port; 
00153   char * unix_socket; 
00154   char * opt_group; 
00155   char * opt_file; 
00156 #endif
00157 } options_record_t, * p_options_record_t;
00158 
00159 /* * GLOBALS * */
00160 //static const char * const sza_version=STRING_EYES(VERSION);
00161 static const char * const sza_version="TEST";
00162 options_record_t orec;
00163 
00164 #if defined (COUNTM_BDB)
00165 static countm_bdb_env_t bdb_env=INITIALIZE_COUNTM_BDB_ENV;
00166 
00175 static const db_lockmode_t bdb_lockmode=DB_LOCK_WRITE;
00176 static countm_bdb_db_t bdb=INITIALIZE_COUNTM_BDB_DB;
00177 #elif defined (COUNTM_MYSQL)
00178 MYSQL * mysql;
00179 #endif
00180 
00181 static const char cmdline_options[cm_param_total][16] = {
00182   "-dba","-dbc","-l=","-h=","-x","-f=",
00183   "L", "I", "D", "-V", "-?",
00184 #if defined(COUNTM_BDB)
00185   "-dbenv=", "-dbfile="
00186 #elif defined(COUNTM_MYSQL)
00187   "-host=","-user=","-passwd=","-db=", "-port=", "-unix_socket=",
00188   "-opt_group=", "-opt_file="
00189 #endif
00190 };
00191 
00192 const char cmdline_descriptions[cm_param_total][63] = {
00193   "Apply operation to DB_ACCESS.",
00194   "Apply operation to DB_COUNTER.",
00195   "The link name.",
00196   "The host name.",
00197   "Print headers and extended output.",
00198   "Input file name for INSERT command.",
00199   "Command: LIST",
00200   "Command: INSERT",
00201   "Command: DELETE",
00202   "Print version information and exit.",
00203   "Print help and exit.",
00204 #if defined(COUNTM_BDB)
00205   "The absolute path name of the BDB database environment.",
00206   "The BDB database file name."
00207 #elif defined(COUNTM_MYSQL)
00208   "The Mysql hostname or IP address.",
00209   "The Mysql login ID.",
00210   "The Mysql password for user.",
00211   "The Mysql database name.",
00212   "The Mysql port number for TCP/IP connections.",
00213   "The Mysql Socket or named pipe.",
00214   "The Mysql MYSQL_READ_DEFAULT_GROUP option.",
00215   "The Mysql MYSQL_READ_DEFAULT_FILE option."
00216 #endif
00217 };
00218 
00220 #if defined(COUNTM_BDB)
00221 static int countm_bdb_env_recover(const char * env_name);
00222 static int countm_split_packet(p_dbcounter_data_t p_dbcd, void * pkt, int pkt_len);
00223 static int countm_make_packet(p_dbcounter_data_t p_dbcd, void ** pkt, int * pkt_len);
00224 static int countm_env_lockfile_lock(const char * env_home, p_countm_env_lockfile_data_t p_ld);
00225 static int countm_env_lockfile_unlock(p_countm_env_lockfile_data_t p_ld);
00226 static int countm_env_lockfile_unlock_inc(p_countm_env_lockfile_data_t p_ld);
00227 static int countm_env_lockfile_unlock_dec(const char * env_home, p_countm_env_lockfile_data_t p_ld);
00228 #elif defined(COUNTM_MYSQL) 
00229 #endif
00230 static int countm_open_databases();
00231 static int countm_close_databases();
00232 static int countm_masterlock_get();
00233 static int countm_masterlock_put();
00234 static int countm_version_verify();
00235 static int countm_dbcounter_list(int bX, int bAccess);
00236 static int countm_dbcounter_list_link(char * p_link, int bX, int bAccess);
00237 static int countm_dbaccess_list_X();
00238 static int countm_dbaccess_list_noX();
00239 static int countm_dbaccess_list_link(char * p_link, int bX);
00240 static int countm_dbcounter_delete_link(char * p_link, int bAccess);
00241 static int countm_dbaccess_delete_link(char * p_link);
00242 static int countm_dbaccess_delete_host(char * p_link, char * p_host);
00243 static int countm_dbaccess_delete_host_all(const char * p_host);
00244 static int countm_dbcounter_insert(char * p_link, p_dbcounter_data_t p_dbcd);
00245 static int countm_dbaccess_insert(char * p_link, char * p_host);
00246 static void countm_print_dbcounter_data(p_dbcounter_data_t p_dbcd);
00247 static void countm_print_enum_resettype(enum resettype rt, char ** r_str);
00248 static int countm_enum_resettype(const char * buf, enum resettype * p_rt);
00249 static int countm_read_info_isaccess(char * buf);
00250 static int countm_read_info_iscounter(char * buf);
00251 static int countm_read_info_counteritem(char * buf, p_dbcounter_data_t p_dbcd);
00252 static int countm_match_extension(const char * fname, const char * pattern);
00253 static int countm_verify_bgfile(char * fn, enum imagetype * img);
00254 static void countm_print_help(char * pc);
00255 static int countm_read_info_readline(FILE * fp, char * p_line, int i_len);
00256 static char * countm_read_info_islink(char * buf);
00257 static int countm_read_info(char * fn);
00258 static int countm_parse_option(p_options_record_t p_or, char * p_param);
00259 static int countm_set_atime(p_dbcounter_data_t p_dbcd);
00260 
00261 #endif /* COUNTM_UTIL_H */

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