From: Frédéric Marchal Date: Sun, 26 Aug 2012 15:37:23 +0000 (+0200) Subject: Allow an empty data size in a common log X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9cf9607190878d22ab5eca93e6c8018965194c17;p=thirdparty%2Fsarg.git Allow an empty data size in a common log 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. --- diff --git a/readlog_common.c b/readlog_common.c index 6c8917a..39753da 100644 --- a/readlog_common.c +++ b/readlog_common.c @@ -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);