]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Store the URL in the structure
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Tue, 3 Jul 2012 19:13:23 +0000 (21:13 +0200)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Tue, 3 Jul 2012 19:13:23 +0000 (21:13 +0200)
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.

include/defs.h
readlog.c
url.c

index 506781fc53cfe04593272a80e9dccbaae315c780..f8c1e7315e57cb2914999bdd246c238e36a04c07 100755 (executable)
@@ -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
index 5b9d132a7cfac1a96de3bca7dc591e3c1b58a4a6..ec243495a2d97d4ae4e99315b578d325caa2f09b 100644 (file)
--- 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 3cdba7379fe02197c5cc83704275b04176e32190..1a43ec3cb277d6c66acf08cdfa4321b88fde388f 100644 (file)
--- 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<sizeof(short_url)-1 && start[i] && start[i]!='/' && start[i]!='?' ; i++)
+                       short_url[i]=start[i];
+               short_url[i]='\0';
+               start=short_url;
 #ifdef USE_PCRE
                if (FirstAliasRe) {
                        if (alias_url_regex(&start)) return(start);