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,1489 @@
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
+
12
+ #include <gd.h>
13
+
14
+
15
+ #define NGX_HTTP_IMAGE_OFF 0
16
+ #define NGX_HTTP_IMAGE_TEST 1
17
+ #define NGX_HTTP_IMAGE_SIZE 2
18
+ #define NGX_HTTP_IMAGE_RESIZE 3
19
+ #define NGX_HTTP_IMAGE_CROP 4
20
+ #define NGX_HTTP_IMAGE_ROTATE 5
21
+
22
+
23
+ #define NGX_HTTP_IMAGE_START 0
24
+ #define NGX_HTTP_IMAGE_READ 1
25
+ #define NGX_HTTP_IMAGE_PROCESS 2
26
+ #define NGX_HTTP_IMAGE_PASS 3
27
+ #define NGX_HTTP_IMAGE_DONE 4
28
+
29
+
30
+ #define NGX_HTTP_IMAGE_NONE 0
31
+ #define NGX_HTTP_IMAGE_JPEG 1
32
+ #define NGX_HTTP_IMAGE_GIF 2
33
+ #define NGX_HTTP_IMAGE_PNG 3
34
+
35
+
36
+ #define NGX_HTTP_IMAGE_BUFFERED 0x08
37
+
38
+
39
+ typedef struct {
40
+ ngx_uint_t filter;
41
+ ngx_uint_t width;
42
+ ngx_uint_t height;
43
+ ngx_uint_t angle;
44
+ ngx_uint_t jpeg_quality;
45
+ ngx_uint_t sharpen;
46
+
47
+ ngx_flag_t transparency;
48
+
49
+ ngx_http_complex_value_t *wcv;
50
+ ngx_http_complex_value_t *hcv;
51
+ ngx_http_complex_value_t *acv;
52
+ ngx_http_complex_value_t *jqcv;
53
+ ngx_http_complex_value_t *shcv;
54
+
55
+ size_t buffer_size;
56
+ } ngx_http_image_filter_conf_t;
57
+
58
+
59
+ typedef struct {
60
+ u_char *image;
61
+ u_char *last;
62
+
63
+ size_t length;
64
+
65
+ ngx_uint_t width;
66
+ ngx_uint_t height;
67
+ ngx_uint_t max_width;
68
+ ngx_uint_t max_height;
69
+ ngx_uint_t angle;
70
+
71
+ ngx_uint_t phase;
72
+ ngx_uint_t type;
73
+ ngx_uint_t force;
74
+ } ngx_http_image_filter_ctx_t;
75
+
76
+
77
+ static ngx_int_t ngx_http_image_send(ngx_http_request_t *r,
78
+ ngx_http_image_filter_ctx_t *ctx, ngx_chain_t *in);
79
+ static ngx_uint_t ngx_http_image_test(ngx_http_request_t *r, ngx_chain_t *in);
80
+ static ngx_int_t ngx_http_image_read(ngx_http_request_t *r, ngx_chain_t *in);
81
+ static ngx_buf_t *ngx_http_image_process(ngx_http_request_t *r);
82
+ static ngx_buf_t *ngx_http_image_json(ngx_http_request_t *r,
83
+ ngx_http_image_filter_ctx_t *ctx);
84
+ static ngx_buf_t *ngx_http_image_asis(ngx_http_request_t *r,
85
+ ngx_http_image_filter_ctx_t *ctx);
86
+ static void ngx_http_image_length(ngx_http_request_t *r, ngx_buf_t *b);
87
+ static ngx_int_t ngx_http_image_size(ngx_http_request_t *r,
88
+ ngx_http_image_filter_ctx_t *ctx);
89
+
90
+ static ngx_buf_t *ngx_http_image_resize(ngx_http_request_t *r,
91
+ ngx_http_image_filter_ctx_t *ctx);
92
+ static gdImagePtr ngx_http_image_source(ngx_http_request_t *r,
93
+ ngx_http_image_filter_ctx_t *ctx);
94
+ static gdImagePtr ngx_http_image_new(ngx_http_request_t *r, int w, int h,
95
+ int colors);
96
+ static u_char *ngx_http_image_out(ngx_http_request_t *r, ngx_uint_t type,
97
+ gdImagePtr img, int *size);
98
+ static void ngx_http_image_cleanup(void *data);
99
+ static ngx_uint_t ngx_http_image_filter_get_value(ngx_http_request_t *r,
100
+ ngx_http_complex_value_t *cv, ngx_uint_t v);
101
+ static ngx_uint_t ngx_http_image_filter_value(ngx_str_t *value);
102
+
103
+
104
+ static void *ngx_http_image_filter_create_conf(ngx_conf_t *cf);
105
+ static char *ngx_http_image_filter_merge_conf(ngx_conf_t *cf, void *parent,
106
+ void *child);
107
+ static char *ngx_http_image_filter(ngx_conf_t *cf, ngx_command_t *cmd,
108
+ void *conf);
109
+ static char *ngx_http_image_filter_jpeg_quality(ngx_conf_t *cf,
110
+ ngx_command_t *cmd, void *conf);
111
+ static char *ngx_http_image_filter_sharpen(ngx_conf_t *cf, ngx_command_t *cmd,
112
+ void *conf);
113
+ static ngx_int_t ngx_http_image_filter_init(ngx_conf_t *cf);
114
+
115
+
116
+ static ngx_command_t ngx_http_image_filter_commands[] = {
117
+
118
+ { ngx_string("image_filter"),
119
+ NGX_HTTP_LOC_CONF|NGX_CONF_TAKE123,
120
+ ngx_http_image_filter,
121
+ NGX_HTTP_LOC_CONF_OFFSET,
122
+ 0,
123
+ NULL },
124
+
125
+ { ngx_string("image_filter_jpeg_quality"),
126
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
127
+ ngx_http_image_filter_jpeg_quality,
128
+ NGX_HTTP_LOC_CONF_OFFSET,
129
+ 0,
130
+ NULL },
131
+
132
+ { ngx_string("image_filter_sharpen"),
133
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
134
+ ngx_http_image_filter_sharpen,
135
+ NGX_HTTP_LOC_CONF_OFFSET,
136
+ 0,
137
+ NULL },
138
+
139
+ { ngx_string("image_filter_transparency"),
140
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
141
+ ngx_conf_set_flag_slot,
142
+ NGX_HTTP_LOC_CONF_OFFSET,
143
+ offsetof(ngx_http_image_filter_conf_t, transparency),
144
+ NULL },
145
+
146
+ { ngx_string("image_filter_buffer"),
147
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
148
+ ngx_conf_set_size_slot,
149
+ NGX_HTTP_LOC_CONF_OFFSET,
150
+ offsetof(ngx_http_image_filter_conf_t, buffer_size),
151
+ NULL },
152
+
153
+ ngx_null_command
154
+ };
155
+
156
+
157
+ static ngx_http_module_t ngx_http_image_filter_module_ctx = {
158
+ NULL, /* preconfiguration */
159
+ ngx_http_image_filter_init, /* postconfiguration */
160
+
161
+ NULL, /* create main configuration */
162
+ NULL, /* init main configuration */
163
+
164
+ NULL, /* create server configuration */
165
+ NULL, /* merge server configuration */
166
+
167
+ ngx_http_image_filter_create_conf, /* create location configuration */
168
+ ngx_http_image_filter_merge_conf /* merge location configuration */
169
+ };
170
+
171
+
172
+ ngx_module_t ngx_http_image_filter_module = {
173
+ NGX_MODULE_V1,
174
+ &ngx_http_image_filter_module_ctx, /* module context */
175
+ ngx_http_image_filter_commands, /* module directives */
176
+ NGX_HTTP_MODULE, /* module type */
177
+ NULL, /* init master */
178
+ NULL, /* init module */
179
+ NULL, /* init process */
180
+ NULL, /* init thread */
181
+ NULL, /* exit thread */
182
+ NULL, /* exit process */
183
+ NULL, /* exit master */
184
+ NGX_MODULE_V1_PADDING
185
+ };
186
+
187
+
188
+ static ngx_http_output_header_filter_pt ngx_http_next_header_filter;
189
+ static ngx_http_output_body_filter_pt ngx_http_next_body_filter;
190
+
191
+
192
+ static ngx_str_t ngx_http_image_types[] = {
193
+ ngx_string("image/jpeg"),
194
+ ngx_string("image/gif"),
195
+ ngx_string("image/png")
196
+ };
197
+
198
+
199
+ static ngx_int_t
200
+ ngx_http_image_header_filter(ngx_http_request_t *r)
201
+ {
202
+ off_t len;
203
+ ngx_http_image_filter_ctx_t *ctx;
204
+ ngx_http_image_filter_conf_t *conf;
205
+
206
+ if (r->headers_out.status == NGX_HTTP_NOT_MODIFIED) {
207
+ return ngx_http_next_header_filter(r);
208
+ }
209
+
210
+ ctx = ngx_http_get_module_ctx(r, ngx_http_image_filter_module);
211
+
212
+ if (ctx) {
213
+ ngx_http_set_ctx(r, NULL, ngx_http_image_filter_module);
214
+ return ngx_http_next_header_filter(r);
215
+ }
216
+
217
+ conf = ngx_http_get_module_loc_conf(r, ngx_http_image_filter_module);
218
+
219
+ if (conf->filter == NGX_HTTP_IMAGE_OFF) {
220
+ return ngx_http_next_header_filter(r);
221
+ }
222
+
223
+ if (r->headers_out.content_type.len
224
+ >= sizeof("multipart/x-mixed-replace") - 1
225
+ && ngx_strncasecmp(r->headers_out.content_type.data,
226
+ (u_char *) "multipart/x-mixed-replace",
227
+ sizeof("multipart/x-mixed-replace") - 1)
228
+ == 0)
229
+ {
230
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
231
+ "image filter: multipart/x-mixed-replace response");
232
+
233
+ return NGX_ERROR;
234
+ }
235
+
236
+ ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_image_filter_ctx_t));
237
+ if (ctx == NULL) {
238
+ return NGX_ERROR;
239
+ }
240
+
241
+ ngx_http_set_ctx(r, ctx, ngx_http_image_filter_module);
242
+
243
+ len = r->headers_out.content_length_n;
244
+
245
+ if (len != -1 && len > (off_t) conf->buffer_size) {
246
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
247
+ "image filter: too big response: %O", len);
248
+
249
+ return NGX_HTTP_UNSUPPORTED_MEDIA_TYPE;
250
+ }
251
+
252
+ if (len == -1) {
253
+ ctx->length = conf->buffer_size;
254
+
255
+ } else {
256
+ ctx->length = (size_t) len;
257
+ }
258
+
259
+ if (r->headers_out.refresh) {
260
+ r->headers_out.refresh->hash = 0;
261
+ }
262
+
263
+ r->main_filter_need_in_memory = 1;
264
+ r->allow_ranges = 0;
265
+
266
+ return NGX_OK;
267
+ }
268
+
269
+
270
+ static ngx_int_t
271
+ ngx_http_image_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
272
+ {
273
+ ngx_int_t rc;
274
+ ngx_str_t *ct;
275
+ ngx_chain_t out;
276
+ ngx_http_image_filter_ctx_t *ctx;
277
+ ngx_http_image_filter_conf_t *conf;
278
+
279
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "image filter");
280
+
281
+ if (in == NULL) {
282
+ return ngx_http_next_body_filter(r, in);
283
+ }
284
+
285
+ ctx = ngx_http_get_module_ctx(r, ngx_http_image_filter_module);
286
+
287
+ if (ctx == NULL) {
288
+ return ngx_http_next_body_filter(r, in);
289
+ }
290
+
291
+ switch (ctx->phase) {
292
+
293
+ case NGX_HTTP_IMAGE_START:
294
+
295
+ ctx->type = ngx_http_image_test(r, in);
296
+
297
+ conf = ngx_http_get_module_loc_conf(r, ngx_http_image_filter_module);
298
+
299
+ if (ctx->type == NGX_HTTP_IMAGE_NONE) {
300
+
301
+ if (conf->filter == NGX_HTTP_IMAGE_SIZE) {
302
+ out.buf = ngx_http_image_json(r, NULL);
303
+
304
+ if (out.buf) {
305
+ out.next = NULL;
306
+ ctx->phase = NGX_HTTP_IMAGE_DONE;
307
+
308
+ return ngx_http_image_send(r, ctx, &out);
309
+ }
310
+ }
311
+
312
+ return ngx_http_filter_finalize_request(r,
313
+ &ngx_http_image_filter_module,
314
+ NGX_HTTP_UNSUPPORTED_MEDIA_TYPE);
315
+ }
316
+
317
+ /* override content type */
318
+
319
+ ct = &ngx_http_image_types[ctx->type - 1];
320
+ r->headers_out.content_type_len = ct->len;
321
+ r->headers_out.content_type = *ct;
322
+ r->headers_out.content_type_lowcase = NULL;
323
+
324
+ if (conf->filter == NGX_HTTP_IMAGE_TEST) {
325
+ ctx->phase = NGX_HTTP_IMAGE_PASS;
326
+
327
+ return ngx_http_image_send(r, ctx, in);
328
+ }
329
+
330
+ ctx->phase = NGX_HTTP_IMAGE_READ;
331
+
332
+ /* fall through */
333
+
334
+ case NGX_HTTP_IMAGE_READ:
335
+
336
+ rc = ngx_http_image_read(r, in);
337
+
338
+ if (rc == NGX_AGAIN) {
339
+ return NGX_OK;
340
+ }
341
+
342
+ if (rc == NGX_ERROR) {
343
+ return ngx_http_filter_finalize_request(r,
344
+ &ngx_http_image_filter_module,
345
+ NGX_HTTP_UNSUPPORTED_MEDIA_TYPE);
346
+ }
347
+
348
+ /* fall through */
349
+
350
+ case NGX_HTTP_IMAGE_PROCESS:
351
+
352
+ out.buf = ngx_http_image_process(r);
353
+
354
+ if (out.buf == NULL) {
355
+ return ngx_http_filter_finalize_request(r,
356
+ &ngx_http_image_filter_module,
357
+ NGX_HTTP_UNSUPPORTED_MEDIA_TYPE);
358
+ }
359
+
360
+ out.next = NULL;
361
+ ctx->phase = NGX_HTTP_IMAGE_PASS;
362
+
363
+ return ngx_http_image_send(r, ctx, &out);
364
+
365
+ case NGX_HTTP_IMAGE_PASS:
366
+
367
+ return ngx_http_next_body_filter(r, in);
368
+
369
+ default: /* NGX_HTTP_IMAGE_DONE */
370
+
371
+ rc = ngx_http_next_body_filter(r, NULL);
372
+
373
+ /* NGX_ERROR resets any pending data */
374
+ return (rc == NGX_OK) ? NGX_ERROR : rc;
375
+ }
376
+ }
377
+
378
+
379
+ static ngx_int_t
380
+ ngx_http_image_send(ngx_http_request_t *r, ngx_http_image_filter_ctx_t *ctx,
381
+ ngx_chain_t *in)
382
+ {
383
+ ngx_int_t rc;
384
+
385
+ rc = ngx_http_next_header_filter(r);
386
+
387
+ if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) {
388
+ return NGX_ERROR;
389
+ }
390
+
391
+ rc = ngx_http_next_body_filter(r, in);
392
+
393
+ if (ctx->phase == NGX_HTTP_IMAGE_DONE) {
394
+ /* NGX_ERROR resets any pending data */
395
+ return (rc == NGX_OK) ? NGX_ERROR : rc;
396
+ }
397
+
398
+ return rc;
399
+ }
400
+
401
+
402
+ static ngx_uint_t
403
+ ngx_http_image_test(ngx_http_request_t *r, ngx_chain_t *in)
404
+ {
405
+ u_char *p;
406
+
407
+ p = in->buf->pos;
408
+
409
+ if (in->buf->last - p < 16) {
410
+ return NGX_HTTP_IMAGE_NONE;
411
+ }
412
+
413
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
414
+ "image filter: \"%c%c\"", p[0], p[1]);
415
+
416
+ if (p[0] == 0xff && p[1] == 0xd8) {
417
+
418
+ /* JPEG */
419
+
420
+ return NGX_HTTP_IMAGE_JPEG;
421
+
422
+ } else if (p[0] == 'G' && p[1] == 'I' && p[2] == 'F' && p[3] == '8'
423
+ && p[5] == 'a')
424
+ {
425
+ if (p[4] == '9' || p[4] == '7') {
426
+ /* GIF */
427
+ return NGX_HTTP_IMAGE_GIF;
428
+ }
429
+
430
+ } else if (p[0] == 0x89 && p[1] == 'P' && p[2] == 'N' && p[3] == 'G'
431
+ && p[4] == 0x0d && p[5] == 0x0a && p[6] == 0x1a && p[7] == 0x0a)
432
+ {
433
+ /* PNG */
434
+
435
+ return NGX_HTTP_IMAGE_PNG;
436
+ }
437
+
438
+ return NGX_HTTP_IMAGE_NONE;
439
+ }
440
+
441
+
442
+ static ngx_int_t
443
+ ngx_http_image_read(ngx_http_request_t *r, ngx_chain_t *in)
444
+ {
445
+ u_char *p;
446
+ size_t size, rest;
447
+ ngx_buf_t *b;
448
+ ngx_chain_t *cl;
449
+ ngx_http_image_filter_ctx_t *ctx;
450
+
451
+ ctx = ngx_http_get_module_ctx(r, ngx_http_image_filter_module);
452
+
453
+ if (ctx->image == NULL) {
454
+ ctx->image = ngx_palloc(r->pool, ctx->length);
455
+ if (ctx->image == NULL) {
456
+ return NGX_ERROR;
457
+ }
458
+
459
+ ctx->last = ctx->image;
460
+ }
461
+
462
+ p = ctx->last;
463
+
464
+ for (cl = in; cl; cl = cl->next) {
465
+
466
+ b = cl->buf;
467
+ size = b->last - b->pos;
468
+
469
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
470
+ "image buf: %uz", size);
471
+
472
+ rest = ctx->image + ctx->length - p;
473
+ size = (rest < size) ? rest : size;
474
+
475
+ p = ngx_cpymem(p, b->pos, size);
476
+ b->pos += size;
477
+
478
+ if (b->last_buf) {
479
+ ctx->last = p;
480
+ return NGX_OK;
481
+ }
482
+ }
483
+
484
+ ctx->last = p;
485
+ r->connection->buffered |= NGX_HTTP_IMAGE_BUFFERED;
486
+
487
+ return NGX_AGAIN;
488
+ }
489
+
490
+
491
+ static ngx_buf_t *
492
+ ngx_http_image_process(ngx_http_request_t *r)
493
+ {
494
+ ngx_int_t rc;
495
+ ngx_http_image_filter_ctx_t *ctx;
496
+ ngx_http_image_filter_conf_t *conf;
497
+
498
+ r->connection->buffered &= ~NGX_HTTP_IMAGE_BUFFERED;
499
+
500
+ ctx = ngx_http_get_module_ctx(r, ngx_http_image_filter_module);
501
+
502
+ rc = ngx_http_image_size(r, ctx);
503
+
504
+ conf = ngx_http_get_module_loc_conf(r, ngx_http_image_filter_module);
505
+
506
+ if (conf->filter == NGX_HTTP_IMAGE_SIZE) {
507
+ return ngx_http_image_json(r, rc == NGX_OK ? ctx : NULL);
508
+ }
509
+
510
+ ctx->angle = ngx_http_image_filter_get_value(r, conf->acv, conf->angle);
511
+
512
+ if (conf->filter == NGX_HTTP_IMAGE_ROTATE) {
513
+
514
+ if (ctx->angle != 90 && ctx->angle != 180 && ctx->angle != 270) {
515
+ return NULL;
516
+ }
517
+
518
+ return ngx_http_image_resize(r, ctx);
519
+ }
520
+
521
+ ctx->max_width = ngx_http_image_filter_get_value(r, conf->wcv, conf->width);
522
+ if (ctx->max_width == 0) {
523
+ return NULL;
524
+ }
525
+
526
+ ctx->max_height = ngx_http_image_filter_get_value(r, conf->hcv,
527
+ conf->height);
528
+ if (ctx->max_height == 0) {
529
+ return NULL;
530
+ }
531
+
532
+ if (rc == NGX_OK
533
+ && ctx->width <= ctx->max_width
534
+ && ctx->height <= ctx->max_height
535
+ && ctx->angle == 0
536
+ && !ctx->force)
537
+ {
538
+ return ngx_http_image_asis(r, ctx);
539
+ }
540
+
541
+ return ngx_http_image_resize(r, ctx);
542
+ }
543
+
544
+
545
+ static ngx_buf_t *
546
+ ngx_http_image_json(ngx_http_request_t *r, ngx_http_image_filter_ctx_t *ctx)
547
+ {
548
+ size_t len;
549
+ ngx_buf_t *b;
550
+
551
+ b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
552
+ if (b == NULL) {
553
+ return NULL;
554
+ }
555
+
556
+ b->memory = 1;
557
+ b->last_buf = 1;
558
+
559
+ ngx_http_clean_header(r);
560
+
561
+ r->headers_out.status = NGX_HTTP_OK;
562
+ ngx_str_set(&r->headers_out.content_type, "text/plain");
563
+ r->headers_out.content_type_lowcase = NULL;
564
+
565
+ if (ctx == NULL) {
566
+ b->pos = (u_char *) "{}" CRLF;
567
+ b->last = b->pos + sizeof("{}" CRLF) - 1;
568
+
569
+ ngx_http_image_length(r, b);
570
+
571
+ return b;
572
+ }
573
+
574
+ len = sizeof("{ \"img\" : "
575
+ "{ \"width\": , \"height\": , \"type\": \"jpeg\" } }" CRLF) - 1
576
+ + 2 * NGX_SIZE_T_LEN;
577
+
578
+ b->pos = ngx_pnalloc(r->pool, len);
579
+ if (b->pos == NULL) {
580
+ return NULL;
581
+ }
582
+
583
+ b->last = ngx_sprintf(b->pos,
584
+ "{ \"img\" : "
585
+ "{ \"width\": %uz,"
586
+ " \"height\": %uz,"
587
+ " \"type\": \"%s\" } }" CRLF,
588
+ ctx->width, ctx->height,
589
+ ngx_http_image_types[ctx->type - 1].data + 6);
590
+
591
+ ngx_http_image_length(r, b);
592
+
593
+ return b;
594
+ }
595
+
596
+
597
+ static ngx_buf_t *
598
+ ngx_http_image_asis(ngx_http_request_t *r, ngx_http_image_filter_ctx_t *ctx)
599
+ {
600
+ ngx_buf_t *b;
601
+
602
+ b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
603
+ if (b == NULL) {
604
+ return NULL;
605
+ }
606
+
607
+ b->pos = ctx->image;
608
+ b->last = ctx->last;
609
+ b->memory = 1;
610
+ b->last_buf = 1;
611
+
612
+ ngx_http_image_length(r, b);
613
+
614
+ return b;
615
+ }
616
+
617
+
618
+ static void
619
+ ngx_http_image_length(ngx_http_request_t *r, ngx_buf_t *b)
620
+ {
621
+ r->headers_out.content_length_n = b->last - b->pos;
622
+
623
+ if (r->headers_out.content_length) {
624
+ r->headers_out.content_length->hash = 0;
625
+ }
626
+
627
+ r->headers_out.content_length = NULL;
628
+ }
629
+
630
+
631
+ static ngx_int_t
632
+ ngx_http_image_size(ngx_http_request_t *r, ngx_http_image_filter_ctx_t *ctx)
633
+ {
634
+ u_char *p, *last;
635
+ size_t len, app;
636
+ ngx_uint_t width, height;
637
+
638
+ p = ctx->image;
639
+
640
+ switch (ctx->type) {
641
+
642
+ case NGX_HTTP_IMAGE_JPEG:
643
+
644
+ p += 2;
645
+ last = ctx->image + ctx->length - 10;
646
+ width = 0;
647
+ height = 0;
648
+ app = 0;
649
+
650
+ while (p < last) {
651
+
652
+ if (p[0] == 0xff && p[1] != 0xff) {
653
+
654
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
655
+ "JPEG: %02xd %02xd", p[0], p[1]);
656
+
657
+ p++;
658
+
659
+ if ((*p == 0xc0 || *p == 0xc1 || *p == 0xc2 || *p == 0xc3
660
+ || *p == 0xc9 || *p == 0xca || *p == 0xcb)
661
+ && (width == 0 || height == 0))
662
+ {
663
+ width = p[6] * 256 + p[7];
664
+ height = p[4] * 256 + p[5];
665
+ }
666
+
667
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
668
+ "JPEG: %02xd %02xd", p[1], p[2]);
669
+
670
+ len = p[1] * 256 + p[2];
671
+
672
+ if (*p >= 0xe1 && *p <= 0xef) {
673
+ /* application data, e.g., EXIF, Adobe XMP, etc. */
674
+ app += len;
675
+ }
676
+
677
+ p += len;
678
+
679
+ continue;
680
+ }
681
+
682
+ p++;
683
+ }
684
+
685
+ if (width == 0 || height == 0) {
686
+ return NGX_DECLINED;
687
+ }
688
+
689
+ if (ctx->length / 20 < app) {
690
+ /* force conversion if application data consume more than 5% */
691
+ ctx->force = 1;
692
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
693
+ "app data size: %uz", app);
694
+ }
695
+
696
+ break;
697
+
698
+ case NGX_HTTP_IMAGE_GIF:
699
+
700
+ if (ctx->length < 10) {
701
+ return NGX_DECLINED;
702
+ }
703
+
704
+ width = p[7] * 256 + p[6];
705
+ height = p[9] * 256 + p[8];
706
+
707
+ break;
708
+
709
+ case NGX_HTTP_IMAGE_PNG:
710
+
711
+ if (ctx->length < 24) {
712
+ return NGX_DECLINED;
713
+ }
714
+
715
+ width = p[18] * 256 + p[19];
716
+ height = p[22] * 256 + p[23];
717
+
718
+ break;
719
+
720
+ default:
721
+
722
+ return NGX_DECLINED;
723
+ }
724
+
725
+ ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
726
+ "image size: %d x %d", width, height);
727
+
728
+ ctx->width = width;
729
+ ctx->height = height;
730
+
731
+ return NGX_OK;
732
+ }
733
+
734
+
735
+ static ngx_buf_t *
736
+ ngx_http_image_resize(ngx_http_request_t *r, ngx_http_image_filter_ctx_t *ctx)
737
+ {
738
+ int sx, sy, dx, dy, ox, oy, ax, ay, size,
739
+ colors, palette, transparent, sharpen,
740
+ red, green, blue, t;
741
+ u_char *out;
742
+ ngx_buf_t *b;
743
+ ngx_uint_t resize;
744
+ gdImagePtr src, dst;
745
+ ngx_pool_cleanup_t *cln;
746
+ ngx_http_image_filter_conf_t *conf;
747
+
748
+ src = ngx_http_image_source(r, ctx);
749
+
750
+ if (src == NULL) {
751
+ return NULL;
752
+ }
753
+
754
+ sx = gdImageSX(src);
755
+ sy = gdImageSY(src);
756
+
757
+ conf = ngx_http_get_module_loc_conf(r, ngx_http_image_filter_module);
758
+
759
+ if (!ctx->force
760
+ && ctx->angle == 0
761
+ && (ngx_uint_t) sx <= ctx->max_width
762
+ && (ngx_uint_t) sy <= ctx->max_height)
763
+ {
764
+ gdImageDestroy(src);
765
+ return ngx_http_image_asis(r, ctx);
766
+ }
767
+
768
+ colors = gdImageColorsTotal(src);
769
+
770
+ if (colors && conf->transparency) {
771
+ transparent = gdImageGetTransparent(src);
772
+
773
+ if (transparent != -1) {
774
+ palette = colors;
775
+ red = gdImageRed(src, transparent);
776
+ green = gdImageGreen(src, transparent);
777
+ blue = gdImageBlue(src, transparent);
778
+
779
+ goto transparent;
780
+ }
781
+ }
782
+
783
+ palette = 0;
784
+ transparent = -1;
785
+ red = 0;
786
+ green = 0;
787
+ blue = 0;
788
+
789
+ transparent:
790
+
791
+ gdImageColorTransparent(src, -1);
792
+
793
+ dx = sx;
794
+ dy = sy;
795
+
796
+ if (conf->filter == NGX_HTTP_IMAGE_RESIZE) {
797
+
798
+ if ((ngx_uint_t) dx > ctx->max_width) {
799
+ dy = dy * ctx->max_width / dx;
800
+ dy = dy ? dy : 1;
801
+ dx = ctx->max_width;
802
+ }
803
+
804
+ if ((ngx_uint_t) dy > ctx->max_height) {
805
+ dx = dx * ctx->max_height / dy;
806
+ dx = dx ? dx : 1;
807
+ dy = ctx->max_height;
808
+ }
809
+
810
+ resize = 1;
811
+
812
+ } else if (conf->filter == NGX_HTTP_IMAGE_ROTATE) {
813
+
814
+ resize = 0;
815
+
816
+ } else { /* NGX_HTTP_IMAGE_CROP */
817
+
818
+ resize = 0;
819
+
820
+ if ((ngx_uint_t) (dx * 100 / dy)
821
+ < ctx->max_width * 100 / ctx->max_height)
822
+ {
823
+ if ((ngx_uint_t) dx > ctx->max_width) {
824
+ dy = dy * ctx->max_width / dx;
825
+ dy = dy ? dy : 1;
826
+ dx = ctx->max_width;
827
+ resize = 1;
828
+ }
829
+
830
+ } else {
831
+ if ((ngx_uint_t) dy > ctx->max_height) {
832
+ dx = dx * ctx->max_height / dy;
833
+ dx = dx ? dx : 1;
834
+ dy = ctx->max_height;
835
+ resize = 1;
836
+ }
837
+ }
838
+ }
839
+
840
+ if (resize) {
841
+ dst = ngx_http_image_new(r, dx, dy, palette);
842
+ if (dst == NULL) {
843
+ gdImageDestroy(src);
844
+ return NULL;
845
+ }
846
+
847
+ if (colors == 0) {
848
+ gdImageSaveAlpha(dst, 1);
849
+ gdImageAlphaBlending(dst, 0);
850
+ }
851
+
852
+ gdImageCopyResampled(dst, src, 0, 0, 0, 0, dx, dy, sx, sy);
853
+
854
+ if (colors) {
855
+ gdImageTrueColorToPalette(dst, 1, 256);
856
+ }
857
+
858
+ gdImageDestroy(src);
859
+
860
+ } else {
861
+ dst = src;
862
+ }
863
+
864
+ if (ctx->angle) {
865
+ src = dst;
866
+
867
+ ax = (dx % 2 == 0) ? 1 : 0;
868
+ ay = (dy % 2 == 0) ? 1 : 0;
869
+
870
+ switch (ctx->angle) {
871
+
872
+ case 90:
873
+ case 270:
874
+ dst = ngx_http_image_new(r, dy, dx, palette);
875
+ if (dst == NULL) {
876
+ gdImageDestroy(src);
877
+ return NULL;
878
+ }
879
+ if (ctx->angle == 90) {
880
+ ox = dy / 2 + ay;
881
+ oy = dx / 2 - ax;
882
+
883
+ } else {
884
+ ox = dy / 2 - ay;
885
+ oy = dx / 2 + ax;
886
+ }
887
+
888
+ gdImageCopyRotated(dst, src, ox, oy, 0, 0,
889
+ dx + ax, dy + ay, ctx->angle);
890
+ gdImageDestroy(src);
891
+
892
+ t = dx;
893
+ dx = dy;
894
+ dy = t;
895
+ break;
896
+
897
+ case 180:
898
+ dst = ngx_http_image_new(r, dx, dy, palette);
899
+ if (dst == NULL) {
900
+ gdImageDestroy(src);
901
+ return NULL;
902
+ }
903
+ gdImageCopyRotated(dst, src, dx / 2 - ax, dy / 2 - ay, 0, 0,
904
+ dx + ax, dy + ay, ctx->angle);
905
+ gdImageDestroy(src);
906
+ break;
907
+ }
908
+ }
909
+
910
+ if (conf->filter == NGX_HTTP_IMAGE_CROP) {
911
+
912
+ src = dst;
913
+
914
+ if ((ngx_uint_t) dx > ctx->max_width) {
915
+ ox = dx - ctx->max_width;
916
+
917
+ } else {
918
+ ox = 0;
919
+ }
920
+
921
+ if ((ngx_uint_t) dy > ctx->max_height) {
922
+ oy = dy - ctx->max_height;
923
+
924
+ } else {
925
+ oy = 0;
926
+ }
927
+
928
+ if (ox || oy) {
929
+
930
+ dst = ngx_http_image_new(r, dx - ox, dy - oy, colors);
931
+
932
+ if (dst == NULL) {
933
+ gdImageDestroy(src);
934
+ return NULL;
935
+ }
936
+
937
+ ox /= 2;
938
+ oy /= 2;
939
+
940
+ ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
941
+ "image crop: %d x %d @ %d x %d",
942
+ dx, dy, ox, oy);
943
+
944
+ if (colors == 0) {
945
+ gdImageSaveAlpha(dst, 1);
946
+ gdImageAlphaBlending(dst, 0);
947
+ }
948
+
949
+ gdImageCopy(dst, src, 0, 0, ox, oy, dx - ox, dy - oy);
950
+
951
+ if (colors) {
952
+ gdImageTrueColorToPalette(dst, 1, 256);
953
+ }
954
+
955
+ gdImageDestroy(src);
956
+ }
957
+ }
958
+
959
+ if (transparent != -1 && colors) {
960
+ gdImageColorTransparent(dst, gdImageColorExact(dst, red, green, blue));
961
+ }
962
+
963
+ sharpen = ngx_http_image_filter_get_value(r, conf->shcv, conf->sharpen);
964
+ if (sharpen > 0) {
965
+ gdImageSharpen(dst, sharpen);
966
+ }
967
+
968
+ out = ngx_http_image_out(r, ctx->type, dst, &size);
969
+
970
+ ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
971
+ "image: %d x %d %d", sx, sy, colors);
972
+
973
+ gdImageDestroy(dst);
974
+ ngx_pfree(r->pool, ctx->image);
975
+
976
+ if (out == NULL) {
977
+ return NULL;
978
+ }
979
+
980
+ cln = ngx_pool_cleanup_add(r->pool, 0);
981
+ if (cln == NULL) {
982
+ gdFree(out);
983
+ return NULL;
984
+ }
985
+
986
+ b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
987
+ if (b == NULL) {
988
+ gdFree(out);
989
+ return NULL;
990
+ }
991
+
992
+ cln->handler = ngx_http_image_cleanup;
993
+ cln->data = out;
994
+
995
+ b->pos = out;
996
+ b->last = out + size;
997
+ b->memory = 1;
998
+ b->last_buf = 1;
999
+
1000
+ ngx_http_image_length(r, b);
1001
+
1002
+ return b;
1003
+ }
1004
+
1005
+
1006
+ static gdImagePtr
1007
+ ngx_http_image_source(ngx_http_request_t *r, ngx_http_image_filter_ctx_t *ctx)
1008
+ {
1009
+ char *failed;
1010
+ gdImagePtr img;
1011
+
1012
+ img = NULL;
1013
+
1014
+ switch (ctx->type) {
1015
+
1016
+ case NGX_HTTP_IMAGE_JPEG:
1017
+ img = gdImageCreateFromJpegPtr(ctx->length, ctx->image);
1018
+ failed = "gdImageCreateFromJpegPtr() failed";
1019
+ break;
1020
+
1021
+ case NGX_HTTP_IMAGE_GIF:
1022
+ img = gdImageCreateFromGifPtr(ctx->length, ctx->image);
1023
+ failed = "gdImageCreateFromGifPtr() failed";
1024
+ break;
1025
+
1026
+ case NGX_HTTP_IMAGE_PNG:
1027
+ img = gdImageCreateFromPngPtr(ctx->length, ctx->image);
1028
+ failed = "gdImageCreateFromPngPtr() failed";
1029
+ break;
1030
+
1031
+ default:
1032
+ failed = "unknown image type";
1033
+ break;
1034
+ }
1035
+
1036
+ if (img == NULL) {
1037
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, failed);
1038
+ }
1039
+
1040
+ return img;
1041
+ }
1042
+
1043
+
1044
+ static gdImagePtr
1045
+ ngx_http_image_new(ngx_http_request_t *r, int w, int h, int colors)
1046
+ {
1047
+ gdImagePtr img;
1048
+
1049
+ if (colors == 0) {
1050
+ img = gdImageCreateTrueColor(w, h);
1051
+
1052
+ if (img == NULL) {
1053
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
1054
+ "gdImageCreateTrueColor() failed");
1055
+ return NULL;
1056
+ }
1057
+
1058
+ } else {
1059
+ img = gdImageCreate(w, h);
1060
+
1061
+ if (img == NULL) {
1062
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
1063
+ "gdImageCreate() failed");
1064
+ return NULL;
1065
+ }
1066
+ }
1067
+
1068
+ return img;
1069
+ }
1070
+
1071
+
1072
+ static u_char *
1073
+ ngx_http_image_out(ngx_http_request_t *r, ngx_uint_t type, gdImagePtr img,
1074
+ int *size)
1075
+ {
1076
+ char *failed;
1077
+ u_char *out;
1078
+ ngx_int_t jq;
1079
+ ngx_http_image_filter_conf_t *conf;
1080
+
1081
+ out = NULL;
1082
+
1083
+ switch (type) {
1084
+
1085
+ case NGX_HTTP_IMAGE_JPEG:
1086
+ conf = ngx_http_get_module_loc_conf(r, ngx_http_image_filter_module);
1087
+
1088
+ jq = ngx_http_image_filter_get_value(r, conf->jqcv, conf->jpeg_quality);
1089
+ if (jq <= 0) {
1090
+ return NULL;
1091
+ }
1092
+
1093
+ out = gdImageJpegPtr(img, size, jq);
1094
+ failed = "gdImageJpegPtr() failed";
1095
+ break;
1096
+
1097
+ case NGX_HTTP_IMAGE_GIF:
1098
+ out = gdImageGifPtr(img, size);
1099
+ failed = "gdImageGifPtr() failed";
1100
+ break;
1101
+
1102
+ case NGX_HTTP_IMAGE_PNG:
1103
+ out = gdImagePngPtr(img, size);
1104
+ failed = "gdImagePngPtr() failed";
1105
+ break;
1106
+
1107
+ default:
1108
+ failed = "unknown image type";
1109
+ break;
1110
+ }
1111
+
1112
+ if (out == NULL) {
1113
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, failed);
1114
+ }
1115
+
1116
+ return out;
1117
+ }
1118
+
1119
+
1120
+ static void
1121
+ ngx_http_image_cleanup(void *data)
1122
+ {
1123
+ gdFree(data);
1124
+ }
1125
+
1126
+
1127
+ static ngx_uint_t
1128
+ ngx_http_image_filter_get_value(ngx_http_request_t *r,
1129
+ ngx_http_complex_value_t *cv, ngx_uint_t v)
1130
+ {
1131
+ ngx_str_t val;
1132
+
1133
+ if (cv == NULL) {
1134
+ return v;
1135
+ }
1136
+
1137
+ if (ngx_http_complex_value(r, cv, &val) != NGX_OK) {
1138
+ return 0;
1139
+ }
1140
+
1141
+ return ngx_http_image_filter_value(&val);
1142
+ }
1143
+
1144
+
1145
+ static ngx_uint_t
1146
+ ngx_http_image_filter_value(ngx_str_t *value)
1147
+ {
1148
+ ngx_int_t n;
1149
+
1150
+ if (value->len == 1 && value->data[0] == '-') {
1151
+ return (ngx_uint_t) -1;
1152
+ }
1153
+
1154
+ n = ngx_atoi(value->data, value->len);
1155
+
1156
+ if (n > 0) {
1157
+ return (ngx_uint_t) n;
1158
+ }
1159
+
1160
+ return 0;
1161
+ }
1162
+
1163
+
1164
+ static void *
1165
+ ngx_http_image_filter_create_conf(ngx_conf_t *cf)
1166
+ {
1167
+ ngx_http_image_filter_conf_t *conf;
1168
+
1169
+ conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_image_filter_conf_t));
1170
+ if (conf == NULL) {
1171
+ return NULL;
1172
+ }
1173
+
1174
+ conf->filter = NGX_CONF_UNSET_UINT;
1175
+ conf->jpeg_quality = NGX_CONF_UNSET_UINT;
1176
+ conf->sharpen = NGX_CONF_UNSET_UINT;
1177
+ conf->angle = NGX_CONF_UNSET_UINT;
1178
+ conf->transparency = NGX_CONF_UNSET;
1179
+ conf->buffer_size = NGX_CONF_UNSET_SIZE;
1180
+
1181
+ return conf;
1182
+ }
1183
+
1184
+
1185
+ static char *
1186
+ ngx_http_image_filter_merge_conf(ngx_conf_t *cf, void *parent, void *child)
1187
+ {
1188
+ ngx_http_image_filter_conf_t *prev = parent;
1189
+ ngx_http_image_filter_conf_t *conf = child;
1190
+
1191
+ if (conf->filter == NGX_CONF_UNSET_UINT) {
1192
+
1193
+ if (prev->filter == NGX_CONF_UNSET_UINT) {
1194
+ conf->filter = NGX_HTTP_IMAGE_OFF;
1195
+
1196
+ } else {
1197
+ conf->filter = prev->filter;
1198
+ conf->width = prev->width;
1199
+ conf->height = prev->height;
1200
+ conf->wcv = prev->wcv;
1201
+ conf->hcv = prev->hcv;
1202
+ }
1203
+ }
1204
+
1205
+ /* 75 is libjpeg default quality */
1206
+ ngx_conf_merge_uint_value(conf->jpeg_quality, prev->jpeg_quality, 75);
1207
+
1208
+ if (conf->jqcv == NULL) {
1209
+ conf->jqcv = prev->jqcv;
1210
+ }
1211
+
1212
+ ngx_conf_merge_uint_value(conf->sharpen, prev->sharpen, 0);
1213
+
1214
+ if (conf->shcv == NULL) {
1215
+ conf->shcv = prev->shcv;
1216
+ }
1217
+
1218
+ ngx_conf_merge_uint_value(conf->angle, prev->angle, 0);
1219
+ if (conf->acv == NULL) {
1220
+ conf->acv = prev->acv;
1221
+ }
1222
+
1223
+ ngx_conf_merge_value(conf->transparency, prev->transparency, 1);
1224
+
1225
+ ngx_conf_merge_size_value(conf->buffer_size, prev->buffer_size,
1226
+ 1 * 1024 * 1024);
1227
+
1228
+ return NGX_CONF_OK;
1229
+ }
1230
+
1231
+
1232
+ static char *
1233
+ ngx_http_image_filter(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
1234
+ {
1235
+ ngx_http_image_filter_conf_t *imcf = conf;
1236
+
1237
+ ngx_str_t *value;
1238
+ ngx_int_t n;
1239
+ ngx_uint_t i;
1240
+ ngx_http_complex_value_t cv;
1241
+ ngx_http_compile_complex_value_t ccv;
1242
+
1243
+ value = cf->args->elts;
1244
+
1245
+ i = 1;
1246
+
1247
+ if (cf->args->nelts == 2) {
1248
+ if (ngx_strcmp(value[i].data, "off") == 0) {
1249
+ imcf->filter = NGX_HTTP_IMAGE_OFF;
1250
+
1251
+ } else if (ngx_strcmp(value[i].data, "test") == 0) {
1252
+ imcf->filter = NGX_HTTP_IMAGE_TEST;
1253
+
1254
+ } else if (ngx_strcmp(value[i].data, "size") == 0) {
1255
+ imcf->filter = NGX_HTTP_IMAGE_SIZE;
1256
+
1257
+ } else {
1258
+ goto failed;
1259
+ }
1260
+
1261
+ return NGX_CONF_OK;
1262
+
1263
+ } else if (cf->args->nelts == 3) {
1264
+
1265
+ if (ngx_strcmp(value[i].data, "rotate") == 0) {
1266
+ if (imcf->filter != NGX_HTTP_IMAGE_RESIZE
1267
+ && imcf->filter != NGX_HTTP_IMAGE_CROP)
1268
+ {
1269
+ imcf->filter = NGX_HTTP_IMAGE_ROTATE;
1270
+ }
1271
+
1272
+ ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
1273
+
1274
+ ccv.cf = cf;
1275
+ ccv.value = &value[++i];
1276
+ ccv.complex_value = &cv;
1277
+
1278
+ if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
1279
+ return NGX_CONF_ERROR;
1280
+ }
1281
+
1282
+ if (cv.lengths == NULL) {
1283
+ n = ngx_http_image_filter_value(&value[i]);
1284
+
1285
+ if (n != 90 && n != 180 && n != 270) {
1286
+ goto failed;
1287
+ }
1288
+
1289
+ imcf->angle = (ngx_uint_t) n;
1290
+
1291
+ } else {
1292
+ imcf->acv = ngx_palloc(cf->pool,
1293
+ sizeof(ngx_http_complex_value_t));
1294
+ if (imcf->acv == NULL) {
1295
+ return NGX_CONF_ERROR;
1296
+ }
1297
+
1298
+ *imcf->acv = cv;
1299
+ }
1300
+
1301
+ return NGX_CONF_OK;
1302
+
1303
+ } else {
1304
+ goto failed;
1305
+ }
1306
+ }
1307
+
1308
+ if (ngx_strcmp(value[i].data, "resize") == 0) {
1309
+ imcf->filter = NGX_HTTP_IMAGE_RESIZE;
1310
+
1311
+ } else if (ngx_strcmp(value[i].data, "crop") == 0) {
1312
+ imcf->filter = NGX_HTTP_IMAGE_CROP;
1313
+
1314
+ } else {
1315
+ goto failed;
1316
+ }
1317
+
1318
+ ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
1319
+
1320
+ ccv.cf = cf;
1321
+ ccv.value = &value[++i];
1322
+ ccv.complex_value = &cv;
1323
+
1324
+ if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
1325
+ return NGX_CONF_ERROR;
1326
+ }
1327
+
1328
+ if (cv.lengths == NULL) {
1329
+ n = ngx_http_image_filter_value(&value[i]);
1330
+
1331
+ if (n == 0) {
1332
+ goto failed;
1333
+ }
1334
+
1335
+ imcf->width = (ngx_uint_t) n;
1336
+
1337
+ } else {
1338
+ imcf->wcv = ngx_palloc(cf->pool, sizeof(ngx_http_complex_value_t));
1339
+ if (imcf->wcv == NULL) {
1340
+ return NGX_CONF_ERROR;
1341
+ }
1342
+
1343
+ *imcf->wcv = cv;
1344
+ }
1345
+
1346
+ ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
1347
+
1348
+ ccv.cf = cf;
1349
+ ccv.value = &value[++i];
1350
+ ccv.complex_value = &cv;
1351
+
1352
+ if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
1353
+ return NGX_CONF_ERROR;
1354
+ }
1355
+
1356
+ if (cv.lengths == NULL) {
1357
+ n = ngx_http_image_filter_value(&value[i]);
1358
+
1359
+ if (n == 0) {
1360
+ goto failed;
1361
+ }
1362
+
1363
+ imcf->height = (ngx_uint_t) n;
1364
+
1365
+ } else {
1366
+ imcf->hcv = ngx_palloc(cf->pool, sizeof(ngx_http_complex_value_t));
1367
+ if (imcf->hcv == NULL) {
1368
+ return NGX_CONF_ERROR;
1369
+ }
1370
+
1371
+ *imcf->hcv = cv;
1372
+ }
1373
+
1374
+ return NGX_CONF_OK;
1375
+
1376
+ failed:
1377
+
1378
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid parameter \"%V\"",
1379
+ &value[i]);
1380
+
1381
+ return NGX_CONF_ERROR;
1382
+ }
1383
+
1384
+
1385
+ static char *
1386
+ ngx_http_image_filter_jpeg_quality(ngx_conf_t *cf, ngx_command_t *cmd,
1387
+ void *conf)
1388
+ {
1389
+ ngx_http_image_filter_conf_t *imcf = conf;
1390
+
1391
+ ngx_str_t *value;
1392
+ ngx_int_t n;
1393
+ ngx_http_complex_value_t cv;
1394
+ ngx_http_compile_complex_value_t ccv;
1395
+
1396
+ value = cf->args->elts;
1397
+
1398
+ ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
1399
+
1400
+ ccv.cf = cf;
1401
+ ccv.value = &value[1];
1402
+ ccv.complex_value = &cv;
1403
+
1404
+ if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
1405
+ return NGX_CONF_ERROR;
1406
+ }
1407
+
1408
+ if (cv.lengths == NULL) {
1409
+ n = ngx_http_image_filter_value(&value[1]);
1410
+
1411
+ if (n <= 0) {
1412
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1413
+ "invalid value \"%V\"", &value[1]);
1414
+ return NGX_CONF_ERROR;
1415
+ }
1416
+
1417
+ imcf->jpeg_quality = (ngx_uint_t) n;
1418
+
1419
+ } else {
1420
+ imcf->jqcv = ngx_palloc(cf->pool, sizeof(ngx_http_complex_value_t));
1421
+ if (imcf->jqcv == NULL) {
1422
+ return NGX_CONF_ERROR;
1423
+ }
1424
+
1425
+ *imcf->jqcv = cv;
1426
+ }
1427
+
1428
+ return NGX_CONF_OK;
1429
+ }
1430
+
1431
+
1432
+ static char *
1433
+ ngx_http_image_filter_sharpen(ngx_conf_t *cf, ngx_command_t *cmd,
1434
+ void *conf)
1435
+ {
1436
+ ngx_http_image_filter_conf_t *imcf = conf;
1437
+
1438
+ ngx_str_t *value;
1439
+ ngx_int_t n;
1440
+ ngx_http_complex_value_t cv;
1441
+ ngx_http_compile_complex_value_t ccv;
1442
+
1443
+ value = cf->args->elts;
1444
+
1445
+ ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
1446
+
1447
+ ccv.cf = cf;
1448
+ ccv.value = &value[1];
1449
+ ccv.complex_value = &cv;
1450
+
1451
+ if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
1452
+ return NGX_CONF_ERROR;
1453
+ }
1454
+
1455
+ if (cv.lengths == NULL) {
1456
+ n = ngx_http_image_filter_value(&value[1]);
1457
+
1458
+ if (n < 0) {
1459
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1460
+ "invalid value \"%V\"", &value[1]);
1461
+ return NGX_CONF_ERROR;
1462
+ }
1463
+
1464
+ imcf->sharpen = (ngx_uint_t) n;
1465
+
1466
+ } else {
1467
+ imcf->shcv = ngx_palloc(cf->pool, sizeof(ngx_http_complex_value_t));
1468
+ if (imcf->shcv == NULL) {
1469
+ return NGX_CONF_ERROR;
1470
+ }
1471
+
1472
+ *imcf->shcv = cv;
1473
+ }
1474
+
1475
+ return NGX_CONF_OK;
1476
+ }
1477
+
1478
+
1479
+ static ngx_int_t
1480
+ ngx_http_image_filter_init(ngx_conf_t *cf)
1481
+ {
1482
+ ngx_http_next_header_filter = ngx_http_top_header_filter;
1483
+ ngx_http_top_header_filter = ngx_http_image_header_filter;
1484
+
1485
+ ngx_http_next_body_filter = ngx_http_top_body_filter;
1486
+ ngx_http_top_body_filter = ngx_http_image_body_filter;
1487
+
1488
+ return NGX_OK;
1489
+ }