Mercurial > hg > nginx-quic
annotate src/http/modules/ngx_http_userid_filter_module.c @ 7524:deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
This ensures that correct ctx is always available, including after
filter finalization. In particular, this fixes a segmentation fault
with the following configuration:
location / {
image_filter test;
perl 'sub {
my $r = shift;
$r->send_http_header();
$r->print("foo\n");
$r->print("bar\n");
}';
}
This also seems to be the only way to correctly handle filter finalization
in various complex cases, for example, when embedded perl is used both
in the original handler and in an error page called after filter
finalization.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Fri, 12 Jul 2019 11:29:22 +0300 |
parents | ecc97cb0eda4 |
children | e3e8b8234f05 |
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 |
4412 | 4 * Copyright (C) Nginx, Inc. |
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
|
5 */ |
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
|
6 |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_config.h> |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #include <ngx_core.h> |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 #include <ngx_http.h> |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
12 |
409
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_OFF 0 |
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_LOG 1 |
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_V1 2 |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
16 #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
|
17 |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
18 /* 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
|
19 #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
|
20 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
21 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
22 typedef struct { |
509 | 23 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
|
24 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
25 ngx_int_t service; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
26 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
27 ngx_str_t name; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
28 ngx_str_t domain; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
29 ngx_str_t path; |
539 | 30 ngx_str_t p3p; |
31 | |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
32 time_t expires; |
539 | 33 |
34 u_char mark; | |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
35 } 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
|
36 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
37 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
38 typedef struct { |
461 | 39 uint32_t uid_got[4]; |
40 uint32_t uid_set[4]; | |
539 | 41 ngx_str_t cookie; |
3943 | 42 ngx_uint_t reset; |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
43 } 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
|
44 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
45 |
2012
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
46 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
|
47 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
|
48 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
|
49 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
|
50 static ngx_int_t ngx_http_userid_set_uid(ngx_http_request_t *r, |
499 | 51 ngx_http_userid_ctx_t *ctx, ngx_http_userid_conf_t *conf); |
3648
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
52 static ngx_int_t ngx_http_userid_create_uid(ngx_http_request_t *r, |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
53 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
|
54 |
573 | 55 static ngx_int_t ngx_http_userid_add_variables(ngx_conf_t *cf); |
681 | 56 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
|
57 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
|
58 static char *ngx_http_userid_merge_conf(ngx_conf_t *cf, void *parent, |
499 | 59 void *child); |
60 static char *ngx_http_userid_domain(ngx_conf_t *cf, void *post, void *data); | |
61 static char *ngx_http_userid_path(ngx_conf_t *cf, void *post, void *data); | |
62 static char *ngx_http_userid_expires(ngx_conf_t *cf, ngx_command_t *cmd, | |
63 void *conf); | |
64 static char *ngx_http_userid_p3p(ngx_conf_t *cf, void *post, void *data); | |
539 | 65 static char *ngx_http_userid_mark(ngx_conf_t *cf, ngx_command_t *cmd, |
66 void *conf); | |
1651
555ee689cecc
use usec and pid as start value
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
67 static ngx_int_t ngx_http_userid_init_worker(ngx_cycle_t *cycle); |
539 | 68 |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
69 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
70 |
1651
555ee689cecc
use usec and pid as start value
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
71 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
|
72 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
|
73 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
|
74 |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
75 |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
76 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
|
77 |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
78 |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
79 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
|
80 |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
81 |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
82 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
|
83 { 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
|
84 { 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
|
85 { 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
|
86 { 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
|
87 { ngx_null_string, 0 } |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
88 }; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
89 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
90 |
461 | 91 static ngx_conf_post_handler_pt ngx_http_userid_domain_p = |
509 | 92 ngx_http_userid_domain; |
461 | 93 static ngx_conf_post_handler_pt ngx_http_userid_path_p = ngx_http_userid_path; |
94 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
|
95 |
199cd29f35a3
nginx-0.0.10-2004-08-31-19:32:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
411
diff
changeset
|
96 |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
97 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
|
98 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
99 { 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
|
100 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
|
101 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
|
102 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
|
103 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
|
104 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
|
105 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
106 { ngx_string("userid_service"), |
539 | 107 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
|
108 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
|
109 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
|
110 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
|
111 NULL }, |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
112 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
113 { ngx_string("userid_name"), |
539 | 114 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
|
115 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
|
116 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
|
117 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
|
118 NULL }, |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
119 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
120 { ngx_string("userid_domain"), |
539 | 121 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
|
122 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
|
123 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
|
124 offsetof(ngx_http_userid_conf_t, domain), |
461 | 125 &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
|
126 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
127 { ngx_string("userid_path"), |
539 | 128 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
|
129 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
|
130 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
|
131 offsetof(ngx_http_userid_conf_t, path), |
461 | 132 &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
|
133 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
134 { 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
|
135 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
|
136 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
|
137 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
|
138 0, |
412
199cd29f35a3
nginx-0.0.10-2004-08-31-19:32:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
411
diff
changeset
|
139 NULL }, |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
140 |
461 | 141 { ngx_string("userid_p3p"), |
142 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
143 ngx_conf_set_str_slot, | |
144 NGX_HTTP_LOC_CONF_OFFSET, | |
145 offsetof(ngx_http_userid_conf_t, p3p), | |
146 &ngx_http_userid_p3p_p }, | |
147 | |
539 | 148 { ngx_string("userid_mark"), |
149 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
150 ngx_http_userid_mark, | |
151 NGX_HTTP_LOC_CONF_OFFSET, | |
152 0, | |
153 NULL }, | |
154 | |
499 | 155 ngx_null_command |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
156 }; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
157 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
158 |
667 | 159 static ngx_http_module_t ngx_http_userid_filter_module_ctx = { |
573 | 160 ngx_http_userid_add_variables, /* preconfiguration */ |
681 | 161 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
|
162 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
163 NULL, /* create main configuration */ |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
164 NULL, /* init main configuration */ |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
165 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
166 NULL, /* create server configuration */ |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
167 NULL, /* merge server configuration */ |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
168 |
4499
778ef9c3fd2d
Fixed spelling in single-line comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4474
diff
changeset
|
169 ngx_http_userid_create_conf, /* create location configuration */ |
778ef9c3fd2d
Fixed spelling in single-line comments.
Ruslan Ermilov <ru@nginx.com>
parents:
4474
diff
changeset
|
170 ngx_http_userid_merge_conf /* merge location configuration */ |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
171 }; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
172 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
173 |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
174 ngx_module_t ngx_http_userid_filter_module = { |
509 | 175 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
|
176 &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
|
177 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
|
178 NGX_HTTP_MODULE, /* module type */ |
541 | 179 NULL, /* init master */ |
681 | 180 NULL, /* init module */ |
1651
555ee689cecc
use usec and pid as start value
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
181 ngx_http_userid_init_worker, /* init process */ |
541 | 182 NULL, /* init thread */ |
183 NULL, /* exit thread */ | |
184 NULL, /* exit process */ | |
185 NULL, /* exit master */ | |
186 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
|
187 }; |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
188 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
189 |
3943 | 190 static ngx_str_t ngx_http_userid_got = ngx_string("uid_got"); |
191 static ngx_str_t ngx_http_userid_set = ngx_string("uid_set"); | |
192 static ngx_str_t ngx_http_userid_reset = ngx_string("uid_reset"); | |
193 static ngx_uint_t ngx_http_userid_reset_index; | |
573 | 194 |
195 | |
499 | 196 static ngx_int_t |
197 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
|
198 { |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
199 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
|
200 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
|
201 |
597 | 202 if (r != r->main) { |
509 | 203 return ngx_http_next_header_filter(r); |
204 } | |
205 | |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
206 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
|
207 |
3647 | 208 if (conf->enable < NGX_HTTP_USERID_V1) { |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
209 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
|
210 } |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
211 |
2012
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
212 ctx = ngx_http_userid_get_uid(r, conf); |
499 | 213 |
214 if (ctx == NULL) { | |
215 return NGX_ERROR; | |
216 } | |
217 | |
2012
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
218 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
|
219 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
|
220 } |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
221 |
2012
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
222 return NGX_ERROR; |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
223 } |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
224 |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
225 |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
226 static ngx_int_t |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
227 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
|
228 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
|
229 { |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
230 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
|
231 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
|
232 |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
233 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
|
234 |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
235 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
|
236 v->not_found = 1; |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
237 return NGX_OK; |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
238 } |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
239 |
3659
7e69af2dd93c
set uid values for main request only
Igor Sysoev <igor@sysoev.ru>
parents:
3649
diff
changeset
|
240 ctx = ngx_http_userid_get_uid(r->main, conf); |
2012
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
241 |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
242 if (ctx == NULL) { |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
243 return NGX_ERROR; |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
244 } |
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 (ctx->uid_got[3] != 0) { |
3659
7e69af2dd93c
set uid values for main request only
Igor Sysoev <igor@sysoev.ru>
parents:
3649
diff
changeset
|
247 return ngx_http_userid_variable(r->main, v, &conf->name, ctx->uid_got); |
2012
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
248 } |
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 v->not_found = 1; |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
251 |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
252 return NGX_OK; |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
253 } |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
254 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
255 |
2012
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
256 static ngx_int_t |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
257 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
|
258 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
|
259 { |
2012
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
260 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
|
261 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
|
262 |
3659
7e69af2dd93c
set uid values for main request only
Igor Sysoev <igor@sysoev.ru>
parents:
3649
diff
changeset
|
263 conf = ngx_http_get_module_loc_conf(r->main, ngx_http_userid_filter_module); |
2012
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
264 |
3648
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
265 if (conf->enable < NGX_HTTP_USERID_V1) { |
2012
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
266 v->not_found = 1; |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
267 return NGX_OK; |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
268 } |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
269 |
3659
7e69af2dd93c
set uid values for main request only
Igor Sysoev <igor@sysoev.ru>
parents:
3649
diff
changeset
|
270 ctx = ngx_http_userid_get_uid(r->main, conf); |
3648
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
271 |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
272 if (ctx == NULL) { |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
273 return NGX_ERROR; |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
274 } |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
275 |
3661
8649a0c0f09d
change logic introduced in r3649:
Igor Sysoev <igor@sysoev.ru>
parents:
3659
diff
changeset
|
276 if (ngx_http_userid_create_uid(r->main, ctx, conf) != NGX_OK) { |
8649a0c0f09d
change logic introduced in r3649:
Igor Sysoev <igor@sysoev.ru>
parents:
3659
diff
changeset
|
277 return NGX_ERROR; |
8649a0c0f09d
change logic introduced in r3649:
Igor Sysoev <igor@sysoev.ru>
parents:
3659
diff
changeset
|
278 } |
3648
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
279 |
3661
8649a0c0f09d
change logic introduced in r3649:
Igor Sysoev <igor@sysoev.ru>
parents:
3659
diff
changeset
|
280 if (ctx->uid_set[3] == 0) { |
8649a0c0f09d
change logic introduced in r3649:
Igor Sysoev <igor@sysoev.ru>
parents:
3659
diff
changeset
|
281 v->not_found = 1; |
8649a0c0f09d
change logic introduced in r3649:
Igor Sysoev <igor@sysoev.ru>
parents:
3659
diff
changeset
|
282 return NGX_OK; |
3648
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
283 } |
2012
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
284 |
3659
7e69af2dd93c
set uid values for main request only
Igor Sysoev <igor@sysoev.ru>
parents:
3649
diff
changeset
|
285 return ngx_http_userid_variable(r->main, v, &conf->name, ctx->uid_set); |
2012
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 { |
3648
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
363 u_char *cookie, *p; |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
364 size_t len; |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
365 ngx_str_t src, dst; |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
366 ngx_table_elt_t *set_cookie, *p3p; |
2528 | 367 |
3661
8649a0c0f09d
change logic introduced in r3649:
Igor Sysoev <igor@sysoev.ru>
parents:
3659
diff
changeset
|
368 if (ngx_http_userid_create_uid(r, ctx, conf) != NGX_OK) { |
8649a0c0f09d
change logic introduced in r3649:
Igor Sysoev <igor@sysoev.ru>
parents:
3659
diff
changeset
|
369 return NGX_ERROR; |
8649a0c0f09d
change logic introduced in r3649:
Igor Sysoev <igor@sysoev.ru>
parents:
3659
diff
changeset
|
370 } |
539 | 371 |
3661
8649a0c0f09d
change logic introduced in r3649:
Igor Sysoev <igor@sysoev.ru>
parents:
3659
diff
changeset
|
372 if (ctx->uid_set[3] == 0) { |
8649a0c0f09d
change logic introduced in r3649:
Igor Sysoev <igor@sysoev.ru>
parents:
3659
diff
changeset
|
373 return NGX_OK; |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
374 } |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
375 |
461 | 376 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
|
377 |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
378 if (conf->expires) { |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
379 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
|
380 } |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
381 |
479 | 382 if (conf->domain.len) { |
461 | 383 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
|
384 } |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
385 |
2049 | 386 cookie = ngx_pnalloc(r->pool, len); |
499 | 387 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
|
388 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
|
389 } |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
390 |
573 | 391 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
|
392 *p++ = '='; |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
393 |
3943 | 394 if (ctx->uid_got[3] == 0 || ctx->reset) { |
539 | 395 src.len = 16; |
396 src.data = (u_char *) ctx->uid_set; | |
397 dst.data = p; | |
398 | |
399 ngx_encode_base64(&dst, &src); | |
400 | |
401 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
|
402 |
539 | 403 if (conf->mark) { |
404 *(p - 2) = conf->mark; | |
405 } | |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
406 |
539 | 407 } else { |
408 p = ngx_cpymem(p, ctx->cookie.data, 22); | |
409 *p++ = conf->mark; | |
410 *p++ = '='; | |
411 } | |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
412 |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
413 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
|
414 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
|
415 |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
416 } 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
|
417 p = ngx_cpymem(p, expires, sizeof("; expires=") - 1); |
455 | 418 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
|
419 } |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
420 |
573 | 421 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
|
422 |
573 | 423 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
|
424 |
499 | 425 set_cookie = ngx_list_push(&r->headers_out.headers); |
426 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
|
427 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
|
428 } |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
429 |
509 | 430 set_cookie->hash = 1; |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3509
diff
changeset
|
431 ngx_str_set(&set_cookie->key, "Set-Cookie"); |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
432 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
|
433 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
|
434 |
461 | 435 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
436 "uid cookie: \"%V\"", &set_cookie->value); | |
437 | |
479 | 438 if (conf->p3p.len == 0) { |
461 | 439 return NGX_OK; |
440 } | |
441 | |
499 | 442 p3p = ngx_list_push(&r->headers_out.headers); |
443 if (p3p == NULL) { | |
461 | 444 return NGX_ERROR; |
445 } | |
446 | |
509 | 447 p3p->hash = 1; |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3509
diff
changeset
|
448 ngx_str_set(&p3p->key, "P3P"); |
461 | 449 p3p->value = conf->p3p; |
450 | |
409
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
451 return NGX_OK; |
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 |
8ac40cae79f0
nginx-0.0.10-2004-08-29-07:55:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
408
diff
changeset
|
454 |
499 | 455 static ngx_int_t |
3648
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
456 ngx_http_userid_create_uid(ngx_http_request_t *r, ngx_http_userid_ctx_t *ctx, |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
457 ngx_http_userid_conf_t *conf) |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
458 { |
3943 | 459 ngx_connection_t *c; |
460 struct sockaddr_in *sin; | |
461 ngx_http_variable_value_t *vv; | |
3648
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
462 #if (NGX_HAVE_INET6) |
3943 | 463 u_char *p; |
464 struct sockaddr_in6 *sin6; | |
3648
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
465 #endif |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
466 |
3661
8649a0c0f09d
change logic introduced in r3649:
Igor Sysoev <igor@sysoev.ru>
parents:
3659
diff
changeset
|
467 if (ctx->uid_set[3] != 0) { |
8649a0c0f09d
change logic introduced in r3649:
Igor Sysoev <igor@sysoev.ru>
parents:
3659
diff
changeset
|
468 return NGX_OK; |
8649a0c0f09d
change logic introduced in r3649:
Igor Sysoev <igor@sysoev.ru>
parents:
3659
diff
changeset
|
469 } |
8649a0c0f09d
change logic introduced in r3649:
Igor Sysoev <igor@sysoev.ru>
parents:
3659
diff
changeset
|
470 |
8649a0c0f09d
change logic introduced in r3649:
Igor Sysoev <igor@sysoev.ru>
parents:
3659
diff
changeset
|
471 if (ctx->uid_got[3] != 0) { |
8649a0c0f09d
change logic introduced in r3649:
Igor Sysoev <igor@sysoev.ru>
parents:
3659
diff
changeset
|
472 |
3943 | 473 vv = ngx_http_get_indexed_variable(r, ngx_http_userid_reset_index); |
474 | |
7028
e6f399a176e7
Userid: ngx_http_get_indexed_variable() error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6626
diff
changeset
|
475 if (vv == NULL || vv->not_found) { |
e6f399a176e7
Userid: ngx_http_get_indexed_variable() error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6626
diff
changeset
|
476 return NGX_ERROR; |
e6f399a176e7
Userid: ngx_http_get_indexed_variable() error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6626
diff
changeset
|
477 } |
e6f399a176e7
Userid: ngx_http_get_indexed_variable() error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6626
diff
changeset
|
478 |
3943 | 479 if (vv->len == 0 || (vv->len == 1 && vv->data[0] == '0')) { |
480 | |
481 if (conf->mark == '\0' | |
482 || (ctx->cookie.len > 23 | |
483 && ctx->cookie.data[22] == conf->mark | |
484 && ctx->cookie.data[23] == '=')) | |
485 { | |
486 return NGX_OK; | |
487 } | |
488 | |
489 ctx->uid_set[0] = ctx->uid_got[0]; | |
490 ctx->uid_set[1] = ctx->uid_got[1]; | |
491 ctx->uid_set[2] = ctx->uid_got[2]; | |
492 ctx->uid_set[3] = ctx->uid_got[3]; | |
493 | |
3661
8649a0c0f09d
change logic introduced in r3649:
Igor Sysoev <igor@sysoev.ru>
parents:
3659
diff
changeset
|
494 return NGX_OK; |
3943 | 495 |
496 } else { | |
497 ctx->reset = 1; | |
498 | |
499 if (vv->len == 3 && ngx_strncmp(vv->data, "log", 3) == 0) { | |
500 ngx_log_error(NGX_LOG_NOTICE, r->connection->log, 0, | |
501 "userid cookie \"%V=%08XD%08XD%08XD%08XD\" was reset", | |
502 &conf->name, ctx->uid_got[0], ctx->uid_got[1], | |
503 ctx->uid_got[2], ctx->uid_got[3]); | |
504 } | |
3661
8649a0c0f09d
change logic introduced in r3649:
Igor Sysoev <igor@sysoev.ru>
parents:
3659
diff
changeset
|
505 } |
8649a0c0f09d
change logic introduced in r3649:
Igor Sysoev <igor@sysoev.ru>
parents:
3659
diff
changeset
|
506 } |
8649a0c0f09d
change logic introduced in r3649:
Igor Sysoev <igor@sysoev.ru>
parents:
3659
diff
changeset
|
507 |
3648
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
508 /* |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
509 * TODO: in the threaded mode the sequencers should be in TLS and their |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
510 * ranges should be divided between threads |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
511 */ |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
512 |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
513 if (conf->enable == NGX_HTTP_USERID_V1) { |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
514 if (conf->service == NGX_CONF_UNSET) { |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
515 ctx->uid_set[0] = 0; |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
516 } else { |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
517 ctx->uid_set[0] = conf->service; |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
518 } |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
519 ctx->uid_set[1] = (uint32_t) ngx_time(); |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
520 ctx->uid_set[2] = start_value; |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
521 ctx->uid_set[3] = sequencer_v1; |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
522 sequencer_v1 += 0x100; |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
523 |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
524 } else { |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
525 if (conf->service == NGX_CONF_UNSET) { |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
526 |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
527 c = r->connection; |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
528 |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
529 if (ngx_connection_local_sockaddr(c, NULL, 0) != NGX_OK) { |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
530 return NGX_ERROR; |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
531 } |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
532 |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
533 switch (c->local_sockaddr->sa_family) { |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
534 |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
535 #if (NGX_HAVE_INET6) |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
536 case AF_INET6: |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
537 sin6 = (struct sockaddr_in6 *) c->local_sockaddr; |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
538 |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
539 p = (u_char *) &ctx->uid_set[0]; |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
540 |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
541 *p++ = sin6->sin6_addr.s6_addr[12]; |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
542 *p++ = sin6->sin6_addr.s6_addr[13]; |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
543 *p++ = sin6->sin6_addr.s6_addr[14]; |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
544 *p = sin6->sin6_addr.s6_addr[15]; |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
545 |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
546 break; |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
547 #endif |
7432
ecc97cb0eda4
Userid: using stub for AF_UNIX addresses.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7028
diff
changeset
|
548 |
ecc97cb0eda4
Userid: using stub for AF_UNIX addresses.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7028
diff
changeset
|
549 #if (NGX_HAVE_UNIX_DOMAIN) |
ecc97cb0eda4
Userid: using stub for AF_UNIX addresses.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7028
diff
changeset
|
550 case AF_UNIX: |
ecc97cb0eda4
Userid: using stub for AF_UNIX addresses.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7028
diff
changeset
|
551 ctx->uid_set[0] = 0; |
ecc97cb0eda4
Userid: using stub for AF_UNIX addresses.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7028
diff
changeset
|
552 break; |
ecc97cb0eda4
Userid: using stub for AF_UNIX addresses.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7028
diff
changeset
|
553 #endif |
ecc97cb0eda4
Userid: using stub for AF_UNIX addresses.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7028
diff
changeset
|
554 |
3648
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
555 default: /* AF_INET */ |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
556 sin = (struct sockaddr_in *) c->local_sockaddr; |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
557 ctx->uid_set[0] = sin->sin_addr.s_addr; |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
558 break; |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
559 } |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
560 |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
561 } else { |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
562 ctx->uid_set[0] = htonl(conf->service); |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
563 } |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
564 |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
565 ctx->uid_set[1] = htonl((uint32_t) ngx_time()); |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
566 ctx->uid_set[2] = htonl(start_value); |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
567 ctx->uid_set[3] = htonl(sequencer_v2); |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
568 sequencer_v2 += 0x100; |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
569 if (sequencer_v2 < 0x03030302) { |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
570 sequencer_v2 = 0x03030302; |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
571 } |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
572 } |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
573 |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
574 return NGX_OK; |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
575 } |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
576 |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
577 |
67dc5dbbcca3
Now $uid_set may be used at any time, r2013 states the same is wrong.
Igor Sysoev <igor@sysoev.ru>
parents:
3647
diff
changeset
|
578 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
|
579 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
|
580 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
|
581 { |
2012
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
582 v->len = name->len + sizeof("=00001111222233334444555566667777") - 1; |
2049 | 583 v->data = ngx_pnalloc(r->pool, v->len); |
573 | 584 if (v->data == NULL) { |
585 return NGX_ERROR; | |
586 } | |
587 | |
657 | 588 v->valid = 1; |
1565 | 589 v->no_cacheable = 0; |
657 | 590 v->not_found = 0; |
591 | |
573 | 592 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
|
593 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
|
594 |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
595 return NGX_OK; |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
596 } |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
597 |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
598 |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
599 static ngx_int_t |
3943 | 600 ngx_http_userid_reset_variable(ngx_http_request_t *r, |
601 ngx_http_variable_value_t *v, uintptr_t data) | |
602 { | |
603 *v = ngx_http_variable_null_value; | |
604 | |
605 return NGX_OK; | |
606 } | |
607 | |
608 | |
609 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
|
610 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
|
611 { |
3943 | 612 ngx_int_t n; |
2012
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
613 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
|
614 |
3522
d24f030507cd
allow to use $uid_got in SSI and perl module
Igor Sysoev <igor@sysoev.ru>
parents:
3516
diff
changeset
|
615 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
|
616 if (var == NULL) { |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
617 return NGX_ERROR; |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
618 } |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
619 |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
620 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
|
621 |
3661
8649a0c0f09d
change logic introduced in r3649:
Igor Sysoev <igor@sysoev.ru>
parents:
3659
diff
changeset
|
622 var = ngx_http_add_variable(cf, &ngx_http_userid_set, 0); |
2012
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
623 if (var == NULL) { |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
624 return NGX_ERROR; |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
625 } |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
626 |
220f5e8603d0
$uid_got and $uid_set may used at any time
Igor Sysoev <igor@sysoev.ru>
parents:
1805
diff
changeset
|
627 var->get_handler = ngx_http_userid_set_variable; |
573 | 628 |
3943 | 629 var = ngx_http_add_variable(cf, &ngx_http_userid_reset, |
630 NGX_HTTP_VAR_CHANGEABLE); | |
631 if (var == NULL) { | |
632 return NGX_ERROR; | |
633 } | |
634 | |
635 var->get_handler = ngx_http_userid_reset_variable; | |
636 | |
637 n = ngx_http_get_variable_index(cf, &ngx_http_userid_reset); | |
638 if (n == NGX_ERROR) { | |
639 return NGX_ERROR; | |
640 } | |
641 | |
642 ngx_http_userid_reset_index = n; | |
643 | |
573 | 644 return NGX_OK; |
645 } | |
646 | |
647 | |
499 | 648 static void * |
649 ngx_http_userid_create_conf(ngx_conf_t *cf) | |
577 | 650 { |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
651 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
|
652 |
499 | 653 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_userid_conf_t)); |
654 if (conf == NULL) { | |
2912
c7d57b539248
return NULL instead of NGX_CONF_ERROR on a create conf failure
Igor Sysoev <igor@sysoev.ru>
parents:
2857
diff
changeset
|
655 return NULL; |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
656 } |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
657 |
479 | 658 /* |
659 * set by ngx_pcalloc(): | |
660 * | |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3509
diff
changeset
|
661 * conf->name = { 0, NULL }; |
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3509
diff
changeset
|
662 * conf->domain = { 0, NULL }; |
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3509
diff
changeset
|
663 * conf->path = { 0, NULL }; |
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3509
diff
changeset
|
664 * conf->p3p = { 0, NULL }; |
479 | 665 */ |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
666 |
509 | 667 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
|
668 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
|
669 conf->expires = NGX_CONF_UNSET; |
539 | 670 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
|
671 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
672 return conf; |
577 | 673 } |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
674 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
675 |
499 | 676 static char * |
677 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
|
678 { |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
679 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
|
680 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
|
681 |
663 | 682 ngx_conf_merge_uint_value(conf->enable, prev->enable, |
683 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
|
684 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
685 ngx_conf_merge_str_value(conf->name, prev->name, "uid"); |
479 | 686 ngx_conf_merge_str_value(conf->domain, prev->domain, ""); |
461 | 687 ngx_conf_merge_str_value(conf->path, prev->path, "; path=/"); |
479 | 688 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
|
689 |
410
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
690 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
|
691 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
|
692 |
539 | 693 if (conf->mark == (u_char) '\xFF') { |
694 if (prev->mark == (u_char) '\xFF') { | |
695 conf->mark = '\0'; | |
696 } else { | |
697 conf->mark = prev->mark; | |
698 } | |
699 } | |
700 | |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
701 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
|
702 } |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
703 |
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
704 |
681 | 705 static ngx_int_t |
706 ngx_http_userid_init(ngx_conf_t *cf) | |
707 { | |
708 ngx_http_next_header_filter = ngx_http_top_header_filter; | |
709 ngx_http_top_header_filter = ngx_http_userid_filter; | |
710 | |
711 return NGX_OK; | |
712 } | |
713 | |
714 | |
499 | 715 static char * |
716 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
|
717 { |
199cd29f35a3
nginx-0.0.10-2004-08-31-19:32:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
411
diff
changeset
|
718 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
|
719 |
461 | 720 u_char *p, *new; |
721 | |
503 | 722 if (ngx_strcmp(domain->data, "none") == 0) { |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3509
diff
changeset
|
723 ngx_str_set(domain, ""); |
461 | 724 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
|
725 } |
199cd29f35a3
nginx-0.0.10-2004-08-31-19:32:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
411
diff
changeset
|
726 |
2049 | 727 new = ngx_pnalloc(cf->pool, sizeof("; domain=") - 1 + domain->len); |
499 | 728 if (new == NULL) { |
461 | 729 return NGX_CONF_ERROR; |
730 } | |
731 | |
732 p = ngx_cpymem(new, "; domain=", sizeof("; domain=") - 1); | |
501 | 733 ngx_memcpy(p, domain->data, domain->len); |
461 | 734 |
735 domain->len += sizeof("; domain=") - 1; | |
736 domain->data = new; | |
737 | |
738 return NGX_CONF_OK; | |
739 } | |
740 | |
741 | |
499 | 742 static char * |
743 ngx_http_userid_path(ngx_conf_t *cf, void *post, void *data) | |
461 | 744 { |
745 ngx_str_t *path = data; | |
746 | |
747 u_char *p, *new; | |
748 | |
2049 | 749 new = ngx_pnalloc(cf->pool, sizeof("; path=") - 1 + path->len); |
499 | 750 if (new == NULL) { |
461 | 751 return NGX_CONF_ERROR; |
752 } | |
753 | |
754 p = ngx_cpymem(new, "; path=", sizeof("; path=") - 1); | |
501 | 755 ngx_memcpy(p, path->data, path->len); |
461 | 756 |
757 path->len += sizeof("; path=") - 1; | |
758 path->data = new; | |
759 | |
412
199cd29f35a3
nginx-0.0.10-2004-08-31-19:32:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
411
diff
changeset
|
760 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
|
761 } |
199cd29f35a3
nginx-0.0.10-2004-08-31-19:32:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
411
diff
changeset
|
762 |
199cd29f35a3
nginx-0.0.10-2004-08-31-19:32:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
411
diff
changeset
|
763 |
499 | 764 static char * |
765 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
|
766 { |
410
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
767 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
|
768 |
539 | 769 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
|
770 |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
771 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
|
772 return "is duplicate"; |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
773 } |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
774 |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
775 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
|
776 |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
777 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
|
778 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
|
779 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
|
780 } |
408
d6e2b445c1b8
nginx-0.0.10-2004-08-27-19:40:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
781 |
410
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
782 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
|
783 ucf->expires = 0; |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
784 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
|
785 } |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
786 |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
787 ucf->expires = ngx_parse_time(&value[1], 1); |
4474 | 788 if (ucf->expires == (time_t) NGX_ERROR) { |
410
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
789 return "invalid value"; |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
790 } |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
791 |
48b9ad5ca1fc
nginx-0.0.10-2004-08-30-19:42:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
409
diff
changeset
|
792 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
|
793 } |
461 | 794 |
795 | |
499 | 796 static char * |
797 ngx_http_userid_p3p(ngx_conf_t *cf, void *post, void *data) | |
461 | 798 { |
799 ngx_str_t *p3p = data; | |
800 | |
503 | 801 if (ngx_strcmp(p3p->data, "none") == 0) { |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3509
diff
changeset
|
802 ngx_str_set(p3p, ""); |
461 | 803 } |
804 | |
805 return NGX_CONF_OK; | |
806 } | |
539 | 807 |
808 | |
809 static char * | |
810 ngx_http_userid_mark(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
811 { | |
812 ngx_http_userid_conf_t *ucf = conf; | |
813 | |
814 ngx_str_t *value; | |
815 | |
816 if (ucf->mark != (u_char) '\xFF') { | |
817 return "is duplicate"; | |
818 } | |
819 | |
820 value = cf->args->elts; | |
821 | |
822 if (ngx_strcmp(value[1].data, "off") == 0) { | |
823 ucf->mark = '\0'; | |
824 return NGX_CONF_OK; | |
825 } | |
826 | |
827 if (value[1].len != 1 | |
828 || !((value[1].data[0] >= '0' && value[1].data[0] <= '9') | |
829 || (value[1].data[0] >= 'A' && value[1].data[0] <= 'Z') | |
830 || (value[1].data[0] >= 'a' && value[1].data[0] <= 'z') | |
831 || value[1].data[0] == '=')) | |
832 { | |
833 return "value must be \"off\" or a single letter, digit or \"=\""; | |
834 } | |
835 | |
836 ucf->mark = value[1].data[0]; | |
837 | |
838 return NGX_CONF_OK; | |
839 } | |
1651
555ee689cecc
use usec and pid as start value
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
840 |
555ee689cecc
use usec and pid as start value
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
841 |
555ee689cecc
use usec and pid as start value
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
842 static ngx_int_t |
555ee689cecc
use usec and pid as start value
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
843 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
|
844 { |
555ee689cecc
use usec and pid as start value
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
845 struct timeval tp; |
555ee689cecc
use usec and pid as start value
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
846 |
555ee689cecc
use usec and pid as start value
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
847 ngx_gettimeofday(&tp); |
555ee689cecc
use usec and pid as start value
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
848 |
555ee689cecc
use usec and pid as start value
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
849 /* use the most significant usec part that fits to 16 bits */ |
6626
b3682580c1bd
Avoid left-shifting integers into the sign bit, which is undefined.
Sergey Kandaurov <pluknet@nginx.com>
parents:
4499
diff
changeset
|
850 start_value = (((uint32_t) tp.tv_usec / 20) << 16) | ngx_pid; |
1651
555ee689cecc
use usec and pid as start value
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
851 |
555ee689cecc
use usec and pid as start value
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
852 return NGX_OK; |
555ee689cecc
use usec and pid as start value
Igor Sysoev <igor@sysoev.ru>
parents:
1640
diff
changeset
|
853 } |