]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Store the HTTP code inside the structure
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Tue, 3 Jul 2012 17:45:44 +0000 (19:45 +0200)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Tue, 3 Jul 2012 17:45:44 +0000 (19:45 +0200)
Continuation of the previous commits.

readlog.c

index 4d380e589c8ff545b3c15154f7137d435bbf4d78..5b9d132a7cfac1a96de3bca7dc591e3c1b58a4a6 100644 (file)
--- a/readlog.c
+++ b/readlog.c
@@ -357,6 +357,7 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
 
                                        if ((str = strchr(code, ':')) != NULL)
                                                *str = '/';
+                                       log_entry.HttpCode=code;
 
                                        ilf=ILF_Common;
                                        ilf_count[ilf]++;
@@ -416,6 +417,7 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
                                                debuga(_("Maybe you have a broken result code in your %s file\n"),arq);
                                                exit(EXIT_FAILURE);
                                        }
+                                       log_entry.HttpCode=code;
                                        if (getword_atoll(&log_entry.DataSize,&gwarea,' ')<0){
                                                debuga(_("Maybe you have a broken amount of data in your %s file\n"),arq);
                                                exit(EXIT_FAILURE);
@@ -480,6 +482,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.HttpCode=code;
                                if (getword_atol(&log_entry.ElapsedTime,&gwarea,'\t')<0){
                                        debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq);
                                        exit(EXIT_FAILURE);
@@ -594,8 +597,11 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
                                }
 
                                if(strcmp(code,"401") == 0 || strcmp(code,"403") == 0 || strcmp(code,"407") == 0) {
-                                       sprintf(val1,"DENIED/%s",code);
-                                       strcpy(code,val1);
+                                       static char valcode[12];
+                                       sprintf(valcode,"DENIED/%s",code);
+                                       log_entry.HttpCode=valcode;
+                               } else {
+                                       log_entry.HttpCode=code;
                                }
                                getword_start(&gwarea,data);
                                if (getword_atoll(&iyear,&gwarea,'-')<0){
@@ -663,8 +669,8 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
                                        continue;
                        }
 
-                       if(vercode(code)) {
-                               if (debugm) printf(_("Excluded code: %s\n"),code);
+                       if(vercode(log_entry.HttpCode)) {
+                               if (debugm) printf(_("Excluded code: %s\n"),log_entry.HttpCode);
                                totregsx++;
                                continue;
                        }
@@ -675,7 +681,7 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
                        // replace any tab by a single space
                        for (str=full_url ; *str ; str++)
                                if (*str=='\t') *str=' ';
-                       for (str=code ; *str ; str++)
+                       for (str=log_entry.HttpCode ; *str ; str++)
                                if (*str=='\t') *str=' ';
 
                        if(ilf!=ILF_Sarg) {
@@ -834,17 +840,17 @@ 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 (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,code,log_entry.ElapsedTime,smartfilter)<=0) {
+                       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,log_entry.HttpCode,log_entry.ElapsedTime,smartfilter)<=0) {
                                debuga(_("Write error in the log file of user %s\n"),log_entry.User);
                                exit(EXIT_FAILURE);
                        }
 
                        if(fp_log && ilf!=ILF_Sarg)
-                               fprintf(fp_log, "%s\t%s\t%s\t%s\t%s\t%"PRIu64"\t%s\t%ld\t%s\n",dia,hora,log_entry.User,log_entry.Ip,url,(uint64_t)log_entry.DataSize,code,log_entry.ElapsedTime,smartfilter);
+                               fprintf(fp_log, "%s\t%s\t%s\t%s\t%s\t%"PRIu64"\t%s\t%ld\t%s\n",dia,hora,log_entry.User,log_entry.Ip,url,(uint64_t)log_entry.DataSize,log_entry.HttpCode,log_entry.ElapsedTime,smartfilter);
 
                        totregsg++;
 
-                       if(!dataonly && download_flag && strstr(code,"DENIED") == 0) {
+                       if(!dataonly && download_flag && strstr(log_entry.HttpCode,"DENIED") == 0) {
                                ndownload = 1;
 
                                if ( ! fp_Download_Unsort ) {
@@ -856,12 +862,12 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
                                fprintf(fp_Download_Unsort,"%s\t%s\t%s\t%s\t%s\n",dia,hora,log_entry.User,log_entry.Ip,download_url);
                        }
 
-                       if(fp_denied && strstr(code,"DENIED/403") != 0) {
+                       if(fp_denied && strstr(log_entry.HttpCode,"DENIED/403") != 0) {
                                fprintf(fp_denied, "%s\t%s\t%s\t%s\t%s\n",dia,hora,log_entry.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)) {
+                               if(fp_authfail && (strstr(log_entry.HttpCode,"DENIED/401") != 0 || strstr(log_entry.HttpCode,"DENIED/407") != 0)) {
                                        fprintf(fp_authfail, "%s\t%s\t%s\t%s\t%s\n",dia,hora,log_entry.User,log_entry.Ip,full_url);
                                        authfail_count++;
                                }
@@ -888,7 +894,7 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
                                printf("TIME=\t%s\n",hora);
                                printf("FUNC=\t%s\n",fun);
                                printf("URL=\t%s\n",url);
-                               printf("CODE=\t%s\n",code);
+                               printf("CODE=\t%s\n",log_entry.HttpCode);
                                printf("LEN=\t%"PRIu64"\n",(uint64_t)log_entry.DataSize);
                        }
                }