diff -Nur linux-2.4.1-orgn/net/khttpd/logging.c linux/net/khttpd/logging.c --- linux-2.4.1-orgn/net/khttpd/logging.c Thu Aug 19 01:45:10 1999 +++ linux/net/khttpd/logging.c Mon Feb 19 05:27:10 2001 @@ -26,9 +26,11 @@ #include #include #include +#include #include #include "structure.h" #include "prototypes.h" +#include "sysctl.h" /* @@ -42,6 +44,12 @@ that shut down. */ +/* Global variables and prototypes */ +static struct socket *LogSock = NULL; +static DECLARE_MUTEX(LogMutex); + +static int LogRequest(struct http_request *Request); + int Logging(const int CPUNR) { @@ -59,14 +67,20 @@ { Req = CurrentRequest->Next; + + if (LogRequest(CurrentRequest)!=0) + { - CleanUpRequest(CurrentRequest); + CleanUpRequest(CurrentRequest); - threadinfo[CPUNR].LoggingQueue = Req; + threadinfo[CPUNR].LoggingQueue = Req; - CurrentRequest = Req; + CurrentRequest = Req; - count++; + count++; + } + else + CurrentRequest = CurrentRequest->Next; } @@ -91,5 +105,90 @@ } threadinfo[CPUNR].LoggingQueue = NULL; + + down(&LogMutex); + + if (LogSock!=NULL) + { + sock_release(LogSock); + LogSock = NULL; + } + + up(&LogMutex); + LeaveFunction("StopLogging"); +} + + +static int LogRequest(struct http_request *Request) +{ + struct khttpd_loginfo loginfo; + + if (LogSock==NULL) + return 1; + + /* try to aquire the logging mutex */ + if (down_trylock(&LogMutex)) + return 0; + + loginfo.Version = 0x16; + strncpy(loginfo.Filename,Request->FileName,sizeof(loginfo.Filename)); + loginfo.RemoteHost = Request->RemoteHost; + loginfo.Datestamp = Request->RequestTime; + loginfo.Filesize = Request->FileLength; + loginfo.Status = Request->Status; + + if (SendBuffer(LogSock,(char*)&loginfo,sizeof(loginfo))<0) + LogSock = NULL; + + + up(&LogMutex); + return 1; +} + +void InitLogging() +{ + struct socket *sock; + struct sockaddr_un name; + int error,size; + + if (sysctl_khttpd_logging == 0) + return; + + + down(&LogMutex); + + if (LogSock!=NULL) + { + up(&LogMutex); + return; + }; + + error = sock_create(PF_UNIX,SOCK_STREAM,0,&sock); + if (error<0) + { + up(&LogMutex); + return; + } + + /* Now bind the socket */ + + name.sun_family = AF_UNIX; + strcpy(name.sun_path,"/tmp/.khttpdlog"); + + size = sizeof(name); + + error = sock->ops->connect(sock,(struct sockaddr*)&name,size,0); + if (error<0) + { + sysctl_khttpd_logging = 0; + sock_release(sock); + up(&LogMutex); + return; + } + + LogSock = sock; + + up(&LogMutex); + } diff -Nur linux-2.4.1-orgn/net/khttpd/main.c linux/net/khttpd/main.c --- linux-2.4.1-orgn/net/khttpd/main.c Sat Nov 18 09:48:51 2000 +++ linux/net/khttpd/main.c Mon Feb 19 05:36:19 2001 @@ -245,10 +245,17 @@ sysctl_khttpd_threads = ActualThreads; InitUserspace(ActualThreads); + InitLogging(); if (InitDataSending(ActualThreads)!=0) { StopListening(); + I=0; + while (I(64-sizeof(__u32)-sizeof(__kernel_size_t) ) ) + if (strlen(Type)>=(64-sizeof(__u32)-sizeof(__kernel_size_t) ) ) { (void)printk(KERN_ERR "httpd: Mime-string too long.\n"); return; @@ -89,7 +89,7 @@ MimeTypes[atomic_read(&MimeCount)].identifier=*I; - strncpy(MimeTypes[atomic_read(&MimeCount)].type,Type,(64-sizeof(__u32)-sizeof(__kernel_size_t))); + strncpy(MimeTypes[atomic_read(&MimeCount)].type,Type,(64-sizeof(__u32)-sizeof(__kernel_size_t))-1); MimeTypes[atomic_read(&MimeCount)].len = strlen(Type); atomic_inc(&MimeCount); @@ -262,6 +262,8 @@ oldfs = get_fs(); set_fs(KERNEL_DS); len = sock_sendmsg(Request->sock,&msg,len2); set_fs(oldfs); + + Request->Status = 200; LeaveFunction("SendHTTPHeader"); diff -Nur linux-2.4.1-orgn/net/khttpd/structure.h linux/net/khttpd/structure.h --- linux-2.4.1-orgn/net/khttpd/structure.h Tue Dec 12 06:32:10 2000 +++ linux/net/khttpd/structure.h Mon Feb 19 06:03:52 2001 @@ -3,7 +3,7 @@ #include #include - +#include struct http_request; @@ -34,6 +34,9 @@ char IMS[128]; /* If-modified-since time, rfc string format */ char Host[128]; /* Value given by the Host: header */ int HTTPVER; /* HTTP-version; 9 for 0.9, 10 for 1.0 and above */ + int Status; /* HTTP reply status-code */ + int RequestTime; /* Time in unix-format of the request */ + __u32 RemoteHost; /* The IP-address+port of the remote host */ /* Derived date from the above fields */ @@ -64,5 +67,21 @@ }; +/* + +The information in this structure is based on the SpecWeb96 requirements for +logging. + +*/ + +struct khttpd_loginfo +{ + char Version; /* kHTTPd version */ + char Filename[256]; + __u32 RemoteHost; + time_t Datestamp; + int Filesize; + int Status; /* HTTP return status */ +}; #endif diff -Nur linux-2.4.1-orgn/net/khttpd/waitheaders.c linux/net/khttpd/waitheaders.c --- linux-2.4.1-orgn/net/khttpd/waitheaders.c Mon Apr 3 07:53:28 2000 +++ linux/net/khttpd/waitheaders.c Mon Feb 19 06:07:05 2001 @@ -104,6 +104,10 @@ continue; } + /* Store the essential information for logging */ + CurrentRequest->RequestTime = CurrentTime_i; + CurrentRequest->RemoteHost = CurrentRequest->sock->sk->daddr; + /* Remove from WaitForHeaderQueue */ @@ -251,6 +255,7 @@ if (Request->IMS_Time>Request->Time) { /* Not modified since last time */ Send304(Request->sock); + Request->Status = 304; Request->FileLength=0; } else /* Normal Case */