]> git.ipfire.org Git - thirdparty/sarg.git/blobdiff - useragent.c
Create a user agent report if the input log provides the information
[thirdparty/sarg.git] / useragent.c
index 53c5f4d275db335ffa81cbb9540d1ec8594f923f..11934204afd0a7d1a43a6cc4ff46df007a986067 100644 (file)
@@ -45,19 +45,21 @@ static struct tm UserAgentEndDate;
  */
 FILE *UserAgent_Open(void)
 {
-       FILE *fp_ou;
+       FILE *fp_ou=NULL;
 
        if (UserAgentTempLog[0]) {
                debuga(__FILE__,__LINE__,_("Useragent log already opened\n"));
                exit(EXIT_FAILURE);
        }
-       snprintf(UserAgentTempLog,sizeof(UserAgentTempLog),"%s/squagent.int_unsort",tmp);
-       if ((fp_ou=fopen(UserAgentTempLog,"w"))==NULL) {
-               debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),UserAgentTempLog,strerror(errno));
-               exit(EXIT_FAILURE);
+       if ((ReportType & REPORT_TYPE_USERAGENT)!=0) {
+               snprintf(UserAgentTempLog,sizeof(UserAgentTempLog),"%s/squagent.int_unsort",tmp);
+               if ((fp_ou=fopen(UserAgentTempLog,"w"))==NULL) {
+                       debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),UserAgentTempLog,strerror(errno));
+                       exit(EXIT_FAILURE);
+               }
+               memset(&UserAgentStartDate,0,sizeof(UserAgentStartDate));
+               memset(&UserAgentEndDate,0,sizeof(UserAgentEndDate));
        }
-       memset(&UserAgentStartDate,0,sizeof(UserAgentStartDate));
-       memset(&UserAgentEndDate,0,sizeof(UserAgentEndDate));
        return(fp_ou);
 }
 
@@ -71,8 +73,10 @@ FILE *UserAgent_Open(void)
  */
 void UserAgent_Write(FILE *fp,const char *Ip,const char *User,const char *Agent)
 {
-       fprintf(fp,"%s\t%s\t%s\n",Ip,Agent,User);
-       useragent_count++;
+       if (fp) {
+               fprintf(fp,"%s\t%s\t%s\n",Ip,Agent,User);
+               useragent_count++;
+       }
 }
 
 /*!
@@ -209,7 +213,7 @@ void UserAgent(void)
        double perc;
        struct getwordstruct gwarea;
 
-       if (!UserAgentTempLog[0]) return;
+       if (!UserAgentTempLog[0] || useragent_count==0) return;
 
        snprintf(tmp2,sizeof(tmp2),"%s/squagent.int_log",tmp);
        if (debug) {