MCPcopy Create free account
hub / github.com/apache/httpd / spot_cookie

Function spot_cookie

modules/metadata/mod_usertrack.c:222–269  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

220}
221
222static int spot_cookie(request_rec *r)
223{
224 cookie_dir_rec *dcfg = ap_get_module_config(r->per_dir_config,
225 &usertrack_module);
226 const char *cookie_header;
227 ap_regmatch_t regm[NUM_SUBS];
228
229 /* Do not run in subrequests */
230 if (!dcfg->enabled || r->main) {
231 return DECLINED;
232 }
233
234 if ((cookie_header = apr_table_get(r->headers_in, "Cookie"))) {
235 if (!ap_regexec(dcfg->regexp, cookie_header, NUM_SUBS, regm, 0)) {
236 char *cookieval = NULL;
237 int err = 0;
238 /* Our regexp,
239 * ^cookie_name=([^;]+)|;[ \t]+cookie_name=([^;]+)
240 * only allows for $1 or $2 to be available. ($0 is always
241 * filled with the entire matched expression, not just
242 * the part in parentheses.) So just check for either one
243 * and assign to cookieval if present. */
244 if (regm[1].rm_so != -1) {
245 cookieval = ap_pregsub(r->pool, "$1", cookie_header,
246 NUM_SUBS, regm);
247 if (cookieval == NULL)
248 err = 1;
249 }
250 if (regm[2].rm_so != -1) {
251 cookieval = ap_pregsub(r->pool, "$2", cookie_header,
252 NUM_SUBS, regm);
253 if (cookieval == NULL)
254 err = 1;
255 }
256 if (err) {
257 ap_log_rerror(APLOG_MARK, APLOG_CRIT, 0, r, APLOGNO(01499)
258 "Failed to extract cookie value (out of mem?)");
259 return HTTP_INTERNAL_SERVER_ERROR;
260 }
261 /* Set the cookie in a note, for logging */
262 apr_table_setn(r->notes, "cookie", cookieval);
263
264 return DECLINED; /* There's already a cookie, no new one */
265 }
266 }
267 make_cookie(r);
268 return OK; /* We set our cookie */
269}
270
271static void *make_cookie_log_state(apr_pool_t *p, server_rec *s)
272{

Callers

nothing calls this directly

Calls 4

ap_get_module_configFunction · 0.85
ap_regexecFunction · 0.85
ap_pregsubFunction · 0.85
make_cookieFunction · 0.85

Tested by

no test coverage detected