From: Frédéric Marchal Date: Tue, 3 Jul 2012 19:13:23 +0000 (+0200) Subject: Store the URL in the structure X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e2379f0549388edd94e3cf713819530a909bc845;p=thirdparty%2Fsarg.git Store the URL in the structure The structure is to be shared with several modules. As a side effect, the denied and authentication failure reports now display the full URL even when the short URL is requested. It has to be defined whether this is desirable or not. --- diff --git a/include/defs.h b/include/defs.h index 506781f..f8c1e73 100755 --- a/include/defs.h +++ b/include/defs.h @@ -240,7 +240,7 @@ void day_totalize(DayObject ddata,const char *tmp, const struct userinfostruct * void read_hostalias(const char *Filename); void free_hostalias(void); const char *skip_scheme(const char *url); -const char *process_url(char *url,bool full_url); +const char *process_url(const char *url,bool full_url); void url_hostname(const char *url,char *hostname,int hostsize); // usage.c diff --git a/readlog.c b/readlog.c index 5b9d132..ec24349 100644 --- a/readlog.c +++ b/readlog.c @@ -78,7 +78,6 @@ int ReadLogFile(struct ReadLogDataStruct *Filter) longline line; char *linebuf; char *str; - char *full_url; char arq_log[255]; char fun[MAXLEN]; char elap[255]; @@ -327,7 +326,7 @@ int ReadLogFile(struct ReadLogDataStruct *Filter) debuga(_("Maybe you have a broken record or garbage in your %s file\n"),arq); exit(EXIT_FAILURE); } - if (getword_ptr(linebuf,&full_url,&gwarea,' ')<0) { + 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); } @@ -426,7 +425,7 @@ int ReadLogFile(struct ReadLogDataStruct *Filter) debuga(_("Maybe you have a broken request method in your %s file\n"),arq); exit(EXIT_FAILURE); } - if (getword_ptr(linebuf,&full_url,&gwarea,' ')<0){ + 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); } @@ -470,7 +469,7 @@ int ReadLogFile(struct ReadLogDataStruct *Filter) exit(EXIT_FAILURE); } log_entry.Ip=ip; - if (getword_ptr(linebuf,&full_url,&gwarea,'\t')<0){ + 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); } @@ -586,7 +585,7 @@ int ReadLogFile(struct ReadLogDataStruct *Filter) } else if (x==isa_cols[ISACOL_Bytes]) { log_entry.DataSize=atoll(str); } else if (x==isa_cols[ISACOL_Uri]) { - full_url=str; + 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); @@ -640,6 +639,10 @@ int ReadLogFile(struct ReadLogDataStruct *Filter) debuga(_("Unknown input log file format: no user\n")); break; } + if (log_entry.Url==NULL) { + debuga(_("Unknown input log file format: no URL\n")); + break; + } if(debugm) printf("DATE=%s IDATA=%d DFROM=%d DUNTIL=%d\n",Filter->DateRange,idata,dfrom,duntil); @@ -679,7 +682,7 @@ int ReadLogFile(struct ReadLogDataStruct *Filter) continue; // replace any tab by a single space - for (str=full_url ; *str ; str++) + for (str=log_entry.Url ; *str ; str++) if (*str=='\t') *str=' '; for (str=log_entry.HttpCode ; *str ; str++) if (*str=='\t') *str=' '; @@ -689,15 +692,15 @@ int ReadLogFile(struct ReadLogDataStruct *Filter) The full URL is not saved in sarg log. There is no point in testing the URL to detect a downloaded file. */ - download_flag=is_download_suffix(full_url); + download_flag=is_download_suffix(log_entry.Url); if (download_flag) { - safe_strcpy(download_url,full_url,sizeof(download_url)); + safe_strcpy(download_url,log_entry.Url,sizeof(download_url)); download_count++; } } else download_flag=false; - url=process_url(full_url,LongUrl); + url=process_url(log_entry.Url,LongUrl); if (!url || url[0] == '\0') continue; if(addr[0] != '\0'){ @@ -863,12 +866,12 @@ int ReadLogFile(struct ReadLogDataStruct *Filter) } 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); + fprintf(fp_denied, "%s\t%s\t%s\t%s\t%s\n",dia,hora,log_entry.User,log_entry.Ip,log_entry.Url); denied_count++; } if((ReportType & REPORT_TYPE_AUTH_FAILURES) != 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); + fprintf(fp_authfail, "%s\t%s\t%s\t%s\t%s\n",dia,hora,log_entry.User,log_entry.Ip,log_entry.Url); authfail_count++; } } diff --git a/url.c b/url.c index 3cdba73..1a43ec3 100644 --- a/url.c +++ b/url.c @@ -857,9 +857,10 @@ Get the part of the URL necessary to generate the report. \param full_url \c True to keep the whole URL. If \c false, the URL is truncated to only keep the host name and port number. */ -const char *process_url(char *url,bool full_url) +const char *process_url(const char *url,bool full_url) { - char *str; + static char short_url[1024]; + int i; const char *start; int type; unsigned char ipv4[4]; @@ -868,8 +869,10 @@ const char *process_url(char *url,bool full_url) start=skip_scheme(url); if (!full_url) { - for (str=(char *)start ; *str && *str!='/' && *str!='?' ; str++); - *str='\0'; + for (i=0 ; i