summaryrefslogtreecommitdiffstatsabout
path: root/functions.h
diff options
context:
space:
mode:
Diffstat (limited to 'functions.h')
-rw-r--r--functions.h182
1 files changed, 54 insertions, 128 deletions
diff --git a/functions.h b/functions.h
index 60d08b5..917a1f9 100644
--- a/functions.h
+++ b/functions.h
@@ -1,4 +1,4 @@
1/* $Header: /home/cvs/mod_log_sql/functions.h,v 1.1 2004/01/20 19:38:08 urkle Exp $ */ 1/* $Header: /home/cvs/mod_log_sql/functions.h,v 1.2 2004/02/05 21:59:46 urkle Exp $ */
2/* Begin the individual functions that, given a request r, 2/* Begin the individual functions that, given a request r,
3 * extract the needed information from it and return the 3 * extract the needed information from it and return the
4 * value to the calling entity. 4 * value to the calling entity.
@@ -9,6 +9,20 @@ static const char *extract_remote_host(request_rec *r, char *a)
9 return (char *) ap_get_remote_host(r->connection, r->per_dir_config, REMOTE_NAME, NULL); 9 return (char *) ap_get_remote_host(r->connection, r->per_dir_config, REMOTE_NAME, NULL);
10} 10}
11 11
12static const char *extract_remote_address(request_rec *r, char *a) __attribute__((unused));
13
14static const char *extract_remote_address(request_rec *r, char *a)
15{
16 return r->connection->remote_ip;
17}
18
19static const char *extract_local_address(request_rec *r, char *a) __attribute__((unused));
20
21static const char *extract_local_address(request_rec *r, char *a)
22{
23 return r->connection->local_ip;
24}
25
12static const char *extract_remote_logname(request_rec *r, char *a) 26static const char *extract_remote_logname(request_rec *r, char *a)
13{ 27{
14 return (char *) ap_get_remote_logname(r); 28 return (char *) ap_get_remote_logname(r);
@@ -29,19 +43,21 @@ static const char *extract_remote_user(request_rec *r, char *a)
29 return rvalue; 43 return rvalue;
30} 44}
31 45
32static const char *extract_request_method(request_rec *r, char *a)
33{
34 return r->method;
35}
36
37static const char *extract_request_protocol(request_rec *r, char *a)
38{
39 return r->protocol;
40}
41
42static const char *extract_request_line(request_rec *r, char *a) 46static const char *extract_request_line(request_rec *r, char *a)
43{ 47{
44 return r->the_request; 48 /* Upddated to mod_log_config logic */
49 /* NOTE: If the original request contained a password, we
50 * re-write the request line here to contain XXXXXX instead:
51 * (note the truncation before the protocol string for HTTP/0.9 requests)
52 * (note also that r->the_request contains the unmodified request)
53 */
54 return (r->parsed_uri.password)
55 ? apr_pstrcat(r->pool, r->method, " ",
56 apr_uri_unparse(r->pool,
57 &r->parsed_uri, 0),
58 r->assbackwards ? NULL : " ",
59 r->protocol, NULL)
60 : r->the_request;
45} 61}
46 62
47static const char *extract_request_file(request_rec *r, char *a) 63static const char *extract_request_file(request_rec *r, char *a)
@@ -54,47 +70,31 @@ static const char *extract_request_uri(request_rec *r, char *a)
54 return r->uri; 70 return r->uri;
55} 71}
56 72
57static const char *extract_request_args(request_rec *r, char *a) 73static const char *extract_request_method(request_rec *r, char *a)
58{
59 return r->args;
60}
61
62static const char *extract_status(request_rec *r, char *a)
63{ 74{
64 if (r->status <= 0) { 75 return r->method;
65 return "-";
66 } else {
67 return apr_psprintf(r->pool, "%d", r->status);
68 }
69} 76}
70 77
71static const char *extract_bytes_sent(request_rec *r, char *a) 78static const char *extract_request_protocol(request_rec *r, char *a)
72{ 79{
73 if (!r->sent_bodyct || !r->bytes_sent) { 80 return r->protocol;
74 return "-";
75 } else {
76 return apr_psprintf(r->pool, "%" APR_OFF_T_FMT, r->bytes_sent);
77 }
78} 81}
79 82
80/* 83static const char *extract_request_query(request_rec *r, char *a)
81static const char *extract_header_in(request_rec *r, char *a)
82{ 84{
83 return table_get(r->headers_in, a); 85 return (r->args) ? apr_pstrcat(r->pool, "?",
86 r->args, NULL)
87 : "";
84} 88}
85 89
86static const char *extract_header_out(request_rec *r, char *a) 90static const char *extract_status(request_rec *r, char *a)
87{ 91{
88 const char *cp = table_get(r->headers_out, a); 92 if (r->status <= 0) {
89 if (!strcasecmp(a, "Content-type") && r->content_type) { 93 return "-";
90 cp = r->content_type; 94 } else {
91 } 95 return apr_psprintf(r->pool, "%d", r->status);
92 if (cp) {
93 return cp;
94 } 96 }
95 return table_get(r->err_headers_out, a);
96} 97}
97*/
98 98
99static const char *extract_virtual_host(request_rec *r, char *a) 99static const char *extract_virtual_host(request_rec *r, char *a)
100{ 100{
@@ -115,6 +115,15 @@ static const char *extract_server_port(request_rec *r, char *a)
115 r->server->port ? r->server->port : ap_default_port(r)); 115 r->server->port ? r->server->port : ap_default_port(r));
116} 116}
117 117
118/* This respects the setting of UseCanonicalName so that
119 * the dynamic mass virtual hosting trick works better.
120 */
121static const char *log_server_name(request_rec *r, char *a) __attribute__((unused));
122static const char *log_server_name(request_rec *r, char *a)
123{
124 return ap_get_server_name(r);
125}
126
118static const char *extract_child_pid(request_rec *r, char *a) 127static const char *extract_child_pid(request_rec *r, char *a)
119{ 128{
120 if (*a == '\0' || !strcmp(a, "pid")) { 129 if (*a == '\0' || !strcmp(a, "pid")) {
@@ -158,83 +167,6 @@ static const char *extract_agent(request_rec *r, char *a)
158 } 167 }
159} 168}
160 169
161static const char *extract_cookie(request_rec *r, char *a)
162{
163 const char *cookiestr;
164 char *cookieend;
165 char *isvalid;
166 char *cookiebuf;
167
168 logsql_state *cls = ap_get_module_config(r->server->module_config,
169 &log_sql_module);
170
171 if (cls->cookie_name != NULL) {
172 #ifdef DEBUG
173 log_error(APLOG_MARK,APLOG_DEBUG, r->server,
174 "watching for cookie '%s'", cls->cookie_name);
175 #endif
176
177 /* Fetch out the cookie header */
178 cookiestr = (char *)apr_table_get(r->headers_in, "cookie2");
179 if (cookiestr != NULL) {
180 #ifdef DEBUG
181 log_error(APLOG_MARK,APLOG_DEBUG, r->server,
182 "Cookie2: [%s]", cookiestr);
183 #endif
184 /* Does the cookie string contain one with our name? */
185 isvalid = strstr(cookiestr, cls->cookie_name);
186 if (isvalid != NULL) {
187 /* Move past the cookie name and equal sign */
188 isvalid += strlen(cls->cookie_name) + 1;
189 /* Duplicate it into the pool */
190 cookiebuf = apr_pstrdup(r->pool, isvalid);
191 /* Segregate just this cookie out of the string
192 * with a terminating nul at the first semicolon */
193 cookieend = strchr(cookiebuf, ';');
194 if (cookieend != NULL)
195 *cookieend = '\0';
196 return cookiebuf;
197 }
198 }
199
200 cookiestr = (char *)apr_table_get(r->headers_in, "cookie");
201 if (cookiestr != NULL) {
202 #ifdef DEBUG
203 log_error(APLOG_MARK,APLOG_DEBUG,r->server,
204 "Cookie: [%s]", cookiestr);
205 #endif
206 isvalid = strstr(cookiestr, cls->cookie_name);
207 if (isvalid != NULL) {
208 isvalid += strlen(cls->cookie_name) + 1;
209 cookiebuf = apr_pstrdup(r->pool, isvalid);
210 cookieend = strchr(cookiebuf, ';');
211 if (cookieend != NULL)
212 *cookieend = '\0';
213 return cookiebuf;
214 }
215 }
216
217 cookiestr = apr_table_get(r->headers_out, "set-cookie");
218 if (cookiestr != NULL) {
219 #ifdef DEBUG
220 log_error(APLOG_MARK,APLOG_DEBUG,r->server,
221 "Set-Cookie: [%s]", cookiestr);
222 #endif
223 isvalid = strstr(cookiestr, cls->cookie_name);
224 if (isvalid != NULL) {
225 isvalid += strlen(cls->cookie_name) + 1;
226 cookiebuf = apr_pstrdup(r->pool, isvalid);
227 cookieend = strchr(cookiebuf, ';');
228 if (cookieend != NULL)
229 *cookieend = '\0';
230 return cookiebuf;
231 }
232 }
233 }
234
235 return "-";
236}
237
238static const char *extract_specific_cookie(request_rec *r, char *a) 170static const char *extract_specific_cookie(request_rec *r, char *a)
239{ 171{
240 const char *cookiestr; 172 const char *cookiestr;
@@ -309,18 +241,12 @@ static const char *extract_specific_cookie(request_rec *r, char *a)
309 return "-"; 241 return "-";
310} 242}
311 243
312 244static const char *extract_cookie(request_rec *r, char *a)
313/*
314static const char *extract_note(request_rec *r, char *a)
315{ 245{
316 return apr_table_get(r->notes, a); 246 logsql_state *cls = ap_get_module_config(r->server->module_config,
317 247 &log_sql_module);
318}
319*/
320 248
321static const char *extract_env_var(request_rec *r, char *a) 249 return extract_specific_cookie(r, (char *)cls->cookie_name);
322{
323 return apr_table_get(r->subprocess_env, a);
324} 250}
325 251
326static const char *extract_unique_id(request_rec *r, char *a) 252static const char *extract_unique_id(request_rec *r, char *a)