Mercurial > hg > nginx
annotate src/http/modules/ngx_http_userid_filter_module.c @ 3593:a79d2ad7a2d8 stable-0.7
merge r3487, r3525:
rewrite fixes:
*) escape ampersand in argument while rewrite
*) autodetect redirect if URI is rewritten to a string starting with $scheme
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 07 Jun 2010 11:51:37 +0000 |
parents | 17995396463d |
children |
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 { |
2528 | 363 u_char *cookie, *p; |
364 size_t len; | |
365 ngx_str_t src, dst; | |
366 ngx_table_elt_t *set_cookie, *p3p; | |
367 ngx_connection_t *c; | |
368 struct sockaddr_in *sin; | |
369 #if (NGX_HAVE_INET6) | |
370 struct sockaddr_in6 *sin6; | |
371 #endif | |
372 | |
539 | 373 /* |
374 * TODO: in the threaded mode the sequencers should be in TLS and their | |
375 * ranges should be divided between threads | |
376 */ | |
377 | |
378 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
|
379 |
539 | 380 if (conf->enable == NGX_HTTP_USERID_V1) { |
381 if (conf->service == NGX_CONF_UNSET) { | |
382 ctx->uid_set[0] = 0; | |
383 } else { | |
384 ctx->uid_set[0] = conf->service; | |
385 } | |
1640 | 386 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
|
387 ctx->uid_set[2] = start_value; |
539 | 388 ctx->uid_set[3] = sequencer_v1; |
389 sequencer_v1 += 0x100; | |
390 | |
410
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
391 } else { |
539 | 392 if (conf->service == NGX_CONF_UNSET) { |
2857
507fc5ac9839
use ngx_connection_local_sockaddr() instead of ngx_http_server_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
2528
diff
changeset
|
393 |
507fc5ac9839
use ngx_connection_local_sockaddr() instead of ngx_http_server_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
2528
diff
changeset
|
394 c = r->connection; |
507fc5ac9839
use ngx_connection_local_sockaddr() instead of ngx_http_server_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
2528
diff
changeset
|
395 |
507fc5ac9839
use ngx_connection_local_sockaddr() instead of ngx_http_server_addr()
Igor Sysoev <igor@sysoev.ru>
parents:
2528
diff
changeset
|
396 if (ngx_connection_local_sockaddr(c, NULL, 0) != NGX_OK) { |
1805 | 397 return NGX_ERROR; |
539 | 398 } |
410
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
399 |
2528 | 400 switch (c->local_sockaddr->sa_family) { |
401 | |
402 #if (NGX_HAVE_INET6) | |
403 case AF_INET6: | |
404 sin6 = (struct sockaddr_in6 *) c->local_sockaddr; | |
405 | |
406 p = (u_char *) &ctx->uid_set[0]; | |
407 | |
408 *p++ = sin6->sin6_addr.s6_addr[12]; | |
409 *p++ = sin6->sin6_addr.s6_addr[13]; | |
410 *p++ = sin6->sin6_addr.s6_addr[14]; | |
411 *p = sin6->sin6_addr.s6_addr[15]; | |
412 | |
413 break; | |
414 #endif | |
415 default: /* AF_INET */ | |
416 sin = (struct sockaddr_in *) c->local_sockaddr; | |
417 ctx->uid_set[0] = sin->sin_addr.s_addr; | |
418 break; | |
419 } | |
539 | 420 |
421 } else { | |
422 ctx->uid_set[0] = htonl(conf->service); | |
423 } | |
424 | |
1640 | 425 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
|
426 ctx->uid_set[2] = htonl(start_value); |
539 | 427 ctx->uid_set[3] = htonl(sequencer_v2); |
428 sequencer_v2 += 0x100; | |
429 if (sequencer_v2 < 0x03030302) { | |
430 sequencer_v2 = 0x03030302; | |
431 } | |
432 } | |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
433 |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
434 } else { |
539 | 435 ctx->uid_set[0] = ctx->uid_got[0]; |
436 ctx->uid_set[1] = ctx->uid_got[1]; | |
437 ctx->uid_set[2] = ctx->uid_got[2]; | |
438 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
|
439 } |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
440 |
461 | 441 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
|
442 |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
443 if (conf->expires) { |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
444 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
|
445 } |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
446 |
479 | 447 if (conf->domain.len) { |
461 | 448 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
|
449 } |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
450 |
2049 | 451 cookie = ngx_pnalloc(r->pool, len); |
499 | 452 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
|
453 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
|
454 } |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
455 |
573 | 456 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
|
457 *p++ = '='; |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
458 |
539 | 459 if (ctx->uid_got[3] == 0) { |
460 src.len = 16; | |
461 src.data = (u_char *) ctx->uid_set; | |
462 dst.data = p; | |
463 | |
464 ngx_encode_base64(&dst, &src); | |
465 | |
466 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
|
467 |
539 | 468 if (conf->mark) { |
469 *(p - 2) = conf->mark; | |
470 } | |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
471 |
539 | 472 } else { |
473 p = ngx_cpymem(p, ctx->cookie.data, 22); | |
474 *p++ = conf->mark; | |
475 *p++ = '='; | |
476 } | |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
477 |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
478 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
|
479 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
|
480 |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
481 } 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
|
482 p = ngx_cpymem(p, expires, sizeof("; expires=") - 1); |
455 | 483 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
|
484 } |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
485 |
573 | 486 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
|
487 |
573 | 488 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
|
489 |
499 | 490 set_cookie = ngx_list_push(&r->headers_out.headers); |
491 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
|
492 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
|
493 } |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
494 |
509 | 495 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
|
496 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
|
497 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
|
498 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
|
499 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
|
500 |
461 | 501 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
502 "uid cookie: \"%V\"", &set_cookie->value); | |
503 | |
479 | 504 if (conf->p3p.len == 0) { |
461 | 505 return NGX_OK; |
506 } | |
507 | |
499 | 508 p3p = ngx_list_push(&r->headers_out.headers); |
509 if (p3p == NULL) { | |
461 | 510 return NGX_ERROR; |
511 } | |
512 | |
509 | 513 p3p->hash = 1; |
461 | 514 p3p->key.len = sizeof("P3P") - 1; |
515 p3p->key.data = (u_char *) "P3P"; | |
516 p3p->value = conf->p3p; | |
517 | |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
518 return NGX_OK; |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
519 } |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
520 |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
521 |
499 | 522 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
|
523 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
|
524 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
|
525 { |
2012
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
526 v->len = name->len + sizeof("=00001111222233334444555566667777") - 1; |
2049 | 527 v->data = ngx_pnalloc(r->pool, v->len); |
573 | 528 if (v->data == NULL) { |
529 return NGX_ERROR; | |
530 } | |
531 | |
657 | 532 v->valid = 1; |
1565 | 533 v->no_cacheable = 0; |
657 | 534 v->not_found = 0; |
535 | |
573 | 536 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
|
537 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
|
538 |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
539 return NGX_OK; |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
540 } |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
541 |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
542 |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
543 static ngx_int_t |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
544 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
|
545 { |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
546 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
|
547 |
3581
17995396463d
merge r3454, r3455, r3486, r3496, r3519, r3523:
Igor Sysoev <igor@sysoev.ru>
parents:
3237
diff
changeset
|
548 var = ngx_http_add_variable(cf, &ngx_http_userid_got, 0); |
2012
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
549 if (var == NULL) { |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
550 return NGX_ERROR; |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
551 } |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
552 |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
553 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
|
554 |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
555 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
|
556 if (var == NULL) { |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
557 return NGX_ERROR; |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
558 } |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
559 |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
560 var->get_handler = ngx_http_userid_set_variable; |
573 | 561 |
562 return NGX_OK; | |
563 } | |
564 | |
565 | |
499 | 566 static void * |
567 ngx_http_userid_create_conf(ngx_conf_t *cf) | |
577 | 568 { |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
569 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
|
570 |
499 | 571 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_userid_conf_t)); |
572 if (conf == NULL) { | |
3237
2efa8d2fcde1
merge r2903, r2911, r2912, r3002:
Igor Sysoev <igor@sysoev.ru>
parents:
2857
diff
changeset
|
573 return NULL; |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
574 } |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
575 |
479 | 576 /* |
577 * set by ngx_pcalloc(): | |
578 * | |
579 * conf->name.len = 0; | |
580 * conf->name.date = NULL; | |
581 * conf->domain.len = 0; | |
582 * conf->domain.date = NULL; | |
583 * conf->path.len = 0; | |
584 * conf->path.date = NULL; | |
585 * conf->p3p.len = 0; | |
586 * conf->p3p.date = NULL; | |
587 */ | |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
588 |
509 | 589 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
|
590 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
|
591 conf->expires = NGX_CONF_UNSET; |
539 | 592 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
|
593 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
594 return conf; |
577 | 595 } |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
596 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
597 |
499 | 598 static char * |
599 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
|
600 { |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
601 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
|
602 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
|
603 |
663 | 604 ngx_conf_merge_uint_value(conf->enable, prev->enable, |
605 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
|
606 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
607 ngx_conf_merge_str_value(conf->name, prev->name, "uid"); |
479 | 608 ngx_conf_merge_str_value(conf->domain, prev->domain, ""); |
461 | 609 ngx_conf_merge_str_value(conf->path, prev->path, "; path=/"); |
479 | 610 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
|
611 |
410
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
612 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
|
613 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
|
614 |
539 | 615 if (conf->mark == (u_char) '\xFF') { |
616 if (prev->mark == (u_char) '\xFF') { | |
617 conf->mark = '\0'; | |
618 } else { | |
619 conf->mark = prev->mark; | |
620 } | |
621 } | |
622 | |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
623 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
|
624 } |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
625 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
626 |
681 | 627 static ngx_int_t |
628 ngx_http_userid_init(ngx_conf_t *cf) | |
629 { | |
630 ngx_http_next_header_filter = ngx_http_top_header_filter; | |
631 ngx_http_top_header_filter = ngx_http_userid_filter; | |
632 | |
633 return NGX_OK; | |
634 } | |
635 | |
636 | |
499 | 637 static char * |
638 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
|
639 { |
199cd29f35a3
nginx-0.0.10-2004-08-31-19:32:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
411
diff
changeset
|
640 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
|
641 |
461 | 642 u_char *p, *new; |
643 | |
503 | 644 if (ngx_strcmp(domain->data, "none") == 0) { |
479 | 645 domain->len = 0; |
646 domain->data = (u_char *) ""; | |
461 | 647 |
648 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
|
649 } |
199cd29f35a3
nginx-0.0.10-2004-08-31-19:32:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
411
diff
changeset
|
650 |
2049 | 651 new = ngx_pnalloc(cf->pool, sizeof("; domain=") - 1 + domain->len); |
499 | 652 if (new == NULL) { |
461 | 653 return NGX_CONF_ERROR; |
654 } | |
655 | |
656 p = ngx_cpymem(new, "; domain=", sizeof("; domain=") - 1); | |
501 | 657 ngx_memcpy(p, domain->data, domain->len); |
461 | 658 |
659 domain->len += sizeof("; domain=") - 1; | |
660 domain->data = new; | |
661 | |
662 return NGX_CONF_OK; | |
663 } | |
664 | |
665 | |
499 | 666 static char * |
667 ngx_http_userid_path(ngx_conf_t *cf, void *post, void *data) | |
461 | 668 { |
669 ngx_str_t *path = data; | |
670 | |
671 u_char *p, *new; | |
672 | |
2049 | 673 new = ngx_pnalloc(cf->pool, sizeof("; path=") - 1 + path->len); |
499 | 674 if (new == NULL) { |
461 | 675 return NGX_CONF_ERROR; |
676 } | |
677 | |
678 p = ngx_cpymem(new, "; path=", sizeof("; path=") - 1); | |
501 | 679 ngx_memcpy(p, path->data, path->len); |
461 | 680 |
681 path->len += sizeof("; path=") - 1; | |
682 path->data = new; | |
683 | |
412
199cd29f35a3
nginx-0.0.10-2004-08-31-19:32:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
411
diff
changeset
|
684 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
|
685 } |
199cd29f35a3
nginx-0.0.10-2004-08-31-19:32:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
411
diff
changeset
|
686 |
199cd29f35a3
nginx-0.0.10-2004-08-31-19:32:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
411
diff
changeset
|
687 |
499 | 688 static char * |
689 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
|
690 { |
410
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
691 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
|
692 |
539 | 693 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
|
694 |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
695 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
|
696 return "is duplicate"; |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
697 } |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
698 |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
699 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
|
700 |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
701 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
|
702 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
|
703 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
|
704 } |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
705 |
410
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
706 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
|
707 ucf->expires = 0; |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
708 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
|
709 } |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
710 |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
711 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
|
712 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
|
713 return "invalid value"; |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
714 } |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
715 |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
716 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
|
717 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
|
718 } |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
719 |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
720 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
|
721 } |
461 | 722 |
723 | |
499 | 724 static char * |
725 ngx_http_userid_p3p(ngx_conf_t *cf, void *post, void *data) | |
461 | 726 { |
727 ngx_str_t *p3p = data; | |
728 | |
503 | 729 if (ngx_strcmp(p3p->data, "none") == 0) { |
479 | 730 p3p->len = 0; |
731 p3p->data = (u_char *) ""; | |
461 | 732 } |
733 | |
734 return NGX_CONF_OK; | |
735 } | |
539 | 736 |
737 | |
738 static char * | |
739 ngx_http_userid_mark(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
740 { | |
741 ngx_http_userid_conf_t *ucf = conf; | |
742 | |
743 ngx_str_t *value; | |
744 | |
745 if (ucf->mark != (u_char) '\xFF') { | |
746 return "is duplicate"; | |
747 } | |
748 | |
749 value = cf->args->elts; | |
750 | |
751 if (ngx_strcmp(value[1].data, "off") == 0) { | |
752 ucf->mark = '\0'; | |
753 return NGX_CONF_OK; | |
754 } | |
755 | |
756 if (value[1].len != 1 | |
757 || !((value[1].data[0] >= '0' && value[1].data[0] <= '9') | |
758 || (value[1].data[0] >= 'A' && value[1].data[0] <= 'Z') | |
759 || (value[1].data[0] >= 'a' && value[1].data[0] <= 'z') | |
760 || value[1].data[0] == '=')) | |
761 { | |
762 return "value must be \"off\" or a single letter, digit or \"=\""; | |
763 } | |
764 | |
765 ucf->mark = value[1].data[0]; | |
766 | |
767 return NGX_CONF_OK; | |
768 } | |
1651
555ee689cecc
use usec and pid as start value
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
769 |
555ee689cecc
use usec and pid as start value
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
770 |
555ee689cecc
use usec and pid as start value
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
771 static ngx_int_t |
555ee689cecc
use usec and pid as start value
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
772 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
|
773 { |
555ee689cecc
use usec and pid as start value
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
774 struct timeval tp; |
555ee689cecc
use usec and pid as start value
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
775 |
555ee689cecc
use usec and pid as start value
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
776 ngx_gettimeofday(&tp); |
555ee689cecc
use usec and pid as start value
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
777 |
555ee689cecc
use usec and pid as start value
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
778 /* 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
|
779 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
|
780 |
555ee689cecc
use usec and pid as start value
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
781 return NGX_OK; |
555ee689cecc
use usec and pid as start value
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
782 } |
555ee689cecc
use usec and pid as start value
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
783 |