]> git.ipfire.org Git - thirdparty/sarg.git/blobdiff - readlog_sarg.c
Update the man page
[thirdparty/sarg.git] / readlog_sarg.c
index 015b2d61af018e7ad830af4b668cf3875691f845..c60ff285d0f1340b3cefddf778f0b44abf2a9988 100644 (file)
@@ -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
 
 #include "include/conf.h"
 #include "include/defs.h"
+#include "include/readlog.h"
 
 //! \c True if the current log is known to be a sarg parsed log.
 static bool InSargLog=false;
+//! \c True if the file name is invalid.
+static bool InvalidFileName=true;
+//! The last period extracted from the log file name.
+static struct periodstruct SargPeriod;
 
 /*!
 A new file is being read. The name of the file is \a FileName.
@@ -36,6 +41,7 @@ A new file is being read. The name of the file is \a FileName.
 static void Sarg_NewFile(const char *FileName)
 {
        InSargLog=false;
+       InvalidFileName=(getperiod_fromsarglog(FileName,&SargPeriod)<0);
 }
 
 /*!
@@ -61,13 +67,20 @@ static enum ReadLogReturnCodeEnum Sarg_ReadEntry(char *Line,struct ReadLogStruct
        int Hour;
        int Minute;
        int Second;
-       
+       char *Ip;
+       char *User;
+
        if (strncmp(Line,"*** SARG Log ***",16)==0) {
+               if (InvalidFileName) {
+                       debuga(__FILE__,__LINE__,_("The name of the file is invalid for a sarg log\n"));
+                       exit(EXIT_FAILURE);
+               }
+               getperiod_merge(&period,&SargPeriod);
                InSargLog=true;
                return(RLRC_Ignore);
        }
        if (!InSargLog) return(RLRC_Unknown);
-       
+
        // get the date
        Day=0;
        while (isdigit(*Line)) Day=Day*10+(*Line++-'0');
@@ -83,7 +96,7 @@ static enum ReadLogReturnCodeEnum Sarg_ReadEntry(char *Line,struct ReadLogStruct
        Year=0;
        while (isdigit(*Line)) Year=Year*10+(*Line++-'0');
        if (*Line!='\t' || Year<1900 || Year>2200) return(RLRC_Unknown);
-       
+
        // get the time
        ++Line;
        Hour=0;
@@ -104,14 +117,15 @@ static enum ReadLogReturnCodeEnum Sarg_ReadEntry(char *Line,struct ReadLogStruct
        Entry->EntryTime.tm_hour=Hour;
        Entry->EntryTime.tm_min=Minute;
        Entry->EntryTime.tm_sec=Second;
+       Entry->EntryTime.tm_isdst=-1;
 
        // the ID of the user
-       Entry->User=++Line;
+       Entry->User=User=++Line;
        for (UserLen=0 ; *Line && *Line!='\t' ; UserLen++) Line++;
        if (*Line!='\t' || UserLen==0) return(RLRC_Unknown);
-       
+
        // get IP address
-       Entry->Ip=++Line;
+       Entry->Ip=Ip=++Line;
        for (IpLen=0 ; *Line && *Line!='\t' ; IpLen++) Line++;
        if (*Line!='\t' || IpLen==0) return(RLRC_Unknown);
 
@@ -119,13 +133,13 @@ static enum ReadLogReturnCodeEnum Sarg_ReadEntry(char *Line,struct ReadLogStruct
        Entry->Url=++Line;
        for (UrlLen=0 ; *Line && *Line!='\t' ; UrlLen++) Line++;
        if (*Line!='\t' || UrlLen==0) return(RLRC_Unknown);
-       
+
        // get the number of transfered bytes.
        Begin=++Line;
        Entry->DataSize=0LL;
        while (isdigit(*Line)) Entry->DataSize=Entry->DataSize*10+(*Line++-'0');
        if (*Line!='\t' || Begin==Line) return(RLRC_Unknown);
-       
+
        // get the HTTP code.
        Entry->HttpCode=++Line;
        for (HttpCodeLen=0 ; *Line && *Line!='\t' ; HttpCodeLen++) Line++;
@@ -138,13 +152,20 @@ static enum ReadLogReturnCodeEnum Sarg_ReadEntry(char *Line,struct ReadLogStruct
        if (*Line!='\t' || Line==Begin) return(RLRC_Unknown);
 
        // get the smart filter
-       
+       //! \bug Smart filter ignored from sarg log format.
+
+       // check the entry time
+       if (mktime(&Entry->EntryTime)==-1) {
+               debuga(__FILE__,__LINE__,_("Invalid date or time found in the common log file\n"));
+               return(RLRC_InternalError);
+       }
+
        // 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->Url[UrlLen]='\0';
-       Entry->User[UserLen]='\0';
-       
+       User[UserLen]='\0';
+
        return(RLRC_NoError);
 }