nginxtra 1.0.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (363) hide show
  1. data/VERSION +1 -0
  2. data/bin/nginxtra +5 -0
  3. data/lib/nginxtra.rb +12 -0
  4. data/lib/nginxtra/action.rb +36 -0
  5. data/lib/nginxtra/actions/compile.rb +60 -0
  6. data/lib/nginxtra/actions/install.rb +99 -0
  7. data/lib/nginxtra/actions/reload.rb +14 -0
  8. data/lib/nginxtra/actions/restart.rb +15 -0
  9. data/lib/nginxtra/actions/start.rb +53 -0
  10. data/lib/nginxtra/actions/status.rb +31 -0
  11. data/lib/nginxtra/actions/stop.rb +14 -0
  12. data/lib/nginxtra/cli.rb +77 -0
  13. data/lib/nginxtra/config.rb +339 -0
  14. data/lib/nginxtra/error.rb +13 -0
  15. data/lib/nginxtra/status.rb +57 -0
  16. data/src/nginx/CHANGES +5630 -0
  17. data/src/nginx/CHANGES.ru +5716 -0
  18. data/src/nginx/LICENSE +25 -0
  19. data/src/nginx/README +3 -0
  20. data/src/nginx/auto/cc/acc +15 -0
  21. data/src/nginx/auto/cc/bcc +72 -0
  22. data/src/nginx/auto/cc/ccc +46 -0
  23. data/src/nginx/auto/cc/conf +189 -0
  24. data/src/nginx/auto/cc/gcc +183 -0
  25. data/src/nginx/auto/cc/icc +121 -0
  26. data/src/nginx/auto/cc/msvc +138 -0
  27. data/src/nginx/auto/cc/name +101 -0
  28. data/src/nginx/auto/cc/owc +104 -0
  29. data/src/nginx/auto/cc/sunc +158 -0
  30. data/src/nginx/auto/define +12 -0
  31. data/src/nginx/auto/endianess +45 -0
  32. data/src/nginx/auto/feature +123 -0
  33. data/src/nginx/auto/have +12 -0
  34. data/src/nginx/auto/have_headers +12 -0
  35. data/src/nginx/auto/headers +13 -0
  36. data/src/nginx/auto/include +61 -0
  37. data/src/nginx/auto/init +51 -0
  38. data/src/nginx/auto/install +184 -0
  39. data/src/nginx/auto/lib/conf +83 -0
  40. data/src/nginx/auto/lib/geoip/conf +79 -0
  41. data/src/nginx/auto/lib/google-perftools/conf +45 -0
  42. data/src/nginx/auto/lib/libatomic/conf +43 -0
  43. data/src/nginx/auto/lib/libatomic/make +14 -0
  44. data/src/nginx/auto/lib/libgd/conf +83 -0
  45. data/src/nginx/auto/lib/libxslt/conf +156 -0
  46. data/src/nginx/auto/lib/make +32 -0
  47. data/src/nginx/auto/lib/md5/conf +103 -0
  48. data/src/nginx/auto/lib/md5/make +96 -0
  49. data/src/nginx/auto/lib/md5/makefile.bcc +22 -0
  50. data/src/nginx/auto/lib/md5/makefile.msvc +22 -0
  51. data/src/nginx/auto/lib/md5/makefile.owc +11 -0
  52. data/src/nginx/auto/lib/openssl/conf +74 -0
  53. data/src/nginx/auto/lib/openssl/make +67 -0
  54. data/src/nginx/auto/lib/openssl/makefile.bcc +18 -0
  55. data/src/nginx/auto/lib/openssl/makefile.msvc +14 -0
  56. data/src/nginx/auto/lib/pcre/conf +180 -0
  57. data/src/nginx/auto/lib/pcre/make +64 -0
  58. data/src/nginx/auto/lib/pcre/makefile.bcc +26 -0
  59. data/src/nginx/auto/lib/pcre/makefile.msvc +22 -0
  60. data/src/nginx/auto/lib/pcre/makefile.owc +24 -0
  61. data/src/nginx/auto/lib/perl/conf +60 -0
  62. data/src/nginx/auto/lib/perl/make +36 -0
  63. data/src/nginx/auto/lib/sha1/conf +79 -0
  64. data/src/nginx/auto/lib/sha1/make +96 -0
  65. data/src/nginx/auto/lib/sha1/makefile.bcc +22 -0
  66. data/src/nginx/auto/lib/sha1/makefile.msvc +22 -0
  67. data/src/nginx/auto/lib/sha1/makefile.owc +11 -0
  68. data/src/nginx/auto/lib/test +40 -0
  69. data/src/nginx/auto/lib/zlib/conf +76 -0
  70. data/src/nginx/auto/lib/zlib/make +114 -0
  71. data/src/nginx/auto/lib/zlib/makefile.bcc +15 -0
  72. data/src/nginx/auto/lib/zlib/makefile.msvc +14 -0
  73. data/src/nginx/auto/lib/zlib/makefile.owc +14 -0
  74. data/src/nginx/auto/lib/zlib/patch.zlib.h +10 -0
  75. data/src/nginx/auto/make +417 -0
  76. data/src/nginx/auto/modules +479 -0
  77. data/src/nginx/auto/nohave +12 -0
  78. data/src/nginx/auto/options +490 -0
  79. data/src/nginx/auto/os/conf +105 -0
  80. data/src/nginx/auto/os/darwin +116 -0
  81. data/src/nginx/auto/os/freebsd +136 -0
  82. data/src/nginx/auto/os/linux +152 -0
  83. data/src/nginx/auto/os/solaris +60 -0
  84. data/src/nginx/auto/os/win32 +29 -0
  85. data/src/nginx/auto/sources +518 -0
  86. data/src/nginx/auto/stubs +8 -0
  87. data/src/nginx/auto/summary +114 -0
  88. data/src/nginx/auto/types/sizeof +83 -0
  89. data/src/nginx/auto/types/typedef +77 -0
  90. data/src/nginx/auto/types/uintptr_t +42 -0
  91. data/src/nginx/auto/types/value +12 -0
  92. data/src/nginx/auto/unix +719 -0
  93. data/src/nginx/conf/fastcgi.conf +24 -0
  94. data/src/nginx/conf/fastcgi_params +23 -0
  95. data/src/nginx/conf/koi-utf +109 -0
  96. data/src/nginx/conf/koi-win +103 -0
  97. data/src/nginx/conf/mime.types +80 -0
  98. data/src/nginx/conf/nginx.conf +118 -0
  99. data/src/nginx/conf/scgi_params +15 -0
  100. data/src/nginx/conf/uwsgi_params +15 -0
  101. data/src/nginx/conf/win-utf +126 -0
  102. data/src/nginx/configure +108 -0
  103. data/src/nginx/contrib/README +15 -0
  104. data/src/nginx/contrib/geo2nginx.pl +58 -0
  105. data/src/nginx/contrib/unicode2nginx/koi-utf +131 -0
  106. data/src/nginx/contrib/unicode2nginx/unicode-to-nginx.pl +45 -0
  107. data/src/nginx/contrib/unicode2nginx/win-utf +130 -0
  108. data/src/nginx/html/50x.html +18 -0
  109. data/src/nginx/html/index.html +8 -0
  110. data/src/nginx/man/nginx.8 +202 -0
  111. data/src/nginx/src/core/nginx.c +1333 -0
  112. data/src/nginx/src/core/nginx.h +20 -0
  113. data/src/nginx/src/core/ngx_array.c +147 -0
  114. data/src/nginx/src/core/ngx_array.h +53 -0
  115. data/src/nginx/src/core/ngx_buf.c +218 -0
  116. data/src/nginx/src/core/ngx_buf.h +162 -0
  117. data/src/nginx/src/core/ngx_conf_file.c +1506 -0
  118. data/src/nginx/src/core/ngx_conf_file.h +348 -0
  119. data/src/nginx/src/core/ngx_config.h +134 -0
  120. data/src/nginx/src/core/ngx_connection.c +1074 -0
  121. data/src/nginx/src/core/ngx_connection.h +195 -0
  122. data/src/nginx/src/core/ngx_core.h +95 -0
  123. data/src/nginx/src/core/ngx_cpuinfo.c +139 -0
  124. data/src/nginx/src/core/ngx_crc.h +39 -0
  125. data/src/nginx/src/core/ngx_crc32.c +129 -0
  126. data/src/nginx/src/core/ngx_crc32.h +79 -0
  127. data/src/nginx/src/core/ngx_crypt.c +238 -0
  128. data/src/nginx/src/core/ngx_crypt.h +20 -0
  129. data/src/nginx/src/core/ngx_cycle.c +1379 -0
  130. data/src/nginx/src/core/ngx_cycle.h +142 -0
  131. data/src/nginx/src/core/ngx_file.c +993 -0
  132. data/src/nginx/src/core/ngx_file.h +151 -0
  133. data/src/nginx/src/core/ngx_hash.c +976 -0
  134. data/src/nginx/src/core/ngx_hash.h +122 -0
  135. data/src/nginx/src/core/ngx_inet.c +1008 -0
  136. data/src/nginx/src/core/ngx_inet.h +120 -0
  137. data/src/nginx/src/core/ngx_list.c +71 -0
  138. data/src/nginx/src/core/ngx_list.h +83 -0
  139. data/src/nginx/src/core/ngx_log.c +459 -0
  140. data/src/nginx/src/core/ngx_log.h +250 -0
  141. data/src/nginx/src/core/ngx_md5.c +289 -0
  142. data/src/nginx/src/core/ngx_md5.h +60 -0
  143. data/src/nginx/src/core/ngx_murmurhash.c +50 -0
  144. data/src/nginx/src/core/ngx_murmurhash.h +19 -0
  145. data/src/nginx/src/core/ngx_open_file_cache.c +882 -0
  146. data/src/nginx/src/core/ngx_open_file_cache.h +119 -0
  147. data/src/nginx/src/core/ngx_output_chain.c +673 -0
  148. data/src/nginx/src/core/ngx_palloc.c +433 -0
  149. data/src/nginx/src/core/ngx_palloc.h +95 -0
  150. data/src/nginx/src/core/ngx_parse.c +249 -0
  151. data/src/nginx/src/core/ngx_parse.h +24 -0
  152. data/src/nginx/src/core/ngx_queue.c +80 -0
  153. data/src/nginx/src/core/ngx_queue.h +112 -0
  154. data/src/nginx/src/core/ngx_radix_tree.c +291 -0
  155. data/src/nginx/src/core/ngx_radix_tree.h +46 -0
  156. data/src/nginx/src/core/ngx_rbtree.c +383 -0
  157. data/src/nginx/src/core/ngx_rbtree.h +84 -0
  158. data/src/nginx/src/core/ngx_regex.c +206 -0
  159. data/src/nginx/src/core/ngx_regex.h +56 -0
  160. data/src/nginx/src/core/ngx_resolver.c +2201 -0
  161. data/src/nginx/src/core/ngx_resolver.h +149 -0
  162. data/src/nginx/src/core/ngx_sha1.h +31 -0
  163. data/src/nginx/src/core/ngx_shmtx.c +284 -0
  164. data/src/nginx/src/core/ngx_shmtx.h +38 -0
  165. data/src/nginx/src/core/ngx_slab.c +701 -0
  166. data/src/nginx/src/core/ngx_slab.h +54 -0
  167. data/src/nginx/src/core/ngx_spinlock.c +53 -0
  168. data/src/nginx/src/core/ngx_string.c +1837 -0
  169. data/src/nginx/src/core/ngx_string.h +231 -0
  170. data/src/nginx/src/core/ngx_times.c +407 -0
  171. data/src/nginx/src/core/ngx_times.h +51 -0
  172. data/src/nginx/src/event/modules/ngx_aio_module.c +171 -0
  173. data/src/nginx/src/event/modules/ngx_devpoll_module.c +569 -0
  174. data/src/nginx/src/event/modules/ngx_epoll_module.c +833 -0
  175. data/src/nginx/src/event/modules/ngx_eventport_module.c +602 -0
  176. data/src/nginx/src/event/modules/ngx_kqueue_module.c +785 -0
  177. data/src/nginx/src/event/modules/ngx_poll_module.c +443 -0
  178. data/src/nginx/src/event/modules/ngx_rtsig_module.c +735 -0
  179. data/src/nginx/src/event/modules/ngx_select_module.c +435 -0
  180. data/src/nginx/src/event/modules/ngx_win32_select_module.c +400 -0
  181. data/src/nginx/src/event/ngx_event.c +1275 -0
  182. data/src/nginx/src/event/ngx_event.h +573 -0
  183. data/src/nginx/src/event/ngx_event_accept.c +428 -0
  184. data/src/nginx/src/event/ngx_event_busy_lock.c +286 -0
  185. data/src/nginx/src/event/ngx_event_busy_lock.h +65 -0
  186. data/src/nginx/src/event/ngx_event_connect.c +258 -0
  187. data/src/nginx/src/event/ngx_event_connect.h +76 -0
  188. data/src/nginx/src/event/ngx_event_mutex.c +70 -0
  189. data/src/nginx/src/event/ngx_event_openssl.c +2382 -0
  190. data/src/nginx/src/event/ngx_event_openssl.h +162 -0
  191. data/src/nginx/src/event/ngx_event_pipe.c +996 -0
  192. data/src/nginx/src/event/ngx_event_pipe.h +95 -0
  193. data/src/nginx/src/event/ngx_event_posted.c +173 -0
  194. data/src/nginx/src/event/ngx_event_posted.h +75 -0
  195. data/src/nginx/src/event/ngx_event_timer.c +159 -0
  196. data/src/nginx/src/event/ngx_event_timer.h +102 -0
  197. data/src/nginx/src/http/modules/ngx_http_access_module.c +384 -0
  198. data/src/nginx/src/http/modules/ngx_http_addition_filter_module.c +250 -0
  199. data/src/nginx/src/http/modules/ngx_http_auth_basic_module.c +478 -0
  200. data/src/nginx/src/http/modules/ngx_http_autoindex_module.c +701 -0
  201. data/src/nginx/src/http/modules/ngx_http_browser_module.c +713 -0
  202. data/src/nginx/src/http/modules/ngx_http_charset_filter_module.c +1681 -0
  203. data/src/nginx/src/http/modules/ngx_http_chunked_filter_module.c +242 -0
  204. data/src/nginx/src/http/modules/ngx_http_dav_module.c +1141 -0
  205. data/src/nginx/src/http/modules/ngx_http_degradation_module.c +243 -0
  206. data/src/nginx/src/http/modules/ngx_http_empty_gif_module.c +140 -0
  207. data/src/nginx/src/http/modules/ngx_http_fastcgi_module.c +2916 -0
  208. data/src/nginx/src/http/modules/ngx_http_flv_module.c +254 -0
  209. data/src/nginx/src/http/modules/ngx_http_geo_module.c +1441 -0
  210. data/src/nginx/src/http/modules/ngx_http_geoip_module.c +671 -0
  211. data/src/nginx/src/http/modules/ngx_http_gzip_filter_module.c +1206 -0
  212. data/src/nginx/src/http/modules/ngx_http_gzip_static_module.c +299 -0
  213. data/src/nginx/src/http/modules/ngx_http_headers_filter_module.c +616 -0
  214. data/src/nginx/src/http/modules/ngx_http_image_filter_module.c +1489 -0
  215. data/src/nginx/src/http/modules/ngx_http_index_module.c +516 -0
  216. data/src/nginx/src/http/modules/ngx_http_limit_req_module.c +809 -0
  217. data/src/nginx/src/http/modules/ngx_http_limit_zone_module.c +553 -0
  218. data/src/nginx/src/http/modules/ngx_http_log_module.c +1357 -0
  219. data/src/nginx/src/http/modules/ngx_http_map_module.c +575 -0
  220. data/src/nginx/src/http/modules/ngx_http_memcached_module.c +624 -0
  221. data/src/nginx/src/http/modules/ngx_http_mp4_module.c +3000 -0
  222. data/src/nginx/src/http/modules/ngx_http_not_modified_filter_module.c +143 -0
  223. data/src/nginx/src/http/modules/ngx_http_proxy_module.c +2831 -0
  224. data/src/nginx/src/http/modules/ngx_http_random_index_module.c +317 -0
  225. data/src/nginx/src/http/modules/ngx_http_range_filter_module.c +855 -0
  226. data/src/nginx/src/http/modules/ngx_http_realip_module.c +476 -0
  227. data/src/nginx/src/http/modules/ngx_http_referer_module.c +613 -0
  228. data/src/nginx/src/http/modules/ngx_http_rewrite_module.c +1019 -0
  229. data/src/nginx/src/http/modules/ngx_http_scgi_module.c +1714 -0
  230. data/src/nginx/src/http/modules/ngx_http_secure_link_module.c +355 -0
  231. data/src/nginx/src/http/modules/ngx_http_split_clients_module.c +242 -0
  232. data/src/nginx/src/http/modules/ngx_http_ssi_filter_module.c +2913 -0
  233. data/src/nginx/src/http/modules/ngx_http_ssi_filter_module.h +114 -0
  234. data/src/nginx/src/http/modules/ngx_http_ssl_module.c +652 -0
  235. data/src/nginx/src/http/modules/ngx_http_ssl_module.h +52 -0
  236. data/src/nginx/src/http/modules/ngx_http_static_module.c +278 -0
  237. data/src/nginx/src/http/modules/ngx_http_stub_status_module.c +144 -0
  238. data/src/nginx/src/http/modules/ngx_http_sub_filter_module.c +716 -0
  239. data/src/nginx/src/http/modules/ngx_http_upstream_ip_hash_module.c +237 -0
  240. data/src/nginx/src/http/modules/ngx_http_userid_filter_module.c +846 -0
  241. data/src/nginx/src/http/modules/ngx_http_uwsgi_module.c +1774 -0
  242. data/src/nginx/src/http/modules/ngx_http_xslt_filter_module.c +984 -0
  243. data/src/nginx/src/http/modules/perl/Makefile.PL +42 -0
  244. data/src/nginx/src/http/modules/perl/nginx.pm +137 -0
  245. data/src/nginx/src/http/modules/perl/nginx.xs +986 -0
  246. data/src/nginx/src/http/modules/perl/ngx_http_perl_module.c +1076 -0
  247. data/src/nginx/src/http/modules/perl/ngx_http_perl_module.h +67 -0
  248. data/src/nginx/src/http/modules/perl/typemap +3 -0
  249. data/src/nginx/src/http/ngx_http.c +2073 -0
  250. data/src/nginx/src/http/ngx_http.h +160 -0
  251. data/src/nginx/src/http/ngx_http_busy_lock.c +307 -0
  252. data/src/nginx/src/http/ngx_http_busy_lock.h +54 -0
  253. data/src/nginx/src/http/ngx_http_cache.h +148 -0
  254. data/src/nginx/src/http/ngx_http_config.h +75 -0
  255. data/src/nginx/src/http/ngx_http_copy_filter_module.c +300 -0
  256. data/src/nginx/src/http/ngx_http_core_module.c +4736 -0
  257. data/src/nginx/src/http/ngx_http_core_module.h +541 -0
  258. data/src/nginx/src/http/ngx_http_file_cache.c +1715 -0
  259. data/src/nginx/src/http/ngx_http_header_filter_module.c +623 -0
  260. data/src/nginx/src/http/ngx_http_parse.c +1734 -0
  261. data/src/nginx/src/http/ngx_http_parse_time.c +276 -0
  262. data/src/nginx/src/http/ngx_http_postpone_filter_module.c +178 -0
  263. data/src/nginx/src/http/ngx_http_request.c +3181 -0
  264. data/src/nginx/src/http/ngx_http_request.h +573 -0
  265. data/src/nginx/src/http/ngx_http_request_body.c +644 -0
  266. data/src/nginx/src/http/ngx_http_script.c +1752 -0
  267. data/src/nginx/src/http/ngx_http_script.h +257 -0
  268. data/src/nginx/src/http/ngx_http_special_response.c +789 -0
  269. data/src/nginx/src/http/ngx_http_upstream.c +4555 -0
  270. data/src/nginx/src/http/ngx_http_upstream.h +350 -0
  271. data/src/nginx/src/http/ngx_http_upstream_round_robin.c +791 -0
  272. data/src/nginx/src/http/ngx_http_upstream_round_robin.h +85 -0
  273. data/src/nginx/src/http/ngx_http_variables.c +2053 -0
  274. data/src/nginx/src/http/ngx_http_variables.h +115 -0
  275. data/src/nginx/src/http/ngx_http_write_filter_module.c +315 -0
  276. data/src/nginx/src/mail/ngx_mail.c +542 -0
  277. data/src/nginx/src/mail/ngx_mail.h +407 -0
  278. data/src/nginx/src/mail/ngx_mail_auth_http_module.c +1452 -0
  279. data/src/nginx/src/mail/ngx_mail_core_module.c +553 -0
  280. data/src/nginx/src/mail/ngx_mail_handler.c +773 -0
  281. data/src/nginx/src/mail/ngx_mail_imap_handler.c +457 -0
  282. data/src/nginx/src/mail/ngx_mail_imap_module.c +253 -0
  283. data/src/nginx/src/mail/ngx_mail_imap_module.h +39 -0
  284. data/src/nginx/src/mail/ngx_mail_parse.c +885 -0
  285. data/src/nginx/src/mail/ngx_mail_pop3_handler.c +500 -0
  286. data/src/nginx/src/mail/ngx_mail_pop3_module.c +264 -0
  287. data/src/nginx/src/mail/ngx_mail_pop3_module.h +38 -0
  288. data/src/nginx/src/mail/ngx_mail_proxy_module.c +1089 -0
  289. data/src/nginx/src/mail/ngx_mail_smtp_handler.c +872 -0
  290. data/src/nginx/src/mail/ngx_mail_smtp_module.c +308 -0
  291. data/src/nginx/src/mail/ngx_mail_smtp_module.h +45 -0
  292. data/src/nginx/src/mail/ngx_mail_ssl_module.c +491 -0
  293. data/src/nginx/src/mail/ngx_mail_ssl_module.h +52 -0
  294. data/src/nginx/src/misc/ngx_cpp_test_module.cpp +27 -0
  295. data/src/nginx/src/misc/ngx_google_perftools_module.c +126 -0
  296. data/src/nginx/src/os/unix/ngx_aio_read.c +109 -0
  297. data/src/nginx/src/os/unix/ngx_aio_read_chain.c +78 -0
  298. data/src/nginx/src/os/unix/ngx_aio_write.c +109 -0
  299. data/src/nginx/src/os/unix/ngx_aio_write_chain.c +100 -0
  300. data/src/nginx/src/os/unix/ngx_alloc.c +90 -0
  301. data/src/nginx/src/os/unix/ngx_alloc.h +45 -0
  302. data/src/nginx/src/os/unix/ngx_atomic.h +311 -0
  303. data/src/nginx/src/os/unix/ngx_channel.c +258 -0
  304. data/src/nginx/src/os/unix/ngx_channel.h +34 -0
  305. data/src/nginx/src/os/unix/ngx_daemon.c +69 -0
  306. data/src/nginx/src/os/unix/ngx_darwin.h +20 -0
  307. data/src/nginx/src/os/unix/ngx_darwin_config.h +96 -0
  308. data/src/nginx/src/os/unix/ngx_darwin_init.c +166 -0
  309. data/src/nginx/src/os/unix/ngx_darwin_sendfile_chain.c +366 -0
  310. data/src/nginx/src/os/unix/ngx_errno.c +87 -0
  311. data/src/nginx/src/os/unix/ngx_errno.h +68 -0
  312. data/src/nginx/src/os/unix/ngx_file_aio_read.c +208 -0
  313. data/src/nginx/src/os/unix/ngx_files.c +566 -0
  314. data/src/nginx/src/os/unix/ngx_files.h +343 -0
  315. data/src/nginx/src/os/unix/ngx_freebsd.h +24 -0
  316. data/src/nginx/src/os/unix/ngx_freebsd_config.h +119 -0
  317. data/src/nginx/src/os/unix/ngx_freebsd_init.c +259 -0
  318. data/src/nginx/src/os/unix/ngx_freebsd_rfork_thread.c +756 -0
  319. data/src/nginx/src/os/unix/ngx_freebsd_rfork_thread.h +122 -0
  320. data/src/nginx/src/os/unix/ngx_freebsd_sendfile_chain.c +436 -0
  321. data/src/nginx/src/os/unix/ngx_gcc_atomic_amd64.h +82 -0
  322. data/src/nginx/src/os/unix/ngx_gcc_atomic_ppc.h +155 -0
  323. data/src/nginx/src/os/unix/ngx_gcc_atomic_sparc64.h +82 -0
  324. data/src/nginx/src/os/unix/ngx_gcc_atomic_x86.h +127 -0
  325. data/src/nginx/src/os/unix/ngx_linux.h +18 -0
  326. data/src/nginx/src/os/unix/ngx_linux_aio_read.c +137 -0
  327. data/src/nginx/src/os/unix/ngx_linux_config.h +117 -0
  328. data/src/nginx/src/os/unix/ngx_linux_init.c +91 -0
  329. data/src/nginx/src/os/unix/ngx_linux_sendfile_chain.c +378 -0
  330. data/src/nginx/src/os/unix/ngx_os.h +84 -0
  331. data/src/nginx/src/os/unix/ngx_posix_config.h +153 -0
  332. data/src/nginx/src/os/unix/ngx_posix_init.c +124 -0
  333. data/src/nginx/src/os/unix/ngx_process.c +590 -0
  334. data/src/nginx/src/os/unix/ngx_process.h +87 -0
  335. data/src/nginx/src/os/unix/ngx_process_cycle.c +1390 -0
  336. data/src/nginx/src/os/unix/ngx_process_cycle.h +61 -0
  337. data/src/nginx/src/os/unix/ngx_pthread_thread.c +278 -0
  338. data/src/nginx/src/os/unix/ngx_readv_chain.c +258 -0
  339. data/src/nginx/src/os/unix/ngx_recv.c +180 -0
  340. data/src/nginx/src/os/unix/ngx_send.c +73 -0
  341. data/src/nginx/src/os/unix/ngx_setproctitle.c +135 -0
  342. data/src/nginx/src/os/unix/ngx_setproctitle.h +52 -0
  343. data/src/nginx/src/os/unix/ngx_shmem.c +126 -0
  344. data/src/nginx/src/os/unix/ngx_shmem.h +29 -0
  345. data/src/nginx/src/os/unix/ngx_socket.c +116 -0
  346. data/src/nginx/src/os/unix/ngx_socket.h +64 -0
  347. data/src/nginx/src/os/unix/ngx_solaris.h +16 -0
  348. data/src/nginx/src/os/unix/ngx_solaris_config.h +107 -0
  349. data/src/nginx/src/os/unix/ngx_solaris_init.c +75 -0
  350. data/src/nginx/src/os/unix/ngx_solaris_sendfilev_chain.c +251 -0
  351. data/src/nginx/src/os/unix/ngx_sunpro_amd64.il +43 -0
  352. data/src/nginx/src/os/unix/ngx_sunpro_atomic_sparc64.h +61 -0
  353. data/src/nginx/src/os/unix/ngx_sunpro_sparc64.il +36 -0
  354. data/src/nginx/src/os/unix/ngx_sunpro_x86.il +44 -0
  355. data/src/nginx/src/os/unix/ngx_thread.h +128 -0
  356. data/src/nginx/src/os/unix/ngx_time.c +104 -0
  357. data/src/nginx/src/os/unix/ngx_time.h +66 -0
  358. data/src/nginx/src/os/unix/ngx_udp_recv.c +115 -0
  359. data/src/nginx/src/os/unix/ngx_user.c +109 -0
  360. data/src/nginx/src/os/unix/ngx_user.h +24 -0
  361. data/src/nginx/src/os/unix/ngx_writev_chain.c +181 -0
  362. data/src/nginx/src/os/unix/rfork_thread.S +73 -0
  363. metadata +419 -0
@@ -0,0 +1,85 @@
1
+
2
+ /*
3
+ * Copyright (C) Igor Sysoev
4
+ * Copyright (C) Nginx, Inc.
5
+ */
6
+
7
+
8
+ #ifndef _NGX_HTTP_UPSTREAM_ROUND_ROBIN_H_INCLUDED_
9
+ #define _NGX_HTTP_UPSTREAM_ROUND_ROBIN_H_INCLUDED_
10
+
11
+
12
+ #include <ngx_config.h>
13
+ #include <ngx_core.h>
14
+ #include <ngx_http.h>
15
+
16
+
17
+ typedef struct {
18
+ struct sockaddr *sockaddr;
19
+ socklen_t socklen;
20
+ ngx_str_t name;
21
+
22
+ ngx_int_t current_weight;
23
+ ngx_int_t weight;
24
+
25
+ ngx_uint_t fails;
26
+ time_t accessed;
27
+
28
+ ngx_uint_t max_fails;
29
+ time_t fail_timeout;
30
+
31
+ ngx_uint_t down; /* unsigned down:1; */
32
+
33
+ #if (NGX_HTTP_SSL)
34
+ ngx_ssl_session_t *ssl_session; /* local to a process */
35
+ #endif
36
+ } ngx_http_upstream_rr_peer_t;
37
+
38
+
39
+ typedef struct ngx_http_upstream_rr_peers_s ngx_http_upstream_rr_peers_t;
40
+
41
+ struct ngx_http_upstream_rr_peers_s {
42
+ ngx_uint_t single; /* unsigned single:1; */
43
+ ngx_uint_t number;
44
+ ngx_uint_t last_cached;
45
+
46
+ /* ngx_mutex_t *mutex; */
47
+ ngx_connection_t **cached;
48
+
49
+ ngx_str_t *name;
50
+
51
+ ngx_http_upstream_rr_peers_t *next;
52
+
53
+ ngx_http_upstream_rr_peer_t peer[1];
54
+ };
55
+
56
+
57
+ typedef struct {
58
+ ngx_http_upstream_rr_peers_t *peers;
59
+ ngx_uint_t current;
60
+ uintptr_t *tried;
61
+ uintptr_t data;
62
+ } ngx_http_upstream_rr_peer_data_t;
63
+
64
+
65
+ ngx_int_t ngx_http_upstream_init_round_robin(ngx_conf_t *cf,
66
+ ngx_http_upstream_srv_conf_t *us);
67
+ ngx_int_t ngx_http_upstream_init_round_robin_peer(ngx_http_request_t *r,
68
+ ngx_http_upstream_srv_conf_t *us);
69
+ ngx_int_t ngx_http_upstream_create_round_robin_peer(ngx_http_request_t *r,
70
+ ngx_http_upstream_resolved_t *ur);
71
+ ngx_int_t ngx_http_upstream_get_round_robin_peer(ngx_peer_connection_t *pc,
72
+ void *data);
73
+ void ngx_http_upstream_free_round_robin_peer(ngx_peer_connection_t *pc,
74
+ void *data, ngx_uint_t state);
75
+
76
+ #if (NGX_HTTP_SSL)
77
+ ngx_int_t
78
+ ngx_http_upstream_set_round_robin_peer_session(ngx_peer_connection_t *pc,
79
+ void *data);
80
+ void ngx_http_upstream_save_round_robin_peer_session(ngx_peer_connection_t *pc,
81
+ void *data);
82
+ #endif
83
+
84
+
85
+ #endif /* _NGX_HTTP_UPSTREAM_ROUND_ROBIN_H_INCLUDED_ */
@@ -0,0 +1,2053 @@
1
+
2
+ /*
3
+ * Copyright (C) Igor Sysoev
4
+ * Copyright (C) Nginx, Inc.
5
+ */
6
+
7
+
8
+ #include <ngx_config.h>
9
+ #include <ngx_core.h>
10
+ #include <ngx_http.h>
11
+ #include <nginx.h>
12
+
13
+
14
+ static ngx_int_t ngx_http_variable_request(ngx_http_request_t *r,
15
+ ngx_http_variable_value_t *v, uintptr_t data);
16
+ static void ngx_http_variable_request_set(ngx_http_request_t *r,
17
+ ngx_http_variable_value_t *v, uintptr_t data);
18
+ static ngx_int_t ngx_http_variable_request_get_size(ngx_http_request_t *r,
19
+ ngx_http_variable_value_t *v, uintptr_t data);
20
+ static void ngx_http_variable_request_set_size(ngx_http_request_t *r,
21
+ ngx_http_variable_value_t *v, uintptr_t data);
22
+ static ngx_int_t ngx_http_variable_header(ngx_http_request_t *r,
23
+ ngx_http_variable_value_t *v, uintptr_t data);
24
+ static ngx_int_t ngx_http_variable_headers(ngx_http_request_t *r,
25
+ ngx_http_variable_value_t *v, uintptr_t data);
26
+
27
+ static ngx_int_t ngx_http_variable_unknown_header_in(ngx_http_request_t *r,
28
+ ngx_http_variable_value_t *v, uintptr_t data);
29
+ static ngx_int_t ngx_http_variable_unknown_header_out(ngx_http_request_t *r,
30
+ ngx_http_variable_value_t *v, uintptr_t data);
31
+ static ngx_int_t ngx_http_variable_request_line(ngx_http_request_t *r,
32
+ ngx_http_variable_value_t *v, uintptr_t data);
33
+ static ngx_int_t ngx_http_variable_cookie(ngx_http_request_t *r,
34
+ ngx_http_variable_value_t *v, uintptr_t data);
35
+ static ngx_int_t ngx_http_variable_argument(ngx_http_request_t *r,
36
+ ngx_http_variable_value_t *v, uintptr_t data);
37
+
38
+ static ngx_int_t ngx_http_variable_host(ngx_http_request_t *r,
39
+ ngx_http_variable_value_t *v, uintptr_t data);
40
+ static ngx_int_t ngx_http_variable_binary_remote_addr(ngx_http_request_t *r,
41
+ ngx_http_variable_value_t *v, uintptr_t data);
42
+ static ngx_int_t ngx_http_variable_remote_addr(ngx_http_request_t *r,
43
+ ngx_http_variable_value_t *v, uintptr_t data);
44
+ static ngx_int_t ngx_http_variable_remote_port(ngx_http_request_t *r,
45
+ ngx_http_variable_value_t *v, uintptr_t data);
46
+ static ngx_int_t ngx_http_variable_server_addr(ngx_http_request_t *r,
47
+ ngx_http_variable_value_t *v, uintptr_t data);
48
+ static ngx_int_t ngx_http_variable_server_port(ngx_http_request_t *r,
49
+ ngx_http_variable_value_t *v, uintptr_t data);
50
+ static ngx_int_t ngx_http_variable_scheme(ngx_http_request_t *r,
51
+ ngx_http_variable_value_t *v, uintptr_t data);
52
+ static ngx_int_t ngx_http_variable_is_args(ngx_http_request_t *r,
53
+ ngx_http_variable_value_t *v, uintptr_t data);
54
+ static ngx_int_t ngx_http_variable_document_root(ngx_http_request_t *r,
55
+ ngx_http_variable_value_t *v, uintptr_t data);
56
+ static ngx_int_t ngx_http_variable_realpath_root(ngx_http_request_t *r,
57
+ ngx_http_variable_value_t *v, uintptr_t data);
58
+ static ngx_int_t ngx_http_variable_request_filename(ngx_http_request_t *r,
59
+ ngx_http_variable_value_t *v, uintptr_t data);
60
+ static ngx_int_t ngx_http_variable_server_name(ngx_http_request_t *r,
61
+ ngx_http_variable_value_t *v, uintptr_t data);
62
+ static ngx_int_t ngx_http_variable_request_method(ngx_http_request_t *r,
63
+ ngx_http_variable_value_t *v, uintptr_t data);
64
+ static ngx_int_t ngx_http_variable_remote_user(ngx_http_request_t *r,
65
+ ngx_http_variable_value_t *v, uintptr_t data);
66
+ static ngx_int_t ngx_http_variable_body_bytes_sent(ngx_http_request_t *r,
67
+ ngx_http_variable_value_t *v, uintptr_t data);
68
+ static ngx_int_t ngx_http_variable_request_completion(ngx_http_request_t *r,
69
+ ngx_http_variable_value_t *v, uintptr_t data);
70
+ static ngx_int_t ngx_http_variable_request_body(ngx_http_request_t *r,
71
+ ngx_http_variable_value_t *v, uintptr_t data);
72
+ static ngx_int_t ngx_http_variable_request_body_file(ngx_http_request_t *r,
73
+ ngx_http_variable_value_t *v, uintptr_t data);
74
+
75
+ static ngx_int_t ngx_http_variable_sent_content_type(ngx_http_request_t *r,
76
+ ngx_http_variable_value_t *v, uintptr_t data);
77
+ static ngx_int_t ngx_http_variable_sent_content_length(ngx_http_request_t *r,
78
+ ngx_http_variable_value_t *v, uintptr_t data);
79
+ static ngx_int_t ngx_http_variable_sent_location(ngx_http_request_t *r,
80
+ ngx_http_variable_value_t *v, uintptr_t data);
81
+ static ngx_int_t ngx_http_variable_sent_last_modified(ngx_http_request_t *r,
82
+ ngx_http_variable_value_t *v, uintptr_t data);
83
+ static ngx_int_t ngx_http_variable_sent_connection(ngx_http_request_t *r,
84
+ ngx_http_variable_value_t *v, uintptr_t data);
85
+ static ngx_int_t ngx_http_variable_sent_keep_alive(ngx_http_request_t *r,
86
+ ngx_http_variable_value_t *v, uintptr_t data);
87
+ static ngx_int_t ngx_http_variable_sent_transfer_encoding(ngx_http_request_t *r,
88
+ ngx_http_variable_value_t *v, uintptr_t data);
89
+
90
+ static ngx_int_t ngx_http_variable_nginx_version(ngx_http_request_t *r,
91
+ ngx_http_variable_value_t *v, uintptr_t data);
92
+ static ngx_int_t ngx_http_variable_hostname(ngx_http_request_t *r,
93
+ ngx_http_variable_value_t *v, uintptr_t data);
94
+ static ngx_int_t ngx_http_variable_pid(ngx_http_request_t *r,
95
+ ngx_http_variable_value_t *v, uintptr_t data);
96
+
97
+ /*
98
+ * TODO:
99
+ * Apache CGI: AUTH_TYPE, PATH_INFO (null), PATH_TRANSLATED
100
+ * REMOTE_HOST (null), REMOTE_IDENT (null),
101
+ * SERVER_SOFTWARE
102
+ *
103
+ * Apache SSI: DOCUMENT_NAME, LAST_MODIFIED, USER_NAME (file owner)
104
+ */
105
+
106
+ /*
107
+ * the $http_host, $http_user_agent, $http_referer, $http_via,
108
+ * and $http_x_forwarded_for variables may be handled by generic
109
+ * ngx_http_variable_unknown_header_in(), but for perfomance reasons
110
+ * they are handled using dedicated entries
111
+ */
112
+
113
+ static ngx_http_variable_t ngx_http_core_variables[] = {
114
+
115
+ { ngx_string("http_host"), NULL, ngx_http_variable_header,
116
+ offsetof(ngx_http_request_t, headers_in.host), 0, 0 },
117
+
118
+ { ngx_string("http_user_agent"), NULL, ngx_http_variable_header,
119
+ offsetof(ngx_http_request_t, headers_in.user_agent), 0, 0 },
120
+
121
+ { ngx_string("http_referer"), NULL, ngx_http_variable_header,
122
+ offsetof(ngx_http_request_t, headers_in.referer), 0, 0 },
123
+
124
+ #if (NGX_HTTP_GZIP)
125
+ { ngx_string("http_via"), NULL, ngx_http_variable_header,
126
+ offsetof(ngx_http_request_t, headers_in.via), 0, 0 },
127
+ #endif
128
+
129
+ #if (NGX_HTTP_PROXY || NGX_HTTP_REALIP)
130
+ { ngx_string("http_x_forwarded_for"), NULL, ngx_http_variable_header,
131
+ offsetof(ngx_http_request_t, headers_in.x_forwarded_for), 0, 0 },
132
+ #endif
133
+
134
+ { ngx_string("http_cookie"), NULL, ngx_http_variable_headers,
135
+ offsetof(ngx_http_request_t, headers_in.cookies), 0, 0 },
136
+
137
+ { ngx_string("content_length"), NULL, ngx_http_variable_header,
138
+ offsetof(ngx_http_request_t, headers_in.content_length), 0, 0 },
139
+
140
+ { ngx_string("content_type"), NULL, ngx_http_variable_header,
141
+ offsetof(ngx_http_request_t, headers_in.content_type), 0, 0 },
142
+
143
+ { ngx_string("host"), NULL, ngx_http_variable_host, 0, 0, 0 },
144
+
145
+ { ngx_string("binary_remote_addr"), NULL,
146
+ ngx_http_variable_binary_remote_addr, 0, 0, 0 },
147
+
148
+ { ngx_string("remote_addr"), NULL, ngx_http_variable_remote_addr, 0, 0, 0 },
149
+
150
+ { ngx_string("remote_port"), NULL, ngx_http_variable_remote_port, 0, 0, 0 },
151
+
152
+ { ngx_string("server_addr"), NULL, ngx_http_variable_server_addr, 0, 0, 0 },
153
+
154
+ { ngx_string("server_port"), NULL, ngx_http_variable_server_port, 0, 0, 0 },
155
+
156
+ { ngx_string("server_protocol"), NULL, ngx_http_variable_request,
157
+ offsetof(ngx_http_request_t, http_protocol), 0, 0 },
158
+
159
+ { ngx_string("scheme"), NULL, ngx_http_variable_scheme, 0, 0, 0 },
160
+
161
+ { ngx_string("request_uri"), NULL, ngx_http_variable_request,
162
+ offsetof(ngx_http_request_t, unparsed_uri), 0, 0 },
163
+
164
+ { ngx_string("uri"), NULL, ngx_http_variable_request,
165
+ offsetof(ngx_http_request_t, uri),
166
+ NGX_HTTP_VAR_NOCACHEABLE, 0 },
167
+
168
+ { ngx_string("document_uri"), NULL, ngx_http_variable_request,
169
+ offsetof(ngx_http_request_t, uri),
170
+ NGX_HTTP_VAR_NOCACHEABLE, 0 },
171
+
172
+ { ngx_string("request"), NULL, ngx_http_variable_request_line, 0, 0, 0 },
173
+
174
+ { ngx_string("document_root"), NULL,
175
+ ngx_http_variable_document_root, 0, NGX_HTTP_VAR_NOCACHEABLE, 0 },
176
+
177
+ { ngx_string("realpath_root"), NULL,
178
+ ngx_http_variable_realpath_root, 0, NGX_HTTP_VAR_NOCACHEABLE, 0 },
179
+
180
+ { ngx_string("query_string"), NULL, ngx_http_variable_request,
181
+ offsetof(ngx_http_request_t, args),
182
+ NGX_HTTP_VAR_NOCACHEABLE, 0 },
183
+
184
+ { ngx_string("args"),
185
+ ngx_http_variable_request_set,
186
+ ngx_http_variable_request,
187
+ offsetof(ngx_http_request_t, args),
188
+ NGX_HTTP_VAR_CHANGEABLE|NGX_HTTP_VAR_NOCACHEABLE, 0 },
189
+
190
+ { ngx_string("is_args"), NULL, ngx_http_variable_is_args,
191
+ 0, NGX_HTTP_VAR_NOCACHEABLE, 0 },
192
+
193
+ { ngx_string("request_filename"), NULL,
194
+ ngx_http_variable_request_filename, 0,
195
+ NGX_HTTP_VAR_NOCACHEABLE, 0 },
196
+
197
+ { ngx_string("server_name"), NULL, ngx_http_variable_server_name, 0, 0, 0 },
198
+
199
+ { ngx_string("request_method"), NULL,
200
+ ngx_http_variable_request_method, 0,
201
+ NGX_HTTP_VAR_NOCACHEABLE, 0 },
202
+
203
+ { ngx_string("remote_user"), NULL, ngx_http_variable_remote_user, 0, 0, 0 },
204
+
205
+ { ngx_string("body_bytes_sent"), NULL, ngx_http_variable_body_bytes_sent,
206
+ 0, 0, 0 },
207
+
208
+ { ngx_string("request_completion"), NULL,
209
+ ngx_http_variable_request_completion,
210
+ 0, 0, 0 },
211
+
212
+ { ngx_string("request_body"), NULL,
213
+ ngx_http_variable_request_body,
214
+ 0, 0, 0 },
215
+
216
+ { ngx_string("request_body_file"), NULL,
217
+ ngx_http_variable_request_body_file,
218
+ 0, 0, 0 },
219
+
220
+ { ngx_string("sent_http_content_type"), NULL,
221
+ ngx_http_variable_sent_content_type, 0, 0, 0 },
222
+
223
+ { ngx_string("sent_http_content_length"), NULL,
224
+ ngx_http_variable_sent_content_length, 0, 0, 0 },
225
+
226
+ { ngx_string("sent_http_location"), NULL,
227
+ ngx_http_variable_sent_location, 0, 0, 0 },
228
+
229
+ { ngx_string("sent_http_last_modified"), NULL,
230
+ ngx_http_variable_sent_last_modified, 0, 0, 0 },
231
+
232
+ { ngx_string("sent_http_connection"), NULL,
233
+ ngx_http_variable_sent_connection, 0, 0, 0 },
234
+
235
+ { ngx_string("sent_http_keep_alive"), NULL,
236
+ ngx_http_variable_sent_keep_alive, 0, 0, 0 },
237
+
238
+ { ngx_string("sent_http_transfer_encoding"), NULL,
239
+ ngx_http_variable_sent_transfer_encoding, 0, 0, 0 },
240
+
241
+ { ngx_string("sent_http_cache_control"), NULL, ngx_http_variable_headers,
242
+ offsetof(ngx_http_request_t, headers_out.cache_control), 0, 0 },
243
+
244
+ { ngx_string("limit_rate"), ngx_http_variable_request_set_size,
245
+ ngx_http_variable_request_get_size,
246
+ offsetof(ngx_http_request_t, limit_rate),
247
+ NGX_HTTP_VAR_CHANGEABLE|NGX_HTTP_VAR_NOCACHEABLE, 0 },
248
+
249
+ { ngx_string("nginx_version"), NULL, ngx_http_variable_nginx_version,
250
+ 0, 0, 0 },
251
+
252
+ { ngx_string("hostname"), NULL, ngx_http_variable_hostname,
253
+ 0, 0, 0 },
254
+
255
+ { ngx_string("pid"), NULL, ngx_http_variable_pid,
256
+ 0, 0, 0 },
257
+
258
+ { ngx_null_string, NULL, NULL, 0, 0, 0 }
259
+ };
260
+
261
+
262
+ ngx_http_variable_value_t ngx_http_variable_null_value =
263
+ ngx_http_variable("");
264
+ ngx_http_variable_value_t ngx_http_variable_true_value =
265
+ ngx_http_variable("1");
266
+
267
+
268
+ ngx_http_variable_t *
269
+ ngx_http_add_variable(ngx_conf_t *cf, ngx_str_t *name, ngx_uint_t flags)
270
+ {
271
+ ngx_int_t rc;
272
+ ngx_uint_t i;
273
+ ngx_hash_key_t *key;
274
+ ngx_http_variable_t *v;
275
+ ngx_http_core_main_conf_t *cmcf;
276
+
277
+ cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
278
+
279
+ key = cmcf->variables_keys->keys.elts;
280
+ for (i = 0; i < cmcf->variables_keys->keys.nelts; i++) {
281
+ if (name->len != key[i].key.len
282
+ || ngx_strncasecmp(name->data, key[i].key.data, name->len) != 0)
283
+ {
284
+ continue;
285
+ }
286
+
287
+ v = key[i].value;
288
+
289
+ if (!(v->flags & NGX_HTTP_VAR_CHANGEABLE)) {
290
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
291
+ "the duplicate \"%V\" variable", name);
292
+ return NULL;
293
+ }
294
+
295
+ return v;
296
+ }
297
+
298
+ v = ngx_palloc(cf->pool, sizeof(ngx_http_variable_t));
299
+ if (v == NULL) {
300
+ return NULL;
301
+ }
302
+
303
+ v->name.len = name->len;
304
+ v->name.data = ngx_pnalloc(cf->pool, name->len);
305
+ if (v->name.data == NULL) {
306
+ return NULL;
307
+ }
308
+
309
+ ngx_strlow(v->name.data, name->data, name->len);
310
+
311
+ v->set_handler = NULL;
312
+ v->get_handler = NULL;
313
+ v->data = 0;
314
+ v->flags = flags;
315
+ v->index = 0;
316
+
317
+ rc = ngx_hash_add_key(cmcf->variables_keys, &v->name, v, 0);
318
+
319
+ if (rc == NGX_ERROR) {
320
+ return NULL;
321
+ }
322
+
323
+ if (rc == NGX_BUSY) {
324
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
325
+ "conflicting variable name \"%V\"", name);
326
+ return NULL;
327
+ }
328
+
329
+ return v;
330
+ }
331
+
332
+
333
+ ngx_int_t
334
+ ngx_http_get_variable_index(ngx_conf_t *cf, ngx_str_t *name)
335
+ {
336
+ ngx_uint_t i;
337
+ ngx_http_variable_t *v;
338
+ ngx_http_core_main_conf_t *cmcf;
339
+
340
+ cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
341
+
342
+ v = cmcf->variables.elts;
343
+
344
+ if (v == NULL) {
345
+ if (ngx_array_init(&cmcf->variables, cf->pool, 4,
346
+ sizeof(ngx_http_variable_t))
347
+ != NGX_OK)
348
+ {
349
+ return NGX_ERROR;
350
+ }
351
+
352
+ } else {
353
+ for (i = 0; i < cmcf->variables.nelts; i++) {
354
+ if (name->len != v[i].name.len
355
+ || ngx_strncasecmp(name->data, v[i].name.data, name->len) != 0)
356
+ {
357
+ continue;
358
+ }
359
+
360
+ return i;
361
+ }
362
+ }
363
+
364
+ v = ngx_array_push(&cmcf->variables);
365
+ if (v == NULL) {
366
+ return NGX_ERROR;
367
+ }
368
+
369
+ v->name.len = name->len;
370
+ v->name.data = ngx_pnalloc(cf->pool, name->len);
371
+ if (v->name.data == NULL) {
372
+ return NGX_ERROR;
373
+ }
374
+
375
+ ngx_strlow(v->name.data, name->data, name->len);
376
+
377
+ v->set_handler = NULL;
378
+ v->get_handler = NULL;
379
+ v->data = 0;
380
+ v->flags = 0;
381
+ v->index = cmcf->variables.nelts - 1;
382
+
383
+ return cmcf->variables.nelts - 1;
384
+ }
385
+
386
+
387
+ ngx_http_variable_value_t *
388
+ ngx_http_get_indexed_variable(ngx_http_request_t *r, ngx_uint_t index)
389
+ {
390
+ ngx_http_variable_t *v;
391
+ ngx_http_core_main_conf_t *cmcf;
392
+
393
+ cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
394
+
395
+ if (cmcf->variables.nelts <= index) {
396
+ ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
397
+ "unknown variable index: %d", index);
398
+ return NULL;
399
+ }
400
+
401
+ if (r->variables[index].not_found || r->variables[index].valid) {
402
+ return &r->variables[index];
403
+ }
404
+
405
+ v = cmcf->variables.elts;
406
+
407
+ if (v[index].get_handler(r, &r->variables[index], v[index].data)
408
+ == NGX_OK)
409
+ {
410
+ if (v[index].flags & NGX_HTTP_VAR_NOCACHEABLE) {
411
+ r->variables[index].no_cacheable = 1;
412
+ }
413
+
414
+ return &r->variables[index];
415
+ }
416
+
417
+ r->variables[index].valid = 0;
418
+ r->variables[index].not_found = 1;
419
+
420
+ return NULL;
421
+ }
422
+
423
+
424
+ ngx_http_variable_value_t *
425
+ ngx_http_get_flushed_variable(ngx_http_request_t *r, ngx_uint_t index)
426
+ {
427
+ ngx_http_variable_value_t *v;
428
+
429
+ v = &r->variables[index];
430
+
431
+ if (v->valid || v->not_found) {
432
+ if (!v->no_cacheable) {
433
+ return v;
434
+ }
435
+
436
+ v->valid = 0;
437
+ v->not_found = 0;
438
+ }
439
+
440
+ return ngx_http_get_indexed_variable(r, index);
441
+ }
442
+
443
+
444
+ ngx_http_variable_value_t *
445
+ ngx_http_get_variable(ngx_http_request_t *r, ngx_str_t *name, ngx_uint_t key)
446
+ {
447
+ ngx_http_variable_t *v;
448
+ ngx_http_variable_value_t *vv;
449
+ ngx_http_core_main_conf_t *cmcf;
450
+
451
+ cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
452
+
453
+ v = ngx_hash_find(&cmcf->variables_hash, key, name->data, name->len);
454
+
455
+ if (v) {
456
+ if (v->flags & NGX_HTTP_VAR_INDEXED) {
457
+ return ngx_http_get_flushed_variable(r, v->index);
458
+
459
+ } else {
460
+
461
+ vv = ngx_palloc(r->pool, sizeof(ngx_http_variable_value_t));
462
+
463
+ if (vv && v->get_handler(r, vv, v->data) == NGX_OK) {
464
+ return vv;
465
+ }
466
+
467
+ return NULL;
468
+ }
469
+ }
470
+
471
+ vv = ngx_palloc(r->pool, sizeof(ngx_http_variable_value_t));
472
+ if (vv == NULL) {
473
+ return NULL;
474
+ }
475
+
476
+ if (ngx_strncmp(name->data, "http_", 5) == 0) {
477
+
478
+ if (ngx_http_variable_unknown_header_in(r, vv, (uintptr_t) name)
479
+ == NGX_OK)
480
+ {
481
+ return vv;
482
+ }
483
+
484
+ return NULL;
485
+ }
486
+
487
+ if (ngx_strncmp(name->data, "sent_http_", 10) == 0) {
488
+
489
+ if (ngx_http_variable_unknown_header_out(r, vv, (uintptr_t) name)
490
+ == NGX_OK)
491
+ {
492
+ return vv;
493
+ }
494
+
495
+ return NULL;
496
+ }
497
+
498
+ if (ngx_strncmp(name->data, "upstream_http_", 14) == 0) {
499
+
500
+ if (ngx_http_upstream_header_variable(r, vv, (uintptr_t) name)
501
+ == NGX_OK)
502
+ {
503
+ return vv;
504
+ }
505
+
506
+ return NULL;
507
+ }
508
+
509
+ if (ngx_strncmp(name->data, "cookie_", 7) == 0) {
510
+
511
+ if (ngx_http_variable_cookie(r, vv, (uintptr_t) name) == NGX_OK) {
512
+ return vv;
513
+ }
514
+
515
+ return NULL;
516
+ }
517
+
518
+ if (ngx_strncmp(name->data, "arg_", 4) == 0) {
519
+
520
+ if (ngx_http_variable_argument(r, vv, (uintptr_t) name) == NGX_OK) {
521
+ return vv;
522
+ }
523
+
524
+ return NULL;
525
+ }
526
+
527
+ vv->not_found = 1;
528
+
529
+ return vv;
530
+ }
531
+
532
+
533
+ static ngx_int_t
534
+ ngx_http_variable_request(ngx_http_request_t *r, ngx_http_variable_value_t *v,
535
+ uintptr_t data)
536
+ {
537
+ ngx_str_t *s;
538
+
539
+ s = (ngx_str_t *) ((char *) r + data);
540
+
541
+ if (s->data) {
542
+ v->len = s->len;
543
+ v->valid = 1;
544
+ v->no_cacheable = 0;
545
+ v->not_found = 0;
546
+ v->data = s->data;
547
+
548
+ } else {
549
+ v->not_found = 1;
550
+ }
551
+
552
+ return NGX_OK;
553
+ }
554
+
555
+
556
+ static void
557
+ ngx_http_variable_request_set(ngx_http_request_t *r,
558
+ ngx_http_variable_value_t *v, uintptr_t data)
559
+ {
560
+ ngx_str_t *s;
561
+
562
+ s = (ngx_str_t *) ((char *) r + data);
563
+
564
+ s->len = v->len;
565
+ s->data = v->data;
566
+ }
567
+
568
+
569
+ static ngx_int_t
570
+ ngx_http_variable_request_get_size(ngx_http_request_t *r,
571
+ ngx_http_variable_value_t *v, uintptr_t data)
572
+ {
573
+ size_t *sp;
574
+
575
+ sp = (size_t *) ((char *) r + data);
576
+
577
+ v->data = ngx_pnalloc(r->pool, NGX_SIZE_T_LEN);
578
+ if (v->data == NULL) {
579
+ return NGX_ERROR;
580
+ }
581
+
582
+ v->len = ngx_sprintf(v->data, "%uz", *sp) - v->data;
583
+ v->valid = 1;
584
+ v->no_cacheable = 0;
585
+ v->not_found = 0;
586
+
587
+ return NGX_OK;
588
+ }
589
+
590
+
591
+ static void
592
+ ngx_http_variable_request_set_size(ngx_http_request_t *r,
593
+ ngx_http_variable_value_t *v, uintptr_t data)
594
+ {
595
+ ssize_t s, *sp;
596
+ ngx_str_t val;
597
+
598
+ val.len = v->len;
599
+ val.data = v->data;
600
+
601
+ s = ngx_parse_size(&val);
602
+
603
+ if (s == NGX_ERROR) {
604
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
605
+ "invalid size \"%V\"", &val);
606
+ return;
607
+ }
608
+
609
+ sp = (ssize_t *) ((char *) r + data);
610
+
611
+ *sp = s;
612
+
613
+ return;
614
+ }
615
+
616
+
617
+ static ngx_int_t
618
+ ngx_http_variable_header(ngx_http_request_t *r, ngx_http_variable_value_t *v,
619
+ uintptr_t data)
620
+ {
621
+ ngx_table_elt_t *h;
622
+
623
+ h = *(ngx_table_elt_t **) ((char *) r + data);
624
+
625
+ if (h) {
626
+ v->len = h->value.len;
627
+ v->valid = 1;
628
+ v->no_cacheable = 0;
629
+ v->not_found = 0;
630
+ v->data = h->value.data;
631
+
632
+ } else {
633
+ v->not_found = 1;
634
+ }
635
+
636
+ return NGX_OK;
637
+ }
638
+
639
+
640
+ static ngx_int_t
641
+ ngx_http_variable_headers(ngx_http_request_t *r, ngx_http_variable_value_t *v,
642
+ uintptr_t data)
643
+ {
644
+ size_t len;
645
+ u_char *p, *end;
646
+ ngx_uint_t i, n;
647
+ ngx_array_t *a;
648
+ ngx_table_elt_t **h;
649
+
650
+ a = (ngx_array_t *) ((char *) r + data);
651
+
652
+ n = a->nelts;
653
+ h = a->elts;
654
+
655
+ len = 0;
656
+
657
+ for (i = 0; i < n; i++) {
658
+
659
+ if (h[i]->hash == 0) {
660
+ continue;
661
+ }
662
+
663
+ len += h[i]->value.len + sizeof("; ") - 1;
664
+ }
665
+
666
+ if (len == 0) {
667
+ v->not_found = 1;
668
+ return NGX_OK;
669
+ }
670
+
671
+ len -= sizeof("; ") - 1;
672
+
673
+ v->valid = 1;
674
+ v->no_cacheable = 0;
675
+ v->not_found = 0;
676
+
677
+ if (n == 1) {
678
+ v->len = (*h)->value.len;
679
+ v->data = (*h)->value.data;
680
+
681
+ return NGX_OK;
682
+ }
683
+
684
+ p = ngx_pnalloc(r->pool, len);
685
+ if (p == NULL) {
686
+ return NGX_ERROR;
687
+ }
688
+
689
+ v->len = len;
690
+ v->data = p;
691
+
692
+ end = p + len;
693
+
694
+ for (i = 0; /* void */ ; i++) {
695
+
696
+ if (h[i]->hash == 0) {
697
+ continue;
698
+ }
699
+
700
+ p = ngx_copy(p, h[i]->value.data, h[i]->value.len);
701
+
702
+ if (p == end) {
703
+ break;
704
+ }
705
+
706
+ *p++ = ';'; *p++ = ' ';
707
+ }
708
+
709
+ return NGX_OK;
710
+ }
711
+
712
+
713
+ static ngx_int_t
714
+ ngx_http_variable_unknown_header_in(ngx_http_request_t *r,
715
+ ngx_http_variable_value_t *v, uintptr_t data)
716
+ {
717
+ return ngx_http_variable_unknown_header(v, (ngx_str_t *) data,
718
+ &r->headers_in.headers.part,
719
+ sizeof("http_") - 1);
720
+ }
721
+
722
+
723
+ static ngx_int_t
724
+ ngx_http_variable_unknown_header_out(ngx_http_request_t *r,
725
+ ngx_http_variable_value_t *v, uintptr_t data)
726
+ {
727
+ return ngx_http_variable_unknown_header(v, (ngx_str_t *) data,
728
+ &r->headers_out.headers.part,
729
+ sizeof("sent_http_") - 1);
730
+ }
731
+
732
+
733
+ ngx_int_t
734
+ ngx_http_variable_unknown_header(ngx_http_variable_value_t *v, ngx_str_t *var,
735
+ ngx_list_part_t *part, size_t prefix)
736
+ {
737
+ u_char ch;
738
+ ngx_uint_t i, n;
739
+ ngx_table_elt_t *header;
740
+
741
+ header = part->elts;
742
+
743
+ for (i = 0; /* void */ ; i++) {
744
+
745
+ if (i >= part->nelts) {
746
+ if (part->next == NULL) {
747
+ break;
748
+ }
749
+
750
+ part = part->next;
751
+ header = part->elts;
752
+ i = 0;
753
+ }
754
+
755
+ if (header[i].hash == 0) {
756
+ continue;
757
+ }
758
+
759
+ for (n = 0; n + prefix < var->len && n < header[i].key.len; n++) {
760
+ ch = header[i].key.data[n];
761
+
762
+ if (ch >= 'A' && ch <= 'Z') {
763
+ ch |= 0x20;
764
+
765
+ } else if (ch == '-') {
766
+ ch = '_';
767
+ }
768
+
769
+ if (var->data[n + prefix] != ch) {
770
+ break;
771
+ }
772
+ }
773
+
774
+ if (n + prefix == var->len && n == header[i].key.len) {
775
+ v->len = header[i].value.len;
776
+ v->valid = 1;
777
+ v->no_cacheable = 0;
778
+ v->not_found = 0;
779
+ v->data = header[i].value.data;
780
+
781
+ return NGX_OK;
782
+ }
783
+ }
784
+
785
+ v->not_found = 1;
786
+
787
+ return NGX_OK;
788
+ }
789
+
790
+
791
+ static ngx_int_t
792
+ ngx_http_variable_request_line(ngx_http_request_t *r,
793
+ ngx_http_variable_value_t *v, uintptr_t data)
794
+ {
795
+ u_char *p, *s;
796
+
797
+ s = r->request_line.data;
798
+
799
+ if (s == NULL) {
800
+ s = r->request_start;
801
+
802
+ if (s == NULL) {
803
+ v->not_found = 1;
804
+ return NGX_OK;
805
+ }
806
+
807
+ for (p = s; p < r->header_in->last; p++) {
808
+ if (*p == CR || *p == LF) {
809
+ break;
810
+ }
811
+ }
812
+
813
+ r->request_line.len = p - s;
814
+ r->request_line.data = s;
815
+ }
816
+
817
+ v->len = r->request_line.len;
818
+ v->valid = 1;
819
+ v->no_cacheable = 0;
820
+ v->not_found = 0;
821
+ v->data = s;
822
+
823
+ return NGX_OK;
824
+ }
825
+
826
+
827
+ static ngx_int_t
828
+ ngx_http_variable_cookie(ngx_http_request_t *r, ngx_http_variable_value_t *v,
829
+ uintptr_t data)
830
+ {
831
+ ngx_str_t *name = (ngx_str_t *) data;
832
+
833
+ ngx_str_t cookie, s;
834
+
835
+ s.len = name->len - (sizeof("cookie_") - 1);
836
+ s.data = name->data + sizeof("cookie_") - 1;
837
+
838
+ if (ngx_http_parse_multi_header_lines(&r->headers_in.cookies, &s, &cookie)
839
+ == NGX_DECLINED)
840
+ {
841
+ v->not_found = 1;
842
+ return NGX_OK;
843
+ }
844
+
845
+ v->len = cookie.len;
846
+ v->valid = 1;
847
+ v->no_cacheable = 0;
848
+ v->not_found = 0;
849
+ v->data = cookie.data;
850
+
851
+ return NGX_OK;
852
+ }
853
+
854
+
855
+ static ngx_int_t
856
+ ngx_http_variable_argument(ngx_http_request_t *r, ngx_http_variable_value_t *v,
857
+ uintptr_t data)
858
+ {
859
+ ngx_str_t *name = (ngx_str_t *) data;
860
+
861
+ u_char *arg;
862
+ size_t len;
863
+ ngx_str_t value;
864
+
865
+ len = name->len - (sizeof("arg_") - 1);
866
+ arg = name->data + sizeof("arg_") - 1;
867
+
868
+ if (ngx_http_arg(r, arg, len, &value) != NGX_OK) {
869
+ v->not_found = 1;
870
+ return NGX_OK;
871
+ }
872
+
873
+ v->data = value.data;
874
+ v->len = value.len;
875
+ v->valid = 1;
876
+ v->no_cacheable = 0;
877
+ v->not_found = 0;
878
+
879
+ return NGX_OK;
880
+ }
881
+
882
+
883
+ static ngx_int_t
884
+ ngx_http_variable_host(ngx_http_request_t *r, ngx_http_variable_value_t *v,
885
+ uintptr_t data)
886
+ {
887
+ ngx_http_core_srv_conf_t *cscf;
888
+
889
+ if (r->headers_in.server.len) {
890
+ v->len = r->headers_in.server.len;
891
+ v->data = r->headers_in.server.data;
892
+
893
+ } else {
894
+ cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
895
+
896
+ v->len = cscf->server_name.len;
897
+ v->data = cscf->server_name.data;
898
+ }
899
+
900
+ v->valid = 1;
901
+ v->no_cacheable = 0;
902
+ v->not_found = 0;
903
+
904
+ return NGX_OK;
905
+ }
906
+
907
+
908
+ static ngx_int_t
909
+ ngx_http_variable_binary_remote_addr(ngx_http_request_t *r,
910
+ ngx_http_variable_value_t *v, uintptr_t data)
911
+ {
912
+ struct sockaddr_in *sin;
913
+ #if (NGX_HAVE_INET6)
914
+ struct sockaddr_in6 *sin6;
915
+ #endif
916
+
917
+ switch (r->connection->sockaddr->sa_family) {
918
+
919
+ #if (NGX_HAVE_INET6)
920
+ case AF_INET6:
921
+ sin6 = (struct sockaddr_in6 *) r->connection->sockaddr;
922
+
923
+ v->len = sizeof(struct in6_addr);
924
+ v->valid = 1;
925
+ v->no_cacheable = 0;
926
+ v->not_found = 0;
927
+ v->data = sin6->sin6_addr.s6_addr;
928
+
929
+ break;
930
+ #endif
931
+
932
+ default: /* AF_INET */
933
+ sin = (struct sockaddr_in *) r->connection->sockaddr;
934
+
935
+ v->len = sizeof(in_addr_t);
936
+ v->valid = 1;
937
+ v->no_cacheable = 0;
938
+ v->not_found = 0;
939
+ v->data = (u_char *) &sin->sin_addr;
940
+
941
+ break;
942
+ }
943
+
944
+ return NGX_OK;
945
+ }
946
+
947
+
948
+ static ngx_int_t
949
+ ngx_http_variable_remote_addr(ngx_http_request_t *r,
950
+ ngx_http_variable_value_t *v, uintptr_t data)
951
+ {
952
+ v->len = r->connection->addr_text.len;
953
+ v->valid = 1;
954
+ v->no_cacheable = 0;
955
+ v->not_found = 0;
956
+ v->data = r->connection->addr_text.data;
957
+
958
+ return NGX_OK;
959
+ }
960
+
961
+
962
+ static ngx_int_t
963
+ ngx_http_variable_remote_port(ngx_http_request_t *r,
964
+ ngx_http_variable_value_t *v, uintptr_t data)
965
+ {
966
+ ngx_uint_t port;
967
+ struct sockaddr_in *sin;
968
+ #if (NGX_HAVE_INET6)
969
+ struct sockaddr_in6 *sin6;
970
+ #endif
971
+
972
+ v->len = 0;
973
+ v->valid = 1;
974
+ v->no_cacheable = 0;
975
+ v->not_found = 0;
976
+
977
+ v->data = ngx_pnalloc(r->pool, sizeof("65535") - 1);
978
+ if (v->data == NULL) {
979
+ return NGX_ERROR;
980
+ }
981
+
982
+ switch (r->connection->sockaddr->sa_family) {
983
+
984
+ #if (NGX_HAVE_INET6)
985
+ case AF_INET6:
986
+ sin6 = (struct sockaddr_in6 *) r->connection->sockaddr;
987
+ port = ntohs(sin6->sin6_port);
988
+ break;
989
+ #endif
990
+
991
+ default: /* AF_INET */
992
+ sin = (struct sockaddr_in *) r->connection->sockaddr;
993
+ port = ntohs(sin->sin_port);
994
+ break;
995
+ }
996
+
997
+ if (port > 0 && port < 65536) {
998
+ v->len = ngx_sprintf(v->data, "%ui", port) - v->data;
999
+ }
1000
+
1001
+ return NGX_OK;
1002
+ }
1003
+
1004
+
1005
+ static ngx_int_t
1006
+ ngx_http_variable_server_addr(ngx_http_request_t *r,
1007
+ ngx_http_variable_value_t *v, uintptr_t data)
1008
+ {
1009
+ ngx_str_t s;
1010
+ u_char addr[NGX_SOCKADDR_STRLEN];
1011
+
1012
+ s.len = NGX_SOCKADDR_STRLEN;
1013
+ s.data = addr;
1014
+
1015
+ if (ngx_connection_local_sockaddr(r->connection, &s, 0) != NGX_OK) {
1016
+ return NGX_ERROR;
1017
+ }
1018
+
1019
+ s.data = ngx_pnalloc(r->pool, s.len);
1020
+ if (s.data == NULL) {
1021
+ return NGX_ERROR;
1022
+ }
1023
+
1024
+ ngx_memcpy(s.data, addr, s.len);
1025
+
1026
+ v->len = s.len;
1027
+ v->valid = 1;
1028
+ v->no_cacheable = 0;
1029
+ v->not_found = 0;
1030
+ v->data = s.data;
1031
+
1032
+ return NGX_OK;
1033
+ }
1034
+
1035
+
1036
+ static ngx_int_t
1037
+ ngx_http_variable_server_port(ngx_http_request_t *r,
1038
+ ngx_http_variable_value_t *v, uintptr_t data)
1039
+ {
1040
+ ngx_uint_t port;
1041
+ struct sockaddr_in *sin;
1042
+ #if (NGX_HAVE_INET6)
1043
+ struct sockaddr_in6 *sin6;
1044
+ #endif
1045
+
1046
+ v->len = 0;
1047
+ v->valid = 1;
1048
+ v->no_cacheable = 0;
1049
+ v->not_found = 0;
1050
+
1051
+ if (ngx_connection_local_sockaddr(r->connection, NULL, 0) != NGX_OK) {
1052
+ return NGX_ERROR;
1053
+ }
1054
+
1055
+ v->data = ngx_pnalloc(r->pool, sizeof("65535") - 1);
1056
+ if (v->data == NULL) {
1057
+ return NGX_ERROR;
1058
+ }
1059
+
1060
+ switch (r->connection->local_sockaddr->sa_family) {
1061
+
1062
+ #if (NGX_HAVE_INET6)
1063
+ case AF_INET6:
1064
+ sin6 = (struct sockaddr_in6 *) r->connection->local_sockaddr;
1065
+ port = ntohs(sin6->sin6_port);
1066
+ break;
1067
+ #endif
1068
+
1069
+ default: /* AF_INET */
1070
+ sin = (struct sockaddr_in *) r->connection->local_sockaddr;
1071
+ port = ntohs(sin->sin_port);
1072
+ break;
1073
+ }
1074
+
1075
+ if (port > 0 && port < 65536) {
1076
+ v->len = ngx_sprintf(v->data, "%ui", port) - v->data;
1077
+ }
1078
+
1079
+ return NGX_OK;
1080
+ }
1081
+
1082
+
1083
+ static ngx_int_t
1084
+ ngx_http_variable_scheme(ngx_http_request_t *r,
1085
+ ngx_http_variable_value_t *v, uintptr_t data)
1086
+ {
1087
+ #if (NGX_HTTP_SSL)
1088
+
1089
+ if (r->connection->ssl) {
1090
+ v->len = sizeof("https") - 1;
1091
+ v->valid = 1;
1092
+ v->no_cacheable = 0;
1093
+ v->not_found = 0;
1094
+ v->data = (u_char *) "https";
1095
+
1096
+ return NGX_OK;
1097
+ }
1098
+
1099
+ #endif
1100
+
1101
+ v->len = sizeof("http") - 1;
1102
+ v->valid = 1;
1103
+ v->no_cacheable = 0;
1104
+ v->not_found = 0;
1105
+ v->data = (u_char *) "http";
1106
+
1107
+ return NGX_OK;
1108
+ }
1109
+
1110
+
1111
+ static ngx_int_t
1112
+ ngx_http_variable_is_args(ngx_http_request_t *r,
1113
+ ngx_http_variable_value_t *v, uintptr_t data)
1114
+ {
1115
+ v->valid = 1;
1116
+ v->no_cacheable = 0;
1117
+ v->not_found = 0;
1118
+
1119
+ if (r->args.len == 0) {
1120
+ v->len = 0;
1121
+ v->data = NULL;
1122
+ return NGX_OK;
1123
+ }
1124
+
1125
+ v->len = 1;
1126
+ v->data = (u_char *) "?";
1127
+
1128
+ return NGX_OK;
1129
+ }
1130
+
1131
+
1132
+ static ngx_int_t
1133
+ ngx_http_variable_document_root(ngx_http_request_t *r,
1134
+ ngx_http_variable_value_t *v, uintptr_t data)
1135
+ {
1136
+ ngx_str_t path;
1137
+ ngx_http_core_loc_conf_t *clcf;
1138
+
1139
+ clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1140
+
1141
+ if (clcf->root_lengths == NULL) {
1142
+ v->len = clcf->root.len;
1143
+ v->valid = 1;
1144
+ v->no_cacheable = 0;
1145
+ v->not_found = 0;
1146
+ v->data = clcf->root.data;
1147
+
1148
+ } else {
1149
+ if (ngx_http_script_run(r, &path, clcf->root_lengths->elts, 0,
1150
+ clcf->root_values->elts)
1151
+ == NULL)
1152
+ {
1153
+ return NGX_ERROR;
1154
+ }
1155
+
1156
+ if (ngx_conf_full_name((ngx_cycle_t *) ngx_cycle, &path, 0) != NGX_OK) {
1157
+ return NGX_ERROR;
1158
+ }
1159
+
1160
+ v->len = path.len;
1161
+ v->valid = 1;
1162
+ v->no_cacheable = 0;
1163
+ v->not_found = 0;
1164
+ v->data = path.data;
1165
+ }
1166
+
1167
+ return NGX_OK;
1168
+ }
1169
+
1170
+
1171
+ static ngx_int_t
1172
+ ngx_http_variable_realpath_root(ngx_http_request_t *r,
1173
+ ngx_http_variable_value_t *v, uintptr_t data)
1174
+ {
1175
+ size_t len;
1176
+ ngx_str_t path;
1177
+ ngx_http_core_loc_conf_t *clcf;
1178
+ u_char real[NGX_MAX_PATH];
1179
+
1180
+ clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1181
+
1182
+ if (clcf->root_lengths == NULL) {
1183
+ path = clcf->root;
1184
+
1185
+ } else {
1186
+ if (ngx_http_script_run(r, &path, clcf->root_lengths->elts, 1,
1187
+ clcf->root_values->elts)
1188
+ == NULL)
1189
+ {
1190
+ return NGX_ERROR;
1191
+ }
1192
+
1193
+ path.data[path.len - 1] = '\0';
1194
+
1195
+ if (ngx_conf_full_name((ngx_cycle_t *) ngx_cycle, &path, 0) != NGX_OK) {
1196
+ return NGX_ERROR;
1197
+ }
1198
+ }
1199
+
1200
+ if (ngx_realpath(path.data, real) == NULL) {
1201
+ ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno,
1202
+ ngx_realpath_n " \"%s\" failed", path.data);
1203
+ return NGX_ERROR;
1204
+ }
1205
+
1206
+ len = ngx_strlen(real);
1207
+
1208
+ v->data = ngx_pnalloc(r->pool, len);
1209
+ if (v->data == NULL) {
1210
+ return NGX_ERROR;
1211
+ }
1212
+
1213
+ v->len = len;
1214
+ v->valid = 1;
1215
+ v->no_cacheable = 0;
1216
+ v->not_found = 0;
1217
+
1218
+ ngx_memcpy(v->data, real, len);
1219
+
1220
+ return NGX_OK;
1221
+ }
1222
+
1223
+
1224
+ static ngx_int_t
1225
+ ngx_http_variable_request_filename(ngx_http_request_t *r,
1226
+ ngx_http_variable_value_t *v, uintptr_t data)
1227
+ {
1228
+ size_t root;
1229
+ ngx_str_t path;
1230
+
1231
+ if (ngx_http_map_uri_to_path(r, &path, &root, 0) == NULL) {
1232
+ return NGX_ERROR;
1233
+ }
1234
+
1235
+ /* ngx_http_map_uri_to_path() allocates memory for terminating '\0' */
1236
+
1237
+ v->len = path.len - 1;
1238
+ v->valid = 1;
1239
+ v->no_cacheable = 0;
1240
+ v->not_found = 0;
1241
+ v->data = path.data;
1242
+
1243
+ return NGX_OK;
1244
+ }
1245
+
1246
+
1247
+ static ngx_int_t
1248
+ ngx_http_variable_server_name(ngx_http_request_t *r,
1249
+ ngx_http_variable_value_t *v, uintptr_t data)
1250
+ {
1251
+ ngx_http_core_srv_conf_t *cscf;
1252
+
1253
+ cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
1254
+
1255
+ v->len = cscf->server_name.len;
1256
+ v->valid = 1;
1257
+ v->no_cacheable = 0;
1258
+ v->not_found = 0;
1259
+ v->data = cscf->server_name.data;
1260
+
1261
+ return NGX_OK;
1262
+ }
1263
+
1264
+
1265
+ static ngx_int_t
1266
+ ngx_http_variable_request_method(ngx_http_request_t *r,
1267
+ ngx_http_variable_value_t *v, uintptr_t data)
1268
+ {
1269
+ if (r->main->method_name.data) {
1270
+ v->len = r->main->method_name.len;
1271
+ v->valid = 1;
1272
+ v->no_cacheable = 0;
1273
+ v->not_found = 0;
1274
+ v->data = r->main->method_name.data;
1275
+
1276
+ } else {
1277
+ v->not_found = 1;
1278
+ }
1279
+
1280
+ return NGX_OK;
1281
+ }
1282
+
1283
+
1284
+ static ngx_int_t
1285
+ ngx_http_variable_remote_user(ngx_http_request_t *r,
1286
+ ngx_http_variable_value_t *v, uintptr_t data)
1287
+ {
1288
+ ngx_int_t rc;
1289
+
1290
+ rc = ngx_http_auth_basic_user(r);
1291
+
1292
+ if (rc == NGX_DECLINED) {
1293
+ v->not_found = 1;
1294
+ return NGX_OK;
1295
+ }
1296
+
1297
+ if (rc == NGX_ERROR) {
1298
+ return NGX_ERROR;
1299
+ }
1300
+
1301
+ v->len = r->headers_in.user.len;
1302
+ v->valid = 1;
1303
+ v->no_cacheable = 0;
1304
+ v->not_found = 0;
1305
+ v->data = r->headers_in.user.data;
1306
+
1307
+ return NGX_OK;
1308
+ }
1309
+
1310
+
1311
+ static ngx_int_t
1312
+ ngx_http_variable_body_bytes_sent(ngx_http_request_t *r,
1313
+ ngx_http_variable_value_t *v, uintptr_t data)
1314
+ {
1315
+ off_t sent;
1316
+ u_char *p;
1317
+
1318
+ sent = r->connection->sent - r->header_size;
1319
+
1320
+ if (sent < 0) {
1321
+ sent = 0;
1322
+ }
1323
+
1324
+ p = ngx_pnalloc(r->pool, NGX_OFF_T_LEN);
1325
+ if (p == NULL) {
1326
+ return NGX_ERROR;
1327
+ }
1328
+
1329
+ v->len = ngx_sprintf(p, "%O", sent) - p;
1330
+ v->valid = 1;
1331
+ v->no_cacheable = 0;
1332
+ v->not_found = 0;
1333
+ v->data = p;
1334
+
1335
+ return NGX_OK;
1336
+ }
1337
+
1338
+
1339
+ static ngx_int_t
1340
+ ngx_http_variable_sent_content_type(ngx_http_request_t *r,
1341
+ ngx_http_variable_value_t *v, uintptr_t data)
1342
+ {
1343
+ if (r->headers_out.content_type.len) {
1344
+ v->len = r->headers_out.content_type.len;
1345
+ v->valid = 1;
1346
+ v->no_cacheable = 0;
1347
+ v->not_found = 0;
1348
+ v->data = r->headers_out.content_type.data;
1349
+
1350
+ } else {
1351
+ v->not_found = 1;
1352
+ }
1353
+
1354
+ return NGX_OK;
1355
+ }
1356
+
1357
+
1358
+ static ngx_int_t
1359
+ ngx_http_variable_sent_content_length(ngx_http_request_t *r,
1360
+ ngx_http_variable_value_t *v, uintptr_t data)
1361
+ {
1362
+ u_char *p;
1363
+
1364
+ if (r->headers_out.content_length) {
1365
+ v->len = r->headers_out.content_length->value.len;
1366
+ v->valid = 1;
1367
+ v->no_cacheable = 0;
1368
+ v->not_found = 0;
1369
+ v->data = r->headers_out.content_length->value.data;
1370
+
1371
+ return NGX_OK;
1372
+ }
1373
+
1374
+ if (r->headers_out.content_length_n >= 0) {
1375
+ p = ngx_pnalloc(r->pool, NGX_OFF_T_LEN);
1376
+ if (p == NULL) {
1377
+ return NGX_ERROR;
1378
+ }
1379
+
1380
+ v->len = ngx_sprintf(p, "%O", r->headers_out.content_length_n) - p;
1381
+ v->valid = 1;
1382
+ v->no_cacheable = 0;
1383
+ v->not_found = 0;
1384
+ v->data = p;
1385
+
1386
+ return NGX_OK;
1387
+ }
1388
+
1389
+ v->not_found = 1;
1390
+
1391
+ return NGX_OK;
1392
+ }
1393
+
1394
+
1395
+ static ngx_int_t
1396
+ ngx_http_variable_sent_location(ngx_http_request_t *r,
1397
+ ngx_http_variable_value_t *v, uintptr_t data)
1398
+ {
1399
+ ngx_str_t name;
1400
+
1401
+ if (r->headers_out.location) {
1402
+ v->len = r->headers_out.location->value.len;
1403
+ v->valid = 1;
1404
+ v->no_cacheable = 0;
1405
+ v->not_found = 0;
1406
+ v->data = r->headers_out.location->value.data;
1407
+
1408
+ return NGX_OK;
1409
+ }
1410
+
1411
+ ngx_str_set(&name, "sent_http_location");
1412
+
1413
+ return ngx_http_variable_unknown_header(v, &name,
1414
+ &r->headers_out.headers.part,
1415
+ sizeof("sent_http_") - 1);
1416
+ }
1417
+
1418
+
1419
+ static ngx_int_t
1420
+ ngx_http_variable_sent_last_modified(ngx_http_request_t *r,
1421
+ ngx_http_variable_value_t *v, uintptr_t data)
1422
+ {
1423
+ u_char *p;
1424
+
1425
+ if (r->headers_out.last_modified) {
1426
+ v->len = r->headers_out.last_modified->value.len;
1427
+ v->valid = 1;
1428
+ v->no_cacheable = 0;
1429
+ v->not_found = 0;
1430
+ v->data = r->headers_out.last_modified->value.data;
1431
+
1432
+ return NGX_OK;
1433
+ }
1434
+
1435
+ if (r->headers_out.last_modified_time >= 0) {
1436
+ p = ngx_pnalloc(r->pool,
1437
+ sizeof("Last-Modified: Mon, 28 Sep 1970 06:00:00 GMT") - 1);
1438
+ if (p == NULL) {
1439
+ return NGX_ERROR;
1440
+ }
1441
+
1442
+ v->len = ngx_http_time(p, r->headers_out.last_modified_time) - p;
1443
+ v->valid = 1;
1444
+ v->no_cacheable = 0;
1445
+ v->not_found = 0;
1446
+ v->data = p;
1447
+
1448
+ return NGX_OK;
1449
+ }
1450
+
1451
+ v->not_found = 1;
1452
+
1453
+ return NGX_OK;
1454
+ }
1455
+
1456
+
1457
+ static ngx_int_t
1458
+ ngx_http_variable_sent_connection(ngx_http_request_t *r,
1459
+ ngx_http_variable_value_t *v, uintptr_t data)
1460
+ {
1461
+ size_t len;
1462
+ char *p;
1463
+
1464
+ if (r->keepalive) {
1465
+ len = sizeof("keep-alive") - 1;
1466
+ p = "keep-alive";
1467
+
1468
+ } else {
1469
+ len = sizeof("close") - 1;
1470
+ p = "close";
1471
+ }
1472
+
1473
+ v->len = len;
1474
+ v->valid = 1;
1475
+ v->no_cacheable = 0;
1476
+ v->not_found = 0;
1477
+ v->data = (u_char *) p;
1478
+
1479
+ return NGX_OK;
1480
+ }
1481
+
1482
+
1483
+ static ngx_int_t
1484
+ ngx_http_variable_sent_keep_alive(ngx_http_request_t *r,
1485
+ ngx_http_variable_value_t *v, uintptr_t data)
1486
+ {
1487
+ u_char *p;
1488
+ ngx_http_core_loc_conf_t *clcf;
1489
+
1490
+ if (r->keepalive) {
1491
+ clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
1492
+
1493
+ if (clcf->keepalive_header) {
1494
+
1495
+ p = ngx_pnalloc(r->pool, sizeof("timeout=") - 1 + NGX_TIME_T_LEN);
1496
+ if (p == NULL) {
1497
+ return NGX_ERROR;
1498
+ }
1499
+
1500
+ v->len = ngx_sprintf(p, "timeout=%T", clcf->keepalive_header) - p;
1501
+ v->valid = 1;
1502
+ v->no_cacheable = 0;
1503
+ v->not_found = 0;
1504
+ v->data = p;
1505
+
1506
+ return NGX_OK;
1507
+ }
1508
+ }
1509
+
1510
+ v->not_found = 1;
1511
+
1512
+ return NGX_OK;
1513
+ }
1514
+
1515
+
1516
+ static ngx_int_t
1517
+ ngx_http_variable_sent_transfer_encoding(ngx_http_request_t *r,
1518
+ ngx_http_variable_value_t *v, uintptr_t data)
1519
+ {
1520
+ if (r->chunked) {
1521
+ v->len = sizeof("chunked") - 1;
1522
+ v->valid = 1;
1523
+ v->no_cacheable = 0;
1524
+ v->not_found = 0;
1525
+ v->data = (u_char *) "chunked";
1526
+
1527
+ } else {
1528
+ v->not_found = 1;
1529
+ }
1530
+
1531
+ return NGX_OK;
1532
+ }
1533
+
1534
+
1535
+ static ngx_int_t
1536
+ ngx_http_variable_request_completion(ngx_http_request_t *r,
1537
+ ngx_http_variable_value_t *v, uintptr_t data)
1538
+ {
1539
+ if (r->request_complete) {
1540
+ v->len = 2;
1541
+ v->valid = 1;
1542
+ v->no_cacheable = 0;
1543
+ v->not_found = 0;
1544
+ v->data = (u_char *) "OK";
1545
+
1546
+ return NGX_OK;
1547
+ }
1548
+
1549
+ v->len = 0;
1550
+ v->valid = 1;
1551
+ v->no_cacheable = 0;
1552
+ v->not_found = 0;
1553
+ v->data = (u_char *) "";
1554
+
1555
+ return NGX_OK;
1556
+ }
1557
+
1558
+
1559
+ static ngx_int_t
1560
+ ngx_http_variable_request_body(ngx_http_request_t *r,
1561
+ ngx_http_variable_value_t *v, uintptr_t data)
1562
+ {
1563
+ u_char *p;
1564
+ size_t len;
1565
+ ngx_buf_t *buf, *next;
1566
+ ngx_chain_t *cl;
1567
+
1568
+ if (r->request_body == NULL
1569
+ || r->request_body->bufs == NULL
1570
+ || r->request_body->temp_file)
1571
+ {
1572
+ v->not_found = 1;
1573
+
1574
+ return NGX_OK;
1575
+ }
1576
+
1577
+ cl = r->request_body->bufs;
1578
+ buf = cl->buf;
1579
+
1580
+ if (cl->next == NULL) {
1581
+ v->len = buf->last - buf->pos;
1582
+ v->valid = 1;
1583
+ v->no_cacheable = 0;
1584
+ v->not_found = 0;
1585
+ v->data = buf->pos;
1586
+
1587
+ return NGX_OK;
1588
+ }
1589
+
1590
+ next = cl->next->buf;
1591
+ len = (buf->last - buf->pos) + (next->last - next->pos);
1592
+
1593
+ p = ngx_pnalloc(r->pool, len);
1594
+ if (p == NULL) {
1595
+ return NGX_ERROR;
1596
+ }
1597
+
1598
+ v->data = p;
1599
+
1600
+ p = ngx_cpymem(p, buf->pos, buf->last - buf->pos);
1601
+ ngx_memcpy(p, next->pos, next->last - next->pos);
1602
+
1603
+ v->len = len;
1604
+ v->valid = 1;
1605
+ v->no_cacheable = 0;
1606
+ v->not_found = 0;
1607
+
1608
+ return NGX_OK;
1609
+ }
1610
+
1611
+
1612
+ static ngx_int_t
1613
+ ngx_http_variable_request_body_file(ngx_http_request_t *r,
1614
+ ngx_http_variable_value_t *v, uintptr_t data)
1615
+ {
1616
+ if (r->request_body == NULL || r->request_body->temp_file == NULL) {
1617
+ v->not_found = 1;
1618
+
1619
+ return NGX_OK;
1620
+ }
1621
+
1622
+ v->len = r->request_body->temp_file->file.name.len;
1623
+ v->valid = 1;
1624
+ v->no_cacheable = 0;
1625
+ v->not_found = 0;
1626
+ v->data = r->request_body->temp_file->file.name.data;
1627
+
1628
+ return NGX_OK;
1629
+ }
1630
+
1631
+
1632
+ static ngx_int_t
1633
+ ngx_http_variable_nginx_version(ngx_http_request_t *r,
1634
+ ngx_http_variable_value_t *v, uintptr_t data)
1635
+ {
1636
+ v->len = sizeof(NGINX_VERSION) - 1;
1637
+ v->valid = 1;
1638
+ v->no_cacheable = 0;
1639
+ v->not_found = 0;
1640
+ v->data = (u_char *) NGINX_VERSION;
1641
+
1642
+ return NGX_OK;
1643
+ }
1644
+
1645
+
1646
+ static ngx_int_t
1647
+ ngx_http_variable_hostname(ngx_http_request_t *r,
1648
+ ngx_http_variable_value_t *v, uintptr_t data)
1649
+ {
1650
+ v->len = ngx_cycle->hostname.len;
1651
+ v->valid = 1;
1652
+ v->no_cacheable = 0;
1653
+ v->not_found = 0;
1654
+ v->data = ngx_cycle->hostname.data;
1655
+
1656
+ return NGX_OK;
1657
+ }
1658
+
1659
+
1660
+ static ngx_int_t
1661
+ ngx_http_variable_pid(ngx_http_request_t *r,
1662
+ ngx_http_variable_value_t *v, uintptr_t data)
1663
+ {
1664
+ u_char *p;
1665
+
1666
+ p = ngx_pnalloc(r->pool, NGX_INT64_LEN);
1667
+ if (p == NULL) {
1668
+ return NGX_ERROR;
1669
+ }
1670
+
1671
+ v->len = ngx_sprintf(p, "%P", ngx_pid) - p;
1672
+ v->valid = 1;
1673
+ v->no_cacheable = 0;
1674
+ v->not_found = 0;
1675
+ v->data = p;
1676
+
1677
+ return NGX_OK;
1678
+ }
1679
+
1680
+
1681
+ void *
1682
+ ngx_http_map_find(ngx_http_request_t *r, ngx_http_map_t *map, ngx_str_t *match)
1683
+ {
1684
+ void *value;
1685
+ u_char *low;
1686
+ size_t len;
1687
+ ngx_uint_t key;
1688
+
1689
+ len = match->len;
1690
+
1691
+ if (len) {
1692
+ low = ngx_pnalloc(r->pool, len);
1693
+ if (low == NULL) {
1694
+ return NULL;
1695
+ }
1696
+
1697
+ } else {
1698
+ low = NULL;
1699
+ }
1700
+
1701
+ key = ngx_hash_strlow(low, match->data, len);
1702
+
1703
+ value = ngx_hash_find_combined(&map->hash, key, low, len);
1704
+ if (value) {
1705
+ return value;
1706
+ }
1707
+
1708
+ #if (NGX_PCRE)
1709
+
1710
+ if (len && map->nregex) {
1711
+ ngx_int_t n;
1712
+ ngx_uint_t i;
1713
+ ngx_http_map_regex_t *reg;
1714
+
1715
+ reg = map->regex;
1716
+
1717
+ for (i = 0; i < map->nregex; i++) {
1718
+
1719
+ n = ngx_http_regex_exec(r, reg[i].regex, match);
1720
+
1721
+ if (n == NGX_OK) {
1722
+ return reg[i].value;
1723
+ }
1724
+
1725
+ if (n == NGX_DECLINED) {
1726
+ continue;
1727
+ }
1728
+
1729
+ /* NGX_ERROR */
1730
+
1731
+ return NULL;
1732
+ }
1733
+ }
1734
+
1735
+ #endif
1736
+
1737
+ return NULL;
1738
+ }
1739
+
1740
+
1741
+ #if (NGX_PCRE)
1742
+
1743
+ static ngx_int_t
1744
+ ngx_http_variable_not_found(ngx_http_request_t *r, ngx_http_variable_value_t *v,
1745
+ uintptr_t data)
1746
+ {
1747
+ v->not_found = 1;
1748
+ return NGX_OK;
1749
+ }
1750
+
1751
+
1752
+ ngx_http_regex_t *
1753
+ ngx_http_regex_compile(ngx_conf_t *cf, ngx_regex_compile_t *rc)
1754
+ {
1755
+ u_char *p;
1756
+ size_t size;
1757
+ ngx_str_t name;
1758
+ ngx_uint_t i, n;
1759
+ ngx_http_variable_t *v;
1760
+ ngx_http_regex_t *re;
1761
+ ngx_http_regex_variable_t *rv;
1762
+ ngx_http_core_main_conf_t *cmcf;
1763
+
1764
+ rc->pool = cf->pool;
1765
+
1766
+ if (ngx_regex_compile(rc) != NGX_OK) {
1767
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V", &rc->err);
1768
+ return NULL;
1769
+ }
1770
+
1771
+ re = ngx_pcalloc(cf->pool, sizeof(ngx_http_regex_t));
1772
+ if (re == NULL) {
1773
+ return NULL;
1774
+ }
1775
+
1776
+ re->regex = rc->regex;
1777
+ re->ncaptures = rc->captures;
1778
+
1779
+ cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
1780
+ cmcf->ncaptures = ngx_max(cmcf->ncaptures, re->ncaptures);
1781
+
1782
+ n = (ngx_uint_t) rc->named_captures;
1783
+
1784
+ if (n == 0) {
1785
+ return re;
1786
+ }
1787
+
1788
+ rv = ngx_palloc(rc->pool, n * sizeof(ngx_http_regex_variable_t));
1789
+ if (rv == NULL) {
1790
+ return NULL;
1791
+ }
1792
+
1793
+ re->variables = rv;
1794
+ re->nvariables = n;
1795
+ re->name = rc->pattern;
1796
+
1797
+ size = rc->name_size;
1798
+ p = rc->names;
1799
+
1800
+ for (i = 0; i < n; i++) {
1801
+ rv[i].capture = 2 * ((p[0] << 8) + p[1]);
1802
+
1803
+ name.data = &p[2];
1804
+ name.len = ngx_strlen(name.data);
1805
+
1806
+ v = ngx_http_add_variable(cf, &name, NGX_HTTP_VAR_CHANGEABLE);
1807
+ if (v == NULL) {
1808
+ return NULL;
1809
+ }
1810
+
1811
+ rv[i].index = ngx_http_get_variable_index(cf, &name);
1812
+ if (rv[i].index == NGX_ERROR) {
1813
+ return NULL;
1814
+ }
1815
+
1816
+ v->get_handler = ngx_http_variable_not_found;
1817
+
1818
+ p += size;
1819
+ }
1820
+
1821
+ return re;
1822
+ }
1823
+
1824
+
1825
+ ngx_int_t
1826
+ ngx_http_regex_exec(ngx_http_request_t *r, ngx_http_regex_t *re, ngx_str_t *s)
1827
+ {
1828
+ ngx_int_t rc, index;
1829
+ ngx_uint_t i, n, len;
1830
+ ngx_http_variable_value_t *vv;
1831
+ ngx_http_core_main_conf_t *cmcf;
1832
+
1833
+ cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
1834
+
1835
+ if (re->ncaptures) {
1836
+ len = cmcf->ncaptures;
1837
+
1838
+ if (r->captures == NULL) {
1839
+ r->captures = ngx_palloc(r->pool, len * sizeof(int));
1840
+ if (r->captures == NULL) {
1841
+ return NGX_ERROR;
1842
+ }
1843
+ }
1844
+
1845
+ } else {
1846
+ len = 0;
1847
+ }
1848
+
1849
+ rc = ngx_regex_exec(re->regex, s, r->captures, len);
1850
+
1851
+ if (rc == NGX_REGEX_NO_MATCHED) {
1852
+ return NGX_DECLINED;
1853
+ }
1854
+
1855
+ if (rc < 0) {
1856
+ ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
1857
+ ngx_regex_exec_n " failed: %i on \"%V\" using \"%V\"",
1858
+ rc, s, &re->name);
1859
+ return NGX_ERROR;
1860
+ }
1861
+
1862
+ for (i = 0; i < re->nvariables; i++) {
1863
+
1864
+ n = re->variables[i].capture;
1865
+ index = re->variables[i].index;
1866
+ vv = &r->variables[index];
1867
+
1868
+ vv->len = r->captures[n + 1] - r->captures[n];
1869
+ vv->valid = 1;
1870
+ vv->no_cacheable = 0;
1871
+ vv->not_found = 0;
1872
+ vv->data = &s->data[r->captures[n]];
1873
+
1874
+ #if (NGX_DEBUG)
1875
+ {
1876
+ ngx_http_variable_t *v;
1877
+
1878
+ v = cmcf->variables.elts;
1879
+
1880
+ ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1881
+ "http regex set $%V to \"%*s\"",
1882
+ &v[index].name, vv->len, vv->data);
1883
+ }
1884
+ #endif
1885
+ }
1886
+
1887
+ r->ncaptures = rc * 2;
1888
+ r->captures_data = s->data;
1889
+
1890
+ return NGX_OK;
1891
+ }
1892
+
1893
+ #endif
1894
+
1895
+
1896
+ ngx_int_t
1897
+ ngx_http_variables_add_core_vars(ngx_conf_t *cf)
1898
+ {
1899
+ ngx_int_t rc;
1900
+ ngx_http_variable_t *v;
1901
+ ngx_http_core_main_conf_t *cmcf;
1902
+
1903
+ cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
1904
+
1905
+ cmcf->variables_keys = ngx_pcalloc(cf->temp_pool,
1906
+ sizeof(ngx_hash_keys_arrays_t));
1907
+ if (cmcf->variables_keys == NULL) {
1908
+ return NGX_ERROR;
1909
+ }
1910
+
1911
+ cmcf->variables_keys->pool = cf->pool;
1912
+ cmcf->variables_keys->temp_pool = cf->pool;
1913
+
1914
+ if (ngx_hash_keys_array_init(cmcf->variables_keys, NGX_HASH_SMALL)
1915
+ != NGX_OK)
1916
+ {
1917
+ return NGX_ERROR;
1918
+ }
1919
+
1920
+ for (v = ngx_http_core_variables; v->name.len; v++) {
1921
+ rc = ngx_hash_add_key(cmcf->variables_keys, &v->name, v,
1922
+ NGX_HASH_READONLY_KEY);
1923
+
1924
+ if (rc == NGX_OK) {
1925
+ continue;
1926
+ }
1927
+
1928
+ if (rc == NGX_BUSY) {
1929
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1930
+ "conflicting variable name \"%V\"", &v->name);
1931
+ }
1932
+
1933
+ return NGX_ERROR;
1934
+ }
1935
+
1936
+ return NGX_OK;
1937
+ }
1938
+
1939
+
1940
+ ngx_int_t
1941
+ ngx_http_variables_init_vars(ngx_conf_t *cf)
1942
+ {
1943
+ ngx_uint_t i, n;
1944
+ ngx_hash_key_t *key;
1945
+ ngx_hash_init_t hash;
1946
+ ngx_http_variable_t *v, *av;
1947
+ ngx_http_core_main_conf_t *cmcf;
1948
+
1949
+ /* set the handlers for the indexed http variables */
1950
+
1951
+ cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
1952
+
1953
+ v = cmcf->variables.elts;
1954
+ key = cmcf->variables_keys->keys.elts;
1955
+
1956
+ for (i = 0; i < cmcf->variables.nelts; i++) {
1957
+
1958
+ for (n = 0; n < cmcf->variables_keys->keys.nelts; n++) {
1959
+
1960
+ av = key[n].value;
1961
+
1962
+ if (av->get_handler
1963
+ && v[i].name.len == key[n].key.len
1964
+ && ngx_strncmp(v[i].name.data, key[n].key.data, v[i].name.len)
1965
+ == 0)
1966
+ {
1967
+ v[i].get_handler = av->get_handler;
1968
+ v[i].data = av->data;
1969
+
1970
+ av->flags |= NGX_HTTP_VAR_INDEXED;
1971
+ v[i].flags = av->flags;
1972
+
1973
+ av->index = i;
1974
+
1975
+ goto next;
1976
+ }
1977
+ }
1978
+
1979
+ if (ngx_strncmp(v[i].name.data, "http_", 5) == 0) {
1980
+ v[i].get_handler = ngx_http_variable_unknown_header_in;
1981
+ v[i].data = (uintptr_t) &v[i].name;
1982
+
1983
+ continue;
1984
+ }
1985
+
1986
+ if (ngx_strncmp(v[i].name.data, "sent_http_", 10) == 0) {
1987
+ v[i].get_handler = ngx_http_variable_unknown_header_out;
1988
+ v[i].data = (uintptr_t) &v[i].name;
1989
+
1990
+ continue;
1991
+ }
1992
+
1993
+ if (ngx_strncmp(v[i].name.data, "upstream_http_", 14) == 0) {
1994
+ v[i].get_handler = ngx_http_upstream_header_variable;
1995
+ v[i].data = (uintptr_t) &v[i].name;
1996
+ v[i].flags = NGX_HTTP_VAR_NOCACHEABLE;
1997
+
1998
+ continue;
1999
+ }
2000
+
2001
+ if (ngx_strncmp(v[i].name.data, "cookie_", 7) == 0) {
2002
+ v[i].get_handler = ngx_http_variable_cookie;
2003
+ v[i].data = (uintptr_t) &v[i].name;
2004
+
2005
+ continue;
2006
+ }
2007
+
2008
+ if (ngx_strncmp(v[i].name.data, "arg_", 4) == 0) {
2009
+ v[i].get_handler = ngx_http_variable_argument;
2010
+ v[i].data = (uintptr_t) &v[i].name;
2011
+ v[i].flags = NGX_HTTP_VAR_NOCACHEABLE;
2012
+
2013
+ continue;
2014
+ }
2015
+
2016
+ ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
2017
+ "unknown \"%V\" variable", &v[i].name);
2018
+
2019
+ return NGX_ERROR;
2020
+
2021
+ next:
2022
+ continue;
2023
+ }
2024
+
2025
+
2026
+ for (n = 0; n < cmcf->variables_keys->keys.nelts; n++) {
2027
+ av = key[n].value;
2028
+
2029
+ if (av->flags & NGX_HTTP_VAR_NOHASH) {
2030
+ key[n].key.data = NULL;
2031
+ }
2032
+ }
2033
+
2034
+
2035
+ hash.hash = &cmcf->variables_hash;
2036
+ hash.key = ngx_hash_key;
2037
+ hash.max_size = cmcf->variables_hash_max_size;
2038
+ hash.bucket_size = cmcf->variables_hash_bucket_size;
2039
+ hash.name = "variables_hash";
2040
+ hash.pool = cf->pool;
2041
+ hash.temp_pool = NULL;
2042
+
2043
+ if (ngx_hash_init(&hash, cmcf->variables_keys->keys.elts,
2044
+ cmcf->variables_keys->keys.nelts)
2045
+ != NGX_OK)
2046
+ {
2047
+ return NGX_ERROR;
2048
+ }
2049
+
2050
+ cmcf->variables_keys = NULL;
2051
+
2052
+ return NGX_OK;
2053
+ }