Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

ngx_http_uploadprogress_module.c 38KB

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