summaryrefslogtreecommitdiffstatsabout
path: root/mod_log_sql.c
diff options
context:
space:
mode:
authorEdward Rudd <urkle@outoforder.cc>2004-01-20 19:38:08 (GMT)
committer Edward Rudd <urkle@outoforder.cc>2004-01-20 19:38:08 (GMT)
commitccd1b379bfc208c34ad61fc42cac4a797af6d153 (patch)
tree572f08ed678630b4244010aadf2a7305f7c98d8a /mod_log_sql.c
parent40f0c8fe04858acd724d6221dbf8a357259e5d6b (diff)
moved extract_* functions to functions.h (version specific in functions(13|20).h)
moves SSL logging routings to mod_log_sql_ssl.c updated changelog added AUTHORS
Diffstat (limited to 'mod_log_sql.c')
-rw-r--r--mod_log_sql.c428
1 files changed, 5 insertions, 423 deletions
diff --git a/mod_log_sql.c b/mod_log_sql.c
index 02d5fd4..1ce4a44 100644
--- a/mod_log_sql.c
+++ b/mod_log_sql.c
@@ -1,4 +1,4 @@
1/* $Header: /home/cvs/mod_log_sql/mod_log_sql.c,v 1.7 2004/01/20 16:27:34 urkle Exp $ */ 1/* $Header: /home/cvs/mod_log_sql/mod_log_sql.c,v 1.8 2004/01/20 19:38:08 urkle Exp $ */
2/* --------* 2/* --------*
3 * DEFINES * 3 * DEFINES *
4 * --------*/ 4 * --------*/
@@ -44,11 +44,6 @@
44#endif 44#endif
45 45
46 46
47#ifdef WANT_SSL_LOGGING
48#include "mod_ssl.h"
49#endif
50
51
52/* Configuratino Defaults */ 47/* Configuratino Defaults */
53#define DEFAULT_TRANSFER_LOG_FMT "AbHhmRSsTUuv" 48#define DEFAULT_TRANSFER_LOG_FMT "AbHhmRSsTUuv"
54#define DEFAULT_NOTES_TABLE_NAME "notes" 49#define DEFAULT_NOTES_TABLE_NAME "notes"
@@ -121,420 +116,13 @@ typedef struct {
121 116
122static int safe_create_tables(logsql_state *cls, request_rec *r); 117static int safe_create_tables(logsql_state *cls, request_rec *r);
123 118
124static char *format_integer(apr_pool_t *p, int i) 119/* Include all the extract functions */
125{ 120#include "functions.h"
126 char dummy[40];
127 apr_snprintf(dummy, sizeof(dummy), "%d", i);
128 return apr_pstrdup(p, dummy);
129}
130
131static char *pfmt(apr_pool_t *p, int i)
132{
133 if (i <= 0) {
134 return "-";
135 } else {
136 return format_integer(p, i);
137 }
138}
139
140/* Begin the individual functions that, given a request r,
141 * extract the needed information from it and return the
142 * value to the calling entity.
143 */
144
145static const char *extract_remote_host(request_rec *r, char *a)
146{
147 return (char *) ap_get_remote_host(r->connection, r->per_dir_config, REMOTE_NAME, NULL);
148}
149
150static const char *extract_remote_logname(request_rec *r, char *a)
151{
152 return (char *) ap_get_remote_logname(r);
153}
154
155static const char *extract_remote_user(request_rec *r, char *a)
156{
157 #ifdef WITH_APACHE13
158 char *rvalue = r->connection->user;
159 #else
160 char *rvalue = r->user;
161 #endif
162 if (rvalue == NULL) {
163 rvalue = "-";
164 } else if (strlen(rvalue) == 0) {
165 rvalue = "\"\"";
166 }
167 return rvalue;
168}
169
170#ifdef WANT_SSL_LOGGING
171static const char *extract_ssl_keysize(request_rec *r, char *a)
172{
173 char *result = NULL;
174 SSLConnRec *scc = myConnConfig(r->connection);
175 SSLSrvConfigRec *ssc = mySrvConfig(r->server);
176
177 if (myCtxConfig(scc,ssc) != NULL) {
178 result = ssl_var_lookup(r->pool, r->server, r->connection, r, "SSL_CIPHER_USEKEYSIZE");
179 #ifdef DEBUG
180 log_error(APLOG_MARK,APLOG_DEBUG,0,r->server,"SSL_KEYSIZE: %s", result);
181 #endif
182 if (result != NULL && result[0] == '\0')
183 result = NULL;
184 return result;
185 } else {
186 return "0";
187 }
188}
189
190static const char *extract_ssl_maxkeysize(request_rec *r, char *a)
191{
192 char *result = NULL;
193 SSLConnRec *scc = myConnConfig(r->connection);
194 SSLSrvConfigRec *ssc = mySrvConfig(r->server);
195
196 if (myCtxConfig(scc,ssc) != NULL) {
197 result = ssl_var_lookup(r->pool, r->server, r->connection, r, "SSL_CIPHER_ALGKEYSIZE");
198 #ifdef DEBUG
199 log_error(APLOG_MARK,APLOG_DEBUG,0,r->server,"SSL_ALGKEYSIZE: %s", result);
200 #endif
201 if (result != NULL && result[0] == '\0')
202 result = NULL;
203 return result;
204 } else {
205 return "0";
206 }
207}
208
209static const char *extract_ssl_cipher(request_rec *r, char *a)
210{
211 char *result = NULL;
212 SSLConnRec *scc = myConnConfig(r->connection);
213 SSLSrvConfigRec *ssc = mySrvConfig(r->server);
214
215 if (myCtxConfig(scc,ssc) != NULL) {
216 result = ssl_var_lookup(r->pool, r->server, r->connection, r, "SSL_CIPHER");
217 #ifdef DEBUG
218 log_error(APLOG_MARK,APLOG_DEBUG,0,r->server,"SSL_CIPHER: %s", result);
219 #endif
220 if (result != NULL && result[0] == '\0')
221 result = NULL;
222 return result;
223 } else {
224 return "-";
225 }
226}
227#endif /* WANT_SSL_LOGGING */
228
229static const char *extract_request_method(request_rec *r, char *a)
230{
231 return r->method;
232}
233
234static const char *extract_request_protocol(request_rec *r, char *a)
235{
236 return r->protocol;
237}
238
239static const char *extract_request_line(request_rec *r, char *a)
240{
241 return r->the_request;
242}
243
244static const char *extract_request_file(request_rec *r, char *a)
245{
246 return r->filename;
247}
248
249static const char *extract_request_uri(request_rec *r, char *a)
250{
251 return r->uri;
252}
253
254static const char *extract_request_args(request_rec *r, char *a)
255{
256 return r->args;
257}
258
259static const char *extract_status(request_rec *r, char *a)
260{
261 return pfmt(r->pool, r->status);
262}
263
264static const char *extract_bytes_sent(request_rec *r, char *a)
265{
266 if (!r->sent_bodyct || !r->bytes_sent) {
267 return "-";
268 } else {
269 return apr_psprintf(r->pool, "%" APR_OFF_T_FMT, r->bytes_sent);
270 }
271}
272
273/*
274static const char *extract_header_in(request_rec *r, char *a)
275{
276 return table_get(r->headers_in, a);
277}
278
279static const char *extract_header_out(request_rec *r, char *a)
280{
281 const char *cp = table_get(r->headers_out, a);
282 if (!strcasecmp(a, "Content-type") && r->content_type) {
283 cp = r->content_type;
284 }
285 if (cp) {
286 return cp;
287 }
288 return table_get(r->err_headers_out, a);
289}
290*/
291
292#if defined(WITH_APACHE13) 121#if defined(WITH_APACHE13)
293#include "functions13.h" 122# include "functions13.h"
294#elif defined(WITH_APACHE20) 123#elif defined(WITH_APACHE20)
295#include "functions20.h" 124# include "functions20.h"
296#endif 125#endif
297static const char *extract_virtual_host(request_rec *r, char *a)
298{
299 return apr_pstrdup(r->pool, r->server->server_hostname);
300}
301
302static const char *extract_machine_id(request_rec *r, char *a)
303{
304 if (!global_config.machid)
305 return "-";
306 else
307 return global_config.machid;
308}
309
310static const char *extract_server_port(request_rec *r, char *a)
311{
312 return apr_psprintf(r->pool, "%u",
313 r->server->port ? r->server->port : ap_default_port(r));
314}
315
316static const char *extract_child_pid(request_rec *r, char *a)
317{
318 if (*a == '\0' || !strcmp(a, "pid")) {
319 return apr_psprintf(r->pool, "%" APR_PID_T_FMT, getpid());
320 }
321 else if (!strcmp(a, "tid")) {
322#if APR_HAS_THREADS
323 apr_os_thread_t tid = apr_os_thread_current();
324#else
325 int tid = 0; /* APR will format "0" anyway but an arg is needed */
326#endif
327 return apr_psprintf(r->pool, "%pT", &tid);
328 }
329 /* bogus format */
330 return a;
331}
332
333static const char *extract_referer(request_rec *r, char *a)
334{
335 const char *tempref;
336
337 tempref = apr_table_get(r->headers_in, "Referer");
338 if (!tempref)
339 {
340 return "-";
341 } else {
342 return tempref;
343 }
344}
345
346static const char *extract_agent(request_rec *r, char *a)
347{
348 const char *tempag;
349
350 tempag = apr_table_get(r->headers_in, "User-Agent");
351 if (!tempag)
352 {
353 return "-";
354 } else {
355 return tempag;
356 }
357}
358
359static const char *extract_cookie(request_rec *r, char *a)
360{
361 const char *cookiestr;
362 char *cookieend;
363 char *isvalid;
364 char *cookiebuf;
365
366 logsql_state *cls = ap_get_module_config(r->server->module_config,
367 &log_sql_module);
368
369 if (cls->cookie_name != NULL) {
370 #ifdef DEBUG
371 log_error(APLOG_MARK,APLOG_DEBUG, r->server,
372 "watching for cookie '%s'", cls->cookie_name);
373 #endif
374
375 /* Fetch out the cookie header */
376 cookiestr = (char *)apr_table_get(r->headers_in, "cookie2");
377 if (cookiestr != NULL) {
378 #ifdef DEBUG
379 log_error(APLOG_MARK,APLOG_DEBUG, r->server,
380 "Cookie2: [%s]", cookiestr);
381 #endif
382 /* Does the cookie string contain one with our name? */
383 isvalid = strstr(cookiestr, cls->cookie_name);
384 if (isvalid != NULL) {
385 /* Move past the cookie name and equal sign */
386 isvalid += strlen(cls->cookie_name) + 1;
387 /* Duplicate it into the pool */
388 cookiebuf = apr_pstrdup(r->pool, isvalid);
389 /* Segregate just this cookie out of the string
390 * with a terminating nul at the first semicolon */
391 cookieend = strchr(cookiebuf, ';');
392 if (cookieend != NULL)
393 *cookieend = '\0';
394 return cookiebuf;
395 }
396 }
397
398 cookiestr = (char *)apr_table_get(r->headers_in, "cookie");
399 if (cookiestr != NULL) {
400 #ifdef DEBUG
401 log_error(APLOG_MARK,APLOG_DEBUG,r->server,
402 "Cookie: [%s]", cookiestr);
403 #endif
404 isvalid = strstr(cookiestr, cls->cookie_name);
405 if (isvalid != NULL) {
406 isvalid += strlen(cls->cookie_name) + 1;
407 cookiebuf = apr_pstrdup(r->pool, isvalid);
408 cookieend = strchr(cookiebuf, ';');
409 if (cookieend != NULL)
410 *cookieend = '\0';
411 return cookiebuf;
412 }
413 }
414
415 cookiestr = apr_table_get(r->headers_out, "set-cookie");
416 if (cookiestr != NULL) {
417 #ifdef DEBUG
418 log_error(APLOG_MARK,APLOG_DEBUG,r->server,
419 "Set-Cookie: [%s]", cookiestr);
420 #endif
421 isvalid = strstr(cookiestr, cls->cookie_name);
422 if (isvalid != NULL) {
423 isvalid += strlen(cls->cookie_name) + 1;
424 cookiebuf = apr_pstrdup(r->pool, isvalid);
425 cookieend = strchr(cookiebuf, ';');
426 if (cookieend != NULL)
427 *cookieend = '\0';
428 return cookiebuf;
429 }
430 }
431 }
432
433 return "-";
434}
435
436static const char *extract_specific_cookie(request_rec *r, char *a)
437{
438 const char *cookiestr;
439 char *cookieend;
440 char *isvalid;
441 char *cookiebuf;
442
443 if (a != NULL) {
444 #ifdef DEBUG
445 log_error(APLOG_MARK,APLOG_DEBUG,
446 r->server,"watching for cookie '%s'", a);
447 #endif
448
449 /* Fetch out the cookie header */
450 cookiestr = (char *)apr_table_get(r->headers_in, "cookie2");
451 if (cookiestr != NULL) {
452 #ifdef DEBUG
453 log_error(APLOG_MARK,APLOG_DEBUG,r->server,
454 "Cookie2: [%s]", cookiestr);
455 #endif
456 /* Does the cookie string contain one with our name? */
457 isvalid = strstr(cookiestr, a);
458 if (isvalid != NULL) {
459 /* Move past the cookie name and equal sign */
460 isvalid += strlen(a) + 1;
461 /* Duplicate it into the pool */
462 cookiebuf = apr_pstrdup(r->pool, isvalid);
463 /* Segregate just this cookie out of the string
464 * with a terminating nul at the first semicolon */
465 cookieend = strchr(cookiebuf, ';');
466 if (cookieend != NULL)
467 *cookieend = '\0';
468 return cookiebuf;
469 }
470 }
471
472 cookiestr = (char *)apr_table_get(r->headers_in, "cookie");
473 if (cookiestr != NULL) {
474 #ifdef DEBUG
475 log_error(APLOG_MARK,APLOG_DEBUG,r->server,
476 "Cookie: [%s]", cookiestr);
477 #endif
478 isvalid = strstr(cookiestr, a);
479 if (isvalid != NULL) {
480 isvalid += strlen(a) + 1;
481 cookiebuf = apr_pstrdup(r->pool, isvalid);
482 cookieend = strchr(cookiebuf, ';');
483 if (cookieend != NULL)
484 *cookieend = '\0';
485 return cookiebuf;
486 }
487 }
488
489 cookiestr = apr_table_get(r->headers_out, "set-cookie");
490 if (cookiestr != NULL) {
491 #ifdef DEBUG
492 log_error(APLOG_MARK,APLOG_DEBUG,r->server,
493 "Set-Cookie: [%s]", cookiestr);
494 #endif
495 isvalid = strstr(cookiestr, a);
496 if (isvalid != NULL) {
497 isvalid += strlen(a) + 1;
498 cookiebuf = apr_pstrdup(r->pool, isvalid);
499 cookieend = strchr(cookiebuf, ';');
500 if (cookieend != NULL)
501 *cookieend = '\0';
502 return cookiebuf;
503 }
504 }
505 }
506
507 return "-";
508}
509
510
511/*
512static const char *extract_note(request_rec *r, char *a)
513{
514 return apr_table_get(r->notes, a);
515
516}
517*/
518
519static const char *extract_env_var(request_rec *r, char *a)
520{
521 return apr_table_get(r->subprocess_env, a);
522}
523
524static const char *extract_unique_id(request_rec *r, char *a)
525{
526 const char *tempid;
527
528 tempid = apr_table_get(r->subprocess_env, "UNIQUE_ID");
529 if (!tempid)
530 return "-";
531 else
532 return tempid;
533}
534
535/* End declarations of various extract_ functions */
536
537
538 126
539struct log_sql_item_list { 127struct log_sql_item_list {
540 char ch; /* its letter code */ 128 char ch; /* its letter code */
@@ -567,15 +155,9 @@ struct log_sql_item_list {
567 { 'u', extract_remote_user, "remote_user", 0, 1 }, 155 { 'u', extract_remote_user, "remote_user", 0, 1 },
568 { 'U', extract_request_uri, "request_uri", 1, 1 }, 156 { 'U', extract_request_uri, "request_uri", 1, 1 },
569 { 'v', extract_virtual_host, "virtual_host", 0, 1 }, 157 { 'v', extract_virtual_host, "virtual_host", 0, 1 },
570 #ifdef WANT_SSL_LOGGING
571 { 'q', extract_ssl_keysize, "ssl_keysize", 0, 1 },
572 { 'Q', extract_ssl_maxkeysize, "ssl_maxkeysize", 0, 1 },
573 { 'z', extract_ssl_cipher, "ssl_cipher", 0, 1 },
574 #endif
575 {'\0'} 158 {'\0'}
576}; 159};
577 160
578
579/* Routine to escape the 'dangerous' characters that would otherwise 161/* Routine to escape the 'dangerous' characters that would otherwise
580 * corrupt the INSERT string: ', \, and " 162 * corrupt the INSERT string: ', \, and "
581 */ 163 */