From: Frédéric Marchal Date: Wed, 14 Sep 2011 07:35:05 +0000 (+0000) Subject: Fix a sorting issue in the DansGuardian log X-Git-Tag: v2.3.2~22 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2f1416e822b09aefd5d08a9d6b0e47d54f0cca3d;p=thirdparty%2Fsarg.git Fix a sorting issue in the DansGuardian log Times with a one digit hour must be sorted before the times with two digits. To fix this issue, a padding zero is prefixed to the hour if it contains only one digit. Thanks to Iain Lopata for the patch. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index c4b5b21..4ec2ef5 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ PROJECT(sarg C) SET(sarg_VERSION 2) SET(sarg_REVISION "3.2-pre2") SET(sarg_BUILD "") -SET(sarg_BUILDDATE "Sep-02-2011") +SET(sarg_BUILDDATE "Sep-14-2011") INCLUDE(AddFileDependencies) INCLUDE(CheckIncludeFile) diff --git a/dansguardian_log.c b/dansguardian_log.c index 3b27f4b..203d603 100644 --- a/dansguardian_log.c +++ b/dansguardian_log.c @@ -35,7 +35,8 @@ void dansguardian_log(void) char guard_ou[MAXLEN]; char loglocation[MAXLEN] = "/var/log/dansguardian/access.log"; int year, mon, day; - char hour[15]; + int hour; + char minsec[15]; char user[MAXLEN], code1[255], code2[255]; char ip[45]; char *url; @@ -93,9 +94,23 @@ void dansguardian_log(void) continue; getword_start(&gwarea,buf); if (getword_atoi(&year,&gwarea,'.')<0 || getword_atoi(&mon,&gwarea,'.')<0 || - getword_atoi(&day,&gwarea,' ')<0 || getword(hour,sizeof(hour),&gwarea,' ')<0 || - getword(user,sizeof(user),&gwarea,' ')<0 || getword(ip,sizeof(ip),&gwarea,' ')<0 || - getword_skip(MAXLEN,&gwarea,'/')<0 || getword_skip(MAXLEN,&gwarea,'/')<0) { + getword_atoi(&day,&gwarea,' ')<0) { + debuga(_("Invalid date found in your dansguardian log file %s\n"),loglocation); + exit(EXIT_FAILURE); + } + if (getword_atoi(&hour,&gwarea,':')<0 || getword(minsec,sizeof(minsec),&gwarea,' ')<0) { + debuga(_("Invalid time found in your dansguardian log file %s\n"),loglocation); + exit(EXIT_FAILURE); + } + if (getword(user,sizeof(user),&gwarea,' ')<0) { + debuga(_("Invalid user found in your dansguardian log file %s\n"),loglocation); + exit(EXIT_FAILURE); + } + if (getword(ip,sizeof(ip),&gwarea,' ')<0) { + debuga(_("Invalid IP address found in your dansguardian log file %s\n"),loglocation); + exit(EXIT_FAILURE); + } + if (getword_skip(MAXLEN,&gwarea,'/')<0 || getword_skip(MAXLEN,&gwarea,'/')<0) { debuga(_("Maybe you have a broken record or garbage in your %s file\n"),loglocation); exit(EXIT_FAILURE); } @@ -119,7 +134,7 @@ void dansguardian_log(void) strcpy(user,ip); ip[0]='\0'; } - fprintf(fp_ou,"%s\t%d\t%s\t%s\t%s\t%s\t%s\n",user,idata,hour,ip,url,code1,code2); + fprintf(fp_ou,"%s\t%d\t%02d:%s\t%s\t%s\t%s\t%s\n",user,idata,hour,minsec,ip,url,code1,code2); dansguardian_count++; } diff --git a/include/info.h b/include/info.h index 8981c4c..27b518a 100755 --- a/include/info.h +++ b/include/info.h @@ -1,3 +1,3 @@ -#define VERSION PACKAGE_VERSION" Sep-02-2011" +#define VERSION PACKAGE_VERSION" Sep-14-2011" #define PGM PACKAGE_NAME #define URL "http://sarg.sourceforge.net"