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

Function make_cookie

modules/metadata/mod_usertrack.c:99–169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

97#define COOKIE_NAME "Apache"
98
99static void make_cookie(request_rec *r)
100{
101 cookie_log_state *cls = ap_get_module_config(r->server->module_config,
102 &usertrack_module);
103 char cookiebuf[2 * (sizeof(apr_uint64_t) + sizeof(int)) + 2];
104 unsigned int random;
105 apr_time_t now = r->request_time ? r->request_time : apr_time_now();
106 char *new_cookie;
107 cookie_dir_rec *dcfg;
108
109 ap_random_insecure_bytes(&random, sizeof(random));
110 apr_snprintf(cookiebuf, sizeof(cookiebuf), "%x.%" APR_UINT64_T_HEX_FMT,
111 random, (apr_uint64_t)now);
112 dcfg = ap_get_module_config(r->per_dir_config, &usertrack_module);
113 if (cls->expires) {
114
115 /* Cookie with date; as strftime '%a, %d-%h-%y %H:%M:%S GMT' */
116 new_cookie = apr_psprintf(r->pool, "%s=%s; path=/",
117 dcfg->cookie_name, cookiebuf);
118
119 if ((dcfg->style == CT_UNSET) || (dcfg->style == CT_NETSCAPE)) {
120 apr_time_exp_t tms;
121 apr_time_exp_gmt(&tms, r->request_time
122 + apr_time_from_sec(cls->expires));
123 new_cookie = apr_psprintf(r->pool,
124 "%s; expires=%s, "
125 "%.2d-%s-%.2d %.2d:%.2d:%.2d GMT",
126 new_cookie, apr_day_snames[tms.tm_wday],
127 tms.tm_mday,
128 apr_month_snames[tms.tm_mon],
129 tms.tm_year % 100,
130 tms.tm_hour, tms.tm_min, tms.tm_sec);
131 }
132 else {
133 new_cookie = apr_psprintf(r->pool, "%s; max-age=%d",
134 new_cookie, cls->expires);
135 }
136 }
137 else {
138 new_cookie = apr_psprintf(r->pool, "%s=%s; path=/",
139 dcfg->cookie_name, cookiebuf);
140 }
141 if (dcfg->cookie_domain != NULL) {
142 new_cookie = apr_pstrcat(r->pool, new_cookie, "; domain=",
143 dcfg->cookie_domain,
144 (dcfg->style == CT_COOKIE2
145 ? "; version=1"
146 : ""),
147 NULL);
148 }
149 if (dcfg->samesite != NULL) {
150 new_cookie = apr_pstrcat(r->pool, new_cookie, "; ",
151 dcfg->samesite,
152 NULL);
153 }
154 if (dcfg->is_secure) {
155 new_cookie = apr_pstrcat(r->pool, new_cookie, "; Secure",
156 NULL);

Callers 1

spot_cookieFunction · 0.85

Calls 2

ap_get_module_configFunction · 0.85
ap_random_insecure_bytesFunction · 0.85

Tested by

no test coverage detected