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,3972 @@
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 "nginx.h"
15
+ #include "ngx_http_lua_directive.h"
16
+ #include "ngx_http_lua_util.h"
17
+ #include "ngx_http_lua_exception.h"
18
+ #include "ngx_http_lua_pcrefix.h"
19
+ #include "ngx_http_lua_regex.h"
20
+ #include "ngx_http_lua_args.h"
21
+ #include "ngx_http_lua_uri.h"
22
+ #include "ngx_http_lua_req_body.h"
23
+ #include "ngx_http_lua_headers.h"
24
+ #include "ngx_http_lua_output.h"
25
+ #include "ngx_http_lua_time.h"
26
+ #include "ngx_http_lua_control.h"
27
+ #include "ngx_http_lua_ndk.h"
28
+ #include "ngx_http_lua_subrequest.h"
29
+ #include "ngx_http_lua_log.h"
30
+ #include "ngx_http_lua_variable.h"
31
+ #include "ngx_http_lua_string.h"
32
+ #include "ngx_http_lua_misc.h"
33
+ #include "ngx_http_lua_consts.h"
34
+ #include "ngx_http_lua_req_method.h"
35
+ #include "ngx_http_lua_shdict.h"
36
+ #include "ngx_http_lua_coroutine.h"
37
+ #include "ngx_http_lua_socket_tcp.h"
38
+ #include "ngx_http_lua_socket_udp.h"
39
+ #include "ngx_http_lua_sleep.h"
40
+ #include "ngx_http_lua_setby.h"
41
+ #include "ngx_http_lua_headerfilterby.h"
42
+ #include "ngx_http_lua_bodyfilterby.h"
43
+ #include "ngx_http_lua_logby.h"
44
+ #include "ngx_http_lua_phase.h"
45
+ #include "ngx_http_lua_probe.h"
46
+ #include "ngx_http_lua_uthread.h"
47
+ #include "ngx_http_lua_contentby.h"
48
+ #include "ngx_http_lua_timer.h"
49
+ #include "ngx_http_lua_config.h"
50
+ #include "ngx_http_lua_worker.h"
51
+ #include "ngx_http_lua_socket_tcp.h"
52
+
53
+
54
+ #if 1
55
+ #undef ngx_http_lua_probe_info
56
+ #define ngx_http_lua_probe_info(msg)
57
+ #endif
58
+
59
+
60
+ #ifndef NGX_HTTP_LUA_BT_DEPTH
61
+ #define NGX_HTTP_LUA_BT_DEPTH 22
62
+ #endif
63
+
64
+
65
+ #ifndef NGX_HTTP_LUA_BT_MAX_COROS
66
+ #define NGX_HTTP_LUA_BT_MAX_COROS 5
67
+ #endif
68
+
69
+
70
+ char ngx_http_lua_code_cache_key;
71
+ char ngx_http_lua_regex_cache_key;
72
+ char ngx_http_lua_socket_pool_key;
73
+ char ngx_http_lua_coroutines_key;
74
+ char ngx_http_lua_headers_metatable_key;
75
+
76
+
77
+ ngx_uint_t ngx_http_lua_location_hash = 0;
78
+ ngx_uint_t ngx_http_lua_content_length_hash = 0;
79
+
80
+
81
+ static ngx_int_t ngx_http_lua_send_http10_headers(ngx_http_request_t *r,
82
+ ngx_http_lua_ctx_t *ctx);
83
+ static void ngx_http_lua_init_registry(lua_State *L, ngx_log_t *log);
84
+ static void ngx_http_lua_init_globals(lua_State *L, ngx_cycle_t *cycle,
85
+ ngx_http_lua_main_conf_t *lmcf, ngx_log_t *log);
86
+ static void ngx_http_lua_set_path(ngx_cycle_t *cycle, lua_State *L, int tab_idx,
87
+ const char *fieldname, const char *path, const char *default_path,
88
+ ngx_log_t *log);
89
+ static ngx_int_t ngx_http_lua_handle_exec(lua_State *L, ngx_http_request_t *r,
90
+ ngx_http_lua_ctx_t *ctx);
91
+ static ngx_int_t ngx_http_lua_handle_exit(lua_State *L, ngx_http_request_t *r,
92
+ ngx_http_lua_ctx_t *ctx);
93
+ static ngx_int_t ngx_http_lua_handle_rewrite_jump(lua_State *L,
94
+ ngx_http_request_t *r, ngx_http_lua_ctx_t *ctx);
95
+ static int ngx_http_lua_thread_traceback(lua_State *L, lua_State *co,
96
+ ngx_http_lua_co_ctx_t *coctx);
97
+ static void ngx_http_lua_inject_ngx_api(lua_State *L,
98
+ ngx_http_lua_main_conf_t *lmcf, ngx_log_t *log);
99
+ static void ngx_http_lua_inject_arg_api(lua_State *L);
100
+ static int ngx_http_lua_param_get(lua_State *L);
101
+ static int ngx_http_lua_param_set(lua_State *L);
102
+ static ngx_int_t ngx_http_lua_output_filter(ngx_http_request_t *r,
103
+ ngx_chain_t *in);
104
+ static ngx_int_t ngx_http_lua_send_special(ngx_http_request_t *r,
105
+ ngx_uint_t flags);
106
+ static void ngx_http_lua_finalize_threads(ngx_http_request_t *r,
107
+ ngx_http_lua_ctx_t *ctx, lua_State *L);
108
+ static ngx_int_t ngx_http_lua_post_zombie_thread(ngx_http_request_t *r,
109
+ ngx_http_lua_co_ctx_t *parent, ngx_http_lua_co_ctx_t *thread);
110
+ static void ngx_http_lua_cleanup_zombie_child_uthreads(ngx_http_request_t *r,
111
+ lua_State *L, ngx_http_lua_ctx_t *ctx, ngx_http_lua_co_ctx_t *coctx);
112
+ static ngx_int_t ngx_http_lua_on_abort_resume(ngx_http_request_t *r);
113
+ static void ngx_http_lua_close_fake_request(ngx_http_request_t *r);
114
+ static void ngx_http_lua_free_fake_request(ngx_http_request_t *r);
115
+ static ngx_int_t ngx_http_lua_flush_pending_output(ngx_http_request_t *r,
116
+ ngx_http_lua_ctx_t *ctx);
117
+ static ngx_int_t
118
+ ngx_http_lua_process_flushing_coroutines(ngx_http_request_t *r,
119
+ ngx_http_lua_ctx_t *ctx);
120
+ static lua_State * ngx_http_lua_new_state(lua_State *parent_vm,
121
+ ngx_cycle_t *cycle, ngx_http_lua_main_conf_t *lmcf, ngx_log_t *log);
122
+ static int ngx_http_lua_get_raw_phase_context(lua_State *L);
123
+
124
+
125
+ #ifndef LUA_PATH_SEP
126
+ #define LUA_PATH_SEP ";"
127
+ #endif
128
+
129
+ #define AUX_MARK "\1"
130
+
131
+
132
+ static void
133
+ ngx_http_lua_set_path(ngx_cycle_t *cycle, lua_State *L, int tab_idx,
134
+ const char *fieldname, const char *path, const char *default_path,
135
+ ngx_log_t *log)
136
+ {
137
+ const char *tmp_path;
138
+ const char *prefix;
139
+
140
+ /* XXX here we use some hack to simplify string manipulation */
141
+ tmp_path = luaL_gsub(L, path, LUA_PATH_SEP LUA_PATH_SEP,
142
+ LUA_PATH_SEP AUX_MARK LUA_PATH_SEP);
143
+
144
+ lua_pushlstring(L, (char *) cycle->prefix.data, cycle->prefix.len);
145
+ prefix = lua_tostring(L, -1);
146
+ tmp_path = luaL_gsub(L, tmp_path, "$prefix", prefix);
147
+ tmp_path = luaL_gsub(L, tmp_path, "${prefix}", prefix);
148
+ lua_pop(L, 3);
149
+
150
+ dd("tmp_path path: %s", tmp_path);
151
+
152
+ #if (NGX_DEBUG)
153
+ tmp_path =
154
+ #else
155
+ (void)
156
+ #endif
157
+ luaL_gsub(L, tmp_path, AUX_MARK, default_path);
158
+
159
+ #if (NGX_DEBUG)
160
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, log, 0,
161
+ "lua setting lua package.%s to \"%s\"", fieldname, tmp_path);
162
+ #endif
163
+
164
+ lua_remove(L, -2);
165
+
166
+ /* fix negative index as there's new data on stack */
167
+ tab_idx = (tab_idx < 0) ? (tab_idx - 1) : tab_idx;
168
+ lua_setfield(L, tab_idx, fieldname);
169
+ }
170
+
171
+
172
+ /**
173
+ * Create new table and set _G field to itself.
174
+ *
175
+ * After:
176
+ * | new table | <- top
177
+ * | ... |
178
+ * */
179
+ void
180
+ ngx_http_lua_create_new_globals_table(lua_State *L, int narr, int nrec)
181
+ {
182
+ lua_createtable(L, narr, nrec + 1);
183
+ lua_pushvalue(L, -1);
184
+ lua_setfield(L, -2, "_G");
185
+ }
186
+
187
+
188
+ static lua_State *
189
+ ngx_http_lua_new_state(lua_State *parent_vm, ngx_cycle_t *cycle,
190
+ ngx_http_lua_main_conf_t *lmcf, ngx_log_t *log)
191
+ {
192
+ lua_State *L;
193
+ const char *old_path;
194
+ const char *new_path;
195
+ size_t old_path_len;
196
+ const char *old_cpath;
197
+ const char *new_cpath;
198
+ size_t old_cpath_len;
199
+
200
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, log, 0, "lua creating new vm state");
201
+
202
+ L = luaL_newstate();
203
+ if (L == NULL) {
204
+ return NULL;
205
+ }
206
+
207
+ luaL_openlibs(L);
208
+
209
+ lua_getglobal(L, "package");
210
+
211
+ if (!lua_istable(L, -1)) {
212
+ ngx_log_error(NGX_LOG_EMERG, log, 0,
213
+ "the \"package\" table does not exist");
214
+ return NULL;
215
+ }
216
+
217
+ if (parent_vm) {
218
+ lua_getglobal(parent_vm, "package");
219
+ lua_getfield(parent_vm, -1, "path");
220
+ old_path = lua_tolstring(parent_vm, -1, &old_path_len);
221
+ lua_pop(parent_vm, 1);
222
+
223
+ lua_pushlstring(L, old_path, old_path_len);
224
+ lua_setfield(L, -2, "path");
225
+
226
+ lua_getfield(parent_vm, -1, "cpath");
227
+ old_path = lua_tolstring(parent_vm, -1, &old_path_len);
228
+ lua_pop(parent_vm, 2);
229
+
230
+ lua_pushlstring(L, old_path, old_path_len);
231
+ lua_setfield(L, -2, "cpath");
232
+
233
+ } else {
234
+ #ifdef LUA_DEFAULT_PATH
235
+ # define LUA_DEFAULT_PATH_LEN (sizeof(LUA_DEFAULT_PATH) - 1)
236
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0,
237
+ "lua prepending default package.path with %s",
238
+ LUA_DEFAULT_PATH);
239
+
240
+ lua_pushliteral(L, LUA_DEFAULT_PATH ";"); /* package default */
241
+ lua_getfield(L, -2, "path"); /* package default old */
242
+ old_path = lua_tolstring(L, -1, &old_path_len);
243
+ lua_concat(L, 2); /* package new */
244
+ lua_setfield(L, -2, "path"); /* package */
245
+ #endif
246
+
247
+ #ifdef LUA_DEFAULT_CPATH
248
+ # define LUA_DEFAULT_CPATH_LEN (sizeof(LUA_DEFAULT_CPATH) - 1)
249
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0,
250
+ "lua prepending default package.cpath with %s",
251
+ LUA_DEFAULT_CPATH);
252
+
253
+ lua_pushliteral(L, LUA_DEFAULT_CPATH ";"); /* package default */
254
+ lua_getfield(L, -2, "cpath"); /* package default old */
255
+ old_cpath = lua_tolstring(L, -1, &old_cpath_len);
256
+ lua_concat(L, 2); /* package new */
257
+ lua_setfield(L, -2, "cpath"); /* package */
258
+ #endif
259
+
260
+ if (lmcf->lua_path.len != 0) {
261
+ lua_getfield(L, -1, "path"); /* get original package.path */
262
+ old_path = lua_tolstring(L, -1, &old_path_len);
263
+
264
+ dd("old path: %s", old_path);
265
+
266
+ lua_pushlstring(L, (char *) lmcf->lua_path.data,
267
+ lmcf->lua_path.len);
268
+ new_path = lua_tostring(L, -1);
269
+
270
+ ngx_http_lua_set_path(cycle, L, -3, "path", new_path, old_path,
271
+ log);
272
+
273
+ lua_pop(L, 2);
274
+ }
275
+
276
+ if (lmcf->lua_cpath.len != 0) {
277
+ lua_getfield(L, -1, "cpath"); /* get original package.cpath */
278
+ old_cpath = lua_tolstring(L, -1, &old_cpath_len);
279
+
280
+ dd("old cpath: %s", old_cpath);
281
+
282
+ lua_pushlstring(L, (char *) lmcf->lua_cpath.data,
283
+ lmcf->lua_cpath.len);
284
+ new_cpath = lua_tostring(L, -1);
285
+
286
+ ngx_http_lua_set_path(cycle, L, -3, "cpath", new_cpath, old_cpath,
287
+ log);
288
+
289
+
290
+ lua_pop(L, 2);
291
+ }
292
+ }
293
+
294
+ lua_pop(L, 1); /* remove the "package" table */
295
+
296
+ ngx_http_lua_init_registry(L, log);
297
+ ngx_http_lua_init_globals(L, cycle, lmcf, log);
298
+
299
+ return L;
300
+ }
301
+
302
+
303
+ lua_State *
304
+ ngx_http_lua_new_thread(ngx_http_request_t *r, lua_State *L, int *ref)
305
+ {
306
+ int base;
307
+ lua_State *co;
308
+
309
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
310
+ "lua creating new thread");
311
+
312
+ base = lua_gettop(L);
313
+
314
+ lua_pushlightuserdata(L, &ngx_http_lua_coroutines_key);
315
+ lua_rawget(L, LUA_REGISTRYINDEX);
316
+
317
+ co = lua_newthread(L);
318
+
319
+ /* {{{ inherit coroutine's globals to main thread's globals table
320
+ * for print() function will try to find tostring() in current
321
+ * globals table.
322
+ */
323
+ /* new globals table for coroutine */
324
+ ngx_http_lua_create_new_globals_table(co, 0, 0);
325
+
326
+ lua_createtable(co, 0, 1);
327
+ ngx_http_lua_get_globals_table(co);
328
+ lua_setfield(co, -2, "__index");
329
+ lua_setmetatable(co, -2);
330
+
331
+ ngx_http_lua_set_globals_table(co);
332
+ /* }}} */
333
+
334
+ *ref = luaL_ref(L, -2);
335
+
336
+ if (*ref == LUA_NOREF) {
337
+ lua_settop(L, base); /* restore main thread stack */
338
+ return NULL;
339
+ }
340
+
341
+ lua_settop(L, base);
342
+ return co;
343
+ }
344
+
345
+
346
+ void
347
+ ngx_http_lua_del_thread(ngx_http_request_t *r, lua_State *L,
348
+ ngx_http_lua_ctx_t *ctx, ngx_http_lua_co_ctx_t *coctx)
349
+ {
350
+ if (coctx->co_ref == LUA_NOREF) {
351
+ return;
352
+ }
353
+
354
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
355
+ "lua deleting light thread");
356
+
357
+ lua_pushlightuserdata(L, &ngx_http_lua_coroutines_key);
358
+ lua_rawget(L, LUA_REGISTRYINDEX);
359
+
360
+ ngx_http_lua_probe_thread_delete(r, coctx->co, ctx);
361
+
362
+ luaL_unref(L, -1, coctx->co_ref);
363
+ coctx->co_ref = LUA_NOREF;
364
+ coctx->co_status = NGX_HTTP_LUA_CO_DEAD;
365
+
366
+ lua_pop(L, 1);
367
+ }
368
+
369
+
370
+ u_char *
371
+ ngx_http_lua_rebase_path(ngx_pool_t *pool, u_char *src, size_t len)
372
+ {
373
+ u_char *p, *dst;
374
+
375
+ if (len == 0) {
376
+ return NULL;
377
+ }
378
+
379
+ if (src[0] == '/') {
380
+ /* being an absolute path already */
381
+ dst = ngx_palloc(pool, len + 1);
382
+ if (dst == NULL) {
383
+ return NULL;
384
+ }
385
+
386
+ p = ngx_copy(dst, src, len);
387
+
388
+ *p = '\0';
389
+
390
+ return dst;
391
+ }
392
+
393
+ dst = ngx_palloc(pool, ngx_cycle->prefix.len + len + 1);
394
+ if (dst == NULL) {
395
+ return NULL;
396
+ }
397
+
398
+ p = ngx_copy(dst, ngx_cycle->prefix.data, ngx_cycle->prefix.len);
399
+ p = ngx_copy(p, src, len);
400
+
401
+ *p = '\0';
402
+
403
+ return dst;
404
+ }
405
+
406
+
407
+ ngx_int_t
408
+ ngx_http_lua_send_header_if_needed(ngx_http_request_t *r,
409
+ ngx_http_lua_ctx_t *ctx)
410
+ {
411
+ ngx_int_t rc;
412
+
413
+ if (!r->header_sent) {
414
+ if (r->headers_out.status == 0) {
415
+ r->headers_out.status = NGX_HTTP_OK;
416
+ }
417
+
418
+ if (!ctx->headers_set && ngx_http_lua_set_content_type(r) != NGX_OK) {
419
+ return NGX_ERROR;
420
+ }
421
+
422
+ if (!ctx->headers_set) {
423
+ ngx_http_clear_content_length(r);
424
+ ngx_http_clear_accept_ranges(r);
425
+ }
426
+
427
+ if (!ctx->buffering) {
428
+ dd("sending headers");
429
+ rc = ngx_http_send_header(r);
430
+ return rc;
431
+ }
432
+ }
433
+
434
+ return NGX_OK;
435
+ }
436
+
437
+
438
+ ngx_int_t
439
+ ngx_http_lua_send_chain_link(ngx_http_request_t *r, ngx_http_lua_ctx_t *ctx,
440
+ ngx_chain_t *in)
441
+ {
442
+ ngx_int_t rc;
443
+ ngx_chain_t *cl;
444
+ ngx_chain_t **ll;
445
+ ngx_http_lua_loc_conf_t *llcf;
446
+
447
+ #if 1
448
+ if (ctx->acquired_raw_req_socket || ctx->eof) {
449
+ dd("ctx->eof already set or raw req socket already acquired");
450
+ return NGX_OK;
451
+ }
452
+ #endif
453
+
454
+ if ((r->method & NGX_HTTP_HEAD) && !r->header_only) {
455
+ r->header_only = 1;
456
+ }
457
+
458
+ llcf = ngx_http_get_module_loc_conf(r, ngx_http_lua_module);
459
+
460
+ if (llcf->http10_buffering
461
+ && !ctx->buffering
462
+ && !r->header_sent
463
+ && r->http_version < NGX_HTTP_VERSION_11
464
+ && r->headers_out.content_length_n < 0)
465
+ {
466
+ ctx->buffering = 1;
467
+ }
468
+
469
+ rc = ngx_http_lua_send_header_if_needed(r, ctx);
470
+
471
+ if (rc == NGX_ERROR || rc > NGX_OK) {
472
+ return rc;
473
+ }
474
+
475
+ if (r->header_only) {
476
+ ctx->eof = 1;
477
+
478
+ if (ctx->buffering) {
479
+ return ngx_http_lua_send_http10_headers(r, ctx);
480
+ }
481
+
482
+ return rc;
483
+ }
484
+
485
+ if (in == NULL) {
486
+ if (ctx->buffering) {
487
+ rc = ngx_http_lua_send_http10_headers(r, ctx);
488
+ if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE) {
489
+ return rc;
490
+ }
491
+
492
+ if (ctx->out) {
493
+
494
+ rc = ngx_http_lua_output_filter(r, ctx->out);
495
+
496
+ if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE) {
497
+ return rc;
498
+ }
499
+
500
+ ctx->out = NULL;
501
+ }
502
+ }
503
+
504
+ #if defined(nginx_version) && nginx_version <= 8004
505
+
506
+ /* earlier versions of nginx does not allow subrequests
507
+ to send last_buf themselves */
508
+ if (r != r->main) {
509
+ return NGX_OK;
510
+ }
511
+
512
+ #endif
513
+
514
+ ctx->eof = 1;
515
+
516
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
517
+ "lua sending last buf of the response body");
518
+
519
+ rc = ngx_http_lua_send_special(r, NGX_HTTP_LAST);
520
+
521
+ if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE) {
522
+ return rc;
523
+ }
524
+
525
+ return NGX_OK;
526
+ }
527
+
528
+ /* in != NULL */
529
+
530
+ if (ctx->buffering) {
531
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
532
+ "lua buffering output bufs for the HTTP 1.0 request");
533
+
534
+ for (cl = ctx->out, ll = &ctx->out; cl; cl = cl->next) {
535
+ ll = &cl->next;
536
+ }
537
+
538
+ *ll = in;
539
+
540
+ return NGX_OK;
541
+ }
542
+
543
+ return ngx_http_lua_output_filter(r, in);
544
+ }
545
+
546
+
547
+ static ngx_int_t
548
+ ngx_http_lua_send_special(ngx_http_request_t *r, ngx_uint_t flags)
549
+ {
550
+ ngx_int_t rc;
551
+ ngx_http_request_t *ar; /* active request */
552
+
553
+ ar = r->connection->data;
554
+
555
+ if (ar != r) {
556
+
557
+ /* bypass ngx_http_postpone_filter_module */
558
+
559
+ r->connection->data = r;
560
+ rc = ngx_http_send_special(r, flags);
561
+ r->connection->data = ar;
562
+ return rc;
563
+ }
564
+
565
+ return ngx_http_send_special(r, flags);
566
+ }
567
+
568
+
569
+ static ngx_int_t
570
+ ngx_http_lua_output_filter(ngx_http_request_t *r, ngx_chain_t *in)
571
+ {
572
+ ngx_int_t rc;
573
+ ngx_http_lua_ctx_t *ctx;
574
+ ngx_http_request_t *ar; /* active request */
575
+
576
+ ar = r->connection->data;
577
+
578
+ if (ar != r) {
579
+
580
+ /* bypass ngx_http_postpone_filter_module */
581
+
582
+ r->connection->data = r;
583
+ rc = ngx_http_output_filter(r, in);
584
+ r->connection->data = ar;
585
+ return rc;
586
+ }
587
+
588
+ rc = ngx_http_output_filter(r, in);
589
+
590
+ if (rc == NGX_ERROR) {
591
+ return NGX_ERROR;
592
+ }
593
+
594
+ ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
595
+
596
+ #if nginx_version >= 1001004
597
+ ngx_chain_update_chains(r->pool,
598
+ #else
599
+ ngx_chain_update_chains(
600
+ #endif
601
+ &ctx->free_bufs, &ctx->busy_bufs, &in,
602
+ (ngx_buf_tag_t) &ngx_http_lua_module);
603
+
604
+ return rc;
605
+ }
606
+
607
+
608
+ static ngx_int_t
609
+ ngx_http_lua_send_http10_headers(ngx_http_request_t *r,
610
+ ngx_http_lua_ctx_t *ctx)
611
+ {
612
+ off_t size;
613
+ ngx_chain_t *cl;
614
+ ngx_int_t rc;
615
+
616
+ if (r->header_sent) {
617
+ return NGX_OK;
618
+ }
619
+
620
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
621
+ "lua sending HTTP 1.0 response headers");
622
+
623
+ if (r->header_only) {
624
+ goto send;
625
+ }
626
+
627
+ if (r->headers_out.content_length == NULL) {
628
+ for (size = 0, cl = ctx->out; cl; cl = cl->next) {
629
+ size += ngx_buf_size(cl->buf);
630
+ }
631
+
632
+ r->headers_out.content_length_n = size;
633
+
634
+ if (r->headers_out.content_length) {
635
+ r->headers_out.content_length->hash = 0;
636
+ }
637
+ }
638
+
639
+ send:
640
+
641
+ rc = ngx_http_send_header(r);
642
+ return rc;
643
+ }
644
+
645
+
646
+ static void
647
+ ngx_http_lua_init_registry(lua_State *L, ngx_log_t *log)
648
+ {
649
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, log, 0,
650
+ "lua initializing lua registry");
651
+
652
+ /* {{{ register a table to anchor lua coroutines reliably:
653
+ * {([int]ref) = [cort]} */
654
+ lua_pushlightuserdata(L, &ngx_http_lua_coroutines_key);
655
+ lua_createtable(L, 0, 32 /* nrec */);
656
+ lua_rawset(L, LUA_REGISTRYINDEX);
657
+ /* }}} */
658
+
659
+ /* create the registry entry for the Lua request ctx data table */
660
+ lua_pushliteral(L, ngx_http_lua_ctx_tables_key);
661
+ lua_createtable(L, 0, 32 /* nrec */);
662
+ lua_rawset(L, LUA_REGISTRYINDEX);
663
+
664
+ /* create the registry entry for the Lua socket connection pool table */
665
+ lua_pushlightuserdata(L, &ngx_http_lua_socket_pool_key);
666
+ lua_createtable(L, 0, 8 /* nrec */);
667
+ lua_rawset(L, LUA_REGISTRYINDEX);
668
+
669
+ #if (NGX_PCRE)
670
+ /* create the registry entry for the Lua precompiled regex object cache */
671
+ lua_pushlightuserdata(L, &ngx_http_lua_regex_cache_key);
672
+ lua_createtable(L, 0, 16 /* nrec */);
673
+ lua_rawset(L, LUA_REGISTRYINDEX);
674
+ #endif
675
+
676
+ /* {{{ register table to cache user code:
677
+ * { [(string)cache_key] = <code closure> } */
678
+ lua_pushlightuserdata(L, &ngx_http_lua_code_cache_key);
679
+ lua_createtable(L, 0, 8 /* nrec */);
680
+ lua_rawset(L, LUA_REGISTRYINDEX);
681
+ /* }}} */
682
+ }
683
+
684
+
685
+ static void
686
+ ngx_http_lua_init_globals(lua_State *L, ngx_cycle_t *cycle,
687
+ ngx_http_lua_main_conf_t *lmcf, ngx_log_t *log)
688
+ {
689
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, log, 0,
690
+ "lua initializing lua globals");
691
+
692
+ lua_pushlightuserdata(L, cycle);
693
+ lua_setglobal(L, "__ngx_cycle");
694
+
695
+ #if defined(NDK) && NDK
696
+ ngx_http_lua_inject_ndk_api(L);
697
+ #endif /* defined(NDK) && NDK */
698
+
699
+ ngx_http_lua_inject_ngx_api(L, lmcf, log);
700
+ }
701
+
702
+
703
+ static void
704
+ ngx_http_lua_inject_ngx_api(lua_State *L, ngx_http_lua_main_conf_t *lmcf,
705
+ ngx_log_t *log)
706
+ {
707
+ lua_createtable(L, 0 /* narr */, 99 /* nrec */); /* ngx.* */
708
+
709
+ lua_pushcfunction(L, ngx_http_lua_get_raw_phase_context);
710
+ lua_setfield(L, -2, "_phase_ctx");
711
+
712
+ ngx_http_lua_inject_arg_api(L);
713
+
714
+ ngx_http_lua_inject_http_consts(L);
715
+ ngx_http_lua_inject_core_consts(L);
716
+
717
+ ngx_http_lua_inject_log_api(L);
718
+ ngx_http_lua_inject_output_api(L);
719
+ ngx_http_lua_inject_time_api(L);
720
+ ngx_http_lua_inject_string_api(L);
721
+ ngx_http_lua_inject_control_api(log, L);
722
+ ngx_http_lua_inject_subrequest_api(L);
723
+ ngx_http_lua_inject_sleep_api(L);
724
+ ngx_http_lua_inject_phase_api(L);
725
+
726
+ #if (NGX_PCRE)
727
+ ngx_http_lua_inject_regex_api(L);
728
+ #endif
729
+
730
+ ngx_http_lua_inject_req_api(log, L);
731
+ ngx_http_lua_inject_resp_header_api(L);
732
+ ngx_http_lua_create_headers_metatable(log, L);
733
+ ngx_http_lua_inject_variable_api(L);
734
+ ngx_http_lua_inject_shdict_api(lmcf, L);
735
+ ngx_http_lua_inject_socket_tcp_api(log, L);
736
+ ngx_http_lua_inject_socket_udp_api(log, L);
737
+ ngx_http_lua_inject_uthread_api(log, L);
738
+ ngx_http_lua_inject_timer_api(L);
739
+ ngx_http_lua_inject_config_api(L);
740
+ ngx_http_lua_inject_worker_api(L);
741
+
742
+ ngx_http_lua_inject_misc_api(L);
743
+
744
+ lua_getglobal(L, "package"); /* ngx package */
745
+ lua_getfield(L, -1, "loaded"); /* ngx package loaded */
746
+ lua_pushvalue(L, -3); /* ngx package loaded ngx */
747
+ lua_setfield(L, -2, "ngx"); /* ngx package loaded */
748
+ lua_pop(L, 2);
749
+
750
+ lua_setglobal(L, "ngx");
751
+
752
+ ngx_http_lua_inject_coroutine_api(log, L);
753
+ }
754
+
755
+
756
+ void
757
+ ngx_http_lua_discard_bufs(ngx_pool_t *pool, ngx_chain_t *in)
758
+ {
759
+ ngx_chain_t *cl;
760
+
761
+ for (cl = in; cl; cl = cl->next) {
762
+ cl->buf->pos = cl->buf->last;
763
+ cl->buf->file_pos = cl->buf->file_last;
764
+ }
765
+ }
766
+
767
+
768
+ ngx_int_t
769
+ ngx_http_lua_add_copy_chain(ngx_http_request_t *r, ngx_http_lua_ctx_t *ctx,
770
+ ngx_chain_t ***plast, ngx_chain_t *in, ngx_int_t *eof)
771
+ {
772
+ ngx_chain_t *cl;
773
+ size_t len;
774
+ ngx_buf_t *b;
775
+
776
+ len = 0;
777
+ *eof = 0;
778
+
779
+ for (cl = in; cl; cl = cl->next) {
780
+ if (ngx_buf_in_memory(cl->buf)) {
781
+ len += cl->buf->last - cl->buf->pos;
782
+ }
783
+
784
+ if (cl->buf->last_in_chain || cl->buf->last_buf) {
785
+ *eof = 1;
786
+ }
787
+ }
788
+
789
+ if (len == 0) {
790
+ return NGX_OK;
791
+ }
792
+
793
+ cl = ngx_http_lua_chain_get_free_buf(r->connection->log, r->pool,
794
+ &ctx->free_bufs, len);
795
+ if (cl == NULL) {
796
+ return NGX_ERROR;
797
+ }
798
+
799
+ dd("chains get free buf: %d == %d", (int) (cl->buf->end - cl->buf->start),
800
+ (int) len);
801
+
802
+ b = cl->buf;
803
+
804
+ while (in) {
805
+ if (ngx_buf_in_memory(in->buf)) {
806
+ b->last = ngx_copy(b->last, in->buf->pos,
807
+ in->buf->last - in->buf->pos);
808
+ }
809
+
810
+ in = in->next;
811
+ }
812
+
813
+ **plast = cl;
814
+ *plast = &cl->next;
815
+
816
+ return NGX_OK;
817
+ }
818
+
819
+
820
+ void
821
+ ngx_http_lua_reset_ctx(ngx_http_request_t *r, lua_State *L,
822
+ ngx_http_lua_ctx_t *ctx)
823
+ {
824
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
825
+ "lua reset ctx");
826
+
827
+ ngx_http_lua_finalize_threads(r, ctx, L);
828
+
829
+ #if 0
830
+ if (ctx->user_co_ctx) {
831
+ /* no way to destroy a list but clean up the whole pool */
832
+ ctx->user_co_ctx = NULL;
833
+ }
834
+ #endif
835
+
836
+ ngx_memzero(&ctx->entry_co_ctx, sizeof(ngx_http_lua_co_ctx_t));
837
+
838
+ ctx->entry_co_ctx.co_ref = LUA_NOREF;
839
+
840
+ ctx->entered_rewrite_phase = 0;
841
+ ctx->entered_access_phase = 0;
842
+ ctx->entered_content_phase = 0;
843
+
844
+ ctx->exit_code = 0;
845
+ ctx->exited = 0;
846
+ ctx->resume_handler = ngx_http_lua_wev_handler;
847
+
848
+ ngx_str_null(&ctx->exec_uri);
849
+ ngx_str_null(&ctx->exec_args);
850
+
851
+ ctx->co_op = 0;
852
+ }
853
+
854
+
855
+ /* post read callback for rewrite and access phases */
856
+ void
857
+ ngx_http_lua_generic_phase_post_read(ngx_http_request_t *r)
858
+ {
859
+ ngx_http_lua_ctx_t *ctx;
860
+
861
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
862
+ "lua post read for rewrite/access phases");
863
+
864
+ ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
865
+
866
+ ctx->read_body_done = 1;
867
+
868
+ #if defined(nginx_version) && nginx_version >= 8011
869
+ r->main->count--;
870
+ #endif
871
+
872
+ if (ctx->waiting_more_body) {
873
+ ctx->waiting_more_body = 0;
874
+ ngx_http_core_run_phases(r);
875
+ }
876
+ }
877
+
878
+
879
+ void
880
+ ngx_http_lua_request_cleanup_handler(void *data)
881
+ {
882
+ ngx_http_lua_ctx_t *ctx = data;
883
+
884
+ ngx_http_lua_request_cleanup(ctx, 0 /* forcible */);
885
+ }
886
+
887
+
888
+ void
889
+ ngx_http_lua_request_cleanup(ngx_http_lua_ctx_t *ctx, int forcible)
890
+ {
891
+ lua_State *L;
892
+ ngx_http_request_t *r;
893
+ ngx_http_lua_main_conf_t *lmcf;
894
+
895
+ r = ctx->request;
896
+
897
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
898
+ "lua request cleanup: forcible=%d", forcible);
899
+
900
+ /* force coroutine handling the request quit */
901
+ if (ctx == NULL) {
902
+ dd("ctx is NULL");
903
+ return;
904
+ }
905
+
906
+ if (ctx->cleanup) {
907
+ *ctx->cleanup = NULL;
908
+ ctx->cleanup = NULL;
909
+ }
910
+
911
+ lmcf = ngx_http_get_module_main_conf(r, ngx_http_lua_module);
912
+
913
+ #if 1
914
+ if (r->connection->fd == -1) {
915
+ /* being a fake request */
916
+ lmcf->running_timers--;
917
+ }
918
+ #endif
919
+
920
+ L = ngx_http_lua_get_lua_vm(r, ctx);
921
+
922
+ ngx_http_lua_finalize_threads(r, ctx, L);
923
+ }
924
+
925
+
926
+ /*
927
+ * description:
928
+ * run a Lua coroutine specified by ctx->cur_co_ctx->co
929
+ * return value:
930
+ * NGX_AGAIN: I/O interruption: r->main->count intact
931
+ * NGX_DONE: I/O interruption: r->main->count already incremented by 1
932
+ * NGX_ERROR: error
933
+ * >= 200 HTTP status code
934
+ */
935
+ ngx_int_t
936
+ ngx_http_lua_run_thread(lua_State *L, ngx_http_request_t *r,
937
+ ngx_http_lua_ctx_t *ctx, volatile int nrets)
938
+ {
939
+ ngx_http_lua_co_ctx_t *next_coctx, *parent_coctx, *orig_coctx;
940
+ int rv, success = 1;
941
+ lua_State *next_co;
942
+ lua_State *old_co;
943
+ const char *err, *msg, *trace;
944
+ ngx_int_t rc;
945
+ #if (NGX_PCRE)
946
+ ngx_pool_t *old_pool = NULL;
947
+ #endif
948
+
949
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
950
+ "lua run thread, top:%d c:%ud", lua_gettop(L),
951
+ r->main->count);
952
+
953
+ /* set Lua VM panic handler */
954
+ lua_atpanic(L, ngx_http_lua_atpanic);
955
+
956
+ dd("ctx = %p", ctx);
957
+
958
+ NGX_LUA_EXCEPTION_TRY {
959
+
960
+ if (ctx->cur_co_ctx->thread_spawn_yielded) {
961
+ ngx_http_lua_probe_info("thread spawn yielded");
962
+
963
+ ctx->cur_co_ctx->thread_spawn_yielded = 0;
964
+ nrets = 1;
965
+ }
966
+
967
+ for ( ;; ) {
968
+
969
+ dd("calling lua_resume: vm %p, nret %d", ctx->cur_co_ctx->co,
970
+ (int) nrets);
971
+
972
+ #if (NGX_PCRE)
973
+ /* XXX: work-around to nginx regex subsystem */
974
+ old_pool = ngx_http_lua_pcre_malloc_init(r->pool);
975
+ #endif
976
+
977
+ /* run code */
978
+ dd("ctx: %p", ctx);
979
+ dd("cur co: %p", ctx->cur_co_ctx->co);
980
+ dd("cur co status: %d", ctx->cur_co_ctx->co_status);
981
+
982
+ orig_coctx = ctx->cur_co_ctx;
983
+
984
+ #ifdef NGX_LUA_USE_ASSERT
985
+ dd("%p: saved co top: %d, nrets: %d, true top: %d",
986
+ orig_coctx->co,
987
+ (int) orig_coctx->co_top, (int) nrets,
988
+ (int) lua_gettop(orig_coctx->co));
989
+ #endif
990
+
991
+ #if DDEBUG
992
+ if (lua_gettop(orig_coctx->co) > 0) {
993
+ dd("top elem: %s", luaL_typename(orig_coctx->co, -1));
994
+ }
995
+ #endif
996
+
997
+ ngx_http_lua_assert(orig_coctx->co_top + nrets
998
+ == lua_gettop(orig_coctx->co));
999
+
1000
+ rv = lua_resume(orig_coctx->co, nrets);
1001
+
1002
+ #if (NGX_PCRE)
1003
+ /* XXX: work-around to nginx regex subsystem */
1004
+ ngx_http_lua_pcre_malloc_done(old_pool);
1005
+ #endif
1006
+
1007
+ #if 0
1008
+ /* test the longjmp thing */
1009
+ if (rand() % 2 == 0) {
1010
+ NGX_LUA_EXCEPTION_THROW(1);
1011
+ }
1012
+ #endif
1013
+
1014
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1015
+ "lua resume returned %d", rv);
1016
+
1017
+ switch (rv) {
1018
+ case LUA_YIELD:
1019
+ /* yielded, let event handler do the rest job */
1020
+ /* FIXME: add io cmd dispatcher here */
1021
+
1022
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1023
+ "lua thread yielded");
1024
+
1025
+ #ifdef NGX_LUA_USE_ASSERT
1026
+ dd("%p: saving curr top after yield: %d (co-op: %d)",
1027
+ orig_coctx->co,
1028
+ (int) lua_gettop(orig_coctx->co), (int) ctx->co_op);
1029
+ orig_coctx->co_top = lua_gettop(orig_coctx->co);
1030
+ #endif
1031
+
1032
+ if (r->uri_changed) {
1033
+ return ngx_http_lua_handle_rewrite_jump(L, r, ctx);
1034
+ }
1035
+
1036
+ if (ctx->exited) {
1037
+ return ngx_http_lua_handle_exit(L, r, ctx);
1038
+ }
1039
+
1040
+ if (ctx->exec_uri.len) {
1041
+ return ngx_http_lua_handle_exec(L, r, ctx);
1042
+ }
1043
+
1044
+ /*
1045
+ * check if coroutine.resume or coroutine.yield called
1046
+ * lua_yield()
1047
+ */
1048
+ switch(ctx->co_op) {
1049
+ case NGX_HTTP_LUA_USER_CORO_NOP:
1050
+ dd("hit! it is the API yield");
1051
+
1052
+ ngx_http_lua_assert(lua_gettop(ctx->cur_co_ctx->co) == 0);
1053
+
1054
+ ctx->cur_co_ctx = NULL;
1055
+
1056
+ return NGX_AGAIN;
1057
+
1058
+ case NGX_HTTP_LUA_USER_THREAD_RESUME:
1059
+
1060
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1061
+ "lua user thread resume");
1062
+
1063
+ ctx->co_op = NGX_HTTP_LUA_USER_CORO_NOP;
1064
+ nrets = lua_gettop(ctx->cur_co_ctx->co) - 1;
1065
+ dd("nrets = %d", nrets);
1066
+
1067
+ #ifdef NGX_LUA_USE_ASSERT
1068
+ /* ignore the return value (the thread) already pushed */
1069
+ orig_coctx->co_top--;
1070
+ #endif
1071
+
1072
+ break;
1073
+
1074
+ case NGX_HTTP_LUA_USER_CORO_RESUME:
1075
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1076
+ "lua coroutine: resume");
1077
+
1078
+ /*
1079
+ * the target coroutine lies at the base of the
1080
+ * parent's stack
1081
+ */
1082
+ ctx->co_op = NGX_HTTP_LUA_USER_CORO_NOP;
1083
+
1084
+ old_co = ctx->cur_co_ctx->parent_co_ctx->co;
1085
+
1086
+ nrets = lua_gettop(old_co);
1087
+ if (nrets) {
1088
+ dd("moving %d return values to parent", nrets);
1089
+ lua_xmove(old_co, ctx->cur_co_ctx->co, nrets);
1090
+
1091
+ #ifdef NGX_LUA_USE_ASSERT
1092
+ ctx->cur_co_ctx->parent_co_ctx->co_top -= nrets;
1093
+ #endif
1094
+ }
1095
+
1096
+ break;
1097
+
1098
+ default:
1099
+ /* ctx->co_op == NGX_HTTP_LUA_USER_CORO_YIELD */
1100
+
1101
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1102
+ "lua coroutine: yield");
1103
+
1104
+ ctx->co_op = NGX_HTTP_LUA_USER_CORO_NOP;
1105
+
1106
+ if (ngx_http_lua_is_thread(ctx)) {
1107
+ ngx_http_lua_probe_thread_yield(r, ctx->cur_co_ctx->co);
1108
+
1109
+ /* discard any return values from user
1110
+ * coroutine.yield()'s arguments */
1111
+ lua_settop(ctx->cur_co_ctx->co, 0);
1112
+
1113
+ #ifdef NGX_LUA_USE_ASSERT
1114
+ ctx->cur_co_ctx->co_top = 0;
1115
+ #endif
1116
+
1117
+ ngx_http_lua_probe_info("set co running");
1118
+ ctx->cur_co_ctx->co_status = NGX_HTTP_LUA_CO_RUNNING;
1119
+
1120
+ if (ctx->posted_threads) {
1121
+ ngx_http_lua_post_thread(r, ctx, ctx->cur_co_ctx);
1122
+ ctx->cur_co_ctx = NULL;
1123
+ return NGX_AGAIN;
1124
+ }
1125
+
1126
+ /* no pending threads, so resume the thread
1127
+ * immediately */
1128
+
1129
+ nrets = 0;
1130
+ continue;
1131
+ }
1132
+
1133
+ /* being a user coroutine that has a parent */
1134
+
1135
+ nrets = lua_gettop(ctx->cur_co_ctx->co);
1136
+
1137
+ next_coctx = ctx->cur_co_ctx->parent_co_ctx;
1138
+ next_co = next_coctx->co;
1139
+
1140
+ /*
1141
+ * prepare return values for coroutine.resume
1142
+ * (true plus any retvals)
1143
+ */
1144
+ lua_pushboolean(next_co, 1);
1145
+
1146
+ if (nrets) {
1147
+ dd("moving %d return values to next co", nrets);
1148
+ lua_xmove(ctx->cur_co_ctx->co, next_co, nrets);
1149
+ #ifdef NGX_LUA_USE_ASSERT
1150
+ ctx->cur_co_ctx->co_top -= nrets;
1151
+ #endif
1152
+ }
1153
+
1154
+ nrets++; /* add the true boolean value */
1155
+
1156
+ ctx->cur_co_ctx = next_coctx;
1157
+
1158
+ break;
1159
+ }
1160
+
1161
+ /* try resuming on the new coroutine again */
1162
+ continue;
1163
+
1164
+ case 0:
1165
+
1166
+ ngx_http_lua_cleanup_pending_operation(ctx->cur_co_ctx);
1167
+
1168
+ ngx_http_lua_probe_coroutine_done(r, ctx->cur_co_ctx->co, 1);
1169
+
1170
+ ctx->cur_co_ctx->co_status = NGX_HTTP_LUA_CO_DEAD;
1171
+
1172
+ if (ctx->cur_co_ctx->zombie_child_threads) {
1173
+ ngx_http_lua_cleanup_zombie_child_uthreads(r, L, ctx,
1174
+ ctx->cur_co_ctx);
1175
+ }
1176
+
1177
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1178
+ "lua light thread ended normally");
1179
+
1180
+ if (ngx_http_lua_is_entry_thread(ctx)) {
1181
+
1182
+ lua_settop(L, 0);
1183
+
1184
+ ngx_http_lua_del_thread(r, L, ctx, ctx->cur_co_ctx);
1185
+
1186
+ dd("uthreads: %d", (int) ctx->uthreads);
1187
+
1188
+ if (ctx->uthreads) {
1189
+
1190
+ ctx->cur_co_ctx = NULL;
1191
+ return NGX_AGAIN;
1192
+ }
1193
+
1194
+ /* all user threads terminated already */
1195
+ goto done;
1196
+ }
1197
+
1198
+ if (ctx->cur_co_ctx->is_uthread) {
1199
+ /* being a user thread */
1200
+
1201
+ lua_settop(L, 0);
1202
+
1203
+ parent_coctx = ctx->cur_co_ctx->parent_co_ctx;
1204
+
1205
+ if (ngx_http_lua_coroutine_alive(parent_coctx)) {
1206
+ if (ctx->cur_co_ctx->waited_by_parent) {
1207
+ ngx_http_lua_probe_info("parent already waiting");
1208
+ ctx->cur_co_ctx->waited_by_parent = 0;
1209
+ success = 1;
1210
+ goto user_co_done;
1211
+ }
1212
+
1213
+ ngx_http_lua_probe_info("parent still alive");
1214
+
1215
+ if (ngx_http_lua_post_zombie_thread(r, parent_coctx,
1216
+ ctx->cur_co_ctx)
1217
+ != NGX_OK)
1218
+ {
1219
+ return NGX_ERROR;
1220
+ }
1221
+
1222
+ lua_pushboolean(ctx->cur_co_ctx->co, 1);
1223
+ lua_insert(ctx->cur_co_ctx->co, 1);
1224
+
1225
+ ctx->cur_co_ctx->co_status = NGX_HTTP_LUA_CO_ZOMBIE;
1226
+ ctx->cur_co_ctx = NULL;
1227
+ return NGX_AGAIN;
1228
+ }
1229
+
1230
+ ngx_http_lua_del_thread(r, L, ctx, ctx->cur_co_ctx);
1231
+ ctx->uthreads--;
1232
+
1233
+ if (ctx->uthreads == 0) {
1234
+ if (ngx_http_lua_entry_thread_alive(ctx)) {
1235
+ ctx->cur_co_ctx = NULL;
1236
+ return NGX_AGAIN;
1237
+ }
1238
+
1239
+ /* all threads terminated already */
1240
+ goto done;
1241
+ }
1242
+
1243
+ /* some other user threads still running */
1244
+ ctx->cur_co_ctx = NULL;
1245
+ return NGX_AGAIN;
1246
+ }
1247
+
1248
+ /* being a user coroutine that has a parent */
1249
+
1250
+ success = 1;
1251
+
1252
+ user_co_done:
1253
+
1254
+ nrets = lua_gettop(ctx->cur_co_ctx->co);
1255
+
1256
+ next_coctx = ctx->cur_co_ctx->parent_co_ctx;
1257
+
1258
+ if (next_coctx == NULL) {
1259
+ /* being a light thread */
1260
+ goto no_parent;
1261
+ }
1262
+
1263
+ next_co = next_coctx->co;
1264
+
1265
+ /*
1266
+ * ended successful, coroutine.resume returns true plus
1267
+ * any return values
1268
+ */
1269
+ lua_pushboolean(next_co, success);
1270
+
1271
+ if (nrets) {
1272
+ lua_xmove(ctx->cur_co_ctx->co, next_co, nrets);
1273
+ }
1274
+
1275
+ if (ctx->cur_co_ctx->is_uthread) {
1276
+ ngx_http_lua_del_thread(r, L, ctx, ctx->cur_co_ctx);
1277
+ ctx->uthreads--;
1278
+ }
1279
+
1280
+ nrets++;
1281
+ ctx->cur_co_ctx = next_coctx;
1282
+
1283
+ ngx_http_lua_probe_info("set parent running");
1284
+
1285
+ next_coctx->co_status = NGX_HTTP_LUA_CO_RUNNING;
1286
+
1287
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1288
+ "lua coroutine: lua user thread ended normally");
1289
+
1290
+ continue;
1291
+
1292
+ case LUA_ERRRUN:
1293
+ err = "runtime error";
1294
+ break;
1295
+
1296
+ case LUA_ERRSYNTAX:
1297
+ err = "syntax error";
1298
+ break;
1299
+
1300
+ case LUA_ERRMEM:
1301
+ err = "memory allocation error";
1302
+ ngx_quit = 1;
1303
+ break;
1304
+
1305
+ case LUA_ERRERR:
1306
+ err = "error handler error";
1307
+ break;
1308
+
1309
+ default:
1310
+ err = "unknown error";
1311
+ break;
1312
+ }
1313
+
1314
+ if (ctx->cur_co_ctx != orig_coctx) {
1315
+ ctx->cur_co_ctx = orig_coctx;
1316
+ }
1317
+
1318
+ if (lua_isstring(ctx->cur_co_ctx->co, -1)) {
1319
+ dd("user custom error msg");
1320
+ msg = lua_tostring(ctx->cur_co_ctx->co, -1);
1321
+
1322
+ } else {
1323
+ msg = "unknown reason";
1324
+ }
1325
+
1326
+ ngx_http_lua_cleanup_pending_operation(ctx->cur_co_ctx);
1327
+
1328
+ ngx_http_lua_probe_coroutine_done(r, ctx->cur_co_ctx->co, 0);
1329
+
1330
+ ctx->cur_co_ctx->co_status = NGX_HTTP_LUA_CO_DEAD;
1331
+
1332
+ ngx_http_lua_thread_traceback(L, ctx->cur_co_ctx->co,
1333
+ ctx->cur_co_ctx);
1334
+ trace = lua_tostring(L, -1);
1335
+
1336
+ if (ctx->cur_co_ctx->is_uthread) {
1337
+
1338
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
1339
+ "lua user thread aborted: %s: %s\n%s",
1340
+ err, msg, trace);
1341
+
1342
+ lua_settop(L, 0);
1343
+
1344
+ parent_coctx = ctx->cur_co_ctx->parent_co_ctx;
1345
+
1346
+ if (ngx_http_lua_coroutine_alive(parent_coctx)) {
1347
+ if (ctx->cur_co_ctx->waited_by_parent) {
1348
+ ctx->cur_co_ctx->waited_by_parent = 0;
1349
+ success = 0;
1350
+ goto user_co_done;
1351
+ }
1352
+
1353
+ if (ngx_http_lua_post_zombie_thread(r, parent_coctx,
1354
+ ctx->cur_co_ctx)
1355
+ != NGX_OK)
1356
+ {
1357
+ return NGX_ERROR;
1358
+ }
1359
+
1360
+ lua_pushboolean(ctx->cur_co_ctx->co, 0);
1361
+ lua_insert(ctx->cur_co_ctx->co, 1);
1362
+
1363
+ ctx->cur_co_ctx->co_status = NGX_HTTP_LUA_CO_ZOMBIE;
1364
+ ctx->cur_co_ctx = NULL;
1365
+ return NGX_AGAIN;
1366
+ }
1367
+
1368
+ ngx_http_lua_del_thread(r, L, ctx, ctx->cur_co_ctx);
1369
+ ctx->uthreads--;
1370
+
1371
+ if (ctx->uthreads == 0) {
1372
+ if (ngx_http_lua_entry_thread_alive(ctx)) {
1373
+ ctx->cur_co_ctx = NULL;
1374
+ return NGX_AGAIN;
1375
+ }
1376
+
1377
+ /* all threads terminated already */
1378
+ goto done;
1379
+ }
1380
+
1381
+ /* some other user threads still running */
1382
+ ctx->cur_co_ctx = NULL;
1383
+ return NGX_AGAIN;
1384
+ }
1385
+
1386
+ if (ngx_http_lua_is_entry_thread(ctx)) {
1387
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
1388
+ "lua entry thread aborted: %s: %s\n%s",
1389
+ err, msg, trace);
1390
+
1391
+ lua_settop(L, 0);
1392
+
1393
+ /* being the entry thread aborted */
1394
+
1395
+ if (r->filter_finalize) {
1396
+ ngx_http_set_ctx(r, ctx, ngx_http_lua_module);
1397
+ }
1398
+
1399
+ ngx_http_lua_request_cleanup(ctx, 0);
1400
+
1401
+ dd("headers sent? %d", r->header_sent ? 1 : 0);
1402
+
1403
+ if (ctx->no_abort) {
1404
+ ctx->no_abort = 0;
1405
+ return NGX_ERROR;
1406
+ }
1407
+
1408
+ return r->header_sent ? NGX_ERROR :
1409
+ NGX_HTTP_INTERNAL_SERVER_ERROR;
1410
+ }
1411
+
1412
+ /* being a user coroutine that has a parent */
1413
+
1414
+ next_coctx = ctx->cur_co_ctx->parent_co_ctx;
1415
+ if (next_coctx == NULL) {
1416
+ goto no_parent;
1417
+ }
1418
+
1419
+ next_co = next_coctx->co;
1420
+
1421
+ ngx_http_lua_probe_info("set parent running");
1422
+
1423
+ next_coctx->co_status = NGX_HTTP_LUA_CO_RUNNING;
1424
+
1425
+ /*
1426
+ * ended with error, coroutine.resume returns false plus
1427
+ * err msg
1428
+ */
1429
+ lua_pushboolean(next_co, 0);
1430
+ lua_xmove(ctx->cur_co_ctx->co, next_co, 1);
1431
+ nrets = 2;
1432
+
1433
+ ctx->cur_co_ctx = next_coctx;
1434
+
1435
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
1436
+ "lua coroutine: %s: %s\n%s", err, msg, trace);
1437
+
1438
+ /* try resuming on the new coroutine again */
1439
+ continue;
1440
+ }
1441
+
1442
+ } NGX_LUA_EXCEPTION_CATCH {
1443
+ dd("nginx execution restored");
1444
+ }
1445
+
1446
+ return NGX_ERROR;
1447
+
1448
+ no_parent:
1449
+
1450
+ lua_settop(L, 0);
1451
+
1452
+ ctx->cur_co_ctx->co_status = NGX_HTTP_LUA_CO_DEAD;
1453
+
1454
+ if (r->filter_finalize) {
1455
+ ngx_http_set_ctx(r, ctx, ngx_http_lua_module);
1456
+ }
1457
+
1458
+ ngx_http_lua_request_cleanup(ctx, 0);
1459
+
1460
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "lua handler aborted: "
1461
+ "user coroutine has no parent");
1462
+
1463
+ return r->header_sent ? NGX_ERROR : NGX_HTTP_INTERNAL_SERVER_ERROR;
1464
+
1465
+ done:
1466
+
1467
+ if (ctx->entered_content_phase && r->connection->fd != -1) {
1468
+ rc = ngx_http_lua_send_chain_link(r, ctx,
1469
+ NULL /* last_buf */);
1470
+
1471
+ if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE) {
1472
+ return rc;
1473
+ }
1474
+ }
1475
+
1476
+ return NGX_OK;
1477
+ }
1478
+
1479
+
1480
+ ngx_int_t
1481
+ ngx_http_lua_wev_handler(ngx_http_request_t *r)
1482
+ {
1483
+ ngx_int_t rc;
1484
+ ngx_event_t *wev;
1485
+ ngx_connection_t *c;
1486
+ ngx_http_lua_ctx_t *ctx;
1487
+ ngx_http_lua_co_ctx_t *coctx;
1488
+ ngx_http_core_loc_conf_t *clcf;
1489
+
1490
+ ngx_http_lua_socket_tcp_upstream_t *u;
1491
+
1492
+ c = r->connection;
1493
+ wev = c->write;
1494
+
1495
+ ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
1496
+ if (ctx == NULL) {
1497
+ return NGX_ERROR;
1498
+ }
1499
+
1500
+ ngx_log_debug3(NGX_LOG_DEBUG_HTTP, c->log, 0,
1501
+ "lua run write event handler: timedout:%ud, ready:%ud, "
1502
+ "writing_raw_req_socket:%ud",
1503
+ wev->timedout, wev->ready, ctx->writing_raw_req_socket);
1504
+
1505
+ clcf = ngx_http_get_module_loc_conf(r->main, ngx_http_core_module);
1506
+
1507
+ if (wev->timedout && !ctx->writing_raw_req_socket) {
1508
+ if (!wev->delayed) {
1509
+ ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT,
1510
+ "client timed out");
1511
+ c->timedout = 1;
1512
+
1513
+ goto flush_coros;
1514
+ }
1515
+
1516
+ wev->timedout = 0;
1517
+ wev->delayed = 0;
1518
+
1519
+ if (!wev->ready) {
1520
+ ngx_add_timer(wev, clcf->send_timeout);
1521
+
1522
+ if (ngx_handle_write_event(wev, clcf->send_lowat) != NGX_OK) {
1523
+ if (ctx->entered_content_phase) {
1524
+ ngx_http_lua_finalize_request(r, NGX_ERROR);
1525
+ }
1526
+ return NGX_ERROR;
1527
+ }
1528
+ }
1529
+ }
1530
+
1531
+ if (!wev->ready && !wev->timedout) {
1532
+ goto useless;
1533
+ }
1534
+
1535
+ if (ctx->writing_raw_req_socket) {
1536
+ ctx->writing_raw_req_socket = 0;
1537
+
1538
+ coctx = ctx->downstream_co_ctx;
1539
+ if (coctx == NULL) {
1540
+ return NGX_ERROR;
1541
+ }
1542
+
1543
+ u = coctx->data;
1544
+ if (u == NULL) {
1545
+ return NGX_ERROR;
1546
+ }
1547
+
1548
+ u->write_event_handler(r, u);
1549
+ return NGX_DONE;
1550
+ }
1551
+
1552
+ if (c->buffered & NGX_HTTP_LOWLEVEL_BUFFERED) {
1553
+ rc = ngx_http_lua_flush_pending_output(r, ctx);
1554
+
1555
+ dd("flush pending output returned %d, c->error: %d", (int) rc,
1556
+ c->error);
1557
+
1558
+ if (rc != NGX_ERROR && rc != NGX_OK) {
1559
+ goto useless;
1560
+ }
1561
+
1562
+ /* when rc == NGX_ERROR, c->error must be set */
1563
+ }
1564
+
1565
+ flush_coros:
1566
+
1567
+ dd("ctx->flushing_coros: %d", (int) ctx->flushing_coros);
1568
+
1569
+ if (ctx->flushing_coros) {
1570
+ return ngx_http_lua_process_flushing_coroutines(r, ctx);
1571
+ }
1572
+
1573
+ /* ctx->flushing_coros == 0 */
1574
+
1575
+ useless:
1576
+
1577
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
1578
+ "useless lua write event handler");
1579
+
1580
+ if (ctx->entered_content_phase) {
1581
+ return NGX_OK;
1582
+ }
1583
+
1584
+ return NGX_DONE;
1585
+ }
1586
+
1587
+
1588
+ static ngx_int_t
1589
+ ngx_http_lua_process_flushing_coroutines(ngx_http_request_t *r,
1590
+ ngx_http_lua_ctx_t *ctx)
1591
+ {
1592
+ ngx_int_t rc, n;
1593
+ ngx_uint_t i;
1594
+ ngx_list_part_t *part;
1595
+ ngx_http_lua_co_ctx_t *coctx;
1596
+
1597
+ dd("processing flushing coroutines");
1598
+
1599
+ coctx = &ctx->entry_co_ctx;
1600
+ n = ctx->flushing_coros;
1601
+
1602
+ if (coctx->flushing) {
1603
+ coctx->flushing = 0;
1604
+
1605
+ ctx->flushing_coros--;
1606
+ n--;
1607
+ ctx->cur_co_ctx = coctx;
1608
+
1609
+ rc = ngx_http_lua_flush_resume_helper(r, ctx);
1610
+ if (rc == NGX_ERROR || rc >= NGX_OK) {
1611
+ return rc;
1612
+ }
1613
+
1614
+ /* rc == NGX_DONE */
1615
+ }
1616
+
1617
+ if (n) {
1618
+
1619
+ if (ctx->user_co_ctx == NULL) {
1620
+ return NGX_ERROR;
1621
+ }
1622
+
1623
+ part = &ctx->user_co_ctx->part;
1624
+ coctx = part->elts;
1625
+
1626
+ for (i = 0; /* void */; i++) {
1627
+
1628
+ if (i >= part->nelts) {
1629
+ if (part->next == NULL) {
1630
+ break;
1631
+ }
1632
+
1633
+ part = part->next;
1634
+ coctx = part->elts;
1635
+ i = 0;
1636
+ }
1637
+
1638
+ if (coctx[i].flushing) {
1639
+ coctx[i].flushing = 0;
1640
+ ctx->cur_co_ctx = &coctx[i];
1641
+
1642
+ rc = ngx_http_lua_flush_resume_helper(r, ctx);
1643
+ if (rc == NGX_ERROR || rc >= NGX_OK) {
1644
+ return rc;
1645
+ }
1646
+
1647
+ /* rc == NGX_DONE */
1648
+
1649
+ ctx->flushing_coros--;
1650
+ n--;
1651
+ if (n == 0) {
1652
+ return NGX_DONE;
1653
+ }
1654
+ }
1655
+ }
1656
+ }
1657
+
1658
+ if (n) {
1659
+ return NGX_ERROR;
1660
+ }
1661
+
1662
+ return NGX_DONE;
1663
+ }
1664
+
1665
+
1666
+ static ngx_int_t
1667
+ ngx_http_lua_flush_pending_output(ngx_http_request_t *r,
1668
+ ngx_http_lua_ctx_t *ctx)
1669
+ {
1670
+ ngx_int_t rc;
1671
+ ngx_chain_t *cl;
1672
+ ngx_event_t *wev;
1673
+ ngx_connection_t *c;
1674
+
1675
+ ngx_http_core_loc_conf_t *clcf;
1676
+
1677
+ c = r->connection;
1678
+ wev = c->write;
1679
+
1680
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
1681
+ "lua flushing output: buffered 0x%uxd",
1682
+ c->buffered);
1683
+
1684
+ if (ctx->busy_bufs) {
1685
+ rc = ngx_http_lua_output_filter(r, NULL);
1686
+
1687
+ } else {
1688
+ cl = ngx_http_lua_get_flush_chain(r, ctx);
1689
+ if (cl == NULL) {
1690
+ return NGX_ERROR;
1691
+ }
1692
+
1693
+ rc = ngx_http_lua_output_filter(r, cl);
1694
+ }
1695
+
1696
+ dd("output filter returned %d", (int) rc);
1697
+
1698
+ if (rc == NGX_ERROR || rc > NGX_OK) {
1699
+ return rc;
1700
+ }
1701
+
1702
+ if (c->buffered & NGX_HTTP_LOWLEVEL_BUFFERED) {
1703
+
1704
+ clcf = ngx_http_get_module_loc_conf(r->main, ngx_http_core_module);
1705
+
1706
+ if (!wev->delayed) {
1707
+ ngx_add_timer(wev, clcf->send_timeout);
1708
+ }
1709
+
1710
+ if (ngx_handle_write_event(wev, clcf->send_lowat) != NGX_OK) {
1711
+ if (ctx->entered_content_phase) {
1712
+ ngx_http_lua_finalize_request(r, NGX_ERROR);
1713
+ }
1714
+
1715
+ return NGX_ERROR;
1716
+ }
1717
+
1718
+ if (ctx->flushing_coros) {
1719
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
1720
+ "lua flush still waiting: buffered 0x%uxd",
1721
+ c->buffered);
1722
+
1723
+ return NGX_DONE;
1724
+ }
1725
+
1726
+ } else {
1727
+ #if 1
1728
+ if (wev->timer_set && !wev->delayed) {
1729
+ ngx_del_timer(wev);
1730
+ }
1731
+ #endif
1732
+ }
1733
+
1734
+ return NGX_OK;
1735
+ }
1736
+
1737
+
1738
+ u_char *
1739
+ ngx_http_lua_digest_hex(u_char *dest, const u_char *buf, int buf_len)
1740
+ {
1741
+ ngx_md5_t md5;
1742
+ u_char md5_buf[MD5_DIGEST_LENGTH];
1743
+
1744
+ ngx_md5_init(&md5);
1745
+ ngx_md5_update(&md5, buf, buf_len);
1746
+ ngx_md5_final(md5_buf, &md5);
1747
+
1748
+ return ngx_hex_dump(dest, md5_buf, sizeof(md5_buf));
1749
+ }
1750
+
1751
+
1752
+ void
1753
+ ngx_http_lua_set_multi_value_table(lua_State *L, int index)
1754
+ {
1755
+ if (index < 0) {
1756
+ index = lua_gettop(L) + index + 1;
1757
+ }
1758
+
1759
+ lua_pushvalue(L, -2); /* stack: table key value key */
1760
+ lua_rawget(L, index);
1761
+ if (lua_isnil(L, -1)) {
1762
+ lua_pop(L, 1); /* stack: table key value */
1763
+ lua_rawset(L, index); /* stack: table */
1764
+
1765
+ } else {
1766
+ if (!lua_istable(L, -1)) {
1767
+ /* just inserted one value */
1768
+ lua_createtable(L, 4, 0);
1769
+ /* stack: table key value value table */
1770
+ lua_insert(L, -2);
1771
+ /* stack: table key value table value */
1772
+ lua_rawseti(L, -2, 1);
1773
+ /* stack: table key value table */
1774
+ lua_insert(L, -2);
1775
+ /* stack: table key table value */
1776
+
1777
+ lua_rawseti(L, -2, 2); /* stack: table key table */
1778
+
1779
+ lua_rawset(L, index); /* stack: table */
1780
+
1781
+ } else {
1782
+ /* stack: table key value table */
1783
+ lua_insert(L, -2); /* stack: table key table value */
1784
+
1785
+ lua_rawseti(L, -2, lua_objlen(L, -2) + 1);
1786
+ /* stack: table key table */
1787
+ lua_pop(L, 2); /* stack: table */
1788
+ }
1789
+ }
1790
+ }
1791
+
1792
+
1793
+ uintptr_t
1794
+ ngx_http_lua_escape_uri(u_char *dst, u_char *src, size_t size, ngx_uint_t type)
1795
+ {
1796
+ ngx_uint_t n;
1797
+ uint32_t *escape;
1798
+ static u_char hex[] = "0123456789ABCDEF";
1799
+
1800
+ /* " ", "#", "%", "?", %00-%1F, %7F-%FF */
1801
+
1802
+ static uint32_t uri[] = {
1803
+ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
1804
+
1805
+ /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */
1806
+ 0xfc00886d, /* 1111 1100 0000 0000 1000 1000 0110 1101 */
1807
+
1808
+ /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */
1809
+ 0x78000000, /* 0111 1000 0000 0000 0000 0000 0000 0000 */
1810
+
1811
+ /* ~}| {zyx wvut srqp onml kjih gfed cba` */
1812
+ 0xa8000000, /* 1010 1000 0000 0000 0000 0000 0000 0000 */
1813
+
1814
+ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
1815
+ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
1816
+ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
1817
+ 0xffffffff /* 1111 1111 1111 1111 1111 1111 1111 1111 */
1818
+ };
1819
+
1820
+ /* " ", "#", "%", "+", "?", %00-%1F, %7F-%FF */
1821
+
1822
+ static uint32_t args[] = {
1823
+ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
1824
+
1825
+ /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */
1826
+ 0x80000829, /* 1000 0000 0000 0000 0000 1000 0010 1001 */
1827
+
1828
+ /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */
1829
+ 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
1830
+
1831
+ /* ~}| {zyx wvut srqp onml kjih gfed cba` */
1832
+ 0x80000000, /* 1000 0000 0000 0000 0000 0000 0000 0000 */
1833
+
1834
+ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
1835
+ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
1836
+ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
1837
+ 0xffffffff /* 1111 1111 1111 1111 1111 1111 1111 1111 */
1838
+ };
1839
+
1840
+ /* " ", "#", """, "%", "'", %00-%1F, %7F-%FF */
1841
+
1842
+ static uint32_t html[] = {
1843
+ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
1844
+
1845
+ /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */
1846
+ 0x000000ad, /* 0000 0000 0000 0000 0000 0000 1010 1101 */
1847
+
1848
+ /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */
1849
+ 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
1850
+
1851
+ /* ~}| {zyx wvut srqp onml kjih gfed cba` */
1852
+ 0x80000000, /* 1000 0000 0000 0000 0000 0000 0000 0000 */
1853
+
1854
+ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
1855
+ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
1856
+ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
1857
+ 0xffffffff /* 1111 1111 1111 1111 1111 1111 1111 1111 */
1858
+ };
1859
+
1860
+ /* " ", """, "%", "'", %00-%1F, %7F-%FF */
1861
+
1862
+ static uint32_t refresh[] = {
1863
+ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
1864
+
1865
+ /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */
1866
+ 0x00000085, /* 0000 0000 0000 0000 0000 0000 1000 0101 */
1867
+
1868
+ /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */
1869
+ 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
1870
+
1871
+ /* ~}| {zyx wvut srqp onml kjih gfed cba` */
1872
+ 0x80000000, /* 1000 0000 0000 0000 0000 0000 0000 0000 */
1873
+
1874
+ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
1875
+ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
1876
+ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
1877
+ 0xffffffff /* 1111 1111 1111 1111 1111 1111 1111 1111 */
1878
+ };
1879
+
1880
+ /* " ", "%", %00-%1F */
1881
+
1882
+ static uint32_t memcached[] = {
1883
+ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
1884
+
1885
+ /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */
1886
+ 0x00000021, /* 0000 0000 0000 0000 0000 0000 0010 0001 */
1887
+
1888
+ /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */
1889
+ 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
1890
+
1891
+ /* ~}| {zyx wvut srqp onml kjih gfed cba` */
1892
+ 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
1893
+
1894
+ 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
1895
+ 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
1896
+ 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
1897
+ 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
1898
+ };
1899
+
1900
+ /* mail_auth is the same as memcached */
1901
+
1902
+ static uint32_t *map[] =
1903
+ { uri, args, html, refresh, memcached, memcached };
1904
+
1905
+
1906
+ escape = map[type];
1907
+
1908
+ if (dst == NULL) {
1909
+
1910
+ /* find the number of the characters to be escaped */
1911
+
1912
+ n = 0;
1913
+
1914
+ while (size) {
1915
+ if (escape[*src >> 5] & (1 << (*src & 0x1f))) {
1916
+ n++;
1917
+ }
1918
+ src++;
1919
+ size--;
1920
+ }
1921
+
1922
+ return (uintptr_t) n;
1923
+ }
1924
+
1925
+ while (size) {
1926
+ if (escape[*src >> 5] & (1 << (*src & 0x1f))) {
1927
+ *dst++ = '%';
1928
+ *dst++ = hex[*src >> 4];
1929
+ *dst++ = hex[*src & 0xf];
1930
+ src++;
1931
+
1932
+ } else {
1933
+ *dst++ = *src++;
1934
+ }
1935
+ size--;
1936
+ }
1937
+
1938
+ return (uintptr_t) dst;
1939
+ }
1940
+
1941
+
1942
+ /* XXX we also decode '+' to ' ' */
1943
+ void
1944
+ ngx_http_lua_unescape_uri(u_char **dst, u_char **src, size_t size,
1945
+ ngx_uint_t type)
1946
+ {
1947
+ u_char *d, *s, ch, c, decoded;
1948
+ enum {
1949
+ sw_usual = 0,
1950
+ sw_quoted,
1951
+ sw_quoted_second
1952
+ } state;
1953
+
1954
+ d = *dst;
1955
+ s = *src;
1956
+
1957
+ state = 0;
1958
+ decoded = 0;
1959
+
1960
+ while (size--) {
1961
+
1962
+ ch = *s++;
1963
+
1964
+ switch (state) {
1965
+ case sw_usual:
1966
+ if (ch == '?'
1967
+ && (type & (NGX_UNESCAPE_URI|NGX_UNESCAPE_REDIRECT)))
1968
+ {
1969
+ *d++ = ch;
1970
+ goto done;
1971
+ }
1972
+
1973
+ if (ch == '%') {
1974
+ state = sw_quoted;
1975
+ break;
1976
+ }
1977
+
1978
+ if (ch == '+') {
1979
+ *d++ = ' ';
1980
+ break;
1981
+ }
1982
+
1983
+ *d++ = ch;
1984
+ break;
1985
+
1986
+ case sw_quoted:
1987
+
1988
+ if (ch >= '0' && ch <= '9') {
1989
+ decoded = (u_char) (ch - '0');
1990
+ state = sw_quoted_second;
1991
+ break;
1992
+ }
1993
+
1994
+ c = (u_char) (ch | 0x20);
1995
+ if (c >= 'a' && c <= 'f') {
1996
+ decoded = (u_char) (c - 'a' + 10);
1997
+ state = sw_quoted_second;
1998
+ break;
1999
+ }
2000
+
2001
+ /* the invalid quoted character */
2002
+
2003
+ state = sw_usual;
2004
+
2005
+ *d++ = ch;
2006
+
2007
+ break;
2008
+
2009
+ case sw_quoted_second:
2010
+
2011
+ state = sw_usual;
2012
+
2013
+ if (ch >= '0' && ch <= '9') {
2014
+ ch = (u_char) ((decoded << 4) + ch - '0');
2015
+
2016
+ if (type & NGX_UNESCAPE_REDIRECT) {
2017
+ if (ch > '%' && ch < 0x7f) {
2018
+ *d++ = ch;
2019
+ break;
2020
+ }
2021
+
2022
+ *d++ = '%'; *d++ = *(s - 2); *d++ = *(s - 1);
2023
+ break;
2024
+ }
2025
+
2026
+ *d++ = ch;
2027
+
2028
+ break;
2029
+ }
2030
+
2031
+ c = (u_char) (ch | 0x20);
2032
+ if (c >= 'a' && c <= 'f') {
2033
+ ch = (u_char) ((decoded << 4) + c - 'a' + 10);
2034
+
2035
+ if (type & NGX_UNESCAPE_URI) {
2036
+ if (ch == '?') {
2037
+ *d++ = ch;
2038
+ goto done;
2039
+ }
2040
+
2041
+ *d++ = ch;
2042
+ break;
2043
+ }
2044
+
2045
+ if (type & NGX_UNESCAPE_REDIRECT) {
2046
+ if (ch == '?') {
2047
+ *d++ = ch;
2048
+ goto done;
2049
+ }
2050
+
2051
+ if (ch > '%' && ch < 0x7f) {
2052
+ *d++ = ch;
2053
+ break;
2054
+ }
2055
+
2056
+ *d++ = '%'; *d++ = *(s - 2); *d++ = *(s - 1);
2057
+ break;
2058
+ }
2059
+
2060
+ *d++ = ch;
2061
+
2062
+ break;
2063
+ }
2064
+
2065
+ /* the invalid quoted character */
2066
+
2067
+ break;
2068
+ }
2069
+ }
2070
+
2071
+ done:
2072
+
2073
+ *dst = d;
2074
+ *src = s;
2075
+ }
2076
+
2077
+
2078
+ void
2079
+ ngx_http_lua_inject_req_api(ngx_log_t *log, lua_State *L)
2080
+ {
2081
+ /* ngx.req table */
2082
+
2083
+ lua_createtable(L, 0 /* narr */, 23 /* nrec */); /* .req */
2084
+
2085
+ ngx_http_lua_inject_req_header_api(L);
2086
+ ngx_http_lua_inject_req_uri_api(log, L);
2087
+ ngx_http_lua_inject_req_args_api(L);
2088
+ ngx_http_lua_inject_req_body_api(L);
2089
+ ngx_http_lua_inject_req_socket_api(L);
2090
+ ngx_http_lua_inject_req_method_api(L);
2091
+ ngx_http_lua_inject_req_time_api(L);
2092
+
2093
+ lua_setfield(L, -2, "req");
2094
+ }
2095
+
2096
+
2097
+ static ngx_int_t
2098
+ ngx_http_lua_handle_exec(lua_State *L, ngx_http_request_t *r,
2099
+ ngx_http_lua_ctx_t *ctx)
2100
+ {
2101
+ ngx_int_t rc;
2102
+
2103
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
2104
+ "lua thread initiated internal redirect to %V",
2105
+ &ctx->exec_uri);
2106
+
2107
+ ngx_http_lua_cleanup_pending_operation(ctx->cur_co_ctx);
2108
+
2109
+ ngx_http_lua_probe_coroutine_done(r, ctx->cur_co_ctx->co, 1);
2110
+
2111
+ ctx->cur_co_ctx->co_status = NGX_HTTP_LUA_CO_DEAD;
2112
+
2113
+ if (r->filter_finalize) {
2114
+ ngx_http_set_ctx(r, ctx, ngx_http_lua_module);
2115
+ }
2116
+
2117
+ ngx_http_lua_request_cleanup(ctx, 1 /* forcible */);
2118
+
2119
+ if (ctx->exec_uri.data[0] == '@') {
2120
+ if (ctx->exec_args.len > 0) {
2121
+ ngx_log_error(NGX_LOG_WARN, r->connection->log, 0,
2122
+ "query strings %V ignored when exec'ing "
2123
+ "named location %V",
2124
+ &ctx->exec_args, &ctx->exec_uri);
2125
+ }
2126
+
2127
+ r->write_event_handler = ngx_http_request_empty_handler;
2128
+
2129
+ #if 1
2130
+ if (r->read_event_handler == ngx_http_lua_rd_check_broken_connection) {
2131
+ /* resume the read event handler */
2132
+
2133
+ r->read_event_handler = ngx_http_block_reading;
2134
+ }
2135
+ #endif
2136
+
2137
+ #if 1
2138
+ /* clear the modules contexts */
2139
+ ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module);
2140
+ #endif
2141
+
2142
+ rc = ngx_http_named_location(r, &ctx->exec_uri);
2143
+ if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE)
2144
+ {
2145
+ return rc;
2146
+ }
2147
+
2148
+ #if 0
2149
+ if (!ctx->entered_content_phase) {
2150
+ /* XXX ensure the main request ref count
2151
+ * is decreased because the current
2152
+ * request will be quit */
2153
+ r->main->count--;
2154
+ dd("XXX decrement main count: c:%d", (int) r->main->count);
2155
+ }
2156
+ #endif
2157
+
2158
+ return NGX_DONE;
2159
+ }
2160
+
2161
+ dd("internal redirect to %.*s", (int) ctx->exec_uri.len,
2162
+ ctx->exec_uri.data);
2163
+
2164
+ r->write_event_handler = ngx_http_request_empty_handler;
2165
+
2166
+ if (r->read_event_handler == ngx_http_lua_rd_check_broken_connection) {
2167
+ /* resume the read event handler */
2168
+
2169
+ r->read_event_handler = ngx_http_block_reading;
2170
+ }
2171
+
2172
+ rc = ngx_http_internal_redirect(r, &ctx->exec_uri, &ctx->exec_args);
2173
+
2174
+ dd("internal redirect returned %d when in content phase? "
2175
+ "%d", (int) rc, ctx->entered_content_phase);
2176
+
2177
+ if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE) {
2178
+ return rc;
2179
+ }
2180
+
2181
+ #if 0
2182
+ if (!ctx->entered_content_phase) {
2183
+ /* XXX ensure the main request ref count
2184
+ * is decreased because the current
2185
+ * request will be quit */
2186
+ dd("XXX decrement main count");
2187
+ r->main->count--;
2188
+ }
2189
+ #endif
2190
+
2191
+ return NGX_DONE;
2192
+ }
2193
+
2194
+
2195
+ static ngx_int_t
2196
+ ngx_http_lua_handle_exit(lua_State *L, ngx_http_request_t *r,
2197
+ ngx_http_lua_ctx_t *ctx)
2198
+ {
2199
+ ngx_int_t rc;
2200
+
2201
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
2202
+ "lua thread aborting request with status %d",
2203
+ ctx->exit_code);
2204
+
2205
+ #if 1
2206
+ if (!r->header_sent
2207
+ && r->headers_out.status == 0
2208
+ && ctx->exit_code >= NGX_HTTP_OK)
2209
+ {
2210
+ r->headers_out.status = ctx->exit_code;
2211
+ }
2212
+ #endif
2213
+
2214
+ ngx_http_lua_cleanup_pending_operation(ctx->cur_co_ctx);
2215
+
2216
+ ngx_http_lua_probe_coroutine_done(r, ctx->cur_co_ctx->co, 1);
2217
+
2218
+ ctx->cur_co_ctx->co_status = NGX_HTTP_LUA_CO_DEAD;
2219
+
2220
+ if (r->filter_finalize) {
2221
+ ngx_http_set_ctx(r, ctx, ngx_http_lua_module);
2222
+ }
2223
+
2224
+ ngx_http_lua_request_cleanup(ctx, 0);
2225
+
2226
+ if (ctx->buffering
2227
+ && r->headers_out.status
2228
+ && ctx->exit_code != NGX_ERROR
2229
+ && ctx->exit_code != NGX_HTTP_REQUEST_TIME_OUT
2230
+ && ctx->exit_code != NGX_HTTP_CLIENT_CLOSED_REQUEST
2231
+ && ctx->exit_code != NGX_HTTP_CLOSE)
2232
+ {
2233
+ rc = ngx_http_lua_send_chain_link(r, ctx, NULL /* indicate last_buf */);
2234
+
2235
+ if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE) {
2236
+ return rc;
2237
+ }
2238
+
2239
+ if (ctx->exit_code >= NGX_HTTP_OK) {
2240
+ return NGX_HTTP_OK;
2241
+ }
2242
+
2243
+ return ctx->exit_code;
2244
+ }
2245
+
2246
+ if ((ctx->exit_code == NGX_OK
2247
+ && ctx->entered_content_phase)
2248
+ || (ctx->exit_code >= NGX_HTTP_OK
2249
+ && ctx->exit_code < NGX_HTTP_SPECIAL_RESPONSE
2250
+ && ctx->exit_code != NGX_HTTP_NO_CONTENT))
2251
+ {
2252
+ rc = ngx_http_lua_send_chain_link(r, ctx, NULL /* indicate last_buf */);
2253
+
2254
+ if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE) {
2255
+ return rc;
2256
+ }
2257
+ }
2258
+
2259
+ #if 1
2260
+ if (r->header_sent
2261
+ && ctx->exit_code > NGX_OK
2262
+ && ctx->exit_code != NGX_HTTP_REQUEST_TIME_OUT
2263
+ && ctx->exit_code != NGX_HTTP_CLIENT_CLOSED_REQUEST
2264
+ && ctx->exit_code != NGX_HTTP_CLOSE)
2265
+ {
2266
+ if (ctx->entered_content_phase) {
2267
+ return NGX_OK;
2268
+ }
2269
+
2270
+ return NGX_HTTP_OK;
2271
+ }
2272
+ #endif
2273
+
2274
+ return ctx->exit_code;
2275
+ }
2276
+
2277
+
2278
+ void
2279
+ ngx_http_lua_process_args_option(ngx_http_request_t *r, lua_State *L,
2280
+ int table, ngx_str_t *args)
2281
+ {
2282
+ u_char *key;
2283
+ size_t key_len;
2284
+ u_char *value;
2285
+ size_t value_len;
2286
+ size_t len = 0;
2287
+ size_t key_escape = 0;
2288
+ uintptr_t total_escape = 0;
2289
+ int n;
2290
+ int i;
2291
+ u_char *p;
2292
+
2293
+ if (table < 0) {
2294
+ table = lua_gettop(L) + table + 1;
2295
+ }
2296
+
2297
+ n = 0;
2298
+ lua_pushnil(L);
2299
+ while (lua_next(L, table) != 0) {
2300
+ if (lua_type(L, -2) != LUA_TSTRING) {
2301
+ luaL_error(L, "attempt to use a non-string key in the "
2302
+ "\"args\" option table");
2303
+ return;
2304
+ }
2305
+
2306
+ key = (u_char *) lua_tolstring(L, -2, &key_len);
2307
+
2308
+ key_escape = 2 * ngx_http_lua_escape_uri(NULL, key, key_len,
2309
+ NGX_ESCAPE_URI);
2310
+ total_escape += key_escape;
2311
+
2312
+ switch (lua_type(L, -1)) {
2313
+ case LUA_TNUMBER:
2314
+ case LUA_TSTRING:
2315
+ value = (u_char *) lua_tolstring(L, -1, &value_len);
2316
+
2317
+ total_escape += 2 * ngx_http_lua_escape_uri(NULL, value, value_len,
2318
+ NGX_ESCAPE_URI);
2319
+
2320
+ len += key_len + value_len + (sizeof("=") - 1);
2321
+ n++;
2322
+
2323
+ break;
2324
+
2325
+ case LUA_TBOOLEAN:
2326
+ if (lua_toboolean(L, -1)) {
2327
+ len += key_len;
2328
+ n++;
2329
+ }
2330
+
2331
+ break;
2332
+
2333
+ case LUA_TTABLE:
2334
+
2335
+ i = 0;
2336
+ lua_pushnil(L);
2337
+ while (lua_next(L, -2) != 0) {
2338
+ if (lua_isboolean(L, -1)) {
2339
+ if (lua_toboolean(L, -1)) {
2340
+ len += key_len;
2341
+
2342
+ } else {
2343
+ lua_pop(L, 1);
2344
+ continue;
2345
+ }
2346
+
2347
+ } else {
2348
+ value = (u_char *) lua_tolstring(L, -1, &value_len);
2349
+
2350
+ if (value == NULL) {
2351
+ luaL_error(L, "attempt to use %s as query arg value",
2352
+ luaL_typename(L, -1));
2353
+ return;
2354
+ }
2355
+
2356
+ total_escape +=
2357
+ 2 * ngx_http_lua_escape_uri(NULL, value,
2358
+ value_len,
2359
+ NGX_ESCAPE_URI);
2360
+
2361
+ len += key_len + value_len + (sizeof("=") - 1);
2362
+ }
2363
+
2364
+ if (i++ > 0) {
2365
+ total_escape += key_escape;
2366
+ }
2367
+
2368
+ n++;
2369
+ lua_pop(L, 1);
2370
+ }
2371
+
2372
+ break;
2373
+
2374
+ default:
2375
+ luaL_error(L, "attempt to use %s as query arg value",
2376
+ luaL_typename(L, -1));
2377
+ return;
2378
+ }
2379
+
2380
+ lua_pop(L, 1);
2381
+ }
2382
+
2383
+ len += (size_t) total_escape;
2384
+
2385
+ if (n > 1) {
2386
+ len += (n - 1) * (sizeof("&") - 1);
2387
+ }
2388
+
2389
+ dd("len 1: %d", (int) len);
2390
+
2391
+ if (r) {
2392
+ p = ngx_palloc(r->pool, len);
2393
+ if (p == NULL) {
2394
+ luaL_error(L, "no memory");
2395
+ return;
2396
+ }
2397
+
2398
+ } else {
2399
+ p = lua_newuserdata(L, len);
2400
+ }
2401
+
2402
+ args->data = p;
2403
+ args->len = len;
2404
+
2405
+ i = 0;
2406
+ lua_pushnil(L);
2407
+ while (lua_next(L, table) != 0) {
2408
+ key = (u_char *) lua_tolstring(L, -2, &key_len);
2409
+
2410
+ switch (lua_type(L, -1)) {
2411
+ case LUA_TNUMBER:
2412
+ case LUA_TSTRING:
2413
+
2414
+ if (total_escape) {
2415
+ p = (u_char *) ngx_http_lua_escape_uri(p, key, key_len,
2416
+ NGX_ESCAPE_URI);
2417
+
2418
+ } else {
2419
+ dd("shortcut: no escape required");
2420
+
2421
+ p = ngx_copy(p, key, key_len);
2422
+ }
2423
+
2424
+ *p++ = '=';
2425
+
2426
+ value = (u_char *) lua_tolstring(L, -1, &value_len);
2427
+
2428
+ if (total_escape) {
2429
+ p = (u_char *) ngx_http_lua_escape_uri(p, value, value_len,
2430
+ NGX_ESCAPE_URI);
2431
+
2432
+ } else {
2433
+ p = ngx_copy(p, value, value_len);
2434
+ }
2435
+
2436
+ if (i != n - 1) {
2437
+ /* not the last pair */
2438
+ *p++ = '&';
2439
+ }
2440
+
2441
+ i++;
2442
+
2443
+ break;
2444
+
2445
+ case LUA_TBOOLEAN:
2446
+ if (lua_toboolean(L, -1)) {
2447
+ if (total_escape) {
2448
+ p = (u_char *) ngx_http_lua_escape_uri(p, key, key_len,
2449
+ NGX_ESCAPE_URI);
2450
+
2451
+ } else {
2452
+ dd("shortcut: no escape required");
2453
+
2454
+ p = ngx_copy(p, key, key_len);
2455
+ }
2456
+
2457
+ if (i != n - 1) {
2458
+ /* not the last pair */
2459
+ *p++ = '&';
2460
+ }
2461
+
2462
+ i++;
2463
+ }
2464
+
2465
+ break;
2466
+
2467
+ case LUA_TTABLE:
2468
+
2469
+ lua_pushnil(L);
2470
+ while (lua_next(L, -2) != 0) {
2471
+
2472
+ if (lua_isboolean(L, -1)) {
2473
+ if (lua_toboolean(L, -1)) {
2474
+ if (total_escape) {
2475
+ p = (u_char *) ngx_http_lua_escape_uri(p, key,
2476
+ key_len,
2477
+ NGX_ESCAPE_URI);
2478
+
2479
+ } else {
2480
+ dd("shortcut: no escape required");
2481
+
2482
+ p = ngx_copy(p, key, key_len);
2483
+ }
2484
+
2485
+ } else {
2486
+ lua_pop(L, 1);
2487
+ continue;
2488
+ }
2489
+
2490
+ } else {
2491
+
2492
+ if (total_escape) {
2493
+ p = (u_char *)
2494
+ ngx_http_lua_escape_uri(p, key,
2495
+ key_len,
2496
+ NGX_ESCAPE_URI);
2497
+
2498
+ } else {
2499
+ dd("shortcut: no escape required");
2500
+
2501
+ p = ngx_copy(p, key, key_len);
2502
+ }
2503
+
2504
+ *p++ = '=';
2505
+
2506
+ value = (u_char *) lua_tolstring(L, -1, &value_len);
2507
+
2508
+ if (total_escape) {
2509
+ p = (u_char *)
2510
+ ngx_http_lua_escape_uri(p, value,
2511
+ value_len,
2512
+ NGX_ESCAPE_URI);
2513
+
2514
+ } else {
2515
+ p = ngx_copy(p, value, value_len);
2516
+ }
2517
+ }
2518
+
2519
+ if (i != n - 1) {
2520
+ /* not the last pair */
2521
+ *p++ = '&';
2522
+ }
2523
+
2524
+ i++;
2525
+ lua_pop(L, 1);
2526
+ }
2527
+
2528
+ break;
2529
+
2530
+ default:
2531
+ luaL_error(L, "should not reach here");
2532
+ return;
2533
+ }
2534
+
2535
+ lua_pop(L, 1);
2536
+ }
2537
+
2538
+ if (p - args->data != (ssize_t) len) {
2539
+ luaL_error(L, "buffer error: %d != %d",
2540
+ (int) (p - args->data), (int) len);
2541
+ return;
2542
+ }
2543
+ }
2544
+
2545
+
2546
+ static ngx_int_t
2547
+ ngx_http_lua_handle_rewrite_jump(lua_State *L, ngx_http_request_t *r,
2548
+ ngx_http_lua_ctx_t *ctx)
2549
+ {
2550
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
2551
+ "lua thread aborting request with URI rewrite jump: "
2552
+ "\"%V?%V\"", &r->uri, &r->args);
2553
+
2554
+ ngx_http_lua_cleanup_pending_operation(ctx->cur_co_ctx);
2555
+
2556
+ ngx_http_lua_probe_coroutine_done(r, ctx->cur_co_ctx->co, 1);
2557
+
2558
+ ctx->cur_co_ctx->co_status = NGX_HTTP_LUA_CO_DEAD;
2559
+
2560
+ if (r->filter_finalize) {
2561
+ ngx_http_set_ctx(r, ctx, ngx_http_lua_module);
2562
+ }
2563
+
2564
+ ngx_http_lua_request_cleanup(ctx, 1 /* forcible */);
2565
+ ngx_http_lua_init_ctx(r, ctx);
2566
+
2567
+ return NGX_OK;
2568
+ }
2569
+
2570
+
2571
+ /* XXX ngx_open_and_stat_file is static in the core. sigh. */
2572
+ ngx_int_t
2573
+ ngx_http_lua_open_and_stat_file(u_char *name, ngx_open_file_info_t *of,
2574
+ ngx_log_t *log)
2575
+ {
2576
+ ngx_fd_t fd;
2577
+ ngx_file_info_t fi;
2578
+
2579
+ if (of->fd != NGX_INVALID_FILE) {
2580
+
2581
+ if (ngx_file_info(name, &fi) == NGX_FILE_ERROR) {
2582
+ of->failed = ngx_file_info_n;
2583
+ goto failed;
2584
+ }
2585
+
2586
+ if (of->uniq == ngx_file_uniq(&fi)) {
2587
+ goto done;
2588
+ }
2589
+
2590
+ } else if (of->test_dir) {
2591
+
2592
+ if (ngx_file_info(name, &fi) == NGX_FILE_ERROR) {
2593
+ of->failed = ngx_file_info_n;
2594
+ goto failed;
2595
+ }
2596
+
2597
+ if (ngx_is_dir(&fi)) {
2598
+ goto done;
2599
+ }
2600
+ }
2601
+
2602
+ if (!of->log) {
2603
+
2604
+ /*
2605
+ * Use non-blocking open() not to hang on FIFO files, etc.
2606
+ * This flag has no effect on a regular files.
2607
+ */
2608
+
2609
+ fd = ngx_open_file(name, NGX_FILE_RDONLY|NGX_FILE_NONBLOCK,
2610
+ NGX_FILE_OPEN, 0);
2611
+
2612
+ } else {
2613
+ fd = ngx_open_file(name, NGX_FILE_APPEND, NGX_FILE_CREATE_OR_OPEN,
2614
+ NGX_FILE_DEFAULT_ACCESS);
2615
+ }
2616
+
2617
+ if (fd == NGX_INVALID_FILE) {
2618
+ of->failed = ngx_open_file_n;
2619
+ goto failed;
2620
+ }
2621
+
2622
+ if (ngx_fd_info(fd, &fi) == NGX_FILE_ERROR) {
2623
+ ngx_log_error(NGX_LOG_CRIT, log, ngx_errno,
2624
+ ngx_fd_info_n " \"%s\" failed", name);
2625
+
2626
+ if (ngx_close_file(fd) == NGX_FILE_ERROR) {
2627
+ ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
2628
+ ngx_close_file_n " \"%s\" failed", name);
2629
+ }
2630
+
2631
+ of->fd = NGX_INVALID_FILE;
2632
+
2633
+ return NGX_ERROR;
2634
+ }
2635
+
2636
+ if (ngx_is_dir(&fi)) {
2637
+ if (ngx_close_file(fd) == NGX_FILE_ERROR) {
2638
+ ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
2639
+ ngx_close_file_n " \"%s\" failed", name);
2640
+ }
2641
+
2642
+ of->fd = NGX_INVALID_FILE;
2643
+
2644
+ } else {
2645
+ of->fd = fd;
2646
+
2647
+ if (of->directio <= ngx_file_size(&fi)) {
2648
+ if (ngx_directio_on(fd) == NGX_FILE_ERROR) {
2649
+ ngx_log_error(NGX_LOG_ALERT, log, ngx_errno,
2650
+ ngx_directio_on_n " \"%s\" failed", name);
2651
+
2652
+ } else {
2653
+ of->is_directio = 1;
2654
+ }
2655
+ }
2656
+ }
2657
+
2658
+ done:
2659
+
2660
+ of->uniq = ngx_file_uniq(&fi);
2661
+ of->mtime = ngx_file_mtime(&fi);
2662
+ of->size = ngx_file_size(&fi);
2663
+ #if defined(nginx_version) && nginx_version >= 1000001
2664
+ of->fs_size = ngx_file_fs_size(&fi);
2665
+ #endif
2666
+ of->is_dir = ngx_is_dir(&fi);
2667
+ of->is_file = ngx_is_file(&fi);
2668
+ of->is_link = ngx_is_link(&fi);
2669
+ of->is_exec = ngx_is_exec(&fi);
2670
+
2671
+ return NGX_OK;
2672
+
2673
+ failed:
2674
+
2675
+ of->fd = NGX_INVALID_FILE;
2676
+ of->err = ngx_errno;
2677
+
2678
+ return NGX_ERROR;
2679
+ }
2680
+
2681
+
2682
+ ngx_chain_t *
2683
+ ngx_http_lua_chain_get_free_buf(ngx_log_t *log, ngx_pool_t *p,
2684
+ ngx_chain_t **free, size_t len)
2685
+ {
2686
+ ngx_buf_t *b;
2687
+ ngx_chain_t *cl;
2688
+ u_char *start, *end;
2689
+
2690
+ const ngx_buf_tag_t tag = (ngx_buf_tag_t) &ngx_http_lua_module;
2691
+
2692
+ if (*free) {
2693
+ cl = *free;
2694
+ *free = cl->next;
2695
+ cl->next = NULL;
2696
+
2697
+ b = cl->buf;
2698
+ start = b->start;
2699
+ end = b->end;
2700
+ if (start && (size_t) (end - start) >= len) {
2701
+ ngx_log_debug4(NGX_LOG_DEBUG_HTTP, log, 0,
2702
+ "lua reuse free buf memory %O >= %uz, cl:%p, p:%p",
2703
+ (off_t) (end - start), len, cl, start);
2704
+
2705
+ ngx_memzero(b, sizeof(ngx_buf_t));
2706
+
2707
+ b->start = start;
2708
+ b->pos = start;
2709
+ b->last = start;
2710
+ b->end = end;
2711
+ b->tag = tag;
2712
+
2713
+ if (len) {
2714
+ b->temporary = 1;
2715
+ }
2716
+
2717
+ return cl;
2718
+ }
2719
+
2720
+ ngx_log_debug4(NGX_LOG_DEBUG_HTTP, log, 0,
2721
+ "lua reuse free buf chain, but reallocate memory "
2722
+ "because %uz >= %O, cl:%p, p:%p", len,
2723
+ (off_t) (b->end - b->start), cl, b->start);
2724
+
2725
+ if (ngx_buf_in_memory(b) && b->start) {
2726
+ ngx_pfree(p, b->start);
2727
+ }
2728
+
2729
+ ngx_memzero(b, sizeof(ngx_buf_t));
2730
+
2731
+ if (len == 0) {
2732
+ return cl;
2733
+ }
2734
+
2735
+ b->start = ngx_palloc(p, len);
2736
+ if (b->start == NULL) {
2737
+ return NULL;
2738
+ }
2739
+
2740
+ b->end = b->start + len;
2741
+
2742
+ dd("buf start: %p", cl->buf->start);
2743
+
2744
+ b->pos = b->start;
2745
+ b->last = b->start;
2746
+ b->tag = tag;
2747
+ b->temporary = 1;
2748
+
2749
+ return cl;
2750
+ }
2751
+
2752
+ cl = ngx_alloc_chain_link(p);
2753
+ if (cl == NULL) {
2754
+ return NULL;
2755
+ }
2756
+
2757
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, log, 0,
2758
+ "lua allocate new chainlink and new buf of size %uz, cl:%p",
2759
+ len, cl);
2760
+
2761
+ cl->buf = len ? ngx_create_temp_buf(p, len) : ngx_calloc_buf(p);
2762
+ if (cl->buf == NULL) {
2763
+ return NULL;
2764
+ }
2765
+
2766
+ dd("buf start: %p", cl->buf->start);
2767
+
2768
+ cl->buf->tag = tag;
2769
+ cl->next = NULL;
2770
+
2771
+ return cl;
2772
+ }
2773
+
2774
+
2775
+ static int
2776
+ ngx_http_lua_thread_traceback(lua_State *L, lua_State *co,
2777
+ ngx_http_lua_co_ctx_t *coctx)
2778
+ {
2779
+ int base;
2780
+ int level, coid;
2781
+ lua_Debug ar;
2782
+
2783
+ base = lua_gettop(L);
2784
+ lua_checkstack(L, 3);
2785
+ lua_pushliteral(L, "stack traceback:");
2786
+ coid = 0;
2787
+
2788
+ while (co) {
2789
+
2790
+ if (coid >= NGX_HTTP_LUA_BT_MAX_COROS) {
2791
+ break;
2792
+ }
2793
+
2794
+ lua_checkstack(L, 2);
2795
+ lua_pushfstring(L, "\ncoroutine %d:", coid++);
2796
+
2797
+ level = 0;
2798
+
2799
+ while (lua_getstack(co, level++, &ar)) {
2800
+
2801
+ lua_checkstack(L, 5);
2802
+
2803
+ if (level > NGX_HTTP_LUA_BT_DEPTH) {
2804
+ lua_pushliteral(L, "\n\t...");
2805
+ break;
2806
+ }
2807
+
2808
+ lua_pushliteral(L, "\n\t");
2809
+ lua_getinfo(co, "Snl", &ar);
2810
+ lua_pushfstring(L, "%s:", ar.short_src);
2811
+
2812
+ if (ar.currentline > 0) {
2813
+ lua_pushfstring(L, "%d:", ar.currentline);
2814
+ }
2815
+
2816
+ if (*ar.namewhat != '\0') { /* is there a name? */
2817
+ lua_pushfstring(L, " in function " LUA_QS, ar.name);
2818
+
2819
+ } else {
2820
+ if (*ar.what == 'm') { /* main? */
2821
+ lua_pushliteral(L, " in main chunk");
2822
+
2823
+ } else if (*ar.what == 'C' || *ar.what == 't') {
2824
+ lua_pushliteral(L, " ?"); /* C function or tail call */
2825
+
2826
+ } else {
2827
+ lua_pushfstring(L, " in function <%s:%d>",
2828
+ ar.short_src, ar.linedefined);
2829
+ }
2830
+ }
2831
+ }
2832
+
2833
+ if (lua_gettop(L) - base >= 15) {
2834
+ lua_concat(L, lua_gettop(L) - base);
2835
+ }
2836
+
2837
+ /* check if the coroutine has a parent coroutine*/
2838
+ coctx = coctx->parent_co_ctx;
2839
+ if (!coctx || coctx->co_status == NGX_HTTP_LUA_CO_DEAD) {
2840
+ break;
2841
+ }
2842
+
2843
+ co = coctx->co;
2844
+ }
2845
+
2846
+ lua_concat(L, lua_gettop(L) - base);
2847
+ return 1;
2848
+ }
2849
+
2850
+
2851
+ int
2852
+ ngx_http_lua_traceback(lua_State *L)
2853
+ {
2854
+ if (!lua_isstring(L, 1)) { /* 'message' not a string? */
2855
+ return 1; /* keep it intact */
2856
+ }
2857
+
2858
+ lua_getglobal(L, "debug");
2859
+ if (!lua_istable(L, -1)) {
2860
+ lua_pop(L, 1);
2861
+ return 1;
2862
+ }
2863
+
2864
+ lua_getfield(L, -1, "traceback");
2865
+ if (!lua_isfunction(L, -1)) {
2866
+ lua_pop(L, 2);
2867
+ return 1;
2868
+ }
2869
+
2870
+ lua_pushvalue(L, 1); /* pass error message */
2871
+ lua_pushinteger(L, 2); /* skip this function and traceback */
2872
+ lua_call(L, 2, 1); /* call debug.traceback */
2873
+ return 1;
2874
+ }
2875
+
2876
+
2877
+ static void
2878
+ ngx_http_lua_inject_arg_api(lua_State *L)
2879
+ {
2880
+ lua_pushliteral(L, "arg");
2881
+ lua_newtable(L); /* .arg table aka {} */
2882
+
2883
+ lua_createtable(L, 0 /* narr */, 2 /* nrec */); /* the metatable */
2884
+
2885
+ lua_pushcfunction(L, ngx_http_lua_param_get);
2886
+ lua_setfield(L, -2, "__index");
2887
+
2888
+ lua_pushcfunction(L, ngx_http_lua_param_set);
2889
+ lua_setfield(L, -2, "__newindex");
2890
+
2891
+ lua_setmetatable(L, -2); /* tie the metatable to param table */
2892
+
2893
+ dd("top: %d, type -1: %s", lua_gettop(L), luaL_typename(L, -1));
2894
+
2895
+ lua_rawset(L, -3); /* set ngx.arg table */
2896
+ }
2897
+
2898
+
2899
+ static int
2900
+ ngx_http_lua_param_get(lua_State *L)
2901
+ {
2902
+ ngx_http_lua_ctx_t *ctx;
2903
+ ngx_http_request_t *r;
2904
+
2905
+ r = ngx_http_lua_get_req(L);
2906
+ if (r == NULL) {
2907
+ return 0;
2908
+ }
2909
+
2910
+ ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
2911
+ if (ctx == NULL) {
2912
+ return luaL_error(L, "ctx not found");
2913
+ }
2914
+
2915
+ ngx_http_lua_check_context(L, ctx, NGX_HTTP_LUA_CONTEXT_SET
2916
+ | NGX_HTTP_LUA_CONTEXT_BODY_FILTER);
2917
+
2918
+ if (ctx->context & (NGX_HTTP_LUA_CONTEXT_SET)) {
2919
+ return ngx_http_lua_setby_param_get(L);
2920
+ }
2921
+
2922
+ /* ctx->context & (NGX_HTTP_LUA_CONTEXT_BODY_FILTER) */
2923
+
2924
+ return ngx_http_lua_body_filter_param_get(L);
2925
+ }
2926
+
2927
+
2928
+ static int
2929
+ ngx_http_lua_param_set(lua_State *L)
2930
+ {
2931
+ ngx_http_lua_ctx_t *ctx;
2932
+ ngx_http_request_t *r;
2933
+
2934
+ r = ngx_http_lua_get_req(L);
2935
+ if (r == NULL) {
2936
+ return 0;
2937
+ }
2938
+
2939
+ ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
2940
+ if (ctx == NULL) {
2941
+ return luaL_error(L, "ctx not found");
2942
+ }
2943
+
2944
+ ngx_http_lua_check_context(L, ctx, NGX_HTTP_LUA_CONTEXT_BODY_FILTER);
2945
+
2946
+ return ngx_http_lua_body_filter_param_set(L, r, ctx);
2947
+ }
2948
+
2949
+
2950
+ ngx_http_lua_co_ctx_t *
2951
+ ngx_http_lua_get_co_ctx(lua_State *L, ngx_http_lua_ctx_t *ctx)
2952
+ {
2953
+ ngx_uint_t i;
2954
+ ngx_list_part_t *part;
2955
+ ngx_http_lua_co_ctx_t *coctx;
2956
+
2957
+ if (L == ctx->entry_co_ctx.co) {
2958
+ return &ctx->entry_co_ctx;
2959
+ }
2960
+
2961
+ if (ctx->user_co_ctx == NULL) {
2962
+ return NULL;
2963
+ }
2964
+
2965
+ part = &ctx->user_co_ctx->part;
2966
+ coctx = part->elts;
2967
+
2968
+ /* FIXME: we should use rbtree here to prevent O(n) lookup overhead */
2969
+
2970
+ for (i = 0; /* void */; i++) {
2971
+
2972
+ if (i >= part->nelts) {
2973
+ if (part->next == NULL) {
2974
+ break;
2975
+ }
2976
+
2977
+ part = part->next;
2978
+ coctx = part->elts;
2979
+ i = 0;
2980
+ }
2981
+
2982
+ if (coctx[i].co == L) {
2983
+ return &coctx[i];
2984
+ }
2985
+ }
2986
+
2987
+ return NULL;
2988
+ }
2989
+
2990
+
2991
+ ngx_http_lua_co_ctx_t *
2992
+ ngx_http_lua_create_co_ctx(ngx_http_request_t *r, ngx_http_lua_ctx_t *ctx)
2993
+ {
2994
+ ngx_http_lua_co_ctx_t *coctx;
2995
+
2996
+ if (ctx->user_co_ctx == NULL) {
2997
+ ctx->user_co_ctx = ngx_list_create(r->pool, 4,
2998
+ sizeof(ngx_http_lua_co_ctx_t));
2999
+ if (ctx->user_co_ctx == NULL) {
3000
+ return NULL;
3001
+ }
3002
+ }
3003
+
3004
+ coctx = ngx_list_push(ctx->user_co_ctx);
3005
+ if (coctx == NULL) {
3006
+ return NULL;
3007
+ }
3008
+
3009
+ ngx_memzero(coctx, sizeof(ngx_http_lua_co_ctx_t));
3010
+
3011
+ coctx->co_ref = LUA_NOREF;
3012
+
3013
+ return coctx;
3014
+ }
3015
+
3016
+
3017
+ /* this is for callers other than the content handler */
3018
+ ngx_int_t
3019
+ ngx_http_lua_run_posted_threads(ngx_connection_t *c, lua_State *L,
3020
+ ngx_http_request_t *r, ngx_http_lua_ctx_t *ctx)
3021
+ {
3022
+ ngx_int_t rc;
3023
+ ngx_http_lua_posted_thread_t *pt;
3024
+
3025
+ for ( ;; ) {
3026
+ if (c->destroyed) {
3027
+ return NGX_DONE;
3028
+ }
3029
+
3030
+ pt = ctx->posted_threads;
3031
+ if (pt == NULL) {
3032
+ return NGX_DONE;
3033
+ }
3034
+
3035
+ ctx->posted_threads = pt->next;
3036
+
3037
+ ngx_http_lua_probe_run_posted_thread(r, pt->co_ctx->co,
3038
+ (int) pt->co_ctx->co_status);
3039
+
3040
+ if (pt->co_ctx->co_status != NGX_HTTP_LUA_CO_RUNNING) {
3041
+ continue;
3042
+ }
3043
+
3044
+ ctx->cur_co_ctx = pt->co_ctx;
3045
+
3046
+ rc = ngx_http_lua_run_thread(L, r, ctx, 0);
3047
+
3048
+ if (rc == NGX_AGAIN) {
3049
+ continue;
3050
+ }
3051
+
3052
+ if (rc == NGX_DONE) {
3053
+ ngx_http_lua_finalize_request(r, NGX_DONE);
3054
+ continue;
3055
+ }
3056
+
3057
+ /* rc == NGX_ERROR || rc >= NGX_OK */
3058
+
3059
+ if (ctx->entered_content_phase) {
3060
+ ngx_http_lua_finalize_request(r, rc);
3061
+ }
3062
+
3063
+ return rc;
3064
+ }
3065
+
3066
+ /* impossible to reach here */
3067
+ }
3068
+
3069
+
3070
+ ngx_int_t
3071
+ ngx_http_lua_post_thread(ngx_http_request_t *r, ngx_http_lua_ctx_t *ctx,
3072
+ ngx_http_lua_co_ctx_t *coctx)
3073
+ {
3074
+ ngx_http_lua_posted_thread_t **p;
3075
+ ngx_http_lua_posted_thread_t *pt;
3076
+
3077
+ pt = ngx_palloc(r->pool, sizeof(ngx_http_lua_posted_thread_t));
3078
+ if (pt == NULL) {
3079
+ return NGX_ERROR;
3080
+ }
3081
+
3082
+ pt->co_ctx = coctx;
3083
+ pt->next = NULL;
3084
+
3085
+ for (p = &ctx->posted_threads; *p; p = &(*p)->next) { /* void */ }
3086
+
3087
+ *p = pt;
3088
+
3089
+ return NGX_OK;
3090
+ }
3091
+
3092
+
3093
+ static void
3094
+ ngx_http_lua_finalize_threads(ngx_http_request_t *r,
3095
+ ngx_http_lua_ctx_t *ctx, lua_State *L)
3096
+ {
3097
+ #ifdef NGX_LUA_USE_ASSERT
3098
+ int top;
3099
+ #endif
3100
+ int inited = 0, ref;
3101
+ ngx_uint_t i;
3102
+ ngx_list_part_t *part;
3103
+ ngx_http_lua_co_ctx_t *cc, *coctx;
3104
+
3105
+ #ifdef NGX_LUA_USE_ASSERT
3106
+ top = lua_gettop(L);
3107
+ #endif
3108
+
3109
+ #if 1
3110
+ coctx = ctx->on_abort_co_ctx;
3111
+ if (coctx && coctx->co_ref != LUA_NOREF) {
3112
+ if (coctx->co_status != NGX_HTTP_LUA_CO_SUSPENDED) {
3113
+ /* the on_abort thread contributes to the coctx->uthreads
3114
+ * counter only when it actually starts running */
3115
+ ngx_http_lua_cleanup_pending_operation(coctx);
3116
+ ctx->uthreads--;
3117
+ }
3118
+
3119
+ ngx_http_lua_probe_thread_delete(r, coctx->co, ctx);
3120
+
3121
+ lua_pushlightuserdata(L, &ngx_http_lua_coroutines_key);
3122
+ lua_rawget(L, LUA_REGISTRYINDEX);
3123
+ inited = 1;
3124
+
3125
+ luaL_unref(L, -1, coctx->co_ref);
3126
+ coctx->co_ref = LUA_NOREF;
3127
+
3128
+ coctx->co_status = NGX_HTTP_LUA_CO_DEAD;
3129
+ ctx->on_abort_co_ctx = NULL;
3130
+ }
3131
+ #endif
3132
+
3133
+ if (ctx->user_co_ctx) {
3134
+ part = &ctx->user_co_ctx->part;
3135
+ cc = part->elts;
3136
+
3137
+ for (i = 0; /* void */; i++) {
3138
+
3139
+ if (i >= part->nelts) {
3140
+ if (part->next == NULL) {
3141
+ break;
3142
+ }
3143
+
3144
+ part = part->next;
3145
+ cc = part->elts;
3146
+ i = 0;
3147
+ }
3148
+
3149
+ coctx = &cc[i];
3150
+
3151
+ ref = coctx->co_ref;
3152
+
3153
+ if (ref != LUA_NOREF) {
3154
+ ngx_http_lua_cleanup_pending_operation(coctx);
3155
+
3156
+ ngx_http_lua_probe_thread_delete(r, coctx->co, ctx);
3157
+
3158
+ if (!inited) {
3159
+ lua_pushlightuserdata(L, &ngx_http_lua_coroutines_key);
3160
+ lua_rawget(L, LUA_REGISTRYINDEX);
3161
+ inited = 1;
3162
+ }
3163
+
3164
+ ngx_http_lua_assert(lua_gettop(L) - top == 1);
3165
+
3166
+ luaL_unref(L, -1, ref);
3167
+ coctx->co_ref = LUA_NOREF;
3168
+
3169
+ coctx->co_status = NGX_HTTP_LUA_CO_DEAD;
3170
+ ctx->uthreads--;
3171
+ }
3172
+ }
3173
+
3174
+ ctx->user_co_ctx = NULL;
3175
+ }
3176
+
3177
+ ngx_http_lua_assert(ctx->uthreads == 0);
3178
+
3179
+ coctx = &ctx->entry_co_ctx;
3180
+
3181
+ ref = coctx->co_ref;
3182
+ if (ref != LUA_NOREF) {
3183
+ ngx_http_lua_cleanup_pending_operation(coctx);
3184
+
3185
+ ngx_http_lua_probe_thread_delete(r, coctx->co, ctx);
3186
+
3187
+ if (!inited) {
3188
+ lua_pushlightuserdata(L, &ngx_http_lua_coroutines_key);
3189
+ lua_rawget(L, LUA_REGISTRYINDEX);
3190
+ inited = 1;
3191
+ }
3192
+
3193
+ ngx_http_lua_assert(lua_gettop(L) - top == 1);
3194
+
3195
+ luaL_unref(L, -1, coctx->co_ref);
3196
+ coctx->co_ref = LUA_NOREF;
3197
+ coctx->co_status = NGX_HTTP_LUA_CO_DEAD;
3198
+ }
3199
+
3200
+ if (inited) {
3201
+ lua_pop(L, 1);
3202
+ }
3203
+ }
3204
+
3205
+
3206
+ static ngx_int_t
3207
+ ngx_http_lua_post_zombie_thread(ngx_http_request_t *r,
3208
+ ngx_http_lua_co_ctx_t *parent, ngx_http_lua_co_ctx_t *thread)
3209
+ {
3210
+ ngx_http_lua_posted_thread_t **p;
3211
+ ngx_http_lua_posted_thread_t *pt;
3212
+
3213
+ pt = ngx_palloc(r->pool, sizeof(ngx_http_lua_posted_thread_t));
3214
+ if (pt == NULL) {
3215
+ return NGX_ERROR;
3216
+ }
3217
+
3218
+ pt->co_ctx = thread;
3219
+ pt->next = NULL;
3220
+
3221
+ for (p = &parent->zombie_child_threads; *p; p = &(*p)->next) { /* void */ }
3222
+
3223
+ *p = pt;
3224
+
3225
+ return NGX_OK;
3226
+ }
3227
+
3228
+
3229
+ static void
3230
+ ngx_http_lua_cleanup_zombie_child_uthreads(ngx_http_request_t *r,
3231
+ lua_State *L, ngx_http_lua_ctx_t *ctx, ngx_http_lua_co_ctx_t *coctx)
3232
+ {
3233
+ ngx_http_lua_posted_thread_t *pt;
3234
+
3235
+ for (pt = coctx->zombie_child_threads; pt; pt = pt->next) {
3236
+ if (pt->co_ctx->co_ref != LUA_NOREF) {
3237
+ ngx_http_lua_del_thread(r, L, ctx, pt->co_ctx);
3238
+ ctx->uthreads--;
3239
+ }
3240
+ }
3241
+
3242
+ coctx->zombie_child_threads = NULL;
3243
+ }
3244
+
3245
+
3246
+ ngx_int_t
3247
+ ngx_http_lua_check_broken_connection(ngx_http_request_t *r, ngx_event_t *ev)
3248
+ {
3249
+ int n;
3250
+ char buf[1];
3251
+ ngx_err_t err;
3252
+ ngx_int_t event;
3253
+ ngx_connection_t *c;
3254
+
3255
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, ev->log, 0,
3256
+ "http lua check client, write event:%d, \"%V\"",
3257
+ ev->write, &r->uri);
3258
+
3259
+ c = r->connection;
3260
+
3261
+ if (c->error) {
3262
+ if ((ngx_event_flags & NGX_USE_LEVEL_EVENT) && ev->active) {
3263
+
3264
+ event = ev->write ? NGX_WRITE_EVENT : NGX_READ_EVENT;
3265
+
3266
+ if (ngx_del_event(ev, event, 0) != NGX_OK) {
3267
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
3268
+ }
3269
+ }
3270
+
3271
+ return NGX_HTTP_CLIENT_CLOSED_REQUEST;
3272
+ }
3273
+
3274
+ #if (NGX_HAVE_KQUEUE)
3275
+
3276
+ if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {
3277
+
3278
+ if (!ev->pending_eof) {
3279
+ return NGX_OK;
3280
+ }
3281
+
3282
+ ev->eof = 1;
3283
+
3284
+ if (ev->kq_errno) {
3285
+ ev->error = 1;
3286
+ }
3287
+
3288
+ ngx_log_error(NGX_LOG_INFO, ev->log, ev->kq_errno,
3289
+ "kevent() reported that client prematurely closed "
3290
+ "connection");
3291
+
3292
+ return NGX_HTTP_CLIENT_CLOSED_REQUEST;
3293
+ }
3294
+
3295
+ #endif
3296
+
3297
+ n = recv(c->fd, buf, 1, MSG_PEEK);
3298
+
3299
+ err = ngx_socket_errno;
3300
+
3301
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ev->log, err,
3302
+ "http lua recv(): %d", n);
3303
+
3304
+ if (ev->write && (n >= 0 || err == NGX_EAGAIN)) {
3305
+ return NGX_OK;
3306
+ }
3307
+
3308
+ if ((ngx_event_flags & NGX_USE_LEVEL_EVENT) && ev->active) {
3309
+ dd("event is active");
3310
+
3311
+ event = ev->write ? NGX_WRITE_EVENT : NGX_READ_EVENT;
3312
+
3313
+ #if 1
3314
+ if (ngx_del_event(ev, event, 0) != NGX_OK) {
3315
+ return NGX_HTTP_INTERNAL_SERVER_ERROR;
3316
+ }
3317
+ #endif
3318
+ }
3319
+
3320
+ dd("HERE %d", (int) n);
3321
+
3322
+ if (n > 0) {
3323
+ return NGX_OK;
3324
+ }
3325
+
3326
+ if (n == -1) {
3327
+ if (err == NGX_EAGAIN) {
3328
+ dd("HERE");
3329
+ return NGX_OK;
3330
+ }
3331
+
3332
+ ev->error = 1;
3333
+
3334
+ } else { /* n == 0 */
3335
+ err = 0;
3336
+ }
3337
+
3338
+ ev->eof = 1;
3339
+
3340
+ ngx_log_error(NGX_LOG_INFO, ev->log, err,
3341
+ "client prematurely closed connection");
3342
+
3343
+ return NGX_HTTP_CLIENT_CLOSED_REQUEST;
3344
+ }
3345
+
3346
+
3347
+ void
3348
+ ngx_http_lua_rd_check_broken_connection(ngx_http_request_t *r)
3349
+ {
3350
+ ngx_int_t rc;
3351
+ ngx_event_t *rev;
3352
+ ngx_http_lua_ctx_t *ctx;
3353
+
3354
+ if (r->done) {
3355
+ return;
3356
+ }
3357
+
3358
+ rc = ngx_http_lua_check_broken_connection(r, r->connection->read);
3359
+
3360
+ if (rc == NGX_OK) {
3361
+ return;
3362
+ }
3363
+
3364
+ /* rc == NGX_ERROR || rc > NGX_OK */
3365
+
3366
+ ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
3367
+ if (ctx == NULL) {
3368
+ return;
3369
+ }
3370
+
3371
+ if (ctx->on_abort_co_ctx == NULL) {
3372
+ r->connection->error = 1;
3373
+ ngx_http_lua_request_cleanup(ctx, 0);
3374
+ ngx_http_lua_finalize_request(r, rc);
3375
+ return;
3376
+ }
3377
+
3378
+ if (ctx->on_abort_co_ctx->co_status != NGX_HTTP_LUA_CO_SUSPENDED) {
3379
+
3380
+ /* on_abort already run for the current request handler */
3381
+
3382
+ rev = r->connection->read;
3383
+
3384
+ if ((ngx_event_flags & NGX_USE_LEVEL_EVENT) && rev->active) {
3385
+ if (ngx_del_event(rev, NGX_READ_EVENT, 0) != NGX_OK) {
3386
+ ngx_http_lua_request_cleanup(ctx, 0);
3387
+ ngx_http_lua_finalize_request(r,
3388
+ NGX_HTTP_INTERNAL_SERVER_ERROR);
3389
+ return;
3390
+ }
3391
+ }
3392
+
3393
+ return;
3394
+ }
3395
+
3396
+ ctx->uthreads++;
3397
+ ctx->resume_handler = ngx_http_lua_on_abort_resume;
3398
+ ctx->on_abort_co_ctx->co_status = NGX_HTTP_LUA_CO_RUNNING;
3399
+ ctx->cur_co_ctx = ctx->on_abort_co_ctx;
3400
+
3401
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
3402
+ "lua waking up the on_abort callback thread");
3403
+
3404
+ if (ctx->entered_content_phase) {
3405
+ r->write_event_handler = ngx_http_lua_content_wev_handler;
3406
+
3407
+ } else {
3408
+ r->write_event_handler = ngx_http_core_run_phases;
3409
+ }
3410
+
3411
+ r->write_event_handler(r);
3412
+ }
3413
+
3414
+
3415
+ static ngx_int_t
3416
+ ngx_http_lua_on_abort_resume(ngx_http_request_t *r)
3417
+ {
3418
+ lua_State *vm;
3419
+ ngx_int_t rc;
3420
+ ngx_connection_t *c;
3421
+ ngx_http_lua_ctx_t *ctx;
3422
+
3423
+ ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
3424
+ if (ctx == NULL) {
3425
+ return NGX_ERROR;
3426
+ }
3427
+
3428
+ ctx->resume_handler = ngx_http_lua_wev_handler;
3429
+
3430
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
3431
+ "lua resuming the on_abort callback thread");
3432
+
3433
+ #if 0
3434
+ ngx_http_lua_probe_info("tcp resume");
3435
+ #endif
3436
+
3437
+ c = r->connection;
3438
+ vm = ngx_http_lua_get_lua_vm(r, ctx);
3439
+
3440
+ rc = ngx_http_lua_run_thread(vm, r, ctx, 0);
3441
+
3442
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
3443
+ "lua run thread returned %d", rc);
3444
+
3445
+ if (rc == NGX_AGAIN) {
3446
+ return ngx_http_lua_run_posted_threads(c, vm, r, ctx);
3447
+ }
3448
+
3449
+ if (rc == NGX_DONE) {
3450
+ ngx_http_lua_finalize_request(r, NGX_DONE);
3451
+ return ngx_http_lua_run_posted_threads(c, vm, r, ctx);
3452
+ }
3453
+
3454
+ if (ctx->entered_content_phase) {
3455
+ ngx_http_lua_finalize_request(r, rc);
3456
+ return NGX_DONE;
3457
+ }
3458
+
3459
+ return rc;
3460
+ }
3461
+
3462
+
3463
+ ngx_int_t
3464
+ ngx_http_lua_test_expect(ngx_http_request_t *r)
3465
+ {
3466
+ ngx_int_t n;
3467
+ ngx_str_t *expect;
3468
+
3469
+ if (r->expect_tested
3470
+ || r->headers_in.expect == NULL
3471
+ || r->http_version < NGX_HTTP_VERSION_11)
3472
+ {
3473
+ return NGX_OK;
3474
+ }
3475
+
3476
+ r->expect_tested = 1;
3477
+
3478
+ expect = &r->headers_in.expect->value;
3479
+
3480
+ if (expect->len != sizeof("100-continue") - 1
3481
+ || ngx_strncasecmp(expect->data, (u_char *) "100-continue",
3482
+ sizeof("100-continue") - 1)
3483
+ != 0)
3484
+ {
3485
+ return NGX_OK;
3486
+ }
3487
+
3488
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
3489
+ "send 100 Continue");
3490
+
3491
+ n = r->connection->send(r->connection,
3492
+ (u_char *) "HTTP/1.1 100 Continue" CRLF CRLF,
3493
+ sizeof("HTTP/1.1 100 Continue" CRLF CRLF) - 1);
3494
+
3495
+ if (n == sizeof("HTTP/1.1 100 Continue" CRLF CRLF) - 1) {
3496
+ return NGX_OK;
3497
+ }
3498
+
3499
+ /* we assume that such small packet should be send successfully */
3500
+
3501
+ return NGX_ERROR;
3502
+ }
3503
+
3504
+
3505
+ void
3506
+ ngx_http_lua_finalize_request(ngx_http_request_t *r, ngx_int_t rc)
3507
+ {
3508
+ ngx_http_lua_ctx_t *ctx;
3509
+
3510
+ ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
3511
+ if (ctx && ctx->cur_co_ctx) {
3512
+ ngx_http_lua_cleanup_pending_operation(ctx->cur_co_ctx);
3513
+ }
3514
+
3515
+ if (r->connection->fd != -1) {
3516
+ ngx_http_finalize_request(r, rc);
3517
+ return;
3518
+ }
3519
+
3520
+ ngx_http_lua_finalize_fake_request(r, rc);
3521
+ }
3522
+
3523
+
3524
+ void
3525
+ ngx_http_lua_finalize_fake_request(ngx_http_request_t *r, ngx_int_t rc)
3526
+ {
3527
+ ngx_connection_t *c;
3528
+
3529
+ c = r->connection;
3530
+
3531
+ ngx_log_debug3(NGX_LOG_DEBUG_HTTP, c->log, 0,
3532
+ "http lua finalize fake request: %d, a:%d, c:%d",
3533
+ rc, r == c->data, r->main->count);
3534
+
3535
+ if (rc == NGX_DONE) {
3536
+ ngx_http_lua_close_fake_request(r);
3537
+ return;
3538
+ }
3539
+
3540
+ if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE) {
3541
+ ngx_http_lua_close_fake_request(r);
3542
+ return;
3543
+ }
3544
+
3545
+ if (c->read->timer_set) {
3546
+ ngx_del_timer(c->read);
3547
+ }
3548
+
3549
+ if (c->write->timer_set) {
3550
+ c->write->delayed = 0;
3551
+ ngx_del_timer(c->write);
3552
+ }
3553
+
3554
+ ngx_http_lua_close_fake_request(r);
3555
+ }
3556
+
3557
+
3558
+ static void
3559
+ ngx_http_lua_close_fake_request(ngx_http_request_t *r)
3560
+ {
3561
+ ngx_connection_t *c;
3562
+
3563
+ r = r->main;
3564
+ c = r->connection;
3565
+
3566
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
3567
+ "http lua fake request count:%d", r->count);
3568
+
3569
+ if (r->count == 0) {
3570
+ ngx_log_error(NGX_LOG_ALERT, c->log, 0, "http lua fake request "
3571
+ "count is zero");
3572
+ }
3573
+
3574
+ r->count--;
3575
+
3576
+ if (r->count) {
3577
+ return;
3578
+ }
3579
+
3580
+ ngx_http_lua_free_fake_request(r);
3581
+ ngx_http_lua_close_fake_connection(c);
3582
+ }
3583
+
3584
+
3585
+ static void
3586
+ ngx_http_lua_free_fake_request(ngx_http_request_t *r)
3587
+ {
3588
+ ngx_log_t *log;
3589
+ ngx_http_cleanup_t *cln;
3590
+
3591
+ log = r->connection->log;
3592
+
3593
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, log, 0, "http lua close fake "
3594
+ "request");
3595
+
3596
+ if (r->pool == NULL) {
3597
+ ngx_log_error(NGX_LOG_ALERT, log, 0, "http lua fake request "
3598
+ "already closed");
3599
+ return;
3600
+ }
3601
+
3602
+ for (cln = r->cleanup; cln; cln = cln->next) {
3603
+ if (cln->handler) {
3604
+ cln->handler(cln->data);
3605
+ }
3606
+ }
3607
+
3608
+ r->request_line.len = 0;
3609
+
3610
+ r->connection->destroyed = 1;
3611
+ }
3612
+
3613
+
3614
+ void
3615
+ ngx_http_lua_close_fake_connection(ngx_connection_t *c)
3616
+ {
3617
+ ngx_pool_t *pool;
3618
+ ngx_connection_t *saved_c = NULL;
3619
+
3620
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
3621
+ "http lua close fake http connection");
3622
+
3623
+ c->destroyed = 1;
3624
+
3625
+ pool = c->pool;
3626
+
3627
+ if (c->read->timer_set) {
3628
+ ngx_del_timer(c->read);
3629
+ }
3630
+
3631
+ if (c->write->timer_set) {
3632
+ ngx_del_timer(c->write);
3633
+ }
3634
+
3635
+ c->read->closed = 1;
3636
+ c->write->closed = 1;
3637
+
3638
+ /* we temporarily use a valid fd (0) to make ngx_free_connection happy */
3639
+
3640
+ c->fd = 0;
3641
+
3642
+ if (ngx_cycle->files) {
3643
+ saved_c = ngx_cycle->files[0];
3644
+ }
3645
+
3646
+ ngx_free_connection(c);
3647
+
3648
+ c->fd = (ngx_socket_t) -1;
3649
+
3650
+ if (ngx_cycle->files) {
3651
+ ngx_cycle->files[0] = saved_c;
3652
+ }
3653
+
3654
+ if (pool) {
3655
+ ngx_destroy_pool(pool);
3656
+ }
3657
+ }
3658
+
3659
+
3660
+ lua_State *
3661
+ ngx_http_lua_init_vm(lua_State *parent_vm, ngx_cycle_t *cycle,
3662
+ ngx_pool_t *pool, ngx_http_lua_main_conf_t *lmcf, ngx_log_t *log,
3663
+ ngx_pool_cleanup_t **pcln)
3664
+ {
3665
+ lua_State *L;
3666
+ ngx_uint_t i;
3667
+ ngx_pool_cleanup_t *cln;
3668
+ ngx_http_lua_preload_hook_t *hook;
3669
+ ngx_http_lua_vm_state_t *state;
3670
+
3671
+ cln = ngx_pool_cleanup_add(pool, 0);
3672
+ if (cln == NULL) {
3673
+ return NULL;
3674
+ }
3675
+
3676
+ /* create new Lua VM instance */
3677
+ L = ngx_http_lua_new_state(parent_vm, cycle, lmcf, log);
3678
+ if (L == NULL) {
3679
+ return NULL;
3680
+ }
3681
+
3682
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, "lua initialize the "
3683
+ "global Lua VM %p", L);
3684
+
3685
+ /* register cleanup handler for Lua VM */
3686
+ cln->handler = ngx_http_lua_cleanup_vm;
3687
+
3688
+ state = ngx_alloc(sizeof(ngx_http_lua_vm_state_t), log);
3689
+ if (state == NULL) {
3690
+ return NULL;
3691
+ }
3692
+ state->vm = L;
3693
+ state->count = 1;
3694
+
3695
+ cln->data = state;
3696
+
3697
+ if (pcln) {
3698
+ *pcln = cln;
3699
+ }
3700
+
3701
+ if (lmcf->preload_hooks) {
3702
+
3703
+ /* register the 3rd-party module's preload hooks */
3704
+
3705
+ lua_getglobal(L, "package");
3706
+ lua_getfield(L, -1, "preload");
3707
+
3708
+ hook = lmcf->preload_hooks->elts;
3709
+
3710
+ for (i = 0; i < lmcf->preload_hooks->nelts; i++) {
3711
+
3712
+ ngx_http_lua_probe_register_preload_package(L, hook[i].package);
3713
+
3714
+ lua_pushcfunction(L, hook[i].loader);
3715
+ lua_setfield(L, -2, (char *) hook[i].package);
3716
+ }
3717
+
3718
+ lua_pop(L, 2);
3719
+ }
3720
+
3721
+ return L;
3722
+ }
3723
+
3724
+
3725
+ void
3726
+ ngx_http_lua_cleanup_vm(void *data)
3727
+ {
3728
+ lua_State *L;
3729
+ ngx_http_lua_vm_state_t *state = data;
3730
+
3731
+ #if (DDEBUG)
3732
+ if (state) {
3733
+ dd("cleanup VM: c:%d, s:%p", (int) state->count, state->vm);
3734
+ }
3735
+ #endif
3736
+
3737
+ if (state) {
3738
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0, "decrementing "
3739
+ "the reference count for Lua VM: %i", state->count);
3740
+
3741
+ if (--state->count == 0) {
3742
+ L = state->vm;
3743
+ ngx_http_lua_cleanup_conn_pools(L);
3744
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
3745
+ "lua close the global Lua VM %p", L);
3746
+ lua_close(L);
3747
+ ngx_free(state);
3748
+ }
3749
+ }
3750
+ }
3751
+
3752
+
3753
+ ngx_connection_t *
3754
+ ngx_http_lua_create_fake_connection(ngx_pool_t *pool)
3755
+ {
3756
+ ngx_log_t *log;
3757
+ ngx_connection_t *c;
3758
+ ngx_connection_t *saved_c = NULL;
3759
+
3760
+ /* (we temporarily use a valid fd (0) to make ngx_get_connection happy) */
3761
+ if (ngx_cycle->files) {
3762
+ saved_c = ngx_cycle->files[0];
3763
+ }
3764
+
3765
+ c = ngx_get_connection(0, ngx_cycle->log);
3766
+
3767
+ if (ngx_cycle->files) {
3768
+ ngx_cycle->files[0] = saved_c;
3769
+ }
3770
+
3771
+ if (c == NULL) {
3772
+ return NULL;
3773
+ }
3774
+
3775
+ c->fd = (ngx_socket_t) -1;
3776
+
3777
+ if (pool) {
3778
+ c->pool = pool;
3779
+
3780
+ } else {
3781
+ c->pool = ngx_create_pool(128, c->log);
3782
+ if (c->pool == NULL) {
3783
+ goto failed;
3784
+ }
3785
+ }
3786
+
3787
+ log = ngx_pcalloc(c->pool, sizeof(ngx_log_t));
3788
+ if (log == NULL) {
3789
+ goto failed;
3790
+ }
3791
+
3792
+ c->log = log;
3793
+ c->log->connection = c->number;
3794
+ c->log->action = NULL;
3795
+ c->log->data = NULL;
3796
+
3797
+ c->log_error = NGX_ERROR_INFO;
3798
+
3799
+ #if 0
3800
+ c->buffer = ngx_create_temp_buf(c->pool, 2);
3801
+ if (c->buffer == NULL) {
3802
+ goto failed;
3803
+ }
3804
+
3805
+ c->buffer->start[0] = CR;
3806
+ c->buffer->start[1] = LF;
3807
+ #endif
3808
+
3809
+ c->error = 1;
3810
+
3811
+ return c;
3812
+
3813
+ failed:
3814
+
3815
+ ngx_http_lua_close_fake_connection(c);
3816
+ return NULL;
3817
+ }
3818
+
3819
+
3820
+ ngx_http_request_t *
3821
+ ngx_http_lua_create_fake_request(ngx_connection_t *c)
3822
+ {
3823
+ ngx_http_request_t *r;
3824
+
3825
+ r = ngx_pcalloc(c->pool, sizeof(ngx_http_request_t));
3826
+ if (r == NULL) {
3827
+ return NULL;
3828
+ }
3829
+
3830
+ c->requests++;
3831
+
3832
+ r->pool = c->pool;
3833
+
3834
+ dd("r pool allocated: %d", (int) (sizeof(ngx_http_lua_ctx_t)
3835
+ + sizeof(void *) * ngx_http_max_module + sizeof(ngx_http_cleanup_t)));
3836
+
3837
+ #if 0
3838
+ hc = ngx_pcalloc(c->pool, sizeof(ngx_http_connection_t));
3839
+ if (hc == NULL) {
3840
+ goto failed;
3841
+ }
3842
+
3843
+ r->header_in = c->buffer;
3844
+ r->header_end = c->buffer->start;
3845
+
3846
+ if (ngx_list_init(&r->headers_out.headers, r->pool, 0,
3847
+ sizeof(ngx_table_elt_t))
3848
+ != NGX_OK)
3849
+ {
3850
+ goto failed;
3851
+ }
3852
+
3853
+ if (ngx_list_init(&r->headers_in.headers, r->pool, 0,
3854
+ sizeof(ngx_table_elt_t))
3855
+ != NGX_OK)
3856
+ {
3857
+ goto failed;
3858
+ }
3859
+ #endif
3860
+
3861
+ r->ctx = ngx_pcalloc(r->pool, sizeof(void *) * ngx_http_max_module);
3862
+ if (r->ctx == NULL) {
3863
+ return NULL;
3864
+ }
3865
+
3866
+ #if 0
3867
+ cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
3868
+
3869
+ r->variables = ngx_pcalloc(r->pool, cmcf->variables.nelts
3870
+ * sizeof(ngx_http_variable_value_t));
3871
+ if (r->variables == NULL) {
3872
+ goto failed;
3873
+ }
3874
+ #endif
3875
+
3876
+ r->connection = c;
3877
+
3878
+ r->headers_in.content_length_n = 0;
3879
+ c->data = r;
3880
+ #if 0
3881
+ hc->request = r;
3882
+ r->http_connection = hc;
3883
+ #endif
3884
+ r->signature = NGX_HTTP_MODULE;
3885
+ r->main = r;
3886
+ r->count = 1;
3887
+
3888
+ r->method = NGX_HTTP_UNKNOWN;
3889
+
3890
+ r->headers_in.keep_alive_n = -1;
3891
+ r->uri_changes = NGX_HTTP_MAX_URI_CHANGES + 1;
3892
+ r->subrequests = NGX_HTTP_MAX_SUBREQUESTS + 1;
3893
+
3894
+ r->http_state = NGX_HTTP_PROCESS_REQUEST_STATE;
3895
+ r->discard_body = 1;
3896
+
3897
+ return r;
3898
+ }
3899
+
3900
+
3901
+ ngx_int_t
3902
+ ngx_http_lua_report(ngx_log_t *log, lua_State *L, int status,
3903
+ const char *prefix)
3904
+ {
3905
+ const char *msg;
3906
+
3907
+ if (status && !lua_isnil(L, -1)) {
3908
+ msg = lua_tostring(L, -1);
3909
+ if (msg == NULL) {
3910
+ msg = "unknown error";
3911
+ }
3912
+
3913
+ ngx_log_error(NGX_LOG_ERR, log, 0, "%s error: %s", prefix, msg);
3914
+ lua_pop(L, 1);
3915
+ }
3916
+
3917
+ /* force a full garbage-collection cycle */
3918
+ lua_gc(L, LUA_GCCOLLECT, 0);
3919
+
3920
+ return status == 0 ? NGX_OK : NGX_ERROR;
3921
+ }
3922
+
3923
+
3924
+ int
3925
+ ngx_http_lua_do_call(ngx_log_t *log, lua_State *L)
3926
+ {
3927
+ int status, base;
3928
+ #if (NGX_PCRE)
3929
+ ngx_pool_t *old_pool;
3930
+ #endif
3931
+
3932
+ base = lua_gettop(L); /* function index */
3933
+ lua_pushcfunction(L, ngx_http_lua_traceback); /* push traceback function */
3934
+ lua_insert(L, base); /* put it under chunk and args */
3935
+
3936
+ #if (NGX_PCRE)
3937
+ old_pool = ngx_http_lua_pcre_malloc_init(ngx_cycle->pool);
3938
+ #endif
3939
+
3940
+ status = lua_pcall(L, 0, 0, base);
3941
+
3942
+ #if (NGX_PCRE)
3943
+ ngx_http_lua_pcre_malloc_done(old_pool);
3944
+ #endif
3945
+
3946
+ lua_remove(L, base);
3947
+
3948
+ return status;
3949
+ }
3950
+
3951
+
3952
+ static int
3953
+ ngx_http_lua_get_raw_phase_context(lua_State *L)
3954
+ {
3955
+ ngx_http_request_t *r;
3956
+ ngx_http_lua_ctx_t *ctx;
3957
+
3958
+ r = lua_touserdata(L, 1);
3959
+ if (r == NULL) {
3960
+ return 0;
3961
+ }
3962
+
3963
+ ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
3964
+ if (ctx == NULL) {
3965
+ return 0;
3966
+ }
3967
+
3968
+ lua_pushinteger(L, (int) ctx->context);
3969
+ return 1;
3970
+ }
3971
+
3972
+ /* vi:set ft=c ts=4 sw=4 et fdm=marker: */