Przeglądaj źródła

fixed ugly up conf that was storing the read_event_handler - instead store it in the http request context

tags/v0.4
Brice Figureau 18 lat temu
rodzic
commit
b9c2b4bc6d
1 zmienionych plików z 27 dodań i 15 usunięć
  1. 27
    15
      ngx_http_uploadprogress_module.c

+ 27
- 15
ngx_http_uploadprogress_module.c Wyświetl plik

42
     time_t                           timeout;
42
     time_t                           timeout;
43
     ngx_event_t                      cleanup;
43
     ngx_event_t                      cleanup;
44
     ngx_http_handler_pt              handler;
44
     ngx_http_handler_pt              handler;
45
-    ngx_http_event_handler_pt        read_event_handler;
46
     u_char                           track;
45
     u_char                           track;
47
 } ngx_http_uploadprogress_conf_t;
46
 } ngx_http_uploadprogress_conf_t;
48
 
47
 
48
+typedef struct {
49
+    ngx_http_event_handler_pt        read_event_handler;
50
+} ngx_http_uploadprogress_module_ctx_t;
51
+
49
 static ngx_int_t ngx_http_reportuploads_handler(ngx_http_request_t *r);
52
 static ngx_int_t ngx_http_reportuploads_handler(ngx_http_request_t *r);
50
 static void ngx_http_uploadprogress_cleanup(void *data);
53
 static void ngx_http_uploadprogress_cleanup(void *data);
51
 static char *ngx_http_report_uploads(ngx_conf_t * cf, ngx_command_t * cmd, void *conf);
54
 static char *ngx_http_report_uploads(ngx_conf_t * cf, ngx_command_t * cmd, void *conf);
257
 static ngx_int_t
260
 static ngx_int_t
258
 ngx_http_uploadprogress_content_handler(ngx_http_request_t *r)
261
 ngx_http_uploadprogress_content_handler(ngx_http_request_t *r)
259
 {
262
 {
260
-    ngx_int_t                        rc;
261
-    ngx_http_uploadprogress_conf_t  *upcf;
263
+    ngx_int_t                                    rc;
264
+    ngx_http_uploadprogress_module_ctx_t        *ctx;
265
+    ngx_http_uploadprogress_conf_t              *upcf;
266
+    
262
     ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "upload-progress: ngx_http_uploadprogress_content_handler");
267
     ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "upload-progress: ngx_http_uploadprogress_content_handler");
263
     upcf = ngx_http_get_module_loc_conf(r, ngx_http_uploadprogress_module);
268
     upcf = ngx_http_get_module_loc_conf(r, ngx_http_uploadprogress_module);
264
 
269
 
270
       return rc;
275
       return rc;
271
     
276
     
272
     /* request is OK, hijack the read_event_handler */
277
     /* request is OK, hijack the read_event_handler */
273
-    upcf->read_event_handler = r->read_event_handler;
278
+    ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_uploadprogress_module_ctx_t));
279
+    if (ctx == NULL) {
280
+      return NGX_ERROR;
281
+    }
282
+
283
+    ngx_http_set_ctx(r, ctx, ngx_http_uploadprogress_module);
274
     r->read_event_handler = ngx_http_uploadprogress_event_handler;
284
     r->read_event_handler = ngx_http_uploadprogress_event_handler;
275
     return rc;
285
     return rc;
276
 }
286
 }
277
 
287
 
278
 static void ngx_http_uploadprogress_event_handler(ngx_http_request_t *r)
288
 static void ngx_http_uploadprogress_event_handler(ngx_http_request_t *r)
279
 {
289
 {
280
-    ngx_str_t                       *id;
281
-    ngx_slab_pool_t                 *shpool;
282
-    ngx_connection_t                *c;
283
-    ngx_http_uploadprogress_ctx_t   *ctx;
284
-    ngx_http_uploadprogress_node_t  *up;
285
-    ngx_http_uploadprogress_conf_t  *upcf;
290
+    ngx_str_t                                   *id;
291
+    ngx_slab_pool_t                             *shpool;
292
+    ngx_connection_t                            *c;
293
+    ngx_http_uploadprogress_ctx_t               *ctx;
294
+    ngx_http_uploadprogress_node_t              *up;
295
+    ngx_http_uploadprogress_conf_t              *upcf;
296
+    ngx_http_uploadprogress_module_ctx_t        *module_ctx;
286
 
297
 
287
     ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "upload-progress: ngx_http_uploadprogress_event_handler");
298
     ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "upload-progress: ngx_http_uploadprogress_event_handler");
288
     
299
     
289
     c = r->connection;
300
     c = r->connection;
290
     
301
     
291
     /* call the original read event handler */
302
     /* call the original read event handler */
292
-    upcf = ngx_http_get_module_loc_conf(r, ngx_http_uploadprogress_module);
293
-    upcf->read_event_handler(r);
303
+    module_ctx = ngx_http_get_module_ctx(r, ngx_http_uploadprogress_module);
304
+    module_ctx->read_event_handler(r);
294
 
305
 
295
     /* check that the request/connection is still OK */
306
     /* check that the request/connection is still OK */
296
     if (r->headers_out.status >= NGX_HTTP_SPECIAL_RESPONSE) {
307
     if (r->headers_out.status >= NGX_HTTP_SPECIAL_RESPONSE) {
309
     ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
320
     ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
310
                    "upload-progress: read_event_handler found id: %V", id);
321
                    "upload-progress: read_event_handler found id: %V", id);
311
 
322
 
323
+    upcf = ngx_http_get_module_loc_conf(r, ngx_http_uploadprogress_module);
312
     if (upcf->shm_zone == NULL) {
324
     if (upcf->shm_zone == NULL) {
313
         ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
325
         ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
314
                        "upload-progress: read_event_handler no shm_zone for id: %V", id);
326
                        "upload-progress: read_event_handler no shm_zone for id: %V", id);
326
     if (up != NULL && !up->done) {
338
     if (up != NULL && !up->done) {
327
         ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
339
         ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
328
                        "upload-progress: read_event_handler found node: %V", id);
340
                        "upload-progress: read_event_handler found node: %V", id);
329
-				up->rest = r->request_body->rest;
330
-				up->length = r->headers_in.content_length_n;
341
+        up->rest = r->request_body->rest;
342
+        up->length = r->headers_in.content_length_n;
331
         ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
343
         ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
332
                        "upload-progress: read_event_handler storing rest %uO/%uO for %V", up->rest, up->length, id);
344
                        "upload-progress: read_event_handler storing rest %uO/%uO for %V", up->rest, up->length, id);
333
     } else {
345
     } else {
344
     ngx_str_t                       *id;
356
     ngx_str_t                       *id;
345
     ngx_buf_t                       *b;
357
     ngx_buf_t                       *b;
346
     ngx_chain_t                      out;
358
     ngx_chain_t                      out;
347
-		ngx_int_t                        rc, size, found=0, done=0, err_status=0;
359
+    ngx_int_t                        rc, size, found=0, done=0, err_status=0;
348
     off_t                            rest=0, length=0;
360
     off_t                            rest=0, length=0;
349
     ngx_uint_t                       len, i;
361
     ngx_uint_t                       len, i;
350
     ngx_slab_pool_t                 *shpool;
362
     ngx_slab_pool_t                 *shpool;

Ładowanie…
Anuluj
Zapisz