diff options
author | Stef Walter <stef@memberwebs.com> | 2004-08-18 22:16:28 +0000 |
---|---|---|
committer | Stef Walter <stef@memberwebs.com> | 2004-08-18 22:16:28 +0000 |
commit | 59099b09a63f200147fc506e75f3052469d69fe9 (patch) | |
tree | 8a977451ae18f9075bcbb3fcd88f6da0e893b275 | |
parent | 861158ad71effd4f48da442f5eb1bb70754eb08b (diff) |
Connection logging cleanup.
-rw-r--r-- | daemon/httpauthd.c | 55 |
1 files changed, 34 insertions, 21 deletions
diff --git a/daemon/httpauthd.c b/daemon/httpauthd.c index b471094..b56f3d2 100644 --- a/daemon/httpauthd.c +++ b/daemon/httpauthd.c @@ -357,14 +357,6 @@ int main(int argc, char* argv[]) memset(&sany, 0, sizeof(sany)); SANY_LEN(sany) = sizeof(sany); - /* TODO: Move this code into the thread */ - /* Get the peer name */ - if(getpeername(fd, &SANY_ADDR(sany), &SANY_LEN(sany)) == -1 || - sock_any_ntop(&sany, peername, MAXPATHLEN, SANY_OPT_NOPORT) == -1) - ha_messagex(NULL, LOG_WARNING, "%d: couldn't get peer address", fd); - else - ha_messagex(NULL, LOG_INFO, "%d: accepted connection from: %s", fd, peername); - /* Look for thread and also clean up others */ for(i = 0; i < g_maxthreads; i++) { @@ -393,7 +385,7 @@ int main(int argc, char* argv[]) break; } - ha_messagex(NULL, LOG_DEBUG, "%d: created thread for connection", fd); + ha_messagex(NULL, LOG_DEBUG, "created thread for connection: %d", fd); fd = -1; break; } @@ -499,9 +491,6 @@ static void* httpauth_thread(void* arg) /* call the processor */ r = httpauth_processor(thread->fd, thread->fd); - /* TODO: Move this to more appropriate place (where we have a req) */ - ha_messagex(NULL, LOG_INFO, "%d: closed connection", thread->fd); - /* mark this as done */ thread->fd = -1; return (void*)r; @@ -1037,6 +1026,23 @@ static int httpauth_set(ha_request_t* rq, ha_buffer_t* cbuf, int ofd) return httpauth_respond(rq, ofd, HA_SERVER_ACCEPTED, 0, NULL); } +static void httpauth_conninfo(ha_request_t* rq, int fd) +{ + struct sockaddr_any addr; + char peername[MAXPATHLEN]; + + ha_messagex(rq, LOG_DEBUG, "processing %d on thread %x", fd, (int)pthread_self()); + + memset(&addr, 0, sizeof(addr)); + SANY_LEN(addr) = sizeof(addr); + + /* Get the peer name */ + if(getpeername(fd, &SANY_ADDR(addr), &SANY_LEN(addr)) == -1 || + sock_any_ntop(&addr, peername, MAXPATHLEN, SANY_OPT_NOPORT) == -1) + ha_messagex(rq, LOG_WARNING, "couldn't get peer address"); + else + ha_messagex(rq, LOG_INFO, "accepted connection from: %s", peername); +} static int httpauth_processor(int ifd, int ofd) { @@ -1049,21 +1055,25 @@ static int httpauth_processor(int ifd, int ofd) ASSERT(ifd != -1); ASSERT(ofd != -1); + memset(&rq, 0, sizeof(rq)); + + ha_lock(NULL); + rq.id = g_unique++; + ha_unlock(NULL); + + /* Used when processing a socket */ + if(ifd == ofd) + httpauth_conninfo(&rq, ifd); + /* Initialize the memory buffers */ ha_bufinit(&buf); ha_bufinit(&cbuf); - memset(&rq, 0, sizeof(rq)); - /* Set up some context stuff */ rq.digest_domain = ""; rq.buf = &buf; rq.conn_buf = &cbuf; - ha_lock(NULL); - rq.id = g_unique++; - ha_unlock(NULL); - if(httpauth_ready(&rq, ofd) == -1) { result = 1; @@ -1129,10 +1139,12 @@ static int httpauth_processor(int ifd, int ofd) } } +finally: + if(ifd == ofd) { - shutdown(ofd, SHUT_RDWR); - close(ofd); + shutdown(ifd, SHUT_RDWR); + close(ifd); } else { @@ -1140,7 +1152,8 @@ static int httpauth_processor(int ifd, int ofd) close(ofd); } -finally: + ha_messagex(&rq, LOG_INFO, "closed connection"); + ha_buffree(&cbuf); ha_buffree(&buf); return result; |