Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

ngx_http_uploadprogress_module.c 38KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204
  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 */
  224. ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_uploadprogress_module_ctx_t));
  225. if (ctx == NULL) {
  226. return NGX_ERROR;
  227. }
  228. ngx_http_set_ctx(r, ctx, ngx_http_uploadprogress_module);
  229. r->read_event_handler = ngx_http_uploadprogress_event_handler;
  230. return rc;
  231. }
  232. static void ngx_http_uploadprogress_event_handler(ngx_http_request_t *r)
  233. {
  234. ngx_str_t *id;
  235. ngx_slab_pool_t *shpool;
  236. ngx_connection_t *c;
  237. ngx_http_uploadprogress_ctx_t *ctx;
  238. ngx_http_uploadprogress_node_t *up;
  239. ngx_http_uploadprogress_conf_t *upcf;
  240. ngx_http_uploadprogress_module_ctx_t *module_ctx;
  241. ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "upload-progress: ngx_http_uploadprogress_event_handler");
  242. c = r->connection;
  243. /* find node, update rest */
  244. id = get_tracking_id(r);
  245. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  246. "upload-progress: read_event_handler found id: %V", id);
  247. upcf = ngx_http_get_module_loc_conf(r, ngx_http_uploadprogress_module);
  248. /* call the original read event handler */
  249. module_ctx = ngx_http_get_module_ctx(r, ngx_http_uploadprogress_module);
  250. module_ctx->read_event_handler(r);
  251. /* at this stage, r is not anymore safe to use */
  252. /* the request could have been closed/freed behind our back */
  253. if (id == NULL) {
  254. ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
  255. "upload-progress: read_event_handler cant find id");
  256. return;
  257. }
  258. if (upcf->shm_zone == NULL) {
  259. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
  260. "upload-progress: read_event_handler no shm_zone for id: %V", id);
  261. return;
  262. }
  263. ctx = upcf->shm_zone->data;
  264. /* get the original connection of the upload */
  265. shpool = (ngx_slab_pool_t *) upcf->shm_zone->shm.addr;
  266. ngx_shmtx_lock(&shpool->mutex);
  267. up = find_node(id, ctx, ngx_cycle->log);
  268. if (up != NULL && !up->done) {
  269. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
  270. "upload-progress: read_event_handler found node: %V", id);
  271. up->rest = r->request_body->rest;
  272. up->length = r->headers_in.content_length_n;
  273. ngx_log_debug3(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
  274. "upload-progress: read_event_handler storing rest %uO/%uO for %V", up->rest, up->length, id);
  275. } else {
  276. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
  277. "upload-progress: read_event_handler not found: %V", id);
  278. }
  279. ngx_shmtx_unlock(&shpool->mutex);
  280. }
  281. /* This generates the response for the report */
  282. static ngx_int_t
  283. ngx_http_reportuploads_handler(ngx_http_request_t * r)
  284. {
  285. ngx_str_t *id;
  286. ngx_buf_t *b;
  287. ngx_chain_t out;
  288. ngx_int_t rc, size, found=0, done=0, err_status=0;
  289. off_t rest=0, length=0;
  290. ngx_uint_t len, i;
  291. ngx_slab_pool_t *shpool;
  292. ngx_http_uploadprogress_conf_t *upcf;
  293. ngx_http_uploadprogress_ctx_t *ctx;
  294. ngx_http_uploadprogress_node_t *up;
  295. ngx_table_elt_t *expires, *cc, **ccp;
  296. if (r->method != NGX_HTTP_GET && r->method != NGX_HTTP_HEAD) {
  297. return NGX_HTTP_NOT_ALLOWED;
  298. }
  299. rc = ngx_http_discard_request_body(r);
  300. if (rc != NGX_OK) {
  301. return rc;
  302. }
  303. /* get the tracking id if any */
  304. id = get_tracking_id(r);
  305. if (id == NULL) {
  306. ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  307. "reportuploads handler cant find id");
  308. return NGX_DECLINED;
  309. }
  310. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  311. "reportuploads handler found id: %V", id);
  312. upcf = ngx_http_get_module_loc_conf(r, ngx_http_uploadprogress_module);
  313. if (upcf->shm_zone == NULL) {
  314. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  315. "reportuploads no shm_zone for id: %V", id);
  316. return NGX_DECLINED;
  317. }
  318. ctx = upcf->shm_zone->data;
  319. /* get the original connection of the upload */
  320. shpool = (ngx_slab_pool_t *) upcf->shm_zone->shm.addr;
  321. ngx_shmtx_lock(&shpool->mutex);
  322. up = find_node(id, ctx, r->connection->log);
  323. if (up != NULL) {
  324. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  325. "reportuploads found node: %V", id);
  326. rest = up->rest;
  327. length = up->length;
  328. done = up->done;
  329. err_status = up->err_status;
  330. found = 1;
  331. } else {
  332. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  333. "reportuploads not found: %V", id);
  334. }
  335. ngx_shmtx_unlock(&shpool->mutex);
  336. /* send the output */
  337. r->headers_out.content_type.len = sizeof("text/javascript") - 1;
  338. r->headers_out.content_type.data = (u_char *) "text/javascript";
  339. /* force no-cache */
  340. expires = r->headers_out.expires;
  341. if (expires == NULL) {
  342. expires = ngx_list_push(&r->headers_out.headers);
  343. if (expires == NULL) {
  344. return NGX_HTTP_INTERNAL_SERVER_ERROR;
  345. }
  346. r->headers_out.expires = expires;
  347. expires->hash = 1;
  348. expires->key.len = sizeof("Expires") - 1;
  349. expires->key.data = (u_char *) "Expires";
  350. }
  351. len = sizeof("Mon, 28 Sep 1970 06:00:00 GMT");
  352. expires->value.len = len - 1;
  353. ccp = r->headers_out.cache_control.elts;
  354. if (ccp == NULL) {
  355. if (ngx_array_init(&r->headers_out.cache_control, r->pool,
  356. 1, sizeof(ngx_table_elt_t *))
  357. != NGX_OK) {
  358. return NGX_HTTP_INTERNAL_SERVER_ERROR;
  359. }
  360. ccp = ngx_array_push(&r->headers_out.cache_control);
  361. if (ccp == NULL) {
  362. return NGX_HTTP_INTERNAL_SERVER_ERROR;
  363. }
  364. cc = ngx_list_push(&r->headers_out.headers);
  365. if (cc == NULL) {
  366. return NGX_HTTP_INTERNAL_SERVER_ERROR;
  367. }
  368. cc->hash = 1;
  369. cc->key.len = sizeof("Cache-Control") - 1;
  370. cc->key.data = (u_char *) "Cache-Control";
  371. *ccp = cc;
  372. } else {
  373. for (i = 1; i < r->headers_out.cache_control.nelts; i++) {
  374. ccp[i]->hash = 0;
  375. }
  376. cc = ccp[0];
  377. }
  378. expires->value.data = (u_char *) "Thu, 01 Jan 1970 00:00:01 GMT";
  379. cc->value.len = sizeof("no-cache") - 1;
  380. cc->value.data = (u_char *) "no-cache";
  381. if (r->method == NGX_HTTP_HEAD) {
  382. r->headers_out.status = NGX_HTTP_OK;
  383. rc = ngx_http_send_header(r);
  384. if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
  385. return rc;
  386. }
  387. }
  388. /*
  389. There are 4 possibilities
  390. * request not yet started: found = false
  391. * request in error: err_status >= NGX_HTTP_SPECIAL_RESPONSE
  392. * request finished: done = true
  393. * request not yet started but registered: length==0 && rest ==0
  394. * reauest in progress: rest > 0
  395. */
  396. if (!found) {
  397. size = sizeof("new Object({ 'state' : 'starting' })\r\n");
  398. } else if (err_status >= NGX_HTTP_SPECIAL_RESPONSE) {
  399. size = sizeof("new Object({ 'state' : 'error', 'status' : ") + NGX_INT_T_LEN + sizeof(" })\r\n");
  400. } else if (done) {
  401. size = sizeof("new Object({ 'state' : 'done' })\r\n");
  402. } else if ( length == 0 && rest == 0 ) {
  403. size = sizeof("new Object({ 'state' : 'starting' })\r\n");
  404. } else {
  405. size = sizeof("new Object({ 'state' : 'uploading', 'received' : ") + NGX_INT_T_LEN + sizeof(" })\r\n");
  406. size += sizeof(", 'size' : ") + NGX_INT_T_LEN;
  407. }
  408. b = ngx_create_temp_buf(r->pool, size);
  409. if (b == NULL) {
  410. return NGX_HTTP_INTERNAL_SERVER_ERROR;
  411. }
  412. out.buf = b;
  413. out.next = NULL;
  414. if (!found) {
  415. b->last = ngx_cpymem(b->last, "new Object({ 'state' : 'starting' })\r\n",
  416. sizeof("new Object({ 'state' : 'starting' })\r\n") - 1);
  417. ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "reportuploads returning starting");
  418. } else if (err_status >= NGX_HTTP_SPECIAL_RESPONSE) {
  419. b->last = ngx_cpymem(b->last, "new Object({ 'state' : 'error', 'status' : ",
  420. sizeof("new Object({ 'state' : 'error', 'status' : ") - 1);
  421. b->last = ngx_sprintf(b->last, "%ui })\r\n", err_status );
  422. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  423. "reportuploads returning error condition: %ui", err_status);
  424. } else if (done) {
  425. b->last = ngx_cpymem(b->last, "new Object({ 'state' : 'done' })\r\n",
  426. sizeof("new Object({ 'state' : 'done' })\r\n") - 1);
  427. ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  428. "reportuploads returning done");
  429. } else if (length == 0 && rest == 0) {
  430. b->last = ngx_cpymem(b->last, "new Object({ 'state' : 'starting' })\r\n",
  431. sizeof("new Object({ 'state' : 'starting' })\r\n") - 1);
  432. ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "reportuploads returning starting");
  433. } else {
  434. b->last = ngx_cpymem(b->last, "new Object({ 'state' : 'uploading', 'received' : ",
  435. sizeof("new Object({ 'state' : 'uploading', 'received' : ") - 1);
  436. b->last = ngx_sprintf(b->last, "%uO, 'size' : %uO })\r\n", (length - rest), length);
  437. ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  438. "reportuploads returning %uO / %uO",(length - rest), length );
  439. }
  440. r->headers_out.status = NGX_HTTP_OK;
  441. r->headers_out.content_length_n = b->last - b->pos;
  442. b->last_buf = 1;
  443. rc = ngx_http_send_header(r);
  444. if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
  445. return rc;
  446. }
  447. return ngx_http_output_filter(r, &out);
  448. }
  449. /*
  450. Let's register the upload connection in our connections rb-tree
  451. */
  452. static ngx_int_t
  453. ngx_http_uploadprogress_handler(ngx_http_request_t * r)
  454. {
  455. size_t n;
  456. ngx_str_t *id;
  457. uint32_t hash;
  458. ngx_slab_pool_t *shpool;
  459. ngx_rbtree_node_t *node;
  460. ngx_http_uploadprogress_conf_t *upcf;
  461. ngx_http_uploadprogress_ctx_t *ctx;
  462. ngx_http_uploadprogress_node_t *up;
  463. ngx_http_uploadprogress_cleanup_t *upcln;
  464. ngx_pool_cleanup_t *cln;
  465. /* Is it a POST connection */
  466. if (r->method != NGX_HTTP_POST) {
  467. return NGX_DECLINED;
  468. }
  469. id = get_tracking_id(r);
  470. if (id == NULL) {
  471. ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  472. "trackuploads no id found in POST upload req");
  473. return NGX_DECLINED;
  474. }
  475. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  476. "trackuploads id found: %V", id);
  477. upcf = ngx_http_get_module_loc_conf(r, ngx_http_uploadprogress_module);
  478. if (!upcf->track) {
  479. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  480. "trackuploads not tracking in this location for id: %V", id);
  481. return NGX_DECLINED;
  482. }
  483. if (upcf->shm_zone == NULL) {
  484. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  485. "trackuploads no shm_zone for id: %V", id);
  486. return NGX_DECLINED;
  487. }
  488. ctx = upcf->shm_zone->data;
  489. hash = ngx_crc32_short(id->data, id->len);
  490. ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  491. "trackuploads hash %08XD for id: %V", hash, id);
  492. shpool = (ngx_slab_pool_t *) upcf->shm_zone->shm.addr;
  493. ngx_shmtx_lock(&shpool->mutex);
  494. if (find_node(id, ctx, r->connection->log) != NULL) {
  495. ngx_shmtx_unlock(&shpool->mutex);
  496. /* already found a node with matching progress ID */
  497. ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
  498. "upload_progress: tracking already registered id: %V", id);
  499. return NGX_HTTP_INTERNAL_SERVER_ERROR;
  500. }
  501. cln = ngx_pool_cleanup_add(r->pool, sizeof(ngx_http_uploadprogress_cleanup_t));
  502. if (cln == NULL) {
  503. ngx_shmtx_unlock(&shpool->mutex);
  504. return NGX_HTTP_INTERNAL_SERVER_ERROR;
  505. }
  506. n = sizeof(ngx_http_uploadprogress_node_t)
  507. + id->len;
  508. node = ngx_slab_alloc_locked(shpool, n);
  509. if (node == NULL) {
  510. ngx_shmtx_unlock(&shpool->mutex);
  511. return NGX_HTTP_SERVICE_UNAVAILABLE;
  512. }
  513. up = (ngx_http_uploadprogress_node_t *) node;
  514. node->key = hash;
  515. up->len = (u_char) id->len;
  516. up->err_status = r->err_status;
  517. up->next = ctx->list_head.next;
  518. up->next->prev = up;
  519. up->prev = &ctx->list_head;
  520. ctx->list_head.next = up;
  521. ngx_memcpy(up->data, id->data, id->len);
  522. ngx_rbtree_insert(ctx->rbtree, node);
  523. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  524. "trackuploads: %08XD inserted in rbtree", node->key);
  525. if (!upcf->cleanup.timer_set) {
  526. upcf->cleanup.data = upcf->shm_zone;
  527. upcf->cleanup.handler = ngx_clean_old_connections;
  528. upcf->cleanup.log = upcf->shm_zone->shm.log;
  529. ngx_add_timer(&upcf->cleanup, TIMER_FREQUENCY);
  530. }
  531. ngx_shmtx_unlock(&shpool->mutex);
  532. cln->handler = ngx_http_uploadprogress_cleanup;
  533. upcln = cln->data;
  534. upcln->shm_zone = upcf->shm_zone;
  535. upcln->node = node;
  536. upcln->timeout = upcf->timeout;
  537. upcln->r = r;
  538. /* finally says to the core we don't handle anything */
  539. return NGX_DECLINED;
  540. }
  541. static void
  542. ngx_http_uploadprogress_rbtree_insert_value(ngx_rbtree_node_t * temp,
  543. ngx_rbtree_node_t * node,
  544. ngx_rbtree_node_t * sentinel)
  545. {
  546. ngx_http_uploadprogress_node_t *upn, *upnt;
  547. for (;;) {
  548. if (node->key < temp->key) {
  549. if (temp->left == sentinel) {
  550. temp->left = node;
  551. break;
  552. }
  553. temp = temp->left;
  554. } else if (node->key > temp->key) {
  555. if (temp->right == sentinel) {
  556. temp->right = node;
  557. break;
  558. }
  559. temp = temp->right;
  560. } else { /* node->key == temp->key */
  561. upn = (ngx_http_uploadprogress_node_t *) node;
  562. upnt = (ngx_http_uploadprogress_node_t *) temp;
  563. if (ngx_memn2cmp(upn->data, upnt->data, upn->len, upnt->len) < 0) {
  564. if (temp->left == sentinel) {
  565. temp->left = node;
  566. break;
  567. }
  568. temp = temp->left;
  569. } else {
  570. if (temp->right == sentinel) {
  571. temp->right = node;
  572. break;
  573. }
  574. temp = temp->right;
  575. }
  576. }
  577. }
  578. node->parent = temp;
  579. node->left = sentinel;
  580. node->right = sentinel;
  581. ngx_rbt_red(node);
  582. }
  583. static void
  584. ngx_clean_old_connections(ngx_event_t * ev)
  585. {
  586. ngx_shm_zone_t *shm_zone;
  587. ngx_http_uploadprogress_ctx_t *ctx;
  588. ngx_slab_pool_t *shpool;
  589. ngx_rbtree_node_t *node;
  590. ngx_http_uploadprogress_node_t *up;
  591. time_t now = ngx_time();
  592. /* scan the rbtree */
  593. shm_zone = ev->data;
  594. ctx = shm_zone->data;
  595. shpool = (ngx_slab_pool_t *) shm_zone->shm.addr;
  596. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, shm_zone->shm.log, 0,
  597. "uploadprogress clean old connections at %T", now);
  598. ngx_shmtx_lock(&shpool->mutex);
  599. node = (ngx_rbtree_node_t *) ctx->list_tail.prev;
  600. for (;;) {
  601. if (node == &ctx->list_head.node) {
  602. break;
  603. }
  604. up = (ngx_http_uploadprogress_node_t *) node;
  605. ngx_log_debug3(NGX_LOG_DEBUG_HTTP, shm_zone->shm.log, 0,
  606. "uploadprogress clean: scanning %08XD (req done %ui) timeout at %T",
  607. node->key, up->done, up->timeout);
  608. if (up->done && up->timeout < now) {
  609. up->next->prev = up->prev;
  610. up->prev->next = up->next;
  611. ngx_log_debug3(NGX_LOG_DEBUG_HTTP, shm_zone->shm.log, 0,
  612. "uploadprogress clean: removing %08XD (req %ui) ",
  613. node->key, up->done, up->timeout);
  614. ngx_rbtree_delete(ctx->rbtree, node);
  615. ngx_slab_free_locked(shpool, node);
  616. }
  617. node = (ngx_rbtree_node_t *) up->prev;
  618. }
  619. ngx_log_debug0(NGX_LOG_DEBUG_HTTP, shm_zone->shm.log, 0,
  620. "uploadprogress clean old connections restarting timer");
  621. ngx_add_timer(ev, TIMER_FREQUENCY); /* trigger again in 60s */
  622. ngx_shmtx_unlock(&shpool->mutex);
  623. }
  624. /*
  625. removes the expired node from the upload rbtree
  626. */
  627. static void
  628. ngx_http_uploadprogress_cleanup(void *data)
  629. {
  630. ngx_http_uploadprogress_cleanup_t *upcln = data;
  631. ngx_slab_pool_t *shpool;
  632. ngx_rbtree_node_t *node;
  633. ngx_http_uploadprogress_ctx_t *ctx;
  634. ngx_http_uploadprogress_node_t *up;
  635. ngx_http_request_t *r;
  636. ngx_log_debug0(NGX_LOG_DEBUG_HTTP, upcln->shm_zone->shm.log, 0,
  637. "uploadprogress cleanup called");
  638. ctx = upcln->shm_zone->data;
  639. shpool = (ngx_slab_pool_t *) upcln->shm_zone->shm.addr;
  640. node = upcln->node;
  641. r = upcln->r;
  642. up = (ngx_http_uploadprogress_node_t *) node;
  643. ngx_shmtx_lock(&shpool->mutex);
  644. up->done = 1; /* mark the original request as done */
  645. up->timeout = ngx_time() + upcln->timeout; /* keep tracking for 60s */
  646. if (r != NULL ) {
  647. ngx_uint_t rc = r->err_status ? r->err_status : r->headers_out.status;
  648. if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
  649. up->err_status = rc;
  650. }
  651. }
  652. ngx_shmtx_unlock(&shpool->mutex);
  653. ngx_log_debug2(NGX_LOG_DEBUG_HTTP, upcln->shm_zone->shm.log, 0,
  654. "uploadprogress cleanup: connection %08XD to be deleted at %T",
  655. node->key, up->timeout);
  656. }
  657. static ngx_int_t
  658. ngx_http_uploadprogress_init_zone(ngx_shm_zone_t * shm_zone, void *data)
  659. {
  660. ngx_http_uploadprogress_ctx_t *octx = data;
  661. ngx_slab_pool_t *shpool;
  662. ngx_rbtree_node_t *sentinel;
  663. ngx_http_uploadprogress_ctx_t *ctx;
  664. ctx = shm_zone->data;
  665. if (octx) {
  666. ctx->rbtree = octx->rbtree;
  667. return NGX_OK;
  668. }
  669. shpool = (ngx_slab_pool_t *) shm_zone->shm.addr;
  670. ctx->rbtree = ngx_slab_alloc(shpool, sizeof(ngx_rbtree_t));
  671. if (ctx->rbtree == NULL) {
  672. return NGX_ERROR;
  673. }
  674. sentinel = ngx_slab_alloc(shpool, sizeof(ngx_rbtree_node_t));
  675. if (sentinel == NULL) {
  676. return NGX_ERROR;
  677. }
  678. ngx_rbtree_sentinel_init(sentinel);
  679. ctx->rbtree->root = sentinel;
  680. ctx->rbtree->sentinel = sentinel;
  681. ctx->rbtree->insert = ngx_http_uploadprogress_rbtree_insert_value;
  682. return NGX_OK;
  683. }
  684. static ngx_int_t
  685. ngx_http_uploadprogress_errortracker(ngx_http_request_t * r)
  686. {
  687. size_t n;
  688. ngx_str_t *id;
  689. ngx_slab_pool_t *shpool;
  690. ngx_rbtree_node_t *node;
  691. ngx_http_uploadprogress_ctx_t *ctx;
  692. ngx_http_uploadprogress_node_t *up;
  693. ngx_http_uploadprogress_conf_t *upcf;
  694. uint32_t hash;
  695. ngx_http_uploadprogress_cleanup_t *upcln;
  696. ngx_pool_cleanup_t *cln;
  697. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  698. "uploadprogress error-tracker error: %D", r->err_status);
  699. if (r->err_status >= NGX_HTTP_SPECIAL_RESPONSE) {
  700. upcf = ngx_http_get_module_loc_conf(r, ngx_http_uploadprogress_module);
  701. if (!upcf->track) {
  702. ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  703. "uploadprogress error-tracker not tracking in this location");
  704. goto finish;
  705. }
  706. id = get_tracking_id(r);
  707. if (id == NULL) {
  708. ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  709. "trackuploads error-tracker no id found in POST upload req");
  710. goto finish;
  711. }
  712. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  713. "trackuploads error-tracker id found: %V", id);
  714. if (upcf->shm_zone == NULL) {
  715. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  716. "trackuploads no shm_zone for id: %V", id);
  717. goto finish;
  718. }
  719. ctx = upcf->shm_zone->data;
  720. hash = ngx_crc32_short(id->data, id->len);
  721. ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  722. "trackuploads error-tracking hash %08XD for id: %V", hash,
  723. id);
  724. shpool = (ngx_slab_pool_t *) upcf->shm_zone->shm.addr;
  725. ngx_shmtx_lock(&shpool->mutex);
  726. if ((up = find_node(id, ctx, r->connection->log)) != NULL) {
  727. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  728. "trackuploads error-tracking found node for id: %V", id);
  729. up->err_status = r->err_status;
  730. ngx_shmtx_unlock(&shpool->mutex);
  731. goto finish;
  732. }
  733. /* no lz found for this tracking id */
  734. n = sizeof(ngx_http_uploadprogress_node_t) + id->len;
  735. cln = ngx_pool_cleanup_add(r->pool, sizeof(ngx_http_uploadprogress_cleanup_t));
  736. if (cln == NULL) {
  737. ngx_shmtx_unlock(&shpool->mutex);
  738. goto finish;
  739. }
  740. node = ngx_slab_alloc_locked(shpool, n);
  741. if (node == NULL) {
  742. ngx_shmtx_unlock(&shpool->mutex);
  743. goto finish;
  744. }
  745. up = (ngx_http_uploadprogress_node_t *) node;
  746. node->key = hash;
  747. up->len = (u_char) id->len;
  748. up->err_status = r->err_status;
  749. ngx_memcpy(up->data, id->data, id->len);
  750. up->next = ctx->list_head.next;
  751. up->next->prev = up;
  752. up->prev = &ctx->list_head;
  753. ctx->list_head.next = up;
  754. ngx_rbtree_insert(ctx->rbtree, node);
  755. /* start the timer if needed */
  756. if (!upcf->cleanup.timer_set) {
  757. upcf->cleanup.data = upcf->shm_zone;
  758. upcf->cleanup.handler = ngx_clean_old_connections;
  759. upcf->cleanup.log = upcf->shm_zone->shm.log;
  760. ngx_add_timer(&upcf->cleanup, TIMER_FREQUENCY);
  761. }
  762. ngx_shmtx_unlock(&shpool->mutex);
  763. cln->handler = ngx_http_uploadprogress_cleanup;
  764. upcln = cln->data;
  765. upcln->shm_zone = upcf->shm_zone;
  766. upcln->node = node;
  767. upcln->timeout = upcf->timeout;
  768. upcln->r = r;
  769. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
  770. "trackuploads error-tracking adding: %08XD", node->key);
  771. }
  772. finish:
  773. /* call the filter chain as usual */
  774. return ngx_http_next_header_filter(r);
  775. }
  776. static ngx_int_t
  777. ngx_http_uploadprogress_init(ngx_conf_t * cf)
  778. {
  779. ngx_http_handler_pt *h;
  780. ngx_http_core_main_conf_t *cmcf;
  781. cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
  782. /* install the tracking handler */
  783. h = ngx_array_push(&cmcf->phases[NGX_HTTP_REWRITE_PHASE].handlers);
  784. if (h == NULL) {
  785. return NGX_ERROR;
  786. }
  787. *h = ngx_http_uploadprogress_handler;
  788. /*
  789. we also need to track HTTP errors
  790. unfortunately, the above handler is not called in case of
  791. errors.
  792. we have to register a header output filter that will be
  793. called in any case to track those errors
  794. */
  795. ngx_http_next_header_filter = ngx_http_top_header_filter;
  796. ngx_http_top_header_filter = ngx_http_uploadprogress_errortracker;
  797. return NGX_OK;
  798. }
  799. static void*
  800. ngx_http_uploadprogress_create_loc_conf(ngx_conf_t * cf)
  801. {
  802. ngx_http_uploadprogress_conf_t *conf;
  803. conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_uploadprogress_conf_t));
  804. if (conf == NULL) {
  805. return NGX_CONF_ERROR;
  806. }
  807. return conf;
  808. }
  809. static char*
  810. ngx_http_uploadprogress_merge_loc_conf(ngx_conf_t * cf, void *parent, void *child)
  811. {
  812. ngx_http_uploadprogress_conf_t *prev = parent;
  813. ngx_http_uploadprogress_conf_t *conf = child;
  814. if (conf->shm_zone == NULL) {
  815. *conf = *prev;
  816. }
  817. return NGX_CONF_OK;
  818. }
  819. static char*
  820. ngx_http_upload_progress(ngx_conf_t * cf, ngx_command_t * cmd, void *conf)
  821. {
  822. ssize_t n;
  823. ngx_str_t *value;
  824. ngx_shm_zone_t *shm_zone;
  825. ngx_http_uploadprogress_ctx_t *ctx;
  826. value = cf->args->elts;
  827. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, cf->log, 0,
  828. "ngx_upload_progress name: %V", &value[1]);
  829. ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_uploadprogress_ctx_t));
  830. if (ctx == NULL) {
  831. return NGX_CONF_ERROR;
  832. }
  833. ctx->list_head.prev = NULL;
  834. ctx->list_head.next = &ctx->list_tail;
  835. ctx->list_tail.prev = &ctx->list_head;
  836. ctx->list_tail.next = NULL;
  837. n = ngx_parse_size(&value[2]);
  838. if (n == NGX_ERROR) {
  839. ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
  840. "invalid size of track_uploads \"%V\"", &value[2]);
  841. return NGX_CONF_ERROR;
  842. }
  843. if (n < (ngx_int_t) (8 * ngx_pagesize)) {
  844. ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
  845. "track_uploads \"%V\" is too small", &value[1]);
  846. return NGX_CONF_ERROR;
  847. }
  848. shm_zone = ngx_shared_memory_add(cf, &value[1], n,
  849. &ngx_http_uploadprogress_module);
  850. if (shm_zone == NULL) {
  851. return NGX_CONF_ERROR;
  852. }
  853. ngx_log_debug2(NGX_LOG_DEBUG_HTTP, cf->log, 0,
  854. "ngx_upload_progress name: %V, szhm_zone: %p", &value[1],
  855. shm_zone);
  856. if (shm_zone->data) {
  857. ctx = shm_zone->data;
  858. ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
  859. "track_uploads \"%V\" is already created", &value[1]);
  860. return NGX_CONF_ERROR;
  861. }
  862. shm_zone->init = ngx_http_uploadprogress_init_zone;
  863. shm_zone->data = ctx;
  864. return NGX_CONF_OK;
  865. }
  866. static char*
  867. ngx_http_track_uploads(ngx_conf_t * cf, ngx_command_t * cmd, void *conf)
  868. {
  869. ngx_http_core_loc_conf_t *clcf;
  870. ngx_http_uploadprogress_conf_t *lzcf = conf;
  871. ngx_str_t *value;
  872. ngx_log_debug0(NGX_LOG_DEBUG_HTTP, cf->log, 0, "ngx_track_uploads in");
  873. value = cf->args->elts;
  874. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, cf->log, 0,
  875. "ngx_track_uploads name: %V", &value[1]);
  876. lzcf->shm_zone = ngx_shared_memory_add(cf, &value[1], 0,
  877. &ngx_http_uploadprogress_module);
  878. if (lzcf->shm_zone == NULL) {
  879. return NGX_CONF_ERROR;
  880. }
  881. lzcf->track = (u_char) 1;
  882. ngx_log_debug2(NGX_LOG_DEBUG_HTTP, cf->log, 0,
  883. "ngx_track_uploads name: %V,szhm_zone: %p", &value[1],
  884. lzcf->shm_zone);
  885. lzcf->timeout = ngx_parse_time(&value[2], 1);
  886. if (lzcf->timeout == NGX_ERROR) {
  887. ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
  888. "track_uploads \"%V\" timeout value invalid", &value[1]);
  889. return NGX_CONF_ERROR;
  890. }
  891. if (lzcf->timeout == NGX_PARSE_LARGE_TIME) {
  892. ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
  893. "track_uploads \"%V\" timeout value must be less than 68 years", &value[1]);
  894. return NGX_CONF_ERROR;
  895. }
  896. clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
  897. lzcf->handler = clcf->handler;
  898. if ( lzcf->handler == NULL )
  899. {
  900. return "track_upload should be the last directive in the location, after either proxy_pass or fastcgi_pass";
  901. }
  902. clcf->handler = ngx_http_uploadprogress_content_handler;
  903. return NGX_CONF_OK;
  904. }
  905. static char*
  906. ngx_http_report_uploads(ngx_conf_t * cf, ngx_command_t * cmd, void *conf)
  907. {
  908. ngx_http_uploadprogress_conf_t *lzcf = conf;
  909. ngx_http_core_loc_conf_t *clcf;
  910. ngx_str_t *value;
  911. ngx_log_debug0(NGX_LOG_DEBUG_HTTP, cf->log, 0, "ngx_report_uploads in");
  912. value = cf->args->elts;
  913. ngx_log_debug1(NGX_LOG_DEBUG_HTTP, cf->log, 0,
  914. "ngx_report_uploads name: %V", &value[1]);
  915. lzcf->shm_zone = ngx_shared_memory_add(cf, &value[1], 0,
  916. &ngx_http_uploadprogress_module);
  917. if (lzcf->shm_zone == NULL) {
  918. return NGX_CONF_ERROR;
  919. }
  920. ngx_log_debug2(NGX_LOG_DEBUG_HTTP, cf->log, 0,
  921. "ngx_report_uploads name: %V, szhm_zone: %p", &value[1],
  922. lzcf->shm_zone);
  923. lzcf->track = (u_char) 0;
  924. /* install our report handler */
  925. clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
  926. clcf->handler = ngx_http_reportuploads_handler;
  927. return NGX_CONF_OK;
  928. }