nginxtra 1.8.1.12 → 1.10.1.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (238) hide show
  1. checksums.yaml +4 -4
  2. data/bin/nginxtra +1 -1
  3. data/bin/nginxtra_rails +1 -1
  4. data/lib/nginxtra/version.rb +1 -1
  5. data/vendor/nginx/CHANGES +363 -25
  6. data/vendor/nginx/CHANGES.ru +365 -21
  7. data/vendor/nginx/LICENSE +2 -2
  8. data/vendor/nginx/auto/cc/conf +32 -0
  9. data/vendor/nginx/auto/cc/gcc +1 -1
  10. data/vendor/nginx/auto/cc/icc +2 -2
  11. data/vendor/nginx/auto/cc/msvc +29 -8
  12. data/vendor/nginx/auto/cc/name +2 -25
  13. data/vendor/nginx/auto/cc/sunc +3 -0
  14. data/vendor/nginx/auto/endianness +7 -2
  15. data/vendor/nginx/auto/install +60 -26
  16. data/vendor/nginx/auto/lib/conf +4 -4
  17. data/vendor/nginx/auto/lib/geoip/conf +6 -1
  18. data/vendor/nginx/auto/lib/libgd/conf +6 -1
  19. data/vendor/nginx/auto/lib/libxslt/conf +11 -2
  20. data/vendor/nginx/auto/lib/make +1 -1
  21. data/vendor/nginx/auto/lib/md5/conf +2 -2
  22. data/vendor/nginx/auto/lib/md5/make +2 -2
  23. data/vendor/nginx/auto/lib/openssl/conf +52 -3
  24. data/vendor/nginx/auto/lib/openssl/make +1 -1
  25. data/vendor/nginx/auto/lib/pcre/conf +2 -2
  26. data/vendor/nginx/auto/lib/pcre/make +2 -2
  27. data/vendor/nginx/auto/lib/perl/conf +6 -3
  28. data/vendor/nginx/auto/lib/perl/make +4 -1
  29. data/vendor/nginx/auto/lib/sha1/conf +2 -2
  30. data/vendor/nginx/auto/lib/sha1/make +2 -2
  31. data/vendor/nginx/auto/lib/zlib/conf +2 -2
  32. data/vendor/nginx/auto/lib/zlib/make +2 -2
  33. data/vendor/nginx/auto/make +281 -16
  34. data/vendor/nginx/auto/module +122 -0
  35. data/vendor/nginx/auto/modules +909 -178
  36. data/vendor/nginx/auto/options +81 -19
  37. data/vendor/nginx/auto/os/conf +9 -0
  38. data/vendor/nginx/auto/os/darwin +3 -0
  39. data/vendor/nginx/auto/os/freebsd +0 -20
  40. data/vendor/nginx/auto/os/linux +0 -12
  41. data/vendor/nginx/auto/os/win32 +5 -1
  42. data/vendor/nginx/auto/sources +11 -311
  43. data/vendor/nginx/auto/summary +1 -0
  44. data/vendor/nginx/auto/types/sizeof +5 -3
  45. data/vendor/nginx/auto/types/typedef +9 -4
  46. data/vendor/nginx/auto/types/uintptr_t +7 -2
  47. data/vendor/nginx/auto/unix +72 -12
  48. data/vendor/nginx/conf/fastcgi.conf +1 -0
  49. data/vendor/nginx/conf/fastcgi_params +1 -0
  50. data/vendor/nginx/conf/scgi_params +1 -0
  51. data/vendor/nginx/conf/uwsgi_params +1 -0
  52. data/vendor/nginx/configure +1 -1
  53. data/vendor/nginx/contrib/vim/syntax/nginx.vim +2 -2
  54. data/vendor/nginx/man/nginx.8 +6 -2
  55. data/vendor/nginx/src/core/nginx.c +281 -114
  56. data/vendor/nginx/src/core/nginx.h +2 -2
  57. data/vendor/nginx/src/core/ngx_conf_file.c +54 -13
  58. data/vendor/nginx/src/core/ngx_conf_file.h +8 -52
  59. data/vendor/nginx/src/core/ngx_config.h +0 -5
  60. data/vendor/nginx/src/core/ngx_connection.c +270 -37
  61. data/vendor/nginx/src/core/ngx_connection.h +35 -12
  62. data/vendor/nginx/src/core/ngx_core.h +4 -0
  63. data/vendor/nginx/src/core/ngx_crypt.c +2 -2
  64. data/vendor/nginx/src/core/ngx_cycle.c +72 -25
  65. data/vendor/nginx/src/core/ngx_cycle.h +28 -39
  66. data/vendor/nginx/src/core/ngx_file.c +14 -5
  67. data/vendor/nginx/src/core/ngx_file.h +2 -0
  68. data/vendor/nginx/src/core/ngx_hash.c +13 -1
  69. data/vendor/nginx/src/core/ngx_inet.c +20 -18
  70. data/vendor/nginx/src/core/ngx_log.c +12 -12
  71. data/vendor/nginx/src/core/ngx_log.h +13 -6
  72. data/vendor/nginx/src/core/ngx_module.c +360 -0
  73. data/vendor/nginx/src/core/ngx_module.h +307 -0
  74. data/vendor/nginx/src/core/ngx_open_file_cache.c +2 -2
  75. data/vendor/nginx/src/core/ngx_output_chain.c +8 -4
  76. data/vendor/nginx/src/core/ngx_palloc.c +42 -44
  77. data/vendor/nginx/src/{http/ngx_http_parse_time.c → core/ngx_parse_time.c} +2 -3
  78. data/vendor/nginx/src/core/ngx_parse_time.h +22 -0
  79. data/vendor/nginx/src/core/ngx_proxy_protocol.c +50 -1
  80. data/vendor/nginx/src/core/ngx_proxy_protocol.h +3 -1
  81. data/vendor/nginx/src/core/ngx_regex.c +1 -38
  82. data/vendor/nginx/src/core/ngx_resolver.c +1814 -320
  83. data/vendor/nginx/src/core/ngx_resolver.h +67 -10
  84. data/vendor/nginx/src/core/ngx_rwlock.c +120 -0
  85. data/vendor/nginx/src/core/ngx_rwlock.h +21 -0
  86. data/vendor/nginx/src/core/ngx_slab.c +6 -5
  87. data/vendor/nginx/src/core/ngx_string.c +1 -1
  88. data/vendor/nginx/src/core/ngx_syslog.c +11 -3
  89. data/vendor/nginx/src/core/ngx_syslog.h +2 -1
  90. data/vendor/nginx/src/core/ngx_thread_pool.c +4 -0
  91. data/vendor/nginx/src/core/ngx_times.c +2 -2
  92. data/vendor/nginx/src/event/modules/ngx_devpoll_module.c +3 -1
  93. data/vendor/nginx/src/event/modules/ngx_epoll_module.c +5 -2
  94. data/vendor/nginx/src/event/modules/ngx_eventport_module.c +5 -5
  95. data/vendor/nginx/src/event/modules/ngx_kqueue_module.c +15 -8
  96. data/vendor/nginx/src/event/modules/ngx_poll_module.c +0 -10
  97. data/vendor/nginx/src/event/modules/ngx_select_module.c +0 -10
  98. data/vendor/nginx/src/event/ngx_event.c +60 -103
  99. data/vendor/nginx/src/event/ngx_event.h +22 -26
  100. data/vendor/nginx/src/event/ngx_event_accept.c +414 -88
  101. data/vendor/nginx/src/event/ngx_event_connect.c +27 -18
  102. data/vendor/nginx/src/event/ngx_event_connect.h +1 -0
  103. data/vendor/nginx/src/event/ngx_event_openssl.c +65 -25
  104. data/vendor/nginx/src/event/ngx_event_openssl.h +17 -0
  105. data/vendor/nginx/src/event/ngx_event_openssl_stapling.c +73 -7
  106. data/vendor/nginx/src/event/ngx_event_pipe.c +85 -27
  107. data/vendor/nginx/src/event/ngx_event_pipe.h +10 -0
  108. data/vendor/nginx/src/http/modules/ngx_http_auth_basic_module.c +1 -1
  109. data/vendor/nginx/src/http/modules/ngx_http_auth_request_module.c +2 -2
  110. data/vendor/nginx/src/http/modules/ngx_http_chunked_filter_module.c +2 -2
  111. data/vendor/nginx/src/http/modules/ngx_http_dav_module.c +6 -6
  112. data/vendor/nginx/src/http/modules/ngx_http_fastcgi_module.c +17 -11
  113. data/vendor/nginx/src/http/modules/ngx_http_gzip_filter_module.c +2 -2
  114. data/vendor/nginx/src/http/modules/ngx_http_headers_filter_module.c +9 -9
  115. data/vendor/nginx/src/http/modules/ngx_http_image_filter_module.c +2 -2
  116. data/vendor/nginx/src/http/modules/ngx_http_limit_conn_module.c +2 -2
  117. data/vendor/nginx/src/http/modules/ngx_http_limit_req_module.c +0 -7
  118. data/vendor/nginx/src/http/modules/ngx_http_map_module.c +6 -6
  119. data/vendor/nginx/src/http/modules/ngx_http_memcached_module.c +2 -1
  120. data/vendor/nginx/src/http/modules/ngx_http_mp4_module.c +13 -13
  121. data/vendor/nginx/src/http/modules/ngx_http_not_modified_filter_module.c +2 -2
  122. data/vendor/nginx/src/http/modules/ngx_http_proxy_module.c +26 -21
  123. data/vendor/nginx/src/http/modules/ngx_http_random_index_module.c +1 -1
  124. data/vendor/nginx/src/http/modules/ngx_http_range_filter_module.c +26 -8
  125. data/vendor/nginx/src/http/modules/ngx_http_realip_module.c +73 -3
  126. data/vendor/nginx/src/http/modules/ngx_http_referer_module.c +1 -1
  127. data/vendor/nginx/src/http/modules/ngx_http_rewrite_module.c +6 -6
  128. data/vendor/nginx/src/http/modules/ngx_http_scgi_module.c +5 -3
  129. data/vendor/nginx/src/http/modules/ngx_http_slice_filter_module.c +526 -0
  130. data/vendor/nginx/src/http/modules/ngx_http_ssi_filter_module.c +7 -7
  131. data/vendor/nginx/src/http/modules/ngx_http_ssl_module.c +19 -16
  132. data/vendor/nginx/src/http/modules/ngx_http_static_module.c +1 -1
  133. data/vendor/nginx/src/http/modules/ngx_http_stub_status_module.c +1 -1
  134. data/vendor/nginx/src/http/modules/ngx_http_sub_filter_module.c +373 -173
  135. data/vendor/nginx/src/http/modules/ngx_http_upstream_hash_module.c +72 -46
  136. data/vendor/nginx/src/http/modules/ngx_http_upstream_ip_hash_module.c +18 -30
  137. data/vendor/nginx/src/http/modules/ngx_http_upstream_keepalive_module.c +50 -39
  138. data/vendor/nginx/src/http/modules/ngx_http_upstream_least_conn_module.c +38 -129
  139. data/vendor/nginx/src/http/modules/ngx_http_upstream_zone_module.c +246 -0
  140. data/vendor/nginx/src/http/modules/ngx_http_uwsgi_module.c +6 -5
  141. data/vendor/nginx/src/http/modules/perl/nginx.xs +9 -9
  142. data/vendor/nginx/src/http/ngx_http.c +46 -43
  143. data/vendor/nginx/src/http/ngx_http.h +4 -9
  144. data/vendor/nginx/src/http/ngx_http_cache.h +4 -0
  145. data/vendor/nginx/src/http/ngx_http_copy_filter_module.c +13 -5
  146. data/vendor/nginx/src/http/ngx_http_core_module.c +92 -91
  147. data/vendor/nginx/src/http/ngx_http_core_module.h +12 -8
  148. data/vendor/nginx/src/http/ngx_http_file_cache.c +61 -10
  149. data/vendor/nginx/src/http/ngx_http_request.c +37 -50
  150. data/vendor/nginx/src/http/ngx_http_request.h +10 -15
  151. data/vendor/nginx/src/http/ngx_http_request_body.c +64 -88
  152. data/vendor/nginx/src/http/ngx_http_script.c +3 -3
  153. data/vendor/nginx/src/http/ngx_http_special_response.c +1 -4
  154. data/vendor/nginx/src/http/ngx_http_upstream.c +245 -109
  155. data/vendor/nginx/src/http/ngx_http_upstream.h +11 -5
  156. data/vendor/nginx/src/http/ngx_http_upstream_round_robin.c +212 -65
  157. data/vendor/nginx/src/http/ngx_http_upstream_round_robin.h +66 -5
  158. data/vendor/nginx/src/http/ngx_http_variables.c +28 -15
  159. data/vendor/nginx/src/http/ngx_http_write_filter_module.c +1 -1
  160. data/vendor/nginx/src/http/v2/ngx_http_v2.c +4349 -0
  161. data/vendor/nginx/src/http/v2/ngx_http_v2.h +337 -0
  162. data/vendor/nginx/src/http/v2/ngx_http_v2_filter_module.c +1391 -0
  163. data/vendor/nginx/src/http/v2/ngx_http_v2_huff_decode.c +2714 -0
  164. data/vendor/nginx/src/http/v2/ngx_http_v2_huff_encode.c +254 -0
  165. data/vendor/nginx/src/http/v2/ngx_http_v2_module.c +469 -0
  166. data/vendor/nginx/src/http/{ngx_http_spdy_module.h → v2/ngx_http_v2_module.h} +10 -9
  167. data/vendor/nginx/src/http/v2/ngx_http_v2_table.c +349 -0
  168. data/vendor/nginx/src/mail/ngx_mail.c +49 -82
  169. data/vendor/nginx/src/mail/ngx_mail.h +16 -23
  170. data/vendor/nginx/src/mail/ngx_mail_auth_http_module.c +1 -1
  171. data/vendor/nginx/src/mail/ngx_mail_core_module.c +60 -34
  172. data/vendor/nginx/src/mail/ngx_mail_handler.c +17 -12
  173. data/vendor/nginx/src/mail/ngx_mail_proxy_module.c +1 -14
  174. data/vendor/nginx/src/mail/ngx_mail_smtp_handler.c +1 -1
  175. data/vendor/nginx/src/mail/ngx_mail_ssl_module.c +5 -5
  176. data/vendor/nginx/src/os/unix/ngx_atomic.h +10 -10
  177. data/vendor/nginx/src/os/unix/ngx_channel.h +4 -4
  178. data/vendor/nginx/src/os/unix/ngx_darwin_config.h +2 -0
  179. data/vendor/nginx/src/os/unix/ngx_darwin_init.c +1 -0
  180. data/vendor/nginx/src/os/unix/ngx_dlopen.c +28 -0
  181. data/vendor/nginx/src/os/unix/ngx_dlopen.h +31 -0
  182. data/vendor/nginx/src/os/unix/ngx_errno.h +1 -0
  183. data/vendor/nginx/src/os/unix/ngx_file_aio_read.c +1 -1
  184. data/vendor/nginx/src/os/unix/ngx_files.c +313 -80
  185. data/vendor/nginx/src/os/unix/ngx_files.h +5 -2
  186. data/vendor/nginx/src/os/unix/ngx_freebsd_config.h +3 -1
  187. data/vendor/nginx/src/os/unix/ngx_freebsd_init.c +1 -0
  188. data/vendor/nginx/src/os/unix/ngx_freebsd_sendfile_chain.c +13 -0
  189. data/vendor/nginx/src/os/unix/ngx_linux.h +0 -2
  190. data/vendor/nginx/src/os/unix/ngx_linux_aio_read.c +1 -1
  191. data/vendor/nginx/src/os/unix/ngx_linux_config.h +2 -6
  192. data/vendor/nginx/src/os/unix/ngx_linux_init.c +1 -33
  193. data/vendor/nginx/src/os/unix/ngx_linux_sendfile_chain.c +55 -12
  194. data/vendor/nginx/src/os/unix/ngx_os.h +3 -9
  195. data/vendor/nginx/src/os/unix/ngx_posix_config.h +14 -1
  196. data/vendor/nginx/src/os/unix/ngx_posix_init.c +2 -1
  197. data/vendor/nginx/src/os/unix/ngx_process.c +1 -1
  198. data/vendor/nginx/src/os/unix/ngx_process_cycle.c +25 -51
  199. data/vendor/nginx/src/os/unix/ngx_process_cycle.h +1 -0
  200. data/vendor/nginx/src/os/unix/ngx_readv_chain.c +24 -28
  201. data/vendor/nginx/src/os/unix/ngx_recv.c +30 -79
  202. data/vendor/nginx/src/os/unix/ngx_send.c +1 -1
  203. data/vendor/nginx/src/os/unix/ngx_setaffinity.c +14 -30
  204. data/vendor/nginx/src/os/unix/ngx_setaffinity.h +15 -1
  205. data/vendor/nginx/src/os/unix/ngx_solaris_config.h +2 -0
  206. data/vendor/nginx/src/os/unix/ngx_solaris_init.c +1 -0
  207. data/vendor/nginx/src/os/unix/ngx_solaris_sendfilev_chain.c +23 -0
  208. data/vendor/nginx/src/os/unix/ngx_sunpro_amd64.il +3 -3
  209. data/vendor/nginx/src/os/unix/ngx_sunpro_x86.il +3 -3
  210. data/vendor/nginx/src/os/unix/ngx_udp_recv.c +5 -48
  211. data/vendor/nginx/src/os/unix/ngx_udp_send.c +56 -0
  212. data/vendor/nginx/src/stream/ngx_stream.c +564 -0
  213. data/vendor/nginx/src/stream/ngx_stream.h +212 -0
  214. data/vendor/nginx/src/stream/ngx_stream_access_module.c +451 -0
  215. data/vendor/nginx/src/stream/ngx_stream_core_module.c +562 -0
  216. data/vendor/nginx/src/stream/ngx_stream_handler.c +344 -0
  217. data/vendor/nginx/src/stream/ngx_stream_limit_conn_module.c +632 -0
  218. data/vendor/nginx/src/stream/ngx_stream_proxy_module.c +1674 -0
  219. data/vendor/nginx/src/stream/ngx_stream_ssl_module.c +460 -0
  220. data/vendor/nginx/src/stream/ngx_stream_ssl_module.h +49 -0
  221. data/vendor/nginx/src/stream/ngx_stream_upstream.c +464 -0
  222. data/vendor/nginx/src/stream/ngx_stream_upstream.h +107 -0
  223. data/vendor/nginx/src/stream/ngx_stream_upstream_hash_module.c +656 -0
  224. data/vendor/nginx/src/stream/ngx_stream_upstream_least_conn_module.c +307 -0
  225. data/vendor/nginx/src/stream/ngx_stream_upstream_round_robin.c +702 -0
  226. data/vendor/nginx/src/stream/ngx_stream_upstream_round_robin.h +139 -0
  227. data/vendor/nginx/src/stream/ngx_stream_upstream_zone_module.c +242 -0
  228. metadata +39 -15
  229. data/vendor/nginx/src/event/modules/ngx_aio_module.c +0 -171
  230. data/vendor/nginx/src/event/modules/ngx_rtsig_module.c +0 -735
  231. data/vendor/nginx/src/http/ngx_http_spdy.c +0 -3701
  232. data/vendor/nginx/src/http/ngx_http_spdy.h +0 -261
  233. data/vendor/nginx/src/http/ngx_http_spdy_filter_module.c +0 -1222
  234. data/vendor/nginx/src/http/ngx_http_spdy_module.c +0 -408
  235. data/vendor/nginx/src/os/unix/ngx_aio_read.c +0 -109
  236. data/vendor/nginx/src/os/unix/ngx_aio_read_chain.c +0 -78
  237. data/vendor/nginx/src/os/unix/ngx_aio_write.c +0 -109
  238. data/vendor/nginx/src/os/unix/ngx_aio_write_chain.c +0 -100
@@ -468,12 +468,12 @@ ngx_http_ssi_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
468
468
  while (ctx->pos < ctx->buf->last) {
469
469
 
470
470
  ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
471
- "saved: %d state: %d", ctx->saved, ctx->state);
471
+ "saved: %uz state: %ui", ctx->saved, ctx->state);
472
472
 
473
473
  rc = ngx_http_ssi_parse(r, ctx);
474
474
 
475
475
  ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
476
- "parse: %d, looked: %d %p-%p",
476
+ "parse: %i, looked: %uz %p-%p",
477
477
  rc, ctx->looked, ctx->copy_start, ctx->copy_end);
478
478
 
479
479
  if (rc == NGX_ERROR) {
@@ -485,7 +485,7 @@ ngx_http_ssi_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
485
485
  if (ctx->output) {
486
486
 
487
487
  ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
488
- "saved: %d", ctx->saved);
488
+ "saved: %uz", ctx->saved);
489
489
 
490
490
  if (ctx->saved) {
491
491
 
@@ -1911,7 +1911,7 @@ ngx_http_ssi_regex_match(ngx_http_request_t *r, ngx_str_t *pattern,
1911
1911
 
1912
1912
  if (rc < NGX_REGEX_NO_MATCHED) {
1913
1913
  ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
1914
- ngx_regex_exec_n " failed: %i on \"%V\" using \"%V\"",
1914
+ ngx_regex_exec_n " failed: %d on \"%V\" using \"%V\"",
1915
1915
  rc, str, pattern);
1916
1916
  return NGX_HTTP_SSI_ERROR;
1917
1917
  }
@@ -2005,7 +2005,7 @@ ngx_http_ssi_include(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx,
2005
2005
 
2006
2006
  if (uri && file) {
2007
2007
  ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
2008
- "inlcusion may be either virtual=\"%V\" or file=\"%V\"",
2008
+ "inclusion may be either virtual=\"%V\" or file=\"%V\"",
2009
2009
  uri, file);
2010
2010
  return NGX_HTTP_SSI_ERROR;
2011
2011
  }
@@ -2525,7 +2525,7 @@ ngx_http_ssi_if(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx,
2525
2525
  }
2526
2526
 
2527
2527
  ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
2528
- "evaluted left: \"%V\"", &left);
2528
+ "evaluated left: \"%V\"", &left);
2529
2529
 
2530
2530
  if (p == last) {
2531
2531
  if (left.len) {
@@ -2589,7 +2589,7 @@ ngx_http_ssi_if(ngx_http_request_t *r, ngx_http_ssi_ctx_t *ctx,
2589
2589
  }
2590
2590
 
2591
2591
  ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
2592
- "evaluted right: \"%V\"", &right);
2592
+ "evaluated right: \"%V\"", &right);
2593
2593
 
2594
2594
  if (noregex) {
2595
2595
  if (left.len != right.len) {
@@ -326,10 +326,10 @@ ngx_http_ssl_alpn_select(ngx_ssl_conn_t *ssl_conn, const unsigned char **out,
326
326
  #if (NGX_DEBUG)
327
327
  unsigned int i;
328
328
  #endif
329
- #if (NGX_HTTP_SPDY)
329
+ #if (NGX_HTTP_V2)
330
330
  ngx_http_connection_t *hc;
331
331
  #endif
332
- #if (NGX_HTTP_SPDY || NGX_DEBUG)
332
+ #if (NGX_HTTP_V2 || NGX_DEBUG)
333
333
  ngx_connection_t *c;
334
334
 
335
335
  c = ngx_ssl_get_connection(ssl_conn);
@@ -337,17 +337,19 @@ ngx_http_ssl_alpn_select(ngx_ssl_conn_t *ssl_conn, const unsigned char **out,
337
337
 
338
338
  #if (NGX_DEBUG)
339
339
  for (i = 0; i < inlen; i += in[i] + 1) {
340
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
341
- "SSL ALPN supported by client: %*s", in[i], &in[i + 1]);
340
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
341
+ "SSL ALPN supported by client: %*s",
342
+ (size_t) in[i], &in[i + 1]);
342
343
  }
343
344
  #endif
344
345
 
345
- #if (NGX_HTTP_SPDY)
346
+ #if (NGX_HTTP_V2)
346
347
  hc = c->data;
347
348
 
348
- if (hc->addr_conf->spdy) {
349
- srv = (unsigned char *) NGX_SPDY_NPN_ADVERTISE NGX_HTTP_NPN_ADVERTISE;
350
- srvlen = sizeof(NGX_SPDY_NPN_ADVERTISE NGX_HTTP_NPN_ADVERTISE) - 1;
349
+ if (hc->addr_conf->http2) {
350
+ srv =
351
+ (unsigned char *) NGX_HTTP_V2_ALPN_ADVERTISE NGX_HTTP_NPN_ADVERTISE;
352
+ srvlen = sizeof(NGX_HTTP_V2_ALPN_ADVERTISE NGX_HTTP_NPN_ADVERTISE) - 1;
351
353
 
352
354
  } else
353
355
  #endif
@@ -364,7 +366,7 @@ ngx_http_ssl_alpn_select(ngx_ssl_conn_t *ssl_conn, const unsigned char **out,
364
366
  }
365
367
 
366
368
  ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
367
- "SSL ALPN selected: %*s", *outlen, *out);
369
+ "SSL ALPN selected: %*s", (size_t) *outlen, *out);
368
370
 
369
371
  return SSL_TLSEXT_ERR_OK;
370
372
  }
@@ -378,22 +380,23 @@ static int
378
380
  ngx_http_ssl_npn_advertised(ngx_ssl_conn_t *ssl_conn,
379
381
  const unsigned char **out, unsigned int *outlen, void *arg)
380
382
  {
381
- #if (NGX_HTTP_SPDY || NGX_DEBUG)
383
+ #if (NGX_HTTP_V2 || NGX_DEBUG)
382
384
  ngx_connection_t *c;
383
385
 
384
386
  c = ngx_ssl_get_connection(ssl_conn);
385
387
  ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "SSL NPN advertised");
386
388
  #endif
387
389
 
388
- #if (NGX_HTTP_SPDY)
390
+ #if (NGX_HTTP_V2)
389
391
  {
390
392
  ngx_http_connection_t *hc;
391
393
 
392
394
  hc = c->data;
393
395
 
394
- if (hc->addr_conf->spdy) {
395
- *out = (unsigned char *) NGX_SPDY_NPN_ADVERTISE NGX_HTTP_NPN_ADVERTISE;
396
- *outlen = sizeof(NGX_SPDY_NPN_ADVERTISE NGX_HTTP_NPN_ADVERTISE) - 1;
396
+ if (hc->addr_conf->http2) {
397
+ *out =
398
+ (unsigned char *) NGX_HTTP_V2_NPN_ADVERTISE NGX_HTTP_NPN_ADVERTISE;
399
+ *outlen = sizeof(NGX_HTTP_V2_NPN_ADVERTISE NGX_HTTP_NPN_ADVERTISE) - 1;
397
400
 
398
401
  return SSL_TLSEXT_ERR_OK;
399
402
  }
@@ -561,7 +564,7 @@ ngx_http_ssl_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
561
564
  prev->prefer_server_ciphers, 0);
562
565
 
563
566
  ngx_conf_merge_bitmask_value(conf->protocols, prev->protocols,
564
- (NGX_CONF_BITMASK_SET|NGX_SSL_SSLv3|NGX_SSL_TLSv1
567
+ (NGX_CONF_BITMASK_SET|NGX_SSL_TLSv1
565
568
  |NGX_SSL_TLSv1_1|NGX_SSL_TLSv1_2));
566
569
 
567
570
  ngx_conf_merge_size_value(conf->buffer_size, prev->buffer_size,
@@ -715,7 +718,7 @@ ngx_http_ssl_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
715
718
  SSL_CTX_set_options(conf->ssl.ctx, SSL_OP_CIPHER_SERVER_PREFERENCE);
716
719
  }
717
720
 
718
- #ifndef LIBRESSL_VERSION_NUMBER
721
+ #if (OPENSSL_VERSION_NUMBER < 0x10100001L && !defined LIBRESSL_VERSION_NUMBER)
719
722
  /* a temporary 512-bit RSA key is required for export versions of MSIE */
720
723
  SSL_CTX_set_tmp_rsa_callback(conf->ssl.ctx, ngx_ssl_rsa512_key_callback);
721
724
  #endif
@@ -204,7 +204,7 @@ ngx_http_static_handler(ngx_http_request_t *r)
204
204
 
205
205
  #endif
206
206
 
207
- if (r->method & NGX_HTTP_POST) {
207
+ if (r->method == NGX_HTTP_POST) {
208
208
  return NGX_HTTP_NOT_ALLOWED;
209
209
  }
210
210
 
@@ -89,7 +89,7 @@ ngx_http_stub_status_handler(ngx_http_request_t *r)
89
89
  ngx_chain_t out;
90
90
  ngx_atomic_int_t ap, hn, ac, rq, rd, wr, wa;
91
91
 
92
- if (r->method != NGX_HTTP_GET && r->method != NGX_HTTP_HEAD) {
92
+ if (!(r->method & (NGX_HTTP_GET|NGX_HTTP_HEAD))) {
93
93
  return NGX_HTTP_NOT_ALLOWED;
94
94
  }
95
95
 
@@ -11,8 +11,32 @@
11
11
 
12
12
 
13
13
  typedef struct {
14
- ngx_str_t match;
14
+ ngx_http_complex_value_t match;
15
15
  ngx_http_complex_value_t value;
16
+ } ngx_http_sub_pair_t;
17
+
18
+
19
+ typedef struct {
20
+ ngx_str_t match;
21
+ ngx_http_complex_value_t *value;
22
+ } ngx_http_sub_match_t;
23
+
24
+
25
+ typedef struct {
26
+ ngx_uint_t min_match_len;
27
+ ngx_uint_t max_match_len;
28
+
29
+ u_char index[257];
30
+ u_char shift[256];
31
+ } ngx_http_sub_tables_t;
32
+
33
+
34
+ typedef struct {
35
+ ngx_uint_t dynamic; /* unsigned dynamic:1; */
36
+
37
+ ngx_array_t *pairs;
38
+
39
+ ngx_http_sub_tables_t *tables;
16
40
 
17
41
  ngx_hash_t types;
18
42
 
@@ -20,17 +44,11 @@ typedef struct {
20
44
  ngx_flag_t last_modified;
21
45
 
22
46
  ngx_array_t *types_keys;
47
+ ngx_array_t *matches;
23
48
  } ngx_http_sub_loc_conf_t;
24
49
 
25
50
 
26
- typedef enum {
27
- sub_start_state = 0,
28
- sub_match_state,
29
- } ngx_http_sub_state_e;
30
-
31
-
32
51
  typedef struct {
33
- ngx_str_t match;
34
52
  ngx_str_t saved;
35
53
  ngx_str_t looked;
36
54
 
@@ -48,12 +66,20 @@ typedef struct {
48
66
  ngx_chain_t *busy;
49
67
  ngx_chain_t *free;
50
68
 
51
- ngx_str_t sub;
69
+ ngx_str_t *sub;
70
+ ngx_uint_t applied;
52
71
 
53
- ngx_uint_t state;
72
+ ngx_int_t offset;
73
+ ngx_uint_t index;
74
+
75
+ ngx_http_sub_tables_t *tables;
76
+ ngx_array_t *matches;
54
77
  } ngx_http_sub_ctx_t;
55
78
 
56
79
 
80
+ static ngx_uint_t ngx_http_sub_cmp_index;
81
+
82
+
57
83
  static ngx_int_t ngx_http_sub_output(ngx_http_request_t *r,
58
84
  ngx_http_sub_ctx_t *ctx);
59
85
  static ngx_int_t ngx_http_sub_parse(ngx_http_request_t *r,
@@ -64,6 +90,9 @@ static char * ngx_http_sub_filter(ngx_conf_t *cf, ngx_command_t *cmd,
64
90
  static void *ngx_http_sub_create_conf(ngx_conf_t *cf);
65
91
  static char *ngx_http_sub_merge_conf(ngx_conf_t *cf,
66
92
  void *parent, void *child);
93
+ static void ngx_http_sub_init_tables(ngx_http_sub_tables_t *tables,
94
+ ngx_http_sub_match_t *match, ngx_uint_t n);
95
+ static ngx_int_t ngx_http_sub_cmp_matches(const void *one, const void *two);
67
96
  static ngx_int_t ngx_http_sub_filter_init(ngx_conf_t *cf);
68
97
 
69
98
 
@@ -139,12 +168,16 @@ static ngx_http_output_body_filter_pt ngx_http_next_body_filter;
139
168
  static ngx_int_t
140
169
  ngx_http_sub_header_filter(ngx_http_request_t *r)
141
170
  {
142
- ngx_http_sub_ctx_t *ctx;
171
+ ngx_str_t *m;
172
+ ngx_uint_t i, j, n;
173
+ ngx_http_sub_ctx_t *ctx;
174
+ ngx_http_sub_pair_t *pairs;
175
+ ngx_http_sub_match_t *matches;
143
176
  ngx_http_sub_loc_conf_t *slcf;
144
177
 
145
178
  slcf = ngx_http_get_module_loc_conf(r, ngx_http_sub_filter_module);
146
179
 
147
- if (slcf->match.len == 0
180
+ if (slcf->pairs == NULL
148
181
  || r->headers_out.content_length_n == 0
149
182
  || ngx_http_test_content_type(r, &slcf->types) == NULL)
150
183
  {
@@ -156,19 +189,76 @@ ngx_http_sub_header_filter(ngx_http_request_t *r)
156
189
  return NGX_ERROR;
157
190
  }
158
191
 
159
- ctx->saved.data = ngx_pnalloc(r->pool, slcf->match.len);
192
+ if (slcf->dynamic == 0) {
193
+ ctx->tables = slcf->tables;
194
+ ctx->matches = slcf->matches;
195
+
196
+ } else {
197
+ pairs = slcf->pairs->elts;
198
+ n = slcf->pairs->nelts;
199
+
200
+ matches = ngx_pcalloc(r->pool, sizeof(ngx_http_sub_match_t) * n);
201
+ if (matches == NULL) {
202
+ return NGX_ERROR;
203
+ }
204
+
205
+ j = 0;
206
+ for (i = 0; i < n; i++) {
207
+ matches[j].value = &pairs[i].value;
208
+
209
+ if (pairs[i].match.lengths == NULL) {
210
+ matches[j].match = pairs[i].match.value;
211
+ j++;
212
+ continue;
213
+ }
214
+
215
+ m = &matches[j].match;
216
+ if (ngx_http_complex_value(r, &pairs[i].match, m) != NGX_OK) {
217
+ return NGX_ERROR;
218
+ }
219
+
220
+ if (m->len == 0) {
221
+ continue;
222
+ }
223
+
224
+ ngx_strlow(m->data, m->data, m->len);
225
+ j++;
226
+ }
227
+
228
+ if (j == 0) {
229
+ return ngx_http_next_header_filter(r);
230
+ }
231
+
232
+ ctx->matches = ngx_palloc(r->pool, sizeof(ngx_array_t));
233
+ if (ctx->matches == NULL) {
234
+ return NGX_ERROR;
235
+ }
236
+
237
+ ctx->matches->elts = matches;
238
+ ctx->matches->nelts = j;
239
+
240
+ ctx->tables = ngx_palloc(r->pool, sizeof(ngx_http_sub_tables_t));
241
+ if (ctx->tables == NULL) {
242
+ return NGX_ERROR;
243
+ }
244
+
245
+ ngx_http_sub_init_tables(ctx->tables, ctx->matches->elts,
246
+ ctx->matches->nelts);
247
+ }
248
+
249
+ ngx_http_set_ctx(r, ctx, ngx_http_sub_filter_module);
250
+
251
+ ctx->saved.data = ngx_pnalloc(r->pool, ctx->tables->max_match_len - 1);
160
252
  if (ctx->saved.data == NULL) {
161
253
  return NGX_ERROR;
162
254
  }
163
255
 
164
- ctx->looked.data = ngx_pnalloc(r->pool, slcf->match.len);
256
+ ctx->looked.data = ngx_pnalloc(r->pool, ctx->tables->max_match_len - 1);
165
257
  if (ctx->looked.data == NULL) {
166
258
  return NGX_ERROR;
167
259
  }
168
260
 
169
- ngx_http_set_ctx(r, ctx, ngx_http_sub_filter_module);
170
-
171
- ctx->match = slcf->match;
261
+ ctx->offset = ctx->tables->min_match_len - 1;
172
262
  ctx->last_out = &ctx->out;
173
263
 
174
264
  r->filter_need_in_memory = 1;
@@ -194,8 +284,10 @@ ngx_http_sub_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
194
284
  {
195
285
  ngx_int_t rc;
196
286
  ngx_buf_t *b;
287
+ ngx_str_t *sub;
197
288
  ngx_chain_t *cl;
198
289
  ngx_http_sub_ctx_t *ctx;
290
+ ngx_http_sub_match_t *match;
199
291
  ngx_http_sub_loc_conf_t *slcf;
200
292
 
201
293
  ctx = ngx_http_get_module_ctx(r, ngx_http_sub_filter_module);
@@ -242,22 +334,14 @@ ngx_http_sub_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
242
334
  ctx->pos = ctx->buf->pos;
243
335
  }
244
336
 
245
- if (ctx->state == sub_start_state) {
246
- ctx->copy_start = ctx->pos;
247
- ctx->copy_end = ctx->pos;
248
- }
249
-
250
337
  b = NULL;
251
338
 
252
339
  while (ctx->pos < ctx->buf->last) {
253
340
 
254
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
255
- "saved: \"%V\" state: %d", &ctx->saved, ctx->state);
256
-
257
341
  rc = ngx_http_sub_parse(r, ctx);
258
342
 
259
343
  ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
260
- "parse: %d, looked: \"%V\" %p-%p",
344
+ "parse: %i, looked: \"%V\" %p-%p",
261
345
  rc, &ctx->looked, ctx->copy_start, ctx->copy_end);
262
346
 
263
347
  if (rc == NGX_ERROR) {
@@ -320,20 +404,6 @@ ngx_http_sub_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
320
404
  ctx->last_out = &cl->next;
321
405
  }
322
406
 
323
- if (ctx->state == sub_start_state) {
324
- ctx->copy_start = ctx->pos;
325
- ctx->copy_end = ctx->pos;
326
-
327
- } else {
328
- ctx->copy_start = NULL;
329
- ctx->copy_end = NULL;
330
- }
331
-
332
- if (ctx->looked.len > (size_t) (ctx->pos - ctx->buf->pos)) {
333
- ctx->saved.len = ctx->looked.len - (ctx->pos - ctx->buf->pos);
334
- ngx_memcpy(ctx->saved.data, ctx->looked.data, ctx->saved.len);
335
- }
336
-
337
407
  if (rc == NGX_AGAIN) {
338
408
  continue;
339
409
  }
@@ -352,19 +422,30 @@ ngx_http_sub_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
352
422
 
353
423
  slcf = ngx_http_get_module_loc_conf(r, ngx_http_sub_filter_module);
354
424
 
355
- if (ctx->sub.data == NULL) {
425
+ if (ctx->sub == NULL) {
426
+ ctx->sub = ngx_pcalloc(r->pool, sizeof(ngx_str_t)
427
+ * ctx->matches->nelts);
428
+ if (ctx->sub == NULL) {
429
+ return NGX_ERROR;
430
+ }
431
+ }
432
+
433
+ sub = &ctx->sub[ctx->index];
434
+
435
+ if (sub->data == NULL) {
436
+ match = ctx->matches->elts;
356
437
 
357
- if (ngx_http_complex_value(r, &slcf->value, &ctx->sub)
438
+ if (ngx_http_complex_value(r, match[ctx->index].value, sub)
358
439
  != NGX_OK)
359
440
  {
360
441
  return NGX_ERROR;
361
442
  }
362
443
  }
363
444
 
364
- if (ctx->sub.len) {
445
+ if (sub->len) {
365
446
  b->memory = 1;
366
- b->pos = ctx->sub.data;
367
- b->last = ctx->sub.data + ctx->sub.len;
447
+ b->pos = sub->data;
448
+ b->last = sub->data + sub->len;
368
449
 
369
450
  } else {
370
451
  b->sync = 1;
@@ -373,7 +454,8 @@ ngx_http_sub_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
373
454
  *ctx->last_out = cl;
374
455
  ctx->last_out = &cl->next;
375
456
 
376
- ctx->once = slcf->once;
457
+ ctx->index = 0;
458
+ ctx->once = slcf->once && (++ctx->applied == ctx->matches->nelts);
377
459
 
378
460
  continue;
379
461
  }
@@ -428,9 +510,6 @@ ngx_http_sub_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
428
510
  }
429
511
 
430
512
  ctx->buf = NULL;
431
-
432
- ctx->saved.len = ctx->looked.len;
433
- ngx_memcpy(ctx->saved.data, ctx->looked.data, ctx->looked.len);
434
513
  }
435
514
 
436
515
  if (ctx->out == NULL && ctx->busy == NULL) {
@@ -513,158 +592,142 @@ ngx_http_sub_output(ngx_http_request_t *r, ngx_http_sub_ctx_t *ctx)
513
592
  static ngx_int_t
514
593
  ngx_http_sub_parse(ngx_http_request_t *r, ngx_http_sub_ctx_t *ctx)
515
594
  {
516
- u_char *p, *last, *copy_end, ch, match;
517
- size_t looked, i;
518
- ngx_http_sub_state_e state;
595
+ u_char *p, *last, *pat, *pat_end, c;
596
+ ngx_str_t *m;
597
+ ngx_int_t offset, start, next, end, len, rc;
598
+ ngx_uint_t shift, i, j;
599
+ ngx_http_sub_match_t *match;
600
+ ngx_http_sub_tables_t *tables;
601
+ ngx_http_sub_loc_conf_t *slcf;
519
602
 
520
- if (ctx->once) {
521
- ctx->copy_start = ctx->pos;
522
- ctx->copy_end = ctx->buf->last;
523
- ctx->pos = ctx->buf->last;
524
- ctx->looked.len = 0;
603
+ slcf = ngx_http_get_module_loc_conf(r, ngx_http_sub_filter_module);
604
+ tables = ctx->tables;
525
605
 
526
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "once");
606
+ offset = ctx->offset;
607
+ end = ctx->buf->last - ctx->pos;
527
608
 
528
- return NGX_AGAIN;
609
+ if (ctx->once) {
610
+ /* sets start and next to end */
611
+ offset = end + (ngx_int_t) tables->min_match_len - 1;
612
+ goto again;
529
613
  }
530
614
 
531
- state = ctx->state;
532
- looked = ctx->looked.len;
533
- last = ctx->buf->last;
534
- copy_end = ctx->copy_end;
615
+ while (offset < end) {
535
616
 
536
- for (p = ctx->pos; p < last; p++) {
617
+ c = offset < 0 ? ctx->looked.data[ctx->looked.len + offset]
618
+ : ctx->pos[offset];
537
619
 
538
- ch = *p;
539
- ch = ngx_tolower(ch);
620
+ c = ngx_tolower(c);
540
621
 
541
- if (state == sub_start_state) {
622
+ shift = tables->shift[c];
623
+ if (shift > 0) {
624
+ offset += shift;
625
+ continue;
626
+ }
542
627
 
543
- /* the tight loop */
628
+ /* a potential match */
544
629
 
545
- match = ctx->match.data[0];
630
+ start = offset - (ngx_int_t) tables->min_match_len + 1;
631
+ match = ctx->matches->elts;
546
632
 
547
- for ( ;; ) {
548
- if (ch == match) {
633
+ i = ngx_max(tables->index[c], ctx->index);
634
+ j = tables->index[c + 1];
549
635
 
550
- if (ctx->match.len == 1) {
551
- ctx->pos = p + 1;
552
- ctx->copy_end = p;
636
+ while (i != j) {
553
637
 
554
- return NGX_OK;
555
- }
638
+ if (slcf->once && ctx->sub && ctx->sub[i].data) {
639
+ goto next;
640
+ }
556
641
 
557
- copy_end = p;
558
- ctx->looked.data[0] = *p;
559
- looked = 1;
560
- state = sub_match_state;
642
+ m = &match[i].match;
561
643
 
562
- goto match_started;
563
- }
644
+ pat = m->data;
645
+ pat_end = m->data + m->len;
564
646
 
565
- if (++p == last) {
566
- break;
567
- }
647
+ if (start >= 0) {
648
+ p = ctx->pos + start;
568
649
 
569
- ch = *p;
570
- ch = ngx_tolower(ch);
571
- }
650
+ } else {
651
+ last = ctx->looked.data + ctx->looked.len;
652
+ p = last + start;
572
653
 
573
- ctx->state = state;
574
- ctx->pos = p;
575
- ctx->looked.len = looked;
576
- ctx->copy_end = p;
654
+ while (p < last && pat < pat_end) {
655
+ if (ngx_tolower(*p) != *pat) {
656
+ goto next;
657
+ }
577
658
 
578
- if (ctx->copy_start == NULL) {
579
- ctx->copy_start = ctx->buf->pos;
659
+ p++;
660
+ pat++;
661
+ }
662
+
663
+ p = ctx->pos;
580
664
  }
581
665
 
582
- return NGX_AGAIN;
666
+ while (p < ctx->buf->last && pat < pat_end) {
667
+ if (ngx_tolower(*p) != *pat) {
668
+ goto next;
669
+ }
583
670
 
584
- match_started:
671
+ p++;
672
+ pat++;
673
+ }
585
674
 
586
- continue;
587
- }
675
+ ctx->index = i;
588
676
 
589
- /* state == sub_match_state */
677
+ if (pat != pat_end) {
678
+ /* partial match */
679
+ goto again;
680
+ }
590
681
 
591
- if (ch == ctx->match.data[looked]) {
592
- ctx->looked.data[looked] = *p;
593
- looked++;
682
+ ctx->offset = offset + (ngx_int_t) m->len;
683
+ next = start + (ngx_int_t) m->len;
684
+ end = ngx_max(next, 0);
685
+ rc = NGX_OK;
594
686
 
595
- if (looked == ctx->match.len) {
687
+ goto done;
596
688
 
597
- ctx->state = sub_start_state;
598
- ctx->pos = p + 1;
599
- ctx->looked.len = 0;
600
- ctx->saved.len = 0;
601
- ctx->copy_end = copy_end;
689
+ next:
602
690
 
603
- if (ctx->copy_start == NULL && copy_end) {
604
- ctx->copy_start = ctx->buf->pos;
605
- }
691
+ i++;
692
+ }
606
693
 
607
- return NGX_OK;
608
- }
694
+ offset++;
695
+ ctx->index = 0;
696
+ }
609
697
 
610
- } else {
611
- /*
612
- * check if there is another partial match in previously
613
- * matched substring to catch cases like "aab" in "aaab"
614
- */
615
-
616
- ctx->looked.data[looked] = *p;
617
- looked++;
618
-
619
- for (i = 1; i < looked; i++) {
620
- if (ngx_strncasecmp(ctx->looked.data + i,
621
- ctx->match.data, looked - i)
622
- == 0)
623
- {
624
- break;
625
- }
626
- }
698
+ again:
627
699
 
628
- if (i < looked) {
629
- if (ctx->saved.len > i) {
630
- ctx->saved.len = i;
631
- }
700
+ ctx->offset = offset;
701
+ start = offset - (ngx_int_t) tables->min_match_len + 1;
702
+ next = start;
703
+ rc = NGX_AGAIN;
632
704
 
633
- if ((size_t) (p + 1 - ctx->buf->pos) >= looked - i) {
634
- copy_end = p + 1 - (looked - i);
635
- }
705
+ done:
636
706
 
637
- ngx_memmove(ctx->looked.data, ctx->looked.data + i, looked - i);
638
- looked = looked - i;
707
+ /* send [ - looked.len, start ] to client */
639
708
 
640
- } else {
641
- copy_end = p;
642
- looked = 0;
643
- state = sub_start_state;
644
- }
709
+ ctx->saved.len = ctx->looked.len + ngx_min(start, 0);
710
+ ngx_memcpy(ctx->saved.data, ctx->looked.data, ctx->saved.len);
645
711
 
646
- if (ctx->saved.len) {
647
- p++;
648
- goto out;
649
- }
650
- }
651
- }
712
+ ctx->copy_start = ctx->pos;
713
+ ctx->copy_end = ctx->pos + ngx_max(start, 0);
652
714
 
653
- ctx->saved.len = 0;
715
+ /* save [ next, end ] in looked */
654
716
 
655
- out:
717
+ len = ngx_min(next, 0);
718
+ p = ctx->looked.data;
719
+ p = ngx_movemem(p, p + ctx->looked.len + len, - len);
656
720
 
657
- ctx->state = state;
658
- ctx->pos = p;
659
- ctx->looked.len = looked;
721
+ len = ngx_max(next, 0);
722
+ p = ngx_cpymem(p, ctx->pos + len, end - len);
723
+ ctx->looked.len = p - ctx->looked.data;
660
724
 
661
- ctx->copy_end = (state == sub_start_state) ? p : copy_end;
725
+ /* update position */
662
726
 
663
- if (ctx->copy_start == NULL && ctx->copy_end) {
664
- ctx->copy_start = ctx->buf->pos;
665
- }
727
+ ctx->pos += end;
728
+ ctx->offset -= end;
666
729
 
667
- return NGX_AGAIN;
730
+ return rc;
668
731
  }
669
732
 
670
733
 
@@ -674,23 +737,60 @@ ngx_http_sub_filter(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
674
737
  ngx_http_sub_loc_conf_t *slcf = conf;
675
738
 
676
739
  ngx_str_t *value;
740
+ ngx_http_sub_pair_t *pair;
677
741
  ngx_http_compile_complex_value_t ccv;
678
742
 
679
- if (slcf->match.data) {
680
- return "is duplicate";
743
+ value = cf->args->elts;
744
+
745
+ if (value[1].len == 0) {
746
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "empty search pattern");
747
+ return NGX_CONF_ERROR;
681
748
  }
682
749
 
683
- value = cf->args->elts;
750
+ if (slcf->pairs == NULL) {
751
+ slcf->pairs = ngx_array_create(cf->pool, 1,
752
+ sizeof(ngx_http_sub_pair_t));
753
+ if (slcf->pairs == NULL) {
754
+ return NGX_CONF_ERROR;
755
+ }
756
+ }
757
+
758
+ if (slcf->pairs->nelts == 255) {
759
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
760
+ "number of search patterns exceeds 255");
761
+ return NGX_CONF_ERROR;
762
+ }
684
763
 
685
764
  ngx_strlow(value[1].data, value[1].data, value[1].len);
686
765
 
687
- slcf->match = value[1];
766
+ pair = ngx_array_push(slcf->pairs);
767
+ if (pair == NULL) {
768
+ return NGX_CONF_ERROR;
769
+ }
770
+
771
+ ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
772
+
773
+ ccv.cf = cf;
774
+ ccv.value = &value[1];
775
+ ccv.complex_value = &pair->match;
776
+
777
+ if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
778
+ return NGX_CONF_ERROR;
779
+ }
780
+
781
+ if (ccv.complex_value->lengths != NULL) {
782
+ slcf->dynamic = 1;
783
+
784
+ } else {
785
+ ngx_strlow(pair->match.value.data, pair->match.value.data,
786
+ pair->match.value.len);
787
+ }
688
788
 
689
789
  ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
690
790
 
691
791
  ccv.cf = cf;
692
792
  ccv.value = &value[2];
693
- ccv.complex_value = &slcf->value;
793
+ ccv.complex_value = &pair->value;
694
794
 
695
795
  if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
696
796
  return NGX_CONF_ERROR;
@@ -713,9 +813,12 @@ ngx_http_sub_create_conf(ngx_conf_t *cf)
713
813
  /*
714
814
  * set by ngx_pcalloc():
715
815
  *
716
- * conf->match = { 0, NULL };
816
+ * conf->dynamic = 0;
817
+ * conf->pairs = NULL;
818
+ * conf->tables = NULL;
717
819
  * conf->types = { NULL };
718
820
  * conf->types_keys = NULL;
821
+ * conf->matches = NULL;
719
822
  */
720
823
 
721
824
  slcf->once = NGX_CONF_UNSET;
@@ -728,17 +831,15 @@ ngx_http_sub_create_conf(ngx_conf_t *cf)
728
831
  static char *
729
832
  ngx_http_sub_merge_conf(ngx_conf_t *cf, void *parent, void *child)
730
833
  {
731
- ngx_http_sub_loc_conf_t *prev = parent;
732
- ngx_http_sub_loc_conf_t *conf = child;
834
+ ngx_uint_t i, n;
835
+ ngx_http_sub_pair_t *pairs;
836
+ ngx_http_sub_match_t *matches;
837
+ ngx_http_sub_loc_conf_t *prev = parent;
838
+ ngx_http_sub_loc_conf_t *conf = child;
733
839
 
734
840
  ngx_conf_merge_value(conf->once, prev->once, 1);
735
- ngx_conf_merge_str_value(conf->match, prev->match, "");
736
841
  ngx_conf_merge_value(conf->last_modified, prev->last_modified, 0);
737
842
 
738
- if (conf->value.value.data == NULL) {
739
- conf->value = prev->value;
740
- }
741
-
742
843
  if (ngx_http_merge_types(cf, &conf->types_keys, &conf->types,
743
844
  &prev->types_keys, &prev->types,
744
845
  ngx_http_html_default_types)
@@ -747,10 +848,109 @@ ngx_http_sub_merge_conf(ngx_conf_t *cf, void *parent, void *child)
747
848
  return NGX_CONF_ERROR;
748
849
  }
749
850
 
851
+ if (conf->pairs == NULL) {
852
+ conf->dynamic = prev->dynamic;
853
+ conf->pairs = prev->pairs;
854
+ conf->matches = prev->matches;
855
+ conf->tables = prev->tables;
856
+ }
857
+
858
+ if (conf->pairs && conf->dynamic == 0 && conf->tables == NULL) {
859
+ pairs = conf->pairs->elts;
860
+ n = conf->pairs->nelts;
861
+
862
+ matches = ngx_palloc(cf->pool, sizeof(ngx_http_sub_match_t) * n);
863
+ if (matches == NULL) {
864
+ return NGX_CONF_ERROR;
865
+ }
866
+
867
+ for (i = 0; i < n; i++) {
868
+ matches[i].match = pairs[i].match.value;
869
+ matches[i].value = &pairs[i].value;
870
+ }
871
+
872
+ conf->matches = ngx_palloc(cf->pool, sizeof(ngx_array_t));
873
+ if (conf->matches == NULL) {
874
+ return NGX_CONF_ERROR;
875
+ }
876
+
877
+ conf->matches->elts = matches;
878
+ conf->matches->nelts = n;
879
+
880
+ conf->tables = ngx_palloc(cf->pool, sizeof(ngx_http_sub_tables_t));
881
+ if (conf->tables == NULL) {
882
+ return NGX_CONF_ERROR;
883
+ }
884
+
885
+ ngx_http_sub_init_tables(conf->tables, conf->matches->elts,
886
+ conf->matches->nelts);
887
+ }
888
+
750
889
  return NGX_CONF_OK;
751
890
  }
752
891
 
753
892
 
893
+ static void
894
+ ngx_http_sub_init_tables(ngx_http_sub_tables_t *tables,
895
+ ngx_http_sub_match_t *match, ngx_uint_t n)
896
+ {
897
+ u_char c;
898
+ ngx_uint_t i, j, min, max, ch;
899
+
900
+ min = match[0].match.len;
901
+ max = match[0].match.len;
902
+
903
+ for (i = 1; i < n; i++) {
904
+ min = ngx_min(min, match[i].match.len);
905
+ max = ngx_max(max, match[i].match.len);
906
+ }
907
+
908
+ tables->min_match_len = min;
909
+ tables->max_match_len = max;
910
+
911
+ ngx_http_sub_cmp_index = tables->min_match_len - 1;
912
+ ngx_sort(match, n, sizeof(ngx_http_sub_match_t), ngx_http_sub_cmp_matches);
913
+
914
+ min = ngx_min(min, 255);
915
+ ngx_memset(tables->shift, min, 256);
916
+
917
+ ch = 0;
918
+
919
+ for (i = 0; i < n; i++) {
920
+
921
+ for (j = 0; j < min; j++) {
922
+ c = match[i].match.data[tables->min_match_len - 1 - j];
923
+ tables->shift[c] = ngx_min(tables->shift[c], (u_char) j);
924
+ }
925
+
926
+ c = match[i].match.data[tables->min_match_len - 1];
927
+ while (ch <= c) {
928
+ tables->index[ch++] = (u_char) i;
929
+ }
930
+ }
931
+
932
+ while (ch < 257) {
933
+ tables->index[ch++] = (u_char) n;
934
+ }
935
+ }
936
+
937
+
938
+ static ngx_int_t
939
+ ngx_http_sub_cmp_matches(const void *one, const void *two)
940
+ {
941
+ ngx_int_t c1, c2;
942
+ ngx_http_sub_match_t *first, *second;
943
+
944
+ first = (ngx_http_sub_match_t *) one;
945
+ second = (ngx_http_sub_match_t *) two;
946
+
947
+ c1 = first->match.data[ngx_http_sub_cmp_index];
948
+ c2 = second->match.data[ngx_http_sub_cmp_index];
949
+
950
+ return c1 - c2;
951
+ }
952
+
953
+
754
954
  static ngx_int_t
755
955
  ngx_http_sub_filter_init(ngx_conf_t *cf)
756
956
  {