]> git.ipfire.org Git - thirdparty/sarg.git/blobdiff - useragent.c
Generate redirector log even if -d is not given
[thirdparty/sarg.git] / useragent.c
index 015024b30e939ca24948cf31b7b86ef3e3da8ebc..1e654d392afdaf0494e60d3e2e62afdfebe524f5 100644 (file)
@@ -32,7 +32,9 @@ FileListObject UserAgentLog=NULL;
 
 void useragent(void)
 {
+       FileObject *fp_log;
        FILE *fp_in = NULL, *fp_ou = NULL, *fp_ht = NULL;
+       char *ptr;
        char buf[MAXLEN];
        char ip[MAXLEN], data[MAXLEN], agent[MAXLEN], user[MAXLEN];
        char ipbefore[MAXLEN], namebefore[MAXLEN];
@@ -52,6 +54,7 @@ void useragent(void)
        int ndate;
        double perc;
        struct getwordstruct gwarea, gwarea1;
+       longline line;
        FileListIterator FIter;
 
        ip[0]='\0';
@@ -71,11 +74,17 @@ void useragent(void)
                exit(EXIT_FAILURE);
        }
 
+       if ((line=longline_create())==NULL) {
+               debuga(__FILE__,__LINE__,_("Not enough memory to read useragent log\n"));
+               exit(EXIT_FAILURE);
+       }
+
        FIter=FileListIter_Open(UserAgentLog);
        while ((FileName=FileListIter_Next(FIter))!=NULL)
        {
-               if((fp_in=fopen(FileName,"r"))==NULL) {
-                       debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),FileName,strerror(errno));
+               longline_reset(line);
+               if((fp_log=decomp(FileName))==NULL) {
+                       debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),FileName,FileObject_GetLastOpenError());
                        exit(EXIT_FAILURE);
                }
 
@@ -83,9 +92,9 @@ void useragent(void)
                        debuga(__FILE__,__LINE__,_("Reading useragent log \"%s\"\n"),FileName);
                }
 
-               while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
+               while((ptr=longline_read(fp_log,line))!=NULL) {
                        totregsl++;
-                       getword_start(&gwarea,buf);
+                       getword_start(&gwarea,ptr);
                        if (getword(ip,sizeof(ip),&gwarea,' ')<0 || getword_skip(MAXLEN,&gwarea,'[')<0 ||
                                getword(data,sizeof(data),&gwarea,' ')<0) {
                                debuga(__FILE__,__LINE__,_("Invalid record in file \"%s\"\n"),FileName);
@@ -128,12 +137,13 @@ void useragent(void)
                        useragent_count++;
                }
 
-               if (fclose(fp_in)==EOF) {
-                       debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),FileName,strerror(errno));
+               if (FileObject_Close(fp_log)==EOF) {
+                       debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),FileName,FileObject_GetLastCloseError());
                        exit(EXIT_FAILURE);
                }
        }
        FileListIter_Close(FIter);
+       longline_destroy(&line);
 
        if(debug) {
                debuga(__FILE__,__LINE__,_("   Records read: %ld\n"),totregsl);