]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Purge the old log file decoding code
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Sun, 26 Aug 2012 13:56:55 +0000 (15:56 +0200)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Sun, 26 Aug 2012 14:00:38 +0000 (16:00 +0200)
The legacy code to read the log files is gone for good.

readlog.c

index 31658304689ca00668cb4627f241f49e40fae129..39f9c708395af0405ef7bc6302c1f98fb469eb3d 100644 (file)
--- a/readlog.c
+++ b/readlog.c
@@ -71,13 +71,8 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
        char *linebuf;
        char *str;
        char arq_log[255];
-       //char fun[MAXLEN];
-       //char elap[255];
        char user[MAX_USER_LEN];
-       //char data[255];
-       //char ip[60];
        char hora[30];
-       //char mes[30];
        char tbuf2[128];
        char dia[128]="";
        char wuser[MAXLEN];
@@ -92,7 +87,6 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
        int blen;
        int OutputNonZero = REPORT_EVERY_X_LINES ;
        int idata=0;
-       //int isa_ncols=0,isa_cols[ISACOL_Last];
        int x;
        int hmr;
        int nopen;
@@ -107,7 +101,6 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
        long int totregsl=0;
        long int totregsg=0;
        long int totregsx=0;
-       //long long int iyear, imonth, iday;
        FILE *fp_in=NULL;
        FILE *fp_log=NULL;
        FILE *fp_Download_Unsort=NULL;
@@ -119,7 +112,6 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
        enum ReadLogReturnCodeEnum log_entry_status;
        struct stat logstat;
        struct getwordstruct gwarea;
-       //struct tm tt;
        struct userfilestruct *prev_ufile;
        struct userinfostruct *uinfo;
        struct userfilestruct *first_user_file=NULL;
@@ -127,7 +119,6 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
        struct userfilestruct *ufile1;
        struct ReadLogStruct log_entry;
        const struct ReadLogProcessStruct *current_format=NULL;
-       //time_t tnum;
 
        for (x=0 ; x<sizeof(format_count)/sizeof(*format_count) ; x++) format_count[x]=0;
        tmp3[0]='\0';
@@ -216,30 +207,6 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
                while ((linebuf=longline_read(fp_in,line))!=NULL) {
                        blen=strlen(linebuf);
 
-#if 0
-                       if (ilf==ILF_Unknown) {
-                               if(strncmp(linebuf,"#Software: Mic",14) == 0) {
-                                       if (debug) {
-                                               fixendofline(linebuf);
-                                               debuga(_("Log is from Microsoft ISA: %s\n"),linebuf);
-                                       }
-                                       ilf=ILF_Isa;
-                                       ilf_count[ilf]++;
-                                       continue;
-                               }
-
-                               if(strncmp(linebuf,"*** SARG Log ***",16) == 0) {
-                                       if (getperiod_fromsarglog(arq,&period)<0) {
-                                               debuga(_("The name of the file is invalid: %s\n"),arq);
-                                               exit(EXIT_FAILURE);
-                                       }
-                                       ilf=ILF_Sarg;
-                                       ilf_count[ilf]++;
-                                       continue;
-                               }
-                       }
-#endif
-
                        recs2++;
                        if (ShowReadStatistics && --OutputNonZero<=0) {
                                if (recs1>0) {
@@ -343,335 +310,6 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
                                fputs("*** SARG Log ***\n",fp_log);
                        }
 
-#if 0
-                       if (ilf==ILF_Squid || ilf==ILF_Common || ilf==ILF_Unknown) {
-                               getword_start(&gwarea,linebuf);
-                               if (getword(data,sizeof(data),&gwarea,' ')<0) {
-                                       debuga(_("Maybe you have a broken time in your access.log file\n"));
-                                       exit(EXIT_FAILURE);
-                               }
-                               if((str=(char *) strchr(data, '.')) != (char *) NULL && (str=(char *) strchr(str+1, '.')) != (char *) NULL ) {
-                                       strcpy(ip,data);
-                                       log_entry.Ip=ip;
-                                       if(squid24) {
-                                               if (getword(user,sizeof(user),&gwarea,' ')<0 || getword_skip(255,&gwarea,' ')<0) {
-                                                       debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq);
-                                                       exit(EXIT_FAILURE);
-                                               }
-                                       } else {
-                                               if (getword_skip(255,&gwarea,' ')<0 || getword(user,sizeof(user),&gwarea,' ')<0) {
-                                                       debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq);
-                                                       exit(EXIT_FAILURE);
-                                               }
-                                       }
-                                       log_entry.User=user;
-                                       if (getword(data,sizeof(data),&gwarea,']')<0 || getword_skip(MAXLEN,&gwarea,'"')<0 ||
-                                                       getword(fun,sizeof(fun),&gwarea,' ')<0) {
-                                               debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq);
-                                               exit(EXIT_FAILURE);
-                                       }
-                                       if (getword_ptr(linebuf,&log_entry.Url,&gwarea,' ')<0) {
-                                               debuga(_("Maybe you have a broken url in your %s file\n"),arq);
-                                               exit(EXIT_FAILURE);
-                                       }
-                                       if (getword_skip(MAXLEN,&gwarea,' ')<0) {
-                                               debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq);
-                                               exit(EXIT_FAILURE);
-                                       }
-                                       if (getword(code2,sizeof(code2),&gwarea,' ')<0) {
-                                               debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq);
-                                               exit(EXIT_FAILURE);
-                                       }
-                                       if (getword_atoll(&log_entry.DataSize,&gwarea,' ')<0) {
-                                               debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq);
-                                               exit(EXIT_FAILURE);
-                                       }
-                                       if((str=(char *) strchr(gwarea.current, ' ')) != (char *) NULL ) {
-                                               if (getword(code,sizeof(code),&gwarea,' ')<0) {
-                                                       debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq);
-                                                       exit(EXIT_FAILURE);
-                                               }
-                                       } else {
-                                               if (getword(code,sizeof(code),&gwarea,'\0')<0) {
-                                                       debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq);
-                                                       exit(EXIT_FAILURE);
-                                               }
-                                       }
-
-                                       if ((str = strchr(code, ':')) != NULL)
-                                               *str = '/';
-                                       log_entry.HttpCode=code;
-
-                                       ilf=ILF_Common;
-                                       ilf_count[ilf]++;
-
-                                       getword_start(&gwarea,data+1);
-                                       if (getword_multisep(data,sizeof(data),&gwarea,':')<0){
-                                               debuga(_("Maybe you have a broken date in your %s file\n"),arq);
-                                               exit(EXIT_FAILURE);
-                                       }
-                                       if (getword_multisep(hora,sizeof(hora),&gwarea,' ')<0){
-                                               debuga(_("Maybe you have a broken date in your %s file\n"),arq);
-                                               exit(EXIT_FAILURE);
-                                       }
-                                       getword_start(&gwarea,data);
-                                       if (getword_atoll(&iday,&gwarea,'/')<0){
-                                               debuga(_("Maybe you have a broken date in your %s file\n"),arq);
-                                               exit(EXIT_FAILURE);
-                                       }
-                                       if (getword(mes,sizeof(mes),&gwarea,'/')<0){
-                                               debuga(_("Maybe you have a broken date in your %s file\n"),arq);
-                                               exit(EXIT_FAILURE);
-                                       }
-                                       if (getword_atoll(&iyear,&gwarea,'/')<0){
-                                               debuga(_("Maybe you have a broken date in your %s file\n"),arq);
-                                               exit(EXIT_FAILURE);
-                                       }
-
-                                       imonth=month2num(mes)+1;
-                                       idata=builddia(iday,imonth,iyear);
-                                       computedate(iyear,imonth,iday,&tt);
-                                       if (sscanf(hora,"%d:%d:%d",&tt.tm_hour,&tt.tm_min,&tt.tm_sec)!=3 || tt.tm_hour<0 || tt.tm_hour>=24 ||
-                                                       tt.tm_min<0 || tt.tm_min>=60 || tt.tm_sec<0 || tt.tm_sec>=60) {
-                                               debuga(_("Invalid time found in %s\n"),arq);
-                                               exit(EXIT_FAILURE);
-                                       }
-                                       log_entry.EntryTime=&tt;
-                               }
-
-                               if(ilf==ILF_Unknown || ilf==ILF_Squid) {
-                                       if (getword(elap,sizeof(elap),&gwarea,' ')<0) {
-                                               debuga(_("Maybe you have a broken elapsed time in your %s file\n"),arq);
-                                               exit(EXIT_FAILURE);
-                                       }
-                                       while(strcmp(elap,"") == 0 && gwarea.current[0] != '\0')
-                                               if (getword(elap,sizeof(elap),&gwarea,' ')<0) {
-                                                       debuga(_("Maybe you have a broken elapsed time in your %s file\n"),arq);
-                                                       exit(EXIT_FAILURE);
-                                               }
-                                       if(strlen(elap) < 1) continue;
-                                       log_entry.ElapsedTime=atol(elap);
-                                       if (getword(ip,sizeof(ip),&gwarea,' ')<0){
-                                               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);
-                                       }
-                                       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);
-                                       }
-                                       if (getword(fun,sizeof(fun),&gwarea,' ')<0){
-                                               debuga(_("Maybe you have a broken request method in your %s file\n"),arq);
-                                               exit(EXIT_FAILURE);
-                                       }
-                                       if (getword_ptr(linebuf,&log_entry.Url,&gwarea,' ')<0){
-                                               debuga(_("Maybe you have a broken url in your %s file\n"),arq);
-                                               exit(EXIT_FAILURE);
-                                       }
-                                       if (getword(user,sizeof(user),&gwarea,' ')<0){
-                                               debuga(_("Maybe you have a broken user ID in your %s file\n"),arq);
-                                               exit(EXIT_FAILURE);
-                                       }
-                                       log_entry.User=user;
-                                       ilf=ILF_Squid;
-                                       ilf_count[ilf]++;
-
-                                       tnum=atoi(data);
-                                       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", log_entry.EntryTime);
-
-                                       idata=(log_entry.EntryTime->tm_year+1900)*10000+(log_entry.EntryTime->tm_mon+1)*100+log_entry.EntryTime->tm_mday;
-                               }
-                       }
-                       if (ilf==ILF_Sarg) {
-                               getword_start(&gwarea,linebuf);
-                               if (getword(data,sizeof(data),&gwarea,'\t')<0){
-                                       debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq);
-                                       exit(EXIT_FAILURE);
-                               }
-                               if (getword(hora,sizeof(hora),&gwarea,'\t')<0) {
-                                       debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq);
-                                       exit(EXIT_FAILURE);
-                               }
-                               if (getword(user,sizeof(user),&gwarea,'\t')<0) {
-                                       debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq);
-                                       exit(EXIT_FAILURE);
-                               }
-                               log_entry.User=user;
-                               if (getword(ip,sizeof(ip),&gwarea,'\t')<0) {
-                                       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,&log_entry.Url,&gwarea,'\t')<0){
-                                       debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq);
-                                       exit(EXIT_FAILURE);
-                               }
-                               if (getword_atoll(&log_entry.DataSize,&gwarea,'\t')<0){
-                                       debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq);
-                                       exit(EXIT_FAILURE);
-                               }
-                               if (getword(code,sizeof(code),&gwarea,'\t')<0){
-                                       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);
-                               }
-                               if (getword(smartfilter,sizeof(smartfilter),&gwarea,'\0')<0){
-                                       debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq);
-                                       exit(EXIT_FAILURE);
-                               }
-                               getword_start(&gwarea,data);
-                               if (getword_atoll(&iday,&gwarea,'/')<0 || iday<1 || iday>31){
-                                       debuga(_("Maybe you have a broken date in your %s file\n"),arq);
-                                       exit(EXIT_FAILURE);
-                               }
-                               if (getword_atoll(&imonth,&gwarea,'/')<0 || imonth<1 || imonth>12){
-                                       debuga(_("Maybe you have a broken date in your %s file\n"),arq);
-                                       exit(EXIT_FAILURE);
-                               }
-                               if (getword_atoll(&iyear,&gwarea,'\0')<0){
-                                       debuga(_("Maybe you have a broken date in your %s file\n"),arq);
-                                       exit(EXIT_FAILURE);
-                               }
-                               idata=builddia(iday,imonth,iyear);
-                               computedate(iyear,imonth,iday,&tt);
-                               if (sscanf(hora,"%d:%d:%d",&tt.tm_hour,&tt.tm_min,&tt.tm_sec)!=3 || tt.tm_hour<0 || tt.tm_hour>=24 ||
-                                               tt.tm_min<0 || tt.tm_min>=60 || tt.tm_sec<0 || tt.tm_sec>=60) {
-                                       debuga(_("Invalid time found in %s\n"),arq);
-                                       exit(EXIT_FAILURE);
-                               }
-                               log_entry.EntryTime=&tt;
-                       }
-                       if (ilf==ILF_Isa) {
-                               if (linebuf[0] == '#') {
-                                       int ncols,cols[ISACOL_Last];
-
-                                       fixendofline(linebuf);
-                                       getword_start(&gwarea,linebuf);
-                                       // remove the #Fields: column at the beginning of the line
-                                       if (getword_skip(1000,&gwarea,' ')<0){
-                                               debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq);
-                                               exit(EXIT_FAILURE);
-                                       }
-                                       for (ncols=0 ; ncols<ISACOL_Last ; ncols++) cols[ncols]=-1;
-                                       ncols=0;
-                                       while(gwarea.current[0] != '\0') {
-                                               if (getword(val1,sizeof(val1),&gwarea,'\t')<0){
-                                                       debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq);
-                                                       exit(EXIT_FAILURE);
-                                               }
-                                               if(strcmp(val1,"c-ip") == 0) cols[ISACOL_Ip]=ncols;
-                                               if(strcmp(val1,"cs-username") == 0) cols[ISACOL_UserName]=ncols;
-                                               if(strcmp(val1,"date") == 0) cols[ISACOL_Date]=ncols;
-                                               if(strcmp(val1,"time") == 0) cols[ISACOL_Time]=ncols;
-                                               if(strcmp(val1,"time-taken") == 0) cols[ISACOL_TimeTaken]=ncols;
-                                               if(strcmp(val1,"sc-bytes") == 0) cols[ISACOL_Bytes]=ncols;
-                                               if(strcmp(val1,"cs-uri") == 0) cols[ISACOL_Uri]=ncols;
-                                               if(strcmp(val1,"sc-status") == 0) cols[ISACOL_Status]=ncols;
-                                               ncols++;
-                                       }
-                                       if (cols[ISACOL_Ip]>=0) {
-                                               isa_ncols=ncols;
-                                               for (ncols=0 ; ncols<ISACOL_Last ; ncols++)
-                                                       isa_cols[ncols]=cols[ncols];
-                                       }
-                                       continue;
-                               }
-                               if (!isa_ncols) continue;
-                               getword_start(&gwarea,linebuf);
-                               for (x=0 ; x<isa_ncols ; x++) {
-                                       if (getword_ptr(linebuf,&str,&gwarea,'\t')<0) {
-                                               debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq);
-                                               exit(EXIT_FAILURE);
-                                       }
-                                       if (x==isa_cols[ISACOL_Ip]) {
-                                               if (strlen(str)>=sizeof(ip)) {
-                                                       debuga(_("Maybe you have a broken IP in your %s file\n"),arq);
-                                                       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);
-                                                       exit(EXIT_FAILURE);
-                                               }
-                                               strcpy(user,str);
-                                               log_entry.User=user;
-                                       } else if (x==isa_cols[ISACOL_Date]) {
-                                               if (strlen(str)>=sizeof(data)) {
-                                                       debuga(_("Maybe you have a broken date in your %s file\n"),arq);
-                                                       exit(EXIT_FAILURE);
-                                               }
-                                               strcpy(data,str);
-                                       } else if (x==isa_cols[ISACOL_Time]) {
-                                               if (strlen(str)>=sizeof(hora)) {
-                                                       debuga(_("Maybe you have a broken time in your %s file\n"),arq);
-                                                       exit(EXIT_FAILURE);
-                                               }
-                                               strcpy(hora,str);
-                                       } else if (x==isa_cols[ISACOL_TimeTaken]) {
-                                               log_entry.ElapsedTime=atol(str);
-                                       } else if (x==isa_cols[ISACOL_Bytes]) {
-                                               log_entry.DataSize=atoll(str);
-                                       } else if (x==isa_cols[ISACOL_Uri]) {
-                                               log_entry.Url=str;
-                                       } else if (x==isa_cols[ISACOL_Status]) {
-                                               if (strlen(str)>=sizeof(code)) {
-                                                       debuga(_("Maybe you have a broken access code in your %s file\n"),arq);
-                                                       exit(EXIT_FAILURE);
-                                               }
-                                               strcpy(code,str);
-                                       }
-                               }
-
-                               if(strcmp(code,"401") == 0 || strcmp(code,"403") == 0 || strcmp(code,"407") == 0) {
-                                       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){
-                                       debuga(_("Maybe you have a broken year in your %s file\n"),arq);
-                                       exit(EXIT_FAILURE);
-                               }
-                               if (getword_atoll(&imonth,&gwarea,'-')<0){
-                                       debuga(_("Maybe you have a broken month in your %s file\n"),arq);
-                                       exit(EXIT_FAILURE);
-                               }
-                               if (getword_atoll(&iday,&gwarea,'\0')<0){
-                                       debuga(_("Maybe you have a broken day in your %s file\n"),arq);
-                                       exit(EXIT_FAILURE);
-                               }
-
-                               idata=builddia(iday,imonth,iyear);
-                               computedate(iyear,imonth,iday,&tt);
-                               if (isa_cols[ISACOL_Time]>=0) {
-                                       if (sscanf(hora,"%d:%d:%d",&tt.tm_hour,&tt.tm_min,&tt.tm_sec)!=3 || tt.tm_hour<0 || tt.tm_hour>=24 ||
-                                                       tt.tm_min<0 || tt.tm_min>=60 || tt.tm_sec<0 || tt.tm_sec>=60) {
-                                               debuga(_("Invalid time found in %s\n"),arq);
-                                               exit(EXIT_FAILURE);
-                                       }
-                               }
-                               log_entry.EntryTime=&tt;
-                       }
-#endif
                        if (log_entry.Ip==NULL) {
                                debuga(_("Unknown input log file format: no IP addresses\n"));
                                break;