]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Use constant strings for the IP address and user name read from the log file
authorFrederic Marchal <fmarchal@users.sourceforge.net>
Sat, 23 Feb 2013 18:26:30 +0000 (19:26 +0100)
committerFrederic Marchal <fmarchal@users.sourceforge.net>
Sat, 23 Feb 2013 18:26:30 +0000 (19:26 +0100)
download.c
include/defs.h
include/readlog.h
readlog.c
readlog_common.c
readlog_extlog.c
readlog_sarg.c
readlog_squid.c

index 0ff44e76fcf90fbe5cf1a70fe98438a6d2ad80e9..1bf745d17d8696eb79b305d9d9d1c2e13e92a427 100644 (file)
@@ -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
index 5b26370ada2f519f6651a358c29491091b2acfe0..d9453a3678844b14baca4d9cc893ebceb3a417fa 100755 (executable)
@@ -2,7 +2,7 @@
 \brief Declaration of the structures and functions.
 */
 
-#include "readlog.h"
+struct ReadLogStruct;//forward declaration
 
 struct getwordstruct
 {
index e286135c35ab4be429e5558291e8280a8650c494..425a5c9f21410fd55c6de39af750aad5155879cc 100644 (file)
@@ -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.
 
index 60660e5899b4d2ae52235ebd949ca7b316a22dfe..7f041137e804ba791768230c1db479ee2e66052b 100644 (file)
--- 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;
index 7457d9d87275435b2a3888be27d64bc17659665b..03fcae85645ca0d4fc2b992bf17aecb15a7d2990 100644 (file)
@@ -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);
 }
index 93dc172f20fd1e09d1af1bcd2f15a9a06e6deb3c..fbf0dfaf212ec1914a8a7cb408989c48ebee89fa 100644 (file)
@@ -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);
 
index b4adc57d9b4c5b0c404da4cab59f23b802ba6835..fc2356d4540f5432a0e7159fb2ab38e8a3d4add2 100644 (file)
@@ -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);
 }
index 726628509cbf6559c94afb9b16af2f57a6d15ab8..6264b1544f277299240ba03b065b7e232a471a20 100644 (file)
@@ -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);
 }