+++ /dev/null
-/*!\file download.c
-\brief Report the downloaded files
-*/
-
-
-/*! \var static char *DownloadSuffix=NULL;
-The buffer to store the list of the suffixes to take into account when generating
-the report of the downloaded files. The suffixes in the list are separated by the ASCII
-null.
-*/
-
-
-
-/*! \var static char **DownloadSuffixIndex=NULL;
-The index of all the suffixes stored in ::DownloadSuffix. The list is sorted alphabetically.
-to speed up the search.
-*/
-
-
-/*! \var static int NDownloadSuffix=0;
-The number of suffixes in ::DownloadSuffixIndex.
-*/
-
-
-
-/*! \fn void download_report(void)
-Generate the report of the downloaded files. The list of the suffixes to take into account
-is set with set_download_suffix().
-*/
-
-
-
-/*! \fn void free_download(void)
-Free the memory allocated by set_download_suffix().
-*/
-
-
-
-/*! \fn void set_download_suffix(const char *list)
-Set the list of the suffixes corresponding to the download of files you want to detect with
-is_download_suffix(). The list is sorted to make the search faster.
-
-\param list A comma separated list of the suffixes to set in ::DownloadSuffix.
-
-\note The memory allocated by this function must be freed by free_download().
-*/
-
-
-
-
-
-/*! \fn int is_download_suffix(const char *url)
-Tell if the URL correspond to a downloaded file. The function takes the extension at the end of the
-URL with a maximum of 9 characters and compare it to the list of the download suffix in
-::DownloadSuffix. If the suffix is found in the list, the function reports the URL as the download
-of a file.
-
-\param url The URL to test.
-
-\retval 1 The URL matches a suffix of a download.
-\retval 0 The URL is not a known download.
-
-\note A downloaded file cannot be detected if the file name is embedded in a GET or POST request. Only requests
-that ends with the file name can be detected.
-
-\note A URL embedding another web site's address ending by .com at the end of the URL will match the download
-extension com if it is defined in the ::DownloadSuffix.
-*/
-
-
-
-
#include "include/conf.h"
#include "include/defs.h"
+/*!
+The buffer to store the list of the suffixes to take into account when generating
+the report of the downloaded files. The suffixes in the list are separated by the ASCII
+null.
+*/
/*@null@*/static char *DownloadSuffix=NULL;
+
+/*!
+The index of all the suffixes stored in ::DownloadSuffix. The list is sorted alphabetically.
+to speed up the search.
+*/
/*@null@*/static char **DownloadSuffixIndex=NULL;
+
+/*!
+The number of suffixes in ::DownloadSuffixIndex.
+*/
static int NDownloadSuffix=0;
+/*!
+Sort the raw log file with the downloaded files.
+
+\param report_in The name of the file where to store the sorted entries.
+*/
+static void download_sort(const char *report_in)
+{
+ int clen;
+ char csort[MAXLEN];
+ int cstatus;
+
+ clen=snprintf(csort,sizeof(csort),"sort -T \"%s\" -t \"\t\" -k 3,3 -k 1,1 -k 2,2 -k 5,5 -o \"%s\" \"%s/download.unsort\"",
+ tmp, report_in, tmp);
+ if (clen>=sizeof(csort)) {
+ debuga(_("Path too long to sort the file: %s\n"),csort);
+ exit(EXIT_FAILURE);
+ }
+ cstatus=system(csort);
+ if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
+ debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus));
+ debuga(_("sort command: %s\n"),csort);
+ exit(EXIT_FAILURE);
+ }
+ if (snprintf(csort,sizeof(csort),"%s/download.unsort",tmp)>=sizeof(csort)) {
+ debuga(_("Path too long for %s/download.unsort\n"),tmp);
+ exit(EXIT_FAILURE);
+ }
+ if (unlink(csort)) {
+ debuga(_("Cannot delete %s - %s\n"),csort,strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+}
+
+/*!
+Generate the report of the downloaded files. The list of the suffixes to take into account
+is set with set_download_suffix().
+*/
void download_report(void)
{
FILE *fp_in = NULL, *fp_ou = NULL;
ouser[0]='\0';
ouser2[0]='\0';
+ // sort the raw file
snprintf(report_in,sizeof(report_in),"%s/download.log",tmp);
+ download_sort(report_in);
if(access(report_in, R_OK) != 0) {
if (debugz) debugaz(_("Downloaded files report not generated as it is empty\n"));
return;
}
+ // produce the report.
snprintf(report,sizeof(report),"%s/download.html",outdirname);
if((fp_in=MY_FOPEN(report_in,"r"))==NULL) {
return;
}
+/*!
+Free the memory allocated by set_download_suffix().
+*/
void free_download(void)
{
if (DownloadSuffix) {
NDownloadSuffix=0;
}
+/*!
+Set the list of the suffixes corresponding to the download of files you want to detect with
+is_download_suffix(). The list is sorted to make the search faster.
+
+\param list A comma separated list of the suffixes to set in ::DownloadSuffix.
+
+\note The memory allocated by this function must be freed by free_download().
+*/
void set_download_suffix(const char *list)
{
char *str;
}
}
+/*!
+Tell if the URL correspond to a downloaded file. The function takes the extension at the end of the
+URL with a maximum of 9 characters and compare it to the list of the download suffix in
+::DownloadSuffix. If the suffix is found in the list, the function reports the URL as the download
+of a file.
+
+\param url The URL to test.
+
+\retval 1 The URL matches a suffix of a download.
+\retval 0 The URL is not a known download.
+
+\note A downloaded file cannot be detected if the file name is embedded in a GET or POST request. Only requests
+that ends with the file name can be detected.
+
+\note A URL embedding another web site's address ending by .com at the end of the URL will match the download
+extension com if it is defined in the ::DownloadSuffix.
+*/
bool is_download_suffix(const char *url)
{
int urllen;
continue;
if(strcmp(direntp->d_name,"authfail.log.unsort") == 0)
continue;
+ if(strcmp(direntp->d_name,"download.unsort") == 0)
+ continue;
if (dlen>0) {
if (dlen>=sizeof(user)) continue;
user[0]='\0';
}
- if(strcmp(direntp->d_name,"download.unsort") == 0)
- clen=snprintf(csort,sizeof(csort),"sort -T \"%s\" -t \"\t\" -k 3,3 -k 1,1 -k 2,2 -k 5,5 -o \"%s/%s.log\" \"%s/%s.unsort\"",
- tmp, tmp, user, tmp, user);
- else
- clen=snprintf(csort,sizeof(csort),"sort -T \"%s\" -t \"\t\" -k 4,4 -k 1,1 -k 2,2 -o \"%s/%s.log\" \"%s/%s.unsort\"",
- tmp, tmp, user, tmp, user);
+ clen=snprintf(csort,sizeof(csort),"sort -T \"%s\" -t \"\t\" -k 4,4 -k 1,1 -k 2,2 -o \"%s/%s.log\" \"%s/%s.unsort\"",
+ tmp, tmp, user, tmp, user);
if (clen>=sizeof(csort)) {
debuga(_("user name too long to sort %s\n"),csort);
exit(EXIT_FAILURE);