Skip to content

Commit 39d6f1a

Browse files
author
Marius Sturm
authored
Merge pull request #9 from TinoWildenhain/master
Handling of datatypes other then string
2 parents 7c0321c + ee77bd7 commit 39d6f1a

File tree

5 files changed

+133
-130
lines changed

5 files changed

+133
-130
lines changed

README.md

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -60,46 +60,45 @@ Configure the module in `/etc/apache2/mods-enabled/log_gelf.conf`:
6060
```
6161
On CentOS both files are combined in `/etc/httpd/conf.modules.d/02-gelf.conf`
6262

63-
| Parameter | Argument | Description |
64-
|--------------|------------------------|----------------------------------------------------|
65-
| GelfEnabled | On/Off | Load GELF logging module |
66-
| GelfUrl | Graylog server URL | Set IP and port of a UDP GELF input |
67-
| GelfSource | (Optional) | Overwrite source field |
68-
| GelfFacility | (Optional) | Overwrite logging facility |
69-
| GelfTag | (Optional) | Add a `tag` field to every log message |
70-
| GelfCookie | (Optional) cookie name | Extract cookie from web request, Use 'c' GelfField |
71-
| GelfHeader | (Optional) header name | Extract header from web request, Use 'X' GelfField |
72-
| GelfFields | (Optional) | Configures which information should be logged |
63+
| Parameter | Argument | Description |
64+
|--------------|------------------------|--------------------------------------------------------|
65+
| GelfEnabled | On/Off | Load GELF logging module |
66+
| GelfUrl | Graylog server URL | Set IP and port of a UDP GELF input |
67+
| GelfSource | (Optional) | Overwrite source field |
68+
| GelfFacility | (Optional) | Overwrite logging facility |
69+
| GelfTag | (Optional) | Add a `tag` field to every log message |
70+
| GelfCookie | (Optional) cookie name | Extract one cookie from web request, Use 'c' GelfField |
71+
| GelfHeader | (Optional) header name | Extract one header from web request, Use 'X' GelfField |
72+
| GelfFields | (Optional) | Configures which information should be logged |
7373

7474
What does the `GelfFields` string mean:
7575

76-
| Character | Logging information |
77-
|-----------|---------------------|
78-
| A | Agent string |
79-
| a | Request arguments |
80-
| B | Bytes send |
81-
| C | Connection status |
82-
| c | Extract Cookie |
83-
| D | Request duration |
84-
| | (in microseconds) |
85-
| f | Requested file |
86-
| H | Protocol |
87-
| h | Remote host |
88-
| i | Remote address |
89-
| L | Local address |
90-
| l | Auth login name |
91-
| m | Request methode |
92-
| p | Server port |
93-
| P | Child PID |
94-
| R | Referer |
95-
| r | Request string |
96-
| s | Return status |
97-
| t | Request timestamp |
98-
| U | Request URI |
99-
| u | Username |
100-
| V | Server name |
101-
| v | VirtualHost name |
102-
| X | Extract Header |
76+
| Character | Logging information |
77+
|-----------|---------------------------------------------|
78+
| A | Agent string |
79+
| a | Request arguments |
80+
| B | Bytes send |
81+
| C | Connection status |
82+
| c | Extract Cookie (name must be in GelfCookie) |
83+
| D | Request duration (in microseconds) |
84+
| f | Requested file |
85+
| H | Protocol |
86+
| h | Remote host |
87+
| i | Remote address |
88+
| L | Local address |
89+
| l | Auth login name |
90+
| m | Request methode |
91+
| p | Server port |
92+
| P | Child PID |
93+
| R | Referer |
94+
| r | Request string |
95+
| s | Return status |
96+
| t | Request timestamp |
97+
| U | Request URI |
98+
| u | Username |
99+
| V | Server name |
100+
| v | VirtualHost name |
101+
| X | Extract Header (name must be in GelfHeader) |
103102

104103
# Packages
105104

src/functions.h

Lines changed: 57 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,42 @@
33
* value to the calling entity.
44
*/
55

6-
static const char *extract_remote_host(request_rec *r, char *a)
6+
json_object *extract_remote_host(request_rec *r, char *a)
77
{
8-
return (char *) ap_get_remote_host(r->connection, r->per_dir_config, REMOTE_NAME, NULL);
8+
return json_object_new_string(ap_get_remote_host(r->connection, r->per_dir_config, REMOTE_NAME, NULL));
99
}
1010

11-
static const char *extract_remote_address(request_rec *r, char *a) __attribute__((unused));
11+
json_object *extract_remote_address(request_rec *r, char *a) __attribute__((unused));
1212

13-
static const char *extract_remote_address(request_rec *r, char *a)
13+
json_object *extract_remote_address(request_rec *r, char *a)
1414
{
1515
#ifdef WITH_APACHE22
16-
return r->connection->remote_ip;
16+
return json_object_new_string(r->connection->remote_ip);
1717
#else
18-
return r->connection->client_ip;
18+
return json_object_new_string(r->connection->client_ip);
1919
#endif
2020
}
2121

22-
static const char *extract_local_address(request_rec *r, char *a) __attribute__((unused));
22+
json_object *extract_local_address(request_rec *r, char *a) __attribute__((unused));
2323

24-
static const char *extract_local_address(request_rec *r, char *a)
24+
json_object *extract_local_address(request_rec *r, char *a)
2525
{
26-
return r->connection->local_ip;
26+
return json_object_new_string(r->connection->local_ip);
2727
}
2828

29-
static const char *extract_remote_logname(request_rec *r, char *a)
29+
json_object *extract_remote_logname(request_rec *r, char *a)
3030
{
3131
const char *rlogin = ap_get_remote_logname(r);
3232
if (rlogin == NULL) {
33-
rlogin = "-";
33+
return NULL;
3434
} else if (strlen(rlogin) == 0) {
3535
rlogin = "\"\"";
3636
}
3737

38-
return rlogin;
38+
return json_object_new_string(rlogin);
3939
}
4040

41-
static const char *extract_remote_user(request_rec *r, char *a)
41+
json_object *extract_remote_user(request_rec *r, char *a)
4242
{
4343
#ifdef WITH_APACHE13
4444
char *rvalue = r->connection->user;
@@ -50,76 +50,77 @@ static const char *extract_remote_user(request_rec *r, char *a)
5050
} else if (strlen(rvalue) == 0) {
5151
rvalue = "\"\"";
5252
}
53-
return rvalue;
53+
return json_object_new_string(rvalue);
5454
}
5555

56-
static const char *extract_request_line(request_rec *r, char *a)
56+
json_object *extract_request_line(request_rec *r, char *a)
5757
{
5858
/* Upddated to mod_log_config logic */
5959
/* NOTE: If the original request contained a password, we
6060
* re-write the request line here to contain XXXXXX instead:
6161
* (note the truncation before the protocol string for HTTP/0.9 requests)
6262
* (note also that r->the_request contains the unmodified request)
6363
*/
64-
return (r->parsed_uri.password)
64+
return json_object_new_string(
65+
(r->parsed_uri.password)
6566
? apr_pstrcat(r->pool, r->method, " ",
6667
apr_uri_unparse(r->pool,
6768
&r->parsed_uri, 0),
6869
r->assbackwards ? NULL : " ",
6970
r->protocol, NULL)
70-
: r->the_request;
71+
: r->the_request);
7172
}
7273

73-
static const char *extract_request_file(request_rec *r, char *a)
74+
json_object *extract_request_file(request_rec *r, char *a)
7475
{
75-
return r->filename;
76+
return json_object_new_string(r->filename);
7677
}
7778

78-
static const char *extract_request_uri(request_rec *r, char *a)
79+
json_object *extract_request_uri(request_rec *r, char *a)
7980
{
80-
return r->uri;
81+
return json_object_new_string(r->uri);
8182
}
8283

83-
static const char *extract_request_method(request_rec *r, char *a)
84+
json_object *extract_request_method(request_rec *r, char *a)
8485
{
85-
return r->method;
86+
return json_object_new_string(r->method);
8687
}
8788

88-
static const char *extract_request_protocol(request_rec *r, char *a)
89+
json_object *extract_request_protocol(request_rec *r, char *a)
8990
{
90-
return r->protocol;
91+
return json_object_new_string(r->protocol);
9192
}
9293

93-
static const char *extract_request_query(request_rec *r, char *a)
94+
json_object *extract_request_query(request_rec *r, char *a)
9495
{
95-
return (r->args) ? apr_pstrcat(r->pool, "?",
96+
return json_object_new_string((r->args) ? apr_pstrcat(r->pool, "?",
9697
r->args, NULL)
97-
: "";
98+
: "");
9899
}
99100

100-
static const char *extract_status(request_rec *r, char *a)
101+
json_object *extract_status(request_rec *r, char *a)
101102
{
102103
if (r->status <= 0) {
103-
return "-";
104+
return NULL;
104105
} else {
105-
return apr_psprintf(r->pool, "%d", r->status);
106+
return json_object_new_int(r->status);
106107
}
107108
}
108109

109-
static const char *extract_virtual_host(request_rec *r, char *a)
110+
json_object *extract_virtual_host(request_rec *r, char *a)
110111
{
111-
return r->server->server_hostname;
112+
return json_object_new_string(r->server->server_hostname);
112113
}
113114

114-
static const char *extract_server_name(request_rec *r, char *a)
115+
json_object *extract_server_name(request_rec *r, char *a)
115116
{
116-
return ap_get_server_name(r);
117+
return json_object_new_string(ap_get_server_name(r));
117118
}
118119

119-
static const char *extract_server_port(request_rec *r, char *a)
120+
json_object *extract_server_port(request_rec *r, char *a)
120121
{
121-
return apr_psprintf(r->pool, "%u",
122-
r->server->port ? r->server->port : ap_default_port(r));
122+
return json_object_new_string(apr_psprintf(r->pool, "%u",
123+
r->server->port ? r->server->port : ap_default_port(r)));
123124
}
124125

125126
/* This respects the setting of UseCanonicalName so that
@@ -131,63 +132,63 @@ static const char *log_server_name(request_rec *r, char *a)
131132
return ap_get_server_name(r);
132133
}
133134

134-
static const char *extract_child_pid(request_rec *r, char *a)
135+
json_object *extract_child_pid(request_rec *r, char *a)
135136
{
136137
if (*a == '\0' || !strcmp(a, "pid")) {
137-
return apr_psprintf(r->pool, "%" APR_PID_T_FMT, getpid());
138+
return json_object_new_string(apr_psprintf(r->pool, "%" APR_PID_T_FMT, getpid()));
138139
}
139140
else if (!strcmp(a, "tid")) {
140141
#if APR_HAS_THREADS
141142
apr_os_thread_t tid = apr_os_thread_current();
142143
#else
143144
int tid = 0; /* APR will format "0" anyway but an arg is needed */
144145
#endif
145-
return apr_psprintf(r->pool, "%pT", &tid);
146+
return json_object_new_string(apr_psprintf(r->pool, "%pT", &tid));
146147
}
147148
/* bogus format */
148-
return a;
149+
return json_object_new_string(a);
149150
}
150151

151-
static const char *extract_header(request_rec *r, char *a)
152+
json_object *extract_header(request_rec *r, char *a)
152153
{
153154
const char *tempref;
154155

155156
tempref = apr_table_get(r->headers_in, a);
156157
if (!tempref)
157158
{
158-
return "-";
159+
return NULL;
159160
} else {
160-
return tempref;
161+
return json_object_new_string(tempref);
161162
}
162163
}
163164

164-
static const char *extract_referer(request_rec *r, char *a)
165+
json_object *extract_referer(request_rec *r, char *a)
165166
{
166167
const char *tempref;
167168

168169
tempref = apr_table_get(r->headers_in, "Referer");
169170
if (!tempref)
170171
{
171-
return "-";
172+
return NULL;
172173
} else {
173-
return tempref;
174+
return json_object_new_string(tempref);
174175
}
175176
}
176177

177-
static const char *extract_agent(request_rec *r, char *a)
178+
json_object *extract_agent(request_rec *r, char *a)
178179
{
179180
const char *tempag;
180181

181182
tempag = apr_table_get(r->headers_in, "User-Agent");
182183
if (!tempag)
183184
{
184-
return "-";
185+
return NULL;
185186
} else {
186-
return tempag;
187+
return json_object_new_string(tempag);
187188
}
188189
}
189190

190-
static const char *extract_specific_cookie(request_rec *r, char *a)
191+
json_object *extract_specific_cookie(request_rec *r, char *a)
191192
{
192193
const char *cookiestr;
193194
char *cookieend;
@@ -215,7 +216,7 @@ static const char *extract_specific_cookie(request_rec *r, char *a)
215216
cookieend = ap_strchr(cookiebuf, ';');
216217
if (cookieend != NULL)
217218
*cookieend = '\0';
218-
return cookiebuf;
219+
return json_object_new_string(cookiebuf);
219220
}
220221
}
221222

@@ -230,7 +231,7 @@ static const char *extract_specific_cookie(request_rec *r, char *a)
230231
cookieend = ap_strchr(cookiebuf, ';');
231232
if (cookieend != NULL)
232233
*cookieend = '\0';
233-
return cookiebuf;
234+
return json_object_new_string(cookiebuf);
234235
}
235236
}
236237

@@ -245,10 +246,10 @@ static const char *extract_specific_cookie(request_rec *r, char *a)
245246
cookieend = ap_strchr(cookiebuf, ';');
246247
if (cookieend != NULL)
247248
*cookieend = '\0';
248-
return cookiebuf;
249+
return json_object_new_string(cookiebuf);
249250
}
250251
}
251252
}
252253

253-
return "-";
254+
return NULL;
254255
}

0 commit comments

Comments
 (0)