summaryrefslogtreecommitdiffstats
path: root/functions.h
diff options
context:
space:
mode:
authorGravatar Edward Rudd 2004-01-20 19:38:08 +0000
committerGravatar Edward Rudd 2004-01-20 19:38:08 +0000
commitccd1b379bfc208c34ad61fc42cac4a797af6d153 (patch)
tree572f08ed678630b4244010aadf2a7305f7c98d8a /functions.h
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 'functions.h')
-rw-r--r--functions.h337
1 files changed, 337 insertions, 0 deletions
diff --git a/functions.h b/functions.h
new file mode 100644
index 0000000..60d08b5
--- /dev/null
+++ b/functions.h
@@ -0,0 +1,337 @@
1/* $Header: /home/cvs/mod_log_sql/functions.h,v 1.1 2004/01/20 19:38:08 urkle Exp $ */
2/* Begin the individual functions that, given a request r,
3 * extract the needed information from it and return the
4 * value to the calling entity.
5 */
6
7static const char *extract_remote_host(request_rec *r, char *a)
8{
9 return (char *) ap_get_remote_host(r->connection, r->per_dir_config, REMOTE_NAME, NULL);
10}
11
12static const char *extract_remote_logname(request_rec *r, char *a)
13{
14 return (char *) ap_get_remote_logname(r);
15}
16
17static const char *extract_remote_user(request_rec *r, char *a)
18{
19 #ifdef WITH_APACHE13
20 char *rvalue = r->connection->user;
21 #else
22 char *rvalue = r->user;
23 #endif
24 if (rvalue == NULL) {
25 rvalue = "-";
26 } else if (strlen(rvalue) == 0) {
27 rvalue = "\"\"";
28 }
29 return rvalue;
30}
31
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)
43{
44 return r->the_request;
45}
46
47static const char *extract_request_file(request_rec *r, char *a)
48{
49 return r->filename;
50}
51
52static const char *extract_request_uri(request_rec *r, char *a)
53{
54 return r->uri;
55}
56
57static const char *extract_request_args(request_rec *r, char *a)
58{
59 return r->args;
60}
61
62static const char *extract_status(request_rec *r, char *a)
63{
64 if (r->status <= 0) {
65 return "-";
66 } else {
67 return apr_psprintf(r->pool, "%d", r->status);
68 }
69}
70
71static const char *extract_bytes_sent(request_rec *r, char *a)
72{
73 if (!r->sent_bodyct || !r->bytes_sent) {
74 return "-";
75 } else {
76 return apr_psprintf(r->pool, "%" APR_OFF_T_FMT, r->bytes_sent);
77 }
78}
79
80/*
81static const char *extract_header_in(request_rec *r, char *a)
82{
83 return table_get(r->headers_in, a);
84}
85
86static const char *extract_header_out(request_rec *r, char *a)
87{
88 const char *cp = table_get(r->headers_out, a);
89 if (!strcasecmp(a, "Content-type") && r->content_type) {
90 cp = r->content_type;
91 }
92 if (cp) {
93 return cp;
94 }
95 return table_get(r->err_headers_out, a);
96}
97*/
98
99static const char *extract_virtual_host(request_rec *r, char *a)
100{
101 return apr_pstrdup(r->pool, r->server->server_hostname);
102}
103
104static const char *extract_machine_id(request_rec *r, char *a)
105{
106 if (!global_config.machid)
107 return "-";
108 else
109 return global_config.machid;
110}
111
112static const char *extract_server_port(request_rec *r, char *a)
113{
114 return apr_psprintf(r->pool, "%u",
115 r->server->port ? r->server->port : ap_default_port(r));
116}
117
118static const char *extract_child_pid(request_rec *r, char *a)
119{
120 if (*a == '\0' || !strcmp(a, "pid")) {
121 return apr_psprintf(r->pool, "%" APR_PID_T_FMT, getpid());
122 }
123 else if (!strcmp(a, "tid")) {
124#if APR_HAS_THREADS
125 apr_os_thread_t tid = apr_os_thread_current();
126#else
127 int tid = 0; /* APR will format "0" anyway but an arg is needed */
128#endif
129 return apr_psprintf(r->pool, "%pT", &tid);
130 }
131 /* bogus format */
132 return a;
133}
134
135static const char *extract_referer(request_rec *r, char *a)
136{
137 const char *tempref;
138
139 tempref = apr_table_get(r->headers_in, "Referer");
140 if (!tempref)
141 {
142 return "-";
143 } else {
144 return tempref;
145 }
146}
147
148static const char *extract_agent(request_rec *r, char *a)
149{
150 const char *tempag;
151
152 tempag = apr_table_get(r->headers_in, "User-Agent");
153 if (!tempag)
154 {
155 return "-";
156 } else {
157 return tempag;
158 }
159}
160
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)
239{
240 const char *cookiestr;
241 char *cookieend;
242 char *isvalid;
243 char *cookiebuf;
244
245 if (a != NULL) {
246 #ifdef DEBUG
247 log_error(APLOG_MARK,APLOG_DEBUG,
248 r->server,"watching for cookie '%s'", a);
249 #endif
250
251 /* Fetch out the cookie header */
252 cookiestr = (char *)apr_table_get(r->headers_in, "cookie2");
253 if (cookiestr != NULL) {
254 #ifdef DEBUG
255 log_error(APLOG_MARK,APLOG_DEBUG,r->server,
256 "Cookie2: [%s]", cookiestr);
257 #endif
258 /* Does the cookie string contain one with our name? */
259 isvalid = strstr(cookiestr, a);
260 if (isvalid != NULL) {
261 /* Move past the cookie name and equal sign */
262 isvalid += strlen(a) + 1;
263 /* Duplicate it into the pool */
264 cookiebuf = apr_pstrdup(r->pool, isvalid);
265 /* Segregate just this cookie out of the string
266 * with a terminating nul at the first semicolon */
267 cookieend = strchr(cookiebuf, ';');
268 if (cookieend != NULL)
269 *cookieend = '\0';
270 return cookiebuf;
271 }
272 }
273
274 cookiestr = (char *)apr_table_get(r->headers_in, "cookie");
275 if (cookiestr != NULL) {
276 #ifdef DEBUG
277 log_error(APLOG_MARK,APLOG_DEBUG,r->server,
278 "Cookie: [%s]", cookiestr);
279 #endif
280 isvalid = strstr(cookiestr, a);
281 if (isvalid != NULL) {
282 isvalid += strlen(a) + 1;
283 cookiebuf = apr_pstrdup(r->pool, isvalid);
284 cookieend = strchr(cookiebuf, ';');
285 if (cookieend != NULL)
286 *cookieend = '\0';
287 return cookiebuf;
288 }
289 }
290
291 cookiestr = apr_table_get(r->headers_out, "set-cookie");
292 if (cookiestr != NULL) {
293 #ifdef DEBUG
294 log_error(APLOG_MARK,APLOG_DEBUG,r->server,
295 "Set-Cookie: [%s]", cookiestr);
296 #endif
297 isvalid = strstr(cookiestr, a);
298 if (isvalid != NULL) {
299 isvalid += strlen(a) + 1;
300 cookiebuf = apr_pstrdup(r->pool, isvalid);
301 cookieend = strchr(cookiebuf, ';');
302 if (cookieend != NULL)
303 *cookieend = '\0';
304 return cookiebuf;
305 }
306 }
307 }
308
309 return "-";
310}
311
312
313/*
314static const char *extract_note(request_rec *r, char *a)
315{
316 return apr_table_get(r->notes, a);
317
318}
319*/
320
321static const char *extract_env_var(request_rec *r, char *a)
322{
323 return apr_table_get(r->subprocess_env, a);
324}
325
326static const char *extract_unique_id(request_rec *r, char *a)
327{
328 const char *tempid;
329
330 tempid = apr_table_get(r->subprocess_env, "UNIQUE_ID");
331 if (!tempid)
332 return "-";
333 else
334 return tempid;
335}
336
337/* End declarations of various extract_ functions */