]> git.ipfire.org Git - thirdparty/sarg.git/blobdiff - readlog.c
Make b-tree cache functions static.
[thirdparty/sarg.git] / readlog.c
index d08306f330ce5f58fc036cdcaa51718f5083643a..d81032e79315a77a4bf787ede68741d38d19ff6d 100644 (file)
--- a/readlog.c
+++ b/readlog.c
@@ -91,8 +91,9 @@ numlist weekdays = { { 0, 1, 2, 3, 4, 5, 6 }, 7 };
 numlist hours = { { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 }, 24 };
 //! Domain suffix to strip from the user name.
 char StripUserSuffix[MAX_USER_LEN]="";
+//! Length of the suffix to strip from the user name.
+int StripSuffixLen=0;
 
-extern char *userfile;
 extern FileListObject AccessLog;
 
 extern const struct ReadLogProcessStruct ReadSquidLog;
@@ -306,19 +307,15 @@ static void ReadOneLogFile(struct ReadLogDataStruct *Filter,const char *arq)
        char *str;
        char hora[30];
        char dia[128]="";
-       char wuser[MAXLEN];
        char tmp3[MAXLEN]="";
        char download_url[MAXLEN];
        char smartfilter[MAXLEN];
        const char *url;
-       const char *user;
-       char UserBuffer[MAX_USER_LEN];
        int OutputNonZero = REPORT_EVERY_X_LINES ;
        int idata=0;
        int x;
        int hmr;
        int nopen;
-       int StripSuffixLen;
        int maxopenfiles=MAX_OPEN_USER_FILES;
        unsigned long int recs1=0UL;
        unsigned long int recs2=0UL;
@@ -326,6 +323,7 @@ static void ReadOneLogFile(struct ReadLogDataStruct *Filter,const char *arq)
        bool download_flag=false;
        bool id_is_ip;
        enum ReadLogReturnCodeEnum log_entry_status;
+       enum UserProcessError PUser;
        struct stat logstat;
        struct getwordstruct gwarea;
        struct userfilestruct *prev_ufile;
@@ -369,7 +367,6 @@ static void ReadOneLogFile(struct ReadLogDataStruct *Filter,const char *arq)
 
        recs1=0UL;
        recs2=0UL;
-       StripSuffixLen=strlen(StripUserSuffix);
 
        // pre-read the file only if we have to show stats
        if (ShowReadStatistics && ShowReadPercent && fp_in->Rewind) {
@@ -529,35 +526,35 @@ static void ReadOneLogFile(struct ReadLogDataStruct *Filter,const char *arq)
                        continue;
                }
 
-               if (StripSuffixLen>0)
+               PUser=process_user(&log_entry.User,log_entry.Ip,&id_is_ip);
+               switch (PUser)
                {
-                       x=strlen(log_entry.User);
-                       if (x>StripSuffixLen && strcasecmp(log_entry.User+(x-StripSuffixLen),StripUserSuffix)==0)
-                       {
-                               if (x-StripSuffixLen>=sizeof(UserBuffer)) {
-                                       if (debugz>=LogLevel_Process) debuga(__FILE__,__LINE__,_("User ID too long: %s\n"),log_entry.User);
-                                       excluded_count[ER_UserNameTooLong]++;
-                                       totregsx++;
-                                       continue;
-                               }
-                               safe_strcpy(UserBuffer,log_entry.User,x-StripSuffixLen+1);
-                               log_entry.User=UserBuffer;
-                       }
-               }
-               if(strlen(log_entry.User) > MAX_USER_LEN) {
-                       if (debugz>=LogLevel_Process) debuga(__FILE__,__LINE__,_("User ID too long: %s\n"),log_entry.User);
-                       excluded_count[ER_UserNameTooLong]++;
-                       totregsx++;
-                       continue;
-               }
-
-               // include_users
-               if(IncludeUsers[0] != '\0') {
-                       snprintf(val1,sizeof(val1),":%s:",log_entry.User);
-                       if((str=(char *) strstr(IncludeUsers,val1)) == (char *) NULL ) {
+                       case USERERR_NoError:
+                               break;
+                       case USERERR_NameTooLong:
+                               if (debugz>=LogLevel_Process) debuga(__FILE__,__LINE__,_("User ID too long: %s\n"),log_entry.User);
+                               excluded_count[ER_UserNameTooLong]++;
+                               totregsx++;
+                               continue;
+                       case USERERR_Excluded:
                                excluded_count[ER_User]++;
                                continue;
-                       }
+                       case USERERR_InvalidChar:
+                               excluded_count[ER_InvalidUserChar]++;
+                               continue;
+                       case USERERR_EmptyUser:
+                               excluded_count[ER_NoUser]++;
+                               continue;
+                       case USERERR_SysUser:
+                               excluded_count[ER_SysUser]++;
+                               continue;
+                       case USERERR_Ignored:
+                               excluded_count[ER_IgnoredUser]++;
+                               totregsx++;
+                               continue;
+                       case USERERR_Untracked:
+                               excluded_count[ER_UntrackedUser]++;
+                               continue;
                }
 
                if(vercode(log_entry.HttpCode)) {
@@ -567,11 +564,6 @@ static void ReadOneLogFile(struct ReadLogDataStruct *Filter,const char *arq)
                        continue;
                }
 
-               if(testvaliduserchar(log_entry.User)) {
-                       excluded_count[ER_InvalidUserChar]++;
-                       continue;
-               }
-
                // replace any tab by a single space
                for (str=log_entry.Url ; *str ; str++)
                        if (*str=='\t') *str=' ';
@@ -626,67 +618,6 @@ static void ReadOneLogFile(struct ReadLogDataStruct *Filter,const char *arq)
                        }
                }
 
-               if(UserIp) {
-                       log_entry.User=log_entry.Ip;
-                       id_is_ip=true;
-               } else {
-                       log_entry.User=log_entry.User;
-                       id_is_ip=false;
-                       if ((log_entry.User[0]=='\0') || (log_entry.User[1]=='\0' && (log_entry.User[0]=='-' || log_entry.User[0]==' '))) {
-                               if(RecordsWithoutUser == RECORDWITHOUTUSER_IP) {
-                                       log_entry.User=log_entry.Ip;
-                                       id_is_ip=true;
-                               }
-                               if(RecordsWithoutUser == RECORDWITHOUTUSER_IGNORE) {
-                                       excluded_count[ER_NoUser]++;
-                                       continue;
-                               }
-                               if(RecordsWithoutUser == RECORDWITHOUTUSER_EVERYBODY)
-                                       log_entry.User="everybody";
-                       } else {
-                               if(NtlmUserFormat == NTLMUSERFORMAT_USER) {
-                                       if ((str=strchr(log_entry.User,'+'))!=NULL || (str=strchr(log_entry.User,'\\'))!=NULL || (str=strchr(log_entry.User,'_'))!=NULL) {
-                                               log_entry.User=str+1;
-                                       }
-                               }
-                       }
-               }
-
-               if(us[0] != '\0'){
-                       if(strcmp(log_entry.User,us)!=0) {
-                               excluded_count[ER_UntrackedUser]++;
-                               continue;
-                       }
-               }
-
-               if(Filter->SysUsers) {
-                       snprintf(wuser,sizeof(wuser),":%s:",log_entry.User);
-                       if(strstr(userfile, wuser) == 0) {
-                               excluded_count[ER_SysUser]++;
-                               continue;
-                       }
-               }
-
-               if(Filter->UserFilter) {
-                       if(!vuexclude(log_entry.User)) {
-                               if (debugz>=LogLevel_Process) debuga(__FILE__,__LINE__,_("Excluded user: %s\n"),log_entry.User);
-                               excluded_count[ER_IgnoredUser]++;
-                               totregsx++;
-                               continue;
-                       }
-               }
-
-               user=process_user(log_entry.User);
-               if (log_entry.User!=user)
-               {
-                       log_entry.User=user;
-                       id_is_ip=false;
-               }
-               if (log_entry.User[0]=='\0' || (log_entry.User[1]=='\0' && (log_entry.User[0]=='-' || log_entry.User[0]==' ' || log_entry.User[0]==':'))) {
-                       excluded_count[ER_NoUser]++;
-                       continue;
-               }
-
                if (log_entry.DataSize<0) log_entry.DataSize=0;
 
                if (log_entry.ElapsedTime<0) log_entry.ElapsedTime=0;
@@ -757,7 +688,7 @@ static void ReadOneLogFile(struct ReadLogDataStruct *Filter,const char *arq)
                        }
                        if ((ufile->file = MY_FOPEN (tmp3, "a")) == NULL) {
                                debuga(__FILE__,__LINE__,_("(log) Cannot open temporary file %s: %s\n"), tmp3, strerror(errno));
-                               exit (1);
+                               exit(EXIT_FAILURE);
                        }
                }