Add log to the server flags.
input/"Looks ok" reyk@
-/* $OpenBSD: config.c,v 1.10 2014/07/31 14:18:38 reyk Exp $ */
+/* $OpenBSD: config.c,v 1.11 2014/08/02 21:21:47 doug Exp $ */
/*
* Copyright (c) 2011 - 2014 Reyk Floeter <reyk@openbsd.org>
if ((srv_conf->flags & f) == 0)
srv_conf->flags |= srv->srv_conf.flags & f;
+ f = SRVFLAG_LOG|SRVFLAG_NO_LOG;
+ if ((srv_conf->flags & f) == 0) {
+ srv_conf->flags |= srv->srv_conf.flags & f;
+ srv_conf->logformat = srv->srv_conf.logformat;
+ }
+
DPRINTF("%s: %s %d received location \"%s\", parent \"%s\"",
__func__, ps->ps_title[privsep_process], ps->ps_instance,
srv_conf->location, srv->srv_conf.name);
-.\" $OpenBSD: httpd.conf.5,v 1.16 2014/08/02 10:24:36 reyk Exp $
+.\" $OpenBSD: httpd.conf.5,v 1.17 2014/08/02 21:21:47 doug Exp $
.\"
.\" Copyright (c) 2014 Reyk Floeter <reyk@openbsd.org>
.\"
.Ar common
or
.Ar combined .
-It is similar to the Apache and nginx logging format.
+It is similar to the default Apache and nginx access log.
If not specified, the default is
.Ar common .
.It Ic root Ar directory
-/* $OpenBSD: httpd.h,v 1.32 2014/08/02 17:05:18 florian Exp $ */
+/* $OpenBSD: httpd.h,v 1.33 2014/08/02 21:21:47 doug Exp $ */
/*
* Copyright (c) 2006 - 2014 Reyk Floeter <reyk@openbsd.org>
};
SPLAY_HEAD(client_tree, client);
-#define SRVFLAG_INDEX 0x01
-#define SRVFLAG_NO_INDEX 0x02
-#define SRVFLAG_AUTO_INDEX 0x04
-#define SRVFLAG_NO_AUTO_INDEX 0x08
-#define SRVFLAG_PATH 0x10
-#define SRVFLAG_LOCATION 0x20
-#define SRVFLAG_FCGI 0x40
-#define SRVFLAG_NO_FCGI 0x80
+#define SRVFLAG_INDEX 0x001
+#define SRVFLAG_NO_INDEX 0x002
+#define SRVFLAG_AUTO_INDEX 0x004
+#define SRVFLAG_NO_AUTO_INDEX 0x008
+#define SRVFLAG_PATH 0x010
+#define SRVFLAG_LOCATION 0x020
+#define SRVFLAG_FCGI 0x040
+#define SRVFLAG_NO_FCGI 0x080
+#define SRVFLAG_LOG 0x100
+#define SRVFLAG_NO_LOG 0x200
#define SRVFLAG_BITS \
"\10\01INDEX\02NO_INDEX\03AUTO_INDEX\04NO_AUTO_INDEX" \
- "\05PATH\06LOCATION\07FCGI\10NO_FCGI"
+ "\05PATH\06LOCATION\07FCGI\10NO_FCGI\11LOG\12NO_LOG"
#define TCPFLAG_NODELAY 0x01
#define TCPFLAG_NNODELAY 0x02
"\05SOCKET_BUFFER_SIZE\06IP_TTL\07IP_MINTTL\10NO_SPLICE"
enum log_format {
- LOG_FORMAT_NONE = -1,
- LOG_FORMAT_COMMON = 0,
- LOG_FORMAT_COMBINED,
+ LOG_FORMAT_COMMON,
+ LOG_FORMAT_COMBINED
};
struct server_config {
int prefixlen;
struct timeval timeout;
- u_int8_t flags;
+ u_int16_t flags;
u_int8_t tcpflags;
int tcpbufsiz;
int tcpbacklog;
-/* $OpenBSD: parse.y,v 1.15 2014/08/01 21:59:56 reyk Exp $ */
+/* $OpenBSD: parse.y,v 1.16 2014/08/02 21:21:47 doug Exp $ */
/*
* Copyright (c) 2007 - 2014 Reyk Floeter <reyk@openbsd.org>
sizeof(s->srv_conf.index));
s->srv_conf.id = ++last_server_id;
s->srv_conf.timeout.tv_sec = SERVER_TIMEOUT;
+ s->srv_conf.flags |= SRVFLAG_LOG;
+ s->srv_conf.logformat = LOG_FORMAT_COMMON;
if (last_server_id == INT_MAX) {
yyerror("too many servers defined");
;
logformat : LOG COMMON {
+ srv->srv_conf.flags &= ~SRVFLAG_NO_LOG;
+ srv->srv_conf.flags |= SRVFLAG_LOG;
srv->srv_conf.logformat = LOG_FORMAT_COMMON;
}
| LOG COMBINED {
+ srv->srv_conf.flags &= ~SRVFLAG_NO_LOG;
+ srv->srv_conf.flags |= SRVFLAG_LOG;
srv->srv_conf.logformat = LOG_FORMAT_COMBINED;
}
| NO LOG {
- srv->srv_conf.logformat = LOG_FORMAT_NONE;
+ srv->srv_conf.flags &= ~SRVFLAG_LOG;
+ srv->srv_conf.flags |= SRVFLAG_NO_LOG;
}
;
-/* $OpenBSD: server_http.c,v 1.27 2014/08/01 22:24:05 reyk Exp $ */
+/* $OpenBSD: server_http.c,v 1.28 2014/08/02 21:21:47 doug Exp $ */
/*
* Copyright (c) 2006 - 2014 Reyk Floeter <reyk@openbsd.org>
int
server_log_http(struct client *clt, u_int code, size_t len)
{
- static char tstamp[64];
- static char ip[INET6_ADDRSTRLEN];
- time_t t;
- struct tm *tm;
+ static char tstamp[64];
+ static char ip[INET6_ADDRSTRLEN];
+ time_t t;
+ struct kv key, *agent, *referrer;
+ struct tm *tm;
struct server_config *srv_conf;
struct http_descriptor *desc;
- struct kv key, *agent, *referrer;
if ((srv_conf = clt->clt_srv_conf) == NULL)
return (-1);
+ if ((srv_conf->flags & SRVFLAG_LOG) == 0)
+ return (0);
if ((desc = clt->clt_desc) == NULL)
return (-1);
- if (srv_conf->logformat == LOG_FORMAT_NONE)
- return (0);
if ((t = time(NULL)) == -1)
return (-1);
return (-1);
if (clt->clt_ss.ss_family == AF_INET) {
- struct sockaddr_in *in = (struct sockaddr_in *)&clt->clt_ss;
+ struct sockaddr_in *in = (struct sockaddr_in *)&clt->clt_ss;
if (inet_ntop(AF_INET, &in->sin_addr, ip, sizeof(ip)) == NULL)
return (-1);
} else if (clt->clt_ss.ss_family == AF_INET6) {
- struct sockaddr_in6 *in = (struct sockaddr_in6 *)&clt->clt_ss;
+ struct sockaddr_in6 *in = (struct sockaddr_in6 *)&clt->clt_ss;
if (inet_ntop(AF_INET6, &in->sin6_addr, ip, sizeof(ip)) == NULL)
return (-1);
} else
/*
* For details on common log format, see:
* https://httpd.apache.org/docs/current/mod/mod_log_config.html
+ *
+ * httpd's format is similar to these Apache LogFormats:
+ * "%v %h %l %u %t \"%r\" %>s %B"
+ * "%v %h %l %u %t \"%r\" %>s %B \"%{Referer}i\" \"%{User-agent}i\""
*/
switch (srv_conf->logformat) {
case LOG_FORMAT_COMMON:
agent == NULL ? "" : agent->kv_value) == -1)
return (-1);
break;
-
- case LOG_FORMAT_NONE:
- return (-1);
}
return (0);