annotate src/http/modules/ngx_http_secure_link_module.c @ 3759:c0a91131a12b

bump version
author Igor Sysoev <igor@sysoev.ru>
date Mon, 06 Sep 2010 11:07:07 +0000
parents 7224d008faaf
children 38f74d11e5bd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2260
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
2 /*
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
3 * Copyright (C) Igor Sysoev
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4 */
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
5
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
6
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
7 #include <ngx_config.h>
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
8 #include <ngx_core.h>
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
9 #include <ngx_http.h>
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
10 #include <ngx_md5.h>
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
11
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
12
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
13 typedef struct {
3756
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
14 ngx_http_complex_value_t *variable;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
15 ngx_http_complex_value_t *md5;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
16 ngx_str_t secret;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
17 ngx_flag_t expires;
2260
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
18 } ngx_http_secure_link_conf_t;
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
19
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
20
3756
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
21 typedef struct {
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
22 ngx_str_t expires;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
23 } ngx_http_secure_link_ctx_t;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
24
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
25
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
26 static ngx_int_t ngx_http_secure_link_old_variable(ngx_http_request_t *r,
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
27 ngx_http_secure_link_conf_t *conf, ngx_http_variable_value_t *v,
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
28 uintptr_t data);
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
29 static ngx_int_t ngx_http_secure_link_expires_variable(ngx_http_request_t *r,
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
30 ngx_http_variable_value_t *v, uintptr_t data);
2260
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
31 static void *ngx_http_secure_link_create_conf(ngx_conf_t *cf);
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
32 static char *ngx_http_secure_link_merge_conf(ngx_conf_t *cf, void *parent,
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
33 void *child);
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
34 static ngx_int_t ngx_http_secure_link_add_variables(ngx_conf_t *cf);
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
35
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
36
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
37 static ngx_command_t ngx_http_secure_link_commands[] = {
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
38
3756
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
39 { ngx_string("secure_link"),
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
40 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
41 ngx_http_set_comlex_value_slot,
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
42 NGX_HTTP_LOC_CONF_OFFSET,
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
43 offsetof(ngx_http_secure_link_conf_t, variable),
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
44 NULL },
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
45
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
46 { ngx_string("secure_link_md5"),
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
47 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
48 ngx_http_set_comlex_value_slot,
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
49 NGX_HTTP_LOC_CONF_OFFSET,
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
50 offsetof(ngx_http_secure_link_conf_t, md5),
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
51 NULL },
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
52
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
53 { ngx_string("secure_link_expires"),
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
54 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
55 ngx_conf_set_flag_slot,
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
56 NGX_HTTP_LOC_CONF_OFFSET,
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
57 offsetof(ngx_http_secure_link_conf_t, expires),
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
58 NULL },
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
59
2260
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
60 { ngx_string("secure_link_secret"),
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
61 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
62 ngx_conf_set_str_slot,
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
63 NGX_HTTP_LOC_CONF_OFFSET,
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
64 offsetof(ngx_http_secure_link_conf_t, secret),
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
65 NULL },
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
66
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
67 ngx_null_command
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
68 };
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
69
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
70
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
71 static ngx_http_module_t ngx_http_secure_link_module_ctx = {
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
72 ngx_http_secure_link_add_variables, /* preconfiguration */
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
73 NULL, /* postconfiguration */
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
74
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
75 NULL, /* create main configuration */
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
76 NULL, /* init main configuration */
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
77
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
78 NULL, /* create server configuration */
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
79 NULL, /* merge server configuration */
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
80
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
81 ngx_http_secure_link_create_conf, /* create location configuration */
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
82 ngx_http_secure_link_merge_conf /* merge location configuration */
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
83 };
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
84
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
85
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
86 ngx_module_t ngx_http_secure_link_module = {
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
87 NGX_MODULE_V1,
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
88 &ngx_http_secure_link_module_ctx, /* module context */
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
89 ngx_http_secure_link_commands, /* module directives */
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
90 NGX_HTTP_MODULE, /* module type */
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
91 NULL, /* init master */
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
92 NULL, /* init module */
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
93 NULL, /* init process */
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
94 NULL, /* init thread */
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
95 NULL, /* exit thread */
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
96 NULL, /* exit process */
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
97 NULL, /* exit master */
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
98 NGX_MODULE_V1_PADDING
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
99 };
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
100
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
101
3756
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
102 static ngx_str_t ngx_http_secure_link_name = ngx_string("secure_link");
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
103 static ngx_str_t ngx_http_secure_link_expires_name =
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
104 ngx_string("secure_link_expires");
2260
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
105
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
106
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
107 static ngx_int_t
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
108 ngx_http_secure_link_variable(ngx_http_request_t *r,
3756
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
109 ngx_http_variable_value_t *v, uintptr_t data)
2260
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
110 {
3756
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
111 u_char *p, *last;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
112 ngx_str_t val, hash;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
113 time_t expires;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
114 ngx_md5_t md5;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
115 ngx_http_secure_link_ctx_t *ctx;
2260
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
116 ngx_http_secure_link_conf_t *conf;
3756
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
117 u_char hash_buf[16], md5_buf[16];
2260
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
118
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
119 conf = ngx_http_get_module_loc_conf(r, ngx_http_secure_link_module);
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
120
3756
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
121 if (conf->secret.len) {
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
122 return ngx_http_secure_link_old_variable(r, conf, v, data);
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
123 }
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
124
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
125 if (conf->variable == NULL || conf->md5 == NULL) {
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
126 goto not_found;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
127 }
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
128
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
129 if (ngx_http_complex_value(r, conf->variable, &val) != NGX_OK) {
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
130 return NGX_ERROR;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
131 }
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
132
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
133 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
134 "secure link: \"%V\"", &val);
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
135
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
136 last = val.data + val.len;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
137
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
138 p = ngx_strlchr(val.data, last, ',');
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
139 expires = 0;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
140
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
141 if (p) {
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
142 val.len = p++ - val.data;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
143
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
144 if (conf->expires) {
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
145 expires = ngx_atotm(p, last - p);
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
146 if (expires <= 0) {
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
147 goto not_found;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
148 }
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
149
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
150 ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_secure_link_ctx_t));
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
151 if (ctx == NULL) {
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
152 return NGX_ERROR;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
153 }
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
154
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
155 ngx_http_set_ctx(r, ctx, ngx_http_secure_link_module);
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
156
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
157 ctx->expires.len = last - p;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
158 ctx->expires.data = p;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
159 }
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
160 }
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
161
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
162 if (val.len > 24) {
2260
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
163 goto not_found;
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
164 }
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
165
3756
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
166 hash.len = 16;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
167 hash.data = hash_buf;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
168
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
169 if (ngx_decode_base64url(&hash, &val) != NGX_OK) {
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
170 goto not_found;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
171 }
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
172
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
173 if (hash.len != 16) {
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
174 goto not_found;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
175 }
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
176
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
177 if (ngx_http_complex_value(r, conf->md5, &val) != NGX_OK) {
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
178 return NGX_ERROR;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
179 }
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
180
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
181 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
182 "secure link md5: \"%V\"", &val);
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
183
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
184 ngx_md5_init(&md5);
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
185 ngx_md5_update(&md5, val.data, val.len);
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
186 ngx_md5_final(md5_buf, &md5);
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
187
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
188 if (ngx_memcmp(hash_buf, md5_buf, 16) != 0) {
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
189 goto not_found;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
190 }
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
191
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
192 v->data = (u_char *) ((expires && expires < ngx_time()) ? "0" : "1");
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
193 v->len = 1;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
194 v->valid = 1;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
195 v->no_cacheable = 0;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
196 v->not_found = 0;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
197
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
198 return NGX_OK;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
199
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
200 not_found:
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
201
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
202 v->not_found = 1;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
203
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
204 return NGX_OK;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
205 }
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
206
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
207
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
208 static ngx_int_t
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
209 ngx_http_secure_link_old_variable(ngx_http_request_t *r,
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
210 ngx_http_secure_link_conf_t *conf, ngx_http_variable_value_t *v,
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
211 uintptr_t data)
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
212 {
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
213 u_char *p, *start, *end, *last;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
214 size_t len;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
215 ngx_int_t n;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
216 ngx_uint_t i;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
217 ngx_md5_t md5;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
218 u_char hash[16];
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
219
2260
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
220 p = &r->unparsed_uri.data[1];
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
221 last = r->unparsed_uri.data + r->unparsed_uri.len;
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
222
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
223 while (p < last) {
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
224 if (*p++ == '/') {
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
225 start = p;
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
226 goto md5_start;
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
227 }
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
228 }
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
229
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
230 goto not_found;
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
231
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
232 md5_start:
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
233
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
234 while (p < last) {
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
235 if (*p++ == '/') {
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
236 end = p - 1;
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
237 goto url_start;
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
238 }
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
239 }
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
240
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
241 goto not_found;
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
242
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
243 url_start:
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
244
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
245 len = last - p;
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
246
2279
bbb17a60ec44 allow short secure links
Igor Sysoev <igor@sysoev.ru>
parents: 2260
diff changeset
247 if (end - start != 32 || len == 0) {
2260
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
248 goto not_found;
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
249 }
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
250
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
251 ngx_md5_init(&md5);
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
252 ngx_md5_update(&md5, p, len);
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
253 ngx_md5_update(&md5, conf->secret.data, conf->secret.len);
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
254 ngx_md5_final(hash, &md5);
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
255
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
256 for (i = 0; i < 16; i++) {
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
257 n = ngx_hextoi(&start[2 * i], 2);
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
258 if (n == NGX_ERROR || n != hash[i]) {
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
259 goto not_found;
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
260 }
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
261 }
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
262
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
263 v->len = len;
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
264 v->valid = 1;
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
265 v->no_cacheable = 0;
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
266 v->not_found = 0;
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
267 v->data = p;
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
268
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
269 return NGX_OK;
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
270
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
271 not_found:
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
272
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
273 v->not_found = 1;
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
274
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
275 return NGX_OK;
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
276 }
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
277
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
278
3756
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
279 static ngx_int_t
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
280 ngx_http_secure_link_expires_variable(ngx_http_request_t *r,
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
281 ngx_http_variable_value_t *v, uintptr_t data)
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
282 {
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
283 ngx_http_secure_link_ctx_t *ctx;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
284
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
285 ctx = ngx_http_get_module_ctx(r, ngx_http_secure_link_module);
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
286
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
287 if (ctx) {
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
288 v->len = ctx->expires.len;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
289 v->valid = 1;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
290 v->no_cacheable = 0;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
291 v->not_found = 0;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
292 v->data = ctx->expires.data;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
293
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
294 } else {
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
295 v->not_found = 1;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
296 }
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
297
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
298 return NGX_OK;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
299 }
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
300
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
301
2260
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
302 static void *
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
303 ngx_http_secure_link_create_conf(ngx_conf_t *cf)
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
304 {
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
305 ngx_http_secure_link_conf_t *conf;
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
306
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
307 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_secure_link_conf_t));
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
308 if (conf == NULL) {
2912
c7d57b539248 return NULL instead of NGX_CONF_ERROR on a create conf failure
Igor Sysoev <igor@sysoev.ru>
parents: 2279
diff changeset
309 return NULL;
2260
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
310 }
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
311
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
312 /*
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
313 * set by ngx_pcalloc():
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
314 *
3756
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
315 * conf->variable = NULL;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
316 * conf->md5 = NULL;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
317 * conf->secret = { 0, NULL };
2260
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
318 */
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
319
3756
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
320 conf->expires = NGX_CONF_UNSET;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
321
2260
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
322 return conf;
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
323 }
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
324
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
325
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
326 static char *
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
327 ngx_http_secure_link_merge_conf(ngx_conf_t *cf, void *parent, void *child)
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
328 {
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
329 ngx_http_secure_link_conf_t *prev = parent;
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
330 ngx_http_secure_link_conf_t *conf = child;
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
331
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
332 ngx_conf_merge_str_value(conf->secret, prev->secret, "");
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
333
3756
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
334 if (conf->variable == NULL) {
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
335 conf->variable = prev->variable;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
336 }
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
337
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
338 if (conf->md5 == NULL) {
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
339 conf->md5 = prev->md5;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
340 }
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
341
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
342 ngx_conf_merge_value(conf->expires, prev->expires, 0);
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
343
2260
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
344 return NGX_CONF_OK;
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
345 }
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
346
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
347
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
348 static ngx_int_t
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
349 ngx_http_secure_link_add_variables(ngx_conf_t *cf)
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
350 {
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
351 ngx_http_variable_t *var;
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
352
3756
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
353 var = ngx_http_add_variable(cf, &ngx_http_secure_link_name, 0);
2260
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
354 if (var == NULL) {
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
355 return NGX_ERROR;
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
356 }
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
357
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
358 var->get_handler = ngx_http_secure_link_variable;
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
359
3756
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
360 var = ngx_http_add_variable(cf, &ngx_http_secure_link_expires_name, 0);
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
361 if (var == NULL) {
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
362 return NGX_ERROR;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
363 }
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
364
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
365 var->get_handler = ngx_http_secure_link_expires_variable;
7224d008faaf new ngx_http_secure_link_module with secure_link, secure_link_md5, and
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
366
2260
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
367 return NGX_OK;
4f1616b32744 ngx_http_secure_link_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
368 }