]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Store the date and time in a structure
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Tue, 3 Jul 2012 10:12:44 +0000 (12:12 +0200)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Tue, 3 Jul 2012 10:12:44 +0000 (12:12 +0200)
The purpose is to store all the fields in a structure that will be
exchanged with modules to read many more type of log files.

readlog.c

index 8b7fb9611dccf216b60d7a90b113a796296e7e4f..aa14807dda40a3ef08e61e74d19e1ffc5b925e82 100644 (file)
--- a/readlog.c
+++ b/readlog.c
@@ -89,7 +89,7 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
        char hora[30];
        char mes[30];
        char tbuf2[128];
-       char dia[128];
+       char dia[128]="";
        char wuser[MAXLEN];
        char tmp3[MAXLEN];
        char sz_Download_Unsort[20000];
@@ -131,13 +131,13 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
        bool totper=false;
        struct stat logstat;
        struct getwordstruct gwarea;
-       struct tm *t;
        struct tm tt;
        struct userfilestruct *prev_ufile;
        struct userinfostruct *uinfo;
        struct userfilestruct *first_user_file=NULL;
        struct userfilestruct *ufile;
        struct userfilestruct *ufile1;
+       struct ReadLogStruct log_entry;
        time_t tnum;
 
        for (ilf=0 ; ilf<ILF_Last ; ilf++) ilf_count[ilf]=0;
@@ -303,7 +303,7 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
                        if(debugm)
                                printf("BUF=%s\n",linebuf);
 
-                       t=NULL;
+                       log_entry.EntryTime=NULL;
                        if (ilf==ILF_Squid || ilf==ILF_Common || ilf==ILF_Unknown) {
                                getword_start(&gwarea,linebuf);
                                if (getword(data,sizeof(data),&gwarea,' ')<0) {
@@ -397,7 +397,7 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
                                                debuga(_("Invalid time found in %s\n"),arq);
                                                exit(EXIT_FAILURE);
                                        }
-                                       t=&tt;
+                                       log_entry.EntryTime=&tt;
                                }
 
                                if(ilf==ILF_Unknown || ilf==ILF_Squid) {
@@ -439,15 +439,15 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
                                        ilf_count[ilf]++;
 
                                        tnum=atoi(data);
-                                       t=localtime(&tnum);
-                                       if (t == NULL) {
+                                       log_entry.EntryTime=localtime(&tnum);
+                                       if (log_entry.EntryTime == NULL) {
                                                debuga(_("Cannot convert the timestamp from the squid log file\n"));
                                                exit(EXIT_FAILURE);
                                        }
 
-                                       strftime(tbuf2, sizeof(tbuf2), "%H%M", t);
+                                       strftime(tbuf2, sizeof(tbuf2), "%H%M", log_entry.EntryTime);
 
-                                       idata=(t->tm_year+1900)*10000+(t->tm_mon+1)*100+t->tm_mday;
+                                       idata=(log_entry.EntryTime->tm_year+1900)*10000+(log_entry.EntryTime->tm_mon+1)*100+log_entry.EntryTime->tm_mday;
                                }
                        }
                        if (ilf==ILF_Sarg) {
@@ -508,7 +508,7 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
                                        debuga(_("Invalid time found in %s\n"),arq);
                                        exit(EXIT_FAILURE);
                                }
-                               t=&tt;
+                               log_entry.EntryTime=&tt;
                        }
                        if (ilf==ILF_Isa) {
                                if (linebuf[0] == '#') {
@@ -626,16 +626,13 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
                                                exit(EXIT_FAILURE);
                                        }
                                }
-                               t=&tt;
+                               log_entry.EntryTime=&tt;
                        }
-                       if (t==NULL) {
+                       if (log_entry.EntryTime==NULL) {
                                debuga(_("Unknown input log file format\n"));
                                break;
                        }
 
-                       strftime(dia, sizeof(dia), "%d/%m/%Y", t);
-                       snprintf(hora,sizeof(hora),"%02d:%02d:%02d",t->tm_hour,t->tm_min,t->tm_sec);
-
                        if(debugm)
                                printf("DATE=%s IDATA=%d DFROM=%d DUNTIL=%d\n",Filter->DateRange,idata,dfrom,duntil);
 
@@ -644,13 +641,11 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
                        }
 
                        // Record only hours usage which is required
-                       if (t) {
-                               if( bsearch( &( t -> tm_wday ), weekdays.list, weekdays.len, sizeof( int ), compar ) == NULL )
-                                       continue;
+                       if( bsearch( &( log_entry.EntryTime->tm_wday ), weekdays.list, weekdays.len, sizeof( int ), compar ) == NULL )
+                               continue;
 
-                               if( bsearch( &( t -> tm_hour ), hours.list, hours.len, sizeof( int ), compar ) == NULL )
-                                       continue;
-                       }
+                       if( bsearch( &( log_entry.EntryTime->tm_hour ), hours.list, hours.len, sizeof( int ), compar ) == NULL )
+                               continue;
 
 
                        if(strlen(user) > MAX_USER_LEN) {
@@ -734,7 +729,7 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
                        }
 
                        if(Filter->StartTime >= 0 && Filter->EndTime >= 0) {
-                               hmr=t->tm_hour*100+t->tm_min;
+                               hmr=log_entry.EntryTime->tm_hour*100+log_entry.EntryTime->tm_min;
                                if(hmr < Filter->StartTime || hmr > Filter->EndTime) continue;
                        }
 
@@ -862,6 +857,9 @@ 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);
+
                        /*if ( strcmp ( user , sz_Last_User ) != 0 ) {
                                if ( fp_Write_User )
                                        fclose( fp_Write_User ) ;
@@ -909,12 +907,12 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
                        if (ilf!=ILF_Sarg) {
                                if(!totper || idata<mindate){
                                        mindate=idata;
-                                       memcpy(&period.start,t,sizeof(*t));
+                                       memcpy(&period.start,log_entry.EntryTime,sizeof(*log_entry.EntryTime));
                                        strcpy(start_hour,tbuf2);
                                }
                                if (!totper || idata>maxdate) {
                                        maxdate=idata;
-                                       memcpy(&period.end,t,sizeof(*t));
+                                       memcpy(&period.end,log_entry.EntryTime,sizeof(*log_entry.EntryTime));
                                }
                                totper=true;
                        }