/*
* SARG Squid Analysis Report Generator http://sarg.sourceforge.net
- * 1998, 2011
+ * 1998, 2015
*
* SARG donations:
* please look at http://sarg.sourceforge.net/donations.php
/*!
Store a IPv4 address to exclude from the reported URL.
-
+
\param addr The 4 char of the address.
\param nbits The number of bits to keep in the prefix.
*/
ip4allocated+=5;
temp=realloc(exclude_ip4,ip4allocated*sizeof(*temp));
if (temp==NULL) {
- debuga(_("Not enough memory to store the exlcluded IP addresses\n"));
+ debuga(__FILE__,__LINE__,_("Not enough memory to store the exlcluded IP addresses\n"));
exit(EXIT_FAILURE);
}
exclude_ip4=temp;
/*!
Store a IPv6 address to exclude from the reported URL.
-
+
\param addr The 8 short int of the address.
\param nbits The number of bits to keep in the prefix.
*/
ip6allocated+=5;
temp=realloc(exclude_ip6,ip6allocated*sizeof(*temp));
if (temp==NULL) {
- debuga(_("Not enough memory to store the exlcluded IP addresses\n"));
+ debuga(__FILE__,__LINE__,_("Not enough memory to store the exlcluded IP addresses\n"));
exit(EXIT_FAILURE);
}
exclude_ip6=temp;
/*!
Store a host name to exclude from the report.
-
+
\param url The host name to exclude.
*/
static void store_exclude_url(const char *url,const char *next)
nameallocated+=5;
temp=realloc(exclude_name,nameallocated*sizeof(*temp));
if (temp==NULL) {
- debuga(_("Not enough memory to store the excluded URLs\n"));
+ debuga(__FILE__,__LINE__,_("Not enough memory to store the excluded URLs\n"));
exit(EXIT_FAILURE);
}
exclude_name=temp;
num_exclude_name++;
item->url=malloc(length+1);
if (!item->url) {
- debuga(_("Not enough memory to store the excluded URLs\n"));
+ debuga(__FILE__,__LINE__,_("Not enough memory to store the excluded URLs\n"));
exit(EXIT_FAILURE);
}
safe_strcpy(item->url,url,length+1);
/*!
Read the file listing the host to exclude from the report.
-
+
\param hexfile The name of the file.
\param debug \c True to print debug information.
*/
const char *next;
if(access(hexfile, R_OK) != 0) {
- debuga(_("Cannot open exclude_hosts file: %s - %s\n"),hexfile,strerror(errno));
+ debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),hexfile,strerror(errno));
exit(EXIT_FAILURE);
}
if(debug)
- debuga(_("Loading exclude host file from: %s\n"),hexfile);
+ debuga(__FILE__,__LINE__,_("Loading exclude host file from \"%s\"\n"),hexfile);
if ((fp_ex = fopen(hexfile, "r")) == NULL) {
- debuga(_("(gethexclude) Cannot open file %s - %s\n"),hexfile,strerror(errno));
+ debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),hexfile,strerror(errno));
exit(EXIT_FAILURE);
}
type=extract_address_mask(buf,&name,ipv4,ipv6,&nbits,&next);
if (type<0) {
- debuga(_("While reading \"%s\""),hexfile);
+ debuga(__FILE__,__LINE__,_("While reading \"%s\"\n"),hexfile);
exit(EXIT_FAILURE);
}
}
}
- fclose(fp_ex);
+ if (fclose(fp_ex)==EOF) {
+ debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),hexfile,strerror(errno));
+ exit(EXIT_FAILURE);
+ }
return;
}
/*!
Check if the URL is excluded as per the host exclusion list.
-
+
\param url The URL to check.
-
+
\retval 1 Keep the URL.
\retval 0 Exclude the URL.
*/
long int nreg=0;
if(debug)
- debuga(_("Loading exclude file from: %s\n"),uexfile);
+ debuga(__FILE__,__LINE__,_("Loading exclude file from \"%s\"\n"),uexfile);
if ((fp_ex = fopen(uexfile, "r")) == NULL) {
- debuga(_("(gethexclude) Cannot open file %s - %s\n"),uexfile,strerror(errno));
+ debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),uexfile,strerror(errno));
exit(EXIT_FAILURE);
}
if (fseek(fp_ex, 0, SEEK_END)==-1) {
- debuga(_("Failed to move till the end of the excluded users file %s: %s\n"),uexfile,strerror(errno));
+ debuga(__FILE__,__LINE__,_("Failed to move till the end of file \"%s\": %s\n"),uexfile,strerror(errno));
exit(EXIT_FAILURE);
}
nreg = ftell(fp_ex);
if (nreg<0) {
- debuga(_("Cannot get the size of file %s\n"),uexfile);
+ debuga(__FILE__,__LINE__,_("Cannot get the size of file \"%s\"\n"),uexfile);
exit(EXIT_FAILURE);
}
nreg += 11;
if (fseek(fp_ex, 0, SEEK_SET)==-1) {
- debuga(_("Failed to rewind the excluded users file %s: %s\n"),uexfile,strerror(errno));
+ debuga(__FILE__,__LINE__,_("Failed to rewind file \"%s\": %s\n"),uexfile,strerror(errno));
exit(EXIT_FAILURE);
}
if((excludeuser=(char *) malloc(nreg))==NULL){
- debuga(_("malloc error (%ld bytes required)\n"),nreg);
+ debuga(__FILE__,__LINE__,_("malloc error (%ld bytes required)\n"),nreg);
exit(EXIT_FAILURE);
}
- bzero(excludeuser,nreg);
+ memset(excludeuser,0,nreg);
while(fgets(buf,sizeof(buf),fp_ex)!=NULL){
if(strchr(buf,'#') != NULL)
strcat(excludeuser,"*END* ");
- fclose(fp_ex);
+ if (fclose(fp_ex)==EOF) {
+ debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),uexfile,strerror(errno));
+ exit(EXIT_FAILURE);
+ }
return;
}