From: Jeff Trawick Date: Wed, 26 Sep 2007 01:45:16 +0000 (+0000) Subject: mod_log_config: Add format options for %p so that the actual local X-Git-Tag: 2.3.0~1395 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c105e90a869395ea9ae6ef90c626d180215afd5d;p=apache mod_log_config: Add format options for %p so that the actual local or remote port can be logged. PR: 43415 Submitted by: Adam Hasselbalch Hansen Extensively commented on and/or modified by Ruediger Pluem and Jeff Trawick git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@579425 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index 54eeeea36f..1f96501125 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,10 @@ Changes with Apache 2.3.0 [ When backported to 2.2.x, remove entry from this file ] + *) mod_log_config: Add format options for %p so that the actual local + or remote port can be logged. PR 43415. [Adam Hasselbalch Hansen + , Ruediger Pluem, Jeff Trawick] + *) scoreboard: improve error message on apr_shm_create failure PR 40037 [Nick Kew] diff --git a/docs/manual/mod/mod_log_config.xml b/docs/manual/mod/mod_log_config.xml index b5a7bed259..27c855c240 100644 --- a/docs/manual/mod/mod_log_config.xml +++ b/docs/manual/mod/mod_log_config.xml @@ -127,6 +127,12 @@ %p The canonical port of the server serving the request + %{format}p + The canonical port of the server serving the request or the + server's actual port or the client's actual port. Valid formats + are canonical, local, or remote. + + %P The process ID of the child that serviced the request. diff --git a/modules/loggers/mod_log_config.c b/modules/loggers/mod_log_config.c index a3237fe181..7b8355522a 100644 --- a/modules/loggers/mod_log_config.c +++ b/modules/loggers/mod_log_config.c @@ -90,7 +90,9 @@ * %...l: remote logname (from identd, if supplied) * %...{Foobar}n: The contents of note "Foobar" from another module. * %...{Foobar}o: The contents of Foobar: header line(s) in the reply. - * %...p: the port the request was served to + * %...p: the canonical port for the server + * %...{format}p: the canonical port for the server, or the actual local + * or remote port * %...P: the process ID of the child that serviced the request. * %...{format}P: the process ID or thread ID of the child/thread that * serviced the request @@ -628,8 +630,22 @@ static const char *log_virtual_host(request_rec *r, char *a) static const char *log_server_port(request_rec *r, char *a) { - return apr_psprintf(r->pool, "%u", - r->server->port ? r->server->port : ap_default_port(r)); + apr_port_t port; + + if (*a == '\0' || !strcasecmp(a, "canonical")) { + port = r->server->port ? r->server->port : ap_default_port(r); + } + else if (!strcasecmp(a, "remote")) { + port = r->connection->remote_addr->port; + } + else if (!strcasecmp(a, "local")) { + port = r->connection->local_addr->port; + } + else { + /* bogus format */ + return a; + } + return apr_itoa(r->pool, (int)port); } /* This respects the setting of UseCanonicalName so that