Mercurial > hg > nginx
annotate src/http/modules/ngx_http_userid_filter_module.c @ 2173:11c59ecbd04f
exit on libxslt test failure
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 13 Aug 2008 08:32:35 +0000 |
parents | 2a92804f4109 |
children | c1975ccd0215 |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
417
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
417
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
417
diff
changeset
|
4 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
417
diff
changeset
|
5 |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
6 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 #include <ngx_config.h> |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_core.h> |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #include <ngx_http.h> |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
12 #define NGX_HTTP_USERID_OFF 0 |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
13 #define NGX_HTTP_USERID_LOG 1 |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
14 #define NGX_HTTP_USERID_V1 2 |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
15 #define NGX_HTTP_USERID_ON 3 |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
16 |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
17 /* 31 Dec 2037 23:55:55 GMT */ |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
18 #define NGX_HTTP_USERID_MAX_EXPIRES 2145916555 |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
19 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
20 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
21 typedef struct { |
509 | 22 ngx_uint_t enable; |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
23 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
24 ngx_int_t service; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
25 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
26 ngx_str_t name; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
27 ngx_str_t domain; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
28 ngx_str_t path; |
539 | 29 ngx_str_t p3p; |
30 | |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
31 time_t expires; |
539 | 32 |
33 u_char mark; | |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
34 } ngx_http_userid_conf_t; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
35 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
36 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
37 typedef struct { |
461 | 38 uint32_t uid_got[4]; |
39 uint32_t uid_set[4]; | |
539 | 40 ngx_str_t cookie; |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
41 } ngx_http_userid_ctx_t; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
42 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
43 |
2012
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
44 static ngx_http_userid_ctx_t *ngx_http_userid_get_uid(ngx_http_request_t *r, |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
45 ngx_http_userid_conf_t *conf); |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
46 static ngx_int_t ngx_http_userid_variable(ngx_http_request_t *r, |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
47 ngx_http_variable_value_t *v, ngx_str_t *name, uint32_t *uid); |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
48 static ngx_int_t ngx_http_userid_set_uid(ngx_http_request_t *r, |
499 | 49 ngx_http_userid_ctx_t *ctx, ngx_http_userid_conf_t *conf); |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
50 |
573 | 51 static ngx_int_t ngx_http_userid_add_variables(ngx_conf_t *cf); |
681 | 52 static ngx_int_t ngx_http_userid_init(ngx_conf_t *cf); |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
53 static void *ngx_http_userid_create_conf(ngx_conf_t *cf); |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
54 static char *ngx_http_userid_merge_conf(ngx_conf_t *cf, void *parent, |
499 | 55 void *child); |
56 static char *ngx_http_userid_domain(ngx_conf_t *cf, void *post, void *data); | |
57 static char *ngx_http_userid_path(ngx_conf_t *cf, void *post, void *data); | |
58 static char *ngx_http_userid_expires(ngx_conf_t *cf, ngx_command_t *cmd, | |
59 void *conf); | |
60 static char *ngx_http_userid_p3p(ngx_conf_t *cf, void *post, void *data); | |
539 | 61 static char *ngx_http_userid_mark(ngx_conf_t *cf, ngx_command_t *cmd, |
62 void *conf); | |
1651
555ee689cecc
use usec and pid as start value
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
63 static ngx_int_t ngx_http_userid_init_worker(ngx_cycle_t *cycle); |
539 | 64 |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
65 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
66 |
1651
555ee689cecc
use usec and pid as start value
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
67 static uint32_t start_value; |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
68 static uint32_t sequencer_v1 = 1; |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
69 static uint32_t sequencer_v2 = 0x03030302; |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
70 |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
71 |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
72 static u_char expires[] = "; expires=Thu, 31-Dec-37 23:55:55 GMT"; |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
73 |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
74 |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
75 static ngx_http_output_header_filter_pt ngx_http_next_header_filter; |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
76 |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
77 |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
78 static ngx_conf_enum_t ngx_http_userid_state[] = { |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
79 { ngx_string("off"), NGX_HTTP_USERID_OFF }, |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
80 { ngx_string("log"), NGX_HTTP_USERID_LOG }, |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
81 { ngx_string("v1"), NGX_HTTP_USERID_V1 }, |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
82 { ngx_string("on"), NGX_HTTP_USERID_ON }, |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
83 { ngx_null_string, 0 } |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
84 }; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
85 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
86 |
461 | 87 static ngx_conf_post_handler_pt ngx_http_userid_domain_p = |
509 | 88 ngx_http_userid_domain; |
461 | 89 static ngx_conf_post_handler_pt ngx_http_userid_path_p = ngx_http_userid_path; |
90 static ngx_conf_post_handler_pt ngx_http_userid_p3p_p = ngx_http_userid_p3p; | |
412
199cd29f35a3
nginx-0.0.10-2004-08-31-19:32:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
411
diff
changeset
|
91 |
199cd29f35a3
nginx-0.0.10-2004-08-31-19:32:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
411
diff
changeset
|
92 |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
93 static ngx_command_t ngx_http_userid_commands[] = { |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
94 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
95 { ngx_string("userid"), |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
96 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
97 ngx_conf_set_enum_slot, |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
98 NGX_HTTP_LOC_CONF_OFFSET, |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
99 offsetof(ngx_http_userid_conf_t, enable), |
412
199cd29f35a3
nginx-0.0.10-2004-08-31-19:32:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
411
diff
changeset
|
100 ngx_http_userid_state }, |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
101 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
102 { ngx_string("userid_service"), |
539 | 103 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
104 ngx_conf_set_num_slot, |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
105 NGX_HTTP_LOC_CONF_OFFSET, |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
106 offsetof(ngx_http_userid_conf_t, service), |
412
199cd29f35a3
nginx-0.0.10-2004-08-31-19:32:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
411
diff
changeset
|
107 NULL }, |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
108 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
109 { ngx_string("userid_name"), |
539 | 110 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
111 ngx_conf_set_str_slot, |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
112 NGX_HTTP_LOC_CONF_OFFSET, |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
113 offsetof(ngx_http_userid_conf_t, name), |
412
199cd29f35a3
nginx-0.0.10-2004-08-31-19:32:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
411
diff
changeset
|
114 NULL }, |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
115 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
116 { ngx_string("userid_domain"), |
539 | 117 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
118 ngx_conf_set_str_slot, |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
119 NGX_HTTP_LOC_CONF_OFFSET, |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
120 offsetof(ngx_http_userid_conf_t, domain), |
461 | 121 &ngx_http_userid_domain_p }, |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
122 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
123 { ngx_string("userid_path"), |
539 | 124 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
125 ngx_conf_set_str_slot, |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
126 NGX_HTTP_LOC_CONF_OFFSET, |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
127 offsetof(ngx_http_userid_conf_t, path), |
461 | 128 &ngx_http_userid_path_p }, |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
129 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
130 { ngx_string("userid_expires"), |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
131 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
410
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
132 ngx_http_userid_expires, |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
133 NGX_HTTP_LOC_CONF_OFFSET, |
410
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
134 0, |
412
199cd29f35a3
nginx-0.0.10-2004-08-31-19:32:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
411
diff
changeset
|
135 NULL }, |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
136 |
461 | 137 { ngx_string("userid_p3p"), |
138 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
139 ngx_conf_set_str_slot, | |
140 NGX_HTTP_LOC_CONF_OFFSET, | |
141 offsetof(ngx_http_userid_conf_t, p3p), | |
142 &ngx_http_userid_p3p_p }, | |
143 | |
539 | 144 { ngx_string("userid_mark"), |
145 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
146 ngx_http_userid_mark, | |
147 NGX_HTTP_LOC_CONF_OFFSET, | |
148 0, | |
149 NULL }, | |
150 | |
499 | 151 ngx_null_command |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
152 }; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
153 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
154 |
667 | 155 static ngx_http_module_t ngx_http_userid_filter_module_ctx = { |
573 | 156 ngx_http_userid_add_variables, /* preconfiguration */ |
681 | 157 ngx_http_userid_init, /* postconfiguration */ |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
158 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
159 NULL, /* create main configuration */ |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
160 NULL, /* init main configuration */ |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
161 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
162 NULL, /* create server configuration */ |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
163 NULL, /* merge server configuration */ |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
164 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
165 ngx_http_userid_create_conf, /* create location configration */ |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
166 ngx_http_userid_merge_conf /* merge location configration */ |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
167 }; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
168 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
169 |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
170 ngx_module_t ngx_http_userid_filter_module = { |
509 | 171 NGX_MODULE_V1, |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
172 &ngx_http_userid_filter_module_ctx, /* module context */ |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
173 ngx_http_userid_commands, /* module directives */ |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
174 NGX_HTTP_MODULE, /* module type */ |
541 | 175 NULL, /* init master */ |
681 | 176 NULL, /* init module */ |
1651
555ee689cecc
use usec and pid as start value
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
177 ngx_http_userid_init_worker, /* init process */ |
541 | 178 NULL, /* init thread */ |
179 NULL, /* exit thread */ | |
180 NULL, /* exit process */ | |
181 NULL, /* exit master */ | |
182 NGX_MODULE_V1_PADDING | |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
183 }; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
184 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
185 |
573 | 186 static ngx_str_t ngx_http_userid_got = ngx_string("uid_got"); |
187 static ngx_str_t ngx_http_userid_set = ngx_string("uid_set"); | |
188 | |
189 | |
499 | 190 static ngx_int_t |
191 ngx_http_userid_filter(ngx_http_request_t *r) | |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
192 { |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
193 ngx_http_userid_ctx_t *ctx; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
194 ngx_http_userid_conf_t *conf; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
195 |
597 | 196 if (r != r->main) { |
509 | 197 return ngx_http_next_header_filter(r); |
198 } | |
199 | |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
200 conf = ngx_http_get_module_loc_conf(r, ngx_http_userid_filter_module); |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
201 |
2012
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
202 if (conf->enable <= NGX_HTTP_USERID_LOG) { |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
203 return ngx_http_next_header_filter(r); |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
204 } |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
205 |
2012
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
206 ctx = ngx_http_userid_get_uid(r, conf); |
499 | 207 |
208 if (ctx == NULL) { | |
209 return NGX_ERROR; | |
210 } | |
211 | |
2012
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
212 if (ctx->uid_got[3] != 0) { |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
213 |
539 | 214 if (conf->mark == '\0') { |
215 return ngx_http_next_header_filter(r); | |
216 | |
217 } else { | |
218 if (ctx->cookie.len > 23 | |
219 && ctx->cookie.data[22] == conf->mark | |
220 && ctx->cookie.data[23] == '=') | |
221 { | |
222 return ngx_http_next_header_filter(r); | |
223 } | |
224 } | |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
225 } |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
226 |
2012
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
227 /* ctx->status == NGX_DECLINED */ |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
228 |
2012
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
229 if (ngx_http_userid_set_uid(r, ctx, conf) == NGX_OK) { |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
230 return ngx_http_next_header_filter(r); |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
231 } |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
232 |
2012
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
233 return NGX_ERROR; |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
234 } |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
235 |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
236 |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
237 static ngx_int_t |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
238 ngx_http_userid_got_variable(ngx_http_request_t *r, |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
239 ngx_http_variable_value_t *v, uintptr_t data) |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
240 { |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
241 ngx_http_userid_ctx_t *ctx; |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
242 ngx_http_userid_conf_t *conf; |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
243 |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
244 conf = ngx_http_get_module_loc_conf(r->main, ngx_http_userid_filter_module); |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
245 |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
246 if (conf->enable == NGX_HTTP_USERID_OFF) { |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
247 v->not_found = 1; |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
248 return NGX_OK; |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
249 } |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
250 |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
251 ctx = ngx_http_userid_get_uid(r, conf); |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
252 |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
253 if (ctx == NULL) { |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
254 return NGX_ERROR; |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
255 } |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
256 |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
257 if (ctx->uid_got[3] != 0) { |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
258 return ngx_http_userid_variable(r, v, &conf->name, ctx->uid_got); |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
259 } |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
260 |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
261 /* ctx->status == NGX_DECLINED */ |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
262 |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
263 v->not_found = 1; |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
264 |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
265 return NGX_OK; |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
266 } |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
267 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
268 |
2012
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
269 static ngx_int_t |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
270 ngx_http_userid_set_variable(ngx_http_request_t *r, |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
271 ngx_http_variable_value_t *v, uintptr_t data) |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
272 { |
2012
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
273 ngx_http_userid_ctx_t *ctx; |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
274 ngx_http_userid_conf_t *conf; |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
275 |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
276 ctx = ngx_http_get_module_ctx(r, ngx_http_userid_filter_module); |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
277 |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
278 if (ctx == NULL || ctx->uid_set[3] == 0) { |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
279 v->not_found = 1; |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
280 return NGX_OK; |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
281 } |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
282 |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
283 conf = ngx_http_get_module_loc_conf(r, ngx_http_userid_filter_module); |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
284 |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
285 return ngx_http_userid_variable(r, v, &conf->name, ctx->uid_set); |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
286 } |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
287 |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
288 |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
289 static ngx_http_userid_ctx_t * |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
290 ngx_http_userid_get_uid(ngx_http_request_t *r, ngx_http_userid_conf_t *conf) |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
291 { |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
292 ngx_int_t n; |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
293 ngx_str_t src, dst; |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
294 ngx_table_elt_t **cookies; |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
295 ngx_http_userid_ctx_t *ctx; |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
296 |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
297 ctx = ngx_http_get_module_ctx(r, ngx_http_userid_filter_module); |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
298 |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
299 if (ctx) { |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
300 return ctx; |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
301 } |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
302 |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
303 if (ctx == NULL) { |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
304 ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_userid_ctx_t)); |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
305 if (ctx == NULL) { |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
306 return NULL; |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
307 } |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
308 |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
309 ngx_http_set_ctx(r, ctx, ngx_http_userid_filter_module); |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
310 } |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
311 |
509 | 312 n = ngx_http_parse_multi_header_lines(&r->headers_in.cookies, &conf->name, |
539 | 313 &ctx->cookie); |
509 | 314 if (n == NGX_DECLINED) { |
2012
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
315 return ctx; |
509 | 316 } |
461 | 317 |
539 | 318 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
319 "uid cookie: \"%V\"", &ctx->cookie); | |
320 | |
321 if (ctx->cookie.len < 22) { | |
509 | 322 cookies = r->headers_in.cookies.elts; |
323 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
324 "client sent too short userid cookie \"%V\"", | |
325 &cookies[n]->value); | |
2012
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
326 return ctx; |
509 | 327 } |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
328 |
539 | 329 src = ctx->cookie; |
330 | |
509 | 331 /* |
539 | 332 * we have to limit the encoded string to 22 characters because |
333 * 1) cookie may be marked by "userid_mark", | |
334 * 2) and there are already the millions cookies with a garbage | |
335 * instead of the correct base64 trail "==" | |
509 | 336 */ |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
337 |
509 | 338 src.len = 22; |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
339 |
509 | 340 dst.data = (u_char *) ctx->uid_got; |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
341 |
509 | 342 if (ngx_decode_base64(&dst, &src) == NGX_ERROR) { |
343 cookies = r->headers_in.cookies.elts; | |
344 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
345 "client sent invalid userid cookie \"%V\"", | |
346 &cookies[n]->value); | |
2012
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
347 return ctx; |
509 | 348 } |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
349 |
509 | 350 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
351 "uid: %08XD%08XD%08XD%08XD", | |
352 ctx->uid_got[0], ctx->uid_got[1], | |
353 ctx->uid_got[2], ctx->uid_got[3]); | |
2012
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
354 |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
355 return ctx; |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
356 } |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
357 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
358 |
499 | 359 static ngx_int_t |
360 ngx_http_userid_set_uid(ngx_http_request_t *r, ngx_http_userid_ctx_t *ctx, | |
361 ngx_http_userid_conf_t *conf) | |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
362 { |
1805 | 363 u_char *cookie, *p; |
364 size_t len; | |
365 ngx_str_t src, dst; | |
366 ngx_table_elt_t *set_cookie, *p3p; | |
539 | 367 /* |
368 * TODO: in the threaded mode the sequencers should be in TLS and their | |
369 * ranges should be divided between threads | |
370 */ | |
371 | |
372 if (ctx->uid_got[3] == 0) { | |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
373 |
539 | 374 if (conf->enable == NGX_HTTP_USERID_V1) { |
375 if (conf->service == NGX_CONF_UNSET) { | |
376 ctx->uid_set[0] = 0; | |
377 } else { | |
378 ctx->uid_set[0] = conf->service; | |
379 } | |
1640 | 380 ctx->uid_set[1] = (uint32_t) ngx_time(); |
1651
555ee689cecc
use usec and pid as start value
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
381 ctx->uid_set[2] = start_value; |
539 | 382 ctx->uid_set[3] = sequencer_v1; |
383 sequencer_v1 += 0x100; | |
384 | |
410
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
385 } else { |
539 | 386 if (conf->service == NGX_CONF_UNSET) { |
1805 | 387 if (ngx_http_server_addr(r, NULL) != NGX_OK) { |
388 return NGX_ERROR; | |
539 | 389 } |
410
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
390 |
539 | 391 ctx->uid_set[0] = htonl(r->in_addr); |
392 | |
393 } else { | |
394 ctx->uid_set[0] = htonl(conf->service); | |
395 } | |
396 | |
1640 | 397 ctx->uid_set[1] = htonl((uint32_t) ngx_time()); |
1651
555ee689cecc
use usec and pid as start value
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
398 ctx->uid_set[2] = htonl(start_value); |
539 | 399 ctx->uid_set[3] = htonl(sequencer_v2); |
400 sequencer_v2 += 0x100; | |
401 if (sequencer_v2 < 0x03030302) { | |
402 sequencer_v2 = 0x03030302; | |
403 } | |
404 } | |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
405 |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
406 } else { |
539 | 407 ctx->uid_set[0] = ctx->uid_got[0]; |
408 ctx->uid_set[1] = ctx->uid_got[1]; | |
409 ctx->uid_set[2] = ctx->uid_got[2]; | |
410 ctx->uid_set[3] = ctx->uid_got[3]; | |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
411 } |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
412 |
461 | 413 len = conf->name.len + 1 + ngx_base64_encoded_length(16) + conf->path.len; |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
414 |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
415 if (conf->expires) { |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
416 len += sizeof(expires) - 1 + 2; |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
417 } |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
418 |
479 | 419 if (conf->domain.len) { |
461 | 420 len += conf->domain.len; |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
421 } |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
422 |
2049 | 423 cookie = ngx_pnalloc(r->pool, len); |
499 | 424 if (cookie == NULL) { |
412
199cd29f35a3
nginx-0.0.10-2004-08-31-19:32:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
411
diff
changeset
|
425 return NGX_ERROR; |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
426 } |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
427 |
573 | 428 p = ngx_copy(cookie, conf->name.data, conf->name.len); |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
429 *p++ = '='; |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
430 |
539 | 431 if (ctx->uid_got[3] == 0) { |
432 src.len = 16; | |
433 src.data = (u_char *) ctx->uid_set; | |
434 dst.data = p; | |
435 | |
436 ngx_encode_base64(&dst, &src); | |
437 | |
438 p += dst.len; | |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
439 |
539 | 440 if (conf->mark) { |
441 *(p - 2) = conf->mark; | |
442 } | |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
443 |
539 | 444 } else { |
445 p = ngx_cpymem(p, ctx->cookie.data, 22); | |
446 *p++ = conf->mark; | |
447 *p++ = '='; | |
448 } | |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
449 |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
450 if (conf->expires == NGX_HTTP_USERID_MAX_EXPIRES) { |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
451 p = ngx_cpymem(p, expires, sizeof(expires) - 1); |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
452 |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
453 } else if (conf->expires) { |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
454 p = ngx_cpymem(p, expires, sizeof("; expires=") - 1); |
455 | 455 p = ngx_http_cookie_time(p, ngx_time() + conf->expires); |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
456 } |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
457 |
573 | 458 p = ngx_copy(p, conf->domain.data, conf->domain.len); |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
459 |
573 | 460 p = ngx_copy(p, conf->path.data, conf->path.len); |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
461 |
499 | 462 set_cookie = ngx_list_push(&r->headers_out.headers); |
463 if (set_cookie == NULL) { | |
412
199cd29f35a3
nginx-0.0.10-2004-08-31-19:32:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
411
diff
changeset
|
464 return NGX_ERROR; |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
465 } |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
466 |
509 | 467 set_cookie->hash = 1; |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
468 set_cookie->key.len = sizeof("Set-Cookie") - 1; |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
469 set_cookie->key.data = (u_char *) "Set-Cookie"; |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
470 set_cookie->value.len = p - cookie; |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
471 set_cookie->value.data = cookie; |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
472 |
461 | 473 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
474 "uid cookie: \"%V\"", &set_cookie->value); | |
475 | |
479 | 476 if (conf->p3p.len == 0) { |
461 | 477 return NGX_OK; |
478 } | |
479 | |
499 | 480 p3p = ngx_list_push(&r->headers_out.headers); |
481 if (p3p == NULL) { | |
461 | 482 return NGX_ERROR; |
483 } | |
484 | |
509 | 485 p3p->hash = 1; |
461 | 486 p3p->key.len = sizeof("P3P") - 1; |
487 p3p->key.data = (u_char *) "P3P"; | |
488 p3p->value = conf->p3p; | |
489 | |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
490 return NGX_OK; |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
491 } |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
492 |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
493 |
499 | 494 static ngx_int_t |
2012
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
495 ngx_http_userid_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v, |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
496 ngx_str_t *name, uint32_t *uid) |
410
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
497 { |
2012
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
498 v->len = name->len + sizeof("=00001111222233334444555566667777") - 1; |
2049 | 499 v->data = ngx_pnalloc(r->pool, v->len); |
573 | 500 if (v->data == NULL) { |
501 return NGX_ERROR; | |
502 } | |
503 | |
657 | 504 v->valid = 1; |
1565 | 505 v->no_cacheable = 0; |
657 | 506 v->not_found = 0; |
507 | |
573 | 508 ngx_sprintf(v->data, "%V=%08XD%08XD%08XD%08XD", |
2012
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
509 name, uid[0], uid[1], uid[2], uid[3]); |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
510 |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
511 return NGX_OK; |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
512 } |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
513 |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
514 |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
515 static ngx_int_t |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
516 ngx_http_userid_add_variables(ngx_conf_t *cf) |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
517 { |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
518 ngx_http_variable_t *var; |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
519 |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
520 var = ngx_http_add_variable(cf, &ngx_http_userid_got, NGX_HTTP_VAR_NOHASH); |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
521 if (var == NULL) { |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
522 return NGX_ERROR; |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
523 } |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
524 |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
525 var->get_handler = ngx_http_userid_got_variable; |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
526 |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
527 var = ngx_http_add_variable(cf, &ngx_http_userid_set, NGX_HTTP_VAR_NOHASH); |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
528 if (var == NULL) { |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
529 return NGX_ERROR; |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
530 } |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
531 |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
532 var->get_handler = ngx_http_userid_set_variable; |
573 | 533 |
534 return NGX_OK; | |
535 } | |
536 | |
537 | |
499 | 538 static void * |
539 ngx_http_userid_create_conf(ngx_conf_t *cf) | |
577 | 540 { |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
541 ngx_http_userid_conf_t *conf; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
542 |
499 | 543 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_userid_conf_t)); |
544 if (conf == NULL) { | |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
545 return NGX_CONF_ERROR; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
546 } |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
547 |
479 | 548 /* |
549 * set by ngx_pcalloc(): | |
550 * | |
551 * conf->name.len = 0; | |
552 * conf->name.date = NULL; | |
553 * conf->domain.len = 0; | |
554 * conf->domain.date = NULL; | |
555 * conf->path.len = 0; | |
556 * conf->path.date = NULL; | |
557 * conf->p3p.len = 0; | |
558 * conf->p3p.date = NULL; | |
559 */ | |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
560 |
509 | 561 conf->enable = NGX_CONF_UNSET_UINT; |
410
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
562 conf->service = NGX_CONF_UNSET; |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
563 conf->expires = NGX_CONF_UNSET; |
539 | 564 conf->mark = (u_char) '\xFF'; |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
565 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
566 return conf; |
577 | 567 } |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
568 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
569 |
499 | 570 static char * |
571 ngx_http_userid_merge_conf(ngx_conf_t *cf, void *parent, void *child) | |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
572 { |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
573 ngx_http_userid_conf_t *prev = parent; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
574 ngx_http_userid_conf_t *conf = child; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
575 |
663 | 576 ngx_conf_merge_uint_value(conf->enable, prev->enable, |
577 NGX_HTTP_USERID_OFF); | |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
578 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
579 ngx_conf_merge_str_value(conf->name, prev->name, "uid"); |
479 | 580 ngx_conf_merge_str_value(conf->domain, prev->domain, ""); |
461 | 581 ngx_conf_merge_str_value(conf->path, prev->path, "; path=/"); |
479 | 582 ngx_conf_merge_str_value(conf->p3p, prev->p3p, ""); |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
583 |
410
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
584 ngx_conf_merge_value(conf->service, prev->service, NGX_CONF_UNSET); |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
585 ngx_conf_merge_sec_value(conf->expires, prev->expires, 0); |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
586 |
539 | 587 if (conf->mark == (u_char) '\xFF') { |
588 if (prev->mark == (u_char) '\xFF') { | |
589 conf->mark = '\0'; | |
590 } else { | |
591 conf->mark = prev->mark; | |
592 } | |
593 } | |
594 | |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
595 return NGX_CONF_OK; |
410
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
596 } |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
597 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
598 |
681 | 599 static ngx_int_t |
600 ngx_http_userid_init(ngx_conf_t *cf) | |
601 { | |
602 ngx_http_next_header_filter = ngx_http_top_header_filter; | |
603 ngx_http_top_header_filter = ngx_http_userid_filter; | |
604 | |
605 return NGX_OK; | |
606 } | |
607 | |
608 | |
499 | 609 static char * |
610 ngx_http_userid_domain(ngx_conf_t *cf, void *post, void *data) | |
412
199cd29f35a3
nginx-0.0.10-2004-08-31-19:32:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
411
diff
changeset
|
611 { |
199cd29f35a3
nginx-0.0.10-2004-08-31-19:32:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
411
diff
changeset
|
612 ngx_str_t *domain = data; |
199cd29f35a3
nginx-0.0.10-2004-08-31-19:32:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
411
diff
changeset
|
613 |
461 | 614 u_char *p, *new; |
615 | |
503 | 616 if (ngx_strcmp(domain->data, "none") == 0) { |
479 | 617 domain->len = 0; |
618 domain->data = (u_char *) ""; | |
461 | 619 |
620 return NGX_CONF_OK; | |
412
199cd29f35a3
nginx-0.0.10-2004-08-31-19:32:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
411
diff
changeset
|
621 } |
199cd29f35a3
nginx-0.0.10-2004-08-31-19:32:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
411
diff
changeset
|
622 |
2049 | 623 new = ngx_pnalloc(cf->pool, sizeof("; domain=") - 1 + domain->len); |
499 | 624 if (new == NULL) { |
461 | 625 return NGX_CONF_ERROR; |
626 } | |
627 | |
628 p = ngx_cpymem(new, "; domain=", sizeof("; domain=") - 1); | |
501 | 629 ngx_memcpy(p, domain->data, domain->len); |
461 | 630 |
631 domain->len += sizeof("; domain=") - 1; | |
632 domain->data = new; | |
633 | |
634 return NGX_CONF_OK; | |
635 } | |
636 | |
637 | |
499 | 638 static char * |
639 ngx_http_userid_path(ngx_conf_t *cf, void *post, void *data) | |
461 | 640 { |
641 ngx_str_t *path = data; | |
642 | |
643 u_char *p, *new; | |
644 | |
2049 | 645 new = ngx_pnalloc(cf->pool, sizeof("; path=") - 1 + path->len); |
499 | 646 if (new == NULL) { |
461 | 647 return NGX_CONF_ERROR; |
648 } | |
649 | |
650 p = ngx_cpymem(new, "; path=", sizeof("; path=") - 1); | |
501 | 651 ngx_memcpy(p, path->data, path->len); |
461 | 652 |
653 path->len += sizeof("; path=") - 1; | |
654 path->data = new; | |
655 | |
412
199cd29f35a3
nginx-0.0.10-2004-08-31-19:32:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
411
diff
changeset
|
656 return NGX_CONF_OK; |
199cd29f35a3
nginx-0.0.10-2004-08-31-19:32:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
411
diff
changeset
|
657 } |
199cd29f35a3
nginx-0.0.10-2004-08-31-19:32:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
411
diff
changeset
|
658 |
199cd29f35a3
nginx-0.0.10-2004-08-31-19:32:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
411
diff
changeset
|
659 |
499 | 660 static char * |
661 ngx_http_userid_expires(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
662 { |
410
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
663 ngx_http_userid_conf_t *ucf = conf; |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
664 |
539 | 665 ngx_str_t *value; |
410
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
666 |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
667 if (ucf->expires != NGX_CONF_UNSET) { |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
668 return "is duplicate"; |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
669 } |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
670 |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
671 value = cf->args->elts; |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
672 |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
673 if (ngx_strcmp(value[1].data, "max") == 0) { |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
674 ucf->expires = NGX_HTTP_USERID_MAX_EXPIRES; |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
675 return NGX_CONF_OK; |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
676 } |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
677 |
410
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
678 if (ngx_strcmp(value[1].data, "off") == 0) { |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
679 ucf->expires = 0; |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
680 return NGX_CONF_OK; |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
681 } |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
682 |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
683 ucf->expires = ngx_parse_time(&value[1], 1); |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
684 if (ucf->expires == NGX_ERROR) { |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
685 return "invalid value"; |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
686 } |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
687 |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
688 if (ucf->expires == NGX_PARSE_LARGE_TIME) { |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
689 return "value must be less than 68 years"; |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
690 } |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
691 |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
692 return NGX_CONF_OK; |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
693 } |
461 | 694 |
695 | |
499 | 696 static char * |
697 ngx_http_userid_p3p(ngx_conf_t *cf, void *post, void *data) | |
461 | 698 { |
699 ngx_str_t *p3p = data; | |
700 | |
503 | 701 if (ngx_strcmp(p3p->data, "none") == 0) { |
479 | 702 p3p->len = 0; |
703 p3p->data = (u_char *) ""; | |
461 | 704 } |
705 | |
706 return NGX_CONF_OK; | |
707 } | |
539 | 708 |
709 | |
710 static char * | |
711 ngx_http_userid_mark(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
712 { | |
713 ngx_http_userid_conf_t *ucf = conf; | |
714 | |
715 ngx_str_t *value; | |
716 | |
717 if (ucf->mark != (u_char) '\xFF') { | |
718 return "is duplicate"; | |
719 } | |
720 | |
721 value = cf->args->elts; | |
722 | |
723 if (ngx_strcmp(value[1].data, "off") == 0) { | |
724 ucf->mark = '\0'; | |
725 return NGX_CONF_OK; | |
726 } | |
727 | |
728 if (value[1].len != 1 | |
729 || !((value[1].data[0] >= '0' && value[1].data[0] <= '9') | |
730 || (value[1].data[0] >= 'A' && value[1].data[0] <= 'Z') | |
731 || (value[1].data[0] >= 'a' && value[1].data[0] <= 'z') | |
732 || value[1].data[0] == '=')) | |
733 { | |
734 return "value must be \"off\" or a single letter, digit or \"=\""; | |
735 } | |
736 | |
737 ucf->mark = value[1].data[0]; | |
738 | |
739 return NGX_CONF_OK; | |
740 } | |
1651
555ee689cecc
use usec and pid as start value
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
741 |
555ee689cecc
use usec and pid as start value
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
742 |
555ee689cecc
use usec and pid as start value
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
743 static ngx_int_t |
555ee689cecc
use usec and pid as start value
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
744 ngx_http_userid_init_worker(ngx_cycle_t *cycle) |
555ee689cecc
use usec and pid as start value
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
745 { |
555ee689cecc
use usec and pid as start value
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
746 struct timeval tp; |
555ee689cecc
use usec and pid as start value
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
747 |
555ee689cecc
use usec and pid as start value
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
748 ngx_gettimeofday(&tp); |
555ee689cecc
use usec and pid as start value
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
749 |
555ee689cecc
use usec and pid as start value
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
750 /* use the most significant usec part that fits to 16 bits */ |
555ee689cecc
use usec and pid as start value
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
751 start_value = ((tp.tv_usec / 20) << 16) | ngx_pid; |
555ee689cecc
use usec and pid as start value
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
752 |
555ee689cecc
use usec and pid as start value
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
753 return NGX_OK; |
555ee689cecc
use usec and pid as start value
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
754 } |
555ee689cecc
use usec and pid as start value
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
755 |