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,54 @@
1
+
2
+ /*
3
+ * Copyright (C) Igor Sysoev
4
+ * Copyright (C) Nginx, Inc.
5
+ */
6
+
7
+
8
+ #ifndef _NGX_SLAB_H_INCLUDED_
9
+ #define _NGX_SLAB_H_INCLUDED_
10
+
11
+
12
+ #include <ngx_config.h>
13
+ #include <ngx_core.h>
14
+
15
+
16
+ typedef struct ngx_slab_page_s ngx_slab_page_t;
17
+
18
+ struct ngx_slab_page_s {
19
+ uintptr_t slab;
20
+ ngx_slab_page_t *next;
21
+ uintptr_t prev;
22
+ };
23
+
24
+
25
+ typedef struct {
26
+ ngx_atomic_t lock;
27
+
28
+ size_t min_size;
29
+ size_t min_shift;
30
+
31
+ ngx_slab_page_t *pages;
32
+ ngx_slab_page_t free;
33
+
34
+ u_char *start;
35
+ u_char *end;
36
+
37
+ ngx_shmtx_t mutex;
38
+
39
+ u_char *log_ctx;
40
+ u_char zero;
41
+
42
+ void *data;
43
+ void *addr;
44
+ } ngx_slab_pool_t;
45
+
46
+
47
+ void ngx_slab_init(ngx_slab_pool_t *pool);
48
+ void *ngx_slab_alloc(ngx_slab_pool_t *pool, size_t size);
49
+ void *ngx_slab_alloc_locked(ngx_slab_pool_t *pool, size_t size);
50
+ void ngx_slab_free(ngx_slab_pool_t *pool, void *p);
51
+ void ngx_slab_free_locked(ngx_slab_pool_t *pool, void *p);
52
+
53
+
54
+ #endif /* _NGX_SLAB_H_INCLUDED_ */
@@ -0,0 +1,53 @@
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
+
11
+
12
+ void
13
+ ngx_spinlock(ngx_atomic_t *lock, ngx_atomic_int_t value, ngx_uint_t spin)
14
+ {
15
+
16
+ #if (NGX_HAVE_ATOMIC_OPS)
17
+
18
+ ngx_uint_t i, n;
19
+
20
+ for ( ;; ) {
21
+
22
+ if (*lock == 0 && ngx_atomic_cmp_set(lock, 0, value)) {
23
+ return;
24
+ }
25
+
26
+ if (ngx_ncpu > 1) {
27
+
28
+ for (n = 1; n < spin; n <<= 1) {
29
+
30
+ for (i = 0; i < n; i++) {
31
+ ngx_cpu_pause();
32
+ }
33
+
34
+ if (*lock == 0 && ngx_atomic_cmp_set(lock, 0, value)) {
35
+ return;
36
+ }
37
+ }
38
+ }
39
+
40
+ ngx_sched_yield();
41
+ }
42
+
43
+ #else
44
+
45
+ #if (NGX_THREADS)
46
+
47
+ #error ngx_spinlock() or ngx_atomic_cmp_set() are not defined !
48
+
49
+ #endif
50
+
51
+ #endif
52
+
53
+ }
@@ -0,0 +1,1837 @@
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
+
11
+
12
+ static u_char *ngx_sprintf_num(u_char *buf, u_char *last, uint64_t ui64,
13
+ u_char zero, ngx_uint_t hexadecimal, ngx_uint_t width);
14
+ static ngx_int_t ngx_decode_base64_internal(ngx_str_t *dst, ngx_str_t *src,
15
+ const u_char *basis);
16
+
17
+
18
+ void
19
+ ngx_strlow(u_char *dst, u_char *src, size_t n)
20
+ {
21
+ while (n) {
22
+ *dst = ngx_tolower(*src);
23
+ dst++;
24
+ src++;
25
+ n--;
26
+ }
27
+ }
28
+
29
+
30
+ u_char *
31
+ ngx_cpystrn(u_char *dst, u_char *src, size_t n)
32
+ {
33
+ if (n == 0) {
34
+ return dst;
35
+ }
36
+
37
+ while (--n) {
38
+ *dst = *src;
39
+
40
+ if (*dst == '\0') {
41
+ return dst;
42
+ }
43
+
44
+ dst++;
45
+ src++;
46
+ }
47
+
48
+ *dst = '\0';
49
+
50
+ return dst;
51
+ }
52
+
53
+
54
+ u_char *
55
+ ngx_pstrdup(ngx_pool_t *pool, ngx_str_t *src)
56
+ {
57
+ u_char *dst;
58
+
59
+ dst = ngx_pnalloc(pool, src->len);
60
+ if (dst == NULL) {
61
+ return NULL;
62
+ }
63
+
64
+ ngx_memcpy(dst, src->data, src->len);
65
+
66
+ return dst;
67
+ }
68
+
69
+
70
+ /*
71
+ * supported formats:
72
+ * %[0][width][x][X]O off_t
73
+ * %[0][width]T time_t
74
+ * %[0][width][u][x|X]z ssize_t/size_t
75
+ * %[0][width][u][x|X]d int/u_int
76
+ * %[0][width][u][x|X]l long
77
+ * %[0][width|m][u][x|X]i ngx_int_t/ngx_uint_t
78
+ * %[0][width][u][x|X]D int32_t/uint32_t
79
+ * %[0][width][u][x|X]L int64_t/uint64_t
80
+ * %[0][width|m][u][x|X]A ngx_atomic_int_t/ngx_atomic_uint_t
81
+ * %[0][width][.width]f double, max valid number fits to %18.15f
82
+ * %P ngx_pid_t
83
+ * %M ngx_msec_t
84
+ * %r rlim_t
85
+ * %p void *
86
+ * %V ngx_str_t *
87
+ * %v ngx_variable_value_t *
88
+ * %s null-terminated string
89
+ * %*s length and string
90
+ * %Z '\0'
91
+ * %N '\n'
92
+ * %c char
93
+ * %% %
94
+ *
95
+ * reserved:
96
+ * %t ptrdiff_t
97
+ * %S null-terminated wchar string
98
+ * %C wchar
99
+ */
100
+
101
+
102
+ u_char * ngx_cdecl
103
+ ngx_sprintf(u_char *buf, const char *fmt, ...)
104
+ {
105
+ u_char *p;
106
+ va_list args;
107
+
108
+ va_start(args, fmt);
109
+ p = ngx_vslprintf(buf, (void *) -1, fmt, args);
110
+ va_end(args);
111
+
112
+ return p;
113
+ }
114
+
115
+
116
+ u_char * ngx_cdecl
117
+ ngx_snprintf(u_char *buf, size_t max, const char *fmt, ...)
118
+ {
119
+ u_char *p;
120
+ va_list args;
121
+
122
+ va_start(args, fmt);
123
+ p = ngx_vslprintf(buf, buf + max, fmt, args);
124
+ va_end(args);
125
+
126
+ return p;
127
+ }
128
+
129
+
130
+ u_char * ngx_cdecl
131
+ ngx_slprintf(u_char *buf, u_char *last, const char *fmt, ...)
132
+ {
133
+ u_char *p;
134
+ va_list args;
135
+
136
+ va_start(args, fmt);
137
+ p = ngx_vslprintf(buf, last, fmt, args);
138
+ va_end(args);
139
+
140
+ return p;
141
+ }
142
+
143
+
144
+ u_char *
145
+ ngx_vslprintf(u_char *buf, u_char *last, const char *fmt, va_list args)
146
+ {
147
+ u_char *p, zero;
148
+ int d;
149
+ double f, scale;
150
+ size_t len, slen;
151
+ int64_t i64;
152
+ uint64_t ui64;
153
+ ngx_msec_t ms;
154
+ ngx_uint_t width, sign, hex, max_width, frac_width, n;
155
+ ngx_str_t *v;
156
+ ngx_variable_value_t *vv;
157
+
158
+ while (*fmt && buf < last) {
159
+
160
+ /*
161
+ * "buf < last" means that we could copy at least one character:
162
+ * the plain character, "%%", "%c", and minus without the checking
163
+ */
164
+
165
+ if (*fmt == '%') {
166
+
167
+ i64 = 0;
168
+ ui64 = 0;
169
+
170
+ zero = (u_char) ((*++fmt == '0') ? '0' : ' ');
171
+ width = 0;
172
+ sign = 1;
173
+ hex = 0;
174
+ max_width = 0;
175
+ frac_width = 0;
176
+ slen = (size_t) -1;
177
+
178
+ while (*fmt >= '0' && *fmt <= '9') {
179
+ width = width * 10 + *fmt++ - '0';
180
+ }
181
+
182
+
183
+ for ( ;; ) {
184
+ switch (*fmt) {
185
+
186
+ case 'u':
187
+ sign = 0;
188
+ fmt++;
189
+ continue;
190
+
191
+ case 'm':
192
+ max_width = 1;
193
+ fmt++;
194
+ continue;
195
+
196
+ case 'X':
197
+ hex = 2;
198
+ sign = 0;
199
+ fmt++;
200
+ continue;
201
+
202
+ case 'x':
203
+ hex = 1;
204
+ sign = 0;
205
+ fmt++;
206
+ continue;
207
+
208
+ case '.':
209
+ fmt++;
210
+
211
+ while (*fmt >= '0' && *fmt <= '9') {
212
+ frac_width = frac_width * 10 + *fmt++ - '0';
213
+ }
214
+
215
+ break;
216
+
217
+ case '*':
218
+ slen = va_arg(args, size_t);
219
+ fmt++;
220
+ continue;
221
+
222
+ default:
223
+ break;
224
+ }
225
+
226
+ break;
227
+ }
228
+
229
+
230
+ switch (*fmt) {
231
+
232
+ case 'V':
233
+ v = va_arg(args, ngx_str_t *);
234
+
235
+ len = ngx_min(((size_t) (last - buf)), v->len);
236
+ buf = ngx_cpymem(buf, v->data, len);
237
+ fmt++;
238
+
239
+ continue;
240
+
241
+ case 'v':
242
+ vv = va_arg(args, ngx_variable_value_t *);
243
+
244
+ len = ngx_min(((size_t) (last - buf)), vv->len);
245
+ buf = ngx_cpymem(buf, vv->data, len);
246
+ fmt++;
247
+
248
+ continue;
249
+
250
+ case 's':
251
+ p = va_arg(args, u_char *);
252
+
253
+ if (slen == (size_t) -1) {
254
+ while (*p && buf < last) {
255
+ *buf++ = *p++;
256
+ }
257
+
258
+ } else {
259
+ len = ngx_min(((size_t) (last - buf)), slen);
260
+ buf = ngx_cpymem(buf, p, len);
261
+ }
262
+
263
+ fmt++;
264
+
265
+ continue;
266
+
267
+ case 'O':
268
+ i64 = (int64_t) va_arg(args, off_t);
269
+ sign = 1;
270
+ break;
271
+
272
+ case 'P':
273
+ i64 = (int64_t) va_arg(args, ngx_pid_t);
274
+ sign = 1;
275
+ break;
276
+
277
+ case 'T':
278
+ i64 = (int64_t) va_arg(args, time_t);
279
+ sign = 1;
280
+ break;
281
+
282
+ case 'M':
283
+ ms = (ngx_msec_t) va_arg(args, ngx_msec_t);
284
+ if ((ngx_msec_int_t) ms == -1) {
285
+ sign = 1;
286
+ i64 = -1;
287
+ } else {
288
+ sign = 0;
289
+ ui64 = (uint64_t) ms;
290
+ }
291
+ break;
292
+
293
+ case 'z':
294
+ if (sign) {
295
+ i64 = (int64_t) va_arg(args, ssize_t);
296
+ } else {
297
+ ui64 = (uint64_t) va_arg(args, size_t);
298
+ }
299
+ break;
300
+
301
+ case 'i':
302
+ if (sign) {
303
+ i64 = (int64_t) va_arg(args, ngx_int_t);
304
+ } else {
305
+ ui64 = (uint64_t) va_arg(args, ngx_uint_t);
306
+ }
307
+
308
+ if (max_width) {
309
+ width = NGX_INT_T_LEN;
310
+ }
311
+
312
+ break;
313
+
314
+ case 'd':
315
+ if (sign) {
316
+ i64 = (int64_t) va_arg(args, int);
317
+ } else {
318
+ ui64 = (uint64_t) va_arg(args, u_int);
319
+ }
320
+ break;
321
+
322
+ case 'l':
323
+ if (sign) {
324
+ i64 = (int64_t) va_arg(args, long);
325
+ } else {
326
+ ui64 = (uint64_t) va_arg(args, u_long);
327
+ }
328
+ break;
329
+
330
+ case 'D':
331
+ if (sign) {
332
+ i64 = (int64_t) va_arg(args, int32_t);
333
+ } else {
334
+ ui64 = (uint64_t) va_arg(args, uint32_t);
335
+ }
336
+ break;
337
+
338
+ case 'L':
339
+ if (sign) {
340
+ i64 = va_arg(args, int64_t);
341
+ } else {
342
+ ui64 = va_arg(args, uint64_t);
343
+ }
344
+ break;
345
+
346
+ case 'A':
347
+ if (sign) {
348
+ i64 = (int64_t) va_arg(args, ngx_atomic_int_t);
349
+ } else {
350
+ ui64 = (uint64_t) va_arg(args, ngx_atomic_uint_t);
351
+ }
352
+
353
+ if (max_width) {
354
+ width = NGX_ATOMIC_T_LEN;
355
+ }
356
+
357
+ break;
358
+
359
+ case 'f':
360
+ f = va_arg(args, double);
361
+
362
+ if (f < 0) {
363
+ *buf++ = '-';
364
+ f = -f;
365
+ }
366
+
367
+ ui64 = (int64_t) f;
368
+
369
+ buf = ngx_sprintf_num(buf, last, ui64, zero, 0, width);
370
+
371
+ if (frac_width) {
372
+
373
+ if (buf < last) {
374
+ *buf++ = '.';
375
+ }
376
+
377
+ scale = 1.0;
378
+
379
+ for (n = frac_width; n; n--) {
380
+ scale *= 10.0;
381
+ }
382
+
383
+ /*
384
+ * (int64_t) cast is required for msvc6:
385
+ * it cannot convert uint64_t to double
386
+ */
387
+ ui64 = (uint64_t) ((f - (int64_t) ui64) * scale + 0.5);
388
+
389
+ buf = ngx_sprintf_num(buf, last, ui64, '0', 0, frac_width);
390
+ }
391
+
392
+ fmt++;
393
+
394
+ continue;
395
+
396
+ #if !(NGX_WIN32)
397
+ case 'r':
398
+ i64 = (int64_t) va_arg(args, rlim_t);
399
+ sign = 1;
400
+ break;
401
+ #endif
402
+
403
+ case 'p':
404
+ ui64 = (uintptr_t) va_arg(args, void *);
405
+ hex = 2;
406
+ sign = 0;
407
+ zero = '0';
408
+ width = NGX_PTR_SIZE * 2;
409
+ break;
410
+
411
+ case 'c':
412
+ d = va_arg(args, int);
413
+ *buf++ = (u_char) (d & 0xff);
414
+ fmt++;
415
+
416
+ continue;
417
+
418
+ case 'Z':
419
+ *buf++ = '\0';
420
+ fmt++;
421
+
422
+ continue;
423
+
424
+ case 'N':
425
+ #if (NGX_WIN32)
426
+ *buf++ = CR;
427
+ #endif
428
+ *buf++ = LF;
429
+ fmt++;
430
+
431
+ continue;
432
+
433
+ case '%':
434
+ *buf++ = '%';
435
+ fmt++;
436
+
437
+ continue;
438
+
439
+ default:
440
+ *buf++ = *fmt++;
441
+
442
+ continue;
443
+ }
444
+
445
+ if (sign) {
446
+ if (i64 < 0) {
447
+ *buf++ = '-';
448
+ ui64 = (uint64_t) -i64;
449
+
450
+ } else {
451
+ ui64 = (uint64_t) i64;
452
+ }
453
+ }
454
+
455
+ buf = ngx_sprintf_num(buf, last, ui64, zero, hex, width);
456
+
457
+ fmt++;
458
+
459
+ } else {
460
+ *buf++ = *fmt++;
461
+ }
462
+ }
463
+
464
+ return buf;
465
+ }
466
+
467
+
468
+ static u_char *
469
+ ngx_sprintf_num(u_char *buf, u_char *last, uint64_t ui64, u_char zero,
470
+ ngx_uint_t hexadecimal, ngx_uint_t width)
471
+ {
472
+ u_char *p, temp[NGX_INT64_LEN + 1];
473
+ /*
474
+ * we need temp[NGX_INT64_LEN] only,
475
+ * but icc issues the warning
476
+ */
477
+ size_t len;
478
+ uint32_t ui32;
479
+ static u_char hex[] = "0123456789abcdef";
480
+ static u_char HEX[] = "0123456789ABCDEF";
481
+
482
+ p = temp + NGX_INT64_LEN;
483
+
484
+ if (hexadecimal == 0) {
485
+
486
+ if (ui64 <= NGX_MAX_UINT32_VALUE) {
487
+
488
+ /*
489
+ * To divide 64-bit numbers and to find remainders
490
+ * on the x86 platform gcc and icc call the libc functions
491
+ * [u]divdi3() and [u]moddi3(), they call another function
492
+ * in its turn. On FreeBSD it is the qdivrem() function,
493
+ * its source code is about 170 lines of the code.
494
+ * The glibc counterpart is about 150 lines of the code.
495
+ *
496
+ * For 32-bit numbers and some divisors gcc and icc use
497
+ * a inlined multiplication and shifts. For example,
498
+ * unsigned "i32 / 10" is compiled to
499
+ *
500
+ * (i32 * 0xCCCCCCCD) >> 35
501
+ */
502
+
503
+ ui32 = (uint32_t) ui64;
504
+
505
+ do {
506
+ *--p = (u_char) (ui32 % 10 + '0');
507
+ } while (ui32 /= 10);
508
+
509
+ } else {
510
+ do {
511
+ *--p = (u_char) (ui64 % 10 + '0');
512
+ } while (ui64 /= 10);
513
+ }
514
+
515
+ } else if (hexadecimal == 1) {
516
+
517
+ do {
518
+
519
+ /* the "(uint32_t)" cast disables the BCC's warning */
520
+ *--p = hex[(uint32_t) (ui64 & 0xf)];
521
+
522
+ } while (ui64 >>= 4);
523
+
524
+ } else { /* hexadecimal == 2 */
525
+
526
+ do {
527
+
528
+ /* the "(uint32_t)" cast disables the BCC's warning */
529
+ *--p = HEX[(uint32_t) (ui64 & 0xf)];
530
+
531
+ } while (ui64 >>= 4);
532
+ }
533
+
534
+ /* zero or space padding */
535
+
536
+ len = (temp + NGX_INT64_LEN) - p;
537
+
538
+ while (len++ < width && buf < last) {
539
+ *buf++ = zero;
540
+ }
541
+
542
+ /* number safe copy */
543
+
544
+ len = (temp + NGX_INT64_LEN) - p;
545
+
546
+ if (buf + len > last) {
547
+ len = last - buf;
548
+ }
549
+
550
+ return ngx_cpymem(buf, p, len);
551
+ }
552
+
553
+
554
+ /*
555
+ * We use ngx_strcasecmp()/ngx_strncasecmp() for 7-bit ASCII strings only,
556
+ * and implement our own ngx_strcasecmp()/ngx_strncasecmp()
557
+ * to avoid libc locale overhead. Besides, we use the ngx_uint_t's
558
+ * instead of the u_char's, because they are slightly faster.
559
+ */
560
+
561
+ ngx_int_t
562
+ ngx_strcasecmp(u_char *s1, u_char *s2)
563
+ {
564
+ ngx_uint_t c1, c2;
565
+
566
+ for ( ;; ) {
567
+ c1 = (ngx_uint_t) *s1++;
568
+ c2 = (ngx_uint_t) *s2++;
569
+
570
+ c1 = (c1 >= 'A' && c1 <= 'Z') ? (c1 | 0x20) : c1;
571
+ c2 = (c2 >= 'A' && c2 <= 'Z') ? (c2 | 0x20) : c2;
572
+
573
+ if (c1 == c2) {
574
+
575
+ if (c1) {
576
+ continue;
577
+ }
578
+
579
+ return 0;
580
+ }
581
+
582
+ return c1 - c2;
583
+ }
584
+ }
585
+
586
+
587
+ ngx_int_t
588
+ ngx_strncasecmp(u_char *s1, u_char *s2, size_t n)
589
+ {
590
+ ngx_uint_t c1, c2;
591
+
592
+ while (n) {
593
+ c1 = (ngx_uint_t) *s1++;
594
+ c2 = (ngx_uint_t) *s2++;
595
+
596
+ c1 = (c1 >= 'A' && c1 <= 'Z') ? (c1 | 0x20) : c1;
597
+ c2 = (c2 >= 'A' && c2 <= 'Z') ? (c2 | 0x20) : c2;
598
+
599
+ if (c1 == c2) {
600
+
601
+ if (c1) {
602
+ n--;
603
+ continue;
604
+ }
605
+
606
+ return 0;
607
+ }
608
+
609
+ return c1 - c2;
610
+ }
611
+
612
+ return 0;
613
+ }
614
+
615
+
616
+ u_char *
617
+ ngx_strnstr(u_char *s1, char *s2, size_t len)
618
+ {
619
+ u_char c1, c2;
620
+ size_t n;
621
+
622
+ c2 = *(u_char *) s2++;
623
+
624
+ n = ngx_strlen(s2);
625
+
626
+ do {
627
+ do {
628
+ if (len-- == 0) {
629
+ return NULL;
630
+ }
631
+
632
+ c1 = *s1++;
633
+
634
+ if (c1 == 0) {
635
+ return NULL;
636
+ }
637
+
638
+ } while (c1 != c2);
639
+
640
+ if (n > len) {
641
+ return NULL;
642
+ }
643
+
644
+ } while (ngx_strncmp(s1, (u_char *) s2, n) != 0);
645
+
646
+ return --s1;
647
+ }
648
+
649
+
650
+ /*
651
+ * ngx_strstrn() and ngx_strcasestrn() are intended to search for static
652
+ * substring with known length in null-terminated string. The argument n
653
+ * must be length of the second substring - 1.
654
+ */
655
+
656
+ u_char *
657
+ ngx_strstrn(u_char *s1, char *s2, size_t n)
658
+ {
659
+ u_char c1, c2;
660
+
661
+ c2 = *(u_char *) s2++;
662
+
663
+ do {
664
+ do {
665
+ c1 = *s1++;
666
+
667
+ if (c1 == 0) {
668
+ return NULL;
669
+ }
670
+
671
+ } while (c1 != c2);
672
+
673
+ } while (ngx_strncmp(s1, (u_char *) s2, n) != 0);
674
+
675
+ return --s1;
676
+ }
677
+
678
+
679
+ u_char *
680
+ ngx_strcasestrn(u_char *s1, char *s2, size_t n)
681
+ {
682
+ ngx_uint_t c1, c2;
683
+
684
+ c2 = (ngx_uint_t) *s2++;
685
+ c2 = (c2 >= 'A' && c2 <= 'Z') ? (c2 | 0x20) : c2;
686
+
687
+ do {
688
+ do {
689
+ c1 = (ngx_uint_t) *s1++;
690
+
691
+ if (c1 == 0) {
692
+ return NULL;
693
+ }
694
+
695
+ c1 = (c1 >= 'A' && c1 <= 'Z') ? (c1 | 0x20) : c1;
696
+
697
+ } while (c1 != c2);
698
+
699
+ } while (ngx_strncasecmp(s1, (u_char *) s2, n) != 0);
700
+
701
+ return --s1;
702
+ }
703
+
704
+
705
+ /*
706
+ * ngx_strlcasestrn() is intended to search for static substring
707
+ * with known length in string until the argument last. The argument n
708
+ * must be length of the second substring - 1.
709
+ */
710
+
711
+ u_char *
712
+ ngx_strlcasestrn(u_char *s1, u_char *last, u_char *s2, size_t n)
713
+ {
714
+ ngx_uint_t c1, c2;
715
+
716
+ c2 = (ngx_uint_t) *s2++;
717
+ c2 = (c2 >= 'A' && c2 <= 'Z') ? (c2 | 0x20) : c2;
718
+ last -= n;
719
+
720
+ do {
721
+ do {
722
+ if (s1 >= last) {
723
+ return NULL;
724
+ }
725
+
726
+ c1 = (ngx_uint_t) *s1++;
727
+
728
+ c1 = (c1 >= 'A' && c1 <= 'Z') ? (c1 | 0x20) : c1;
729
+
730
+ } while (c1 != c2);
731
+
732
+ } while (ngx_strncasecmp(s1, s2, n) != 0);
733
+
734
+ return --s1;
735
+ }
736
+
737
+
738
+ ngx_int_t
739
+ ngx_rstrncmp(u_char *s1, u_char *s2, size_t n)
740
+ {
741
+ if (n == 0) {
742
+ return 0;
743
+ }
744
+
745
+ n--;
746
+
747
+ for ( ;; ) {
748
+ if (s1[n] != s2[n]) {
749
+ return s1[n] - s2[n];
750
+ }
751
+
752
+ if (n == 0) {
753
+ return 0;
754
+ }
755
+
756
+ n--;
757
+ }
758
+ }
759
+
760
+
761
+ ngx_int_t
762
+ ngx_rstrncasecmp(u_char *s1, u_char *s2, size_t n)
763
+ {
764
+ u_char c1, c2;
765
+
766
+ if (n == 0) {
767
+ return 0;
768
+ }
769
+
770
+ n--;
771
+
772
+ for ( ;; ) {
773
+ c1 = s1[n];
774
+ if (c1 >= 'a' && c1 <= 'z') {
775
+ c1 -= 'a' - 'A';
776
+ }
777
+
778
+ c2 = s2[n];
779
+ if (c2 >= 'a' && c2 <= 'z') {
780
+ c2 -= 'a' - 'A';
781
+ }
782
+
783
+ if (c1 != c2) {
784
+ return c1 - c2;
785
+ }
786
+
787
+ if (n == 0) {
788
+ return 0;
789
+ }
790
+
791
+ n--;
792
+ }
793
+ }
794
+
795
+
796
+ ngx_int_t
797
+ ngx_memn2cmp(u_char *s1, u_char *s2, size_t n1, size_t n2)
798
+ {
799
+ size_t n;
800
+ ngx_int_t m, z;
801
+
802
+ if (n1 <= n2) {
803
+ n = n1;
804
+ z = -1;
805
+
806
+ } else {
807
+ n = n2;
808
+ z = 1;
809
+ }
810
+
811
+ m = ngx_memcmp(s1, s2, n);
812
+
813
+ if (m || n1 == n2) {
814
+ return m;
815
+ }
816
+
817
+ return z;
818
+ }
819
+
820
+
821
+ ngx_int_t
822
+ ngx_dns_strcmp(u_char *s1, u_char *s2)
823
+ {
824
+ ngx_uint_t c1, c2;
825
+
826
+ for ( ;; ) {
827
+ c1 = (ngx_uint_t) *s1++;
828
+ c2 = (ngx_uint_t) *s2++;
829
+
830
+ c1 = (c1 >= 'A' && c1 <= 'Z') ? (c1 | 0x20) : c1;
831
+ c2 = (c2 >= 'A' && c2 <= 'Z') ? (c2 | 0x20) : c2;
832
+
833
+ if (c1 == c2) {
834
+
835
+ if (c1) {
836
+ continue;
837
+ }
838
+
839
+ return 0;
840
+ }
841
+
842
+ /* in ASCII '.' > '-', but we need '.' to be the lowest character */
843
+
844
+ c1 = (c1 == '.') ? ' ' : c1;
845
+ c2 = (c2 == '.') ? ' ' : c2;
846
+
847
+ return c1 - c2;
848
+ }
849
+ }
850
+
851
+
852
+ ngx_int_t
853
+ ngx_atoi(u_char *line, size_t n)
854
+ {
855
+ ngx_int_t value;
856
+
857
+ if (n == 0) {
858
+ return NGX_ERROR;
859
+ }
860
+
861
+ for (value = 0; n--; line++) {
862
+ if (*line < '0' || *line > '9') {
863
+ return NGX_ERROR;
864
+ }
865
+
866
+ value = value * 10 + (*line - '0');
867
+ }
868
+
869
+ if (value < 0) {
870
+ return NGX_ERROR;
871
+
872
+ } else {
873
+ return value;
874
+ }
875
+ }
876
+
877
+
878
+ /* parse a fixed point number, e.g., ngx_atofp("10.5", 4, 2) returns 1050 */
879
+
880
+ ngx_int_t
881
+ ngx_atofp(u_char *line, size_t n, size_t point)
882
+ {
883
+ ngx_int_t value;
884
+ ngx_uint_t dot;
885
+
886
+ if (n == 0) {
887
+ return NGX_ERROR;
888
+ }
889
+
890
+ dot = 0;
891
+
892
+ for (value = 0; n--; line++) {
893
+
894
+ if (point == 0) {
895
+ return NGX_ERROR;
896
+ }
897
+
898
+ if (*line == '.') {
899
+ if (dot) {
900
+ return NGX_ERROR;
901
+ }
902
+
903
+ dot = 1;
904
+ continue;
905
+ }
906
+
907
+ if (*line < '0' || *line > '9') {
908
+ return NGX_ERROR;
909
+ }
910
+
911
+ value = value * 10 + (*line - '0');
912
+ point -= dot;
913
+ }
914
+
915
+ while (point--) {
916
+ value = value * 10;
917
+ }
918
+
919
+ if (value < 0) {
920
+ return NGX_ERROR;
921
+
922
+ } else {
923
+ return value;
924
+ }
925
+ }
926
+
927
+
928
+ ssize_t
929
+ ngx_atosz(u_char *line, size_t n)
930
+ {
931
+ ssize_t value;
932
+
933
+ if (n == 0) {
934
+ return NGX_ERROR;
935
+ }
936
+
937
+ for (value = 0; n--; line++) {
938
+ if (*line < '0' || *line > '9') {
939
+ return NGX_ERROR;
940
+ }
941
+
942
+ value = value * 10 + (*line - '0');
943
+ }
944
+
945
+ if (value < 0) {
946
+ return NGX_ERROR;
947
+
948
+ } else {
949
+ return value;
950
+ }
951
+ }
952
+
953
+
954
+ off_t
955
+ ngx_atoof(u_char *line, size_t n)
956
+ {
957
+ off_t value;
958
+
959
+ if (n == 0) {
960
+ return NGX_ERROR;
961
+ }
962
+
963
+ for (value = 0; n--; line++) {
964
+ if (*line < '0' || *line > '9') {
965
+ return NGX_ERROR;
966
+ }
967
+
968
+ value = value * 10 + (*line - '0');
969
+ }
970
+
971
+ if (value < 0) {
972
+ return NGX_ERROR;
973
+
974
+ } else {
975
+ return value;
976
+ }
977
+ }
978
+
979
+
980
+ time_t
981
+ ngx_atotm(u_char *line, size_t n)
982
+ {
983
+ time_t value;
984
+
985
+ if (n == 0) {
986
+ return NGX_ERROR;
987
+ }
988
+
989
+ for (value = 0; n--; line++) {
990
+ if (*line < '0' || *line > '9') {
991
+ return NGX_ERROR;
992
+ }
993
+
994
+ value = value * 10 + (*line - '0');
995
+ }
996
+
997
+ if (value < 0) {
998
+ return NGX_ERROR;
999
+
1000
+ } else {
1001
+ return value;
1002
+ }
1003
+ }
1004
+
1005
+
1006
+ ngx_int_t
1007
+ ngx_hextoi(u_char *line, size_t n)
1008
+ {
1009
+ u_char c, ch;
1010
+ ngx_int_t value;
1011
+
1012
+ if (n == 0) {
1013
+ return NGX_ERROR;
1014
+ }
1015
+
1016
+ for (value = 0; n--; line++) {
1017
+ ch = *line;
1018
+
1019
+ if (ch >= '0' && ch <= '9') {
1020
+ value = value * 16 + (ch - '0');
1021
+ continue;
1022
+ }
1023
+
1024
+ c = (u_char) (ch | 0x20);
1025
+
1026
+ if (c >= 'a' && c <= 'f') {
1027
+ value = value * 16 + (c - 'a' + 10);
1028
+ continue;
1029
+ }
1030
+
1031
+ return NGX_ERROR;
1032
+ }
1033
+
1034
+ if (value < 0) {
1035
+ return NGX_ERROR;
1036
+
1037
+ } else {
1038
+ return value;
1039
+ }
1040
+ }
1041
+
1042
+
1043
+ u_char *
1044
+ ngx_hex_dump(u_char *dst, u_char *src, size_t len)
1045
+ {
1046
+ static u_char hex[] = "0123456789abcdef";
1047
+
1048
+ while (len--) {
1049
+ *dst++ = hex[*src >> 4];
1050
+ *dst++ = hex[*src++ & 0xf];
1051
+ }
1052
+
1053
+ return dst;
1054
+ }
1055
+
1056
+
1057
+ void
1058
+ ngx_encode_base64(ngx_str_t *dst, ngx_str_t *src)
1059
+ {
1060
+ u_char *d, *s;
1061
+ size_t len;
1062
+ static u_char basis64[] =
1063
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
1064
+
1065
+ len = src->len;
1066
+ s = src->data;
1067
+ d = dst->data;
1068
+
1069
+ while (len > 2) {
1070
+ *d++ = basis64[(s[0] >> 2) & 0x3f];
1071
+ *d++ = basis64[((s[0] & 3) << 4) | (s[1] >> 4)];
1072
+ *d++ = basis64[((s[1] & 0x0f) << 2) | (s[2] >> 6)];
1073
+ *d++ = basis64[s[2] & 0x3f];
1074
+
1075
+ s += 3;
1076
+ len -= 3;
1077
+ }
1078
+
1079
+ if (len) {
1080
+ *d++ = basis64[(s[0] >> 2) & 0x3f];
1081
+
1082
+ if (len == 1) {
1083
+ *d++ = basis64[(s[0] & 3) << 4];
1084
+ *d++ = '=';
1085
+
1086
+ } else {
1087
+ *d++ = basis64[((s[0] & 3) << 4) | (s[1] >> 4)];
1088
+ *d++ = basis64[(s[1] & 0x0f) << 2];
1089
+ }
1090
+
1091
+ *d++ = '=';
1092
+ }
1093
+
1094
+ dst->len = d - dst->data;
1095
+ }
1096
+
1097
+
1098
+ ngx_int_t
1099
+ ngx_decode_base64(ngx_str_t *dst, ngx_str_t *src)
1100
+ {
1101
+ static u_char basis64[] = {
1102
+ 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
1103
+ 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
1104
+ 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 62, 77, 77, 77, 63,
1105
+ 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 77, 77, 77, 77, 77, 77,
1106
+ 77, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
1107
+ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 77, 77, 77, 77, 77,
1108
+ 77, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
1109
+ 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 77, 77, 77, 77, 77,
1110
+
1111
+ 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
1112
+ 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
1113
+ 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
1114
+ 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
1115
+ 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
1116
+ 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
1117
+ 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
1118
+ 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77
1119
+ };
1120
+
1121
+ return ngx_decode_base64_internal(dst, src, basis64);
1122
+ }
1123
+
1124
+
1125
+ ngx_int_t
1126
+ ngx_decode_base64url(ngx_str_t *dst, ngx_str_t *src)
1127
+ {
1128
+ static u_char basis64[] = {
1129
+ 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
1130
+ 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
1131
+ 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 62, 77, 77,
1132
+ 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 77, 77, 77, 77, 77, 77,
1133
+ 77, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
1134
+ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 77, 77, 77, 77, 63,
1135
+ 77, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
1136
+ 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 77, 77, 77, 77, 77,
1137
+
1138
+ 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
1139
+ 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
1140
+ 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
1141
+ 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
1142
+ 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
1143
+ 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
1144
+ 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
1145
+ 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77
1146
+ };
1147
+
1148
+ return ngx_decode_base64_internal(dst, src, basis64);
1149
+ }
1150
+
1151
+
1152
+ static ngx_int_t
1153
+ ngx_decode_base64_internal(ngx_str_t *dst, ngx_str_t *src, const u_char *basis)
1154
+ {
1155
+ size_t len;
1156
+ u_char *d, *s;
1157
+
1158
+ for (len = 0; len < src->len; len++) {
1159
+ if (src->data[len] == '=') {
1160
+ break;
1161
+ }
1162
+
1163
+ if (basis[src->data[len]] == 77) {
1164
+ return NGX_ERROR;
1165
+ }
1166
+ }
1167
+
1168
+ if (len % 4 == 1) {
1169
+ return NGX_ERROR;
1170
+ }
1171
+
1172
+ s = src->data;
1173
+ d = dst->data;
1174
+
1175
+ while (len > 3) {
1176
+ *d++ = (u_char) (basis[s[0]] << 2 | basis[s[1]] >> 4);
1177
+ *d++ = (u_char) (basis[s[1]] << 4 | basis[s[2]] >> 2);
1178
+ *d++ = (u_char) (basis[s[2]] << 6 | basis[s[3]]);
1179
+
1180
+ s += 4;
1181
+ len -= 4;
1182
+ }
1183
+
1184
+ if (len > 1) {
1185
+ *d++ = (u_char) (basis[s[0]] << 2 | basis[s[1]] >> 4);
1186
+ }
1187
+
1188
+ if (len > 2) {
1189
+ *d++ = (u_char) (basis[s[1]] << 4 | basis[s[2]] >> 2);
1190
+ }
1191
+
1192
+ dst->len = d - dst->data;
1193
+
1194
+ return NGX_OK;
1195
+ }
1196
+
1197
+
1198
+ /*
1199
+ * ngx_utf8_decode() decodes two and more bytes UTF sequences only
1200
+ * the return values:
1201
+ * 0x80 - 0x10ffff valid character
1202
+ * 0x110000 - 0xfffffffd invalid sequence
1203
+ * 0xfffffffe incomplete sequence
1204
+ * 0xffffffff error
1205
+ */
1206
+
1207
+ uint32_t
1208
+ ngx_utf8_decode(u_char **p, size_t n)
1209
+ {
1210
+ size_t len;
1211
+ uint32_t u, i, valid;
1212
+
1213
+ u = **p;
1214
+
1215
+ if (u >= 0xf0) {
1216
+
1217
+ u &= 0x07;
1218
+ valid = 0xffff;
1219
+ len = 3;
1220
+
1221
+ } else if (u >= 0xe0) {
1222
+
1223
+ u &= 0x0f;
1224
+ valid = 0x7ff;
1225
+ len = 2;
1226
+
1227
+ } else if (u >= 0xc2) {
1228
+
1229
+ u &= 0x1f;
1230
+ valid = 0x7f;
1231
+ len = 1;
1232
+
1233
+ } else {
1234
+ (*p)++;
1235
+ return 0xffffffff;
1236
+ }
1237
+
1238
+ if (n - 1 < len) {
1239
+ return 0xfffffffe;
1240
+ }
1241
+
1242
+ (*p)++;
1243
+
1244
+ while (len) {
1245
+ i = *(*p)++;
1246
+
1247
+ if (i < 0x80) {
1248
+ return 0xffffffff;
1249
+ }
1250
+
1251
+ u = (u << 6) | (i & 0x3f);
1252
+
1253
+ len--;
1254
+ }
1255
+
1256
+ if (u > valid) {
1257
+ return u;
1258
+ }
1259
+
1260
+ return 0xffffffff;
1261
+ }
1262
+
1263
+
1264
+ size_t
1265
+ ngx_utf8_length(u_char *p, size_t n)
1266
+ {
1267
+ u_char c, *last;
1268
+ size_t len;
1269
+
1270
+ last = p + n;
1271
+
1272
+ for (len = 0; p < last; len++) {
1273
+
1274
+ c = *p;
1275
+
1276
+ if (c < 0x80) {
1277
+ p++;
1278
+ continue;
1279
+ }
1280
+
1281
+ if (ngx_utf8_decode(&p, n) > 0x10ffff) {
1282
+ /* invalid UTF-8 */
1283
+ return n;
1284
+ }
1285
+ }
1286
+
1287
+ return len;
1288
+ }
1289
+
1290
+
1291
+ u_char *
1292
+ ngx_utf8_cpystrn(u_char *dst, u_char *src, size_t n, size_t len)
1293
+ {
1294
+ u_char c, *next;
1295
+
1296
+ if (n == 0) {
1297
+ return dst;
1298
+ }
1299
+
1300
+ while (--n) {
1301
+
1302
+ c = *src;
1303
+ *dst = c;
1304
+
1305
+ if (c < 0x80) {
1306
+
1307
+ if (c != '\0') {
1308
+ dst++;
1309
+ src++;
1310
+ len--;
1311
+
1312
+ continue;
1313
+ }
1314
+
1315
+ return dst;
1316
+ }
1317
+
1318
+ next = src;
1319
+
1320
+ if (ngx_utf8_decode(&next, len) > 0x10ffff) {
1321
+ /* invalid UTF-8 */
1322
+ break;
1323
+ }
1324
+
1325
+ while (src < next) {
1326
+ *dst++ = *src++;
1327
+ len--;
1328
+ }
1329
+ }
1330
+
1331
+ *dst = '\0';
1332
+
1333
+ return dst;
1334
+ }
1335
+
1336
+
1337
+ uintptr_t
1338
+ ngx_escape_uri(u_char *dst, u_char *src, size_t size, ngx_uint_t type)
1339
+ {
1340
+ ngx_uint_t n;
1341
+ uint32_t *escape;
1342
+ static u_char hex[] = "0123456789abcdef";
1343
+
1344
+ /* " ", "#", "%", "?", %00-%1F, %7F-%FF */
1345
+
1346
+ static uint32_t uri[] = {
1347
+ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
1348
+
1349
+ /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */
1350
+ 0x80000029, /* 1000 0000 0000 0000 0000 0000 0010 1001 */
1351
+
1352
+ /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */
1353
+ 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
1354
+
1355
+ /* ~}| {zyx wvut srqp onml kjih gfed cba` */
1356
+ 0x80000000, /* 1000 0000 0000 0000 0000 0000 0000 0000 */
1357
+
1358
+ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
1359
+ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
1360
+ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
1361
+ 0xffffffff /* 1111 1111 1111 1111 1111 1111 1111 1111 */
1362
+ };
1363
+
1364
+ /* " ", "#", "%", "&", "+", "?", %00-%1F, %7F-%FF */
1365
+
1366
+ static uint32_t args[] = {
1367
+ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
1368
+
1369
+ /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */
1370
+ 0x88000869, /* 1000 1000 0000 0000 0000 1000 0110 1001 */
1371
+
1372
+ /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */
1373
+ 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
1374
+
1375
+ /* ~}| {zyx wvut srqp onml kjih gfed cba` */
1376
+ 0x80000000, /* 1000 0000 0000 0000 0000 0000 0000 0000 */
1377
+
1378
+ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
1379
+ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
1380
+ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
1381
+ 0xffffffff /* 1111 1111 1111 1111 1111 1111 1111 1111 */
1382
+ };
1383
+
1384
+ /* not ALPHA, DIGIT, "-", ".", "_", "~" */
1385
+
1386
+ static uint32_t uri_component[] = {
1387
+ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
1388
+
1389
+ /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */
1390
+ 0xfc009fff, /* 1111 1100 0000 0000 1001 1111 1111 1111 */
1391
+
1392
+ /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */
1393
+ 0x78000001, /* 0111 1000 0000 0000 0000 0000 0000 0001 */
1394
+
1395
+ /* ~}| {zyx wvut srqp onml kjih gfed cba` */
1396
+ 0xb8000001, /* 1011 1000 0000 0000 0000 0000 0000 0001 */
1397
+
1398
+ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
1399
+ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
1400
+ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
1401
+ 0xffffffff /* 1111 1111 1111 1111 1111 1111 1111 1111 */
1402
+ };
1403
+
1404
+ /* " ", "#", """, "%", "'", %00-%1F, %7F-%FF */
1405
+
1406
+ static uint32_t html[] = {
1407
+ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
1408
+
1409
+ /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */
1410
+ 0x000000ad, /* 0000 0000 0000 0000 0000 0000 1010 1101 */
1411
+
1412
+ /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */
1413
+ 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
1414
+
1415
+ /* ~}| {zyx wvut srqp onml kjih gfed cba` */
1416
+ 0x80000000, /* 1000 0000 0000 0000 0000 0000 0000 0000 */
1417
+
1418
+ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
1419
+ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
1420
+ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
1421
+ 0xffffffff /* 1111 1111 1111 1111 1111 1111 1111 1111 */
1422
+ };
1423
+
1424
+ /* " ", """, "%", "'", %00-%1F, %7F-%FF */
1425
+
1426
+ static uint32_t refresh[] = {
1427
+ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
1428
+
1429
+ /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */
1430
+ 0x00000085, /* 0000 0000 0000 0000 0000 0000 1000 0101 */
1431
+
1432
+ /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */
1433
+ 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
1434
+
1435
+ /* ~}| {zyx wvut srqp onml kjih gfed cba` */
1436
+ 0x80000000, /* 1000 0000 0000 0000 0000 0000 0000 0000 */
1437
+
1438
+ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
1439
+ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
1440
+ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
1441
+ 0xffffffff /* 1111 1111 1111 1111 1111 1111 1111 1111 */
1442
+ };
1443
+
1444
+ /* " ", "%", %00-%1F */
1445
+
1446
+ static uint32_t memcached[] = {
1447
+ 0xffffffff, /* 1111 1111 1111 1111 1111 1111 1111 1111 */
1448
+
1449
+ /* ?>=< ;:98 7654 3210 /.-, +*)( '&%$ #"! */
1450
+ 0x00000021, /* 0000 0000 0000 0000 0000 0000 0010 0001 */
1451
+
1452
+ /* _^]\ [ZYX WVUT SRQP ONML KJIH GFED CBA@ */
1453
+ 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
1454
+
1455
+ /* ~}| {zyx wvut srqp onml kjih gfed cba` */
1456
+ 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
1457
+
1458
+ 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
1459
+ 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
1460
+ 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
1461
+ 0x00000000, /* 0000 0000 0000 0000 0000 0000 0000 0000 */
1462
+ };
1463
+
1464
+ /* mail_auth is the same as memcached */
1465
+
1466
+ static uint32_t *map[] =
1467
+ { uri, args, uri_component, html, refresh, memcached, memcached };
1468
+
1469
+
1470
+ escape = map[type];
1471
+
1472
+ if (dst == NULL) {
1473
+
1474
+ /* find the number of the characters to be escaped */
1475
+
1476
+ n = 0;
1477
+
1478
+ while (size) {
1479
+ if (escape[*src >> 5] & (1 << (*src & 0x1f))) {
1480
+ n++;
1481
+ }
1482
+ src++;
1483
+ size--;
1484
+ }
1485
+
1486
+ return (uintptr_t) n;
1487
+ }
1488
+
1489
+ while (size) {
1490
+ if (escape[*src >> 5] & (1 << (*src & 0x1f))) {
1491
+ *dst++ = '%';
1492
+ *dst++ = hex[*src >> 4];
1493
+ *dst++ = hex[*src & 0xf];
1494
+ src++;
1495
+
1496
+ } else {
1497
+ *dst++ = *src++;
1498
+ }
1499
+ size--;
1500
+ }
1501
+
1502
+ return (uintptr_t) dst;
1503
+ }
1504
+
1505
+
1506
+ void
1507
+ ngx_unescape_uri(u_char **dst, u_char **src, size_t size, ngx_uint_t type)
1508
+ {
1509
+ u_char *d, *s, ch, c, decoded;
1510
+ enum {
1511
+ sw_usual = 0,
1512
+ sw_quoted,
1513
+ sw_quoted_second
1514
+ } state;
1515
+
1516
+ d = *dst;
1517
+ s = *src;
1518
+
1519
+ state = 0;
1520
+ decoded = 0;
1521
+
1522
+ while (size--) {
1523
+
1524
+ ch = *s++;
1525
+
1526
+ switch (state) {
1527
+ case sw_usual:
1528
+ if (ch == '?'
1529
+ && (type & (NGX_UNESCAPE_URI|NGX_UNESCAPE_REDIRECT)))
1530
+ {
1531
+ *d++ = ch;
1532
+ goto done;
1533
+ }
1534
+
1535
+ if (ch == '%') {
1536
+ state = sw_quoted;
1537
+ break;
1538
+ }
1539
+
1540
+ *d++ = ch;
1541
+ break;
1542
+
1543
+ case sw_quoted:
1544
+
1545
+ if (ch >= '0' && ch <= '9') {
1546
+ decoded = (u_char) (ch - '0');
1547
+ state = sw_quoted_second;
1548
+ break;
1549
+ }
1550
+
1551
+ c = (u_char) (ch | 0x20);
1552
+ if (c >= 'a' && c <= 'f') {
1553
+ decoded = (u_char) (c - 'a' + 10);
1554
+ state = sw_quoted_second;
1555
+ break;
1556
+ }
1557
+
1558
+ /* the invalid quoted character */
1559
+
1560
+ state = sw_usual;
1561
+
1562
+ *d++ = ch;
1563
+
1564
+ break;
1565
+
1566
+ case sw_quoted_second:
1567
+
1568
+ state = sw_usual;
1569
+
1570
+ if (ch >= '0' && ch <= '9') {
1571
+ ch = (u_char) ((decoded << 4) + ch - '0');
1572
+
1573
+ if (type & NGX_UNESCAPE_REDIRECT) {
1574
+ if (ch > '%' && ch < 0x7f) {
1575
+ *d++ = ch;
1576
+ break;
1577
+ }
1578
+
1579
+ *d++ = '%'; *d++ = *(s - 2); *d++ = *(s - 1);
1580
+
1581
+ break;
1582
+ }
1583
+
1584
+ *d++ = ch;
1585
+
1586
+ break;
1587
+ }
1588
+
1589
+ c = (u_char) (ch | 0x20);
1590
+ if (c >= 'a' && c <= 'f') {
1591
+ ch = (u_char) ((decoded << 4) + c - 'a' + 10);
1592
+
1593
+ if (type & NGX_UNESCAPE_URI) {
1594
+ if (ch == '?') {
1595
+ *d++ = ch;
1596
+ goto done;
1597
+ }
1598
+
1599
+ *d++ = ch;
1600
+ break;
1601
+ }
1602
+
1603
+ if (type & NGX_UNESCAPE_REDIRECT) {
1604
+ if (ch == '?') {
1605
+ *d++ = ch;
1606
+ goto done;
1607
+ }
1608
+
1609
+ if (ch > '%' && ch < 0x7f) {
1610
+ *d++ = ch;
1611
+ break;
1612
+ }
1613
+
1614
+ *d++ = '%'; *d++ = *(s - 2); *d++ = *(s - 1);
1615
+ break;
1616
+ }
1617
+
1618
+ *d++ = ch;
1619
+
1620
+ break;
1621
+ }
1622
+
1623
+ /* the invalid quoted character */
1624
+
1625
+ break;
1626
+ }
1627
+ }
1628
+
1629
+ done:
1630
+
1631
+ *dst = d;
1632
+ *src = s;
1633
+ }
1634
+
1635
+
1636
+ uintptr_t
1637
+ ngx_escape_html(u_char *dst, u_char *src, size_t size)
1638
+ {
1639
+ u_char ch;
1640
+ ngx_uint_t len;
1641
+
1642
+ if (dst == NULL) {
1643
+
1644
+ len = 0;
1645
+
1646
+ while (size) {
1647
+ switch (*src++) {
1648
+
1649
+ case '<':
1650
+ len += sizeof("&lt;") - 2;
1651
+ break;
1652
+
1653
+ case '>':
1654
+ len += sizeof("&gt;") - 2;
1655
+ break;
1656
+
1657
+ case '&':
1658
+ len += sizeof("&amp;") - 2;
1659
+ break;
1660
+
1661
+ case '"':
1662
+ len += sizeof("&quot;") - 2;
1663
+ break;
1664
+
1665
+ default:
1666
+ break;
1667
+ }
1668
+ size--;
1669
+ }
1670
+
1671
+ return (uintptr_t) len;
1672
+ }
1673
+
1674
+ while (size) {
1675
+ ch = *src++;
1676
+
1677
+ switch (ch) {
1678
+
1679
+ case '<':
1680
+ *dst++ = '&'; *dst++ = 'l'; *dst++ = 't'; *dst++ = ';';
1681
+ break;
1682
+
1683
+ case '>':
1684
+ *dst++ = '&'; *dst++ = 'g'; *dst++ = 't'; *dst++ = ';';
1685
+ break;
1686
+
1687
+ case '&':
1688
+ *dst++ = '&'; *dst++ = 'a'; *dst++ = 'm'; *dst++ = 'p';
1689
+ *dst++ = ';';
1690
+ break;
1691
+
1692
+ case '"':
1693
+ *dst++ = '&'; *dst++ = 'q'; *dst++ = 'u'; *dst++ = 'o';
1694
+ *dst++ = 't'; *dst++ = ';';
1695
+ break;
1696
+
1697
+ default:
1698
+ *dst++ = ch;
1699
+ break;
1700
+ }
1701
+ size--;
1702
+ }
1703
+
1704
+ return (uintptr_t) dst;
1705
+ }
1706
+
1707
+
1708
+ void
1709
+ ngx_str_rbtree_insert_value(ngx_rbtree_node_t *temp,
1710
+ ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel)
1711
+ {
1712
+ ngx_str_node_t *n, *t;
1713
+ ngx_rbtree_node_t **p;
1714
+
1715
+ for ( ;; ) {
1716
+
1717
+ n = (ngx_str_node_t *) node;
1718
+ t = (ngx_str_node_t *) temp;
1719
+
1720
+ if (node->key != temp->key) {
1721
+
1722
+ p = (node->key < temp->key) ? &temp->left : &temp->right;
1723
+
1724
+ } else if (n->str.len != t->str.len) {
1725
+
1726
+ p = (n->str.len < t->str.len) ? &temp->left : &temp->right;
1727
+
1728
+ } else {
1729
+ p = (ngx_memcmp(n->str.data, t->str.data, n->str.len) < 0)
1730
+ ? &temp->left : &temp->right;
1731
+ }
1732
+
1733
+ if (*p == sentinel) {
1734
+ break;
1735
+ }
1736
+
1737
+ temp = *p;
1738
+ }
1739
+
1740
+ *p = node;
1741
+ node->parent = temp;
1742
+ node->left = sentinel;
1743
+ node->right = sentinel;
1744
+ ngx_rbt_red(node);
1745
+ }
1746
+
1747
+
1748
+ ngx_str_node_t *
1749
+ ngx_str_rbtree_lookup(ngx_rbtree_t *rbtree, ngx_str_t *val, uint32_t hash)
1750
+ {
1751
+ ngx_int_t rc;
1752
+ ngx_str_node_t *n;
1753
+ ngx_rbtree_node_t *node, *sentinel;
1754
+
1755
+ node = rbtree->root;
1756
+ sentinel = rbtree->sentinel;
1757
+
1758
+ while (node != sentinel) {
1759
+
1760
+ n = (ngx_str_node_t *) node;
1761
+
1762
+ if (hash != node->key) {
1763
+ node = (hash < node->key) ? node->left : node->right;
1764
+ continue;
1765
+ }
1766
+
1767
+ if (val->len != n->str.len) {
1768
+ node = (val->len < n->str.len) ? node->left : node->right;
1769
+ continue;
1770
+ }
1771
+
1772
+ rc = ngx_memcmp(val->data, n->str.data, val->len);
1773
+
1774
+ if (rc < 0) {
1775
+ node = node->left;
1776
+ continue;
1777
+ }
1778
+
1779
+ if (rc > 0) {
1780
+ node = node->right;
1781
+ continue;
1782
+ }
1783
+
1784
+ return n;
1785
+ }
1786
+
1787
+ return NULL;
1788
+ }
1789
+
1790
+
1791
+ /* ngx_sort() is implemented as insertion sort because we need stable sort */
1792
+
1793
+ void
1794
+ ngx_sort(void *base, size_t n, size_t size,
1795
+ ngx_int_t (*cmp)(const void *, const void *))
1796
+ {
1797
+ u_char *p1, *p2, *p;
1798
+
1799
+ p = ngx_alloc(size, ngx_cycle->log);
1800
+ if (p == NULL) {
1801
+ return;
1802
+ }
1803
+
1804
+ for (p1 = (u_char *) base + size;
1805
+ p1 < (u_char *) base + n * size;
1806
+ p1 += size)
1807
+ {
1808
+ ngx_memcpy(p, p1, size);
1809
+
1810
+ for (p2 = p1;
1811
+ p2 > (u_char *) base && cmp(p2 - size, p) > 0;
1812
+ p2 -= size)
1813
+ {
1814
+ ngx_memcpy(p2, p2 - size, size);
1815
+ }
1816
+
1817
+ ngx_memcpy(p2, p, size);
1818
+ }
1819
+
1820
+ ngx_free(p);
1821
+ }
1822
+
1823
+
1824
+ #if (NGX_MEMCPY_LIMIT)
1825
+
1826
+ void *
1827
+ ngx_memcpy(void *dst, void *src, size_t n)
1828
+ {
1829
+ if (n > NGX_MEMCPY_LIMIT) {
1830
+ ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0, "memcpy %uz bytes", n);
1831
+ ngx_debug_point();
1832
+ }
1833
+
1834
+ return memcpy(dst, src, n);
1835
+ }
1836
+
1837
+ #endif