diff options
| author | 2002-05-14 21:47:15 +0000 | |
|---|---|---|
| committer | 2002-05-14 21:47:15 +0000 | |
| commit | aed1f25397eff242228dadb33f934d2722ba684d (patch) | |
| tree | 37a784d4de9562c611c7d70f271f83d9c32ff299 /mod_log_sql.c | |
| parent | 3a3c68117e1fdb7814815568a39b042b92b4df5d (diff) | |
Added notes logging capability. This is a commit prior to a lot of work
that will rename mod_log_mysql to mod_log_sql.
Diffstat (limited to 'mod_log_sql.c')
| -rw-r--r-- | mod_log_sql.c | 318 |
1 files changed, 228 insertions, 90 deletions
diff --git a/mod_log_sql.c b/mod_log_sql.c index 25a5013..84c6115 100644 --- a/mod_log_sql.c +++ b/mod_log_sql.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $Id: mod_log_sql.c,v 1.11 2002/04/23 17:26:15 helios Exp $ */ | 1 | /* $Id: mod_log_sql.c,v 1.12 2002/05/14 21:47:15 helios Exp $ */ |
| 2 | 2 | ||
| 3 | /* --------* | 3 | /* --------* |
| 4 | * DEFINES * | 4 | * DEFINES * |
| @@ -20,12 +20,12 @@ | |||
| 20 | * INCLUDES * | 20 | * INCLUDES * |
| 21 | * ---------*/ | 21 | * ---------*/ |
| 22 | #include <time.h> | 22 | #include <time.h> |
| 23 | #include <mysql/mysql.h> | ||
| 24 | #include <stdio.h> | 23 | #include <stdio.h> |
| 25 | #include "httpd.h" | 24 | #include "httpd.h" |
| 26 | #include "http_config.h" | 25 | #include "http_config.h" |
| 27 | #include "http_log.h" | 26 | #include "http_log.h" |
| 28 | #include "http_core.h" | 27 | #include "http_core.h" |
| 28 | #include "mysql.h" | ||
| 29 | 29 | ||
| 30 | #if MODULE_MAGIC_NUMBER >= 19980324 /* M_M_N is defined in /usr/local/Apache/include/ap_mmn.h, 19990320 as of this writing. */ | 30 | #if MODULE_MAGIC_NUMBER >= 19980324 /* M_M_N is defined in /usr/local/Apache/include/ap_mmn.h, 19990320 as of this writing. */ |
| 31 | #include "ap_compat.h" | 31 | #include "ap_compat.h" |
| @@ -55,7 +55,7 @@ char *db_name = NULL; | |||
| 55 | char *db_host = NULL; | 55 | char *db_host = NULL; |
| 56 | char *db_user = NULL; | 56 | char *db_user = NULL; |
| 57 | char *db_pwd = NULL; | 57 | char *db_pwd = NULL; |
| 58 | char *socket_file = "/var/lib/mysql/mysql.sock"; | 58 | char *socket_file = "/tmp/mysql.sock"; |
| 59 | 59 | ||
| 60 | typedef const char *(*item_key_func) (request_rec *, char *); | 60 | typedef const char *(*item_key_func) (request_rec *, char *); |
| 61 | 61 | ||
| @@ -67,10 +67,12 @@ typedef const char *(*item_key_func) (request_rec *, char *); | |||
| 67 | */ | 67 | */ |
| 68 | typedef struct { | 68 | typedef struct { |
| 69 | int table_made; | 69 | int table_made; |
| 70 | char *transfer_table_name; | ||
| 71 | array_header *referer_ignore_list; | 70 | array_header *referer_ignore_list; |
| 72 | array_header *transfer_ignore_list; | 71 | array_header *transfer_ignore_list; |
| 73 | array_header *remhost_ignore_list; | 72 | array_header *remhost_ignore_list; |
| 73 | array_header *notes_list; | ||
| 74 | char *notes_table_name; | ||
| 75 | char *transfer_table_name; | ||
| 74 | char *transfer_log_format; | 76 | char *transfer_log_format; |
| 75 | char *preserve_file; | 77 | char *preserve_file; |
| 76 | char *cookie_name; | 78 | char *cookie_name; |
| @@ -322,64 +324,66 @@ static const char *extract_cookie(request_rec *r, char *a) | |||
| 322 | 324 | ||
| 323 | log_mysql_state *cls = get_module_config(r->server->module_config, &mysql_log_module); | 325 | log_mysql_state *cls = get_module_config(r->server->module_config, &mysql_log_module); |
| 324 | 326 | ||
| 325 | #ifdef DEBUG | 327 | if (cls->cookie_name != NULL) { |
| 326 | ap_log_error(APLOG_MARK,DEBUGLEVEL,r->server,"watching for cookie '%s'", cls->cookie_name); | ||
| 327 | #endif | ||
| 328 | |||
| 329 | /* Fetch out the cookie header */ | ||
| 330 | cookiestr = (char *)table_get(r->headers_in, "cookie2"); | ||
| 331 | if (cookiestr != NULL) { | ||
| 332 | #ifdef DEBUG | 328 | #ifdef DEBUG |
| 333 | ap_log_error(APLOG_MARK,DEBUGLEVEL,r->server,"Cookie2: [%s]", cookiestr); | 329 | ap_log_error(APLOG_MARK,DEBUGLEVEL,r->server,"watching for cookie '%s'", cls->cookie_name); |
| 334 | #endif | 330 | #endif |
| 335 | /* Does the cookie string contain one with our name? */ | 331 | |
| 336 | isvalid = strstr(cookiestr, cls->cookie_name); | 332 | /* Fetch out the cookie header */ |
| 337 | if (isvalid != NULL) { | 333 | cookiestr = (char *)table_get(r->headers_in, "cookie2"); |
| 338 | /* Move past the cookie name and equal sign */ | 334 | if (cookiestr != NULL) { |
| 339 | isvalid += strlen(cls->cookie_name) + 1; | 335 | #ifdef DEBUG |
| 340 | /* Duplicate it into the pool */ | 336 | ap_log_error(APLOG_MARK,DEBUGLEVEL,r->server,"Cookie2: [%s]", cookiestr); |
| 341 | cookiebuf = ap_pstrdup(r->pool, isvalid); | 337 | #endif |
| 342 | /* Segregate just this cookie out of the string | 338 | /* Does the cookie string contain one with our name? */ |
| 343 | * with a terminating nul at the first semicolon */ | 339 | isvalid = strstr(cookiestr, cls->cookie_name); |
| 344 | cookieend = strchr(cookiebuf, ';'); | 340 | if (isvalid != NULL) { |
| 345 | if (cookieend != NULL) | 341 | /* Move past the cookie name and equal sign */ |
| 346 | *cookieend = '\0'; | 342 | isvalid += strlen(cls->cookie_name) + 1; |
| 347 | return cookiebuf; | 343 | /* Duplicate it into the pool */ |
| 348 | } | 344 | cookiebuf = ap_pstrdup(r->pool, isvalid); |
| 349 | } | 345 | /* Segregate just this cookie out of the string |
| 350 | 346 | * with a terminating nul at the first semicolon */ | |
| 351 | cookiestr = (char *)table_get(r->headers_in, "cookie"); | 347 | cookieend = strchr(cookiebuf, ';'); |
| 352 | if (cookiestr != NULL) { | 348 | if (cookieend != NULL) |
| 353 | #ifdef DEBUG | 349 | *cookieend = '\0'; |
| 354 | ap_log_error(APLOG_MARK,DEBUGLEVEL,r->server,"Cookie: [%s]", cookiestr); | 350 | return cookiebuf; |
| 355 | #endif | 351 | } |
| 356 | isvalid = strstr(cookiestr, cls->cookie_name); | ||
| 357 | if (isvalid != NULL) { | ||
| 358 | isvalid += strlen(cls->cookie_name) + 1; | ||
| 359 | cookiebuf = ap_pstrdup(r->pool, isvalid); | ||
| 360 | cookieend = strchr(cookiebuf, ';'); | ||
| 361 | if (cookieend != NULL) | ||
| 362 | *cookieend = '\0'; | ||
| 363 | return cookiebuf; | ||
| 364 | } | 352 | } |
| 365 | } | ||
| 366 | 353 | ||
| 367 | cookiestr = table_get(r->headers_out, "set-cookie"); | 354 | cookiestr = (char *)table_get(r->headers_in, "cookie"); |
| 368 | if (cookiestr != NULL) { | 355 | if (cookiestr != NULL) { |
| 369 | #ifdef DEBUG | 356 | #ifdef DEBUG |
| 370 | ap_log_error(APLOG_MARK,DEBUGLEVEL,r->server,"Set-Cookie: [%s]", cookiestr); | 357 | ap_log_error(APLOG_MARK,DEBUGLEVEL,r->server,"Cookie: [%s]", cookiestr); |
| 371 | #endif | 358 | #endif |
| 372 | isvalid = strstr(cookiestr, cls->cookie_name); | 359 | isvalid = strstr(cookiestr, cls->cookie_name); |
| 373 | if (isvalid != NULL) { | 360 | if (isvalid != NULL) { |
| 374 | isvalid += strlen(cls->cookie_name) + 1; | 361 | isvalid += strlen(cls->cookie_name) + 1; |
| 375 | cookiebuf = ap_pstrdup(r->pool, isvalid); | 362 | cookiebuf = ap_pstrdup(r->pool, isvalid); |
| 376 | cookieend = strchr(cookiebuf, ';'); | 363 | cookieend = strchr(cookiebuf, ';'); |
| 377 | if (cookieend != NULL) | 364 | if (cookieend != NULL) |
| 378 | *cookieend = '\0'; | 365 | *cookieend = '\0'; |
| 379 | return cookiebuf; | 366 | return cookiebuf; |
| 367 | } | ||
| 380 | } | 368 | } |
| 381 | } | ||
| 382 | 369 | ||
| 370 | cookiestr = table_get(r->headers_out, "set-cookie"); | ||
| 371 | if (cookiestr != NULL) { | ||
| 372 | #ifdef DEBUG | ||
| 373 | ap_log_error(APLOG_MARK,DEBUGLEVEL,r->server,"Set-Cookie: [%s]", cookiestr); | ||
| 374 | #endif | ||
| 375 | isvalid = strstr(cookiestr, cls->cookie_name); | ||
| 376 | if (isvalid != NULL) { | ||
| 377 | isvalid += strlen(cls->cookie_name) + 1; | ||
| 378 | cookiebuf = ap_pstrdup(r->pool, isvalid); | ||
| 379 | cookieend = strchr(cookiebuf, ';'); | ||
| 380 | if (cookieend != NULL) | ||
| 381 | *cookieend = '\0'; | ||
| 382 | return cookiebuf; | ||
| 383 | } | ||
| 384 | } | ||
| 385 | } | ||
| 386 | |||
| 383 | return "-"; | 387 | return "-"; |
| 384 | } | 388 | } |
| 385 | 389 | ||
| @@ -393,12 +397,26 @@ static const char *extract_request_timestamp(request_rec *r, char *a) | |||
| 393 | 397 | ||
| 394 | static const char *extract_note(request_rec *r, char *a) | 398 | static const char *extract_note(request_rec *r, char *a) |
| 395 | { | 399 | { |
| 396 | return table_get(r->notes, a); | 400 | return ap_table_get(r->notes, a); |
| 401 | |||
| 402 | /*ap_table_do(extract_table, r, r->notes, NULL);*/ | ||
| 403 | |||
| 397 | } | 404 | } |
| 398 | 405 | ||
| 399 | static const char *extract_env_var(request_rec *r, char *a) | 406 | static const char *extract_env_var(request_rec *r, char *a) |
| 400 | { | 407 | { |
| 401 | return table_get(r->subprocess_env, "HTTP_USER_AGENT"); | 408 | return ap_table_get(r->subprocess_env, a); |
| 409 | } | ||
| 410 | |||
| 411 | static const char *extract_unique_id(request_rec *r, char *a) | ||
| 412 | { | ||
| 413 | const char *tempid; | ||
| 414 | |||
| 415 | tempid = ap_table_get(r->subprocess_env, "UNIQUE_ID"); | ||
| 416 | if (!tempid) | ||
| 417 | return "-"; | ||
| 418 | else | ||
| 419 | return tempid; | ||
| 402 | } | 420 | } |
| 403 | 421 | ||
| 404 | /* End declarations of various extract_ functions */ | 422 | /* End declarations of various extract_ functions */ |
| @@ -421,7 +439,8 @@ struct log_mysql_item_list { | |||
| 421 | { 'H', extract_request_protocol, "request_protocol", 0, 1 }, | 439 | { 'H', extract_request_protocol, "request_protocol", 0, 1 }, |
| 422 | { 'h', extract_remote_host, "remote_host", 0, 1 }, | 440 | { 'h', extract_remote_host, "remote_host", 0, 1 }, |
| 423 | { 'i', extract_header_in, "header_in", 0, 1 }, | 441 | { 'i', extract_header_in, "header_in", 0, 1 }, |
| 424 | { 'l', extract_remote_logname, "remote_logname", 0, 1 }, | 442 | { 'I', extract_unique_id, "id", 0, 1 }, |
| 443 | { 'l', extract_remote_logname, "remote_logname", 0, 1 }, | ||
| 425 | { 'm', extract_request_method, "request_method", 0, 1 }, | 444 | { 'm', extract_request_method, "request_method", 0, 1 }, |
| 426 | { 'n', extract_note, "note", 0, 1 }, | 445 | { 'n', extract_note, "note", 0, 1 }, |
| 427 | { 'o', extract_header_out, "header_out", 0, 1 }, | 446 | { 'o', extract_header_out, "header_out", 0, 1 }, |
| @@ -506,6 +525,31 @@ int open_logdb_link() | |||
| 506 | return 0; | 525 | return 0; |
| 507 | } | 526 | } |
| 508 | 527 | ||
| 528 | #ifdef DEBUG | ||
| 529 | static int trace(void *data, const char *key, const char *val) | ||
| 530 | { | ||
| 531 | FILE *fp; | ||
| 532 | request_rec *r = (request_rec *)data; | ||
| 533 | |||
| 534 | fp = pfopen(r->pool, "/tmp/trace", "a"); | ||
| 535 | |||
| 536 | if (fp) { | ||
| 537 | fprintf(fp, "Field '%s' == '%s'\n", key, val); | ||
| 538 | } | ||
| 539 | |||
| 540 | pfclose(r->pool, fp); | ||
| 541 | |||
| 542 | return TRUE; | ||
| 543 | } | ||
| 544 | #endif | ||
| 545 | |||
| 546 | const char *extract_table(void *data, const char *key, const char *val) | ||
| 547 | { | ||
| 548 | request_rec *r = (request_rec *)data; | ||
| 549 | |||
| 550 | return ap_pstrcat(r->pool, key, " = ", val, " ", NULL); | ||
| 551 | } | ||
| 552 | |||
| 509 | void preserve_entry(request_rec *r, const char *query) | 553 | void preserve_entry(request_rec *r, const char *query) |
| 510 | { | 554 | { |
| 511 | FILE *fp; | 555 | FILE *fp; |
| @@ -514,9 +558,10 @@ void preserve_entry(request_rec *r, const char *query) | |||
| 514 | fp = pfopen(r->pool, cls->preserve_file, "a"); | 558 | fp = pfopen(r->pool, cls->preserve_file, "a"); |
| 515 | if (fp == NULL) | 559 | if (fp == NULL) |
| 516 | ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"attempted append of local offline file but failed."); | 560 | ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"attempted append of local offline file but failed."); |
| 517 | else | 561 | else { |
| 518 | fprintf(fp,"%s;\n", query); | 562 | fprintf(fp,"%s;\n", query); |
| 519 | pfclose(r->pool, fp); | 563 | pfclose(r->pool, fp); |
| 564 | } | ||
| 520 | } | 565 | } |
| 521 | 566 | ||
| 522 | /*-----------------------------------------------------*/ | 567 | /*-----------------------------------------------------*/ |
| @@ -629,11 +674,11 @@ const char *set_log_mysql_cookie(cmd_parms *parms, void *dummy, char *arg) | |||
| 629 | 674 | ||
| 630 | const char *set_log_mysql_preserve_file(cmd_parms *parms, void *dummy, char *arg) | 675 | const char *set_log_mysql_preserve_file(cmd_parms *parms, void *dummy, char *arg) |
| 631 | { | 676 | { |
| 632 | char *pfile; | 677 | /* char *pfile; */ |
| 633 | log_mysql_state *cls = get_module_config(parms->server->module_config, &mysql_log_module); | 678 | log_mysql_state *cls = get_module_config(parms->server->module_config, &mysql_log_module); |
| 634 | 679 | ||
| 635 | pfile = ap_pstrcat(parms->pool, "/tmp/", arg, NULL); | 680 | /* pfile = ap_pstrcat(parms->pool, "/tmp/", arg, NULL); */ |
| 636 | cls->preserve_file = pfile; | 681 | cls->preserve_file = arg; |
| 637 | return NULL; | 682 | return NULL; |
| 638 | } | 683 | } |
| 639 | 684 | ||
| @@ -662,6 +707,17 @@ const char *set_transfer_log_mysql_table(cmd_parms *parms, void *dummy, char *ar | |||
| 662 | return NULL; | 707 | return NULL; |
| 663 | } | 708 | } |
| 664 | 709 | ||
| 710 | const char *set_notes_log_mysql_table(cmd_parms *parms, void *dummy, char *arg) | ||
| 711 | { | ||
| 712 | log_mysql_state *cls = get_module_config(parms->server->module_config, &mysql_log_module); | ||
| 713 | |||
| 714 | if (massvirtual != 0) | ||
| 715 | ap_log_error(APLOG_MARK,WARNINGLEVEL,parms->server,"do not set MySQLNotesLogTable when MySQLMassVirtualHosting is On. Ignoring."); | ||
| 716 | else | ||
| 717 | cls->notes_table_name = arg; | ||
| 718 | return NULL; | ||
| 719 | } | ||
| 720 | |||
| 665 | const char *set_mysql_transfer_log_format(cmd_parms *parms, void *dummy, char *arg) | 721 | const char *set_mysql_transfer_log_format(cmd_parms *parms, void *dummy, char *arg) |
| 666 | { | 722 | { |
| 667 | log_mysql_state *cls = get_module_config(parms->server->module_config, &mysql_log_module); | 723 | log_mysql_state *cls = get_module_config(parms->server->module_config, &mysql_log_module); |
| @@ -677,6 +733,7 @@ const char *set_mysql_socket_file(cmd_parms *parms, void *dummy, char *arg) | |||
| 677 | return NULL; | 733 | return NULL; |
| 678 | } | 734 | } |
| 679 | 735 | ||
| 736 | |||
| 680 | const char *add_referer_mysql_ignore(cmd_parms *parms, void *dummy, char *arg) | 737 | const char *add_referer_mysql_ignore(cmd_parms *parms, void *dummy, char *arg) |
| 681 | { | 738 | { |
| 682 | char **addme; | 739 | char **addme; |
| @@ -707,6 +764,16 @@ const char *add_remhost_mysql_ignore(cmd_parms *parms, void *dummy, char *arg) | |||
| 707 | return NULL; | 764 | return NULL; |
| 708 | } | 765 | } |
| 709 | 766 | ||
| 767 | const char *add_mysql_note(cmd_parms *parms, void *dummy, char *arg) | ||
| 768 | { | ||
| 769 | char **addme; | ||
| 770 | log_mysql_state *cls = get_module_config(parms->server->module_config, &mysql_log_module); | ||
| 771 | |||
| 772 | addme = push_array(cls->notes_list); | ||
| 773 | *addme = pstrdup(cls->notes_list->pool, arg); | ||
| 774 | return NULL; | ||
| 775 | } | ||
| 776 | |||
| 710 | 777 | ||
| 711 | 778 | ||
| 712 | 779 | ||
| @@ -780,17 +847,18 @@ void *log_mysql_make_state(pool *p, server_rec *s) | |||
| 780 | 847 | ||
| 781 | log_mysql_state *cls = (log_mysql_state *) ap_palloc(p, sizeof(log_mysql_state)); | 848 | log_mysql_state *cls = (log_mysql_state *) ap_palloc(p, sizeof(log_mysql_state)); |
| 782 | 849 | ||
| 783 | |||
| 784 | cls->transfer_table_name = NULL; | 850 | cls->transfer_table_name = NULL; |
| 785 | cls->transfer_log_format = NULL; | 851 | cls->transfer_log_format = NULL; |
| 852 | cls->notes_table_name = "notes"; | ||
| 786 | 853 | ||
| 787 | cls->referer_ignore_list = make_array(p, 1, sizeof(char *)); | 854 | cls->referer_ignore_list = make_array(p, 1, sizeof(char *)); |
| 788 | cls->transfer_ignore_list = make_array(p, 1, sizeof(char *)); | 855 | cls->transfer_ignore_list = make_array(p, 1, sizeof(char *)); |
| 789 | cls->remhost_ignore_list = make_array(p, 1, sizeof(char *)); | 856 | cls->remhost_ignore_list = make_array(p, 1, sizeof(char *)); |
| 790 | 857 | cls->notes_list = make_array(p, 1, sizeof(char *)); | |
| 791 | cls->table_made = 0; | 858 | cls->table_made = 0; |
| 792 | 859 | ||
| 793 | cls->preserve_file = "/tmp/mysql-preserve"; | 860 | cls->preserve_file = "/tmp/mysql-preserve"; |
| 861 | cls->cookie_name = NULL; | ||
| 794 | 862 | ||
| 795 | return (void *) cls; | 863 | return (void *) cls; |
| 796 | } | 864 | } |
| @@ -803,6 +871,9 @@ command_rec log_mysql_cmds[] = { | |||
| 803 | {"MySQLTransferLogTable", set_transfer_log_mysql_table, NULL, RSRC_CONF, TAKE1, | 871 | {"MySQLTransferLogTable", set_transfer_log_mysql_table, NULL, RSRC_CONF, TAKE1, |
| 804 | "The MySQL table that holds the transfer log"} | 872 | "The MySQL table that holds the transfer log"} |
| 805 | , | 873 | , |
| 874 | {"MySQLNotesLogTable", set_notes_log_mysql_table, NULL, RSRC_CONF, TAKE1, | ||
| 875 | "The MySQL table that holds the notes"} | ||
| 876 | , | ||
| 806 | {"MySQLTransferLogFormat", set_mysql_transfer_log_format, NULL, RSRC_CONF, TAKE1, | 877 | {"MySQLTransferLogFormat", set_mysql_transfer_log_format, NULL, RSRC_CONF, TAKE1, |
| 807 | "Instruct the module what information to log to the MySQL transfer log"} | 878 | "Instruct the module what information to log to the MySQL transfer log"} |
| 808 | , | 879 | , |
| @@ -836,6 +907,9 @@ command_rec log_mysql_cmds[] = { | |||
| 836 | {"MySQLSocketFile", set_mysql_socket_file, NULL, RSRC_CONF, TAKE1, | 907 | {"MySQLSocketFile", set_mysql_socket_file, NULL, RSRC_CONF, TAKE1, |
| 837 | "Name of the file to employ for socket connections to MySQL"} | 908 | "Name of the file to employ for socket connections to MySQL"} |
| 838 | , | 909 | , |
| 910 | {"MySQLWhichNotes", add_mysql_note, NULL, RSRC_CONF, ITERATE, | ||
| 911 | "Members of the 'notes' table that you would like to log"} | ||
| 912 | , | ||
| 839 | {NULL} | 913 | {NULL} |
| 840 | }; | 914 | }; |
| 841 | 915 | ||
| @@ -848,30 +922,38 @@ int log_mysql_transaction(request_rec *orig) | |||
| 848 | { | 922 | { |
| 849 | char **ptrptr, **ptrptr2; | 923 | char **ptrptr, **ptrptr2; |
| 850 | log_mysql_state *cls = get_module_config(orig->server->module_config, &mysql_log_module); | 924 | log_mysql_state *cls = get_module_config(orig->server->module_config, &mysql_log_module); |
| 851 | const char *str; | 925 | const char *access_query; |
| 852 | request_rec *r; | 926 | request_rec *r; |
| 853 | 927 | ||
| 854 | /* We handle mass virtual hosting differently. Dynamically determine the name | 928 | /* We handle mass virtual hosting differently. Dynamically determine the name |
| 855 | * of the table from the virtual server's name, and flag it for creation. | 929 | * of the table from the virtual server's name, and flag it for creation. |
| 856 | */ | 930 | */ |
| 857 | if (massvirtual == 1) { | 931 | if (massvirtual == 1) { |
| 858 | char *base = "access_"; | 932 | char *access_base = "access_"; |
| 859 | char *tablename; | 933 | char *notes_base = "notes_"; |
| 934 | char *a_tablename; | ||
| 935 | char *n_tablename; | ||
| 860 | int i; | 936 | int i; |
| 861 | 937 | ||
| 862 | /* Find memory long enough to hold the table name + \0. */ | 938 | /* Find memory long enough to hold the table name + \0. */ |
| 863 | tablename = ap_pstrcat(orig->pool, base, ap_get_server_name(orig), NULL); | 939 | a_tablename = ap_pstrcat(orig->pool, access_base, ap_get_server_name(orig), NULL); |
| 940 | n_tablename = ap_pstrcat(orig->pool, notes_base, ap_get_server_name(orig), NULL); | ||
| 864 | 941 | ||
| 865 | /* Transform any dots to underscores */ | 942 | /* Transform any dots or dashes to underscores */ |
| 866 | for (i = 0; i < strlen(tablename); i++) { | 943 | for (i = 0; i < strlen(a_tablename); i++) { |
| 867 | if (tablename[i] == '.') | 944 | if ( (a_tablename[i] == '.') || (a_tablename[i] == '-') ) |
| 868 | tablename[i] = '_'; | 945 | a_tablename[i] = '_'; |
| 946 | } | ||
| 947 | for (i = 0; i < strlen(n_tablename); i++) { | ||
| 948 | if ( (n_tablename[i] == '.') || (n_tablename[i] == '-') ) | ||
| 949 | n_tablename[i] = '_'; | ||
| 869 | } | 950 | } |
| 870 | 951 | ||
| 871 | /* Tell this virtual server its transfer table name, and | 952 | /* Tell this virtual server its transfer table name, and |
| 872 | * turn on create_tables, which is implied by massvirtual. | 953 | * turn on create_tables, which is implied by massvirtual. |
| 873 | */ | 954 | */ |
| 874 | cls->transfer_table_name = tablename; | 955 | cls->transfer_table_name = a_tablename; |
| 956 | cls->notes_table_name = n_tablename; | ||
| 875 | create_tables = 1; | 957 | create_tables = 1; |
| 876 | } | 958 | } |
| 877 | 959 | ||
| @@ -880,19 +962,27 @@ int log_mysql_transaction(request_rec *orig) | |||
| 880 | return DECLINED; | 962 | return DECLINED; |
| 881 | } else { | 963 | } else { |
| 882 | const char *thehost; | 964 | const char *thehost; |
| 965 | const char *thenote; | ||
| 883 | char *fields = "", *values = ""; | 966 | char *fields = "", *values = ""; |
| 967 | char *notesets = ""; | ||
| 968 | char *note_query = ""; | ||
| 969 | const char *unique_id; | ||
| 884 | const char *formatted_item; | 970 | const char *formatted_item; |
| 885 | int i, j, length; | 971 | int i, j, length; |
| 886 | char *createstring = NULL; | 972 | char *create_access = NULL; |
| 973 | char *create_notes = NULL; | ||
| 887 | 974 | ||
| 888 | for (r = orig; r->next; r = r->next) { | 975 | for (r = orig; r->next; r = r->next) { |
| 889 | continue; | 976 | continue; |
| 890 | } | 977 | } |
| 891 | 978 | ||
| 979 | #ifdef DEBUG | ||
| 980 | /*ap_table_do(trace, orig, orig->subprocess_env, NULL);*/ | ||
| 981 | #endif | ||
| 892 | 982 | ||
| 893 | /* The following is a stolen upsetting mess of pointers, I'm sorry | 983 | /* The following is a stolen upsetting mess of pointers, I'm sorry. |
| 894 | * Anyone with the motiviation and/or the time should feel free | 984 | * Anyone with the motiviation and/or the time should feel free |
| 895 | * to make this cleaner, and while at it, clean the same mess at the RefererLog part :) */ | 985 | * to make this cleaner. :) */ |
| 896 | ptrptr2 = (char **) (cls->transfer_ignore_list->elts + (cls->transfer_ignore_list->nelts * cls->transfer_ignore_list->elt_size)); | 986 | ptrptr2 = (char **) (cls->transfer_ignore_list->elts + (cls->transfer_ignore_list->nelts * cls->transfer_ignore_list->elt_size)); |
| 897 | 987 | ||
| 898 | /* Go through each element of the ignore list and compare it to the | 988 | /* Go through each element of the ignore list and compare it to the |
| @@ -960,14 +1050,52 @@ int log_mysql_transaction(request_rec *orig) | |||
| 960 | } | 1050 | } |
| 961 | 1051 | ||
| 962 | 1052 | ||
| 1053 | /* | ||
| 1054 | fields = pstrcat(r->pool, fields, ",note", NULL); | ||
| 1055 | values = pstrcat(r->pool, values, ",'", NULL); | ||
| 1056 | */ | ||
| 1057 | |||
| 1058 | /* Work through the list of notes defined by MySQLNotesToLog */ | ||
| 1059 | i = 0; | ||
| 1060 | unique_id = extract_unique_id(r, ""); | ||
| 1061 | |||
| 1062 | ptrptr2 = (char **) (cls->notes_list->elts + (cls->notes_list->nelts * cls->notes_list->elt_size)); | ||
| 1063 | for (ptrptr = (char **) cls->notes_list->elts; ptrptr < ptrptr2; ptrptr = (char **) ((char *) ptrptr + cls->notes_list->elt_size)) { | ||
| 1064 | /* If the specified note (*ptrptr) exists for the current request... */ | ||
| 1065 | if ((thenote = ap_table_get(r->notes, *ptrptr))) { | ||
| 1066 | notesets = ap_pstrcat(r->pool, notesets, | ||
| 1067 | (i > 0 ? "," : ""), | ||
| 1068 | "('", | ||
| 1069 | unique_id, | ||
| 1070 | "','", | ||
| 1071 | escape_query(*ptrptr, r->pool), | ||
| 1072 | "','", | ||
| 1073 | escape_query(thenote, r->pool), | ||
| 1074 | "')", | ||
| 1075 | NULL); | ||
| 1076 | i++; | ||
| 1077 | } | ||
| 1078 | } | ||
| 1079 | note_query = ap_pstrcat(r->pool, note_query, "insert into ", cls->notes_table_name, " (id, item, val) values ", notesets, NULL); | ||
| 1080 | #ifdef DEBUG | ||
| 1081 | ap_log_error(APLOG_MARK,DEBUGLEVEL,orig->server,"note string: %s", note_query); | ||
| 1082 | #endif | ||
| 1083 | |||
| 1084 | /* | ||
| 1085 | values = pstrcat(r->pool, values, "'", NULL); | ||
| 1086 | */ | ||
| 1087 | |||
| 1088 | |||
| 1089 | |||
| 963 | /* Is this virtual server's table flagged as made? We flag it as such in order | 1090 | /* Is this virtual server's table flagged as made? We flag it as such in order |
| 964 | * to avoid extra processing with each request. If it's not flagged as made, | 1091 | * to avoid extra processing with each request. If it's not flagged as made, |
| 965 | * set up the CREATE string. | 1092 | * set up the CREATE string. |
| 966 | */ | 1093 | */ |
| 967 | if ((cls->table_made != 1) && (create_tables != 0)) { | 1094 | if ((cls->table_made != 1) && (create_tables != 0)) { |
| 968 | char *createprefix = "create table if not exists "; | 1095 | char *createprefix = "create table if not exists "; |
| 969 | char *createsuffix = | 1096 | char *access_suffix = |
| 970 | " (agent varchar(255),\ | 1097 | " (id char(19),\ |
| 1098 | agent varchar(255),\ | ||
| 971 | bytes_sent int unsigned,\ | 1099 | bytes_sent int unsigned,\ |
| 972 | child_pid smallint unsigned,\ | 1100 | child_pid smallint unsigned,\ |
| 973 | cookie varchar(255),\ | 1101 | cookie varchar(255),\ |
| @@ -989,21 +1117,28 @@ int log_mysql_transaction(request_rec *orig) | |||
| 989 | status smallint unsigned,\ | 1117 | status smallint unsigned,\ |
| 990 | time_stamp int unsigned,\ | 1118 | time_stamp int unsigned,\ |
| 991 | virtual_host varchar(50))"; | 1119 | virtual_host varchar(50))"; |
| 992 | 1120 | ||
| 1121 | char *notes_suffix = | ||
| 1122 | " (id char(19),\ | ||
| 1123 | item varchar(80),\ | ||
| 1124 | val varchar(80))"; | ||
| 1125 | |||
| 993 | /* Find memory long enough to hold the whole CREATE string + \0 */ | 1126 | /* Find memory long enough to hold the whole CREATE string + \0 */ |
| 994 | createstring = ap_pstrcat(orig->pool, createprefix, cls->transfer_table_name, createsuffix, NULL); | 1127 | create_access = ap_pstrcat(orig->pool, createprefix, cls->transfer_table_name, access_suffix, NULL); |
| 1128 | create_notes = ap_pstrcat(orig->pool, createprefix, cls->notes_table_name, notes_suffix, NULL); | ||
| 995 | 1129 | ||
| 996 | #ifdef DEBUG | 1130 | #ifdef DEBUG |
| 997 | ap_log_error(APLOG_MARK,DEBUGLEVEL,orig->server,"create string: %s", createstring); | 1131 | ap_log_error(APLOG_MARK,DEBUGLEVEL,orig->server,"create string: %s", create_access); |
| 1132 | ap_log_error(APLOG_MARK,DEBUGLEVEL,orig->server,"create string: %s", create_notes); | ||
| 998 | #endif | 1133 | #endif |
| 999 | 1134 | ||
| 1000 | } | 1135 | } |
| 1001 | 1136 | ||
| 1002 | /* Set up the actual INSERT statement and escape it. */ | 1137 | /* Set up the actual INSERT statement */ |
| 1003 | str = ap_pstrcat(r->pool, "insert into ", cls->transfer_table_name, " (", fields, ") values (", values, ")", NULL); | 1138 | access_query = ap_pstrcat(r->pool, "insert into ", cls->transfer_table_name, " (", fields, ") values (", values, ")", NULL); |
| 1004 | 1139 | ||
| 1005 | #ifdef DEBUG | 1140 | #ifdef DEBUG |
| 1006 | ap_log_error(APLOG_MARK,DEBUGLEVEL,r->server,"insert string: %s", str); | 1141 | ap_log_error(APLOG_MARK,DEBUGLEVEL,r->server,"insert string: %s", access_query); |
| 1007 | #endif | 1142 | #endif |
| 1008 | 1143 | ||
| 1009 | 1144 | ||
| @@ -1017,7 +1152,8 @@ int log_mysql_transaction(request_rec *orig) | |||
| 1017 | /* Unable to re-establish a DB link, so assume that it's really | 1152 | /* Unable to re-establish a DB link, so assume that it's really |
| 1018 | * gone and send the entry to the preserve file instead. | 1153 | * gone and send the entry to the preserve file instead. |
| 1019 | * Note that we don't keep logging the db error over and over. */ | 1154 | * Note that we don't keep logging the db error over and over. */ |
| 1020 | preserve_entry(orig, str); | 1155 | preserve_entry(orig, access_query); |
| 1156 | preserve_entry(orig, note_query); | ||
| 1021 | return OK; | 1157 | return OK; |
| 1022 | } else { | 1158 | } else { |
| 1023 | /* Whew, we got the DB link back */ | 1159 | /* Whew, we got the DB link back */ |
| @@ -1027,13 +1163,15 @@ int log_mysql_transaction(request_rec *orig) | |||
| 1027 | 1163 | ||
| 1028 | /* Make the table if we're supposed to */ | 1164 | /* Make the table if we're supposed to */ |
| 1029 | if ((cls->table_made != 1) && (create_tables != 0)) { | 1165 | if ((cls->table_made != 1) && (create_tables != 0)) { |
| 1030 | mysql_query(mysql_log,createstring); | 1166 | mysql_query(mysql_log, create_access); |
| 1167 | mysql_query(mysql_log, create_notes); | ||
| 1031 | cls->table_made = 1; | 1168 | cls->table_made = 1; |
| 1032 | } | 1169 | } |
| 1033 | 1170 | ||
| 1034 | /* Make the insert */ | 1171 | /* Make the insert */ |
| 1035 | safe_mysql_query(orig, str); | 1172 | safe_mysql_query(orig, access_query); |
| 1036 | 1173 | safe_mysql_query(orig, note_query); | |
| 1174 | |||
| 1037 | return OK; | 1175 | return OK; |
| 1038 | } | 1176 | } |
| 1039 | } | 1177 | } |
