X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=readlog_squid.c;h=529abc9a5290c20e69332c9137fea30d2b6b5bf0;hb=563609cca18d31e264adeb674fe133347f0aa725;hp=6717198b09b1163ce5d475cec7f2ffaa9a2ad21c;hpb=bd43d81faa4dbf3000558431dc94b1d69dc6e636;p=thirdparty%2Fsarg.git diff --git a/readlog_squid.c b/readlog_squid.c index 6717198..529abc9 100644 --- a/readlog_squid.c +++ b/readlog_squid.c @@ -1,6 +1,6 @@ /* * SARG Squid Analysis Report Generator http://sarg.sourceforge.net - * 1998, 2012 + * 1998, 2015 * * SARG donations: * please look at http://sarg.sourceforge.net/donations.php @@ -26,6 +26,7 @@ #include "include/conf.h" #include "include/defs.h" +#include "include/readlog.h" /*! A new file is being read. The name of the file is \a FileName. @@ -50,9 +51,12 @@ static enum ReadLogReturnCodeEnum Squid_ReadEntry(char *Line,struct ReadLogStruc time_t log_time; int IpLen; int HttpCodeLen; + int HttpMethodLen; int UrlLen; int UserLen; struct tm *tt; + char *Ip; + char *User; // get log time. Begin=Line; @@ -67,16 +71,31 @@ static enum ReadLogReturnCodeEnum Squid_ReadEntry(char *Line,struct ReadLogStruc // skip spaces before the elapsed time. while (*Line==' ') Line++; - if (!isdigit(*Line)) return(RLRC_Unknown); // get the elapsed time. Begin=Line; Entry->ElapsedTime=0L; - while (isdigit(*Line)) Entry->ElapsedTime=Entry->ElapsedTime*10+(*Line++-'0'); + if (*Line=='-') + { + /* + * Negative elapsed time happens in squid (see + * http://www.squid-cache.org/mail-archive/squid-users/200711/0192.html) + * but no answer were provided as to why it happens. Let's just + * assume a zero elapsed time and ignore every following digit. + */ + Line++; + if (!isdigit(*Line)) return(RLRC_Unknown); + while (isdigit(*Line)) Line++; + } + else + { + if (!isdigit(*Line)) return(RLRC_Unknown); + while (isdigit(*Line)) Entry->ElapsedTime=Entry->ElapsedTime*10+(*Line++-'0'); + } if (*Line!=' ' || Line==Begin) return(RLRC_Unknown); // get IP address. It can be a fqdn if that option is enabled in squid. - Entry->Ip=++Line; + Entry->Ip=Ip=++Line; for (IpLen=0 ; *Line && *Line!=' ' ; IpLen++) Line++; if (*Line!=' ' || IpLen==0) return(RLRC_Unknown); @@ -91,10 +110,10 @@ static enum ReadLogReturnCodeEnum Squid_ReadEntry(char *Line,struct ReadLogStruc while (isdigit(*Line)) Entry->DataSize=Entry->DataSize*10+(*Line++-'0'); if (*Line!=' ' || Begin==Line) return(RLRC_Unknown); - // skip the HTTP function - Begin=++Line; - while (*Line && *Line!=' ') Line++; - if (*Line!=' '|| Line==Begin) return(RLRC_Unknown); + // get the HTTP method + Entry->HttpMethod=++Line; + for (HttpMethodLen=0 ; *Line && *Line!=' ' ; HttpMethodLen++) Line++; + if (*Line!=' '|| HttpMethodLen==0) return(RLRC_Unknown); // the url Entry->Url=++Line; @@ -102,23 +121,24 @@ static enum ReadLogReturnCodeEnum Squid_ReadEntry(char *Line,struct ReadLogStruc if (*Line!=' ' || UrlLen==0) return(RLRC_Unknown); // the ID of the user or - if the user is unidentified - Entry->User=++Line; + Entry->User=User=++Line; for (UserLen=0 ; *Line && *Line!=' ' ; UserLen++) Line++; if (*Line!=' ' || UserLen==0) return(RLRC_Unknown); // now, the format is known with a good confidence. If the time doesn't decode, it is an error. tt=localtime(&log_time); if (tt==NULL) { - debuga(_("Cannot convert the timestamp from the squid log file\n")); + debuga(__FILE__,__LINE__,_("Cannot convert the timestamp from the squid log file\n")); return(RLRC_InternalError); } memcpy(&Entry->EntryTime,tt,sizeof(struct tm)); // it is safe to alter the line buffer now that we are returning a valid entry - Entry->Ip[IpLen]='\0'; + Ip[IpLen]='\0'; Entry->HttpCode[HttpCodeLen]='\0'; + Entry->HttpMethod[HttpMethodLen]='\0'; Entry->Url[UrlLen]='\0'; - Entry->User[UserLen]='\0'; + User[UserLen]='\0'; return(RLRC_NoError); }