]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
The reported user agent report date was wrong
authorFrederic Marchal <fmarchal@users.sourceforge.net>
Sun, 1 Nov 2015 16:11:32 +0000 (17:11 +0100)
committerFrederic Marchal <fmarchal@users.sourceforge.net>
Sun, 1 Nov 2015 16:11:32 +0000 (17:11 +0100)
At the top of the user agent report, the period covered by the report was
wrong when the entries were coming from an extended log or when several
useragent.log files were provided with the useragent option in sarg.conf.

Thanks to Evgeniy Yakushev for reporting this bug.

include/defs.h
readlog.c
useragent.c
util.c

index 26a1c4cb6f0c331ba9601aa0548dc84862f0bc59..17d2ab3d12a1cd8aa5e4a0dfbaabb7c27870df4a 100644 (file)
@@ -337,7 +337,7 @@ void usage(const char *prog);
 
 // useragent.c
 FILE *UserAgent_Open(void);
-void UserAgent_Write(FILE *fp,const char *Ip,const char *User,const char *Agent);
+void UserAgent_Write(FILE *fp,const struct tm *Time,const char *Ip,const char *User,const char *Agent);
 void UserAgent_Readlog(void);
 void UserAgent(void);
 
@@ -420,7 +420,7 @@ char *strlow(char *string);
 char *strup(char *string);
 int month2num(const char *month);
 int builddia(int day, int month, int year);
-int compare_date(struct tm *date1,struct tm *date2);
+int compare_date(const struct tm *date1,const struct tm *date2);
 bool IsTreeFileDirName(const char *Name);
 bool IsTreeYearFileName(const char *Name);
 bool IsTreeMonthFileName(const char *Name);
index 3805de0cb35f4355509a154933aa6fe797108e72..1b66c49a9122c1a2d57be3e703eb01d5ab1432b1 100644 (file)
--- a/readlog.c
+++ b/readlog.c
@@ -719,7 +719,7 @@ static void ReadOneLogFile(struct ReadLogDataStruct *Filter,const char *arq)
                {
                        if (!UseragentLog)
                                UseragentLog=UserAgent_Open();
-                       UserAgent_Write(UseragentLog,log_entry.Ip,log_entry.User,log_entry.UserAgent);
+                       UserAgent_Write(UseragentLog,&log_entry.EntryTime,log_entry.Ip,log_entry.User,log_entry.UserAgent);
                }
 
                if (log_line.current_format!=&ReadSargLog) {
index 11934204afd0a7d1a43a6cc4ff46df007a986067..c95c2fdf54673a0ea19ef246324f7404d2812fae 100644 (file)
@@ -71,9 +71,13 @@ FILE *UserAgent_Open(void)
  * \param User The user name.
  * \param Agent The user agent string.
  */
-void UserAgent_Write(FILE *fp,const char *Ip,const char *User,const char *Agent)
+void UserAgent_Write(FILE *fp,const struct tm *Time,const char *Ip,const char *User,const char *Agent)
 {
        if (fp) {
+               if (useragent_count==0 || compare_date(&UserAgentStartDate,Time)>0)
+                       memcpy(&UserAgentStartDate,Time,sizeof(UserAgentStartDate));
+               if (useragent_count==0 || compare_date(&UserAgentEndDate,Time)<0)
+                       memcpy(&UserAgentEndDate,Time,sizeof(UserAgentEndDate));
                fprintf(fp,"%s\t%s\t%s\n",Ip,Agent,User);
                useragent_count++;
        }
@@ -150,10 +154,6 @@ void UserAgent_Readlog(void)
                        logtime.tm_year=year-1900;
                        logtime.tm_mon=month-1;
                        logtime.tm_mday=day;
-                       if (totregsl==1 || compare_date(&UserAgentStartDate,&logtime)>0)
-                               memcpy(&UserAgentStartDate,&logtime,sizeof(logtime));
-                       if (compare_date(&UserAgentEndDate,&logtime)<0)
-                               memcpy(&UserAgentEndDate,&logtime,sizeof(logtime));
                        if (getword_skip(MAXLEN,&gwarea,'"')<0 || getword(agent,sizeof(agent),&gwarea,'"')<0) {
                                debuga(__FILE__,__LINE__,_("Invalid useragent in file \"%s\"\n"),FileName);
                                exit(EXIT_FAILURE);
@@ -172,7 +172,7 @@ void UserAgent_Readlog(void)
                                strcpy(user,ip);
                        }
 
-                       UserAgent_Write(fp_ou,ip,user,agent);
+                       UserAgent_Write(fp_ou,&logtime,ip,user,agent);
                }
 
                if (FileObject_Close(fp_log)==EOF) {
diff --git a/util.c b/util.c
index 0a48ffe3dde6d556b978e808ca1c6dcfbbee4605..cdcbf1689649a20158c5511470fc57060903d7f2 100644 (file)
--- a/util.c
+++ b/util.c
@@ -507,7 +507,7 @@ Compare two dates.
 \retval 0 If date1==date2.
 \retval 1 if date1>date2.
 */
-int compare_date(struct tm *date1,struct tm *date2)
+int compare_date(const struct tm *date1,const struct tm *date2)
 {
        if (date1->tm_year<date2->tm_year) return(-1);
        if (date1->tm_year>date2->tm_year) return(1);