From: Frederic Marchal Date: Sat, 23 Feb 2013 18:26:30 +0000 (+0100) Subject: Use constant strings for the IP address and user name read from the log file X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f83d7b44070dd37f39e558eb8b5c9a3dcacbf887;p=thirdparty%2Fsarg.git Use constant strings for the IP address and user name read from the log file --- diff --git a/download.c b/download.c index 0ff44e7..1bf745d 100644 --- a/download.c +++ b/download.c @@ -26,6 +26,7 @@ #include "include/conf.h" #include "include/defs.h" +#include "include/readlog.h" /*! The buffer to store the list of the suffixes to take into account when generating diff --git a/include/defs.h b/include/defs.h index 5b26370..d9453a3 100755 --- a/include/defs.h +++ b/include/defs.h @@ -2,7 +2,7 @@ \brief Declaration of the structures and functions. */ -#include "readlog.h" +struct ReadLogStruct;//forward declaration struct getwordstruct { diff --git a/include/readlog.h b/include/readlog.h index e286135..425a5c9 100644 --- a/include/readlog.h +++ b/include/readlog.h @@ -26,9 +26,9 @@ struct ReadLogStruct //! The time corresponding to the entry. struct tm EntryTime; //! The IP address connecting to internet. - char *Ip; + const char *Ip; //! The user's name. - char *User; + const char *User; /*! The URL of the visited site. diff --git a/readlog.c b/readlog.c index 60660e5..7f04113 100644 --- a/readlog.c +++ b/readlog.c @@ -495,7 +495,6 @@ static void ReadOneLogFile(struct ReadLogDataStruct *Filter,const char *arq) if(RecordsWithoutUser == RECORDWITHOUTUSER_EVERYBODY) log_entry.User="everybody"; } else { - strlow(log_entry.User); if(NtlmUserFormat == NTLMUSERFORMAT_USER) { if ((str=strchr(log_entry.User,'+'))!=NULL || (str=strchr(log_entry.User,'\\'))!=NULL || (str=strchr(log_entry.User,'_'))!=NULL) { log_entry.User=str+1; diff --git a/readlog_common.c b/readlog_common.c index 7457d9d..03fcae8 100644 --- a/readlog_common.c +++ b/readlog_common.c @@ -26,6 +26,7 @@ #include "include/conf.h" #include "include/defs.h" +#include "include/readlog.h" /*! A new file is being read. The name of the file is \a FileName. @@ -78,9 +79,11 @@ static enum ReadLogReturnCodeEnum Common_ReadEntry(char *Line,struct ReadLogStru int Hour; int Minute; int Second; + char *Ip; + char *User; // get IP address - Entry->Ip=Line; + Entry->Ip=Ip=Line; for (IpLen=0 ; *Line && *Line!=' ' ; IpLen++) Line++; if (*Line!=' ' || IpLen==0) return(RLRC_Unknown); @@ -92,7 +95,7 @@ static enum ReadLogReturnCodeEnum Common_ReadEntry(char *Line,struct ReadLogStru } // the ID of the user or - if the user is unidentified - Entry->User=++Line; + Entry->User=User=++Line; for (UserLen=0 ; *Line && *Line!=' ' ; UserLen++) Line++; if (*Line!=' ' || UserLen==0) return(RLRC_Unknown); @@ -190,10 +193,10 @@ static enum ReadLogReturnCodeEnum Common_ReadEntry(char *Line,struct ReadLogStru } // 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); } diff --git a/readlog_extlog.c b/readlog_extlog.c index 93dc172..fbf0dfa 100644 --- a/readlog_extlog.c +++ b/readlog_extlog.c @@ -26,6 +26,7 @@ #include "include/conf.h" #include "include/defs.h" +#include "include/readlog.h" /*! Maximum number of columns accepted in an extended log format. @@ -382,7 +383,9 @@ static enum ReadLogReturnCodeEnum ExtLog_ReadEntry(char *Line,struct ReadLogStru { int col; enum ext_col_id col_id; + char *Ip=NULL; char *IpEnd; + char *User=NULL; char *UserEnd; char *UrlEnd; char *HttpCodeEnd; @@ -405,12 +408,12 @@ static enum ReadLogReturnCodeEnum ExtLog_ReadEntry(char *Line,struct ReadLogStru switch (col_id) { case EXTCOL_Ip: - Entry->Ip=Line; + Entry->Ip=Ip=Line; Line=ExtLog_GetString(Line,col,&IpEnd); if (!Line) return(RLRC_Unknown); break; case EXTCOL_UserName: - Entry->User=Line; + Entry->User=User=Line; Line=ExtLog_GetString(Line,col,&UserEnd); if (!Line) return(RLRC_Unknown); break; @@ -460,8 +463,8 @@ static enum ReadLogReturnCodeEnum ExtLog_ReadEntry(char *Line,struct ReadLogStru return(RLRC_InternalError); } - ExtLog_FixString(Entry->Ip,IpEnd); - ExtLog_FixString(Entry->User,UserEnd); + ExtLog_FixString(Ip,IpEnd); + ExtLog_FixString(User,UserEnd); ExtLog_FixString(Entry->Url,UrlEnd); ExtLog_FixString(Entry->HttpCode,HttpCodeEnd); diff --git a/readlog_sarg.c b/readlog_sarg.c index b4adc57..fc2356d 100644 --- a/readlog_sarg.c +++ b/readlog_sarg.c @@ -26,6 +26,7 @@ #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; @@ -66,6 +67,8 @@ 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) { @@ -117,12 +120,12 @@ static enum ReadLogReturnCodeEnum Sarg_ReadEntry(char *Line,struct ReadLogStruct 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); @@ -158,10 +161,10 @@ static enum ReadLogReturnCodeEnum Sarg_ReadEntry(char *Line,struct ReadLogStruct } // 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); } diff --git a/readlog_squid.c b/readlog_squid.c index 7266285..6264b15 100644 --- a/readlog_squid.c +++ b/readlog_squid.c @@ -26,6 +26,7 @@ #include "include/conf.h" #include "include/defs.h" +#include "include/readlog.h" /*! A new file is being read. The name of the file is \a FileName. @@ -53,6 +54,8 @@ static enum ReadLogReturnCodeEnum Squid_ReadEntry(char *Line,struct ReadLogStruc int UrlLen; int UserLen; struct tm *tt; + char *Ip; + char *User; // get log time. Begin=Line; @@ -76,7 +79,7 @@ static enum ReadLogReturnCodeEnum Squid_ReadEntry(char *Line,struct ReadLogStruc if (*Line!=' ' || Line==Begin) return(RLRC_Unknown); // get IP address. It can be a fqdn if that option is enabled in squid. - Entry->Ip=++Line; + Entry->Ip=Ip=++Line; for (IpLen=0 ; *Line && *Line!=' ' ; IpLen++) Line++; if (*Line!=' ' || IpLen==0) return(RLRC_Unknown); @@ -102,7 +105,7 @@ static enum ReadLogReturnCodeEnum Squid_ReadEntry(char *Line,struct ReadLogStruc if (*Line!=' ' || UrlLen==0) return(RLRC_Unknown); // the ID of the user or - if the user is unidentified - Entry->User=++Line; + Entry->User=User=++Line; for (UserLen=0 ; *Line && *Line!=' ' ; UserLen++) Line++; if (*Line!=' ' || UserLen==0) return(RLRC_Unknown); @@ -115,10 +118,10 @@ static enum ReadLogReturnCodeEnum Squid_ReadEntry(char *Line,struct ReadLogStruc memcpy(&Entry->EntryTime,tt,sizeof(struct tm)); // 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); }