]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Allow an empty data size in a common log
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Sun, 26 Aug 2012 15:37:23 +0000 (17:37 +0200)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Sun, 26 Aug 2012 15:37:23 +0000 (17:37 +0200)
Any column of the common log format may be - to denote missing or
no applicable data. In particular, apache writes a - when the URL is a
redirection. That case is taken into account with this patch.

readlog_common.c

index 6c8917a90fe15a86cbdea810258ba8fa8ba93093..39753da8f4ea529e71171f0247dde3d9fcb0f54e 100644 (file)
@@ -34,6 +34,25 @@ static void Common_NewFile(const char *FileName)
 {
 }
 
+/*!
+Extract a column containing a long long int from \a Line.
+
+The extracted value is stored in \a Value.
+
+The pointer to the next byte just after the number is returned
+by the function.
+*/
+static char *Common_GetLongLongInt(char *Line,long long int *Value)
+{
+       *Value=0LL;
+       if (*Line=='-') {
+               ++Line;
+       } else {
+               while (isdigit(*Line)) *Value=*Value*10+(*Line++-'0');
+       }
+       return(Line);
+}
+
 /*!
 Read one entry from a standard squid log format.
 
@@ -160,8 +179,7 @@ static enum ReadLogReturnCodeEnum Common_ReadEntry(char *Line,struct ReadLogStru
 
        // get the number of transfered bytes.
        Begin=++Line;
-       Entry->DataSize=0LL;
-       while (isdigit(*Line)) Entry->DataSize=Entry->DataSize*10+(*Line++-'0');
+       Line=Common_GetLongLongInt(Line,&Entry->DataSize);
        // some log contains more columns
        if ((*Line && *Line!=' ') || Begin==Line) return(RLRC_Unknown);