]> granicus.if.org Git - apache/blob - server/util_debug.c
config: follow up to r1809302.
[apache] / server / util_debug.c
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 #define APR_WANT_STRFUNC
18 #include "apr_want.h"
19
20 #include "httpd.h"
21 #include "http_config.h"
22 #include "http_core.h"
23
24 /* Possibly get rid of the macros we defined in httpd.h */
25 #if defined(strchr)
26 #undef strchr
27 #endif
28
29 #if defined (strrchr)
30 #undef strrchr
31 #endif
32
33 #if defined (strstr)
34 #undef strstr
35 #endif
36
37
38 #if defined(ap_strchr)
39 #undef ap_strchr
40 AP_DECLARE(char *) ap_strchr(char *s, int c);
41 #endif
42
43 AP_DECLARE(char *) ap_strchr(char *s, int c)
44 {
45     return strchr(s,c);
46 }
47
48 #if defined(ap_strchr_c)
49 #undef ap_strchr_c
50 AP_DECLARE(const char *) ap_strchr_c(const char *s, int c);
51 #endif
52
53 AP_DECLARE(const char *) ap_strchr_c(const char *s, int c)
54 {
55     return strchr(s,c);
56 }
57
58 #if defined(ap_strrchr)
59 #undef ap_strrchr
60 AP_DECLARE(char *) ap_strrchr(char *s, int c);
61 #endif
62
63 AP_DECLARE(char *) ap_strrchr(char *s, int c)
64 {
65     return strrchr(s,c);
66 }
67
68 #if defined(ap_strrchr_c)
69 #undef ap_strrchr_c
70 AP_DECLARE(const char *) ap_strrchr_c(const char *s, int c);
71 #endif
72
73 AP_DECLARE(const char *) ap_strrchr_c(const char *s, int c)
74 {
75     return strrchr(s,c);
76 }
77
78 #if defined(ap_strstr)
79 #undef ap_strstr
80 AP_DECLARE(char *) ap_strstr(char *s, const char *c);
81 #endif
82
83 AP_DECLARE(char *) ap_strstr(char *s, const char *c)
84 {
85     return strstr(s,c);
86 }
87
88 #if defined(ap_strstr_c)
89 #undef ap_strstr_c
90 AP_DECLARE(const char *) ap_strstr_c(const char *s, const char *c);
91 #endif
92
93 AP_DECLARE(const char *) ap_strstr_c(const char *s, const char *c)
94 {
95     return strstr(s,c);
96 }
97
98 #if defined(ap_get_module_config)
99 #undef ap_get_module_config
100 AP_DECLARE(void *) ap_get_module_config(const ap_conf_vector_t *cv,
101                                         const module *m);
102 #endif
103
104 AP_DECLARE(void *) ap_get_module_config(const ap_conf_vector_t *cv,
105                                         const module *m)
106 {
107     return ((void **)cv)[m->module_index];
108 }
109
110 AP_DECLARE(int) ap_get_module_flags(const module *m)
111 {
112     if (m->version < AP_MODULE_FLAGS_MMN_MAJOR
113             || (m->version == AP_MODULE_FLAGS_MMN_MAJOR
114                 && (m->minor_version < AP_MODULE_FLAGS_MMN_MINOR))) {
115         return 0;
116     }
117
118     return m->flags;
119 }
120
121 #if defined(ap_get_core_module_config)
122 #undef ap_get_core_module_config
123 AP_DECLARE(void *) ap_get_core_module_config(const ap_conf_vector_t *cv);
124 #endif
125
126 AP_DECLARE(void *) ap_get_core_module_config(const ap_conf_vector_t *cv)
127 {
128     return ((void **)cv)[AP_CORE_MODULE_INDEX];
129 }
130
131
132 #if defined(ap_get_server_module_loglevel)
133 #undef ap_get_server_module_loglevel
134 AP_DECLARE(int) ap_get_server_module_loglevel(const server_rec *s, int module_index);
135 #endif
136
137 AP_DECLARE(int) ap_get_server_module_loglevel(const server_rec *s, int module_index)
138 {
139     if (module_index < 0 || s->log.module_levels == NULL ||
140         s->log.module_levels[module_index] < 0)
141     {
142         return s->log.level;
143     }
144
145     return s->log.module_levels[module_index];
146 }
147
148 #if defined(ap_get_conn_module_loglevel)
149 #undef ap_get_conn_module_loglevel
150 AP_DECLARE(int) ap_get_conn_module_loglevel(const conn_rec *c, int module_index);
151 #endif
152
153 AP_DECLARE(int) ap_get_conn_module_loglevel(const conn_rec *c, int module_index)
154 {
155     const struct ap_logconf *l = (c)->log ? (c)->log : &(c)->base_server->log;
156     if (module_index < 0 || l->module_levels == NULL ||
157         l->module_levels[module_index] < 0)
158     {
159         return l->level;
160     }
161
162     return l->module_levels[module_index];
163 }
164
165 #if defined(ap_get_conn_server_module_loglevel)
166 #undef ap_get_conn_server_module_loglevel
167 AP_DECLARE(int) ap_get_conn_server_module_loglevel(const conn_rec *c,
168                                                    const server_rec *s,
169                                                    int module_index);
170 #endif
171
172 AP_DECLARE(int) ap_get_conn_server_module_loglevel(const conn_rec *c,
173                                                    const server_rec *s,
174                                                    int module_index)
175 {
176     const struct ap_logconf *l = (c->log && c->log != &c->base_server->log) ?
177                                  c->log : &s->log;
178     if (module_index < 0 || l->module_levels == NULL ||
179         l->module_levels[module_index] < 0)
180     {
181         return l->level;
182     }
183
184     return l->module_levels[module_index];
185 }
186
187 #if defined(ap_get_request_module_loglevel)
188 #undef ap_get_request_module_loglevel
189 AP_DECLARE(int) ap_get_request_module_loglevel(const request_rec *c, int module_index);
190 #endif
191
192 AP_DECLARE(int) ap_get_request_module_loglevel(const request_rec *r, int module_index)
193 {
194     const struct ap_logconf *l = r->log             ? r->log             :
195                                  r->connection->log ? r->connection->log :
196                                  &r->server->log;
197     if (module_index < 0 || l->module_levels == NULL ||
198         l->module_levels[module_index] < 0)
199     {
200         return l->level;
201     }
202
203     return l->module_levels[module_index];
204 }
205
206 /**
207  * Generic accessors for other modules to set at their own module-specific
208  * data
209  * @param conf_vector The vector in which the modules configuration is stored.
210  *        usually r->per_dir_config or s->module_config
211  * @param m The module to set the data for.
212  * @param val The module-specific data to set
213  * @fn void ap_set_module_config(ap_conf_vector_t *cv, const module *m, void *val)
214  */
215 #if defined(ap_set_module_config)
216 #undef ap_set_module_config
217 AP_DECLARE(void) ap_set_module_config(ap_conf_vector_t *cv, const module *m,
218                                       void *val);
219 #endif
220
221 AP_DECLARE(void) ap_set_module_config(ap_conf_vector_t *cv, const module *m,
222                                       void *val)
223 {
224     ((void **)cv)[m->module_index] = val;
225 }
226
227
228 #if defined(ap_set_core_module_config)
229 #undef ap_set_core_module_config
230 AP_DECLARE(void) ap_set_core_module_config(ap_conf_vector_t *cv, void *val);
231 #endif
232
233 AP_DECLARE(void) ap_set_core_module_config(ap_conf_vector_t *cv, void *val)
234 {
235     ((void **)cv)[AP_CORE_MODULE_INDEX] = val;
236 }
237
238 #if defined(apr_palloc)
239 #undef apr_palloc
240 #endif
241 AP_DECLARE(void *) ap_palloc_debug(apr_pool_t *p, apr_size_t size)
242 {
243     /* poison uninitialized memory */
244     return memset(apr_palloc(p, size), 0xEE, size);
245 }
246
247 #if defined(apr_pcalloc)
248 #undef apr_pcalloc
249 #endif
250 AP_DECLARE(void *) ap_pcalloc_debug(apr_pool_t *p, apr_size_t size)
251 {
252     return memset(apr_palloc(p, size), 0, size);
253 }