]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Store the IP address in a structure
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Tue, 3 Jul 2012 10:19:03 +0000 (12:19 +0200)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Tue, 3 Jul 2012 10:19:03 +0000 (12:19 +0200)
Yet another log variable stored in the structure to be exchanged with the
modules to read the input log files.

readlog.c

index aa14807dda40a3ef08e61e74d19e1ffc5b925e82..99015d8d16b470b72a198d32b603b47ba715ea83 100644 (file)
--- a/readlog.c
+++ b/readlog.c
@@ -84,7 +84,7 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
        char elap[255];
        char user[MAX_USER_LEN];
        char data[255];
-       char ip[MAXLEN];
+       char ip[60];
        char tam[255];
        char hora[30];
        char mes[30];
@@ -303,7 +303,7 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
                        if(debugm)
                                printf("BUF=%s\n",linebuf);
 
-                       log_entry.EntryTime=NULL;
+                       memset(&log_entry,0,sizeof(log_entry));
                        if (ilf==ILF_Squid || ilf==ILF_Common || ilf==ILF_Unknown) {
                                getword_start(&gwarea,linebuf);
                                if (getword(data,sizeof(data),&gwarea,' ')<0) {
@@ -312,6 +312,7 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
                                }
                                if((str=(char *) strchr(data, '.')) != (char *) NULL && (str=(char *) strchr(str+1, '.')) != (char *) NULL ) {
                                        strcpy(ip,data);
+                                       log_entry.Ip=ip;
                                        strcpy(elap,"0");
                                        if(squid24) {
                                                if (getword(user,sizeof(user),&gwarea,' ')<0 || getword_skip(255,&gwarea,' ')<0) {
@@ -415,6 +416,7 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
                                                debuga(_("Maybe you have a broken client IP address in your %s file\n"),arq);
                                                exit(EXIT_FAILURE);
                                        }
+                                       log_entry.Ip=ip;
                                        if (getword(code,sizeof(code),&gwarea,' ')<0){
                                                debuga(_("Maybe you have a broken result code in your %s file\n"),arq);
                                                exit(EXIT_FAILURE);
@@ -468,6 +470,7 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
                                        debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq);
                                        exit(EXIT_FAILURE);
                                }
+                               log_entry.Ip=ip;
                                if (getword_ptr(linebuf,&full_url,&gwarea,'\t')<0){
                                        debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq);
                                        exit(EXIT_FAILURE);
@@ -558,6 +561,7 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
                                                        exit(EXIT_FAILURE);
                                                }
                                                strcpy(ip,str);
+                                               log_entry.Ip=ip;
                                        } else if (x==isa_cols[ISACOL_UserName]) {
                                                if (strlen(str)>=sizeof(user)) {
                                                        debuga(_("Maybe you have a broken user ID in your %s file\n"),arq);
@@ -629,7 +633,11 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
                                log_entry.EntryTime=&tt;
                        }
                        if (log_entry.EntryTime==NULL) {
-                               debuga(_("Unknown input log file format\n"));
+                               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;
                        }
 
@@ -718,7 +726,7 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
                        if (!url || url[0] == '\0') continue;
 
                        if(addr[0] != '\0'){
-                               if(strcmp(addr,ip)!=0) continue;
+                               if(strcmp(addr,log_entry.Ip)!=0) continue;
                        }
                        if(Filter->HostFilter) {
                                if(!vhexclude(url)) {
@@ -738,13 +746,13 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
                        }
 
                        if(UserIp) {
-                               strcpy(user,ip);
+                               strcpy(user,log_entry.Ip);
                                id_is_ip=true;
                        } else {
                                id_is_ip=false;
                                if(strcmp(user,"-") == 0 || strcmp(user," ") == 0 || strcmp(user,"") == 0) {
                                        if(RecordsWithoutUser == RECORDWITHOUTUSER_IP) {
-                                               strcpy(user,ip);
+                                               strcpy(user,log_entry.Ip);
                                                id_is_ip=true;
                                        }
                                        if(RecordsWithoutUser == RECORDWITHOUTUSER_IGNORE)
@@ -871,13 +879,13 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
                                }
                                strcpy( sz_Last_User , user ) ;
                        }*/
-                       if (fprintf(ufile->file, "%s\t%s\t%s\t%s\t%ld\t%s\t%ld\t%s\n",dia,hora,ip,url,nbytes,code,elap_time,smartfilter)<=0) {
+                       if (fprintf(ufile->file, "%s\t%s\t%s\t%s\t%ld\t%s\t%ld\t%s\n",dia,hora,log_entry.Ip,url,nbytes,code,elap_time,smartfilter)<=0) {
                                debuga(_("Write error in the log file of user %s\n"),user);
                                exit(EXIT_FAILURE);
                        }
 
                        if(fp_log && ilf!=ILF_Sarg)
-                               fprintf(fp_log, "%s\t%s\t%s\t%s\t%s\t%ld\t%s\t%ld\t%s\n",dia,hora,user,ip,url,nbytes,code,elap_time,smartfilter);
+                               fprintf(fp_log, "%s\t%s\t%s\t%s\t%s\t%ld\t%s\t%ld\t%s\n",dia,hora,user,log_entry.Ip,url,nbytes,code,elap_time,smartfilter);
 
                        totregsg++;
 
@@ -890,16 +898,16 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
                                                exit (1);
                                        }
                                }
-                               fprintf(fp_Download_Unsort,"%s\t%s\t%s\t%s\t%s\n",dia,hora,user,ip,download_url);
+                               fprintf(fp_Download_Unsort,"%s\t%s\t%s\t%s\t%s\n",dia,hora,user,log_entry.Ip,download_url);
                        }
 
                        if(fp_denied && strstr(code,"DENIED/403") != 0) {
-                               fprintf(fp_denied, "%s\t%s\t%s\t%s\t%s\n",dia,hora,user,ip,full_url);
+                               fprintf(fp_denied, "%s\t%s\t%s\t%s\t%s\n",dia,hora,user,log_entry.Ip,full_url);
                                denied_count++;
                        }
                        if((ReportType & REPORT_TYPE_AUTH_FAILURES) != 0) {
                                if(fp_authfail && (strstr(code,"DENIED/401") != 0 || strstr(code,"DENIED/407") != 0)) {
-                                       fprintf(fp_authfail, "%s\t%s\t%s\t%s\t%s\n",dia,hora,user,ip,full_url);
+                                       fprintf(fp_authfail, "%s\t%s\t%s\t%s\t%s\n",dia,hora,user,log_entry.Ip,full_url);
                                        authfail_count++;
                                }
                        }
@@ -918,7 +926,7 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
                        }
 
                        if(debugm){
-                               printf("IP=\t%s\n",ip);
+                               printf("IP=\t%s\n",log_entry.Ip);
                                printf("USER=\t%s\n",user);
                                printf("ELAP=\t%ld\n",elap_time);
                                printf("DATE=\t%s\n",dia);