00001 #ifndef COUNTM_H
00002 #define COUNTM_H
00003
00013
00021 #define DB_COUNTER "DB_COUNTER"
00022
00031 #define DB_ACCESS "DB_ACCESS"
00032
00039
00040 #define COUNTM_CONFIG_ICASE 0
00041
00046 #define DEFAULT_FONT_POINT_SIZE 20
00047
00054 #define COUNTM_ATIME_LENGTH 11
00055
00061 #define COUNTM_STR_SEPARATOR "/"
00062
00068 #define COUNTM_CHR_SEPARATOR '/'
00069
00077 #define COUNTM_BDB_ENV_LOCK "env.lock"
00078
00085 #define COUNTM_EXTENSIONS_SUBS 3
00086
00092 #define COUNTM_EXTENSIONS_USESUB 1
00093
00100 #define COUNTM_EXTENSIONS_TTF "^(.+)(\\.ttf|\\.pfa|\\.pfb|\\.dfont)$"
00101
00106 #define COUNTM_EXTENSIONS_JPEG "^(.+)(\\.jpeg|\\.jpg)$"
00107
00112 #define COUNTM_EXTENSIONS_PNG "^(.+)(\\.png)$"
00113
00118 #define COUNTM_UTILITY_LOCKOBJECT "COUNTM_UTILITY_LOCKOBJECT"
00119
00126 #define COUNTM_PARAMETER_LINK "link"
00127
00132 #define COUNTM_PARAMETER_FONT "font"
00133
00138 #define COUNTM_PARAMETER_IGNORE "ignore"
00139
00144 #define COUNTM_PARAMETER_WIDTH "width"
00145
00150 #define COUNTM_PARAMETER_POINT "point"
00151
00156 #define COUNTM_PARAMETER_BGCOLOR "bgcolor"
00157
00163 #define COUNTM_PARAMETER_BGFILE_TYPE "bgfile_type"
00164
00169 #define COUNTM_PARAMETER_TEXT "text"
00170
00175 #define COUNTM_PARAMETER_IMAGE "image"
00176
00182 #define COUNTM_PARAMETER_CNT "cnt"
00183
00188 #define COUNTM_PARAMETER_RANDOM "random"
00189
00194 #define COUNTM_PARAMETER_INSERT "insert"
00195
00200 #define COUNTM_PARAMETER_COUNT "count"
00201
00207 #define COUNTM_PARAMETER_ATIME "atime"
00208
00214 #define COUNTM_PARAMETER_HOST "host"
00215
00221 #define COUNTM_PARAMETER_CNT "cnt"
00222
00228 #define COUNTM_MYSQL_QUERY_BUFF_SIZE 2048
00229
00234 #define COUNTM_STR_NOTDEF "notdef"
00235
00241 #define MAX_WIDTH_CHAR_DISPLAY 9
00242
00243
00244
00245
00246
00247
00248
00253 enum imagetype {
00254 img_notdef=-1,
00255 img_jpeg=0,
00256 img_png=1
00257 };
00258
00263 enum randomtype {
00264 random_notdef=-1,
00265 random_true=0,
00266 random_false=1
00267 };
00268
00273 enum resettype {
00274 reset_notdef,
00275 reset_value,
00276 reset_delete,
00277 reset_init,
00278 reset_access
00279 };
00280
00285 enum counttype {
00286 count_notdef,
00287 count_inc,
00288 count_dec,
00289 count_norm_inc,
00290 count_norm_dec,
00291 count_inc_nopub,
00292 count_dec_nopub
00293 };
00294
00299 enum countm_state {
00300 countm_state_notdef=-1,
00301 countm_state_off=0,
00302 countm_state_on=1
00303 };
00304
00309 typedef struct value_status {
00310 unsigned int status_width_val:1;
00311 unsigned int status_point_val:1;
00312 unsigned int status_bgcolor_val:1;
00314 unsigned int status_text_val:1;
00315 unsigned int status_font:1;
00319 unsigned int status_bgfile:1;
00323 } status_t, * p_status_t;
00324
00325 #define INITIALIZE_STATUS_RECORD \
00326 {\
00327 .status_width_val=0,\
00328 .status_point_val=0,\
00329 .status_bgcolor_val=0,\
00330 .status_text_val=0,\
00331 .status_font=0,\
00332 .status_bgfile=0\
00333 }
00334
00339 typedef unsigned long cntval_t;
00340
00345 typedef struct rgb {
00346 int rgb_r;
00347 int rgb_g;
00348 int rgb_b;
00349 } rgb_t, * p_rgb_t;
00350
00361 typedef struct dbcounter_record {
00362 cntval_t cnt;
00363 enum imagetype image;
00364 enum counttype count;
00365 enum randomtype random;
00366 enum imagetype bgfile_type;
00367 status_t status;
00368 int width_val;
00369 int point_val;
00370 rgb_t bgcolor_val;
00371 rgb_t text_val;
00372 char atime[COUNTM_ATIME_LENGTH];
00373 } dbcounter_record_t, * p_dbcounter_record_t;
00374
00379 typedef struct dbcounter_data {
00380 cntval_t cnt;
00381 enum imagetype image;
00382 enum counttype count;
00383 enum randomtype random;
00384 enum imagetype bgfile_type;
00385 status_t status;
00386 int width_val;
00387 int point_val;
00388 rgb_t bgcolor_val;
00389 rgb_t text_val;
00390 char atime[COUNTM_ATIME_LENGTH];
00391 const char * font;
00392 const char * bgfile;
00393 } dbcounter_data_t, * p_dbcounter_data_t;
00394
00395
00396 #define INITIALIZE_DBCOUNTER_DATA \
00397 {\
00398 .cnt=0,\
00399 .image=img_notdef,\
00400 .count=count_notdef,\
00401 .random=random_notdef,\
00402 .bgfile_type=img_notdef,\
00403 .status=INITIALIZE_STATUS_RECORD,\
00404 .width_val=0,\
00405 .point_val=0,\
00406 .bgcolor_val={0,0,0},\
00407 .text_val={255,255,255},\
00408 .font=NULL,\
00409 .bgfile=NULL\
00410 }
00411
00412
00413 #if defined(COUNTM_BDB)
00414
00415
00416
00421 typedef enum countm_bdb_state {
00422 countm_bdb_state_unknown,
00423 countm_bdb_state_none,
00424 countm_bdb_state_valid
00425 } countm_bdb_state_e;
00426
00432 typedef struct countm_bdb_env {
00433 DB_ENV * db_env;
00434 char * name;
00435 u_int32_t lock_id;
00436 char * lock_object;
00437 DB_LOCK lock;
00438 } countm_bdb_env_t, * p_countm_bdb_env_t;
00439
00440 #define INITIALIZE_COUNTM_BDB_ENV {\
00441 .db_env=NULL,\
00442 .name=NULL,\
00443 .lock_id=0,\
00444 .lock_object=NULL\
00445 }
00446
00451 typedef struct countm_bdb_db {
00452 DB * counter;
00453 DB * access;
00454 char * name;
00455 int i_env;
00456 } countm_bdb_db_t, * p_countm_bdb_db_t;
00457
00458 #define INITIALIZE_COUNTM_BDB_DB {\
00459 .counter=NULL,\
00460 .access=NULL,\
00461 .name=NULL,\
00462 .i_env=0\
00463 }
00464
00465
00466 #elif defined(COUNTM_MYSQL)
00467
00468
00469
00474 typedef enum countm_mysql_dbaccess_table {
00475 countm_mysql_dbaccess_table_link=0,
00476 countm_mysql_dbaccess_table_start=countm_mysql_dbaccess_table_link,
00477 countm_mysql_dbaccess_table_host,
00478 countm_mysql_dbaccess_table_total
00479 } countm_mysql_dbaccess_table_e;
00480
00484 const char countm_dbaccess_field[countm_mysql_dbaccess_table_total][32]={
00485 COUNTM_PARAMETER_LINK,
00486 COUNTM_PARAMETER_HOST
00487 };
00488
00493 typedef enum countm_mysql_dbcounter_table {
00494 countm_mysql_dbcounter_table_link=0,
00495 countm_mysql_dbcounter_table_start=countm_mysql_dbcounter_table_link,
00496 countm_mysql_dbcounter_table_font,
00497 countm_mysql_dbcounter_table_width,
00498 countm_mysql_dbcounter_table_point,
00499 countm_mysql_dbcounter_table_bgcolor,
00500 countm_mysql_dbcounter_table_bgfile_type,
00501 countm_mysql_dbcounter_table_text,
00502 countm_mysql_dbcounter_table_image,
00503 countm_mysql_dbcounter_table_cnt,
00504 countm_mysql_dbcounter_table_random,
00505 countm_mysql_dbcounter_table_count,
00506 countm_mysql_dbcounter_table_atime,
00507 countm_mysql_dbcounter_table_total
00508 } countm_mysql_dbcounter_table_e;
00509
00513 const char countm_dbcounter_field[countm_mysql_dbcounter_table_total][32]={
00514 COUNTM_PARAMETER_LINK,
00515 COUNTM_PARAMETER_FONT,
00516 COUNTM_PARAMETER_WIDTH,
00517 COUNTM_PARAMETER_POINT,
00518 COUNTM_PARAMETER_BGCOLOR,
00519 COUNTM_PARAMETER_BGFILE_TYPE,
00520 COUNTM_PARAMETER_TEXT,
00521 COUNTM_PARAMETER_IMAGE,
00522 COUNTM_PARAMETER_CNT,
00523 COUNTM_PARAMETER_RANDOM,
00524 COUNTM_PARAMETER_COUNT,
00525 COUNTM_PARAMETER_ATIME
00526 };
00527
00528 #endif
00529
00530
00531
00532
00533
00534
00535
00539 extern const char * const version;
00540
00541
00542 #if defined(COUNTM_BDB)
00543
00544
00545
00549 static countm_bdb_db_t bdb_db_init=INITIALIZE_COUNTM_BDB_DB;
00553 static countm_bdb_env_t bdb_env_init=INITIALIZE_COUNTM_BDB_ENV;
00554
00558 static const u_int32_t bdb_counter_flags=0;
00559 static const u_int32_t bdb_counter_set_flags=0;
00563 static const u_int32_t bdb_access_flags=0;
00564 static const u_int32_t bdb_access_set_flags=DB_DUPSORT;
00568 static const u_int32_t bdb_env_flags=DB_INIT_MPOOL|DB_INIT_LOCK;
00569 static const u_int32_t bdb_env_set_flags=0;
00574 static u_int32_t bdbthreaded=0;
00575
00576 #elif defined(COUNTM_MYSQL)
00577
00578
00579 #endif
00580
00581
00582
00583
00584 static void countm_print_enum_imagetype(enum imagetype it, char ** r_str);
00585 static void countm_print_enum_randomtype(enum randomtype rt, char ** r_str);
00586 static void countm_print_enum_counttype(enum counttype ct, char ** r_str);
00587 static void countm_print_struct_rgb(p_rgb_t p_rgb, char * buf);
00588 static int countm_enum_counttype(const char * buf, enum counttype * p_ct);
00589 static int countm_enum_imagetype(const char * buf, enum imagetype * p_it);
00590 static int countm_enum_randomtype(const char * buf, enum randomtype * p_rt);
00591 static void countm_rgb_color(const char *hexnum, p_rgb_t rgb);
00592
00593 #endif