13 #define NGX_HTTP_USERID_OFF 0
14 #define NGX_HTTP_USERID_LOG 1
15 #define NGX_HTTP_USERID_V1 2
16 #define NGX_HTTP_USERID_ON 3
19 #define NGX_HTTP_USERID_MAX_EXPIRES 2145916555
57 static void *ngx_http_userid_create_conf(
ngx_conf_t *cf);
58 static char *ngx_http_userid_merge_conf(
ngx_conf_t *cf,
void *parent,
60 static char *ngx_http_userid_domain(
ngx_conf_t *cf,
void *post,
void *data);
61 static char *ngx_http_userid_path(
ngx_conf_t *cf,
void *post,
void *data);
64 static char *ngx_http_userid_p3p(
ngx_conf_t *cf,
void *post,
void *data);
71 static uint32_t start_value;
72 static uint32_t sequencer_v1 = 1;
73 static uint32_t sequencer_v2 = 0x03030302;
76 static u_char expires[] =
"; expires=Thu, 31-Dec-37 23:55:55 GMT";
92 ngx_http_userid_domain;
104 ngx_http_userid_state },
125 &ngx_http_userid_domain_p },
132 &ngx_http_userid_path_p },
136 ngx_http_userid_expires,
146 &ngx_http_userid_p3p_p },
150 ngx_http_userid_mark,
160 ngx_http_userid_add_variables,
161 ngx_http_userid_init,
169 ngx_http_userid_create_conf,
170 ngx_http_userid_merge_conf
176 &ngx_http_userid_filter_module_ctx,
177 ngx_http_userid_commands,
181 ngx_http_userid_init_worker,
193 static ngx_uint_t ngx_http_userid_reset_index;
203 return ngx_http_next_header_filter(r);
209 return ngx_http_next_header_filter(r);
212 ctx = ngx_http_userid_get_uid(r, conf);
218 if (ngx_http_userid_set_uid(r, ctx, conf) ==
NGX_OK) {
219 return ngx_http_next_header_filter(r);
240 ctx = ngx_http_userid_get_uid(r->
main, conf);
247 return ngx_http_userid_variable(r->
main, v, &conf->
name, ctx->
uid_got);
270 ctx = ngx_http_userid_get_uid(r->
main, conf);
276 if (ngx_http_userid_create_uid(r->
main, ctx, conf) !=
NGX_OK) {
285 return ngx_http_userid_variable(r->
main, v, &conf->
name, ctx->
uid_set);
319 "uid cookie: \"%V\"", &ctx->
cookie);
324 "client sent too short userid cookie \"%V\"",
345 "client sent invalid userid cookie \"%V\"",
351 "uid: %08XD%08XD%08XD%08XD",
368 if (ngx_http_userid_create_uid(r, ctx, conf) !=
NGX_OK) {
379 len +=
sizeof(expires) - 1 + 2;
387 if (cookie == NULL) {
404 *(p - 2) = conf->
mark;
414 p =
ngx_cpymem(p, expires,
sizeof(expires) - 1);
417 p =
ngx_cpymem(p, expires,
sizeof(
"; expires=") - 1);
426 if (set_cookie == NULL) {
430 set_cookie->
hash = 1;
436 "uid cookie: \"%V\"", &set_cookie->
value);
460 struct sockaddr_in *sin;
464 struct sockaddr_in6 *sin6;
475 if (vv->
len == 0 || (vv->
len == 1 && vv->
data[0] ==
'0')) {
477 if (conf->
mark ==
'\0'
497 "userid cookie \"%V=%08XD%08XD%08XD%08XD\" was reset",
517 ctx->
uid_set[3] = sequencer_v1;
518 sequencer_v1 += 0x100;
535 p = (u_char *) &ctx->
uid_set[0];
537 *p++ = sin6->sin6_addr.s6_addr[12];
538 *p++ = sin6->sin6_addr.s6_addr[13];
539 *p++ = sin6->sin6_addr.s6_addr[14];
540 *p = sin6->sin6_addr.s6_addr[15];
546 ctx->
uid_set[0] = sin->sin_addr.s_addr;
555 ctx->
uid_set[2] = htonl(start_value);
556 ctx->
uid_set[3] = htonl(sequencer_v2);
557 sequencer_v2 += 0x100;
558 if (sequencer_v2 < 0x03030302) {
559 sequencer_v2 = 0x03030302;
571 v->
len = name->
len +
sizeof(
"=00001111222233334444555566667777") - 1;
573 if (v->
data == NULL) {
582 name, uid[0], uid[1], uid[2], uid[3]);
631 ngx_http_userid_reset_index = n;
659 conf->
mark = (u_char)
'\xFF';
666 ngx_http_userid_merge_conf(
ngx_conf_t *cf,
void *parent,
void *child)
682 if (conf->
mark == (u_char)
'\xFF') {
683 if (prev->
mark == (u_char)
'\xFF') {
705 ngx_http_userid_domain(
ngx_conf_t *cf,
void *post,
void *data)
721 p =
ngx_cpymem(
new,
"; domain=",
sizeof(
"; domain=") - 1);
724 domain->
len +=
sizeof(
"; domain=") - 1;
732 ngx_http_userid_path(
ngx_conf_t *cf,
void *post,
void *data)
743 p =
ngx_cpymem(
new,
"; path=",
sizeof(
"; path=") - 1);
746 path->
len +=
sizeof(
"; path=") - 1;
761 return "is duplicate";
778 return "invalid value";
786 ngx_http_userid_p3p(
ngx_conf_t *cf,
void *post,
void *data)
805 if (ucf->
mark != (u_char)
'\xFF') {
806 return "is duplicate";
816 if (value[1].len != 1
817 || !((value[1].data[0] >=
'0' && value[1].data[0] <=
'9')
818 || (value[1].data[0] >=
'A' && value[1].data[0] <=
'Z')
819 || (value[1].data[0] >=
'a' && value[1].data[0] <=
'z')
820 || value[1].data[0] ==
'='))
822 return "value must be \"off\" or a single letter, digit or \"=\"";
839 start_value = ((tp.tv_usec / 20) << 16) |
ngx_pid;