nginxtra 1.6.3.9 → 1.8.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (181) hide show
  1. checksums.yaml +4 -4
  2. data/bin/nginxtra +1 -1
  3. data/bin/nginxtra_rails +1 -1
  4. data/lib/nginxtra/version.rb +1 -1
  5. data/vendor/nginx/CHANGES +358 -14
  6. data/vendor/nginx/CHANGES.ru +372 -18
  7. data/vendor/nginx/LICENSE +2 -2
  8. data/vendor/nginx/auto/cc/clang +5 -0
  9. data/vendor/nginx/auto/cc/gcc +5 -0
  10. data/vendor/nginx/auto/lib/google-perftools/conf +1 -1
  11. data/vendor/nginx/auto/lib/openssl/make +0 -5
  12. data/vendor/nginx/auto/lib/perl/conf +9 -1
  13. data/vendor/nginx/auto/make +1 -1
  14. data/vendor/nginx/auto/modules +11 -0
  15. data/vendor/nginx/auto/options +10 -2
  16. data/vendor/nginx/auto/os/darwin +0 -1
  17. data/vendor/nginx/auto/os/freebsd +6 -23
  18. data/vendor/nginx/auto/sources +16 -14
  19. data/vendor/nginx/auto/summary +3 -24
  20. data/vendor/nginx/auto/threads +20 -0
  21. data/vendor/nginx/auto/types/sizeof +2 -12
  22. data/vendor/nginx/auto/unix +50 -6
  23. data/vendor/nginx/configure +5 -0
  24. data/vendor/nginx/contrib/vim/syntax/nginx.vim +183 -50
  25. data/vendor/nginx/src/core/nginx.c +21 -9
  26. data/vendor/nginx/src/core/nginx.h +8 -2
  27. data/vendor/nginx/src/core/ngx_buf.c +88 -0
  28. data/vendor/nginx/src/core/ngx_buf.h +15 -1
  29. data/vendor/nginx/src/core/ngx_conf_file.c +4 -1
  30. data/vendor/nginx/src/core/ngx_connection.c +25 -66
  31. data/vendor/nginx/src/core/ngx_connection.h +1 -3
  32. data/vendor/nginx/src/core/ngx_core.h +11 -3
  33. data/vendor/nginx/src/core/ngx_crypt.c +1 -1
  34. data/vendor/nginx/src/core/ngx_cycle.c +7 -1
  35. data/vendor/nginx/src/core/ngx_cycle.h +6 -2
  36. data/vendor/nginx/src/core/ngx_file.c +13 -5
  37. data/vendor/nginx/src/core/ngx_file.h +6 -0
  38. data/vendor/nginx/src/core/ngx_log.c +215 -21
  39. data/vendor/nginx/src/core/ngx_log.h +9 -1
  40. data/vendor/nginx/src/core/ngx_output_chain.c +104 -15
  41. data/vendor/nginx/src/core/ngx_palloc.c +3 -7
  42. data/vendor/nginx/src/core/ngx_rbtree.c +2 -4
  43. data/vendor/nginx/src/core/ngx_rbtree.h +2 -4
  44. data/vendor/nginx/src/core/ngx_regex.c +14 -6
  45. data/vendor/nginx/src/core/ngx_resolver.c +16 -23
  46. data/vendor/nginx/src/core/ngx_resolver.h +8 -7
  47. data/vendor/nginx/src/core/ngx_shmtx.c +1 -1
  48. data/vendor/nginx/src/core/ngx_slab.c +89 -2
  49. data/vendor/nginx/src/core/ngx_slab.h +3 -0
  50. data/vendor/nginx/src/core/ngx_string.c +58 -2
  51. data/vendor/nginx/src/core/ngx_string.h +1 -0
  52. data/vendor/nginx/src/core/ngx_syslog.c +374 -0
  53. data/vendor/nginx/src/core/ngx_syslog.h +30 -0
  54. data/vendor/nginx/src/core/ngx_thread_pool.c +630 -0
  55. data/vendor/nginx/src/core/ngx_thread_pool.h +36 -0
  56. data/vendor/nginx/src/core/ngx_times.c +19 -2
  57. data/vendor/nginx/src/core/ngx_times.h +1 -0
  58. data/vendor/nginx/src/event/modules/ngx_aio_module.c +1 -1
  59. data/vendor/nginx/src/event/modules/ngx_devpoll_module.c +9 -24
  60. data/vendor/nginx/src/event/modules/ngx_epoll_module.c +152 -28
  61. data/vendor/nginx/src/event/modules/ngx_eventport_module.c +43 -25
  62. data/vendor/nginx/src/event/modules/ngx_kqueue_module.c +86 -156
  63. data/vendor/nginx/src/event/modules/ngx_poll_module.c +21 -37
  64. data/vendor/nginx/src/event/modules/ngx_rtsig_module.c +15 -27
  65. data/vendor/nginx/src/event/modules/ngx_select_module.c +10 -12
  66. data/vendor/nginx/src/event/modules/ngx_win32_select_module.c +7 -9
  67. data/vendor/nginx/src/event/ngx_event.c +5 -33
  68. data/vendor/nginx/src/event/ngx_event.h +15 -50
  69. data/vendor/nginx/src/event/ngx_event_accept.c +11 -10
  70. data/vendor/nginx/src/event/ngx_event_connect.c +0 -11
  71. data/vendor/nginx/src/event/ngx_event_connect.h +1 -4
  72. data/vendor/nginx/src/event/ngx_event_openssl.c +622 -38
  73. data/vendor/nginx/src/event/ngx_event_openssl.h +20 -2
  74. data/vendor/nginx/src/event/ngx_event_openssl_stapling.c +5 -1
  75. data/vendor/nginx/src/event/ngx_event_pipe.c +45 -19
  76. data/vendor/nginx/src/event/ngx_event_pipe.h +3 -0
  77. data/vendor/nginx/src/event/ngx_event_posted.c +7 -145
  78. data/vendor/nginx/src/event/ngx_event_posted.h +12 -39
  79. data/vendor/nginx/src/event/ngx_event_timer.c +50 -70
  80. data/vendor/nginx/src/event/ngx_event_timer.h +2 -14
  81. data/vendor/nginx/src/http/modules/ngx_http_addition_filter_module.c +1 -1
  82. data/vendor/nginx/src/http/modules/ngx_http_autoindex_module.c +416 -71
  83. data/vendor/nginx/src/http/modules/ngx_http_charset_filter_module.c +19 -15
  84. data/vendor/nginx/src/http/modules/ngx_http_dav_module.c +16 -4
  85. data/vendor/nginx/src/http/modules/ngx_http_fastcgi_module.c +601 -134
  86. data/vendor/nginx/src/http/modules/ngx_http_geo_module.c +1 -1
  87. data/vendor/nginx/src/http/modules/ngx_http_geoip_module.c +9 -3
  88. data/vendor/nginx/src/http/modules/ngx_http_gunzip_filter_module.c +9 -3
  89. data/vendor/nginx/src/http/modules/ngx_http_gzip_filter_module.c +9 -3
  90. data/vendor/nginx/src/http/modules/ngx_http_gzip_static_module.c +0 -2
  91. data/vendor/nginx/src/http/modules/ngx_http_headers_filter_module.c +197 -91
  92. data/vendor/nginx/src/http/modules/ngx_http_image_filter_module.c +1 -0
  93. data/vendor/nginx/src/http/modules/ngx_http_limit_conn_module.c +65 -162
  94. data/vendor/nginx/src/http/modules/ngx_http_limit_req_module.c +53 -67
  95. data/vendor/nginx/src/http/modules/ngx_http_log_module.c +128 -23
  96. data/vendor/nginx/src/http/modules/ngx_http_memcached_module.c +25 -6
  97. data/vendor/nginx/src/http/modules/ngx_http_mp4_module.c +1 -1
  98. data/vendor/nginx/src/http/modules/ngx_http_not_modified_filter_module.c +39 -13
  99. data/vendor/nginx/src/http/modules/ngx_http_proxy_module.c +697 -141
  100. data/vendor/nginx/src/http/modules/ngx_http_rewrite_module.c +5 -1
  101. data/vendor/nginx/src/http/modules/ngx_http_scgi_module.c +282 -125
  102. data/vendor/nginx/src/http/modules/ngx_http_ssi_filter_module.c +4 -1
  103. data/vendor/nginx/src/http/modules/ngx_http_ssl_module.c +44 -1
  104. data/vendor/nginx/src/http/modules/ngx_http_ssl_module.h +2 -0
  105. data/vendor/nginx/src/http/modules/ngx_http_stub_status_module.c +10 -8
  106. data/vendor/nginx/src/http/modules/ngx_http_sub_filter_module.c +18 -3
  107. data/vendor/nginx/src/http/modules/ngx_http_upstream_hash_module.c +641 -0
  108. data/vendor/nginx/src/http/modules/ngx_http_upstream_ip_hash_module.c +1 -1
  109. data/vendor/nginx/src/http/modules/ngx_http_upstream_keepalive_module.c +3 -21
  110. data/vendor/nginx/src/http/modules/ngx_http_upstream_least_conn_module.c +0 -5
  111. data/vendor/nginx/src/http/modules/ngx_http_uwsgi_module.c +449 -125
  112. data/vendor/nginx/src/http/modules/ngx_http_xslt_filter_module.c +4 -2
  113. data/vendor/nginx/src/http/modules/perl/ngx_http_perl_module.c +2 -1
  114. data/vendor/nginx/src/http/ngx_http.c +10 -5
  115. data/vendor/nginx/src/http/ngx_http.h +4 -4
  116. data/vendor/nginx/src/http/ngx_http_cache.h +26 -1
  117. data/vendor/nginx/src/http/ngx_http_copy_filter_module.c +109 -68
  118. data/vendor/nginx/src/http/ngx_http_core_module.c +191 -46
  119. data/vendor/nginx/src/http/ngx_http_core_module.h +16 -4
  120. data/vendor/nginx/src/http/ngx_http_file_cache.c +584 -67
  121. data/vendor/nginx/src/http/ngx_http_parse.c +55 -4
  122. data/vendor/nginx/src/http/ngx_http_request.c +14 -6
  123. data/vendor/nginx/src/http/ngx_http_request.h +12 -4
  124. data/vendor/nginx/src/http/ngx_http_request_body.c +114 -28
  125. data/vendor/nginx/src/http/ngx_http_spdy.c +383 -229
  126. data/vendor/nginx/src/http/ngx_http_spdy.h +8 -5
  127. data/vendor/nginx/src/http/ngx_http_spdy_filter_module.c +12 -4
  128. data/vendor/nginx/src/http/ngx_http_special_response.c +2 -2
  129. data/vendor/nginx/src/http/ngx_http_upstream.c +808 -132
  130. data/vendor/nginx/src/http/ngx_http_upstream.h +33 -3
  131. data/vendor/nginx/src/http/ngx_http_upstream_round_robin.c +72 -65
  132. data/vendor/nginx/src/http/ngx_http_upstream_round_robin.h +1 -2
  133. data/vendor/nginx/src/http/ngx_http_variables.c +47 -3
  134. data/vendor/nginx/src/http/ngx_http_write_filter_module.c +15 -6
  135. data/vendor/nginx/src/mail/ngx_mail.c +2 -3
  136. data/vendor/nginx/src/mail/ngx_mail.h +2 -0
  137. data/vendor/nginx/src/mail/ngx_mail_auth_http_module.c +140 -11
  138. data/vendor/nginx/src/mail/ngx_mail_core_module.c +3 -3
  139. data/vendor/nginx/src/mail/ngx_mail_handler.c +79 -2
  140. data/vendor/nginx/src/mail/ngx_mail_imap_module.c +3 -1
  141. data/vendor/nginx/src/mail/ngx_mail_pop3_module.c +3 -1
  142. data/vendor/nginx/src/mail/ngx_mail_smtp_module.c +3 -1
  143. data/vendor/nginx/src/mail/ngx_mail_ssl_module.c +125 -1
  144. data/vendor/nginx/src/mail/ngx_mail_ssl_module.h +8 -0
  145. data/vendor/nginx/src/misc/ngx_cpp_test_module.cpp +1 -1
  146. data/vendor/nginx/src/os/unix/ngx_aio_read_chain.c +1 -1
  147. data/vendor/nginx/src/os/unix/ngx_channel.c +0 -7
  148. data/vendor/nginx/src/os/unix/ngx_darwin_config.h +0 -3
  149. data/vendor/nginx/src/os/unix/ngx_darwin_sendfile_chain.c +44 -208
  150. data/vendor/nginx/src/os/unix/ngx_file_aio_read.c +25 -17
  151. data/vendor/nginx/src/os/unix/ngx_files.c +109 -0
  152. data/vendor/nginx/src/os/unix/ngx_files.h +6 -0
  153. data/vendor/nginx/src/os/unix/ngx_freebsd_config.h +0 -6
  154. data/vendor/nginx/src/os/unix/ngx_freebsd_sendfile_chain.c +78 -206
  155. data/vendor/nginx/src/os/unix/ngx_linux_aio_read.c +25 -14
  156. data/vendor/nginx/src/os/unix/ngx_linux_config.h +4 -1
  157. data/vendor/nginx/src/os/unix/ngx_linux_sendfile_chain.c +235 -194
  158. data/vendor/nginx/src/os/unix/ngx_os.h +25 -3
  159. data/vendor/nginx/src/os/unix/ngx_posix_init.c +4 -2
  160. data/vendor/nginx/src/os/unix/ngx_process_cycle.c +13 -195
  161. data/vendor/nginx/src/os/unix/ngx_process_cycle.h +0 -1
  162. data/vendor/nginx/src/os/unix/ngx_readv_chain.c +27 -108
  163. data/vendor/nginx/src/os/unix/ngx_setproctitle.h +2 -2
  164. data/vendor/nginx/src/os/unix/ngx_solaris_sendfilev_chain.c +12 -67
  165. data/vendor/nginx/src/os/unix/ngx_thread.h +26 -83
  166. data/vendor/nginx/src/os/unix/ngx_thread_cond.c +87 -0
  167. data/vendor/nginx/src/os/unix/ngx_thread_id.c +70 -0
  168. data/vendor/nginx/src/os/unix/ngx_thread_mutex.c +174 -0
  169. data/vendor/nginx/src/os/unix/ngx_user.c +2 -20
  170. data/vendor/nginx/src/os/unix/ngx_writev_chain.c +129 -98
  171. metadata +16 -17
  172. data/vendor/nginx/auto/lib/zlib/patch.zlib.h +0 -10
  173. data/vendor/nginx/src/event/ngx_event_busy_lock.c +0 -286
  174. data/vendor/nginx/src/event/ngx_event_busy_lock.h +0 -65
  175. data/vendor/nginx/src/event/ngx_event_mutex.c +0 -70
  176. data/vendor/nginx/src/http/ngx_http_busy_lock.c +0 -307
  177. data/vendor/nginx/src/http/ngx_http_busy_lock.h +0 -54
  178. data/vendor/nginx/src/os/unix/ngx_freebsd_rfork_thread.c +0 -756
  179. data/vendor/nginx/src/os/unix/ngx_freebsd_rfork_thread.h +0 -122
  180. data/vendor/nginx/src/os/unix/ngx_pthread_thread.c +0 -278
  181. data/vendor/nginx/src/os/unix/rfork_thread.S +0 -73
@@ -51,12 +51,16 @@ typedef void (*ngx_resolver_handler_pt)(ngx_resolver_ctx_t *ctx);
51
51
 
52
52
 
53
53
  typedef struct {
54
- ngx_rbtree_node_t node;
55
- ngx_queue_t queue;
56
-
57
54
  /* PTR: resolved name, A: name to resolve */
58
55
  u_char *name;
59
56
 
57
+ ngx_queue_t queue;
58
+
59
+ /* event ident must be after 3 pointers as in ngx_connection_t */
60
+ ngx_int_t ident;
61
+
62
+ ngx_rbtree_node_t node;
63
+
60
64
  #if (NGX_HAVE_INET6)
61
65
  /* PTR: IPv6 address to resolve (IPv4 address is in rbtree node key) */
62
66
  struct in6_addr addr6;
@@ -103,7 +107,7 @@ typedef struct {
103
107
  void *dummy;
104
108
  ngx_log_t *log;
105
109
 
106
- /* ident must be after 3 pointers */
110
+ /* event ident must be after 3 pointers as in ngx_connection_t */
107
111
  ngx_int_t ident;
108
112
 
109
113
  /* simple round robin DNS peers balancer */
@@ -143,9 +147,6 @@ struct ngx_resolver_ctx_s {
143
147
  ngx_resolver_t *resolver;
144
148
  ngx_udp_connection_t *udp_connection;
145
149
 
146
- /* ident must be after 3 pointers */
147
- ngx_int_t ident;
148
-
149
150
  ngx_int_t state;
150
151
  ngx_str_t name;
151
152
 
@@ -259,7 +259,7 @@ ngx_shmtx_trylock(ngx_shmtx_t *mtx)
259
259
 
260
260
  #if __osf__ /* Tru64 UNIX */
261
261
 
262
- if (err == NGX_EACCESS) {
262
+ if (err == NGX_EACCES) {
263
263
  return 0;
264
264
  }
265
265
 
@@ -129,6 +129,8 @@ ngx_slab_init(ngx_slab_pool_t *pool)
129
129
  pool->pages->slab = pages;
130
130
  }
131
131
 
132
+ pool->last = pool->pages + pages;
133
+
132
134
  pool->log_nomem = 1;
133
135
  pool->log_ctx = &pool->zero;
134
136
  pool->zero = '\0';
@@ -158,7 +160,7 @@ ngx_slab_alloc_locked(ngx_slab_pool_t *pool, size_t size)
158
160
  ngx_uint_t i, slot, shift, map;
159
161
  ngx_slab_page_t *page, *prev, *slots;
160
162
 
161
- if (size >= ngx_slab_max_size) {
163
+ if (size > ngx_slab_max_size) {
162
164
 
163
165
  ngx_log_debug1(NGX_LOG_DEBUG_ALLOC, ngx_cycle->log, 0,
164
166
  "slab alloc: %uz", size);
@@ -396,6 +398,35 @@ done:
396
398
  }
397
399
 
398
400
 
401
+ void *
402
+ ngx_slab_calloc(ngx_slab_pool_t *pool, size_t size)
403
+ {
404
+ void *p;
405
+
406
+ ngx_shmtx_lock(&pool->mutex);
407
+
408
+ p = ngx_slab_calloc_locked(pool, size);
409
+
410
+ ngx_shmtx_unlock(&pool->mutex);
411
+
412
+ return p;
413
+ }
414
+
415
+
416
+ void *
417
+ ngx_slab_calloc_locked(ngx_slab_pool_t *pool, size_t size)
418
+ {
419
+ void *p;
420
+
421
+ p = ngx_slab_alloc_locked(pool, size);
422
+ if (p) {
423
+ ngx_memzero(p, size);
424
+ }
425
+
426
+ return p;
427
+ }
428
+
429
+
399
430
  void
400
431
  ngx_slab_free(ngx_slab_pool_t *pool, void *p)
401
432
  {
@@ -626,6 +657,8 @@ ngx_slab_alloc_pages(ngx_slab_pool_t *pool, ngx_uint_t pages)
626
657
  if (page->slab >= pages) {
627
658
 
628
659
  if (page->slab > pages) {
660
+ page[page->slab - 1].prev = (uintptr_t) &page[pages];
661
+
629
662
  page[pages].slab = page->slab - pages;
630
663
  page[pages].next = page->next;
631
664
  page[pages].prev = page->prev;
@@ -672,7 +705,8 @@ static void
672
705
  ngx_slab_free_pages(ngx_slab_pool_t *pool, ngx_slab_page_t *page,
673
706
  ngx_uint_t pages)
674
707
  {
675
- ngx_slab_page_t *prev;
708
+ ngx_uint_t type;
709
+ ngx_slab_page_t *prev, *join;
676
710
 
677
711
  page->slab = pages--;
678
712
 
@@ -686,6 +720,59 @@ ngx_slab_free_pages(ngx_slab_pool_t *pool, ngx_slab_page_t *page,
686
720
  page->next->prev = page->prev;
687
721
  }
688
722
 
723
+ join = page + page->slab;
724
+
725
+ if (join < pool->last) {
726
+ type = join->prev & NGX_SLAB_PAGE_MASK;
727
+
728
+ if (type == NGX_SLAB_PAGE) {
729
+
730
+ if (join->next != NULL) {
731
+ pages += join->slab;
732
+ page->slab += join->slab;
733
+
734
+ prev = (ngx_slab_page_t *) (join->prev & ~NGX_SLAB_PAGE_MASK);
735
+ prev->next = join->next;
736
+ join->next->prev = join->prev;
737
+
738
+ join->slab = NGX_SLAB_PAGE_FREE;
739
+ join->next = NULL;
740
+ join->prev = NGX_SLAB_PAGE;
741
+ }
742
+ }
743
+ }
744
+
745
+ if (page > pool->pages) {
746
+ join = page - 1;
747
+ type = join->prev & NGX_SLAB_PAGE_MASK;
748
+
749
+ if (type == NGX_SLAB_PAGE) {
750
+
751
+ if (join->slab == NGX_SLAB_PAGE_FREE) {
752
+ join = (ngx_slab_page_t *) (join->prev & ~NGX_SLAB_PAGE_MASK);
753
+ }
754
+
755
+ if (join->next != NULL) {
756
+ pages += join->slab;
757
+ join->slab += page->slab;
758
+
759
+ prev = (ngx_slab_page_t *) (join->prev & ~NGX_SLAB_PAGE_MASK);
760
+ prev->next = join->next;
761
+ join->next->prev = join->prev;
762
+
763
+ page->slab = NGX_SLAB_PAGE_FREE;
764
+ page->next = NULL;
765
+ page->prev = NGX_SLAB_PAGE;
766
+
767
+ page = join;
768
+ }
769
+ }
770
+ }
771
+
772
+ if (pages) {
773
+ page[pages].prev = (uintptr_t) page;
774
+ }
775
+
689
776
  page->prev = (uintptr_t) &pool->free;
690
777
  page->next = pool->free.next;
691
778
 
@@ -29,6 +29,7 @@ typedef struct {
29
29
  size_t min_shift;
30
30
 
31
31
  ngx_slab_page_t *pages;
32
+ ngx_slab_page_t *last;
32
33
  ngx_slab_page_t free;
33
34
 
34
35
  u_char *start;
@@ -49,6 +50,8 @@ typedef struct {
49
50
  void ngx_slab_init(ngx_slab_pool_t *pool);
50
51
  void *ngx_slab_alloc(ngx_slab_pool_t *pool, size_t size);
51
52
  void *ngx_slab_alloc_locked(ngx_slab_pool_t *pool, size_t size);
53
+ void *ngx_slab_calloc(ngx_slab_pool_t *pool, size_t size);
54
+ void *ngx_slab_calloc_locked(ngx_slab_pool_t *pool, size_t size);
52
55
  void ngx_slab_free(ngx_slab_pool_t *pool, void *p);
53
56
  void ngx_slab_free_locked(ngx_slab_pool_t *pool, void *p);
54
57
 
@@ -429,8 +429,12 @@ ngx_vslprintf(u_char *buf, u_char *last, const char *fmt, va_list args)
429
429
  case 'N':
430
430
  #if (NGX_WIN32)
431
431
  *buf++ = CR;
432
- #endif
432
+ if (buf < last) {
433
+ *buf++ = LF;
434
+ }
435
+ #else
433
436
  *buf++ = LF;
437
+ #endif
434
438
  fmt++;
435
439
 
436
440
  continue;
@@ -1422,7 +1426,7 @@ ngx_escape_uri(u_char *dst, u_char *src, size_t size, ngx_uint_t type)
1422
1426
  {
1423
1427
  ngx_uint_t n;
1424
1428
  uint32_t *escape;
1425
- static u_char hex[] = "0123456789abcdef";
1429
+ static u_char hex[] = "0123456789ABCDEF";
1426
1430
 
1427
1431
  /* " ", "#", "%", "?", %00-%1F, %7F-%FF */
1428
1432
 
@@ -1788,6 +1792,58 @@ ngx_escape_html(u_char *dst, u_char *src, size_t size)
1788
1792
  }
1789
1793
 
1790
1794
 
1795
+ uintptr_t
1796
+ ngx_escape_json(u_char *dst, u_char *src, size_t size)
1797
+ {
1798
+ u_char ch;
1799
+ ngx_uint_t len;
1800
+
1801
+ if (dst == NULL) {
1802
+ len = 0;
1803
+
1804
+ while (size) {
1805
+ ch = *src++;
1806
+
1807
+ if (ch == '\\' || ch == '"') {
1808
+ len++;
1809
+
1810
+ } else if (ch <= 0x1f) {
1811
+ len += sizeof("\\u001F") - 2;
1812
+ }
1813
+
1814
+ size--;
1815
+ }
1816
+
1817
+ return (uintptr_t) len;
1818
+ }
1819
+
1820
+ while (size) {
1821
+ ch = *src++;
1822
+
1823
+ if (ch > 0x1f) {
1824
+
1825
+ if (ch == '\\' || ch == '"') {
1826
+ *dst++ = '\\';
1827
+ }
1828
+
1829
+ *dst++ = ch;
1830
+
1831
+ } else {
1832
+ *dst++ = '\\'; *dst++ = 'u'; *dst++ = '0'; *dst++ = '0';
1833
+ *dst++ = '0' + (ch >> 4);
1834
+
1835
+ ch &= 0xf;
1836
+
1837
+ *dst++ = (ch < 10) ? ('0' + ch) : ('A' + ch - 10);
1838
+ }
1839
+
1840
+ size--;
1841
+ }
1842
+
1843
+ return (uintptr_t) dst;
1844
+ }
1845
+
1846
+
1791
1847
  void
1792
1848
  ngx_str_rbtree_insert_value(ngx_rbtree_node_t *temp,
1793
1849
  ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel)
@@ -207,6 +207,7 @@ uintptr_t ngx_escape_uri(u_char *dst, u_char *src, size_t size,
207
207
  ngx_uint_t type);
208
208
  void ngx_unescape_uri(u_char **dst, u_char **src, size_t size, ngx_uint_t type);
209
209
  uintptr_t ngx_escape_html(u_char *dst, u_char *src, size_t size);
210
+ uintptr_t ngx_escape_json(u_char *dst, u_char *src, size_t size);
210
211
 
211
212
 
212
213
  typedef struct {
@@ -0,0 +1,374 @@
1
+
2
+ /*
3
+ * Copyright (C) Nginx, Inc.
4
+ */
5
+
6
+
7
+ #include <ngx_config.h>
8
+ #include <ngx_core.h>
9
+ #include <ngx_event.h>
10
+
11
+
12
+ #define NGX_SYSLOG_MAX_STR \
13
+ NGX_MAX_ERROR_STR + sizeof("<255>Jan 01 00:00:00 ") - 1 \
14
+ + (NGX_MAXHOSTNAMELEN - 1) + 1 /* space */ \
15
+ + 32 /* tag */ + 2 /* colon, space */
16
+
17
+
18
+ static char *ngx_syslog_parse_args(ngx_conf_t *cf, ngx_syslog_peer_t *peer);
19
+ static ngx_int_t ngx_syslog_init_peer(ngx_syslog_peer_t *peer);
20
+ static void ngx_syslog_cleanup(void *data);
21
+
22
+
23
+ static char *facilities[] = {
24
+ "kern", "user", "mail", "daemon", "auth", "intern", "lpr", "news", "uucp",
25
+ "clock", "authpriv", "ftp", "ntp", "audit", "alert", "cron", "local0",
26
+ "local1", "local2", "local3", "local4", "local5", "local6", "local7",
27
+ NULL
28
+ };
29
+
30
+ /* note 'error/warn' like in nginx.conf, not 'err/warning' */
31
+ static char *severities[] = {
32
+ "emerg", "alert", "crit", "error", "warn", "notice", "info", "debug", NULL
33
+ };
34
+
35
+ static ngx_log_t ngx_syslog_dummy_log;
36
+ static ngx_event_t ngx_syslog_dummy_event;
37
+
38
+
39
+ char *
40
+ ngx_syslog_process_conf(ngx_conf_t *cf, ngx_syslog_peer_t *peer)
41
+ {
42
+ peer->pool = cf->pool;
43
+ peer->facility = NGX_CONF_UNSET_UINT;
44
+ peer->severity = NGX_CONF_UNSET_UINT;
45
+
46
+ if (ngx_syslog_parse_args(cf, peer) != NGX_CONF_OK) {
47
+ return NGX_CONF_ERROR;
48
+ }
49
+
50
+ if (peer->server.sockaddr == NULL) {
51
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
52
+ "no syslog server specified");
53
+ return NGX_CONF_ERROR;
54
+ }
55
+
56
+ if (peer->facility == NGX_CONF_UNSET_UINT) {
57
+ peer->facility = 23; /* local7 */
58
+ }
59
+
60
+ if (peer->severity == NGX_CONF_UNSET_UINT) {
61
+ peer->severity = 6; /* info */
62
+ }
63
+
64
+ if (peer->tag.data == NULL) {
65
+ ngx_str_set(&peer->tag, "nginx");
66
+ }
67
+
68
+ peer->conn.fd = (ngx_socket_t) -1;
69
+
70
+ return NGX_CONF_OK;
71
+ }
72
+
73
+
74
+ static char *
75
+ ngx_syslog_parse_args(ngx_conf_t *cf, ngx_syslog_peer_t *peer)
76
+ {
77
+ u_char *p, *comma, c;
78
+ size_t len;
79
+ ngx_str_t *value;
80
+ ngx_url_t u;
81
+ ngx_uint_t i;
82
+
83
+ value = cf->args->elts;
84
+
85
+ p = value[1].data + sizeof("syslog:") - 1;
86
+
87
+ for ( ;; ) {
88
+ comma = (u_char *) ngx_strchr(p, ',');
89
+
90
+ if (comma != NULL) {
91
+ len = comma - p;
92
+ *comma = '\0';
93
+
94
+ } else {
95
+ len = value[1].data + value[1].len - p;
96
+ }
97
+
98
+ if (ngx_strncmp(p, "server=", 7) == 0) {
99
+
100
+ if (peer->server.sockaddr != NULL) {
101
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
102
+ "duplicate syslog \"server\"");
103
+ return NGX_CONF_ERROR;
104
+ }
105
+
106
+ ngx_memzero(&u, sizeof(ngx_url_t));
107
+
108
+ u.url.data = p + 7;
109
+ u.url.len = len - 7;
110
+ u.default_port = 514;
111
+
112
+ if (ngx_parse_url(cf->pool, &u) != NGX_OK) {
113
+ if (u.err) {
114
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
115
+ "%s in syslog server \"%V\"",
116
+ u.err, &u.url);
117
+ }
118
+
119
+ return NGX_CONF_ERROR;
120
+ }
121
+
122
+ peer->server = u.addrs[0];
123
+
124
+ } else if (ngx_strncmp(p, "facility=", 9) == 0) {
125
+
126
+ if (peer->facility != NGX_CONF_UNSET_UINT) {
127
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
128
+ "duplicate syslog \"facility\"");
129
+ return NGX_CONF_ERROR;
130
+ }
131
+
132
+ for (i = 0; facilities[i] != NULL; i++) {
133
+
134
+ if (ngx_strcmp(p + 9, facilities[i]) == 0) {
135
+ peer->facility = i;
136
+ goto next;
137
+ }
138
+ }
139
+
140
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
141
+ "unknown syslog facility \"%s\"", p + 9);
142
+ return NGX_CONF_ERROR;
143
+
144
+ } else if (ngx_strncmp(p, "severity=", 9) == 0) {
145
+
146
+ if (peer->severity != NGX_CONF_UNSET_UINT) {
147
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
148
+ "duplicate syslog \"severity\"");
149
+ return NGX_CONF_ERROR;
150
+ }
151
+
152
+ for (i = 0; severities[i] != NULL; i++) {
153
+
154
+ if (ngx_strcmp(p + 9, severities[i]) == 0) {
155
+ peer->severity = i;
156
+ goto next;
157
+ }
158
+ }
159
+
160
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
161
+ "unknown syslog severity \"%s\"", p + 9);
162
+ return NGX_CONF_ERROR;
163
+
164
+ } else if (ngx_strncmp(p, "tag=", 4) == 0) {
165
+
166
+ if (peer->tag.data != NULL) {
167
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
168
+ "duplicate syslog \"tag\"");
169
+ return NGX_CONF_ERROR;
170
+ }
171
+
172
+ /*
173
+ * RFC 3164: the TAG is a string of ABNF alphanumeric characters
174
+ * that MUST NOT exceed 32 characters.
175
+ */
176
+ if (len - 4 > 32) {
177
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
178
+ "syslog tag length exceeds 32");
179
+ return NGX_CONF_ERROR;
180
+ }
181
+
182
+ for (i = 4; i < len; i++) {
183
+ c = ngx_tolower(p[i]);
184
+
185
+ if (c < '0' || (c > '9' && c < 'a' && c != '_') || c > 'z') {
186
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
187
+ "syslog \"tag\" only allows "
188
+ "alphanumeric characters "
189
+ "and underscore");
190
+ return NGX_CONF_ERROR;
191
+ }
192
+ }
193
+
194
+ peer->tag.data = p + 4;
195
+ peer->tag.len = len - 4;
196
+
197
+ } else {
198
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
199
+ "unknown syslog parameter \"%s\"", p);
200
+ return NGX_CONF_ERROR;
201
+ }
202
+
203
+ next:
204
+
205
+ if (comma == NULL) {
206
+ break;
207
+ }
208
+
209
+ p = comma + 1;
210
+ }
211
+
212
+ return NGX_CONF_OK;
213
+ }
214
+
215
+
216
+ u_char *
217
+ ngx_syslog_add_header(ngx_syslog_peer_t *peer, u_char *buf)
218
+ {
219
+ ngx_uint_t pri;
220
+
221
+ pri = peer->facility * 8 + peer->severity;
222
+
223
+ return ngx_sprintf(buf, "<%ui>%V %V %V: ", pri, &ngx_cached_syslog_time,
224
+ &ngx_cycle->hostname, &peer->tag);
225
+ }
226
+
227
+
228
+ void
229
+ ngx_syslog_writer(ngx_log_t *log, ngx_uint_t level, u_char *buf,
230
+ size_t len)
231
+ {
232
+ u_char *p, msg[NGX_SYSLOG_MAX_STR];
233
+ ngx_uint_t head_len;
234
+ ngx_syslog_peer_t *peer;
235
+
236
+ peer = log->wdata;
237
+
238
+ if (peer->busy) {
239
+ return;
240
+ }
241
+
242
+ peer->busy = 1;
243
+ peer->severity = level - 1;
244
+
245
+ p = ngx_syslog_add_header(peer, msg);
246
+ head_len = p - msg;
247
+
248
+ len -= NGX_LINEFEED_SIZE;
249
+
250
+ if (len > NGX_SYSLOG_MAX_STR - head_len) {
251
+ len = NGX_SYSLOG_MAX_STR - head_len;
252
+ }
253
+
254
+ p = ngx_snprintf(p, len, "%s", buf);
255
+
256
+ (void) ngx_syslog_send(peer, msg, p - msg);
257
+
258
+ peer->busy = 0;
259
+ }
260
+
261
+
262
+ ssize_t
263
+ ngx_syslog_send(ngx_syslog_peer_t *peer, u_char *buf, size_t len)
264
+ {
265
+ ssize_t n;
266
+
267
+ if (peer->conn.fd == (ngx_socket_t) -1) {
268
+ if (ngx_syslog_init_peer(peer) != NGX_OK) {
269
+ return NGX_ERROR;
270
+ }
271
+ }
272
+
273
+ /* log syslog socket events with valid log */
274
+ peer->conn.log = ngx_cycle->log;
275
+
276
+ if (ngx_send) {
277
+ n = ngx_send(&peer->conn, buf, len);
278
+
279
+ } else {
280
+ /* event module has not yet set ngx_io */
281
+ n = ngx_os_io.send(&peer->conn, buf, len);
282
+ }
283
+
284
+ #if (NGX_HAVE_UNIX_DOMAIN)
285
+
286
+ if (n == NGX_ERROR && peer->server.sockaddr->sa_family == AF_UNIX) {
287
+
288
+ if (ngx_close_socket(peer->conn.fd) == -1) {
289
+ ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_socket_errno,
290
+ ngx_close_socket_n " failed");
291
+ }
292
+
293
+ peer->conn.fd = (ngx_socket_t) -1;
294
+ }
295
+
296
+ #endif
297
+
298
+ return n;
299
+ }
300
+
301
+
302
+ static ngx_int_t
303
+ ngx_syslog_init_peer(ngx_syslog_peer_t *peer)
304
+ {
305
+ ngx_socket_t fd;
306
+ ngx_pool_cleanup_t *cln;
307
+
308
+ peer->conn.read = &ngx_syslog_dummy_event;
309
+ peer->conn.write = &ngx_syslog_dummy_event;
310
+
311
+ ngx_syslog_dummy_event.log = &ngx_syslog_dummy_log;
312
+
313
+ fd = ngx_socket(peer->server.sockaddr->sa_family, SOCK_DGRAM, 0);
314
+ if (fd == (ngx_socket_t) -1) {
315
+ ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_socket_errno,
316
+ ngx_socket_n " failed");
317
+ return NGX_ERROR;
318
+ }
319
+
320
+ if (ngx_nonblocking(fd) == -1) {
321
+ ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_socket_errno,
322
+ ngx_nonblocking_n " failed");
323
+ goto failed;
324
+ }
325
+
326
+ if (connect(fd, peer->server.sockaddr, peer->server.socklen) == -1) {
327
+ ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_socket_errno,
328
+ "connect() failed");
329
+ goto failed;
330
+ }
331
+
332
+ cln = ngx_pool_cleanup_add(peer->pool, 0);
333
+ if (cln == NULL) {
334
+ goto failed;
335
+ }
336
+
337
+ cln->data = peer;
338
+ cln->handler = ngx_syslog_cleanup;
339
+
340
+ peer->conn.fd = fd;
341
+
342
+ /* UDP sockets are always ready to write */
343
+ peer->conn.write->ready = 1;
344
+
345
+ return NGX_OK;
346
+
347
+ failed:
348
+
349
+ if (ngx_close_socket(fd) == -1) {
350
+ ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_socket_errno,
351
+ ngx_close_socket_n " failed");
352
+ }
353
+
354
+ return NGX_ERROR;
355
+ }
356
+
357
+
358
+ static void
359
+ ngx_syslog_cleanup(void *data)
360
+ {
361
+ ngx_syslog_peer_t *peer = data;
362
+
363
+ /* prevents further use of this peer */
364
+ peer->busy = 1;
365
+
366
+ if (peer->conn.fd == (ngx_socket_t) -1) {
367
+ return;
368
+ }
369
+
370
+ if (ngx_close_socket(peer->conn.fd) == -1) {
371
+ ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, ngx_socket_errno,
372
+ ngx_close_socket_n " failed");
373
+ }
374
+ }