From: Frédéric Marchal Date: Tue, 1 Dec 2009 19:46:01 +0000 (+0000) Subject: Allow multiple headers in an ISA log. X-Git-Tag: v2_2_7~70 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=076cbab80cd7f51f88d56ae1e29fbf77da5f89bf;p=thirdparty%2Fsarg.git Allow multiple headers in an ISA log. Introduce getword_skip to skip a word without storing it in a buffer. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 4fa0ae6..bbba5b7 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ PROJECT(sarg C) SET(sarg_VERSION 2) SET(sarg_REVISION 2) SET(sarg_BUILD "7rc1") -SET(sarg_BUILDDATE "Nov-28-2009") +SET(sarg_BUILDDATE "Dec-01-2009") INCLUDE(AddFileDependencies) INCLUDE(CheckIncludeFile) diff --git a/documentation/util.txt b/documentation/util.txt index b544a9f..5b872de 100644 --- a/documentation/util.txt +++ b/documentation/util.txt @@ -28,7 +28,7 @@ the function displays an error message and returns an error code. \param stop The character indicating the end of the word. \retval 0 The word is extracted. -\retval -1 The stop character was not found before the limit or the end of the string is reached. +\retval -1 The stop character was not found before the limit is reached. */ @@ -50,27 +50,24 @@ the function displays an error message and returns an error code. \param stop The character indicating the end of the word. \retval 0 The word is extracted. -\retval -1 The stop character was not found before the limit or the end of the string is reached. +\retval -1 The stop character was not found before the limit is reached. */ +/*! \fn int getword_skip(int limit, char *line, int stop) +Skip one "word" from the text line and remove it from the text line. The word's boundary is defined +by the \a stop character. -/*! \fn int getword3(char *word, int limit, char *line, int stop) - -This function is now identical to getword(). - -\param word The buffer to store the extracted word. -\param limit The size of the buffer. If the stop character isn't found before that limit is reached, +\param limit The maximum number of characters to skip. If the stop character isn't found before that limit is reached, the function displays an error message and returns an error code. \param line The text line from which the word must be extracted. \param stop The character indicating the end of the word. -\retval 0 The word is extracted. -\retval -1 The stop character was not found before the limit or the end of the string is reached. - +\retval 0 The word is skipped. +\retval -1 The stop character was not found before the limit is reached. */ diff --git a/include/defs.h b/include/defs.h index b450534..4ce1f9b 100755 --- a/include/defs.h +++ b/include/defs.h @@ -115,6 +115,7 @@ void useragent(void); // util.c int getword(char *word, int limit, char *line, int stop); int getword_multisep(char *word, int limit, char *line, int stop); +int getword_skip(int limit, char *line, int stop); void name_month(char *month,int month_len); void conv_month_name(char *month); void buildymd(const char *dia, const char *mes, const char *ano, char *wdata); diff --git a/include/info.h b/include/info.h index 2b62dfe..734a073 100755 --- a/include/info.h +++ b/include/info.h @@ -1,3 +1,3 @@ -#define VERSION PACKAGE_VERSION" Nov-28-2009" +#define VERSION PACKAGE_VERSION" Dec-01-2009" #define PGM PACKAGE_NAME #define URL "http://sarg.sourceforge.net" diff --git a/log.c b/log.c index 88b3b24..b723be9 100644 --- a/log.c +++ b/log.c @@ -45,6 +45,17 @@ static void getuexclude(const char *uexfile, int debug); int main(int argc,char *argv[]) { + enum isa_col_id { + ISACOL_Ip, + ISACOL_UserName, + ISACOL_Date, + ISACOL_Time, + ISACOL_TimeTaken, + ISACOL_Bytes, + ISACOL_Uri, + ISACOL_Status, + ISACOL_Last //last entry of the list ! + }; FILE *fp_in = NULL, *fp_denied=NULL, *fp_authfail=NULL, *fp_log=NULL; @@ -104,7 +115,7 @@ int main(int argc,char *argv[]) int narq=0; int iarq=0; int exstring=0; - int i0=0,i1=-1,i2=-1,i3=-1,i4=-1,i5=-1,i6=-1,i7=-1,i8=-1; + int isa_ncols=0,isa_cols[ISACOL_Last]; long totregsl=0; long totregsg=0; long totregsx=0; @@ -945,84 +956,88 @@ int main(int argc,char *argv[]) exit(1); } } else if(isalog) { - if(!i0) { - if (getword(val1,sizeof(val1),bufz,' ')<0){ + if (bufz[0] == '#') { + int ncols,cols[ISACOL_Last]; + + fixendofline(bufz); + // remove the #Fields: column at the beginning of the line + if (getword_skip(1000,bufz,' ')<0){ printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arq); exit(1); } - fixendofline(bufz); + for (ncols=0 ; ncols=0) { + isa_ncols=ncols; + for (isa_ncols=0 ; isa_ncols=sizeof(ip)) { printf("SARG: Maybe you have a broken IP in your %s file.\n",arq); exit(1); } strcpy(ip,val1); - } else if (x==i2) { + } else if (x==isa_cols[ISACOL_UserName]) { if (strlen(val1)>=sizeof(user)) { printf("SARG: Maybe you have a broken user in your %s file.\n",arq); exit(1); } strcpy(user,val1); - } else if (x==i3) { + } else if (x==isa_cols[ISACOL_Date]) { if (strlen(val1)>=sizeof(data)) { printf("SARG: Maybe you have a broken date in your %s file.\n",arq); exit(1); } strcpy(data,val1); - } else if (x==i4) { + } else if (x==isa_cols[ISACOL_Time]) { if (strlen(val1)>=sizeof(hora)) { printf("SARG: Maybe you have a broken time in your %s file.\n",arq); exit(1); } strcpy(hora,val1); - } else if (x==i5) { + } else if (x==isa_cols[ISACOL_TimeTaken]) { if (strlen(val1)>=sizeof(elap)) { printf("SARG: Maybe you have a broken download duration in your %s file.\n",arq); exit(1); } strcpy(elap,val1); - } else if (x==i6) { + } else if (x==isa_cols[ISACOL_Bytes]) { if (strlen(val1)>=sizeof(tam)) { printf("SARG: Maybe you have a broken download size in your %s file.\n",arq); exit(1); } strcpy(tam,val1); - } else if (x==i7) { + } else if (x==isa_cols[ISACOL_Uri]) { if (strlen(val1)>=sizeof(url)) { printf("SARG: Maybe you have a broken URL in your %s file.\n",arq); exit(1); } strcpy(url,val1); - } else if (x==i8) { + } else if (x==isa_cols[ISACOL_Status]) { if (strlen(val1)>=sizeof(code)) { printf("SARG: Maybe you have a broken access code in your %s file.\n",arq); exit(1); diff --git a/util.c b/util.c index cee9667..88ed598 100644 --- a/util.c +++ b/util.c @@ -111,6 +111,27 @@ int getword_multisep(char *word, int limit, char *line, int stop) return(0); } +int getword_skip(int limit, char *line, int stop) +{ + int x,y; + + for(x=0;((line[x]) && (line[x] != stop ));x++) { + if(x>=limit) { + printf("SARG: getword_skip loop detected after %d bytes.\n",x); + printf("SARG: Record=\"%s\"\n",line); + printf("SARG: searching for \'x%x\'\n",stop); + //printf("SARG: Maybe you have a broken record or garbage in your access.log file.\n"); + return(-1); + } + } + + if (line[x]) ++x; + y=0; + + while((line[y++] = line[x++])); + return(0); +} + #ifdef LEGACY_MY_ATOLL