Apache HTTPD
mod_log_debug.c
Go to the documentation of this file.
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "apr_strings.h"
18
19#include "httpd.h"
20#include "http_config.h"
21#include "http_log.h"
22#include "http_protocol.h"
23#include "http_request.h"
24#include "ap_expr.h"
25
26extern module AP_MODULE_DECLARE_DATA log_debug_module;
27
33
37
38static const char *allhooks = "all";
39static const char * const hooks[] = {
40 "log_transaction", /* 0 */
41 "quick_handler", /* 1 */
42 "handler", /* 2 */
43 "translate_name", /* 3 */
44 "map_to_storage", /* 4 */
45 "fixups", /* 5 */
46 "type_checker", /* 6 */
47 "check_access", /* 7 */
48 "check_access_ex", /* 8 */
49 "check_authn", /* 9 */
50 "check_authz", /* 10 */
51 "insert_filter", /* 11 */
52 "pre_translate_name", /* 12 */
53 NULL
54};
55
56static void do_debug_log(request_rec *r, const char *hookname)
57{
58 log_debug_dirconf *dconf = ap_get_module_config(r->per_dir_config, &log_debug_module);
59 int i;
60 if (dconf->entries == NULL)
61 return;
62
63 for (i = 0; i < dconf->entries->nelts; i++) {
64 const char *msg, *err;
65 msg_entry *entry = APR_ARRAY_IDX(dconf->entries, i, msg_entry *);
66 if (entry->hook != allhooks && entry->hook != hookname)
67 continue;
68 if (entry->condition) {
69 int ret = ap_expr_exec(r, entry->condition, &err);
70 if (err) {
72 "Can't evaluate condition: %s", err);
73 continue;
74 }
75 if (!ret)
76 continue;
77 }
78 msg = ap_expr_str_exec(r, entry->msg_expr, &err);
79 if (err)
81 "Can't evaluate message expression: %s", err);
82 if (APLOGrdebug(r))
83 /* Intentional no APLOGNO */
85 "%s (%s hook, %s:%d)",
86 msg, hookname, entry->msg_expr->filename,
87 entry->msg_expr->line_number);
88 else
89 /* Intentional no APLOGNO */
91 "%s", msg);
92 }
93}
94
96{
97 do_debug_log(r, hooks[0]);
98 return DECLINED;
99}
100
102{
103 do_debug_log(r, hooks[1]);
104 return DECLINED;
105}
106
108{
109 do_debug_log(r, hooks[2]);
110 return DECLINED;
111}
112
114{
115 do_debug_log(r, hooks[12]);
116 return DECLINED;
117}
118
120{
121 do_debug_log(r, hooks[3]);
122 return DECLINED;
123}
124
126{
127 do_debug_log(r, hooks[4]);
128 return DECLINED;
129}
130
132{
133 do_debug_log(r, hooks[5]);
134 return DECLINED;
135}
136
138{
139 do_debug_log(r, hooks[6]);
140 return DECLINED;
141}
142
144{
145 do_debug_log(r, hooks[7]);
146 return DECLINED;
147}
148
150{
151 do_debug_log(r, hooks[8]);
152 return DECLINED;
153}
154
156{
157 do_debug_log(r, hooks[9]);
158 return DECLINED;
159}
160
162{
163 do_debug_log(r, hooks[10]);
164 return DECLINED;
165}
166
168{
169 do_debug_log(r, hooks[11]);
170}
171
173{
175 return dconf;
176}
177
179{
182 const log_debug_dirconf *new = new_conf;
183
184 if (parent->entries == NULL)
185 merged->entries = new->entries;
186 else if (new->entries == NULL)
187 merged->entries = parent->entries;
188 else
189 /* apr_array_append actually creates a new array */
190 merged->entries = apr_array_append(p, parent->entries, new->entries);
191
192 return merged;
193}
194
195static const char *cmd_log_message(cmd_parms *cmd, void *dconf_, const char *arg1,
196 const char *arg2, const char *arg3)
197{
198 msg_entry *entry = apr_pcalloc(cmd->pool, sizeof(msg_entry));
199 log_debug_dirconf *dconf = dconf_;
200 int i, j;
201 const char *err;
202 const char *args[2];
203 args[0] = arg2;
204 args[1] = arg3;
205
208 &err, NULL);
209 if (err)
210 return apr_psprintf(cmd->pool,
211 "Could not parse message expression '%s': %s",
212 arg1, err);
213
214 for (i = 0; i < 2; i++) {
215 if (args[i] == NULL)
216 break;
217
218 if (strncasecmp(args[i], "hook=", 5) == 0) {
219 const char *name = args[i] + 5;
220 j = 0;
221 while (hooks[j]) {
222 if (strcasecmp(hooks[j], name) == 0) {
223 entry->hook = hooks[j];
224 break;
225 }
226 j++;
227 }
228 if (entry->hook == NULL) {
229 if (strcmp(name, "*") == 0 || strcasecmp(name, allhooks) == 0)
230 entry->hook = allhooks;
231 else
232 return apr_psprintf(cmd->pool, "Invalid hook name: %s", name);
233 }
234 }
235 else if (strncasecmp(args[i], "expr=", 5) == 0) {
236 const char *expr = args[i] + 5;
237 entry->condition = ap_expr_parse_cmd(cmd, expr,
239 &err, NULL);
240 if (err)
241 return apr_psprintf(cmd->pool,
242 "Could not parse expression '%s': %s",
243 expr, err);
244 }
245 else {
246 return apr_psprintf(cmd->pool, "Invalid argument %s", args[i]);
247 }
248 }
249 if (entry->hook == NULL)
250 entry->hook = hooks[0];
251
252 if (!dconf->entries)
253 dconf->entries = apr_array_make(cmd->pool, 4, sizeof(msg_entry *));
254
255 APR_ARRAY_PUSH(dconf->entries, msg_entry *) = entry;
256
257 return NULL;
258}
259
261{
263 "Log a debug message to the error log if this config block is used for "
264 " a request"),
265 {NULL}
266};
267
284
286{
288 log_debug_create_dconf, /* create per-dir config */
289 log_debug_merge_dconf, /* merge per-dir config */
290 NULL, /* server config */
291 NULL, /* merge server config */
292 log_debug_cmds, /* command apr_table_t */
293 register_hooks /* register hooks */
294};
295
Expression parser.
APR Strings library.
apr_array_append(apr_pool_t *p, const apr_array_header_t *first, const apr_array_header_t *second)
Definition apr_tables.c:213
#define AP_INIT_TAKE123(directive, func, mconfig, where, help)
#define ap_get_module_config(v, m)
#define AP_DECLARE_MODULE(foo)
void ap_hook_quick_handler(ap_HOOK_quick_handler_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
Definition config.c:173
void ap_hook_handler(ap_HOOK_handler_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
Definition config.c:170
request_rec * r
ap_conf_vector_t ap_conf_vector_t * new_conf
#define DECLINED
Definition httpd.h:457
#define APLOGNO(n)
Definition http_log.h:117
#define APLOGrdebug(r)
Definition http_log.h:245
#define APLOG_INFO
Definition http_log.h:70
#define ap_log_rerror
Definition http_log.h:454
#define APLOG_ERR
Definition http_log.h:67
#define APLOG_MARK
Definition http_log.h:283
void ap_hook_log_transaction(ap_HOOK_log_transaction_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
Definition protocol.c:2587
#define AP_AUTH_INTERNAL_PER_URI
void ap_hook_pre_translate_name(ap_HOOK_pre_translate_name_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
Definition request.c:79
void ap_hook_check_access_ex(ap_HOOK_access_checker_ex_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder, int type)
Definition request.c:2206
void ap_hook_check_access(ap_HOOK_access_checker_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder, int type)
Definition request.c:2194
void ap_hook_translate_name(ap_HOOK_translate_name_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
Definition request.c:81
void ap_hook_map_to_storage(ap_HOOK_map_to_storage_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
Definition request.c:83
void ap_hook_fixups(ap_HOOK_fixups_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
Definition request.c:87
void ap_hook_type_checker(ap_HOOK_type_checker_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
Definition request.c:89
void ap_hook_check_authn(ap_HOOK_check_user_id_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder, int type)
Definition request.c:2218
void ap_hook_insert_filter(ap_HOOK_insert_filter_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder)
Definition request.c:96
void ap_hook_check_authz(ap_HOOK_auth_checker_t *pf, const char *const *aszPre, const char *const *aszSucc, int nOrder, int type)
Definition request.c:2230
#define APR_HOOK_FIRST
Definition apr_hooks.h:301
#define AP_EXPR_FLAG_DONT_VARY
Definition ap_expr.h:61
#define AP_EXPR_FLAG_STRING_RESULT
Definition ap_expr.h:68
#define ap_expr_parse_cmd(cmd, expr, flags, err, lookup_fn)
Definition ap_expr.h:340
int ap_expr_exec(request_rec *r, const ap_expr_info_t *expr, const char **err)
const char * ap_expr_str_exec(request_rec *r, const ap_expr_info_t *expr, const char **err)
#define ACCESS_CONF
#define RSRC_CONF
#define STANDARD20_MODULE_STUFF
apr_size_t size
int strcasecmp(const char *a, const char *b)
int strncasecmp(const char *a, const char *b, size_t n)
apr_pool_t * parent
Definition apr_pools.h:197
#define apr_pcalloc(p, size)
Definition apr_pools.h:465
#define APR_ARRAY_PUSH(ary, type)
Definition apr_tables.h:150
#define APR_ARRAY_IDX(ary, i, type)
Definition apr_tables.h:141
apr_int32_t apr_int32_t apr_int32_t err
apr_cmdtype_e cmd
const char const char *const * args
Apache Configuration.
Apache Logging library.
HTTP protocol handling.
Apache Request library.
HTTP Daemon routines.
apr_pool_t * p
Definition md_event.c:32
static void * log_debug_create_dconf(apr_pool_t *p, char *dirspec)
static int log_debug_check_access(request_rec *r)
static int log_debug_handler(request_rec *r)
static const command_rec log_debug_cmds[]
static const char * allhooks
static void do_debug_log(request_rec *r, const char *hookname)
static int log_debug_check_access_ex(request_rec *r)
static int log_debug_check_authn(request_rec *r)
static int log_debug_log_transaction(request_rec *r)
static int log_debug_check_authz(request_rec *r)
static int log_debug_quick_handler(request_rec *r, int lookup_uri)
static void * log_debug_merge_dconf(apr_pool_t *p, void *parent_conf, void *new_conf)
static void register_hooks(apr_pool_t *p)
static int log_debug_translate_name(request_rec *r)
static int log_debug_map_to_storage(request_rec *r)
static const char *const hooks[]
static int log_debug_pre_translate_name(request_rec *r)
static const char * cmd_log_message(cmd_parms *cmd, void *dconf_, const char *arg1, const char *arg2, const char *arg3)
static int log_debug_fixups(request_rec *r)
static int log_debug_type_checker(request_rec *r)
static void log_debug_insert_filter(request_rec *r)
return NULL
Definition mod_so.c:359
int i
Definition mod_so.c:347
char * name
unsigned int line_number
Definition ap_expr.h:49
const char * filename
Definition ap_expr.h:47
apr_array_header_t * entries
ap_expr_info_t * msg_expr
ap_expr_info_t * condition
const char * hook
A structure that represents the current request.
Definition httpd.h:845
struct ap_conf_vector_t * per_dir_config
Definition httpd.h:1047