]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Store the entry time in a structure instead of a pointer
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Sun, 26 Aug 2012 09:18:52 +0000 (11:18 +0200)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Sun, 26 Aug 2012 09:18:52 +0000 (11:18 +0200)
Instead of requiring that the module keeps track of the entry time on
behalf of the main loop, the entry time is stored in the entry structure.
Therefore, there is no need to keep a static variable inside the module
and pass its pointer to the caller.

authfail.c
denied.c
include/readlog.h
readlog.c
readlog_common.c
readlog_sarg.c
readlog_squid.c

index 7741e14f502e88f6bad5d5648901826d8e64fbd4..5250796db4bf0492a521d2b741c75f9bb1fc9e1d 100644 (file)
@@ -69,7 +69,7 @@ void authfail_write(const struct ReadLogStruct *log_entry)
        char date[80];
        
        if (fp_authfail && (strstr(log_entry->HttpCode,"DENIED/401") != 0 || strstr(log_entry->HttpCode,"DENIED/407") != 0)) {
-               strftime(date,sizeof(date),"%d/%m/%Y\t%H:%M:%S",log_entry->EntryTime);
+               strftime(date,sizeof(date),"%d/%m/%Y\t%H:%M:%S",&log_entry->EntryTime);
                fprintf(fp_authfail, "%s\t%s\t%s\t%s\n",date,log_entry->User,log_entry->Ip,log_entry->Url);
                authfail_exists=true;
        }
index e483afe0383d993338a5317ee7d30feea7258426..67fd1774aeb1bb563343ff191fd1fea24e3bf094 100644 (file)
--- a/denied.c
+++ b/denied.c
@@ -69,7 +69,7 @@ void denied_write(const struct ReadLogStruct *log_entry)
        char date[80];
        
        if (fp_denied && strstr(log_entry->HttpCode,"DENIED/403") != 0) {
-               strftime(date,sizeof(date),"%d/%m/%Y\t%H:%M:%S",log_entry->EntryTime);
+               strftime(date,sizeof(date),"%d/%m/%Y\t%H:%M:%S",&log_entry->EntryTime);
                fprintf(fp_denied, "%s\t%s\t%s\t%s\n",date,log_entry->User,log_entry->Ip,log_entry->Url);
                denied_exists=true;
        }
index f895064586e7b89cb8d4fdb8ecedcb5d0dc3c1f3..8e18b5bd56d2b905272d8477fa8a81aa1d9a0c82 100644 (file)
@@ -24,7 +24,7 @@ enum ReadLogReturnCodeEnum
 struct ReadLogStruct
 {
        //! The time corresponding to the entry.
-       struct tm *EntryTime;
+       struct tm EntryTime;
        //! The IP address connecting to internet.
        char *Ip;
        //! The user's name.
index 1de337d3214d25fa4776c17ffa3baea98b11abdb..fcd51718189ddb3c5c5f0c2c207f51db4ea01e21 100644 (file)
--- a/readlog.c
+++ b/readlog.c
@@ -669,10 +669,6 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
                                log_entry.EntryTime=&tt;
                        }
 #endif
-                       if (log_entry.EntryTime==NULL) {
-                               debuga(_("Unknown input log file format: no time\n"));
-                               break;
-                       }
                        if (log_entry.Ip==NULL) {
                                debuga(_("Unknown input log file format: no IP addresses\n"));
                                break;
@@ -694,10 +690,10 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
                        }
 
                        // Record only hours usage which is required
-                       if( bsearch( &( log_entry.EntryTime->tm_wday ), weekdays.list, weekdays.len, sizeof( int ), compar ) == NULL )
+                       if( bsearch( &( log_entry.EntryTime.tm_wday ), weekdays.list, weekdays.len, sizeof( int ), compar ) == NULL )
                                continue;
 
-                       if( bsearch( &( log_entry.EntryTime->tm_hour ), hours.list, hours.len, sizeof( int ), compar ) == NULL )
+                       if( bsearch( &( log_entry.EntryTime.tm_hour ), hours.list, hours.len, sizeof( int ), compar ) == NULL )
                                continue;
 
 
@@ -757,7 +753,7 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
                        }
 
                        if(Filter->StartTime >= 0 && Filter->EndTime >= 0) {
-                               hmr=log_entry.EntryTime->tm_hour*100+log_entry.EntryTime->tm_min;
+                               hmr=log_entry.EntryTime.tm_hour*100+log_entry.EntryTime.tm_min;
                                if(hmr < Filter->StartTime || hmr > Filter->EndTime) continue;
                        }
 
@@ -879,8 +875,8 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
                                }
                        }
 
-                       strftime(dia, sizeof(dia), "%d/%m/%Y", log_entry.EntryTime);
-                       strftime(hora,sizeof(hora),"%H:%M:%S",log_entry.EntryTime);
+                       strftime(dia, sizeof(dia), "%d/%m/%Y",&log_entry.EntryTime);
+                       strftime(hora,sizeof(hora),"%H:%M:%S",&log_entry.EntryTime);
 
                        if (fprintf(ufile->file, "%s\t%s\t%s\t%s\t%"PRIu64"\t%s\t%ld\t%s\n",dia,hora,
                                    log_entry.Ip,url,(uint64_t)log_entry.DataSize,
@@ -916,12 +912,12 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
                        if (current_format!=&ReadSargLog) {
                                if(!totper || idata<mindate){
                                        mindate=idata;
-                                       memcpy(&period.start,log_entry.EntryTime,sizeof(*log_entry.EntryTime));
+                                       memcpy(&period.start,&log_entry.EntryTime,sizeof(log_entry.EntryTime));
                                        strcpy(start_hour,tbuf2);
                                }
                                if (!totper || idata>maxdate) {
                                        maxdate=idata;
-                                       memcpy(&period.end,log_entry.EntryTime,sizeof(*log_entry.EntryTime));
+                                       memcpy(&period.end,&log_entry.EntryTime,sizeof(log_entry.EntryTime));
                                }
                                totper=true;
                        }
index 2a53130bda8a62d710574bd03ab56edc63c1e690..5cd1074f27c54907e0d9e493ebcaef2add996436 100644 (file)
@@ -59,7 +59,6 @@ static enum ReadLogReturnCodeEnum Common_ReadEntry(char *Line,struct ReadLogStru
        int Hour;
        int Minute;
        int Second;
-       static struct tm tt;
 
        // get IP address
        Entry->Ip=Line;
@@ -123,13 +122,12 @@ static enum ReadLogReturnCodeEnum Common_ReadEntry(char *Line,struct ReadLogStru
        while (*Line && *Line!=']') Line++;
        if (*Line!=']') return(RLRC_Unknown);
        
-       tt.tm_year=Year-1900;
-       tt.tm_mon=Month;
-       tt.tm_mday=Day;
-       tt.tm_hour=Hour;
-       tt.tm_min=Minute;
-       tt.tm_sec=Second;
-       Entry->EntryTime=&tt;
+       Entry->EntryTime.tm_year=Year-1900;
+       Entry->EntryTime.tm_mon=Month;
+       Entry->EntryTime.tm_mday=Day;
+       Entry->EntryTime.tm_hour=Hour;
+       Entry->EntryTime.tm_min=Minute;
+       Entry->EntryTime.tm_sec=Second;
 
        // the URL is enclosed between double qhotes
        ++Line;
index 7eda5b4a745fce74a224abc9a76643fabbed4c55..015b2d61af018e7ad830af4b668cf3875691f845 100644 (file)
@@ -61,7 +61,6 @@ static enum ReadLogReturnCodeEnum Sarg_ReadEntry(char *Line,struct ReadLogStruct
        int Hour;
        int Minute;
        int Second;
-       static struct tm tt;
        
        if (strncmp(Line,"*** SARG Log ***",16)==0) {
                InSargLog=true;
@@ -99,13 +98,12 @@ static enum ReadLogReturnCodeEnum Sarg_ReadEntry(char *Line,struct ReadLogStruct
        while (isdigit(*Line)) Second=Second*10+(*Line++-'0');
        if (*Line!='\t' || Second>60) return(RLRC_Unknown); //second can be 60 due to a leap second
 
-       tt.tm_year=Year-1900;
-       tt.tm_mon=Month-1;
-       tt.tm_mday=Day;
-       tt.tm_hour=Hour;
-       tt.tm_min=Minute;
-       tt.tm_sec=Second;
-       Entry->EntryTime=&tt;
+       Entry->EntryTime.tm_year=Year-1900;
+       Entry->EntryTime.tm_mon=Month-1;
+       Entry->EntryTime.tm_mday=Day;
+       Entry->EntryTime.tm_hour=Hour;
+       Entry->EntryTime.tm_min=Minute;
+       Entry->EntryTime.tm_sec=Second;
 
        // the ID of the user
        Entry->User=++Line;
index a83ecd6832e963d23e5893b01e62482e385bfc21..a7ac4b7191ad64fd55c5a15e1cbb1d27f2a55f16 100644 (file)
@@ -52,6 +52,7 @@ static enum ReadLogReturnCodeEnum Squid_ReadEntry(char *Line,struct ReadLogStruc
        int HttpCodeLen;
        int UrlLen;
        int UserLen;
+       struct tm *tt;
        
        // get log time.
        Begin=Line;
@@ -106,11 +107,12 @@ static enum ReadLogReturnCodeEnum Squid_ReadEntry(char *Line,struct ReadLogStruc
        if (*Line!=' ' || UserLen==0) return(RLRC_Unknown);
        
        // now, the format is known with a good confidence. If the time doesn't decode, it is an error.
-       Entry->EntryTime=localtime(&log_time);
-       if (Entry->EntryTime == NULL) {
+       tt=localtime(&log_time);
+       if (tt==NULL) {
                debuga(_("Cannot convert the timestamp from the squid log file\n"));
                return(RLRC_InternalError);
        }
+       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';