View | Details | Raw Unified | Return to bug 163023
Collapse All | Expand All

(-)/usr/ports/www/nginx/Makefile (-1 / +1 lines)
Lines 542-548 Link Here
542
.endif
542
.endif
543
543
544
.if defined(WITH_XRID_HEADER_MODULE)
544
.if defined(WITH_XRID_HEADER_MODULE)
545
GIT_XRID_MODULE_VERSION=        0daa3cc
545
GIT_XRID_MODULE_VERSION=	0daa3cc
546
FETCH_ARGS=	-pRr
546
FETCH_ARGS=	-pRr
547
MASTER_SITES+=	https://github.com/gabor/nginx-x-rid-header/tarball/master/:xrid
547
MASTER_SITES+=	https://github.com/gabor/nginx-x-rid-header/tarball/master/:xrid
548
DISTFILES+=	gabor-nginx-x-rid-header-${GIT_XRID_MODULE_VERSION}.tar.gz:xrid
548
DISTFILES+=	gabor-nginx-x-rid-header-${GIT_XRID_MODULE_VERSION}.tar.gz:xrid
(-)/usr/ports/www/nginx/files/extra-patch-ngx_http_udplog_module.c (-4 / +412 lines)
Lines 1-6 Link Here
1
--- ../nginx_udplog_module-1.0.0/ngx_http_udplog_module.c.orig	2010-01-11 19:16:46.000000000 +0300
1
--- ../nginx_udplog_module-1.0.0/ngx_http_udplog_module.c.orig	2010-01-05 20:20:35.000000000 +0100
2
+++ ../nginx_udplog_module-1.0.0/ngx_http_udplog_module.c	2010-01-11 19:20:17.000000000 +0300
2
+++ ../nginx_udplog_module-1.0.0/ngx_http_udplog_module.c	2011-12-02 18:31:18.000000000 +0100
3
@@ -280,7 +280,7 @@
3
@@ -1,4 +1,3 @@
4
-
5
 /*
6
  * Copyright (C) 2010 Valery Kholodkov
7
  *
8
@@ -45,6 +44,12 @@
9
 } ngx_http_log_fmt_t;
10
 
11
 typedef struct {
12
+    ngx_str_t                value;
13
+    ngx_array_t             *lengths;
14
+    ngx_array_t             *values;
15
+} ngx_http_log_tag_template_t;
16
+
17
+typedef struct {
18
     ngx_array_t                 formats;    /* array of ngx_http_log_fmt_t */
19
     ngx_uint_t                  combined_used; /* unsigned  combined_used:1 */
20
 } ngx_http_log_main_conf_t;
21
@@ -64,8 +69,7 @@
22
 typedef struct {
23
     ngx_udp_endpoint_t       *endpoint;
24
     ngx_http_log_fmt_t       *format;
25
-    ngx_uint_t                facility;
26
-    ngx_uint_t                severity;
27
+    ngx_uint_t                bare:1;
28
 } ngx_http_udplog_t;
29
 
30
 typedef struct {
31
@@ -73,8 +77,11 @@
32
 } ngx_http_udplog_main_conf_t;
33
 
34
 typedef struct {
35
-    ngx_array_t                *logs;       /* array of ngx_http_udplog_t */
36
-    unsigned                    off;
37
+    ngx_array_t                 *logs;       /* array of ngx_http_udplog_t */
38
+    unsigned                     off;
39
+    ngx_http_log_tag_template_t *tag;
40
+    ngx_uint_t                   facility;
41
+    ngx_uint_t                   severity;
42
 } ngx_http_udplog_conf_t;
43
 
44
 ngx_int_t ngx_udp_connect(ngx_udp_connection_t *uc);
45
@@ -88,6 +95,8 @@
46
     void *child);
47
 
48
 static char *ngx_http_udplog_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
49
+static char *ngx_http_udplog_set_priority(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
50
+static char *ngx_http_udplog_set_tag(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
51
 
52
 static ngx_int_t ngx_http_udplog_init(ngx_conf_t *cf);
53
 
54
@@ -96,12 +105,26 @@
55
 
56
     { ngx_string("access_udplog"),
57
       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
58
-                        |NGX_HTTP_LMT_CONF|NGX_CONF_TAKE123,
59
+                        |NGX_HTTP_LMT_CONF|NGX_CONF_TAKE1234,
60
       ngx_http_udplog_set_log,
61
       NGX_HTTP_LOC_CONF_OFFSET,
62
       0,
63
       NULL },
64
 
65
+    { ngx_string("udplog_priority"),
66
+      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE12,
67
+      ngx_http_udplog_set_priority,
68
+      NGX_HTTP_LOC_CONF_OFFSET,
69
+      0,
70
+      NULL },
71
+
72
+    { ngx_string("udplog_tag"),
73
+      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
74
+      ngx_http_udplog_set_tag,
75
+      NGX_HTTP_LOC_CONF_OFFSET,
76
+      offsetof(ngx_http_udplog_conf_t, tag),
77
+      NULL },
78
+
79
       ngx_null_command
80
 };
81
 
82
@@ -166,7 +189,7 @@
83
     { ngx_null_string, 0 }
84
 };
85
 
86
-static ngx_udplog_severity_t ngx_udplog_severity[] = {
87
+static ngx_udplog_severity_t ngx_udplog_severities[] = {
88
     { ngx_string("emerg"),      0 },
89
     { ngx_string("alert"),      1 },
90
     { ngx_string("crit"),       2 },
91
@@ -190,6 +213,7 @@
92
     u_char                   *line, *p;
93
     size_t                    len;
94
     ngx_uint_t                i, l, pri;
95
+    ngx_str_t                 tag;
96
     ngx_http_udplog_t        *log;
97
     ngx_http_log_op_t        *op;
98
     ngx_http_udplog_conf_t   *ulcf;
99
@@ -205,12 +229,31 @@
100
         return NGX_OK;
101
     }
102
 
103
+    if(ulcf->tag != NULL)
104
+    {
105
+        if(ulcf->tag->lengths == NULL) {
106
+            tag = ulcf->tag->value;
107
+        }
108
+        else{
109
+            if (ngx_http_script_run(r, &tag, ulcf->tag->lengths->elts, 0, ulcf->tag->values->elts)
110
+                == NULL)
111
+            {
112
+                return NGX_ERROR;
113
+            }
114
+        }
115
+    }
116
+    else {
117
+        tag.data = (u_char*)"nginx";
118
+        tag.len = sizeof("nginx") - 1;
119
+    }
120
+
121
     time = ngx_time();
122
     ngx_gmtime(time, &tm);
123
 
124
     log = ulcf->logs->elts;
125
+    pri = ulcf->facility * 8 + ulcf->severity;
126
+
127
     for (l = 0; l < ulcf->logs->nelts; l++) {
128
-        pri = log[l].facility * 8 + log[l].severity;
129
 
130
         if(pri > 255) {
131
             pri = NGX_UDPLOG_FACILITY_LOCAL7 * 8 + NGX_UDPLOG_SEVERITY_INFO;
132
@@ -231,7 +274,8 @@
133
             }
134
         }
135
 
136
-        len += sizeof("<255>") - 1 + sizeof("Jan 31 00:00:00") - 1 + 1 + ngx_cycle->hostname.len + 1;
137
+        len += sizeof("<255>") - 1 + sizeof("Jan 31 00:00:00") - 1 + 1 + ngx_cycle->hostname.len + 1
138
+            + tag.len + 2;
139
 
140
 #if defined nginx_version && nginx_version >= 7003
141
         line = ngx_pnalloc(r->pool, len);
142
@@ -245,9 +289,12 @@
143
         /*
144
          * BSD syslog message header (see RFC 3164)
145
          */
146
-        p = ngx_sprintf(line, "<%ui>%s %2d %02d:%02d:%02d %V ", pri, months[tm.ngx_tm_mon - 1], tm.ngx_tm_mday,
147
-            tm.ngx_tm_hour, tm.ngx_tm_min, tm.ngx_tm_sec, &ngx_cycle->hostname);
148
-
149
+	if(!log[l].bare){
150
+	  p = ngx_sprintf(line, "<%ui>%s %2d %02d:%02d:%02d %V %V: ", pri, months[tm.ngx_tm_mon - 1], tm.ngx_tm_mday,
151
+			  tm.ngx_tm_hour, tm.ngx_tm_min, tm.ngx_tm_sec, &ngx_cycle->hostname, &tag);
152
+	}else{
153
+	  p = line;
154
+	}
155
         for (i = 0; i < log[l].format->ops->nelts; i++) {
156
             p = op[i].run(r, p, &op[i]);
157
         }
158
@@ -280,10 +327,15 @@
4
     uc->sockaddr = endpoint->peer_addr.sockaddr;
159
     uc->sockaddr = endpoint->peer_addr.sockaddr;
5
     uc->socklen = endpoint->peer_addr.socklen;
160
     uc->socklen = endpoint->peer_addr.socklen;
6
     uc->server = endpoint->peer_addr.name;
161
     uc->server = endpoint->peer_addr.name;
Lines 9-15 Link Here
9
     uc->log = &cf->cycle->new_log;
164
     uc->log = &cf->cycle->new_log;
10
 #else
165
 #else
11
     uc->log = cf->cycle->new_log;
166
     uc->log = cf->cycle->new_log;
12
@@ -335,7 +335,11 @@
167
+#if defined nginx_version && nginx_version >= 8032
168
+    uc->log.handler = NULL;
169
+    uc->log.data = NULL;
170
+    uc->log.action = "logging";
171
+#endif
172
 #endif
173
 
174
     return NGX_OK;
175
@@ -320,6 +372,11 @@
176
 
177
     if (uc->connection == NULL) {
178
         if(ngx_udp_connect(uc) != NGX_OK) {
179
+            if(uc->connection != NULL) {
180
+                ngx_free_connection(uc->connection);
181
+                uc->connection = NULL;
182
+            }
183
+
184
             return NGX_ERROR;
185
         }
186
 
187
@@ -335,7 +392,11 @@
13
     }
188
     }
14
 
189
 
15
     if ((size_t) n != (size_t) len) {
190
     if ((size_t) n != (size_t) len) {
Lines 21-23 Link Here
21
         return NGX_ERROR;
196
         return NGX_ERROR;
22
     }
197
     }
23
 
198
 
199
@@ -364,6 +425,9 @@
200
     if (conf == NULL) {
201
         return NGX_CONF_ERROR;
202
     }
203
+    conf->off = 1;
204
+    conf->facility = NGX_CONF_UNSET_UINT;
205
+    conf->severity = NGX_CONF_UNSET_UINT;
206
 
207
     return conf;
208
 }
209
@@ -374,37 +438,21 @@
210
     ngx_http_udplog_conf_t *prev = parent;
211
     ngx_http_udplog_conf_t *conf = child;
212
 
213
-    ngx_http_udplog_t         *log;
214
-    ngx_http_log_fmt_t        *fmt;
215
-    ngx_http_log_main_conf_t  *lmcf;
216
-
217
-    if(conf->logs || conf->off) {
218
-        return NGX_CONF_OK;
219
+    if(conf->tag == NULL) {
220
+        conf->tag = prev->tag;
221
     }
222
 
223
-    conf->logs = prev->logs;
224
-    conf->off = prev->off;
225
+    ngx_conf_merge_uint_value(conf->facility,
226
+                              prev->facility, NGX_UDPLOG_FACILITY_LOCAL7);
227
+    ngx_conf_merge_uint_value(conf->severity,
228
+                              prev->severity, NGX_UDPLOG_SEVERITY_INFO);
229
 
230
     if(conf->logs || conf->off) {
231
         return NGX_CONF_OK;
232
     }
233
 
234
-    conf->logs = ngx_array_create(cf->pool, 2, sizeof(ngx_http_udplog_t));
235
-    if(conf->logs == NULL) {
236
-        return NGX_CONF_ERROR;
237
-    }
238
-
239
-    log = ngx_array_push(conf->logs);
240
-    if(log == NULL) {
241
-        return NGX_CONF_ERROR;
242
-    }
243
-
244
-    lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_log_module);
245
-    fmt = lmcf->formats.elts;
246
-
247
-    /* the default "combined" format */
248
-    log->format = &fmt[0];
249
-    lmcf->combined_used = 1;
250
+    conf->logs = prev->logs;
251
+    conf->off = prev->off;
252
 
253
     return NGX_CONF_OK;
254
 }
255
@@ -434,12 +482,6 @@
256
     return endpoint;
257
 }
258
 
259
-static ngx_int_t
260
-ngx_http_udplog_set_facility_and_severity(ngx_http_udplog_t *log, ngx_str_t *value)
261
-{
262
-    return NGX_OK;
263
-}
264
-
265
 static char *
266
 ngx_http_udplog_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
267
 {
268
@@ -458,6 +500,7 @@
269
         ulcf->off = 1;
270
         return NGX_CONF_OK;
271
     }
272
+    ulcf->off = 0;
273
 
274
     if (ulcf->logs == NULL) {
275
         ulcf->logs = ngx_array_create(cf->pool, 2, sizeof(ngx_http_udplog_t));
276
@@ -483,10 +526,11 @@
277
 
278
     ngx_memzero(&u, sizeof(ngx_url_t));
279
 
280
-    u.host = value[1];
281
-    u.port = 514;
282
+    u.url = value[1];
283
+    u.default_port = 514;
284
+    u.no_resolve = 0;
285
 
286
-    if(ngx_inet_resolve_host(cf->pool, &u) != NGX_OK) {
287
+    if(ngx_parse_url(cf->pool, &u) != NGX_OK) {
288
         ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V: %s", &u.host, u.err);
289
         return NGX_CONF_ERROR;
290
     }
291
@@ -496,7 +540,7 @@
292
     if(log->endpoint == NULL) {
293
         return NGX_CONF_ERROR;
294
     }
295
-
296
+    log->bare = 0;
297
     if (cf->args->nelts >= 3) {
298
         name = value[2];
299
 
300
@@ -508,14 +552,18 @@
301
         name.data = (u_char *) "combined";
302
         lmcf->combined_used = 1;
303
     }
304
-
305
+    if (cf->args->nelts >= 4) {
306
+      if (ngx_strcmp(value[3].data, "bare") == 0) {
307
+	log->bare = 1;
308
+      }
309
+    }
310
     fmt = lmcf->formats.elts;
311
     for (i = 0; i < lmcf->formats.nelts; i++) {
312
         if (fmt[i].name.len == name.len
313
             && ngx_strcasecmp(fmt[i].name.data, name.data) == 0)
314
         {
315
             log->format = &fmt[i];
316
-            goto facility;
317
+            goto done;
318
         }
319
     }
320
 
321
@@ -523,12 +571,105 @@
322
                        "unknown log format \"%V\"", &name);
323
     return NGX_CONF_ERROR;
324
 
325
-facility:
326
-    log->facility = NGX_UDPLOG_FACILITY_LOCAL7;
327
-    log->severity = NGX_UDPLOG_SEVERITY_INFO;
328
+done:
329
+
330
+    return NGX_CONF_OK;
331
+}
332
+
333
+
334
+static char *
335
+ngx_http_udplog_set_priority(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
336
+{
337
+    ngx_http_udplog_conf_t     *ulcf = conf;
338
+    ngx_str_t                  *value;
339
+    ngx_udplog_facility_t      *f;
340
+    ngx_udplog_severity_t      *s;
341
+
342
+    value = cf->args->elts;
343
+
344
+    f = ngx_udplog_facilities;
345
+
346
+    while(f->name.data != NULL) {
347
+        if(ngx_strncmp(f->name.data, value[1].data, f->name.len) == 0)
348
+            break;
349
+
350
+        f++;
351
+    }
352
+
353
+    if(f->name.data != NULL) {
354
+        ulcf->facility = f->number;
355
+    }
356
+    else {
357
+        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
358
+                           "unknown facility \"%V\"", &value[1]);
359
+        return NGX_CONF_ERROR;
360
+    }
361
+
362
+    if (cf->args->nelts == 3) {
363
+        s = ngx_udplog_severities;
364
+
365
+        while(s->name.data != NULL) {
366
+            if(ngx_strncmp(s->name.data, value[2].data, s->name.len) == 0)
367
+                break;
368
+
369
+            s++;
370
+        }
371
+
372
+        if(s->name.data != NULL) {
373
+            ulcf->severity = s->number;
374
+        }
375
+        else {
376
+            ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
377
+                               "unknown severity \"%V\"", &value[2]);
378
+            return NGX_CONF_ERROR;
379
+        }
380
+    }
381
+
382
+    return NGX_CONF_OK;
383
+}
384
+
385
+static char *
386
+ngx_http_udplog_set_tag(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
387
+{
388
+    ngx_int_t                   n;
389
+    ngx_str_t                  *value;
390
+    ngx_http_script_compile_t   sc;
391
+    ngx_http_log_tag_template_t **field, *h;
392
+
393
+    field = (ngx_http_log_tag_template_t**) (((u_char*)conf) + cmd->offset);
394
+
395
+    value = cf->args->elts;
396
+
397
+    if (*field == NULL) {
398
+        *field = ngx_palloc(cf->pool, sizeof(ngx_http_log_tag_template_t));
399
+        if (*field == NULL) {
400
+            return NGX_CONF_ERROR;
401
+        }
402
+    }
403
+
404
+    h = *field;
405
+
406
+    h->value = value[1];
407
+    h->lengths = NULL;
408
+    h->values = NULL;
409
+
410
+    /*
411
+     * Compile field name
412
+     */
413
+    n = ngx_http_script_variables_count(&value[1]);
414
+
415
+    if (n > 0) {
416
+        ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
417
+
418
+        sc.cf = cf;
419
+        sc.source = &value[1];
420
+        sc.lengths = &h->lengths;
421
+        sc.values = &h->values;
422
+        sc.variables = n;
423
+        sc.complete_lengths = 1;
424
+        sc.complete_values = 1;
425
 
426
-    if(cf->args->nelts == 4) {
427
-        if(ngx_http_udplog_set_facility_and_severity(log, &value[3]) != NGX_OK) {
428
+        if (ngx_http_script_compile(&sc) != NGX_OK) {
429
             return NGX_CONF_ERROR;
430
         }
431
     }

Return to bug 163023