|
|
@@ -0,0 +1,852 @@
|
|
|
1
|
+
|
|
|
2
|
+/*
|
|
|
3
|
+ * Copyright (C) 2007 Brice Figureau
|
|
|
4
|
+ */
|
|
|
5
|
+
|
|
|
6
|
+#include <ngx_config.h>
|
|
|
7
|
+#include <ngx_core.h>
|
|
|
8
|
+#include <ngx_http.h>
|
|
|
9
|
+
|
|
|
10
|
+typedef struct {
|
|
|
11
|
+ u_char color;
|
|
|
12
|
+ ngx_http_request_t *r;
|
|
|
13
|
+ u_char len;
|
|
|
14
|
+ u_char data[1];
|
|
|
15
|
+} ngx_http_uploadprogress_node_t;
|
|
|
16
|
+
|
|
|
17
|
+
|
|
|
18
|
+typedef struct {
|
|
|
19
|
+ ngx_shm_zone_t *shm_zone;
|
|
|
20
|
+ ngx_rbtree_node_t *node;
|
|
|
21
|
+} ngx_http_uploadprogress_cleanup_t;
|
|
|
22
|
+
|
|
|
23
|
+typedef struct {
|
|
|
24
|
+ ngx_rbtree_t *rbtree;
|
|
|
25
|
+} ngx_http_uploadprogress_ctx_t;
|
|
|
26
|
+
|
|
|
27
|
+typedef struct {
|
|
|
28
|
+ ngx_shm_zone_t *shm_zone;
|
|
|
29
|
+ u_char track;
|
|
|
30
|
+} ngx_http_uploadprogress_conf_t;
|
|
|
31
|
+
|
|
|
32
|
+static ngx_int_t ngx_http_reportuploads_handler(ngx_http_request_t *r);
|
|
|
33
|
+static ngx_int_t ngx_http_reportuploads_handler(ngx_http_request_t *r);
|
|
|
34
|
+static void ngx_http_uploadprogress_cleanup(void *data);
|
|
|
35
|
+static char *ngx_http_report_uploads(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
|
|
36
|
+static ngx_int_t ngx_http_uploadprogress_init_zone(ngx_shm_zone_t *shm_zone, void *data);
|
|
|
37
|
+static ngx_int_t ngx_http_uploadprogress_init(ngx_conf_t *cf);
|
|
|
38
|
+static void *ngx_http_uploadprogress_create_loc_conf(ngx_conf_t *cf);
|
|
|
39
|
+static char *ngx_http_uploadprogress_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child);
|
|
|
40
|
+static char *ngx_http_track_uploads(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
|
|
41
|
+static char *ngx_http_report_uploads(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
|
|
42
|
+static char *ngx_http_upload_progress(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
|
|
|
43
|
+
|
|
|
44
|
+static ngx_command_t ngx_http_uploadprogress_commands[] = {
|
|
|
45
|
+
|
|
|
46
|
+ { ngx_string("upload_progress"),
|
|
|
47
|
+ NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE2,
|
|
|
48
|
+ ngx_http_upload_progress,
|
|
|
49
|
+ 0,
|
|
|
50
|
+ 0,
|
|
|
51
|
+ NULL },
|
|
|
52
|
+
|
|
|
53
|
+ { ngx_string("track_uploads"),
|
|
|
54
|
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
|
55
|
+ ngx_http_track_uploads,
|
|
|
56
|
+ NGX_HTTP_LOC_CONF_OFFSET,
|
|
|
57
|
+ 0,
|
|
|
58
|
+ NULL },
|
|
|
59
|
+
|
|
|
60
|
+ { ngx_string("report_uploads"),
|
|
|
61
|
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
|
|
|
62
|
+ ngx_http_report_uploads,
|
|
|
63
|
+ NGX_HTTP_LOC_CONF_OFFSET,
|
|
|
64
|
+ 0,
|
|
|
65
|
+ NULL },
|
|
|
66
|
+
|
|
|
67
|
+ ngx_null_command
|
|
|
68
|
+};
|
|
|
69
|
+
|
|
|
70
|
+
|
|
|
71
|
+static ngx_http_module_t ngx_http_uploadprogress_module_ctx = {
|
|
|
72
|
+ NULL, /* preconfiguration */
|
|
|
73
|
+ ngx_http_uploadprogress_init, /* postconfiguration */
|
|
|
74
|
+
|
|
|
75
|
+ NULL, /* create main configuration */
|
|
|
76
|
+ NULL, /* init main configuration */
|
|
|
77
|
+
|
|
|
78
|
+ NULL, /* create server configuration */
|
|
|
79
|
+ NULL, /* merge server configuration */
|
|
|
80
|
+
|
|
|
81
|
+ ngx_http_uploadprogress_create_loc_conf, /* create location configuration */
|
|
|
82
|
+ ngx_http_uploadprogress_merge_loc_conf /* merge location configuration */
|
|
|
83
|
+};
|
|
|
84
|
+
|
|
|
85
|
+
|
|
|
86
|
+ngx_module_t ngx_http_uploadprogress_module = {
|
|
|
87
|
+ NGX_MODULE_V1,
|
|
|
88
|
+ &ngx_http_uploadprogress_module_ctx, /* module context */
|
|
|
89
|
+ ngx_http_uploadprogress_commands, /* module directives */
|
|
|
90
|
+ NGX_HTTP_MODULE, /* module type */
|
|
|
91
|
+ NULL, /* init master */
|
|
|
92
|
+ NULL, /* init module */
|
|
|
93
|
+ NULL, /* init process */
|
|
|
94
|
+ NULL, /* init thread */
|
|
|
95
|
+ NULL, /* exit thread */
|
|
|
96
|
+ NULL, /* exit process */
|
|
|
97
|
+ NULL, /* exit master */
|
|
|
98
|
+ NGX_MODULE_V1_PADDING
|
|
|
99
|
+};
|
|
|
100
|
+
|
|
|
101
|
+static ngx_str_t x_progress_id = ngx_string("X-Progress-ID");
|
|
|
102
|
+
|
|
|
103
|
+static ngx_str_t*
|
|
|
104
|
+get_tracking_id(ngx_http_request_t *r)
|
|
|
105
|
+{
|
|
|
106
|
+ u_char *p,*start_p;
|
|
|
107
|
+ ngx_uint_t i;
|
|
|
108
|
+ ngx_list_part_t *part;
|
|
|
109
|
+ ngx_table_elt_t *header;
|
|
|
110
|
+ ngx_str_t *ret;
|
|
|
111
|
+
|
|
|
112
|
+ part = &r->headers_in.headers.part;
|
|
|
113
|
+ header = part->elts;
|
|
|
114
|
+
|
|
|
115
|
+ for (i = 0; /* void */; i++) {
|
|
|
116
|
+
|
|
|
117
|
+ if (i >= part->nelts) {
|
|
|
118
|
+ if (part->next == NULL) {
|
|
|
119
|
+ break;
|
|
|
120
|
+ }
|
|
|
121
|
+
|
|
|
122
|
+ part = part->next;
|
|
|
123
|
+ header = part->elts;
|
|
|
124
|
+ i = 0;
|
|
|
125
|
+ }
|
|
|
126
|
+
|
|
|
127
|
+ if (header[i].key.len == x_progress_id.len && ngx_strncmp(header[i].key.data, x_progress_id.data,header[i].key.len) == 0)
|
|
|
128
|
+ {
|
|
|
129
|
+ ret = ngx_pcalloc(r->pool, sizeof(ngx_str_t));
|
|
|
130
|
+ ret->data = header[i].value.data;
|
|
|
131
|
+ ret->len = header[i].value.len;
|
|
|
132
|
+ return ret;
|
|
|
133
|
+ }
|
|
|
134
|
+ }
|
|
|
135
|
+
|
|
|
136
|
+ /* not found, check as a reaquest arg */
|
|
|
137
|
+ if (r->args.len) {
|
|
|
138
|
+ p = (u_char *) ngx_strstr(r->args.data, "X-Progress-ID=");
|
|
|
139
|
+
|
|
|
140
|
+ if (p) {
|
|
|
141
|
+ start_p = p += 14;
|
|
|
142
|
+ while (p < r->args.data + r->args.len) {
|
|
|
143
|
+ if (*p++ != '&') {
|
|
|
144
|
+ continue;
|
|
|
145
|
+ }
|
|
|
146
|
+ }
|
|
|
147
|
+
|
|
|
148
|
+ ret = ngx_pcalloc(r->pool, sizeof(ngx_str_t));
|
|
|
149
|
+ ret->data = start_p;
|
|
|
150
|
+ ret->len = p-start_p;
|
|
|
151
|
+ return ret;
|
|
|
152
|
+ }
|
|
|
153
|
+ }
|
|
|
154
|
+
|
|
|
155
|
+ return NULL;
|
|
|
156
|
+}
|
|
|
157
|
+
|
|
|
158
|
+
|
|
|
159
|
+/* This generates the response for the report */
|
|
|
160
|
+static ngx_int_t
|
|
|
161
|
+ngx_http_reportuploads_handler(ngx_http_request_t *r)
|
|
|
162
|
+{
|
|
|
163
|
+ ngx_str_t *id;
|
|
|
164
|
+ ngx_buf_t *b;
|
|
|
165
|
+ ngx_chain_t out;
|
|
|
166
|
+ ngx_http_request_t *orig;
|
|
|
167
|
+ ngx_int_t rc, size;
|
|
|
168
|
+ uint32_t hash;
|
|
|
169
|
+ ngx_slab_pool_t *shpool;
|
|
|
170
|
+ ngx_rbtree_node_t *node, *sentinel;
|
|
|
171
|
+ ngx_http_uploadprogress_conf_t *lzcf;
|
|
|
172
|
+ ngx_http_uploadprogress_ctx_t *ctx;
|
|
|
173
|
+ ngx_http_uploadprogress_node_t *lz;
|
|
|
174
|
+ ngx_table_elt_t *expires, *cc, **ccp;
|
|
|
175
|
+
|
|
|
176
|
+ if (r->method != NGX_HTTP_GET && r->method != NGX_HTTP_HEAD) {
|
|
|
177
|
+ return NGX_HTTP_NOT_ALLOWED;
|
|
|
178
|
+ }
|
|
|
179
|
+
|
|
|
180
|
+ rc = ngx_http_discard_request_body(r);
|
|
|
181
|
+
|
|
|
182
|
+ if (rc != NGX_OK) {
|
|
|
183
|
+ return rc;
|
|
|
184
|
+ }
|
|
|
185
|
+
|
|
|
186
|
+ /* get the tracking id if any */
|
|
|
187
|
+ id = get_tracking_id(r);
|
|
|
188
|
+
|
|
|
189
|
+
|
|
|
190
|
+ if ( id == NULL )
|
|
|
191
|
+ {
|
|
|
192
|
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
|
193
|
+ "reportuploads handler cant find id");
|
|
|
194
|
+ return NGX_DECLINED;
|
|
|
195
|
+ }
|
|
|
196
|
+
|
|
|
197
|
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
|
198
|
+ "reportuploads handler found id: %V", id);
|
|
|
199
|
+
|
|
|
200
|
+ lzcf = ngx_http_get_module_loc_conf(r, ngx_http_uploadprogress_module);
|
|
|
201
|
+
|
|
|
202
|
+ if (lzcf->shm_zone == NULL) {
|
|
|
203
|
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
|
204
|
+ "reportuploads no shm_zone for id: %V", id);
|
|
|
205
|
+ return NGX_DECLINED;
|
|
|
206
|
+ }
|
|
|
207
|
+
|
|
|
208
|
+ orig = NULL;
|
|
|
209
|
+ ctx = lzcf->shm_zone->data;
|
|
|
210
|
+
|
|
|
211
|
+ hash = ngx_crc32_short(id->data, id->len);
|
|
|
212
|
+
|
|
|
213
|
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
|
214
|
+ "reportuploads trying to find block with hash %08XD for id: %V", hash, id);
|
|
|
215
|
+
|
|
|
216
|
+ /* get the original connection of the upload */
|
|
|
217
|
+ shpool = (ngx_slab_pool_t *) lzcf->shm_zone->shm.addr;
|
|
|
218
|
+ ngx_shmtx_lock(&shpool->mutex);
|
|
|
219
|
+
|
|
|
220
|
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
|
221
|
+ "reportuploads in mutex lock for hash %08XD for id: %V", hash, id);
|
|
|
222
|
+
|
|
|
223
|
+ node = ctx->rbtree->root;
|
|
|
224
|
+ sentinel = ctx->rbtree->sentinel;
|
|
|
225
|
+
|
|
|
226
|
+ ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
|
227
|
+ "reportuploads root %p, sentinel %p for id: %V", node,sentinel, id);
|
|
|
228
|
+
|
|
|
229
|
+ while (node != sentinel) {
|
|
|
230
|
+
|
|
|
231
|
+ if (hash < node->key) {
|
|
|
232
|
+ node = node->left;
|
|
|
233
|
+ continue;
|
|
|
234
|
+ }
|
|
|
235
|
+
|
|
|
236
|
+ if (hash > node->key) {
|
|
|
237
|
+ node = node->right;
|
|
|
238
|
+ continue;
|
|
|
239
|
+ }
|
|
|
240
|
+
|
|
|
241
|
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
|
242
|
+ "reportuploads found matching hash %08XD, node %p for id: %V", hash, node, id);
|
|
|
243
|
+
|
|
|
244
|
+ /* hash == node->key */
|
|
|
245
|
+
|
|
|
246
|
+ do {
|
|
|
247
|
+ lz = (ngx_http_uploadprogress_node_t *) &node->color;
|
|
|
248
|
+
|
|
|
249
|
+ rc = ngx_memn2cmp(id->data, lz->data, id->len, (size_t) lz->len);
|
|
|
250
|
+
|
|
|
251
|
+ if (rc == 0) {
|
|
|
252
|
+ /* found the right one */
|
|
|
253
|
+ /* lz contains the right node*/
|
|
|
254
|
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
|
255
|
+ "reportuploads found request: %p", lz->r);
|
|
|
256
|
+ orig = lz->r;
|
|
|
257
|
+ goto found;
|
|
|
258
|
+ }
|
|
|
259
|
+
|
|
|
260
|
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
|
261
|
+ "reportuploads oops not the same : lz %V != id %V", lz, id);
|
|
|
262
|
+
|
|
|
263
|
+
|
|
|
264
|
+ node = (rc < 0) ? node->left : node->right;
|
|
|
265
|
+
|
|
|
266
|
+ } while (node != sentinel && hash == node->key);
|
|
|
267
|
+
|
|
|
268
|
+ lz = NULL;
|
|
|
269
|
+
|
|
|
270
|
+ /* couldn't find one */
|
|
|
271
|
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
|
272
|
+ "reportuploads not matching request");
|
|
|
273
|
+ }
|
|
|
274
|
+
|
|
|
275
|
+found:
|
|
|
276
|
+ ngx_shmtx_unlock(&shpool->mutex);
|
|
|
277
|
+
|
|
|
278
|
+ /* send the output */
|
|
|
279
|
+ r->headers_out.content_type.len = sizeof("text/javascript") - 1;
|
|
|
280
|
+ r->headers_out.content_type.data = (u_char *) "text/javascript";
|
|
|
281
|
+
|
|
|
282
|
+ /* no-cache */
|
|
|
283
|
+
|
|
|
284
|
+ expires = r->headers_out.expires;
|
|
|
285
|
+
|
|
|
286
|
+ if (expires == NULL) {
|
|
|
287
|
+
|
|
|
288
|
+ expires = ngx_list_push(&r->headers_out.headers);
|
|
|
289
|
+ if (expires == NULL) {
|
|
|
290
|
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
|
291
|
+ }
|
|
|
292
|
+
|
|
|
293
|
+ r->headers_out.expires = expires;
|
|
|
294
|
+
|
|
|
295
|
+ expires->hash = 1;
|
|
|
296
|
+ expires->key.len = sizeof("Expires") - 1;
|
|
|
297
|
+ expires->key.data = (u_char *) "Expires";
|
|
|
298
|
+ }
|
|
|
299
|
+
|
|
|
300
|
+ len = sizeof("Mon, 28 Sep 1970 06:00:00 GMT");
|
|
|
301
|
+ expires->value.len = len - 1;
|
|
|
302
|
+
|
|
|
303
|
+ ccp = r->headers_out.cache_control.elts;
|
|
|
304
|
+ if (ccp == NULL) {
|
|
|
305
|
+
|
|
|
306
|
+ if (ngx_array_init(&r->headers_out.cache_control, r->pool,
|
|
|
307
|
+ 1, sizeof(ngx_table_elt_t *))
|
|
|
308
|
+ != NGX_OK)
|
|
|
309
|
+ {
|
|
|
310
|
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
|
311
|
+ }
|
|
|
312
|
+
|
|
|
313
|
+ ccp = ngx_array_push(&r->headers_out.cache_control);
|
|
|
314
|
+ if (ccp == NULL) {
|
|
|
315
|
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
|
316
|
+ }
|
|
|
317
|
+
|
|
|
318
|
+ cc = ngx_list_push(&r->headers_out.headers);
|
|
|
319
|
+ if (cc == NULL) {
|
|
|
320
|
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
|
321
|
+ }
|
|
|
322
|
+
|
|
|
323
|
+ cc->hash = 1;
|
|
|
324
|
+ cc->key.len = sizeof("Cache-Control") - 1;
|
|
|
325
|
+ cc->key.data = (u_char *) "Cache-Control";
|
|
|
326
|
+
|
|
|
327
|
+ *ccp = cc;
|
|
|
328
|
+
|
|
|
329
|
+ } else {
|
|
|
330
|
+ for (i = 1; i < r->headers_out.cache_control.nelts; i++) {
|
|
|
331
|
+ ccp[i]->hash = 0;
|
|
|
332
|
+ }
|
|
|
333
|
+
|
|
|
334
|
+ cc = ccp[0];
|
|
|
335
|
+ }
|
|
|
336
|
+
|
|
|
337
|
+ expires->value.data = (u_char *) "Thu, 01 Jan 1970 00:00:01 GMT";
|
|
|
338
|
+
|
|
|
339
|
+ cc->value.len = sizeof("no-cache") - 1;
|
|
|
340
|
+ cc->value.data = (u_char *) "no-cache";
|
|
|
341
|
+
|
|
|
342
|
+
|
|
|
343
|
+ if (r->method == NGX_HTTP_HEAD) {
|
|
|
344
|
+ r->headers_out.status = NGX_HTTP_OK;
|
|
|
345
|
+
|
|
|
346
|
+ rc = ngx_http_send_header(r);
|
|
|
347
|
+
|
|
|
348
|
+ if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
|
|
|
349
|
+ return rc;
|
|
|
350
|
+ }
|
|
|
351
|
+ }
|
|
|
352
|
+
|
|
|
353
|
+ if ( orig == NULL )
|
|
|
354
|
+ {
|
|
|
355
|
+ if (lz != NULL )
|
|
|
356
|
+ {
|
|
|
357
|
+ size = sizeof("new Object({ 'state' : 'done' })\r\n");
|
|
|
358
|
+ }
|
|
|
359
|
+ else
|
|
|
360
|
+ {
|
|
|
361
|
+ size = sizeof("new Object({ 'state' : 'starting' })\r\n");
|
|
|
362
|
+ }
|
|
|
363
|
+ }
|
|
|
364
|
+ else if ( orig->err_status == 413)
|
|
|
365
|
+ {
|
|
|
366
|
+ size = sizeof("new Object({ 'state' : 'error', 'status' : 413 })\r\n");
|
|
|
367
|
+ }
|
|
|
368
|
+ else
|
|
|
369
|
+ {
|
|
|
370
|
+ size = sizeof("new Object({ 'state' : 'uploading', 'received' : ") + NGX_INT_T_LEN + sizeof(" })\r\n");
|
|
|
371
|
+ size += sizeof(", 'size' : ") + NGX_INT_T_LEN;
|
|
|
372
|
+ }
|
|
|
373
|
+
|
|
|
374
|
+ b = ngx_create_temp_buf(r->pool, size);
|
|
|
375
|
+ if (b == NULL) {
|
|
|
376
|
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
|
377
|
+ }
|
|
|
378
|
+
|
|
|
379
|
+ out.buf = b;
|
|
|
380
|
+ out.next = NULL;
|
|
|
381
|
+
|
|
|
382
|
+ if (orig == NULL)
|
|
|
383
|
+ {
|
|
|
384
|
+ if (lz == NULL )
|
|
|
385
|
+ {
|
|
|
386
|
+ b->last = ngx_cpymem(b->last, "new Object({ 'state' : 'starting' })\r\n",
|
|
|
387
|
+ sizeof("new Object({ 'state' : 'starting' })\r\n") - 1);
|
|
|
388
|
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
|
389
|
+ "reportuploads returning starting");
|
|
|
390
|
+ }
|
|
|
391
|
+ else
|
|
|
392
|
+ {
|
|
|
393
|
+ b->last = ngx_cpymem(b->last, "new Object({ 'state' : 'done' })\r\n",
|
|
|
394
|
+ sizeof("new Object({ 'state' : 'done' })\r\n") - 1);
|
|
|
395
|
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
|
396
|
+ "reportuploads returning done");
|
|
|
397
|
+ }
|
|
|
398
|
+ }
|
|
|
399
|
+ else if ( orig->err_status == 413)
|
|
|
400
|
+ {
|
|
|
401
|
+ b->last = ngx_cpymem(b->last, "new Object({ 'state' : 'error', 'status' : 413 })\r\n",
|
|
|
402
|
+ sizeof("new Object({ 'state' : 'error', 'status' : 413 })\r\n") - 1);
|
|
|
403
|
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
|
404
|
+ "reportuploads returning error 413");
|
|
|
405
|
+ }
|
|
|
406
|
+ else
|
|
|
407
|
+ {
|
|
|
408
|
+ b->last = ngx_cpymem(b->last,"new Object({ 'state' : 'uploading', 'received' : ",
|
|
|
409
|
+ sizeof("new Object({ 'state' : 'uploading', 'received' : ")-1 );
|
|
|
410
|
+
|
|
|
411
|
+ b->last = ngx_sprintf(b->last, "%uO, 'size' : %uO })\r\n", (orig->headers_in.content_length_n - orig->request_body->rest), orig->headers_in.content_length_n);
|
|
|
412
|
+
|
|
|
413
|
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
|
414
|
+ "reportuploads returning %uO / %uO", (orig->headers_in.content_length_n - orig->request_body->rest), orig->headers_in.content_length_n);
|
|
|
415
|
+
|
|
|
416
|
+ }
|
|
|
417
|
+
|
|
|
418
|
+ // force no caching for proxy
|
|
|
419
|
+
|
|
|
420
|
+
|
|
|
421
|
+ r->headers_out.status = NGX_HTTP_OK;
|
|
|
422
|
+ r->headers_out.content_length_n = b->last - b->pos;
|
|
|
423
|
+
|
|
|
424
|
+ b->last_buf = 1;
|
|
|
425
|
+ rc = ngx_http_send_header(r);
|
|
|
426
|
+
|
|
|
427
|
+ if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
|
|
|
428
|
+ return rc;
|
|
|
429
|
+ }
|
|
|
430
|
+
|
|
|
431
|
+ return ngx_http_output_filter(r, &out);;
|
|
|
432
|
+}
|
|
|
433
|
+
|
|
|
434
|
+/*
|
|
|
435
|
+This is the post read phase. It registers the upload connection in the rb tree
|
|
|
436
|
+*/
|
|
|
437
|
+static ngx_int_t
|
|
|
438
|
+ngx_http_uploadprogress_handler(ngx_http_request_t *r)
|
|
|
439
|
+{
|
|
|
440
|
+ size_t n;
|
|
|
441
|
+ ngx_str_t *id;
|
|
|
442
|
+ ngx_int_t rc;
|
|
|
443
|
+ uint32_t hash;
|
|
|
444
|
+ ngx_slab_pool_t *shpool;
|
|
|
445
|
+ ngx_rbtree_node_t *node, *sentinel;
|
|
|
446
|
+ ngx_http_uploadprogress_conf_t *lzcf;
|
|
|
447
|
+ ngx_http_uploadprogress_ctx_t *ctx;
|
|
|
448
|
+ ngx_http_uploadprogress_node_t *lz;
|
|
|
449
|
+ ngx_http_uploadprogress_cleanup_t *lzcln;
|
|
|
450
|
+ ngx_pool_cleanup_t *cln;
|
|
|
451
|
+
|
|
|
452
|
+ id = get_tracking_id(r);
|
|
|
453
|
+ if ( id == NULL )
|
|
|
454
|
+ {
|
|
|
455
|
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
|
456
|
+ "trackuploads no id found in POST upload req");
|
|
|
457
|
+ return NGX_DECLINED;
|
|
|
458
|
+ }
|
|
|
459
|
+
|
|
|
460
|
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
|
461
|
+ "trackuploads id found: %V", id);
|
|
|
462
|
+
|
|
|
463
|
+ lzcf = ngx_http_get_module_loc_conf(r, ngx_http_uploadprogress_module);
|
|
|
464
|
+
|
|
|
465
|
+ if (!lzcf->track) {
|
|
|
466
|
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
|
467
|
+ "trackuploads not tracking in this location for id: %V", id);
|
|
|
468
|
+ return NGX_DECLINED;
|
|
|
469
|
+ }
|
|
|
470
|
+
|
|
|
471
|
+ if (lzcf->shm_zone == NULL) {
|
|
|
472
|
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
|
473
|
+ "trackuploads no shm_zone for id: %V", id);
|
|
|
474
|
+ return NGX_DECLINED;
|
|
|
475
|
+ }
|
|
|
476
|
+
|
|
|
477
|
+ ctx = lzcf->shm_zone->data;
|
|
|
478
|
+
|
|
|
479
|
+ hash = ngx_crc32_short(id->data, id->len);
|
|
|
480
|
+
|
|
|
481
|
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
|
482
|
+ "trackuploads hash %08XD for id: %V",hash, id);
|
|
|
483
|
+
|
|
|
484
|
+ cln = ngx_pool_cleanup_add(r->pool, sizeof(ngx_http_uploadprogress_cleanup_t));
|
|
|
485
|
+ if (cln == NULL) {
|
|
|
486
|
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
|
487
|
+ }
|
|
|
488
|
+
|
|
|
489
|
+ shpool = (ngx_slab_pool_t *) lzcf->shm_zone->shm.addr;
|
|
|
490
|
+
|
|
|
491
|
+ ngx_shmtx_lock(&shpool->mutex);
|
|
|
492
|
+
|
|
|
493
|
+ node = ctx->rbtree->root;
|
|
|
494
|
+ sentinel = ctx->rbtree->sentinel;
|
|
|
495
|
+
|
|
|
496
|
+ while (node != sentinel) {
|
|
|
497
|
+
|
|
|
498
|
+ if (hash < node->key) {
|
|
|
499
|
+ node = node->left;
|
|
|
500
|
+ continue;
|
|
|
501
|
+ }
|
|
|
502
|
+
|
|
|
503
|
+ if (hash > node->key) {
|
|
|
504
|
+ node = node->right;
|
|
|
505
|
+ continue;
|
|
|
506
|
+ }
|
|
|
507
|
+
|
|
|
508
|
+ /* hash == node->key */
|
|
|
509
|
+
|
|
|
510
|
+ do {
|
|
|
511
|
+ lz = (ngx_http_uploadprogress_node_t *) &node->color;
|
|
|
512
|
+
|
|
|
513
|
+ rc = ngx_memn2cmp(id->data, lz->data, id->len, (size_t) lz->len);
|
|
|
514
|
+
|
|
|
515
|
+ if (rc == 0) {
|
|
|
516
|
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
|
517
|
+ "trackuploads already registered: %V",id);
|
|
|
518
|
+ /* oops found already one */
|
|
|
519
|
+ ngx_shmtx_unlock(&shpool->mutex);
|
|
|
520
|
+
|
|
|
521
|
+ return NGX_HTTP_SERVICE_UNAVAILABLE;
|
|
|
522
|
+ }
|
|
|
523
|
+
|
|
|
524
|
+ node = (rc < 0) ? node->left : node->right;
|
|
|
525
|
+
|
|
|
526
|
+ } while (node != sentinel && hash == node->key);
|
|
|
527
|
+
|
|
|
528
|
+ break;
|
|
|
529
|
+ }
|
|
|
530
|
+
|
|
|
531
|
+ n = offsetof(ngx_rbtree_node_t, color)
|
|
|
532
|
+ + offsetof(ngx_http_uploadprogress_node_t, data)
|
|
|
533
|
+ + id->len;
|
|
|
534
|
+
|
|
|
535
|
+ node = ngx_slab_alloc_locked(shpool, n);
|
|
|
536
|
+ if (node == NULL) {
|
|
|
537
|
+ ngx_shmtx_unlock(&shpool->mutex);
|
|
|
538
|
+ return NGX_HTTP_SERVICE_UNAVAILABLE;
|
|
|
539
|
+ }
|
|
|
540
|
+
|
|
|
541
|
+ lz = (ngx_http_uploadprogress_node_t *) &node->color;
|
|
|
542
|
+
|
|
|
543
|
+ node->key = hash;
|
|
|
544
|
+ lz->len = (u_char) id->len;
|
|
|
545
|
+ lz->r = r;
|
|
|
546
|
+ ngx_memcpy(lz->data, id->data, id->len);
|
|
|
547
|
+
|
|
|
548
|
+ ngx_rbtree_insert(ctx->rbtree, node);
|
|
|
549
|
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
|
550
|
+ "trackuploads: %08XD", node->key);
|
|
|
551
|
+
|
|
|
552
|
+ ngx_shmtx_unlock(&shpool->mutex);
|
|
|
553
|
+
|
|
|
554
|
+ cln->handler = ngx_http_uploadprogress_cleanup;
|
|
|
555
|
+ lzcln = cln->data;
|
|
|
556
|
+
|
|
|
557
|
+ lzcln->shm_zone = lzcf->shm_zone;
|
|
|
558
|
+ lzcln->node = node;
|
|
|
559
|
+
|
|
|
560
|
+ return NGX_DECLINED;
|
|
|
561
|
+}
|
|
|
562
|
+
|
|
|
563
|
+static void
|
|
|
564
|
+ngx_http_uploadprogress_rbtree_insert_value(ngx_rbtree_node_t *temp,
|
|
|
565
|
+ ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel)
|
|
|
566
|
+{
|
|
|
567
|
+ ngx_http_uploadprogress_node_t *lzn, *lznt;
|
|
|
568
|
+
|
|
|
569
|
+ for ( ;; ) {
|
|
|
570
|
+
|
|
|
571
|
+ if (node->key < temp->key) {
|
|
|
572
|
+
|
|
|
573
|
+ if (temp->left == sentinel) {
|
|
|
574
|
+ temp->left = node;
|
|
|
575
|
+ break;
|
|
|
576
|
+ }
|
|
|
577
|
+
|
|
|
578
|
+ temp = temp->left;
|
|
|
579
|
+
|
|
|
580
|
+ } else if (node->key > temp->key) {
|
|
|
581
|
+
|
|
|
582
|
+ if (temp->right == sentinel) {
|
|
|
583
|
+ temp->right = node;
|
|
|
584
|
+ break;
|
|
|
585
|
+ }
|
|
|
586
|
+
|
|
|
587
|
+ temp = temp->right;
|
|
|
588
|
+
|
|
|
589
|
+ } else { /* node->key == temp->key */
|
|
|
590
|
+
|
|
|
591
|
+ lzn = (ngx_http_uploadprogress_node_t *) &node->color;
|
|
|
592
|
+ lznt = (ngx_http_uploadprogress_node_t *) &temp->color;
|
|
|
593
|
+
|
|
|
594
|
+ if (ngx_memn2cmp(lzn->data, lznt->data, lzn->len, lznt->len) < 0) {
|
|
|
595
|
+
|
|
|
596
|
+ if (temp->left == sentinel) {
|
|
|
597
|
+ temp->left = node;
|
|
|
598
|
+ break;
|
|
|
599
|
+ }
|
|
|
600
|
+
|
|
|
601
|
+ temp = temp->left;
|
|
|
602
|
+
|
|
|
603
|
+ } else {
|
|
|
604
|
+
|
|
|
605
|
+ if (temp->right == sentinel) {
|
|
|
606
|
+ temp->right = node;
|
|
|
607
|
+ break;
|
|
|
608
|
+ }
|
|
|
609
|
+
|
|
|
610
|
+ temp = temp->right;
|
|
|
611
|
+ }
|
|
|
612
|
+ }
|
|
|
613
|
+ }
|
|
|
614
|
+
|
|
|
615
|
+ node->parent = temp;
|
|
|
616
|
+ node->left = sentinel;
|
|
|
617
|
+ node->right = sentinel;
|
|
|
618
|
+ ngx_rbt_red(node);
|
|
|
619
|
+}
|
|
|
620
|
+
|
|
|
621
|
+/*
|
|
|
622
|
+removes the expired node from the upload rbtree
|
|
|
623
|
+*/
|
|
|
624
|
+static void
|
|
|
625
|
+ngx_http_uploadprogress_cleanup(void *data)
|
|
|
626
|
+{
|
|
|
627
|
+ ngx_http_uploadprogress_cleanup_t *lzcln = data;
|
|
|
628
|
+
|
|
|
629
|
+ ngx_slab_pool_t *shpool;
|
|
|
630
|
+ ngx_rbtree_node_t *node;
|
|
|
631
|
+ ngx_http_uploadprogress_ctx_t *ctx;
|
|
|
632
|
+ ngx_http_uploadprogress_node_t *lz;
|
|
|
633
|
+
|
|
|
634
|
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, lzcln->shm_zone->shm.log, 0,
|
|
|
635
|
+ "uploadprogress cleanup called");
|
|
|
636
|
+
|
|
|
637
|
+ ctx = lzcln->shm_zone->data;
|
|
|
638
|
+ shpool = (ngx_slab_pool_t *) lzcln->shm_zone->shm.addr;
|
|
|
639
|
+ node = lzcln->node;
|
|
|
640
|
+ lz = (ngx_http_uploadprogress_node_t *) &node->color;
|
|
|
641
|
+
|
|
|
642
|
+ ngx_shmtx_lock(&shpool->mutex);
|
|
|
643
|
+
|
|
|
644
|
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, lzcln->shm_zone->shm.log, 0,
|
|
|
645
|
+ "upload progress cleanup: %08XD", node->key);
|
|
|
646
|
+
|
|
|
647
|
+ ngx_rbtree_delete(ctx->rbtree, node);
|
|
|
648
|
+ ngx_slab_free_locked(shpool, node);
|
|
|
649
|
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, lzcln->shm_zone->shm.log, 0,
|
|
|
650
|
+ "upload progress cleanup node removed: %08XD", node->key);
|
|
|
651
|
+ ngx_shmtx_unlock(&shpool->mutex);
|
|
|
652
|
+}
|
|
|
653
|
+
|
|
|
654
|
+static ngx_int_t
|
|
|
655
|
+ngx_http_uploadprogress_init_zone(ngx_shm_zone_t *shm_zone, void *data)
|
|
|
656
|
+{
|
|
|
657
|
+ ngx_http_uploadprogress_ctx_t *octx = data;
|
|
|
658
|
+
|
|
|
659
|
+ ngx_slab_pool_t *shpool;
|
|
|
660
|
+ ngx_rbtree_node_t *sentinel;
|
|
|
661
|
+ ngx_http_uploadprogress_ctx_t *ctx;
|
|
|
662
|
+
|
|
|
663
|
+ ctx = shm_zone->data;
|
|
|
664
|
+
|
|
|
665
|
+ if (octx) {
|
|
|
666
|
+ ctx->rbtree = octx->rbtree;
|
|
|
667
|
+ return NGX_OK;
|
|
|
668
|
+ }
|
|
|
669
|
+
|
|
|
670
|
+ shpool = (ngx_slab_pool_t *) shm_zone->shm.addr;
|
|
|
671
|
+
|
|
|
672
|
+ ctx->rbtree = ngx_slab_alloc(shpool, sizeof(ngx_rbtree_t));
|
|
|
673
|
+ if (ctx->rbtree == NULL) {
|
|
|
674
|
+ return NGX_ERROR;
|
|
|
675
|
+ }
|
|
|
676
|
+
|
|
|
677
|
+ sentinel = ngx_slab_alloc(shpool, sizeof(ngx_rbtree_node_t));
|
|
|
678
|
+ if (sentinel == NULL) {
|
|
|
679
|
+ return NGX_ERROR;
|
|
|
680
|
+ }
|
|
|
681
|
+
|
|
|
682
|
+ ngx_rbtree_sentinel_init(sentinel);
|
|
|
683
|
+
|
|
|
684
|
+ ctx->rbtree->root = sentinel;
|
|
|
685
|
+ ctx->rbtree->sentinel = sentinel;
|
|
|
686
|
+ ctx->rbtree->insert = ngx_http_uploadprogress_rbtree_insert_value;
|
|
|
687
|
+
|
|
|
688
|
+ return NGX_OK;
|
|
|
689
|
+}
|
|
|
690
|
+
|
|
|
691
|
+
|
|
|
692
|
+static ngx_int_t
|
|
|
693
|
+ngx_http_uploadprogress_init(ngx_conf_t *cf)
|
|
|
694
|
+{
|
|
|
695
|
+ ngx_http_handler_pt *h;
|
|
|
696
|
+ ngx_http_core_main_conf_t *cmcf;
|
|
|
697
|
+
|
|
|
698
|
+ cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
|
|
|
699
|
+
|
|
|
700
|
+ h = ngx_array_push(&cmcf->phases[NGX_HTTP_REWRITE_PHASE].handlers);
|
|
|
701
|
+ if (h == NULL) {
|
|
|
702
|
+ return NGX_ERROR;
|
|
|
703
|
+ }
|
|
|
704
|
+
|
|
|
705
|
+ *h = ngx_http_uploadprogress_handler;
|
|
|
706
|
+ return NGX_OK;
|
|
|
707
|
+}
|
|
|
708
|
+
|
|
|
709
|
+static void *
|
|
|
710
|
+ngx_http_uploadprogress_create_loc_conf(ngx_conf_t *cf)
|
|
|
711
|
+{
|
|
|
712
|
+ ngx_http_uploadprogress_conf_t *conf;
|
|
|
713
|
+
|
|
|
714
|
+ conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_uploadprogress_conf_t));
|
|
|
715
|
+ if (conf == NULL) {
|
|
|
716
|
+ return NGX_CONF_ERROR;
|
|
|
717
|
+ }
|
|
|
718
|
+ return conf;
|
|
|
719
|
+}
|
|
|
720
|
+
|
|
|
721
|
+
|
|
|
722
|
+static char *
|
|
|
723
|
+ngx_http_uploadprogress_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
|
|
|
724
|
+{
|
|
|
725
|
+ ngx_http_uploadprogress_conf_t *prev = parent;
|
|
|
726
|
+ ngx_http_uploadprogress_conf_t *conf = child;
|
|
|
727
|
+
|
|
|
728
|
+ if (conf->shm_zone == NULL) {
|
|
|
729
|
+ *conf = *prev;
|
|
|
730
|
+ }
|
|
|
731
|
+
|
|
|
732
|
+ return NGX_CONF_OK;
|
|
|
733
|
+}
|
|
|
734
|
+
|
|
|
735
|
+
|
|
|
736
|
+static char *
|
|
|
737
|
+ngx_http_upload_progress(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
|
738
|
+{
|
|
|
739
|
+ ssize_t n;
|
|
|
740
|
+ ngx_str_t *value;
|
|
|
741
|
+ ngx_shm_zone_t *shm_zone;
|
|
|
742
|
+ ngx_http_uploadprogress_ctx_t *ctx;
|
|
|
743
|
+
|
|
|
744
|
+ value = cf->args->elts;
|
|
|
745
|
+
|
|
|
746
|
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, cf->log, 0,
|
|
|
747
|
+ "ngx_upload_progress name: %V", &value[1]);
|
|
|
748
|
+
|
|
|
749
|
+ ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_uploadprogress_ctx_t));
|
|
|
750
|
+ if (ctx == NULL) {
|
|
|
751
|
+ return NGX_CONF_ERROR;
|
|
|
752
|
+ }
|
|
|
753
|
+
|
|
|
754
|
+ n = ngx_parse_size(&value[2]);
|
|
|
755
|
+
|
|
|
756
|
+ if (n == NGX_ERROR) {
|
|
|
757
|
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
|
758
|
+ "invalid size of track_uploads \"%V\"", &value[2]);
|
|
|
759
|
+ return NGX_CONF_ERROR;
|
|
|
760
|
+ }
|
|
|
761
|
+
|
|
|
762
|
+ if (n < (ngx_int_t) (8 * ngx_pagesize)) {
|
|
|
763
|
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
|
764
|
+ "track_uploads \"%V\" is too small", &value[1]);
|
|
|
765
|
+ return NGX_CONF_ERROR;
|
|
|
766
|
+ }
|
|
|
767
|
+
|
|
|
768
|
+ shm_zone = ngx_shared_memory_add(cf, &value[1], n,
|
|
|
769
|
+ &ngx_http_uploadprogress_module);
|
|
|
770
|
+ if (shm_zone == NULL) {
|
|
|
771
|
+ return NGX_CONF_ERROR;
|
|
|
772
|
+ }
|
|
|
773
|
+
|
|
|
774
|
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, cf->log, 0,
|
|
|
775
|
+ "ngx_upload_progress name: %V, szhm_zone: %p", value[1], shm_zone);
|
|
|
776
|
+
|
|
|
777
|
+ if (shm_zone->data) {
|
|
|
778
|
+ ctx = shm_zone->data;
|
|
|
779
|
+
|
|
|
780
|
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
|
|
781
|
+ "track_uploads \"%V\" is already created",
|
|
|
782
|
+ &value[1]);
|
|
|
783
|
+ return NGX_CONF_ERROR;
|
|
|
784
|
+ }
|
|
|
785
|
+
|
|
|
786
|
+ shm_zone->init = ngx_http_uploadprogress_init_zone;
|
|
|
787
|
+ shm_zone->data = ctx;
|
|
|
788
|
+
|
|
|
789
|
+ return NGX_CONF_OK;
|
|
|
790
|
+}
|
|
|
791
|
+
|
|
|
792
|
+static char *
|
|
|
793
|
+ngx_http_track_uploads(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
|
794
|
+{
|
|
|
795
|
+ ngx_http_uploadprogress_conf_t *lzcf = conf;
|
|
|
796
|
+ ngx_str_t *value;
|
|
|
797
|
+
|
|
|
798
|
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, cf->log, 0,
|
|
|
799
|
+ "ngx_track_uploads in");
|
|
|
800
|
+
|
|
|
801
|
+ value = cf->args->elts;
|
|
|
802
|
+
|
|
|
803
|
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, cf->log, 0,
|
|
|
804
|
+ "ngx_track_uploads name: %V", value[1]);
|
|
|
805
|
+
|
|
|
806
|
+ lzcf->shm_zone = ngx_shared_memory_add(cf, &value[1], 0,
|
|
|
807
|
+ &ngx_http_uploadprogress_module);
|
|
|
808
|
+ if (lzcf->shm_zone == NULL) {
|
|
|
809
|
+ return NGX_CONF_ERROR;
|
|
|
810
|
+ }
|
|
|
811
|
+
|
|
|
812
|
+ lzcf->track = (u_char)1;
|
|
|
813
|
+
|
|
|
814
|
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, cf->log, 0,
|
|
|
815
|
+ "ngx_track_uploads name: %V,szhm_zone: %p", value[1], lzcf->shm_zone);
|
|
|
816
|
+
|
|
|
817
|
+ return NGX_CONF_OK;
|
|
|
818
|
+}
|
|
|
819
|
+
|
|
|
820
|
+
|
|
|
821
|
+static char *
|
|
|
822
|
+ngx_http_report_uploads(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
|
823
|
+{
|
|
|
824
|
+ ngx_http_uploadprogress_conf_t *lzcf = conf;
|
|
|
825
|
+ ngx_http_core_loc_conf_t *clcf;
|
|
|
826
|
+ ngx_str_t *value;
|
|
|
827
|
+
|
|
|
828
|
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, cf->log, 0,
|
|
|
829
|
+ "ngx_report_uploads in");
|
|
|
830
|
+
|
|
|
831
|
+ value = cf->args->elts;
|
|
|
832
|
+
|
|
|
833
|
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, cf->log, 0,
|
|
|
834
|
+ "ngx_report_uploads name: %V", value[1]);
|
|
|
835
|
+
|
|
|
836
|
+ lzcf->shm_zone = ngx_shared_memory_add(cf, &value[1], 0,
|
|
|
837
|
+ &ngx_http_uploadprogress_module);
|
|
|
838
|
+ if (lzcf->shm_zone == NULL) {
|
|
|
839
|
+ return NGX_CONF_ERROR;
|
|
|
840
|
+ }
|
|
|
841
|
+
|
|
|
842
|
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, cf->log, 0,
|
|
|
843
|
+ "ngx_report_uploads name: %V, szhm_zone: %p", value[1], lzcf->shm_zone);
|
|
|
844
|
+
|
|
|
845
|
+ lzcf->track = (u_char)0;
|
|
|
846
|
+
|
|
|
847
|
+ /* install our report handler */
|
|
|
848
|
+ clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
|
|
|
849
|
+ clcf->handler = ngx_http_reportuploads_handler;
|
|
|
850
|
+
|
|
|
851
|
+ return NGX_CONF_OK;
|
|
|
852
|
+}
|