passenger 4.0.59 → 4.0.60

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of passenger might be problematic. Click here for more details.

Files changed (579) hide show
  1. checksums.yaml +8 -8
  2. checksums.yaml.gz.asc +7 -7
  3. data.tar.gz.asc +7 -7
  4. data/CHANGELOG +15 -0
  5. data/bin/passenger-install-apache2-module +2 -1
  6. data/bin/passenger-install-nginx-module +8 -2
  7. data/ext/apache2/Hooks.cpp +21 -2
  8. data/ext/apache2/MergeDirConfig.cpp +40 -40
  9. data/ext/common/ApplicationPool2/Group.h +14 -10
  10. data/ext/common/ApplicationPool2/Implementation.cpp +13 -7
  11. data/ext/common/ApplicationPool2/SmartSpawner.h +4 -1
  12. data/ext/common/Constants.h +1 -1
  13. data/ext/nginx/ContentHandler.c +17 -1
  14. data/lib/phusion_passenger.rb +4 -5
  15. data/lib/phusion_passenger/platform_info/depcheck_specs/libs.rb +4 -3
  16. data/lib/phusion_passenger/platform_info/openssl.rb +61 -0
  17. data/lib/phusion_passenger/standalone/runtime_installer.rb +27 -22
  18. data/packaging/debian/LICENSE.md +19 -0
  19. data/packaging/debian/README.md +320 -0
  20. data/packaging/debian/Vagrantfile +25 -0
  21. data/packaging/debian/build +210 -0
  22. data/packaging/debian/debian_specs/nginx/changelog +1989 -0
  23. data/packaging/debian/debian_specs/nginx/compat.erb +5 -0
  24. data/packaging/debian/debian_specs/nginx/conf/fastcgi.conf +25 -0
  25. data/packaging/debian/debian_specs/nginx/conf/fastcgi_params +24 -0
  26. data/packaging/debian/debian_specs/nginx/conf/koi-utf +109 -0
  27. data/packaging/debian/debian_specs/nginx/conf/koi-win +103 -0
  28. data/packaging/debian/debian_specs/nginx/conf/mime.types +89 -0
  29. data/packaging/debian/debian_specs/nginx/conf/nginx.conf.erb +97 -0
  30. data/packaging/debian/debian_specs/nginx/conf/proxy_params +4 -0
  31. data/packaging/debian/debian_specs/nginx/conf/scgi_params +16 -0
  32. data/packaging/debian/debian_specs/nginx/conf/sites-available/default.erb +93 -0
  33. data/packaging/debian/debian_specs/nginx/conf/snippets/fastcgi-php.conf +13 -0
  34. data/packaging/debian/debian_specs/nginx/conf/snippets/snakeoil.conf +5 -0
  35. data/packaging/debian/debian_specs/nginx/conf/uwsgi_params +16 -0
  36. data/packaging/debian/debian_specs/nginx/conf/win-utf +125 -0
  37. data/packaging/debian/debian_specs/nginx/control.erb +226 -0
  38. data/packaging/debian/debian_specs/nginx/copyright +196 -0
  39. data/packaging/debian/debian_specs/nginx/debian-full.lintian-overrides +1 -0
  40. data/packaging/debian/debian_specs/nginx/gbp.conf +2 -0
  41. data/packaging/debian/debian_specs/nginx/help/docs/fcgiwrap +14 -0
  42. data/packaging/debian/debian_specs/nginx/help/docs/php +119 -0
  43. data/packaging/debian/debian_specs/nginx/help/docs/support-irc +28 -0
  44. data/packaging/debian/debian_specs/nginx/help/docs/upstream +51 -0
  45. data/packaging/debian/debian_specs/nginx/help/examples/drupal +114 -0
  46. data/packaging/debian/debian_specs/nginx/help/examples/http +59 -0
  47. data/packaging/debian/debian_specs/nginx/help/examples/mail +30 -0
  48. data/packaging/debian/debian_specs/nginx/help/examples/mailman +59 -0
  49. data/packaging/debian/debian_specs/nginx/help/examples/nginx.conf +34 -0
  50. data/packaging/debian/debian_specs/nginx/help/examples/nginx_modsite +162 -0
  51. data/packaging/debian/debian_specs/nginx/help/examples/virtual_hosts +155 -0
  52. data/packaging/debian/debian_specs/nginx/help/examples/wordpress +74 -0
  53. data/packaging/debian/debian_specs/nginx/helpers.rb +41 -0
  54. data/packaging/debian/debian_specs/nginx/index-debian.html.in +32 -0
  55. data/packaging/debian/debian_specs/nginx/index-ubuntu.html.in +32 -0
  56. data/packaging/debian/debian_specs/nginx/index.html.erb +10 -0
  57. data/packaging/debian/debian_specs/nginx/modules/README.Modules-versions +65 -0
  58. data/packaging/debian/debian_specs/nginx/modules/headers-more-nginx-module/README.markdown +510 -0
  59. data/packaging/debian/debian_specs/nginx/modules/headers-more-nginx-module/config +5 -0
  60. data/packaging/debian/debian_specs/nginx/modules/headers-more-nginx-module/doc/HttpHeadersMoreModule.wiki +395 -0
  61. data/packaging/debian/debian_specs/nginx/modules/headers-more-nginx-module/src/ddebug.h +119 -0
  62. data/packaging/debian/debian_specs/nginx/modules/headers-more-nginx-module/src/ngx_http_headers_more_filter_module.c +348 -0
  63. data/packaging/debian/debian_specs/nginx/modules/headers-more-nginx-module/src/ngx_http_headers_more_filter_module.h +80 -0
  64. data/packaging/debian/debian_specs/nginx/modules/headers-more-nginx-module/src/ngx_http_headers_more_headers_in.c +826 -0
  65. data/packaging/debian/debian_specs/nginx/modules/headers-more-nginx-module/src/ngx_http_headers_more_headers_in.h +26 -0
  66. data/packaging/debian/debian_specs/nginx/modules/headers-more-nginx-module/src/ngx_http_headers_more_headers_out.c +716 -0
  67. data/packaging/debian/debian_specs/nginx/modules/headers-more-nginx-module/src/ngx_http_headers_more_headers_out.h +26 -0
  68. data/packaging/debian/debian_specs/nginx/modules/headers-more-nginx-module/src/ngx_http_headers_more_util.c +380 -0
  69. data/packaging/debian/debian_specs/nginx/modules/headers-more-nginx-module/src/ngx_http_headers_more_util.h +52 -0
  70. data/packaging/debian/debian_specs/nginx/modules/headers-more-nginx-module/util/build.sh +32 -0
  71. data/packaging/debian/debian_specs/nginx/modules/headers-more-nginx-module/valgrind.suppress +215 -0
  72. data/packaging/debian/debian_specs/nginx/modules/nginx-auth-pam/ChangeLog +35 -0
  73. data/packaging/debian/debian_specs/nginx/modules/nginx-auth-pam/LICENSE +25 -0
  74. data/packaging/debian/debian_specs/nginx/modules/nginx-auth-pam/README.md +93 -0
  75. data/packaging/debian/debian_specs/nginx/modules/nginx-auth-pam/config +4 -0
  76. data/packaging/debian/debian_specs/nginx/modules/nginx-auth-pam/ngx_http_auth_pam_module.c +462 -0
  77. data/packaging/debian/debian_specs/nginx/modules/nginx-cache-purge/CHANGES +66 -0
  78. data/packaging/debian/debian_specs/nginx/modules/nginx-cache-purge/LICENSE +26 -0
  79. data/packaging/debian/debian_specs/nginx/modules/nginx-cache-purge/README.md +171 -0
  80. data/packaging/debian/debian_specs/nginx/modules/nginx-cache-purge/TODO.md +7 -0
  81. data/packaging/debian/debian_specs/nginx/modules/nginx-cache-purge/config +21 -0
  82. data/packaging/debian/debian_specs/nginx/modules/nginx-cache-purge/ngx_cache_purge_module.c +1803 -0
  83. data/packaging/debian/debian_specs/nginx/modules/nginx-dav-ext-module/README +29 -0
  84. data/packaging/debian/debian_specs/nginx/modules/nginx-dav-ext-module/config +9 -0
  85. data/packaging/debian/debian_specs/nginx/modules/nginx-dav-ext-module/ngx_http_dav_ext_module.c +824 -0
  86. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/README +139 -0
  87. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/README_AUTO_LIB +395 -0
  88. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/TODO +1 -0
  89. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/auto/actions/array +10 -0
  90. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/auto/actions/palloc +8 -0
  91. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/auto/build +597 -0
  92. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/auto/data/action_replacements +5 -0
  93. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/auto/data/action_types +12 -0
  94. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/auto/data/conf_args +22 -0
  95. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/auto/data/conf_locs +25 -0
  96. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/auto/data/conf_macros +35 -0
  97. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/auto/data/contexts +22 -0
  98. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/auto/data/header_files +3 -0
  99. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/auto/data/headers +4 -0
  100. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/auto/data/module_dependencies +5 -0
  101. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/auto/data/modules_optional +15 -0
  102. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/auto/data/prefixes +2 -0
  103. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/auto/src/array.h +7 -0
  104. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/auto/src/conf_cmd_basic.h +43 -0
  105. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/auto/src/conf_merge.h +78 -0
  106. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/auto/src/palloc.h +6 -0
  107. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/auto/text/autogen +12 -0
  108. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/config +49 -0
  109. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/docs/core/action_macros +63 -0
  110. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/docs/core/conf_cmds +62 -0
  111. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/docs/modules/set_var +124 -0
  112. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/docs/patches/more_logging_info +48 -0
  113. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/docs/upstream/list +45 -0
  114. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/examples/README +12 -0
  115. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/examples/http/set_var/config +4 -0
  116. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/examples/http/set_var/ngx_http_set_var_examples_module.c +136 -0
  117. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/ngx_auto_lib_core +797 -0
  118. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/notes/CHANGES +17 -0
  119. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/notes/LICENSE +24 -0
  120. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/objs/ndk_array.h +113 -0
  121. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/objs/ndk_conf_cmd_basic.h +2203 -0
  122. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/objs/ndk_conf_cmd_extra.h +5423 -0
  123. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/objs/ndk_conf_merge.h +227 -0
  124. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/objs/ndk_config.c +72 -0
  125. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/objs/ndk_config.h +98 -0
  126. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/objs/ndk_includes.h +66 -0
  127. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/objs/ndk_palloc.h +112 -0
  128. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/patches/auto_config +16 -0
  129. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/patches/expose_rewrite_functions +291 -0
  130. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/patches/rewrite_phase_handler +19 -0
  131. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/src/hash/md5.h +117 -0
  132. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/src/hash/murmurhash2.c +77 -0
  133. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/src/hash/sha.h +200 -0
  134. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/src/ndk.c +155 -0
  135. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/src/ndk.h +58 -0
  136. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/src/ndk_buf.c +43 -0
  137. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/src/ndk_buf.h +5 -0
  138. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/src/ndk_complex_path.c +129 -0
  139. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/src/ndk_complex_path.h +30 -0
  140. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/src/ndk_complex_value.c +192 -0
  141. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/src/ndk_complex_value.h +21 -0
  142. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/src/ndk_conf_file.c +396 -0
  143. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/src/ndk_conf_file.h +44 -0
  144. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/src/ndk_debug.c +72 -0
  145. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/src/ndk_debug.h +171 -0
  146. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/src/ndk_encoding.c +57 -0
  147. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/src/ndk_encoding.h +12 -0
  148. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/src/ndk_hash.c +82 -0
  149. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/src/ndk_hash.h +45 -0
  150. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/src/ndk_http.c +138 -0
  151. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/src/ndk_http.h +3 -0
  152. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/src/ndk_http_headers.h +35 -0
  153. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/src/ndk_log.c +3 -0
  154. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/src/ndk_log.h +165 -0
  155. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/src/ndk_parse.h +67 -0
  156. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/src/ndk_path.c +583 -0
  157. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/src/ndk_path.h +22 -0
  158. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/src/ndk_process.c +20 -0
  159. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/src/ndk_process.h +12 -0
  160. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/src/ndk_regex.c +215 -0
  161. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/src/ndk_regex.h +7 -0
  162. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/src/ndk_rewrite.c +103 -0
  163. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/src/ndk_rewrite.h +26 -0
  164. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/src/ndk_set_var.c +602 -0
  165. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/src/ndk_set_var.h +44 -0
  166. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/src/ndk_string.c +434 -0
  167. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/src/ndk_string.h +37 -0
  168. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/src/ndk_string_util.h +14 -0
  169. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/src/ndk_upstream_list.c +205 -0
  170. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/src/ndk_upstream_list.h +27 -0
  171. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/src/ndk_uri.c +45 -0
  172. data/packaging/debian/debian_specs/nginx/modules/nginx-development-kit/src/ndk_uri.h +6 -0
  173. data/packaging/debian/debian_specs/nginx/modules/nginx-echo/LICENSE +25 -0
  174. data/packaging/debian/debian_specs/nginx/modules/nginx-echo/README.markdown +1850 -0
  175. data/packaging/debian/debian_specs/nginx/modules/nginx-echo/config +5 -0
  176. data/packaging/debian/debian_specs/nginx/modules/nginx-echo/doc/HttpEchoModule.wiki +1558 -0
  177. data/packaging/debian/debian_specs/nginx/modules/nginx-echo/src/ddebug.h +109 -0
  178. data/packaging/debian/debian_specs/nginx/modules/nginx-echo/src/ngx_http_echo_echo.c +344 -0
  179. data/packaging/debian/debian_specs/nginx/modules/nginx-echo/src/ngx_http_echo_echo.h +25 -0
  180. data/packaging/debian/debian_specs/nginx/modules/nginx-echo/src/ngx_http_echo_filter.c +282 -0
  181. data/packaging/debian/debian_specs/nginx/modules/nginx-echo/src/ngx_http_echo_filter.h +15 -0
  182. data/packaging/debian/debian_specs/nginx/modules/nginx-echo/src/ngx_http_echo_foreach.c +183 -0
  183. data/packaging/debian/debian_specs/nginx/modules/nginx-echo/src/ngx_http_echo_foreach.h +16 -0
  184. data/packaging/debian/debian_specs/nginx/modules/nginx-echo/src/ngx_http_echo_handler.c +429 -0
  185. data/packaging/debian/debian_specs/nginx/modules/nginx-echo/src/ngx_http_echo_handler.h +18 -0
  186. data/packaging/debian/debian_specs/nginx/modules/nginx-echo/src/ngx_http_echo_location.c +178 -0
  187. data/packaging/debian/debian_specs/nginx/modules/nginx-echo/src/ngx_http_echo_location.h +13 -0
  188. data/packaging/debian/debian_specs/nginx/modules/nginx-echo/src/ngx_http_echo_module.c +667 -0
  189. data/packaging/debian/debian_specs/nginx/modules/nginx-echo/src/ngx_http_echo_module.h +137 -0
  190. data/packaging/debian/debian_specs/nginx/modules/nginx-echo/src/ngx_http_echo_request_info.c +452 -0
  191. data/packaging/debian/debian_specs/nginx/modules/nginx-echo/src/ngx_http_echo_request_info.h +31 -0
  192. data/packaging/debian/debian_specs/nginx/modules/nginx-echo/src/ngx_http_echo_sleep.c +208 -0
  193. data/packaging/debian/debian_specs/nginx/modules/nginx-echo/src/ngx_http_echo_sleep.h +16 -0
  194. data/packaging/debian/debian_specs/nginx/modules/nginx-echo/src/ngx_http_echo_subrequest.c +788 -0
  195. data/packaging/debian/debian_specs/nginx/modules/nginx-echo/src/ngx_http_echo_subrequest.h +19 -0
  196. data/packaging/debian/debian_specs/nginx/modules/nginx-echo/src/ngx_http_echo_timer.c +96 -0
  197. data/packaging/debian/debian_specs/nginx/modules/nginx-echo/src/ngx_http_echo_timer.h +13 -0
  198. data/packaging/debian/debian_specs/nginx/modules/nginx-echo/src/ngx_http_echo_util.c +298 -0
  199. data/packaging/debian/debian_specs/nginx/modules/nginx-echo/src/ngx_http_echo_util.h +58 -0
  200. data/packaging/debian/debian_specs/nginx/modules/nginx-echo/src/ngx_http_echo_var.c +110 -0
  201. data/packaging/debian/debian_specs/nginx/modules/nginx-echo/src/ngx_http_echo_var.h +9 -0
  202. data/packaging/debian/debian_specs/nginx/modules/nginx-echo/util/build.sh +45 -0
  203. data/packaging/debian/debian_specs/nginx/modules/nginx-echo/util/releng +8 -0
  204. data/packaging/debian/debian_specs/nginx/modules/nginx-echo/util/wiki2pod.pl +131 -0
  205. data/packaging/debian/debian_specs/nginx/modules/nginx-echo/valgrind.suppress +38 -0
  206. data/packaging/debian/debian_specs/nginx/modules/nginx-http-push/LICENCE +24 -0
  207. data/packaging/debian/debian_specs/nginx/modules/nginx-http-push/README +206 -0
  208. data/packaging/debian/debian_specs/nginx/modules/nginx-http-push/changelog.txt +54 -0
  209. data/packaging/debian/debian_specs/nginx/modules/nginx-http-push/config +26 -0
  210. data/packaging/debian/debian_specs/nginx/modules/nginx-http-push/protocol.txt +191 -0
  211. data/packaging/debian/debian_specs/nginx/modules/nginx-http-push/src/ngx_http_push_defs.c +59 -0
  212. data/packaging/debian/debian_specs/nginx/modules/nginx-http-push/src/ngx_http_push_defs.h +73 -0
  213. data/packaging/debian/debian_specs/nginx/modules/nginx-http-push/src/ngx_http_push_module.c +783 -0
  214. data/packaging/debian/debian_specs/nginx/modules/nginx-http-push/src/ngx_http_push_module.h +31 -0
  215. data/packaging/debian/debian_specs/nginx/modules/nginx-http-push/src/ngx_http_push_module_setup.c +361 -0
  216. data/packaging/debian/debian_specs/nginx/modules/nginx-http-push/src/ngx_http_push_types.h +120 -0
  217. data/packaging/debian/debian_specs/nginx/modules/nginx-http-push/src/store/memory/store.c +1180 -0
  218. data/packaging/debian/debian_specs/nginx/modules/nginx-http-push/src/store/memory/store.h +1 -0
  219. data/packaging/debian/debian_specs/nginx/modules/nginx-http-push/src/store/ngx_http_push_module_ipc.c +146 -0
  220. data/packaging/debian/debian_specs/nginx/modules/nginx-http-push/src/store/ngx_http_push_module_ipc.h +5 -0
  221. data/packaging/debian/debian_specs/nginx/modules/nginx-http-push/src/store/ngx_http_push_store.h +51 -0
  222. data/packaging/debian/debian_specs/nginx/modules/nginx-http-push/src/store/ngx_rwlock.c +178 -0
  223. data/packaging/debian/debian_specs/nginx/modules/nginx-http-push/src/store/ngx_rwlock.h +5 -0
  224. data/packaging/debian/debian_specs/nginx/modules/nginx-http-push/src/store/rbtree_util.c +246 -0
  225. data/packaging/debian/debian_specs/nginx/modules/nginx-http-push/src/store/rbtree_util.h +9 -0
  226. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/Changes +51 -0
  227. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/README.markdown +6954 -0
  228. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/config +363 -0
  229. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/doc/HttpLuaModule.wiki +5898 -0
  230. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/dtrace/ngx_lua_provider.d +61 -0
  231. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/misc/recv-until-pm/Makefile +3 -0
  232. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/misc/recv-until-pm/lib/RecvUntil.pm +138 -0
  233. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/misc/recv-until-pm/t/sanity.t +140 -0
  234. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/api/ngx_http_lua_api.h +52 -0
  235. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ddebug.h +82 -0
  236. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_accessby.c +377 -0
  237. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_accessby.h +22 -0
  238. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_api.c +77 -0
  239. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_args.c +537 -0
  240. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_args.h +20 -0
  241. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_bodyfilterby.c +632 -0
  242. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_bodyfilterby.h +31 -0
  243. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_cache.c +296 -0
  244. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_cache.h +24 -0
  245. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_capturefilter.c +175 -0
  246. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_capturefilter.h +20 -0
  247. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_clfactory.c +887 -0
  248. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_clfactory.h +22 -0
  249. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_common.h +478 -0
  250. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_config.c +67 -0
  251. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_config.h +19 -0
  252. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_consts.c +148 -0
  253. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_consts.h +20 -0
  254. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_contentby.c +369 -0
  255. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_contentby.h +26 -0
  256. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_control.c +483 -0
  257. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_control.h +20 -0
  258. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_coroutine.c +379 -0
  259. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_coroutine.h +23 -0
  260. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_ctx.c +216 -0
  261. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_ctx.h +23 -0
  262. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_directive.c +1081 -0
  263. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_directive.h +56 -0
  264. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_exception.c +58 -0
  265. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_exception.h +33 -0
  266. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_headerfilterby.c +302 -0
  267. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_headerfilterby.h +29 -0
  268. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_headers.c +1370 -0
  269. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_headers.h +22 -0
  270. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_headers_in.c +782 -0
  271. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_headers_in.h +22 -0
  272. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_headers_out.c +625 -0
  273. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_headers_out.h +23 -0
  274. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_initby.c +42 -0
  275. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_initby.h +23 -0
  276. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_initworkerby.c +320 -0
  277. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_initworkerby.h +25 -0
  278. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_log.c +300 -0
  279. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_log.h +20 -0
  280. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_logby.c +227 -0
  281. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_logby.h +22 -0
  282. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_misc.c +252 -0
  283. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_misc.h +20 -0
  284. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_module.c +924 -0
  285. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_ndk.c +184 -0
  286. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_ndk.h +21 -0
  287. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_output.c +794 -0
  288. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_output.h +28 -0
  289. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_pcrefix.c +106 -0
  290. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_pcrefix.h +23 -0
  291. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_phase.c +94 -0
  292. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_phase.h +13 -0
  293. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_probe.h +85 -0
  294. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_regex.c +2468 -0
  295. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_regex.h +22 -0
  296. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_req_body.c +1169 -0
  297. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_req_body.h +20 -0
  298. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_req_method.c +252 -0
  299. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_req_method.h +19 -0
  300. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_rewriteby.c +351 -0
  301. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_rewriteby.h +22 -0
  302. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_script.c +538 -0
  303. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_script.h +86 -0
  304. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_setby.c +216 -0
  305. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_setby.h +15 -0
  306. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_shdict.c +1844 -0
  307. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_shdict.h +52 -0
  308. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_sleep.c +191 -0
  309. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_sleep.h +20 -0
  310. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_socket_tcp.c +5314 -0
  311. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_socket_tcp.h +156 -0
  312. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_socket_udp.c +1624 -0
  313. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_socket_udp.h +56 -0
  314. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_string.c +704 -0
  315. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_string.h +20 -0
  316. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_subrequest.c +1741 -0
  317. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_subrequest.h +46 -0
  318. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_time.c +278 -0
  319. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_time.h +21 -0
  320. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_timer.c +661 -0
  321. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_timer.h +20 -0
  322. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_uri.c +110 -0
  323. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_uri.h +20 -0
  324. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_uthread.c +283 -0
  325. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_uthread.h +36 -0
  326. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_util.c +3972 -0
  327. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_util.h +423 -0
  328. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_variable.c +499 -0
  329. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_variable.h +20 -0
  330. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_worker.c +64 -0
  331. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/src/ngx_http_lua_worker.h +17 -0
  332. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/tapset/ngx_lua.stp +5 -0
  333. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/util/build.sh +39 -0
  334. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/util/build2.sh +55 -0
  335. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/util/fix-comments +27 -0
  336. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/util/gdbinit +415 -0
  337. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/util/ngx-links +62 -0
  338. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/util/reindex +64 -0
  339. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/util/releng +8 -0
  340. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/util/retab +8 -0
  341. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/util/revim +102 -0
  342. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/util/run_test.sh +10 -0
  343. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/util/update-readme.sh +4 -0
  344. data/packaging/debian/debian_specs/nginx/modules/nginx-lua/valgrind.suppress +144 -0
  345. data/packaging/debian/debian_specs/nginx/modules/nginx-upload-progress/CHANGES +107 -0
  346. data/packaging/debian/debian_specs/nginx/modules/nginx-upload-progress/LICENSE +25 -0
  347. data/packaging/debian/debian_specs/nginx/modules/nginx-upload-progress/Makefile +8 -0
  348. data/packaging/debian/debian_specs/nginx/modules/nginx-upload-progress/README +329 -0
  349. data/packaging/debian/debian_specs/nginx/modules/nginx-upload-progress/config +3 -0
  350. data/packaging/debian/debian_specs/nginx/modules/nginx-upload-progress/ngx_http_uploadprogress_module.c +1774 -0
  351. data/packaging/debian/debian_specs/nginx/modules/nginx-upstream-fair/README +53 -0
  352. data/packaging/debian/debian_specs/nginx/modules/nginx-upstream-fair/config +3 -0
  353. data/packaging/debian/debian_specs/nginx/modules/nginx-upstream-fair/ngx_http_upstream_fair_module.c +1356 -0
  354. data/packaging/debian/debian_specs/nginx/modules/ngx-fancyindex/CHANGELOG.md +37 -0
  355. data/packaging/debian/debian_specs/nginx/modules/ngx-fancyindex/HACKING.md +24 -0
  356. data/packaging/debian/debian_specs/nginx/modules/ngx-fancyindex/LICENSE +20 -0
  357. data/packaging/debian/debian_specs/nginx/modules/ngx-fancyindex/README.rst +182 -0
  358. data/packaging/debian/debian_specs/nginx/modules/ngx-fancyindex/config +8 -0
  359. data/packaging/debian/debian_specs/nginx/modules/ngx-fancyindex/nginx-0.6-support.patch +23 -0
  360. data/packaging/debian/debian_specs/nginx/modules/ngx-fancyindex/ngx_http_fancyindex_module.c +1305 -0
  361. data/packaging/debian/debian_specs/nginx/modules/ngx-fancyindex/template.awk +52 -0
  362. data/packaging/debian/debian_specs/nginx/modules/ngx-fancyindex/template.h +103 -0
  363. data/packaging/debian/debian_specs/nginx/modules/ngx-fancyindex/template.html +102 -0
  364. data/packaging/debian/debian_specs/nginx/modules/ngx_http_substitutions_filter_module/CHANGES +37 -0
  365. data/packaging/debian/debian_specs/nginx/modules/ngx_http_substitutions_filter_module/README +141 -0
  366. data/packaging/debian/debian_specs/nginx/modules/ngx_http_substitutions_filter_module/config +3 -0
  367. data/packaging/debian/debian_specs/nginx/modules/ngx_http_substitutions_filter_module/doc/README.google_code_home_page.wiki +120 -0
  368. data/packaging/debian/debian_specs/nginx/modules/ngx_http_substitutions_filter_module/doc/README.html +199 -0
  369. data/packaging/debian/debian_specs/nginx/modules/ngx_http_substitutions_filter_module/doc/README.wiki +123 -0
  370. data/packaging/debian/debian_specs/nginx/modules/ngx_http_substitutions_filter_module/ngx_http_subs_filter_module.c +1298 -0
  371. data/packaging/debian/debian_specs/nginx/modules/ngx_http_substitutions_filter_module/test/README +275 -0
  372. data/packaging/debian/debian_specs/nginx/modules/ngx_http_substitutions_filter_module/test/inc/Module/AutoInstall.pm +820 -0
  373. data/packaging/debian/debian_specs/nginx/modules/ngx_http_substitutions_filter_module/test/inc/Module/Install.pm +470 -0
  374. data/packaging/debian/debian_specs/nginx/modules/ngx_http_substitutions_filter_module/test/inc/Module/Install/AutoInstall.pm +82 -0
  375. data/packaging/debian/debian_specs/nginx/modules/ngx_http_substitutions_filter_module/test/inc/Module/Install/Base.pm +83 -0
  376. data/packaging/debian/debian_specs/nginx/modules/ngx_http_substitutions_filter_module/test/inc/Module/Install/Can.pm +81 -0
  377. data/packaging/debian/debian_specs/nginx/modules/ngx_http_substitutions_filter_module/test/inc/Module/Install/Fetch.pm +93 -0
  378. data/packaging/debian/debian_specs/nginx/modules/ngx_http_substitutions_filter_module/test/inc/Module/Install/Include.pm +34 -0
  379. data/packaging/debian/debian_specs/nginx/modules/ngx_http_substitutions_filter_module/test/inc/Module/Install/Makefile.pm +415 -0
  380. data/packaging/debian/debian_specs/nginx/modules/ngx_http_substitutions_filter_module/test/inc/Module/Install/Metadata.pm +716 -0
  381. data/packaging/debian/debian_specs/nginx/modules/ngx_http_substitutions_filter_module/test/inc/Module/Install/TestBase.pm +29 -0
  382. data/packaging/debian/debian_specs/nginx/modules/ngx_http_substitutions_filter_module/test/inc/Module/Install/Win32.pm +64 -0
  383. data/packaging/debian/debian_specs/nginx/modules/ngx_http_substitutions_filter_module/test/inc/Module/Install/WriteAll.pm +63 -0
  384. data/packaging/debian/debian_specs/nginx/modules/ngx_http_substitutions_filter_module/test/inc/Spiffy.pm +539 -0
  385. data/packaging/debian/debian_specs/nginx/modules/ngx_http_substitutions_filter_module/test/inc/Test/Base.pm +682 -0
  386. data/packaging/debian/debian_specs/nginx/modules/ngx_http_substitutions_filter_module/test/inc/Test/Base/Filter.pm +341 -0
  387. data/packaging/debian/debian_specs/nginx/modules/ngx_http_substitutions_filter_module/test/inc/Test/Builder.pm +1413 -0
  388. data/packaging/debian/debian_specs/nginx/modules/ngx_http_substitutions_filter_module/test/inc/Test/Builder/Module.pm +81 -0
  389. data/packaging/debian/debian_specs/nginx/modules/ngx_http_substitutions_filter_module/test/inc/Test/More.pm +735 -0
  390. data/packaging/debian/debian_specs/nginx/modules/ngx_http_substitutions_filter_module/test/lib/Test/Nginx.pm +315 -0
  391. data/packaging/debian/debian_specs/nginx/modules/ngx_http_substitutions_filter_module/test/lib/Test/Nginx/LWP.pm +524 -0
  392. data/packaging/debian/debian_specs/nginx/modules/ngx_http_substitutions_filter_module/test/lib/Test/Nginx/Socket.pm +1749 -0
  393. data/packaging/debian/debian_specs/nginx/modules/ngx_http_substitutions_filter_module/test/lib/Test/Nginx/Util.pm +874 -0
  394. data/packaging/debian/debian_specs/nginx/modules/ngx_http_substitutions_filter_module/test/t/subs.t +136 -0
  395. data/packaging/debian/debian_specs/nginx/modules/ngx_http_substitutions_filter_module/test/t/subs_capture.t +32 -0
  396. data/packaging/debian/debian_specs/nginx/modules/ngx_http_substitutions_filter_module/test/t/subs_fix_string.t +32 -0
  397. data/packaging/debian/debian_specs/nginx/modules/ngx_http_substitutions_filter_module/test/t/subs_regex.t +108 -0
  398. data/packaging/debian/debian_specs/nginx/modules/ngx_http_substitutions_filter_module/test/t/subs_types.t +59 -0
  399. data/packaging/debian/debian_specs/nginx/modules/ngx_http_substitutions_filter_module/test/test.sh +5 -0
  400. data/packaging/debian/debian_specs/nginx/modules/ngx_http_substitutions_filter_module/util/update-readme.sh +7 -0
  401. data/packaging/debian/debian_specs/nginx/modules/ngx_http_substitutions_filter_module/util/wiki2google_code_homepage.pl +29 -0
  402. data/packaging/debian/debian_specs/nginx/modules/ngx_http_substitutions_filter_module/util/wiki2pod.pl +129 -0
  403. data/packaging/debian/debian_specs/nginx/nginx-common.NEWS +135 -0
  404. data/packaging/debian/debian_specs/nginx/nginx-common.README.Debian +45 -0
  405. data/packaging/debian/debian_specs/nginx/nginx-common.dirs.erb +32 -0
  406. data/packaging/debian/debian_specs/nginx/nginx-common.install +3 -0
  407. data/packaging/debian/debian_specs/nginx/nginx-common.lintian-overrides +2 -0
  408. data/packaging/debian/debian_specs/nginx/nginx-common.manpages +1 -0
  409. data/packaging/debian/debian_specs/nginx/nginx-common.nginx.default +10 -0
  410. data/packaging/debian/debian_specs/nginx/nginx-common.nginx.init.erb +214 -0
  411. data/packaging/debian/debian_specs/nginx/nginx-common.nginx.logrotate +18 -0
  412. data/packaging/debian/debian_specs/nginx/nginx-common.nginx.service.erb +37 -0
  413. data/packaging/debian/debian_specs/nginx/nginx-common.postinst.erb +66 -0
  414. data/packaging/debian/debian_specs/nginx/nginx-common.postrm.erb +46 -0
  415. data/packaging/debian/debian_specs/nginx/nginx-common.preinst +47 -0
  416. data/packaging/debian/debian_specs/nginx/nginx-common.prerm.erb +28 -0
  417. data/packaging/debian/debian_specs/nginx/nginx-doc.docs +2 -0
  418. data/packaging/debian/debian_specs/nginx/nginx-doc.examples +1 -0
  419. data/packaging/debian/debian_specs/nginx/nginx-extras.install.erb +17 -0
  420. data/packaging/debian/debian_specs/nginx/nginx-extras.lintian-overrides +1 -0
  421. data/packaging/debian/debian_specs/nginx/nginx-extras.postinst.erb +44 -0
  422. data/packaging/debian/debian_specs/nginx/nginx-extras.prerm +22 -0
  423. data/packaging/debian/debian_specs/nginx/nginx.1 +47 -0
  424. data/packaging/debian/debian_specs/nginx/patches/perl-use-dpkg-buildflags.patch +23 -0
  425. data/packaging/debian/debian_specs/nginx/patches/series +1 -0
  426. data/packaging/debian/debian_specs/nginx/rules.erb +185 -0
  427. data/packaging/debian/debian_specs/nginx/source/format +1 -0
  428. data/packaging/debian/debian_specs/nginx/tests/control +4 -0
  429. data/packaging/debian/debian_specs/nginx/ufw/nginx +14 -0
  430. data/packaging/debian/debian_specs/nginx/upstream/signing-key.asc +34 -0
  431. data/packaging/debian/debian_specs/nginx/watch +3 -0
  432. data/packaging/debian/debian_specs/passenger/README.Debian +12 -0
  433. data/packaging/debian/debian_specs/passenger/changelog +316 -0
  434. data/packaging/debian/debian_specs/passenger/compat +1 -0
  435. data/packaging/debian/debian_specs/passenger/control.erb +123 -0
  436. data/packaging/debian/debian_specs/passenger/copyright +385 -0
  437. data/packaging/debian/debian_specs/passenger/helpers.rb +24 -0
  438. data/packaging/debian/debian_specs/passenger/libapache2-mod-passenger.install +3 -0
  439. data/packaging/debian/debian_specs/passenger/libapache2-mod-passenger.postinst +36 -0
  440. data/packaging/debian/debian_specs/passenger/libapache2-mod-passenger.prerm +15 -0
  441. data/packaging/debian/debian_specs/passenger/locations.ini.erb +14 -0
  442. data/packaging/debian/debian_specs/passenger/passenger-dev.install.erb +3 -0
  443. data/packaging/debian/debian_specs/passenger/passenger-doc.install.erb +2 -0
  444. data/packaging/debian/debian_specs/passenger/passenger.conf +6 -0
  445. data/packaging/debian/debian_specs/passenger/passenger.docs +4 -0
  446. data/packaging/debian/debian_specs/passenger/passenger.install.erb +16 -0
  447. data/packaging/debian/debian_specs/passenger/passenger.load +3 -0
  448. data/packaging/debian/debian_specs/passenger/passenger.manpages +3 -0
  449. data/packaging/debian/debian_specs/passenger/passenger_free_ruby.c +29 -0
  450. data/packaging/debian/debian_specs/passenger/passenger_ruby_utils.c +54 -0
  451. data/packaging/debian/debian_specs/passenger/passenger_system_ruby.c.erb +37 -0
  452. data/packaging/debian/debian_specs/passenger/patches/series +0 -0
  453. data/packaging/debian/debian_specs/passenger/rules.erb +84 -0
  454. data/packaging/debian/debian_specs/passenger/source/format +1 -0
  455. data/packaging/debian/debian_specs/passenger_enterprise/README.Debian +12 -0
  456. data/packaging/debian/debian_specs/passenger_enterprise/changelog +316 -0
  457. data/packaging/debian/debian_specs/passenger_enterprise/compat +1 -0
  458. data/packaging/debian/debian_specs/passenger_enterprise/control.erb +123 -0
  459. data/packaging/debian/debian_specs/passenger_enterprise/copyright +385 -0
  460. data/packaging/debian/debian_specs/passenger_enterprise/helpers.rb +2 -0
  461. data/packaging/debian/debian_specs/passenger_enterprise/libapache2-mod-passenger-enterprise.install +3 -0
  462. data/packaging/debian/debian_specs/passenger_enterprise/libapache2-mod-passenger-enterprise.postinst +36 -0
  463. data/packaging/debian/debian_specs/passenger_enterprise/libapache2-mod-passenger-enterprise.prerm +15 -0
  464. data/packaging/debian/debian_specs/passenger_enterprise/locations.ini.erb +14 -0
  465. data/packaging/debian/debian_specs/passenger_enterprise/passenger-enterprise-dev.install.erb +3 -0
  466. data/packaging/debian/debian_specs/passenger_enterprise/passenger-enterprise-doc.install.erb +2 -0
  467. data/packaging/debian/debian_specs/passenger_enterprise/passenger-enterprise.docs +4 -0
  468. data/packaging/debian/debian_specs/passenger_enterprise/passenger-enterprise.install.erb +14 -0
  469. data/packaging/debian/debian_specs/passenger_enterprise/passenger-enterprise.manpages +3 -0
  470. data/packaging/debian/debian_specs/passenger_enterprise/passenger.conf +6 -0
  471. data/packaging/debian/debian_specs/passenger_enterprise/passenger.load +3 -0
  472. data/packaging/debian/debian_specs/passenger_enterprise/passenger_free_ruby.c.erb +1 -0
  473. data/packaging/debian/debian_specs/passenger_enterprise/passenger_ruby_utils.c.erb +1 -0
  474. data/packaging/debian/debian_specs/passenger_enterprise/passenger_system_ruby.c.erb +1 -0
  475. data/packaging/debian/debian_specs/passenger_enterprise/patches/series +0 -0
  476. data/packaging/debian/debian_specs/passenger_enterprise/rules.erb +84 -0
  477. data/packaging/debian/debian_specs/passenger_enterprise/source/format +1 -0
  478. data/packaging/debian/docker_images/Makefile +38 -0
  479. data/packaging/debian/docker_images/buildbox/CONTAINER_VERSION.txt +0 -0
  480. data/packaging/debian/docker_images/buildbox/Dockerfile +3 -0
  481. data/packaging/debian/docker_images/buildbox/Gemfile +9 -0
  482. data/packaging/debian/docker_images/buildbox/Gemfile.lock +42 -0
  483. data/packaging/debian/docker_images/buildbox/install.sh +85 -0
  484. data/packaging/debian/docker_images/buildbox/pbuilderrc +4 -0
  485. data/packaging/debian/docker_images/buildbox/sudoers.conf +6 -0
  486. data/packaging/debian/docker_images/setup-buildbox-docker-image +7 -0
  487. data/packaging/debian/docker_images/setup-testbox-docker-image-debian-6 +7 -0
  488. data/packaging/debian/docker_images/setup-testbox-docker-image-debian-7 +7 -0
  489. data/packaging/debian/docker_images/setup-testbox-docker-image-debian-8 +7 -0
  490. data/packaging/debian/docker_images/setup-testbox-docker-image-ubuntu-12.04 +7 -0
  491. data/packaging/debian/docker_images/setup-testbox-docker-image-ubuntu-14.04 +7 -0
  492. data/packaging/debian/docker_images/setup-testbox-docker-image-ubuntu-15.04 +7 -0
  493. data/packaging/debian/docker_images/setup-testbox-docker-image-ubuntu-15.10 +7 -0
  494. data/packaging/debian/docker_images/testbox-debian-6/Dockerfile +3 -0
  495. data/packaging/debian/docker_images/testbox-debian-6/Gemfile +2 -0
  496. data/packaging/debian/docker_images/testbox-debian-6/Gemfile.lock +23 -0
  497. data/packaging/debian/docker_images/testbox-debian-6/argparse.py +2374 -0
  498. data/packaging/debian/docker_images/testbox-debian-6/install.sh +78 -0
  499. data/packaging/debian/docker_images/testbox-debian-7/Dockerfile +3 -0
  500. data/packaging/debian/docker_images/testbox-debian-7/Gemfile +2 -0
  501. data/packaging/debian/docker_images/testbox-debian-7/Gemfile.lock +23 -0
  502. data/packaging/debian/docker_images/testbox-debian-7/install.sh +71 -0
  503. data/packaging/debian/docker_images/testbox-debian-8/Dockerfile +3 -0
  504. data/packaging/debian/docker_images/testbox-debian-8/Gemfile +2 -0
  505. data/packaging/debian/docker_images/testbox-debian-8/Gemfile.lock +23 -0
  506. data/packaging/debian/docker_images/testbox-debian-8/install.sh +70 -0
  507. data/packaging/debian/docker_images/testbox-ubuntu-12.04/Dockerfile +3 -0
  508. data/packaging/debian/docker_images/testbox-ubuntu-12.04/Gemfile +2 -0
  509. data/packaging/debian/docker_images/testbox-ubuntu-12.04/Gemfile.lock +23 -0
  510. data/packaging/debian/docker_images/testbox-ubuntu-12.04/install.sh +69 -0
  511. data/packaging/debian/docker_images/testbox-ubuntu-14.04/Dockerfile +3 -0
  512. data/packaging/debian/docker_images/testbox-ubuntu-14.04/Gemfile +2 -0
  513. data/packaging/debian/docker_images/testbox-ubuntu-14.04/Gemfile.lock +23 -0
  514. data/packaging/debian/docker_images/testbox-ubuntu-14.04/install.sh +69 -0
  515. data/packaging/debian/docker_images/testbox-ubuntu-15.04/Dockerfile +3 -0
  516. data/packaging/debian/docker_images/testbox-ubuntu-15.04/Gemfile +2 -0
  517. data/packaging/debian/docker_images/testbox-ubuntu-15.04/Gemfile.lock +23 -0
  518. data/packaging/debian/docker_images/testbox-ubuntu-15.04/install.sh +69 -0
  519. data/packaging/debian/docker_images/testbox-ubuntu-15.10/Dockerfile +3 -0
  520. data/packaging/debian/docker_images/testbox-ubuntu-15.10/Gemfile +2 -0
  521. data/packaging/debian/docker_images/testbox-ubuntu-15.10/Gemfile.lock +23 -0
  522. data/packaging/debian/docker_images/testbox-ubuntu-15.10/install.sh +69 -0
  523. data/packaging/debian/internal/build/Rakefile +235 -0
  524. data/packaging/debian/internal/build/build-passenger-orig-tarball.sh +76 -0
  525. data/packaging/debian/internal/build/build-source-package.rb +121 -0
  526. data/packaging/debian/internal/build/download-nginx-orig-tarball.sh +17 -0
  527. data/packaging/debian/internal/build/rakefile_support.rb +96 -0
  528. data/packaging/debian/internal/build/setup-environment-essentials.sh +15 -0
  529. data/packaging/debian/internal/build/setup-environment.sh +29 -0
  530. data/packaging/debian/internal/lib/distro_info.rb +82 -0
  531. data/packaging/debian/internal/lib/distro_info.sh +303 -0
  532. data/packaging/debian/internal/lib/distro_info.sh.erb +65 -0
  533. data/packaging/debian/internal/lib/library.sh +83 -0
  534. data/packaging/debian/internal/lib/preprocessor.rb +173 -0
  535. data/packaging/debian/internal/lib/tracking.rb +95 -0
  536. data/packaging/debian/internal/lib/tracking_category.rb +45 -0
  537. data/packaging/debian/internal/lib/tracking_database.rb +132 -0
  538. data/packaging/debian/internal/lib/tracking_task.rb +148 -0
  539. data/packaging/debian/internal/lib/utils.rb +78 -0
  540. data/packaging/debian/internal/publish/Rakefile +97 -0
  541. data/packaging/debian/internal/publish/oss-binaries.phusionpassenger.com-fingerprint.txt +1 -0
  542. data/packaging/debian/internal/publish/packagecloud_fingerprint.txt +1 -0
  543. data/packaging/debian/internal/publish/passenger_website_fingerprint.txt +1 -0
  544. data/packaging/debian/internal/publish/preinit.sh +7 -0
  545. data/packaging/debian/internal/publish/rakefile_support.rb +183 -0
  546. data/packaging/debian/internal/scripts/gpg_noninteractive/gpg +11 -0
  547. data/packaging/debian/internal/scripts/initccache.sh +35 -0
  548. data/packaging/debian/internal/scripts/inituidgid.sh +19 -0
  549. data/packaging/debian/internal/scripts/my_init +340 -0
  550. data/packaging/debian/internal/scripts/pin_certificates +34 -0
  551. data/packaging/debian/internal/scripts/regen_distro_info_script.sh +3 -0
  552. data/packaging/debian/internal/scripts/setup-vagrant.sh +12 -0
  553. data/packaging/debian/internal/scripts/setuser +31 -0
  554. data/packaging/debian/internal/shell/initpbuilder.sh +3 -0
  555. data/packaging/debian/internal/shell/preinit.sh +28 -0
  556. data/packaging/debian/internal/shell/sudoers.conf +1 -0
  557. data/packaging/debian/internal/test/apache/apache-24.conf +5 -0
  558. data/packaging/debian/internal/test/apache/apache-pre-24.conf +4 -0
  559. data/packaging/debian/internal/test/apache/vhost.conf +17 -0
  560. data/packaging/debian/internal/test/misc/config.json +15 -0
  561. data/packaging/debian/internal/test/misc/hosts.conf +4 -0
  562. data/packaging/debian/internal/test/misc/init.sh +25 -0
  563. data/packaging/debian/internal/test/misc/nodejs_test_app.js +6 -0
  564. data/packaging/debian/internal/test/misc/python_test_app.py +3 -0
  565. data/packaging/debian/internal/test/misc/ruby_test_app.rb +5 -0
  566. data/packaging/debian/internal/test/misc/test_support.rb +61 -0
  567. data/packaging/debian/internal/test/nginx/vhost.conf +23 -0
  568. data/packaging/debian/internal/test/system_web_server_test.rb +126 -0
  569. data/packaging/debian/internal/test/test.sh +141 -0
  570. data/packaging/debian/jenkins/publish/clear_caches.rb +48 -0
  571. data/packaging/debian/jenkins/publish/publish.sh +69 -0
  572. data/packaging/debian/jenkins/test/test.sh +63 -0
  573. data/packaging/debian/passenger_apt_automation.sublime-project +14 -0
  574. data/packaging/debian/publish +172 -0
  575. data/packaging/debian/shell +116 -0
  576. data/packaging/debian/test +142 -0
  577. metadata +563 -3
  578. metadata.gz.asc +7 -7
  579. data/resources/oss-binaries.phusionpassenger.com.crt +0 -208
@@ -0,0 +1,28 @@
1
+
2
+ /*
3
+ * Copyright (C) Xiaozhe Wang (chaoslawful)
4
+ * Copyright (C) Yichun Zhang (agentzh)
5
+ */
6
+
7
+
8
+ #ifndef _NGX_HTTP_LUA_OUTPUT_H_INCLUDED_
9
+ #define _NGX_HTTP_LUA_OUTPUT_H_INCLUDED_
10
+
11
+
12
+ #include "ngx_http_lua_common.h"
13
+
14
+
15
+ void ngx_http_lua_inject_output_api(lua_State *L);
16
+
17
+ size_t ngx_http_lua_calc_strlen_in_table(lua_State *L, int index, int arg_i,
18
+ unsigned strict);
19
+
20
+ u_char * ngx_http_lua_copy_str_in_table(lua_State *L, int index, u_char *dst);
21
+
22
+ ngx_int_t ngx_http_lua_flush_resume_helper(ngx_http_request_t *r,
23
+ ngx_http_lua_ctx_t *ctx);
24
+
25
+
26
+ #endif /* _NGX_HTTP_LUA_OUTPUT_H_INCLUDED_ */
27
+
28
+ /* vi:set ft=c ts=4 sw=4 et fdm=marker: */
@@ -0,0 +1,106 @@
1
+
2
+ /*
3
+ * Copyright (C) Xiaozhe Wang (chaoslawful)
4
+ * Copyright (C) Yichun Zhang (agentzh)
5
+ */
6
+
7
+
8
+ #ifndef DDEBUG
9
+ #define DDEBUG 0
10
+ #endif
11
+ #include "ddebug.h"
12
+
13
+
14
+ #include "ngx_http_lua_pcrefix.h"
15
+ #include "stdio.h"
16
+
17
+ #if (NGX_PCRE)
18
+
19
+ static ngx_pool_t *ngx_http_lua_pcre_pool = NULL;
20
+
21
+ static void *(*old_pcre_malloc)(size_t);
22
+ static void (*old_pcre_free)(void *ptr);
23
+
24
+
25
+ /* XXX: work-around to nginx regex subsystem, must init a memory pool
26
+ * to use PCRE functions. As PCRE still has memory-leaking problems,
27
+ * and nginx overwrote pcre_malloc/free hooks with its own static
28
+ * functions, so nobody else can reuse nginx regex subsystem... */
29
+ static void *
30
+ ngx_http_lua_pcre_malloc(size_t size)
31
+ {
32
+ dd("lua pcre pool is %p", ngx_http_lua_pcre_pool);
33
+
34
+ if (ngx_http_lua_pcre_pool) {
35
+ return ngx_palloc(ngx_http_lua_pcre_pool, size);
36
+ }
37
+
38
+ fprintf(stderr, "error: lua pcre malloc failed due to empty pcre pool");
39
+
40
+ return NULL;
41
+ }
42
+
43
+
44
+ static void
45
+ ngx_http_lua_pcre_free(void *ptr)
46
+ {
47
+ dd("lua pcre pool is %p", ngx_http_lua_pcre_pool);
48
+
49
+ if (ngx_http_lua_pcre_pool) {
50
+ ngx_pfree(ngx_http_lua_pcre_pool, ptr);
51
+ return;
52
+ }
53
+
54
+ fprintf(stderr, "error: lua pcre free failed due to empty pcre pool");
55
+ }
56
+
57
+
58
+ ngx_pool_t *
59
+ ngx_http_lua_pcre_malloc_init(ngx_pool_t *pool)
60
+ {
61
+ ngx_pool_t *old_pool;
62
+
63
+ if (pcre_malloc != ngx_http_lua_pcre_malloc) {
64
+
65
+ dd("overriding nginx pcre malloc and free");
66
+
67
+ ngx_http_lua_pcre_pool = pool;
68
+
69
+ old_pcre_malloc = pcre_malloc;
70
+ old_pcre_free = pcre_free;
71
+
72
+ pcre_malloc = ngx_http_lua_pcre_malloc;
73
+ pcre_free = ngx_http_lua_pcre_free;
74
+
75
+ return NULL;
76
+ }
77
+
78
+ dd("lua pcre pool was %p", ngx_http_lua_pcre_pool);
79
+
80
+ old_pool = ngx_http_lua_pcre_pool;
81
+ ngx_http_lua_pcre_pool = pool;
82
+
83
+ dd("lua pcre pool is %p", ngx_http_lua_pcre_pool);
84
+
85
+ return old_pool;
86
+ }
87
+
88
+
89
+ void
90
+ ngx_http_lua_pcre_malloc_done(ngx_pool_t *old_pool)
91
+ {
92
+ dd("lua pcre pool was %p", ngx_http_lua_pcre_pool);
93
+
94
+ ngx_http_lua_pcre_pool = old_pool;
95
+
96
+ dd("lua pcre pool is %p", ngx_http_lua_pcre_pool);
97
+
98
+ if (old_pool == NULL) {
99
+ pcre_malloc = old_pcre_malloc;
100
+ pcre_free = old_pcre_free;
101
+ }
102
+ }
103
+
104
+ #endif /* NGX_PCRE */
105
+
106
+ /* vi:set ft=c ts=4 sw=4 et fdm=marker: */
@@ -0,0 +1,23 @@
1
+
2
+ /*
3
+ * Copyright (C) Xiaozhe Wang (chaoslawful)
4
+ * Copyright (C) Yichun Zhang (agentzh)
5
+ */
6
+
7
+
8
+ #ifndef _NGX_HTTP_LUA_PCREFIX_H_INCLUDED_
9
+ #define _NGX_HTTP_LUA_PCREFIX_H_INCLUDED_
10
+
11
+
12
+ #include "ngx_http_lua_common.h"
13
+
14
+
15
+ #if (NGX_PCRE)
16
+ ngx_pool_t *ngx_http_lua_pcre_malloc_init(ngx_pool_t *pool);
17
+ void ngx_http_lua_pcre_malloc_done(ngx_pool_t *old_pool);
18
+ #endif
19
+
20
+
21
+ #endif /* _NGX_HTTP_LUA_PCREFIX_H_INCLUDED_ */
22
+
23
+ /* vi:set ft=c ts=4 sw=4 et fdm=marker: */
@@ -0,0 +1,94 @@
1
+
2
+ /*
3
+ * Copyright (C) Yichun Zhang (agentzh)
4
+ */
5
+
6
+
7
+ #ifndef DDEBUG
8
+ #define DDEBUG 0
9
+ #endif
10
+ #include "ddebug.h"
11
+
12
+
13
+ #include "ngx_http_lua_phase.h"
14
+ #include "ngx_http_lua_util.h"
15
+ #include "ngx_http_lua_ctx.h"
16
+
17
+
18
+ static int ngx_http_lua_ngx_get_phase(lua_State *L);
19
+
20
+
21
+ static int
22
+ ngx_http_lua_ngx_get_phase(lua_State *L)
23
+ {
24
+ ngx_http_request_t *r;
25
+ ngx_http_lua_ctx_t *ctx;
26
+
27
+ r = ngx_http_lua_get_req(L);
28
+
29
+ /* If we have no request object, assume we are called from the "init"
30
+ * phase. */
31
+
32
+ if (r == NULL) {
33
+ lua_pushliteral(L, "init");
34
+ return 1;
35
+ }
36
+
37
+ ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
38
+ if (ctx == NULL) {
39
+ return luaL_error(L, "no request ctx found");
40
+ }
41
+
42
+ switch (ctx->context) {
43
+ case NGX_HTTP_LUA_CONTEXT_INIT_WORKER:
44
+ lua_pushliteral(L, "init_worker");
45
+ break;
46
+
47
+ case NGX_HTTP_LUA_CONTEXT_SET:
48
+ lua_pushliteral(L, "set");
49
+ break;
50
+
51
+ case NGX_HTTP_LUA_CONTEXT_REWRITE:
52
+ lua_pushliteral(L, "rewrite");
53
+ break;
54
+
55
+ case NGX_HTTP_LUA_CONTEXT_ACCESS:
56
+ lua_pushliteral(L, "access");
57
+ break;
58
+
59
+ case NGX_HTTP_LUA_CONTEXT_CONTENT:
60
+ lua_pushliteral(L, "content");
61
+ break;
62
+
63
+ case NGX_HTTP_LUA_CONTEXT_LOG:
64
+ lua_pushliteral(L, "log");
65
+ break;
66
+
67
+ case NGX_HTTP_LUA_CONTEXT_HEADER_FILTER:
68
+ lua_pushliteral(L, "header_filter");
69
+ break;
70
+
71
+ case NGX_HTTP_LUA_CONTEXT_BODY_FILTER:
72
+ lua_pushliteral(L, "body_filter");
73
+ break;
74
+
75
+ case NGX_HTTP_LUA_CONTEXT_TIMER:
76
+ lua_pushliteral(L, "timer");
77
+ break;
78
+
79
+ default:
80
+ return luaL_error(L, "unknown phase: %d", (int) ctx->context);
81
+ }
82
+
83
+ return 1;
84
+ }
85
+
86
+
87
+ void
88
+ ngx_http_lua_inject_phase_api(lua_State *L)
89
+ {
90
+ lua_pushcfunction(L, ngx_http_lua_ngx_get_phase);
91
+ lua_setfield(L, -2, "get_phase");
92
+ }
93
+
94
+ /* vi:set ft=c ts=4 sw=4 et fdm=marker: */
@@ -0,0 +1,13 @@
1
+ #ifndef _NGX_HTTP_LUA_PHASE_H_INCLUDED_
2
+ #define _NGX_HTTP_LUA_PHASE_H_INCLUDED_
3
+
4
+
5
+ #include "ngx_http_lua_common.h"
6
+
7
+
8
+ void ngx_http_lua_inject_phase_api(lua_State *L);
9
+
10
+
11
+ #endif /* _NGX_HTTP_LUA_PHASE_H_INCLUDED_ */
12
+
13
+ /* vi:set ft=c ts=4 sw=4 et fdm=marker: */
@@ -0,0 +1,85 @@
1
+ /*
2
+ * automatically generated from the file dtrace/ngx_lua_provider.d by the
3
+ * gen-dtrace-probe-header tool in the nginx-devel-utils project:
4
+ * https://github.com/agentzh/nginx-devel-utils
5
+ */
6
+
7
+ #ifndef _NGX_HTTP_LUA_PROBE_H_INCLUDED_
8
+ #define _NGX_HTTP_LUA_PROBE_H_INCLUDED_
9
+
10
+
11
+ #include <ngx_config.h>
12
+ #include <ngx_core.h>
13
+ #include <ngx_http.h>
14
+
15
+
16
+ #if defined(NGX_DTRACE) && NGX_DTRACE
17
+
18
+ #include <ngx_dtrace_provider.h>
19
+
20
+ #define ngx_http_lua_probe_info(s) \
21
+ NGINX_LUA_HTTP_LUA_INFO(s)
22
+
23
+ #define ngx_http_lua_probe_register_preload_package(L, pkg) \
24
+ NGINX_LUA_HTTP_LUA_REGISTER_PRELOAD_PACKAGE(L, pkg)
25
+
26
+ #define ngx_http_lua_probe_req_socket_consume_preread(r, data, len) \
27
+ NGINX_LUA_HTTP_LUA_REQ_SOCKET_CONSUME_PREREAD(r, data, len)
28
+
29
+ #define ngx_http_lua_probe_user_coroutine_create(r, parent, child) \
30
+ NGINX_LUA_HTTP_LUA_USER_COROUTINE_CREATE(r, parent, child)
31
+
32
+ #define ngx_http_lua_probe_user_coroutine_resume(r, parent, child) \
33
+ NGINX_LUA_HTTP_LUA_USER_COROUTINE_RESUME(r, parent, child)
34
+
35
+ #define ngx_http_lua_probe_user_coroutine_yield(r, parent, child) \
36
+ NGINX_LUA_HTTP_LUA_USER_COROUTINE_YIELD(r, parent, child)
37
+
38
+ #define ngx_http_lua_probe_thread_yield(r, L) \
39
+ NGINX_LUA_HTTP_LUA_THREAD_YIELD(r, L)
40
+
41
+ #define ngx_http_lua_probe_socket_tcp_send_start(r, u, data, len) \
42
+ NGINX_LUA_HTTP_LUA_SOCKET_TCP_SEND_START(r, u, data, len)
43
+
44
+ #define ngx_http_lua_probe_socket_tcp_receive_done(r, u, data, len) \
45
+ NGINX_LUA_HTTP_LUA_SOCKET_TCP_RECEIVE_DONE(r, u, data, len)
46
+
47
+ #define ngx_http_lua_probe_socket_tcp_setkeepalive_buf_unread(r, u, data, len)\
48
+ NGINX_LUA_HTTP_LUA_SOCKET_TCP_SETKEEPALIVE_BUF_UNREAD(r, u, data, len)
49
+
50
+ #define ngx_http_lua_probe_user_thread_spawn(r, creator, newthread) \
51
+ NGINX_LUA_HTTP_LUA_USER_THREAD_SPAWN(r, creator, newthread)
52
+
53
+ #define ngx_http_lua_probe_thread_delete(r, thread, ctx) \
54
+ NGINX_LUA_HTTP_LUA_THREAD_DELETE(r, thread, ctx)
55
+
56
+ #define ngx_http_lua_probe_run_posted_thread(r, thread, status) \
57
+ NGINX_LUA_HTTP_LUA_RUN_POSTED_THREAD(r, thread, status)
58
+
59
+ #define ngx_http_lua_probe_coroutine_done(r, co, success) \
60
+ NGINX_LUA_HTTP_LUA_COROUTINE_DONE(r, co, success)
61
+
62
+ #define ngx_http_lua_probe_user_thread_wait(parent, child) \
63
+ NGINX_LUA_HTTP_LUA_USER_THREAD_WAIT(parent, child)
64
+
65
+ #else /* !(NGX_DTRACE) */
66
+
67
+ #define ngx_http_lua_probe_info(s)
68
+ #define ngx_http_lua_probe_register_preload_package(L, pkg)
69
+ #define ngx_http_lua_probe_req_socket_consume_preread(r, data, len)
70
+ #define ngx_http_lua_probe_user_coroutine_create(r, parent, child)
71
+ #define ngx_http_lua_probe_user_coroutine_resume(r, parent, child)
72
+ #define ngx_http_lua_probe_user_coroutine_yield(r, parent, child)
73
+ #define ngx_http_lua_probe_thread_yield(r, L)
74
+ #define ngx_http_lua_probe_socket_tcp_send_start(r, u, data, len)
75
+ #define ngx_http_lua_probe_socket_tcp_receive_done(r, u, data, len)
76
+ #define ngx_http_lua_probe_socket_tcp_setkeepalive_buf_unread(r, u, data, len)
77
+ #define ngx_http_lua_probe_user_thread_spawn(r, creator, newthread)
78
+ #define ngx_http_lua_probe_thread_delete(r, thread, ctx)
79
+ #define ngx_http_lua_probe_run_posted_thread(r, thread, status)
80
+ #define ngx_http_lua_probe_coroutine_done(r, co, success)
81
+ #define ngx_http_lua_probe_user_thread_wait(parent, child)
82
+
83
+ #endif
84
+
85
+ #endif /* _NGX_HTTP_LUA_PROBE_H_INCLUDED_ */
@@ -0,0 +1,2468 @@
1
+
2
+ /*
3
+ * Copyright (C) Yichun Zhang (agentzh)
4
+ */
5
+
6
+
7
+ #ifndef DDEBUG
8
+ #define DDEBUG 0
9
+ #endif
10
+ #include "ddebug.h"
11
+
12
+
13
+ #if (NGX_PCRE)
14
+
15
+ #include "ngx_http_lua_regex.h"
16
+ #include "ngx_http_lua_pcrefix.h"
17
+ #include "ngx_http_lua_script.h"
18
+ #include "ngx_http_lua_pcrefix.h"
19
+ #include "ngx_http_lua_util.h"
20
+ #include <pcre.h>
21
+
22
+
23
+ #if (PCRE_MAJOR > 8) || (PCRE_MAJOR == 8 && PCRE_MINOR >= 21)
24
+ # define LUA_HAVE_PCRE_JIT 1
25
+ #else
26
+ # define LUA_HAVE_PCRE_JIT 0
27
+ #endif
28
+
29
+
30
+ #if (PCRE_MAJOR >= 6)
31
+ # define LUA_HAVE_PCRE_DFA 1
32
+ #else
33
+ # define LUA_HAVE_PCRE_DFA 0
34
+ #endif
35
+
36
+
37
+ #define NGX_LUA_RE_COMPILE_ONCE (1<<0)
38
+ #define NGX_LUA_RE_MODE_DFA (1<<1)
39
+ #define NGX_LUA_RE_MODE_JIT (1<<2)
40
+ #define NGX_LUA_RE_MODE_DUPNAMES (1<<3)
41
+ #define NGX_LUA_RE_NO_UTF8_CHECK (1<<4)
42
+
43
+ #define NGX_LUA_RE_DFA_MODE_WORKSPACE_COUNT (100)
44
+
45
+
46
+ typedef struct {
47
+ #ifndef NGX_LUA_NO_FFI_API
48
+ ngx_pool_t *pool;
49
+ u_char *name_table;
50
+ int name_count;
51
+ int name_entry_size;
52
+ #endif
53
+
54
+ int ncaptures;
55
+ int *captures;
56
+
57
+ pcre *regex;
58
+ pcre_extra *regex_sd;
59
+
60
+ ngx_http_lua_complex_value_t *replace;
61
+
62
+ #ifndef NGX_LUA_NO_FFI_API
63
+ /* only for (stap) debugging, and may be an invalid pointer */
64
+ const u_char *pattern;
65
+ #endif
66
+ } ngx_http_lua_regex_t;
67
+
68
+
69
+ typedef struct {
70
+ ngx_str_t pattern;
71
+ ngx_pool_t *pool;
72
+ ngx_int_t options;
73
+
74
+ pcre *regex;
75
+ int captures;
76
+ ngx_str_t err;
77
+ } ngx_http_lua_regex_compile_t;
78
+
79
+
80
+ typedef struct {
81
+ ngx_http_cleanup_pt *cleanup;
82
+ ngx_http_request_t *request;
83
+ pcre *regex;
84
+ pcre_extra *regex_sd;
85
+ int ncaptures;
86
+ int *captures;
87
+ int captures_len;
88
+ uint8_t flags;
89
+ } ngx_http_lua_regex_ctx_t;
90
+
91
+
92
+ static int ngx_http_lua_ngx_re_gmatch_iterator(lua_State *L);
93
+ static ngx_uint_t ngx_http_lua_ngx_re_parse_opts(lua_State *L,
94
+ ngx_http_lua_regex_compile_t *re, ngx_str_t *opts, int narg);
95
+ static int ngx_http_lua_ngx_re_sub_helper(lua_State *L, unsigned global);
96
+ static int ngx_http_lua_ngx_re_match_helper(lua_State *L, int wantcaps);
97
+ static int ngx_http_lua_ngx_re_find(lua_State *L);
98
+ static int ngx_http_lua_ngx_re_match(lua_State *L);
99
+ static int ngx_http_lua_ngx_re_gmatch(lua_State *L);
100
+ static int ngx_http_lua_ngx_re_sub(lua_State *L);
101
+ static int ngx_http_lua_ngx_re_gsub(lua_State *L);
102
+ static void ngx_http_lua_regex_free_study_data(ngx_pool_t *pool,
103
+ pcre_extra *sd);
104
+ static ngx_int_t ngx_http_lua_regex_compile(ngx_http_lua_regex_compile_t *rc);
105
+ static void ngx_http_lua_ngx_re_gmatch_cleanup(void *data);
106
+ static int ngx_http_lua_ngx_re_gmatch_gc(lua_State *L);
107
+ static void ngx_http_lua_re_collect_named_captures(lua_State *L,
108
+ int res_tb_idx, u_char *name_table, int name_count, int name_entry_size,
109
+ unsigned flags, ngx_str_t *subj);
110
+
111
+
112
+ #define ngx_http_lua_regex_exec(re, e, s, start, captures, size, opts) \
113
+ pcre_exec(re, e, (const char *) (s)->data, (s)->len, start, opts, \
114
+ captures, size)
115
+
116
+
117
+ #define ngx_http_lua_regex_dfa_exec(re, e, s, start, captures, size, ws, \
118
+ wscount, opts) \
119
+ pcre_dfa_exec(re, e, (const char *) (s)->data, (s)->len, start, opts, \
120
+ captures, size, ws, wscount)
121
+
122
+
123
+ static int
124
+ ngx_http_lua_ngx_re_match(lua_State *L)
125
+ {
126
+ return ngx_http_lua_ngx_re_match_helper(L, 1 /* want captures */);
127
+ }
128
+
129
+
130
+ static int
131
+ ngx_http_lua_ngx_re_find(lua_State *L)
132
+ {
133
+ return ngx_http_lua_ngx_re_match_helper(L, 0 /* want captures */);
134
+ }
135
+
136
+
137
+ static int
138
+ ngx_http_lua_ngx_re_match_helper(lua_State *L, int wantcaps)
139
+ {
140
+ /* u_char *p; */
141
+ int res_tb_idx = 0;
142
+ ngx_http_request_t *r;
143
+ ngx_str_t subj;
144
+ ngx_str_t pat;
145
+ ngx_str_t opts;
146
+ ngx_http_lua_regex_t *re;
147
+ const char *msg;
148
+ ngx_int_t rc;
149
+ ngx_uint_t n;
150
+ int i;
151
+ ngx_int_t pos = 0;
152
+ int nargs;
153
+ int *cap = NULL;
154
+ int ovecsize;
155
+ ngx_uint_t flags;
156
+ ngx_pool_t *pool, *old_pool;
157
+ ngx_http_lua_main_conf_t *lmcf;
158
+ u_char errstr[NGX_MAX_CONF_ERRSTR + 1];
159
+ pcre_extra *sd = NULL;
160
+ int name_entry_size = 0, name_count;
161
+ u_char *name_table = NULL;
162
+ int exec_opts;
163
+ int group_id = 0;
164
+
165
+ ngx_http_lua_regex_compile_t re_comp;
166
+
167
+ nargs = lua_gettop(L);
168
+
169
+ if (nargs != 2 && nargs != 3 && nargs != 4 && nargs != 5) {
170
+ return luaL_error(L, "expecting 2, 3, 4 or 5 arguments, "
171
+ "but got %d", nargs);
172
+ }
173
+
174
+ r = ngx_http_lua_get_req(L);
175
+ if (r == NULL) {
176
+ return luaL_error(L, "no request object found");
177
+ }
178
+
179
+ subj.data = (u_char *) luaL_checklstring(L, 1, &subj.len);
180
+ pat.data = (u_char *) luaL_checklstring(L, 2, &pat.len);
181
+
182
+ ngx_memzero(&re_comp, sizeof(ngx_http_lua_regex_compile_t));
183
+
184
+ if (nargs >= 3) {
185
+ opts.data = (u_char *) luaL_checklstring(L, 3, &opts.len);
186
+
187
+ if (nargs == 4) {
188
+ luaL_checktype(L, 4, LUA_TTABLE);
189
+ lua_getfield(L, 4, "pos");
190
+ if (lua_isnumber(L, -1)) {
191
+ pos = (ngx_int_t) lua_tointeger(L, -1);
192
+ if (pos <= 0) {
193
+ pos = 0;
194
+
195
+ } else {
196
+ pos--; /* 1-based on the Lua land */
197
+ }
198
+
199
+ } else if (lua_isnil(L, -1)) {
200
+ pos = 0;
201
+
202
+ } else {
203
+ msg = lua_pushfstring(L, "bad pos field type in the ctx table "
204
+ "argument: %s", luaL_typename(L, -1));
205
+
206
+ return luaL_argerror(L, 4, msg);
207
+ }
208
+
209
+ lua_pop(L, 1);
210
+ }
211
+
212
+ } else {
213
+ opts.data = (u_char *) "";
214
+ opts.len = 0;
215
+ }
216
+
217
+ if (nargs == 5) {
218
+ if (wantcaps) {
219
+ luaL_checktype(L, 5, LUA_TTABLE);
220
+ res_tb_idx = 5;
221
+
222
+ #if 0
223
+ /* clear the Lua table */
224
+ lua_pushnil(L);
225
+ while (lua_next(L, res_tb_idx) != 0) {
226
+ lua_pop(L, 1);
227
+ lua_pushvalue(L, -1);
228
+ lua_pushnil(L);
229
+ lua_rawset(L, res_tb_idx);
230
+ }
231
+ #endif
232
+
233
+ } else {
234
+ group_id = luaL_checkint(L, 5);
235
+ if (group_id < 0) {
236
+ group_id = 0;
237
+ }
238
+ }
239
+ }
240
+
241
+ re_comp.options = 0;
242
+
243
+ flags = ngx_http_lua_ngx_re_parse_opts(L, &re_comp, &opts, 3);
244
+
245
+ lmcf = ngx_http_get_module_main_conf(r, ngx_http_lua_module);
246
+
247
+ if (flags & NGX_LUA_RE_COMPILE_ONCE) {
248
+ pool = lmcf->pool;
249
+
250
+ dd("server pool %p", lmcf->pool);
251
+
252
+ lua_pushlightuserdata(L, &ngx_http_lua_regex_cache_key);
253
+ lua_rawget(L, LUA_REGISTRYINDEX); /* table */
254
+
255
+ lua_pushliteral(L, "m");
256
+ lua_pushvalue(L, 2); /* table regex */
257
+
258
+ dd("options size: %d", (int) sizeof(re_comp.options));
259
+
260
+ lua_pushlstring(L, (char *) &re_comp.options, sizeof(re_comp.options));
261
+ /* table regex opts */
262
+
263
+ lua_concat(L, 3); /* table key */
264
+ lua_pushvalue(L, -1); /* table key key */
265
+
266
+ dd("regex cache key: %.*s", (int) (pat.len + sizeof(re_comp.options)),
267
+ lua_tostring(L, -1));
268
+
269
+ lua_rawget(L, -3); /* table key re */
270
+ re = lua_touserdata(L, -1);
271
+
272
+ lua_pop(L, 1); /* table key */
273
+
274
+ if (re) {
275
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
276
+ "lua regex cache hit for match regex \"%s\" with "
277
+ "options \"%s\"", pat.data, opts.data);
278
+
279
+ lua_pop(L, 2);
280
+
281
+ dd("restoring regex %p, ncaptures %d, captures %p", re->regex,
282
+ re->ncaptures, re->captures);
283
+
284
+ re_comp.regex = re->regex;
285
+ sd = re->regex_sd;
286
+ re_comp.captures = re->ncaptures;
287
+ cap = re->captures;
288
+
289
+ if (flags & NGX_LUA_RE_MODE_DFA) {
290
+ ovecsize = 2;
291
+
292
+ } else {
293
+ ovecsize = (re->ncaptures + 1) * 3;
294
+ }
295
+
296
+ goto exec;
297
+ }
298
+
299
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
300
+ "lua regex cache miss for match regex \"%s\" "
301
+ "with options \"%s\"", pat.data, opts.data);
302
+
303
+ if (lmcf->regex_cache_entries >= lmcf->regex_cache_max_entries) {
304
+
305
+ if (lmcf->regex_cache_entries == lmcf->regex_cache_max_entries) {
306
+ ngx_log_error(NGX_LOG_WARN, r->connection->log, 0,
307
+ "lua exceeding regex cache max entries (%i)",
308
+ lmcf->regex_cache_max_entries);
309
+
310
+ lmcf->regex_cache_entries++;
311
+ }
312
+
313
+ pool = r->pool;
314
+ flags &= ~NGX_LUA_RE_COMPILE_ONCE;
315
+ }
316
+
317
+ } else {
318
+ pool = r->pool;
319
+ }
320
+
321
+ dd("pool %p, r pool %p", pool, r->pool);
322
+
323
+ re_comp.pattern = pat;
324
+ re_comp.err.len = NGX_MAX_CONF_ERRSTR;
325
+ re_comp.err.data = errstr;
326
+ re_comp.pool = pool;
327
+
328
+ ngx_log_debug5(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
329
+ "lua compiling match regex \"%s\" with options \"%s\" "
330
+ "(compile once: %d) (dfa mode: %d) (jit mode: %d)",
331
+ pat.data, opts.data,
332
+ (flags & NGX_LUA_RE_COMPILE_ONCE) != 0,
333
+ (flags & NGX_LUA_RE_MODE_DFA) != 0,
334
+ (flags & NGX_LUA_RE_MODE_JIT) != 0);
335
+
336
+ old_pool = ngx_http_lua_pcre_malloc_init(pool);
337
+
338
+ rc = ngx_http_lua_regex_compile(&re_comp);
339
+
340
+ ngx_http_lua_pcre_malloc_done(old_pool);
341
+
342
+ if (rc != NGX_OK) {
343
+ dd("compile failed");
344
+
345
+ lua_pushnil(L);
346
+ if (!wantcaps) {
347
+ lua_pushnil(L);
348
+ }
349
+ lua_pushlstring(L, (char *) re_comp.err.data, re_comp.err.len);
350
+ return wantcaps ? 2 : 3;
351
+ }
352
+
353
+ #if (LUA_HAVE_PCRE_JIT)
354
+
355
+ if (flags & NGX_LUA_RE_MODE_JIT) {
356
+
357
+ old_pool = ngx_http_lua_pcre_malloc_init(pool);
358
+
359
+ sd = pcre_study(re_comp.regex, PCRE_STUDY_JIT_COMPILE, &msg);
360
+
361
+ ngx_http_lua_pcre_malloc_done(old_pool);
362
+
363
+ # if (NGX_DEBUG)
364
+ dd("sd = %p", sd);
365
+
366
+ if (msg != NULL) {
367
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
368
+ "pcre study failed with PCRE_STUDY_JIT_COMPILE: "
369
+ "%s (%p)", msg, sd);
370
+ }
371
+
372
+ if (sd != NULL) {
373
+ int jitted;
374
+
375
+ old_pool = ngx_http_lua_pcre_malloc_init(pool);
376
+
377
+ pcre_fullinfo(re_comp.regex, sd, PCRE_INFO_JIT, &jitted);
378
+
379
+ ngx_http_lua_pcre_malloc_done(old_pool);
380
+
381
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
382
+ "pcre JIT compiling result: %d", jitted);
383
+ }
384
+ # endif /* !(NGX_DEBUG) */
385
+
386
+ } else {
387
+ old_pool = ngx_http_lua_pcre_malloc_init(pool);
388
+
389
+ sd = pcre_study(re_comp.regex, 0, &msg);
390
+
391
+ ngx_http_lua_pcre_malloc_done(old_pool);
392
+
393
+ # if (NGX_DEBUG)
394
+ dd("sd = %p", sd);
395
+
396
+ if (msg != NULL) {
397
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
398
+ "pcre_study failed with PCRE_STUDY_JIT_COMPILE: "
399
+ "%s (%p)", msg, sd);
400
+ }
401
+ # endif /* NGX_DEBUG */
402
+ }
403
+
404
+ #else /* !(LUA_HAVE_PCRE_JIT) */
405
+
406
+ if (flags & NGX_LUA_RE_MODE_JIT) {
407
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
408
+ "your pcre build does not have JIT support and "
409
+ "the \"j\" regex option is ignored");
410
+ }
411
+
412
+ #endif /* LUA_HAVE_PCRE_JIT */
413
+
414
+ if (sd && lmcf->regex_match_limit > 0) {
415
+ sd->flags |= PCRE_EXTRA_MATCH_LIMIT;
416
+ sd->match_limit = lmcf->regex_match_limit;
417
+ }
418
+
419
+ dd("compile done, captures %d", (int) re_comp.captures);
420
+
421
+ if (flags & NGX_LUA_RE_MODE_DFA) {
422
+ ovecsize = 2;
423
+
424
+ } else {
425
+ ovecsize = (re_comp.captures + 1) * 3;
426
+ }
427
+
428
+ dd("allocating cap with size: %d", (int) ovecsize);
429
+
430
+ cap = ngx_palloc(pool, ovecsize * sizeof(int));
431
+
432
+ if (cap == NULL) {
433
+ flags &= ~NGX_LUA_RE_COMPILE_ONCE;
434
+ msg = "no memory";
435
+ goto error;
436
+ }
437
+
438
+ if (flags & NGX_LUA_RE_COMPILE_ONCE) {
439
+
440
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
441
+ "lua saving compiled regex (%d captures) into the cache "
442
+ "(entries %i)", re_comp.captures,
443
+ lmcf->regex_cache_entries);
444
+
445
+ re = ngx_palloc(pool, sizeof(ngx_http_lua_regex_t));
446
+ if (re == NULL) {
447
+ msg = "no memory";
448
+ goto error;
449
+ }
450
+
451
+ dd("saving regex %p, ncaptures %d, captures %p", re_comp.regex,
452
+ re_comp.captures, cap);
453
+
454
+ re->regex = re_comp.regex;
455
+ re->regex_sd = sd;
456
+ re->ncaptures = re_comp.captures;
457
+ re->captures = cap;
458
+ re->replace = NULL;
459
+
460
+ lua_pushlightuserdata(L, re); /* table key value */
461
+ lua_rawset(L, -3); /* table */
462
+ lua_pop(L, 1);
463
+
464
+ if (lmcf) {
465
+ lmcf->regex_cache_entries++;
466
+ }
467
+ }
468
+
469
+ exec:
470
+
471
+ if (pcre_fullinfo(re_comp.regex, NULL, PCRE_INFO_NAMECOUNT,
472
+ &name_count) != 0)
473
+ {
474
+ msg = "cannot acquire named subpattern count";
475
+ goto error;
476
+ }
477
+
478
+ if (name_count > 0) {
479
+ if (pcre_fullinfo(re_comp.regex, NULL, PCRE_INFO_NAMEENTRYSIZE,
480
+ &name_entry_size) != 0)
481
+ {
482
+ msg = "cannot acquire named subpattern entry size";
483
+ goto error;
484
+ }
485
+
486
+ if (pcre_fullinfo(re_comp.regex, NULL, PCRE_INFO_NAMETABLE,
487
+ &name_table) != 0)
488
+ {
489
+ msg = "cannot acquire named subpattern table";
490
+ goto error;
491
+ }
492
+ }
493
+
494
+ if (flags & NGX_LUA_RE_NO_UTF8_CHECK) {
495
+ exec_opts = PCRE_NO_UTF8_CHECK;
496
+
497
+ } else {
498
+ exec_opts = 0;
499
+ }
500
+
501
+ if (flags & NGX_LUA_RE_MODE_DFA) {
502
+
503
+ #if LUA_HAVE_PCRE_DFA
504
+
505
+ int ws[NGX_LUA_RE_DFA_MODE_WORKSPACE_COUNT];
506
+ rc = ngx_http_lua_regex_dfa_exec(re_comp.regex, sd, &subj,
507
+ (int) pos, cap, ovecsize, ws,
508
+ sizeof(ws)/sizeof(ws[0]), exec_opts);
509
+
510
+ #else /* LUA_HAVE_PCRE_DFA */
511
+
512
+ msg = "at least pcre 6.0 is required for the DFA mode";
513
+ goto error;
514
+
515
+ #endif /* LUA_HAVE_PCRE_DFA */
516
+
517
+ } else {
518
+ rc = ngx_http_lua_regex_exec(re_comp.regex, sd, &subj, (int) pos, cap,
519
+ ovecsize, exec_opts);
520
+ }
521
+
522
+ if (rc == NGX_REGEX_NO_MATCHED) {
523
+ ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
524
+ "regex \"%V\" not matched on string \"%V\" starting "
525
+ "from %i", &pat, &subj, pos);
526
+
527
+ if (!(flags & NGX_LUA_RE_COMPILE_ONCE)) {
528
+ if (sd) {
529
+ ngx_http_lua_regex_free_study_data(pool, sd);
530
+ }
531
+
532
+ ngx_pfree(pool, re_comp.regex);
533
+ ngx_pfree(pool, cap);
534
+ }
535
+
536
+ lua_pushnil(L);
537
+ return 1;
538
+ }
539
+
540
+ if (rc < 0) {
541
+ msg = lua_pushfstring(L, ngx_regex_exec_n " failed: %d", (int) rc);
542
+ goto error;
543
+ }
544
+
545
+ if (rc == 0) {
546
+ if (flags & NGX_LUA_RE_MODE_DFA) {
547
+ rc = 1;
548
+
549
+ } else {
550
+ msg = "capture size too small";
551
+ goto error;
552
+ }
553
+ }
554
+
555
+ dd("rc = %d", (int) rc);
556
+
557
+ if (nargs == 4) { /* having ctx table */
558
+ pos = cap[1];
559
+ lua_pushinteger(L, (lua_Integer) (pos + 1));
560
+ lua_setfield(L, 4, "pos");
561
+ }
562
+
563
+ if (!wantcaps) {
564
+ if (group_id > re_comp.captures) {
565
+ lua_pushnil(L);
566
+ lua_pushnil(L);
567
+ lua_pushliteral(L, "nth out of bound");
568
+ return 3;
569
+ }
570
+
571
+ if (group_id >= rc) {
572
+ lua_pushnil(L);
573
+ lua_pushnil(L);
574
+ return 2;
575
+ }
576
+
577
+ {
578
+ int from, to;
579
+
580
+ from = cap[group_id * 2] + 1;
581
+ to = cap[group_id * 2 + 1];
582
+ if (from < 0 || to < 0) {
583
+ lua_pushnil(L);
584
+ lua_pushnil(L);
585
+ return 2;
586
+ }
587
+
588
+ lua_pushinteger(L, from);
589
+ lua_pushinteger(L, to);
590
+ return 2;
591
+ }
592
+ }
593
+
594
+ if (res_tb_idx == 0) {
595
+ lua_createtable(L, rc /* narr */, 0 /* nrec */);
596
+ res_tb_idx = lua_gettop(L);
597
+ }
598
+
599
+ for (i = 0, n = 0; i < rc; i++, n += 2) {
600
+ dd("capture %d: %d %d", i, cap[n], cap[n + 1]);
601
+ if (cap[n] < 0) {
602
+ lua_pushnil(L);
603
+
604
+ } else {
605
+ lua_pushlstring(L, (char *) &subj.data[cap[n]],
606
+ cap[n + 1] - cap[n]);
607
+
608
+ dd("pushing capture %s at %d", lua_tostring(L, -1), (int) i);
609
+ }
610
+
611
+ lua_rawseti(L, res_tb_idx, (int) i);
612
+ }
613
+
614
+ if (name_count > 0) {
615
+ ngx_http_lua_re_collect_named_captures(L, res_tb_idx, name_table,
616
+ name_count, name_entry_size,
617
+ flags, &subj);
618
+ }
619
+
620
+ if (!(flags & NGX_LUA_RE_COMPILE_ONCE)) {
621
+
622
+ if (sd) {
623
+ ngx_http_lua_regex_free_study_data(pool, sd);
624
+ }
625
+
626
+ ngx_pfree(pool, re_comp.regex);
627
+ ngx_pfree(pool, cap);
628
+ }
629
+
630
+ return 1;
631
+
632
+ error:
633
+
634
+ if (!(flags & NGX_LUA_RE_COMPILE_ONCE)) {
635
+ if (sd) {
636
+ ngx_http_lua_regex_free_study_data(pool, sd);
637
+ }
638
+
639
+ if (re_comp.regex) {
640
+ ngx_pfree(pool, re_comp.regex);
641
+ }
642
+
643
+ if (cap) {
644
+ ngx_pfree(pool, cap);
645
+ }
646
+ }
647
+
648
+ lua_pushnil(L);
649
+ if (!wantcaps) {
650
+ lua_pushnil(L);
651
+ }
652
+ lua_pushstring(L, msg);
653
+ return wantcaps ? 2 : 3;
654
+ }
655
+
656
+
657
+ static int
658
+ ngx_http_lua_ngx_re_gmatch(lua_State *L)
659
+ {
660
+ ngx_http_lua_main_conf_t *lmcf;
661
+ ngx_http_request_t *r;
662
+ ngx_str_t subj;
663
+ ngx_str_t pat;
664
+ ngx_str_t opts;
665
+ int ovecsize;
666
+ ngx_http_lua_regex_t *re;
667
+ ngx_http_lua_regex_ctx_t *ctx;
668
+ const char *msg;
669
+ int nargs;
670
+ ngx_int_t flags;
671
+ int *cap = NULL;
672
+ ngx_int_t rc;
673
+ ngx_pool_t *pool, *old_pool;
674
+ u_char errstr[NGX_MAX_CONF_ERRSTR + 1];
675
+ pcre_extra *sd = NULL;
676
+ ngx_http_cleanup_t *cln;
677
+
678
+ ngx_http_lua_regex_compile_t re_comp;
679
+
680
+ nargs = lua_gettop(L);
681
+
682
+ if (nargs != 2 && nargs != 3) {
683
+ return luaL_error(L, "expecting two or three arguments, but got %d",
684
+ nargs);
685
+ }
686
+
687
+ r = ngx_http_lua_get_req(L);
688
+ if (r == NULL) {
689
+ return luaL_error(L, "no request object found");
690
+ }
691
+
692
+ subj.data = (u_char *) luaL_checklstring(L, 1, &subj.len);
693
+ pat.data = (u_char *) luaL_checklstring(L, 2, &pat.len);
694
+
695
+ if (nargs == 3) {
696
+ opts.data = (u_char *) luaL_checklstring(L, 3, &opts.len);
697
+ lua_pop(L, 1);
698
+
699
+ } else {
700
+ opts.data = (u_char *) "";
701
+ opts.len = 0;
702
+ }
703
+
704
+ /* stack: subj regex */
705
+
706
+ re_comp.options = 0;
707
+
708
+ flags = ngx_http_lua_ngx_re_parse_opts(L, &re_comp, &opts, 3);
709
+
710
+ lmcf = ngx_http_get_module_main_conf(r, ngx_http_lua_module);
711
+
712
+ if (flags & NGX_LUA_RE_COMPILE_ONCE) {
713
+ pool = lmcf->pool;
714
+
715
+ dd("server pool %p", lmcf->pool);
716
+
717
+ lua_pushlightuserdata(L, &ngx_http_lua_regex_cache_key);
718
+ lua_rawget(L, LUA_REGISTRYINDEX); /* table */
719
+
720
+ lua_pushliteral(L, "m");
721
+ lua_pushvalue(L, 2); /* table regex */
722
+
723
+ dd("options size: %d", (int) sizeof(re_comp.options));
724
+
725
+ lua_pushlstring(L, (char *) &re_comp.options,
726
+ sizeof(re_comp.options)); /* table regex opts */
727
+
728
+ lua_concat(L, 3); /* table key */
729
+ lua_pushvalue(L, -1); /* table key key */
730
+
731
+ dd("regex cache key: %.*s", (int) (pat.len + sizeof(re_comp.options)),
732
+ lua_tostring(L, -1));
733
+
734
+ lua_rawget(L, -3); /* table key re */
735
+ re = lua_touserdata(L, -1);
736
+
737
+ lua_pop(L, 1); /* table key */
738
+
739
+ if (re) {
740
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
741
+ "lua regex cache hit for match regex \"%s\" "
742
+ "with options \"%s\"", pat.data, opts.data);
743
+
744
+ lua_pop(L, 2);
745
+
746
+ dd("restoring regex %p, ncaptures %d, captures %p", re->regex,
747
+ re->ncaptures, re->captures);
748
+
749
+ re_comp.regex = re->regex;
750
+ sd = re->regex_sd;
751
+ re_comp.captures = re->ncaptures;
752
+ cap = re->captures;
753
+
754
+ if (flags & NGX_LUA_RE_MODE_DFA) {
755
+ ovecsize = 2;
756
+
757
+ } else {
758
+ ovecsize = (re->ncaptures + 1) * 3;
759
+ }
760
+
761
+ goto compiled;
762
+ }
763
+
764
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
765
+ "lua regex cache miss for match regex \"%s\" "
766
+ "with options \"%s\"", pat.data, opts.data);
767
+
768
+ if (lmcf->regex_cache_entries >= lmcf->regex_cache_max_entries) {
769
+
770
+ if (lmcf->regex_cache_entries == lmcf->regex_cache_max_entries) {
771
+ ngx_log_error(NGX_LOG_WARN, r->connection->log, 0,
772
+ "lua exceeding regex cache max entries (%i)",
773
+ lmcf->regex_cache_max_entries);
774
+
775
+ lmcf->regex_cache_entries++;
776
+ }
777
+
778
+ pool = r->pool;
779
+ flags &= ~NGX_LUA_RE_COMPILE_ONCE;
780
+ }
781
+
782
+ } else {
783
+ pool = r->pool;
784
+ }
785
+
786
+ re_comp.pattern = pat;
787
+ re_comp.err.len = NGX_MAX_CONF_ERRSTR;
788
+ re_comp.err.data = errstr;
789
+ re_comp.pool = pool;
790
+
791
+ ngx_log_debug5(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
792
+ "lua compiling gmatch regex \"%s\" with options \"%s\" "
793
+ "(compile once: %d) (dfa mode: %d) (jit mode: %d)",
794
+ pat.data, opts.data,
795
+ (flags & NGX_LUA_RE_COMPILE_ONCE) != 0,
796
+ (flags & NGX_LUA_RE_MODE_DFA) != 0,
797
+ (flags & NGX_LUA_RE_MODE_JIT) != 0);
798
+
799
+ old_pool = ngx_http_lua_pcre_malloc_init(pool);
800
+
801
+ rc = ngx_http_lua_regex_compile(&re_comp);
802
+
803
+ ngx_http_lua_pcre_malloc_done(old_pool);
804
+
805
+ if (rc != NGX_OK) {
806
+ dd("compile failed");
807
+
808
+ lua_pushnil(L);
809
+ lua_pushlstring(L, (char *) re_comp.err.data, re_comp.err.len);
810
+ return 2;
811
+ }
812
+
813
+ #if LUA_HAVE_PCRE_JIT
814
+
815
+ if (flags & NGX_LUA_RE_MODE_JIT) {
816
+
817
+ old_pool = ngx_http_lua_pcre_malloc_init(pool);
818
+
819
+ sd = pcre_study(re_comp.regex, PCRE_STUDY_JIT_COMPILE, &msg);
820
+
821
+ ngx_http_lua_pcre_malloc_done(old_pool);
822
+
823
+ # if (NGX_DEBUG)
824
+ dd("sd = %p", sd);
825
+
826
+ if (msg != NULL) {
827
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
828
+ "pcre_study failed with PCRE_STUDY_JIT_COMPILE: "
829
+ "%s (%p)", msg, sd);
830
+ }
831
+
832
+ if (sd != NULL) {
833
+ int jitted;
834
+
835
+ old_pool = ngx_http_lua_pcre_malloc_init(pool);
836
+
837
+ pcre_fullinfo(re_comp.regex, sd, PCRE_INFO_JIT, &jitted);
838
+
839
+ ngx_http_lua_pcre_malloc_done(old_pool);
840
+
841
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
842
+ "pcre JIT compiling result: %d", jitted);
843
+ }
844
+ # endif /* NGX_DEBUG */
845
+
846
+ } else {
847
+
848
+ old_pool = ngx_http_lua_pcre_malloc_init(pool);
849
+
850
+ sd = pcre_study(re_comp.regex, 0, &msg);
851
+
852
+ ngx_http_lua_pcre_malloc_done(old_pool);
853
+
854
+ # if (NGX_DEBUG)
855
+ dd("sd = %p", sd);
856
+
857
+ if (msg != NULL) {
858
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
859
+ "pcre study failed with PCRE_STUDY_JIT_COMPILE: "
860
+ "%s (%p)", msg, sd);
861
+ }
862
+ # endif /* NGX_DEBUG */
863
+ }
864
+
865
+ #else /* LUA_HAVE_PCRE_JIT */
866
+
867
+ if (flags & NGX_LUA_RE_MODE_JIT) {
868
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
869
+ "your pcre build does not have JIT support and "
870
+ "the \"j\" regex option is ignored");
871
+ }
872
+
873
+ #endif /* LUA_HAVE_PCRE_JIT */
874
+
875
+ if (sd && lmcf->regex_match_limit > 0) {
876
+ sd->flags |= PCRE_EXTRA_MATCH_LIMIT;
877
+ sd->match_limit = lmcf->regex_match_limit;
878
+ }
879
+
880
+ dd("compile done, captures %d", re_comp.captures);
881
+
882
+ if (flags & NGX_LUA_RE_MODE_DFA) {
883
+ ovecsize = 2;
884
+
885
+ } else {
886
+ ovecsize = (re_comp.captures + 1) * 3;
887
+ }
888
+
889
+ cap = ngx_palloc(pool, ovecsize * sizeof(int));
890
+ if (cap == NULL) {
891
+ flags &= ~NGX_LUA_RE_COMPILE_ONCE;
892
+ msg = "no memory";
893
+ goto error;
894
+ }
895
+
896
+ if (flags & NGX_LUA_RE_COMPILE_ONCE) {
897
+
898
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
899
+ "lua saving compiled regex (%d captures) into the cache "
900
+ "(entries %i)", re_comp.captures,
901
+ lmcf->regex_cache_entries);
902
+
903
+ re = ngx_palloc(pool, sizeof(ngx_http_lua_regex_t));
904
+ if (re == NULL) {
905
+ msg = "no memory";
906
+ goto error;
907
+ }
908
+
909
+ dd("saving regex %p, ncaptures %d, captures %p", re_comp.regex,
910
+ re_comp.captures, cap);
911
+
912
+ re->regex = re_comp.regex;
913
+ re->regex_sd = sd;
914
+ re->ncaptures = re_comp.captures;
915
+ re->captures = cap;
916
+ re->replace = NULL;
917
+
918
+ lua_pushlightuserdata(L, re); /* table key value */
919
+ lua_rawset(L, -3); /* table */
920
+ lua_pop(L, 1);
921
+
922
+ if (lmcf) {
923
+ lmcf->regex_cache_entries++;
924
+ }
925
+ }
926
+
927
+ compiled:
928
+
929
+ lua_settop(L, 1);
930
+
931
+ ctx = lua_newuserdata(L, sizeof(ngx_http_lua_regex_ctx_t));
932
+
933
+ ctx->request = r;
934
+ ctx->regex = re_comp.regex;
935
+ ctx->regex_sd = sd;
936
+ ctx->ncaptures = re_comp.captures;
937
+ ctx->captures = cap;
938
+ ctx->captures_len = ovecsize;
939
+ ctx->flags = (uint8_t) flags;
940
+
941
+ if (!(flags & NGX_LUA_RE_COMPILE_ONCE)) {
942
+ lua_createtable(L, 0 /* narr */, 1 /* nrec */); /* metatable */
943
+ lua_pushcfunction(L, ngx_http_lua_ngx_re_gmatch_gc);
944
+ lua_setfield(L, -2, "__gc");
945
+ lua_setmetatable(L, -2);
946
+
947
+ cln = ngx_http_cleanup_add(r, 0);
948
+ if (cln == NULL) {
949
+ msg = "no memory";
950
+ goto error;
951
+ }
952
+
953
+ cln->handler = ngx_http_lua_ngx_re_gmatch_cleanup;
954
+ cln->data = ctx;
955
+ ctx->cleanup = &cln->handler;
956
+
957
+ } else {
958
+ ctx->cleanup = NULL;
959
+ }
960
+
961
+ lua_pushinteger(L, 0);
962
+
963
+ /* upvalues in order: subj ctx offset */
964
+ lua_pushcclosure(L, ngx_http_lua_ngx_re_gmatch_iterator, 3);
965
+
966
+ return 1;
967
+
968
+ error:
969
+
970
+ if (!(flags & NGX_LUA_RE_COMPILE_ONCE)) {
971
+ if (sd) {
972
+ ngx_http_lua_regex_free_study_data(pool, sd);
973
+ }
974
+
975
+ if (re_comp.regex) {
976
+ ngx_pfree(pool, re_comp.regex);
977
+ }
978
+
979
+ if (cap) {
980
+ ngx_pfree(pool, cap);
981
+ }
982
+ }
983
+
984
+ lua_pushnil(L);
985
+ lua_pushstring(L, msg);
986
+ return 2;
987
+ }
988
+
989
+
990
+ static int
991
+ ngx_http_lua_ngx_re_gmatch_iterator(lua_State *L)
992
+ {
993
+ ngx_http_lua_regex_ctx_t *ctx;
994
+ ngx_http_request_t *r;
995
+ int *cap;
996
+ ngx_int_t rc;
997
+ ngx_uint_t n;
998
+ int i;
999
+ ngx_str_t subj;
1000
+ int offset;
1001
+ const char *msg = NULL;
1002
+ int name_entry_size = 0, name_count;
1003
+ u_char *name_table = NULL;
1004
+ int exec_opts;
1005
+
1006
+ /* upvalues in order: subj ctx offset */
1007
+
1008
+ subj.data = (u_char *) lua_tolstring(L, lua_upvalueindex(1), &subj.len);
1009
+ ctx = (ngx_http_lua_regex_ctx_t *) lua_touserdata(L, lua_upvalueindex(2));
1010
+ offset = (int) lua_tointeger(L, lua_upvalueindex(3));
1011
+
1012
+ if (offset < 0) {
1013
+ lua_pushnil(L);
1014
+ return 1;
1015
+ }
1016
+
1017
+ cap = ctx->captures;
1018
+
1019
+ dd("offset %d, r %p, subj %s", (int) offset, ctx->request, subj.data);
1020
+
1021
+ r = ngx_http_lua_get_req(L);
1022
+ if (r == NULL) {
1023
+ return luaL_error(L, "no request object found");
1024
+ }
1025
+
1026
+ if (r != ctx->request || r->pool != ctx->request->pool) {
1027
+ return luaL_error(L, "attempt to use ngx.re.gmatch iterator in a "
1028
+ "request that did not create it");
1029
+ }
1030
+
1031
+ dd("regex exec...");
1032
+
1033
+ if (pcre_fullinfo(ctx->regex, NULL, PCRE_INFO_NAMECOUNT,
1034
+ &name_count) != 0)
1035
+ {
1036
+ msg = "cannot acquire named subpattern count";
1037
+ goto error;
1038
+ }
1039
+
1040
+ if (name_count > 0) {
1041
+ if (pcre_fullinfo(ctx->regex, NULL, PCRE_INFO_NAMEENTRYSIZE,
1042
+ &name_entry_size) != 0)
1043
+ {
1044
+ msg = "cannot acquire named subpattern entry size";
1045
+ goto error;
1046
+ }
1047
+
1048
+ if (pcre_fullinfo(ctx->regex, NULL, PCRE_INFO_NAMETABLE,
1049
+ &name_table) != 0)
1050
+ {
1051
+ msg = "cannot acquire named subpattern table";
1052
+ goto error;
1053
+ }
1054
+ }
1055
+
1056
+ if (ctx->flags & NGX_LUA_RE_NO_UTF8_CHECK) {
1057
+ exec_opts = PCRE_NO_UTF8_CHECK;
1058
+
1059
+ } else {
1060
+ exec_opts = 0;
1061
+ }
1062
+
1063
+ if (ctx->flags & NGX_LUA_RE_MODE_DFA) {
1064
+
1065
+ #if LUA_HAVE_PCRE_DFA
1066
+
1067
+ int ws[NGX_LUA_RE_DFA_MODE_WORKSPACE_COUNT];
1068
+
1069
+ rc = ngx_http_lua_regex_dfa_exec(ctx->regex, ctx->regex_sd, &subj,
1070
+ offset, cap, ctx->captures_len, ws,
1071
+ sizeof(ws)/sizeof(ws[0]), exec_opts);
1072
+
1073
+ #else /* LUA_HAVE_PCRE_DFA */
1074
+ msg = "at least pcre 6.0 is required for the DFA mode";
1075
+ goto error;
1076
+
1077
+ #endif /* LUA_HAVE_PCRE_DFA */
1078
+
1079
+ } else {
1080
+ rc = ngx_http_lua_regex_exec(ctx->regex, ctx->regex_sd, &subj,
1081
+ offset, cap, ctx->captures_len,
1082
+ exec_opts);
1083
+ }
1084
+
1085
+ if (rc == NGX_REGEX_NO_MATCHED) {
1086
+ /* set upvalue "offset" to -1 */
1087
+ lua_pushinteger(L, -1);
1088
+ lua_replace(L, lua_upvalueindex(3));
1089
+
1090
+ if (!(ctx->flags & NGX_LUA_RE_COMPILE_ONCE)) {
1091
+ if (ctx->regex_sd) {
1092
+ ngx_http_lua_regex_free_study_data(r->pool, ctx->regex_sd);
1093
+ ctx->regex_sd = NULL;
1094
+ }
1095
+
1096
+ ngx_pfree(r->pool, cap);
1097
+ }
1098
+
1099
+ lua_pushnil(L);
1100
+ return 1;
1101
+ }
1102
+
1103
+ if (rc < 0) {
1104
+ msg = lua_pushfstring(L, ngx_regex_exec_n " failed: %d", (int) rc);
1105
+ goto error;
1106
+ }
1107
+
1108
+ if (rc == 0) {
1109
+ if (ctx->flags & NGX_LUA_RE_MODE_DFA) {
1110
+ rc = 1;
1111
+
1112
+ } else {
1113
+ goto error;
1114
+ }
1115
+ }
1116
+
1117
+ dd("rc = %d", (int) rc);
1118
+
1119
+ lua_createtable(L, rc /* narr */, 0 /* nrec */);
1120
+
1121
+ for (i = 0, n = 0; i < rc; i++, n += 2) {
1122
+ dd("capture %d: %d %d", i, cap[n], cap[n + 1]);
1123
+ if (cap[n] < 0) {
1124
+ lua_pushnil(L);
1125
+
1126
+ } else {
1127
+ lua_pushlstring(L, (char *) &subj.data[cap[n]],
1128
+ cap[n + 1] - cap[n]);
1129
+
1130
+ dd("pushing capture %s at %d", lua_tostring(L, -1), (int) i);
1131
+ }
1132
+
1133
+ lua_rawseti(L, -2, (int) i);
1134
+ }
1135
+
1136
+ if (name_count > 0) {
1137
+ ngx_http_lua_re_collect_named_captures(L, lua_gettop(L), name_table,
1138
+ name_count, name_entry_size,
1139
+ ctx->flags, &subj);
1140
+ }
1141
+
1142
+ offset = cap[1];
1143
+ if (offset == cap[0]) {
1144
+ offset++;
1145
+ }
1146
+
1147
+ if (offset > (ssize_t) subj.len) {
1148
+ offset = -1;
1149
+
1150
+ if (!(ctx->flags & NGX_LUA_RE_COMPILE_ONCE)) {
1151
+ if (ctx->regex_sd) {
1152
+ ngx_http_lua_regex_free_study_data(r->pool, ctx->regex_sd);
1153
+ ctx->regex_sd = NULL;
1154
+ }
1155
+
1156
+ ngx_pfree(r->pool, cap);
1157
+ }
1158
+ }
1159
+
1160
+ lua_pushinteger(L, offset);
1161
+ lua_replace(L, lua_upvalueindex(3));
1162
+
1163
+ return 1;
1164
+
1165
+ error:
1166
+
1167
+ lua_pushinteger(L, -1);
1168
+ lua_replace(L, lua_upvalueindex(3));
1169
+
1170
+ if (!(ctx->flags & NGX_LUA_RE_COMPILE_ONCE)) {
1171
+ if (ctx->regex_sd) {
1172
+ ngx_http_lua_regex_free_study_data(r->pool, ctx->regex_sd);
1173
+ ctx->regex_sd = NULL;
1174
+ }
1175
+
1176
+ ngx_pfree(r->pool, cap);
1177
+ }
1178
+
1179
+ lua_pushnil(L);
1180
+ lua_pushstring(L, msg);
1181
+ return 2;
1182
+ }
1183
+
1184
+
1185
+ static ngx_uint_t
1186
+ ngx_http_lua_ngx_re_parse_opts(lua_State *L, ngx_http_lua_regex_compile_t *re,
1187
+ ngx_str_t *opts, int narg)
1188
+ {
1189
+ u_char *p;
1190
+ const char *msg;
1191
+ ngx_uint_t flags;
1192
+
1193
+ flags = 0;
1194
+ p = opts->data;
1195
+
1196
+ while (*p != '\0') {
1197
+ switch (*p) {
1198
+ case 'i':
1199
+ re->options |= NGX_REGEX_CASELESS;
1200
+ break;
1201
+
1202
+ case 's':
1203
+ re->options |= PCRE_DOTALL;
1204
+ break;
1205
+
1206
+ case 'm':
1207
+ re->options |= PCRE_MULTILINE;
1208
+ break;
1209
+
1210
+ case 'u':
1211
+ re->options |= PCRE_UTF8;
1212
+ break;
1213
+
1214
+ case 'U':
1215
+ re->options |= PCRE_UTF8;
1216
+ flags |= NGX_LUA_RE_NO_UTF8_CHECK;
1217
+ break;
1218
+
1219
+ case 'x':
1220
+ re->options |= PCRE_EXTENDED;
1221
+ break;
1222
+
1223
+ case 'o':
1224
+ flags |= NGX_LUA_RE_COMPILE_ONCE;
1225
+ break;
1226
+
1227
+ case 'j':
1228
+ flags |= NGX_LUA_RE_MODE_JIT;
1229
+ break;
1230
+
1231
+ case 'd':
1232
+ flags |= NGX_LUA_RE_MODE_DFA;
1233
+ break;
1234
+
1235
+ case 'a':
1236
+ re->options |= PCRE_ANCHORED;
1237
+ break;
1238
+
1239
+ #if (PCRE_MAJOR > 8) || (PCRE_MAJOR == 8 && PCRE_MINOR >= 12)
1240
+ case 'D':
1241
+ re->options |= PCRE_DUPNAMES;
1242
+ flags |= NGX_LUA_RE_MODE_DUPNAMES;
1243
+ break;
1244
+
1245
+ case 'J':
1246
+ re->options |= PCRE_JAVASCRIPT_COMPAT;
1247
+ break;
1248
+ #endif
1249
+
1250
+ default:
1251
+ msg = lua_pushfstring(L, "unknown flag \"%c\" (flags \"%s\")",
1252
+ *p, opts->data);
1253
+ return luaL_argerror(L, narg, msg);
1254
+ }
1255
+
1256
+ p++;
1257
+ }
1258
+
1259
+ /* pcre does not support JIT for DFA mode yet,
1260
+ * so if DFA mode is specified, we turn off JIT automatically
1261
+ * */
1262
+ if ((flags & NGX_LUA_RE_MODE_JIT) && (flags & NGX_LUA_RE_MODE_DFA)) {
1263
+ flags &= ~NGX_LUA_RE_MODE_JIT;
1264
+ }
1265
+
1266
+ return flags;
1267
+ }
1268
+
1269
+
1270
+ static int
1271
+ ngx_http_lua_ngx_re_sub(lua_State *L)
1272
+ {
1273
+ return ngx_http_lua_ngx_re_sub_helper(L, 0 /* global */);
1274
+ }
1275
+
1276
+
1277
+ static int
1278
+ ngx_http_lua_ngx_re_gsub(lua_State *L)
1279
+ {
1280
+ return ngx_http_lua_ngx_re_sub_helper(L, 1 /* global */);
1281
+ }
1282
+
1283
+
1284
+ static int
1285
+ ngx_http_lua_ngx_re_sub_helper(lua_State *L, unsigned global)
1286
+ {
1287
+ ngx_http_lua_regex_t *re;
1288
+ ngx_http_request_t *r;
1289
+ ngx_str_t subj;
1290
+ ngx_str_t pat;
1291
+ ngx_str_t opts;
1292
+ ngx_str_t tpl;
1293
+ ngx_http_lua_main_conf_t *lmcf;
1294
+ ngx_pool_t *pool, *old_pool;
1295
+ const char *msg;
1296
+ ngx_int_t rc;
1297
+ ngx_uint_t n;
1298
+ ngx_int_t i;
1299
+ int nargs;
1300
+ int *cap = NULL;
1301
+ int ovecsize;
1302
+ int type;
1303
+ unsigned func;
1304
+ int offset;
1305
+ int cp_offset;
1306
+ size_t count;
1307
+ luaL_Buffer luabuf;
1308
+ ngx_int_t flags;
1309
+ u_char *p;
1310
+ u_char errstr[NGX_MAX_CONF_ERRSTR + 1];
1311
+ pcre_extra *sd = NULL;
1312
+ int name_entry_size = 0, name_count;
1313
+ u_char *name_table = NULL;
1314
+ int exec_opts;
1315
+
1316
+ ngx_http_lua_regex_compile_t re_comp;
1317
+ ngx_http_lua_complex_value_t *ctpl = NULL;
1318
+ ngx_http_lua_compile_complex_value_t ccv;
1319
+
1320
+ nargs = lua_gettop(L);
1321
+
1322
+ if (nargs != 3 && nargs != 4) {
1323
+ return luaL_error(L, "expecting three or four arguments, but got %d",
1324
+ nargs);
1325
+ }
1326
+
1327
+ r = ngx_http_lua_get_req(L);
1328
+ if (r == NULL) {
1329
+ return luaL_error(L, "no request object found");
1330
+ }
1331
+
1332
+ subj.data = (u_char *) luaL_checklstring(L, 1, &subj.len);
1333
+ pat.data = (u_char *) luaL_checklstring(L, 2, &pat.len);
1334
+
1335
+ func = 0;
1336
+
1337
+ type = lua_type(L, 3);
1338
+ switch (type) {
1339
+ case LUA_TFUNCTION:
1340
+ func = 1;
1341
+ tpl.len = 0;
1342
+ tpl.data = (u_char *) "";
1343
+ break;
1344
+
1345
+ case LUA_TNUMBER:
1346
+ case LUA_TSTRING:
1347
+ tpl.data = (u_char *) lua_tolstring(L, 3, &tpl.len);
1348
+ break;
1349
+
1350
+ default:
1351
+ msg = lua_pushfstring(L, "string, number, or function expected, "
1352
+ "got %s", lua_typename(L, type));
1353
+ return luaL_argerror(L, 3, msg);
1354
+ }
1355
+
1356
+ ngx_memzero(&re_comp, sizeof(ngx_http_lua_regex_compile_t));
1357
+
1358
+ if (nargs == 4) {
1359
+ opts.data = (u_char *) luaL_checklstring(L, 4, &opts.len);
1360
+ lua_pop(L, 1);
1361
+
1362
+ } else { /* nargs == 3 */
1363
+ opts.data = (u_char *) "";
1364
+ opts.len = 0;
1365
+ }
1366
+
1367
+ /* stack: subj regex repl */
1368
+
1369
+ re_comp.options = 0;
1370
+
1371
+ flags = ngx_http_lua_ngx_re_parse_opts(L, &re_comp, &opts, 4);
1372
+
1373
+ lmcf = ngx_http_get_module_main_conf(r, ngx_http_lua_module);
1374
+
1375
+ if (flags & NGX_LUA_RE_COMPILE_ONCE) {
1376
+ pool = lmcf->pool;
1377
+
1378
+ dd("server pool %p", lmcf->pool);
1379
+
1380
+ lua_pushlightuserdata(L, &ngx_http_lua_regex_cache_key);
1381
+ lua_rawget(L, LUA_REGISTRYINDEX); /* table */
1382
+
1383
+ lua_pushliteral(L, "s");
1384
+ lua_pushinteger(L, tpl.len);
1385
+ lua_pushliteral(L, ":");
1386
+ lua_pushvalue(L, 2);
1387
+
1388
+ if (tpl.len != 0) {
1389
+ lua_pushvalue(L, 3);
1390
+ }
1391
+
1392
+ dd("options size: %d", (int) sizeof(re_comp.options));
1393
+
1394
+ lua_pushlstring(L, (char *) &re_comp.options, sizeof(re_comp.options));
1395
+ /* table regex opts */
1396
+
1397
+ if (tpl.len == 0) {
1398
+ lua_concat(L, 5); /* table key */
1399
+
1400
+ } else {
1401
+ lua_concat(L, 6); /* table key */
1402
+ }
1403
+
1404
+ lua_pushvalue(L, -1); /* table key key */
1405
+
1406
+ dd("regex cache key: %.*s", (int) (pat.len + sizeof(re_comp.options)),
1407
+ lua_tostring(L, -1));
1408
+
1409
+ lua_rawget(L, -3); /* table key re */
1410
+ re = lua_touserdata(L, -1);
1411
+
1412
+ lua_pop(L, 1); /* table key */
1413
+
1414
+ if (re) {
1415
+ ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1416
+ "lua regex cache hit for sub regex \"%s\" with "
1417
+ "options \"%s\" and replace \"%s\"",
1418
+ pat.data, opts.data,
1419
+ func ? (u_char *) "<func>" : tpl.data);
1420
+
1421
+ lua_pop(L, 2);
1422
+
1423
+ dd("restoring regex %p, ncaptures %d, captures %p", re->regex,
1424
+ re->ncaptures, re->captures);
1425
+
1426
+ re_comp.regex = re->regex;
1427
+ sd = re->regex_sd;
1428
+ re_comp.captures = re->ncaptures;
1429
+ cap = re->captures;
1430
+ ctpl = re->replace;
1431
+
1432
+ if (flags & NGX_LUA_RE_MODE_DFA) {
1433
+ ovecsize = 2;
1434
+
1435
+ } else {
1436
+ ovecsize = (re->ncaptures + 1) * 3;
1437
+ }
1438
+
1439
+ goto exec;
1440
+ }
1441
+
1442
+ ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1443
+ "lua regex cache miss for %ssub regex \"%s\" with "
1444
+ "options \"%s\" and replace \"%s\"",
1445
+ global ? "g" : "", pat.data, opts.data,
1446
+ func ? (u_char *) "<func>" : tpl.data);
1447
+
1448
+ if (lmcf->regex_cache_entries >= lmcf->regex_cache_max_entries) {
1449
+
1450
+ if (lmcf->regex_cache_entries == lmcf->regex_cache_max_entries) {
1451
+ ngx_log_error(NGX_LOG_WARN, r->connection->log, 0,
1452
+ "lua exceeding regex cache max entries (%i)",
1453
+ lmcf->regex_cache_max_entries);
1454
+
1455
+ lmcf->regex_cache_entries++;
1456
+ }
1457
+
1458
+ pool = r->pool;
1459
+ flags &= ~NGX_LUA_RE_COMPILE_ONCE;
1460
+ }
1461
+
1462
+ } else {
1463
+ pool = r->pool;
1464
+ }
1465
+
1466
+ re_comp.pattern = pat;
1467
+ re_comp.err.len = NGX_MAX_CONF_ERRSTR;
1468
+ re_comp.err.data = errstr;
1469
+ re_comp.pool = pool;
1470
+
1471
+ dd("compiling regex");
1472
+
1473
+ ngx_log_debug6(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1474
+ "lua compiling %ssub regex \"%s\" with options \"%s\" "
1475
+ "(compile once: %d) (dfa mode: %d) (jit mode: %d)",
1476
+ global ? "g" : "", pat.data, opts.data,
1477
+ (flags & NGX_LUA_RE_COMPILE_ONCE) != 0,
1478
+ (flags & NGX_LUA_RE_MODE_DFA) != 0,
1479
+ (flags & NGX_LUA_RE_MODE_JIT) != 0);
1480
+
1481
+ old_pool = ngx_http_lua_pcre_malloc_init(pool);
1482
+
1483
+ rc = ngx_http_lua_regex_compile(&re_comp);
1484
+
1485
+ ngx_http_lua_pcre_malloc_done(old_pool);
1486
+
1487
+ if (rc != NGX_OK) {
1488
+ dd("compile failed");
1489
+
1490
+ lua_pushnil(L);
1491
+ lua_pushnil(L);
1492
+ lua_pushlstring(L, (char *) re_comp.err.data, re_comp.err.len);
1493
+ return 3;
1494
+ }
1495
+
1496
+ #if LUA_HAVE_PCRE_JIT
1497
+
1498
+ if (flags & NGX_LUA_RE_MODE_JIT) {
1499
+
1500
+ old_pool = ngx_http_lua_pcre_malloc_init(pool);
1501
+
1502
+ sd = pcre_study(re_comp.regex, PCRE_STUDY_JIT_COMPILE, &msg);
1503
+
1504
+ ngx_http_lua_pcre_malloc_done(old_pool);
1505
+
1506
+ # if (NGX_DEBUG)
1507
+ dd("sd = %p", sd);
1508
+
1509
+ if (msg != NULL) {
1510
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1511
+ "pcre study failed with PCRE_STUDY_JIT_COMPILE: "
1512
+ "%s (%p)", msg, sd);
1513
+ }
1514
+
1515
+ if (sd != NULL) {
1516
+ int jitted;
1517
+
1518
+ old_pool = ngx_http_lua_pcre_malloc_init(pool);
1519
+
1520
+ pcre_fullinfo(re_comp.regex, sd, PCRE_INFO_JIT, &jitted);
1521
+
1522
+ ngx_http_lua_pcre_malloc_done(old_pool);
1523
+
1524
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1525
+ "pcre JIT compiling result: %d", jitted);
1526
+ }
1527
+ # endif /* NGX_DEBUG */
1528
+
1529
+ } else {
1530
+
1531
+ old_pool = ngx_http_lua_pcre_malloc_init(pool);
1532
+
1533
+ sd = pcre_study(re_comp.regex, 0, &msg);
1534
+
1535
+ ngx_http_lua_pcre_malloc_done(old_pool);
1536
+
1537
+ # if (NGX_DEBUG)
1538
+ dd("sd = %p", sd);
1539
+
1540
+ if (msg != NULL) {
1541
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1542
+ "pcre_study failed with PCRE_STUDY_JIT_COMPILE: "
1543
+ "%s (%p)", msg, sd);
1544
+ }
1545
+ # endif /* NGX_DEBUG */
1546
+ }
1547
+
1548
+ #else /* LUA_HAVE_PCRE_JIT */
1549
+
1550
+ if (flags & NGX_LUA_RE_MODE_JIT) {
1551
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1552
+ "your pcre build does not have JIT support and "
1553
+ "the \"j\" regex option is ignored");
1554
+ }
1555
+
1556
+ #endif /* LUA_HAVE_PCRE_JIT */
1557
+
1558
+ if (sd && lmcf->regex_match_limit > 0) {
1559
+ sd->flags |= PCRE_EXTRA_MATCH_LIMIT;
1560
+ sd->match_limit = lmcf->regex_match_limit;
1561
+ }
1562
+
1563
+ dd("compile done, captures %d", re_comp.captures);
1564
+
1565
+ if (flags & NGX_LUA_RE_MODE_DFA) {
1566
+ ovecsize = 2;
1567
+
1568
+ } else {
1569
+ ovecsize = (re_comp.captures + 1) * 3;
1570
+ }
1571
+
1572
+ cap = ngx_palloc(pool, ovecsize * sizeof(int));
1573
+ if (cap == NULL) {
1574
+ flags &= ~NGX_LUA_RE_COMPILE_ONCE;
1575
+ msg = "no memory";
1576
+ goto error;
1577
+ }
1578
+
1579
+ if (func) {
1580
+ ctpl = NULL;
1581
+
1582
+ } else {
1583
+ ctpl = ngx_palloc(pool, sizeof(ngx_http_lua_complex_value_t));
1584
+ if (ctpl == NULL) {
1585
+ flags &= ~NGX_LUA_RE_COMPILE_ONCE;
1586
+ msg = "no memory";
1587
+ goto error;
1588
+ }
1589
+
1590
+ if ((flags & NGX_LUA_RE_COMPILE_ONCE) && tpl.len != 0) {
1591
+ /* copy the string buffer pointed to by tpl.data from Lua VM */
1592
+ p = ngx_palloc(pool, tpl.len + 1);
1593
+ if (p == NULL) {
1594
+ flags &= ~NGX_LUA_RE_COMPILE_ONCE;
1595
+ msg = "no memory";
1596
+ goto error;
1597
+ }
1598
+
1599
+ ngx_memcpy(p, tpl.data, tpl.len);
1600
+ p[tpl.len] = '\0';
1601
+
1602
+ tpl.data = p;
1603
+ }
1604
+
1605
+ ngx_memzero(&ccv, sizeof(ngx_http_lua_compile_complex_value_t));
1606
+ ccv.pool = pool;
1607
+ ccv.log = r->connection->log;
1608
+ ccv.value = &tpl;
1609
+ ccv.complex_value = ctpl;
1610
+
1611
+ if (ngx_http_lua_compile_complex_value(&ccv) != NGX_OK) {
1612
+ ngx_pfree(pool, cap);
1613
+ ngx_pfree(pool, ctpl);
1614
+
1615
+ if ((flags & NGX_LUA_RE_COMPILE_ONCE) && tpl.len != 0) {
1616
+ ngx_pfree(pool, tpl.data);
1617
+ }
1618
+
1619
+ if (sd) {
1620
+ ngx_http_lua_regex_free_study_data(pool, sd);
1621
+ }
1622
+
1623
+ ngx_pfree(pool, re_comp.regex);
1624
+
1625
+ lua_pushnil(L);
1626
+ lua_pushnil(L);
1627
+ lua_pushliteral(L, "failed to compile the replacement template");
1628
+ return 3;
1629
+ }
1630
+ }
1631
+
1632
+ if (flags & NGX_LUA_RE_COMPILE_ONCE) {
1633
+
1634
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1635
+ "lua saving compiled sub regex (%d captures) into "
1636
+ "the cache (entries %i)", re_comp.captures,
1637
+ lmcf->regex_cache_entries);
1638
+
1639
+ re = ngx_palloc(pool, sizeof(ngx_http_lua_regex_t));
1640
+ if (re == NULL) {
1641
+ msg = "no memory";
1642
+ goto error;
1643
+ }
1644
+
1645
+ dd("saving regex %p, ncaptures %d, captures %p", re_comp.regex,
1646
+ re_comp.captures, cap);
1647
+
1648
+ re->regex = re_comp.regex;
1649
+ re->regex_sd = sd;
1650
+ re->ncaptures = re_comp.captures;
1651
+ re->captures = cap;
1652
+ re->replace = ctpl;
1653
+
1654
+ lua_pushlightuserdata(L, re); /* table key value */
1655
+ lua_rawset(L, -3); /* table */
1656
+ lua_pop(L, 1);
1657
+
1658
+ if (lmcf) {
1659
+ lmcf->regex_cache_entries++;
1660
+ }
1661
+ }
1662
+
1663
+ exec:
1664
+
1665
+ count = 0;
1666
+ offset = 0;
1667
+ cp_offset = 0;
1668
+
1669
+ if (pcre_fullinfo(re_comp.regex, NULL, PCRE_INFO_NAMECOUNT,
1670
+ &name_count) != 0)
1671
+ {
1672
+ msg = "cannot acquire named subpattern count";
1673
+ goto error;
1674
+ }
1675
+
1676
+ if (name_count > 0) {
1677
+ if (pcre_fullinfo(re_comp.regex, NULL, PCRE_INFO_NAMEENTRYSIZE,
1678
+ &name_entry_size) != 0)
1679
+ {
1680
+ msg = "cannot acquire named subpattern entry size";
1681
+ goto error;
1682
+ }
1683
+
1684
+ if (pcre_fullinfo(re_comp.regex, NULL, PCRE_INFO_NAMETABLE,
1685
+ &name_table) != 0)
1686
+ {
1687
+ msg = "cannot acquire named subpattern table";
1688
+ goto error;
1689
+ }
1690
+ }
1691
+
1692
+ if (flags & NGX_LUA_RE_NO_UTF8_CHECK) {
1693
+ exec_opts = PCRE_NO_UTF8_CHECK;
1694
+
1695
+ } else {
1696
+ exec_opts = 0;
1697
+ }
1698
+
1699
+ for (;;) {
1700
+ if (flags & NGX_LUA_RE_MODE_DFA) {
1701
+
1702
+ #if LUA_HAVE_PCRE_DFA
1703
+
1704
+ int ws[NGX_LUA_RE_DFA_MODE_WORKSPACE_COUNT];
1705
+ rc = ngx_http_lua_regex_dfa_exec(re_comp.regex, sd, &subj,
1706
+ offset, cap, ovecsize, ws,
1707
+ sizeof(ws)/sizeof(ws[0]),
1708
+ exec_opts);
1709
+
1710
+ #else /* LUA_HAVE_PCRE_DFA */
1711
+
1712
+ msg = "at least pcre 6.0 is required for the DFA mode";
1713
+ goto error;
1714
+
1715
+ #endif /* LUA_HAVE_PCRE_DFA */
1716
+
1717
+ } else {
1718
+ rc = ngx_http_lua_regex_exec(re_comp.regex, sd, &subj, offset, cap,
1719
+ ovecsize, exec_opts);
1720
+ }
1721
+
1722
+ if (rc == NGX_REGEX_NO_MATCHED) {
1723
+ break;
1724
+ }
1725
+
1726
+ if (rc < 0) {
1727
+ msg = lua_pushfstring(L, ngx_regex_exec_n " failed: %d",
1728
+ (int) rc);
1729
+ goto error;
1730
+ }
1731
+
1732
+ if (rc == 0) {
1733
+ if (flags & NGX_LUA_RE_MODE_DFA) {
1734
+ rc = 1;
1735
+
1736
+ } else {
1737
+ msg = "capture size too small";
1738
+ goto error;
1739
+ }
1740
+ }
1741
+
1742
+ dd("rc = %d", (int) rc);
1743
+
1744
+ count++;
1745
+
1746
+ if (count == 1) {
1747
+ luaL_buffinit(L, &luabuf);
1748
+ }
1749
+
1750
+ if (func) {
1751
+ lua_pushvalue(L, 3);
1752
+
1753
+ lua_createtable(L, rc - 1 /* narr */, 1 /* nrec */);
1754
+
1755
+ for (i = 0, n = 0; i < rc; i++, n += 2) {
1756
+ dd("capture %d: %d %d", (int) i, cap[n], cap[n + 1]);
1757
+ if (cap[n] < 0) {
1758
+ lua_pushnil(L);
1759
+
1760
+ } else {
1761
+ lua_pushlstring(L, (char *) &subj.data[cap[n]],
1762
+ cap[n + 1] - cap[n]);
1763
+
1764
+ dd("pushing capture %s at %d", lua_tostring(L, -1),
1765
+ (int) i);
1766
+ }
1767
+
1768
+ lua_rawseti(L, -2, (int) i);
1769
+ }
1770
+
1771
+ if (name_count > 0) {
1772
+ ngx_http_lua_re_collect_named_captures(L, lua_gettop(L),
1773
+ name_table,
1774
+ name_count,
1775
+ name_entry_size,
1776
+ flags, &subj);
1777
+ }
1778
+
1779
+ dd("stack size at call: %d", lua_gettop(L));
1780
+
1781
+ lua_call(L, 1 /* nargs */, 1 /* nresults */);
1782
+ type = lua_type(L, -1);
1783
+ switch (type) {
1784
+ case LUA_TNUMBER:
1785
+ case LUA_TSTRING:
1786
+ tpl.data = (u_char *) lua_tolstring(L, -1, &tpl.len);
1787
+ break;
1788
+
1789
+ default:
1790
+ msg = lua_pushfstring(L, "string or number expected to be "
1791
+ "returned by the replace "
1792
+ "function, got %s",
1793
+ lua_typename(L, type));
1794
+ return luaL_argerror(L, 3, msg);
1795
+ }
1796
+
1797
+ lua_insert(L, 1);
1798
+
1799
+ luaL_addlstring(&luabuf, (char *) &subj.data[cp_offset],
1800
+ cap[0] - cp_offset);
1801
+
1802
+ luaL_addlstring(&luabuf, (char *) tpl.data, tpl.len);
1803
+
1804
+ lua_remove(L, 1);
1805
+
1806
+ cp_offset = cap[1];
1807
+ offset = cp_offset;
1808
+ if (offset == cap[0]) {
1809
+ offset++;
1810
+ if (offset > (ssize_t) subj.len) {
1811
+ break;
1812
+ }
1813
+ }
1814
+
1815
+ if (global) {
1816
+ continue;
1817
+ }
1818
+
1819
+ break;
1820
+ }
1821
+
1822
+ rc = ngx_http_lua_complex_value(r, &subj, cp_offset, rc, cap, ctpl,
1823
+ &luabuf);
1824
+
1825
+ if (rc != NGX_OK) {
1826
+ msg = lua_pushfstring(L, "failed to eval the template for "
1827
+ "replacement: \"%s\"", tpl.data);
1828
+ goto error;
1829
+ }
1830
+
1831
+ cp_offset = cap[1];
1832
+ offset = cp_offset;
1833
+ if (offset == cap[0]) {
1834
+ offset++;
1835
+ if (offset > (ssize_t) subj.len) {
1836
+ break;
1837
+ }
1838
+ }
1839
+
1840
+ if (global) {
1841
+ continue;
1842
+ }
1843
+
1844
+ break;
1845
+ }
1846
+
1847
+ if (count == 0) {
1848
+ dd("no match, just the original subject");
1849
+ lua_settop(L, 1);
1850
+
1851
+ } else {
1852
+ if (offset < (int) subj.len) {
1853
+ dd("adding trailer: %s (len %d)", &subj.data[cp_offset],
1854
+ (int) (subj.len - cp_offset));
1855
+
1856
+
1857
+ luaL_addlstring(&luabuf, (char *) &subj.data[cp_offset],
1858
+ subj.len - cp_offset);
1859
+ }
1860
+
1861
+ luaL_pushresult(&luabuf);
1862
+
1863
+ dd("the dst string: %s", lua_tostring(L, -1));
1864
+ }
1865
+
1866
+ if (!(flags & NGX_LUA_RE_COMPILE_ONCE)) {
1867
+ if (sd) {
1868
+ ngx_http_lua_regex_free_study_data(pool, sd);
1869
+ }
1870
+
1871
+ if (re_comp.regex) {
1872
+ ngx_pfree(pool, re_comp.regex);
1873
+ }
1874
+
1875
+ if (ctpl) {
1876
+ ngx_pfree(pool, ctpl);
1877
+ }
1878
+
1879
+ if (cap) {
1880
+ ngx_pfree(pool, cap);
1881
+ }
1882
+ }
1883
+
1884
+ lua_pushinteger(L, count);
1885
+ return 2;
1886
+
1887
+ error:
1888
+
1889
+ if (!(flags & NGX_LUA_RE_COMPILE_ONCE)) {
1890
+ if (sd) {
1891
+ ngx_http_lua_regex_free_study_data(pool, sd);
1892
+ }
1893
+
1894
+ if (re_comp.regex) {
1895
+ ngx_pfree(pool, re_comp.regex);
1896
+ }
1897
+
1898
+ if (ctpl) {
1899
+ ngx_pfree(pool, ctpl);
1900
+ }
1901
+
1902
+ if (cap) {
1903
+ ngx_pfree(pool, cap);
1904
+ }
1905
+ }
1906
+
1907
+ lua_pushnil(L);
1908
+ lua_pushnil(L);
1909
+ lua_pushstring(L, msg);
1910
+ return 3;
1911
+ }
1912
+
1913
+
1914
+ void
1915
+ ngx_http_lua_inject_regex_api(lua_State *L)
1916
+ {
1917
+ /* ngx.re */
1918
+
1919
+ lua_createtable(L, 0, 5 /* nrec */); /* .re */
1920
+
1921
+ lua_pushcfunction(L, ngx_http_lua_ngx_re_find);
1922
+ lua_setfield(L, -2, "find");
1923
+
1924
+ lua_pushcfunction(L, ngx_http_lua_ngx_re_match);
1925
+ lua_setfield(L, -2, "match");
1926
+
1927
+ lua_pushcfunction(L, ngx_http_lua_ngx_re_gmatch);
1928
+ lua_setfield(L, -2, "gmatch");
1929
+
1930
+ lua_pushcfunction(L, ngx_http_lua_ngx_re_sub);
1931
+ lua_setfield(L, -2, "sub");
1932
+
1933
+ lua_pushcfunction(L, ngx_http_lua_ngx_re_gsub);
1934
+ lua_setfield(L, -2, "gsub");
1935
+
1936
+ lua_setfield(L, -2, "re");
1937
+ }
1938
+
1939
+
1940
+ static void
1941
+ ngx_http_lua_regex_free_study_data(ngx_pool_t *pool, pcre_extra *sd)
1942
+ {
1943
+ ngx_pool_t *old_pool;
1944
+
1945
+ old_pool = ngx_http_lua_pcre_malloc_init(pool);
1946
+
1947
+ #if LUA_HAVE_PCRE_JIT
1948
+ pcre_free_study(sd);
1949
+ #else
1950
+ pcre_free(sd);
1951
+ #endif
1952
+
1953
+ ngx_http_lua_pcre_malloc_done(old_pool);
1954
+ }
1955
+
1956
+
1957
+ static ngx_int_t
1958
+ ngx_http_lua_regex_compile(ngx_http_lua_regex_compile_t *rc)
1959
+ {
1960
+ int n, erroff;
1961
+ char *p;
1962
+ const char *errstr;
1963
+ pcre *re;
1964
+ ngx_pool_t *old_pool;
1965
+
1966
+ old_pool = ngx_http_lua_pcre_malloc_init(rc->pool);
1967
+
1968
+ re = pcre_compile((const char *) rc->pattern.data, (int) rc->options,
1969
+ &errstr, &erroff, NULL);
1970
+
1971
+ ngx_http_lua_pcre_malloc_done(old_pool);
1972
+
1973
+ if (re == NULL) {
1974
+ if ((size_t) erroff == rc->pattern.len) {
1975
+ rc->err.len = ngx_snprintf(rc->err.data, rc->err.len,
1976
+ "pcre_compile() failed: %s in \"%V\"",
1977
+ errstr, &rc->pattern)
1978
+ - rc->err.data;
1979
+
1980
+ } else {
1981
+ rc->err.len = ngx_snprintf(rc->err.data, rc->err.len,
1982
+ "pcre_compile() failed: %s in \"%V\" "
1983
+ "at \"%s\"", errstr, &rc->pattern,
1984
+ rc->pattern.data + erroff)
1985
+ - rc->err.data;
1986
+ }
1987
+
1988
+ return NGX_ERROR;
1989
+ }
1990
+
1991
+ rc->regex = re;
1992
+
1993
+ #if 1
1994
+ n = pcre_fullinfo(re, NULL, PCRE_INFO_CAPTURECOUNT, &rc->captures);
1995
+ if (n < 0) {
1996
+ p = "pcre_fullinfo(\"%V\", PCRE_INFO_CAPTURECOUNT) failed: %d";
1997
+ goto failed;
1998
+ }
1999
+ #endif
2000
+
2001
+ return NGX_OK;
2002
+
2003
+ failed:
2004
+
2005
+ rc->err.len = ngx_snprintf(rc->err.data, rc->err.len, p, &rc->pattern, n)
2006
+ - rc->err.data;
2007
+ return NGX_OK;
2008
+ }
2009
+
2010
+
2011
+ static void
2012
+ ngx_http_lua_ngx_re_gmatch_cleanup(void *data)
2013
+ {
2014
+ ngx_http_lua_regex_ctx_t *ctx = data;
2015
+
2016
+ if (ctx) {
2017
+ if (ctx->regex_sd) {
2018
+ ngx_http_lua_regex_free_study_data(ctx->request->pool,
2019
+ ctx->regex_sd);
2020
+ ctx->regex_sd = NULL;
2021
+ }
2022
+
2023
+ if (ctx->cleanup) {
2024
+ *ctx->cleanup = NULL;
2025
+ ctx->cleanup = NULL;
2026
+ }
2027
+
2028
+ ctx->request = NULL;
2029
+ }
2030
+
2031
+ return;
2032
+ }
2033
+
2034
+
2035
+ static int
2036
+ ngx_http_lua_ngx_re_gmatch_gc(lua_State *L)
2037
+ {
2038
+ ngx_http_lua_regex_ctx_t *ctx;
2039
+
2040
+ ctx = lua_touserdata(L, 1);
2041
+
2042
+ if (ctx && ctx->cleanup) {
2043
+ ngx_http_lua_ngx_re_gmatch_cleanup(ctx);
2044
+ }
2045
+
2046
+ return 0;
2047
+ }
2048
+
2049
+
2050
+ static void
2051
+ ngx_http_lua_re_collect_named_captures(lua_State *L, int res_tb_idx,
2052
+ u_char *name_table, int name_count, int name_entry_size, unsigned flags,
2053
+ ngx_str_t *subj)
2054
+ {
2055
+ int i, n;
2056
+ size_t len;
2057
+ u_char *name_entry;
2058
+ char *name;
2059
+
2060
+ for (i = 0; i < name_count; i++) {
2061
+ dd("top: %d", lua_gettop(L));
2062
+
2063
+ name_entry = &name_table[i * name_entry_size];
2064
+ n = (name_entry[0] << 8) | name_entry[1];
2065
+ name = (char *) &name_entry[2];
2066
+
2067
+ lua_rawgeti(L, -1, n);
2068
+ if (lua_isnil(L, -1)) {
2069
+ lua_pop(L, 1);
2070
+ continue;
2071
+ }
2072
+
2073
+ if (flags & NGX_LUA_RE_MODE_DUPNAMES) {
2074
+
2075
+ lua_getfield(L, -2, name); /* big_tb cap small_tb */
2076
+
2077
+ if (lua_isnil(L, -1)) {
2078
+ lua_pop(L, 1);
2079
+
2080
+ /* assuming named submatches are usually unique */
2081
+ lua_createtable(L, 1 /* narr */, 0 /* nrec */);
2082
+ lua_pushstring(L, name);
2083
+ lua_pushvalue(L, -2); /* big_tb cap small_tb key small_tb */
2084
+ lua_rawset(L, res_tb_idx); /* big_tb cap small_tb */
2085
+ len = 0;
2086
+
2087
+ } else {
2088
+ len = lua_objlen(L, -1);
2089
+ }
2090
+
2091
+ lua_pushvalue(L, -2); /* big_tb cap small_tb cap */
2092
+ lua_rawseti(L, -2, (int) len + 1); /* big_tb cap small_tb */
2093
+ lua_pop(L, 2);
2094
+
2095
+ } else {
2096
+ lua_pushstring(L, name); /* big_tb cap key */
2097
+ lua_pushvalue(L, -2); /* big_tb cap key cap */
2098
+ lua_rawset(L, res_tb_idx); /* big_tb cap */
2099
+ lua_pop(L, 1);
2100
+ }
2101
+
2102
+ dd("top 2: %d", lua_gettop(L));
2103
+ }
2104
+ }
2105
+
2106
+
2107
+ #ifndef NGX_LUA_NO_FFI_API
2108
+ ngx_http_lua_regex_t *
2109
+ ngx_http_lua_ffi_compile_regex(const unsigned char *pat, size_t pat_len,
2110
+ int flags, int pcre_opts, u_char *errstr,
2111
+ size_t errstr_size)
2112
+ {
2113
+ int *cap = NULL, ovecsize;
2114
+ u_char *p;
2115
+ ngx_int_t rc;
2116
+ const char *msg;
2117
+ ngx_pool_t *pool, *old_pool;
2118
+ pcre_extra *sd = NULL;
2119
+ ngx_http_lua_regex_t *re;
2120
+
2121
+ ngx_http_lua_main_conf_t *lmcf;
2122
+ ngx_http_lua_regex_compile_t re_comp;
2123
+
2124
+ pool = ngx_create_pool(512, ngx_cycle->log);
2125
+ if (pool == NULL) {
2126
+ msg = "no memory";
2127
+ goto error;
2128
+ }
2129
+
2130
+ re = ngx_palloc(pool, sizeof(ngx_http_lua_regex_t));
2131
+ if (re == NULL) {
2132
+ ngx_destroy_pool(pool);
2133
+ pool = NULL;
2134
+ msg = "no memory";
2135
+ goto error;
2136
+ }
2137
+
2138
+ re->pool = pool;
2139
+
2140
+ re_comp.options = pcre_opts;
2141
+ re_comp.pattern.data = (u_char *) pat;
2142
+ re_comp.pattern.len = pat_len;
2143
+ re_comp.err.len = errstr_size - 1;
2144
+ re_comp.err.data = errstr;
2145
+ re_comp.pool = pool;
2146
+
2147
+ old_pool = ngx_http_lua_pcre_malloc_init(pool);
2148
+ rc = ngx_http_lua_regex_compile(&re_comp);
2149
+ ngx_http_lua_pcre_malloc_done(old_pool);
2150
+
2151
+ if (rc != NGX_OK) {
2152
+ re_comp.err.data[re_comp.err.len] = '\0';
2153
+ msg = (char *) re_comp.err.data;
2154
+ goto error;
2155
+ }
2156
+
2157
+ #if (LUA_HAVE_PCRE_JIT)
2158
+
2159
+ if (flags & NGX_LUA_RE_MODE_JIT) {
2160
+
2161
+ old_pool = ngx_http_lua_pcre_malloc_init(pool);
2162
+ sd = pcre_study(re_comp.regex, PCRE_STUDY_JIT_COMPILE, &msg);
2163
+ ngx_http_lua_pcre_malloc_done(old_pool);
2164
+
2165
+ # if (NGX_DEBUG)
2166
+ if (msg != NULL) {
2167
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
2168
+ "pcre study failed with PCRE_STUDY_JIT_COMPILE: "
2169
+ "%s (%p)", msg, sd);
2170
+ }
2171
+
2172
+ if (sd != NULL) {
2173
+ int jitted;
2174
+
2175
+ old_pool = ngx_http_lua_pcre_malloc_init(pool);
2176
+
2177
+ pcre_fullinfo(re_comp.regex, sd, PCRE_INFO_JIT, &jitted);
2178
+
2179
+ ngx_http_lua_pcre_malloc_done(old_pool);
2180
+
2181
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
2182
+ "pcre JIT compiling result: %d", jitted);
2183
+ }
2184
+ # endif /* !(NGX_DEBUG) */
2185
+
2186
+ } else {
2187
+ old_pool = ngx_http_lua_pcre_malloc_init(pool);
2188
+ sd = pcre_study(re_comp.regex, 0, &msg);
2189
+ ngx_http_lua_pcre_malloc_done(old_pool);
2190
+ }
2191
+
2192
+ #endif /* LUA_HAVE_PCRE_JIT */
2193
+
2194
+ lmcf = ngx_http_cycle_get_module_main_conf(ngx_cycle,
2195
+ ngx_http_lua_module);
2196
+
2197
+ if (sd && lmcf && lmcf->regex_match_limit > 0) {
2198
+ sd->flags |= PCRE_EXTRA_MATCH_LIMIT;
2199
+ sd->match_limit = lmcf->regex_match_limit;
2200
+ }
2201
+
2202
+ if (flags & NGX_LUA_RE_MODE_DFA) {
2203
+ ovecsize = 2;
2204
+
2205
+ } else {
2206
+ ovecsize = (re_comp.captures + 1) * 3;
2207
+ }
2208
+
2209
+ dd("allocating cap with size: %d", (int) ovecsize);
2210
+
2211
+ cap = ngx_palloc(pool, ovecsize * sizeof(int));
2212
+ if (cap == NULL) {
2213
+ msg = "no memory";
2214
+ goto error;
2215
+ }
2216
+
2217
+ if (pcre_fullinfo(re_comp.regex, NULL, PCRE_INFO_NAMECOUNT,
2218
+ &re->name_count) != 0)
2219
+ {
2220
+ msg = "cannot acquire named subpattern count";
2221
+ goto error;
2222
+ }
2223
+
2224
+ if (re->name_count > 0) {
2225
+ if (pcre_fullinfo(re_comp.regex, NULL, PCRE_INFO_NAMEENTRYSIZE,
2226
+ &re->name_entry_size) != 0)
2227
+ {
2228
+ msg = "cannot acquire named subpattern entry size";
2229
+ goto error;
2230
+ }
2231
+
2232
+ if (pcre_fullinfo(re_comp.regex, NULL, PCRE_INFO_NAMETABLE,
2233
+ &re->name_table) != 0)
2234
+ {
2235
+ msg = "cannot acquire named subpattern table";
2236
+ goto error;
2237
+ }
2238
+ }
2239
+
2240
+ re->regex = re_comp.regex;
2241
+ re->regex_sd = sd;
2242
+ re->ncaptures = re_comp.captures;
2243
+ re->captures = cap;
2244
+ re->replace = NULL;
2245
+
2246
+ /* only for (stap) debugging, the pointer might be invalid when the
2247
+ * string is collected later on.... */
2248
+ re->pattern = pat;
2249
+
2250
+ return re;
2251
+
2252
+ error:
2253
+
2254
+ p = ngx_snprintf(errstr, errstr_size - 1, "%s", msg);
2255
+ *p = '\0';
2256
+
2257
+ if (sd) {
2258
+ ngx_http_lua_regex_free_study_data(pool, sd);
2259
+ }
2260
+
2261
+ if (pool) {
2262
+ ngx_destroy_pool(pool);
2263
+ }
2264
+
2265
+ return NULL;
2266
+ }
2267
+
2268
+
2269
+ int
2270
+ ngx_http_lua_ffi_exec_regex(ngx_http_lua_regex_t *re, int flags,
2271
+ const u_char *s, size_t len, int pos)
2272
+ {
2273
+ int rc, ovecsize, exec_opts, *cap;
2274
+ ngx_str_t subj;
2275
+ pcre_extra *sd;
2276
+
2277
+ cap = re->captures;
2278
+ sd = re->regex_sd;
2279
+
2280
+ if (flags & NGX_LUA_RE_MODE_DFA) {
2281
+ ovecsize = 2;
2282
+
2283
+ } else {
2284
+ ovecsize = (re->ncaptures + 1) * 3;
2285
+ }
2286
+
2287
+ if (flags & NGX_LUA_RE_NO_UTF8_CHECK) {
2288
+ exec_opts = PCRE_NO_UTF8_CHECK;
2289
+
2290
+ } else {
2291
+ exec_opts = 0;
2292
+ }
2293
+
2294
+ subj.data = (u_char *) s;
2295
+ subj.len = len;
2296
+
2297
+ if (flags & NGX_LUA_RE_MODE_DFA) {
2298
+
2299
+ #if LUA_HAVE_PCRE_DFA
2300
+
2301
+ int ws[NGX_LUA_RE_DFA_MODE_WORKSPACE_COUNT];
2302
+ rc = ngx_http_lua_regex_dfa_exec(re->regex, sd, &subj,
2303
+ (int) pos, cap, ovecsize, ws,
2304
+ sizeof(ws)/sizeof(ws[0]), exec_opts);
2305
+
2306
+ #else /* LUA_HAVE_PCRE_DFA */
2307
+
2308
+ return PCRE_ERROR_INTERNAL;
2309
+
2310
+ #endif /* LUA_HAVE_PCRE_DFA */
2311
+
2312
+ } else {
2313
+ rc = ngx_http_lua_regex_exec(re->regex, sd, &subj, (int) pos, cap,
2314
+ ovecsize, exec_opts);
2315
+ }
2316
+
2317
+ return rc;
2318
+ }
2319
+
2320
+
2321
+ void
2322
+ ngx_http_lua_ffi_destroy_regex(ngx_http_lua_regex_t *re)
2323
+ {
2324
+ ngx_pool_t *old_pool;
2325
+
2326
+ dd("destroy regex called");
2327
+
2328
+ if (re == NULL || re->pool == NULL) {
2329
+ return;
2330
+ }
2331
+
2332
+ if (re->regex_sd) {
2333
+ old_pool = ngx_http_lua_pcre_malloc_init(re->pool);
2334
+ #if LUA_HAVE_PCRE_JIT
2335
+ pcre_free_study(re->regex_sd);
2336
+ #else
2337
+ pcre_free(re->regex_sd);
2338
+ #endif
2339
+ ngx_http_lua_pcre_malloc_done(old_pool);
2340
+ re->regex_sd = NULL;
2341
+ }
2342
+
2343
+ ngx_destroy_pool(re->pool);
2344
+ }
2345
+
2346
+
2347
+ int
2348
+ ngx_http_lua_ffi_compile_replace_template(ngx_http_lua_regex_t *re,
2349
+ const u_char *replace_data, size_t replace_len)
2350
+ {
2351
+ ngx_int_t rc;
2352
+ ngx_str_t tpl;
2353
+ ngx_http_lua_complex_value_t *ctpl;
2354
+ ngx_http_lua_compile_complex_value_t ccv;
2355
+
2356
+ ctpl = ngx_palloc(re->pool, sizeof(ngx_http_lua_complex_value_t));
2357
+ if (ctpl == NULL) {
2358
+ return NGX_ERROR;
2359
+ }
2360
+
2361
+ if (replace_len != 0) {
2362
+ /* copy the string buffer pointed to by tpl.data from Lua VM */
2363
+ tpl.data = ngx_palloc(re->pool, replace_len + 1);
2364
+ if (tpl.data == NULL) {
2365
+ return NGX_ERROR;
2366
+ }
2367
+
2368
+ ngx_memcpy(tpl.data, replace_data, replace_len);
2369
+ tpl.data[replace_len] = '\0';
2370
+
2371
+ } else {
2372
+ tpl.data = (u_char *) replace_data;
2373
+ }
2374
+
2375
+ tpl.len = replace_len;
2376
+
2377
+ ngx_memzero(&ccv, sizeof(ngx_http_lua_compile_complex_value_t));
2378
+ ccv.pool = re->pool;
2379
+ ccv.log = ngx_cycle->log;
2380
+ ccv.value = &tpl;
2381
+ ccv.complex_value = ctpl;
2382
+
2383
+ rc = ngx_http_lua_compile_complex_value(&ccv);
2384
+
2385
+ re->replace = ctpl;
2386
+
2387
+ return rc;
2388
+ }
2389
+
2390
+
2391
+ ngx_http_lua_script_engine_t *
2392
+ ngx_http_lua_ffi_create_script_engine(void)
2393
+ {
2394
+ return ngx_calloc(sizeof(ngx_http_lua_script_engine_t), ngx_cycle->log);
2395
+ }
2396
+
2397
+
2398
+ void
2399
+ ngx_http_lua_ffi_init_script_engine(ngx_http_lua_script_engine_t *e,
2400
+ const unsigned char *subj, ngx_http_lua_regex_t *compiled, int count)
2401
+ {
2402
+ e->log = ngx_cycle->log;
2403
+ e->ncaptures = count * 2;
2404
+ e->captures = compiled->captures;
2405
+ e->captures_data = (u_char *) subj;
2406
+ }
2407
+
2408
+
2409
+ void
2410
+ ngx_http_lua_ffi_destroy_script_engine(ngx_http_lua_script_engine_t *e)
2411
+ {
2412
+ ngx_free(e);
2413
+ }
2414
+
2415
+
2416
+ size_t
2417
+ ngx_http_lua_ffi_script_eval_len(ngx_http_lua_script_engine_t *e,
2418
+ ngx_http_lua_complex_value_t *val)
2419
+ {
2420
+ size_t len;
2421
+
2422
+ ngx_http_lua_script_len_code_pt lcode;
2423
+
2424
+ e->ip = val->lengths;
2425
+ len = 0;
2426
+
2427
+ while (*(uintptr_t *) e->ip) {
2428
+ lcode = *(ngx_http_lua_script_len_code_pt *) e->ip;
2429
+ len += lcode(e);
2430
+ }
2431
+
2432
+ return len;
2433
+ }
2434
+
2435
+
2436
+ void
2437
+ ngx_http_lua_ffi_script_eval_data(ngx_http_lua_script_engine_t *e,
2438
+ ngx_http_lua_complex_value_t *val, u_char *dst)
2439
+ {
2440
+ ngx_http_lua_script_code_pt code;
2441
+
2442
+ e->ip = val->values;
2443
+ e->pos = dst;
2444
+
2445
+ while (*(uintptr_t *) e->ip) {
2446
+ code = *(ngx_http_lua_script_code_pt *) e->ip;
2447
+ code(e);
2448
+ }
2449
+ }
2450
+
2451
+
2452
+ uint32_t
2453
+ ngx_http_lua_ffi_max_regex_cache_size(void)
2454
+ {
2455
+ ngx_http_lua_main_conf_t *lmcf;
2456
+ lmcf = ngx_http_cycle_get_module_main_conf(ngx_cycle,
2457
+ ngx_http_lua_module);
2458
+ if (lmcf == NULL) {
2459
+ return 0;
2460
+ }
2461
+ return (uint32_t) lmcf->regex_cache_max_entries;
2462
+ }
2463
+ #endif /* NGX_LUA_NO_FFI_API */
2464
+
2465
+
2466
+ #endif /* NGX_PCRE */
2467
+
2468
+ /* vi:set ft=c ts=4 sw=4 et fdm=marker: */