"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "exclude.c" between
sarg-2.3.11.tar.gz and sarg-2.4.0.tar.gz

About: SARG ia a Squid Analysis Report Generator.

exclude.c  (sarg-2.3.11):exclude.c  (sarg-2.4.0)
/* /*
* SARG Squid Analysis Report Generator http://sarg.sourceforge.net * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
* 1998, 2013 * 1998, 2015
* *
* SARG donations: * SARG donations:
* please look at http://sarg.sourceforge.net/donations.php * please look at http://sarg.sourceforge.net/donations.php
* Support: * Support:
* http://sourceforge.net/projects/sarg/forums/forum/363374 * http://sourceforge.net/projects/sarg/forums/forum/363374
* --------------------------------------------------------------------- * ---------------------------------------------------------------------
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
skipping to change at line 82 skipping to change at line 82
static void store_exclude_ip4(unsigned char *addr,int nbits) static void store_exclude_ip4(unsigned char *addr,int nbits)
{ {
int i; int i;
if (num_exclude_ip4>=ip4allocated) { if (num_exclude_ip4>=ip4allocated) {
struct hostip4struct *temp; struct hostip4struct *temp;
ip4allocated+=5; ip4allocated+=5;
temp=realloc(exclude_ip4,ip4allocated*sizeof(*temp)); temp=realloc(exclude_ip4,ip4allocated*sizeof(*temp));
if (temp==NULL) { if (temp==NULL) {
debuga(_("Not enough memory to store the exlcluded IP add resses\n")); debuga(__FILE__,__LINE__,_("Not enough memory to store th e exlcluded IP addresses\n"));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
exclude_ip4=temp; exclude_ip4=temp;
} }
exclude_ip4[num_exclude_ip4].address=0UL; exclude_ip4[num_exclude_ip4].address=0UL;
for (i=0 ; i<4 ; i++) for (i=0 ; i<4 ; i++)
exclude_ip4[num_exclude_ip4].address=(exclude_ip4[num_exclude_ip4 ].address<<8) | (unsigned char)(addr[i] & 0xFFU); exclude_ip4[num_exclude_ip4].address=(exclude_ip4[num_exclude_ip4 ].address<<8) | (unsigned char)(addr[i] & 0xFFU);
exclude_ip4[num_exclude_ip4].mask=(0xFFFFFFFFUL << (32-nbits)); exclude_ip4[num_exclude_ip4].mask=(0xFFFFFFFFUL << (32-nbits));
num_exclude_ip4++; num_exclude_ip4++;
} }
skipping to change at line 110 skipping to change at line 110
static void store_exclude_ip6(unsigned short *addr,int nbits) static void store_exclude_ip6(unsigned short *addr,int nbits)
{ {
int i; int i;
if (num_exclude_ip6>=ip6allocated) { if (num_exclude_ip6>=ip6allocated) {
struct hostip6struct *temp; struct hostip6struct *temp;
ip6allocated+=5; ip6allocated+=5;
temp=realloc(exclude_ip6,ip6allocated*sizeof(*temp)); temp=realloc(exclude_ip6,ip6allocated*sizeof(*temp));
if (temp==NULL) { if (temp==NULL) {
debuga(_("Not enough memory to store the exlcluded IP add resses\n")); debuga(__FILE__,__LINE__,_("Not enough memory to store th e exlcluded IP addresses\n"));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
exclude_ip6=temp; exclude_ip6=temp;
} }
for (i=0 ; i<8 ; i++) for (i=0 ; i<8 ; i++)
exclude_ip6[num_exclude_ip6].address[i]=addr[i]; exclude_ip6[num_exclude_ip6].address[i]=addr[i];
exclude_ip6[num_exclude_ip6].nbits=nbits; exclude_ip6[num_exclude_ip6].nbits=nbits;
num_exclude_ip6++; num_exclude_ip6++;
} }
skipping to change at line 161 skipping to change at line 161
url+=start; url+=start;
length-=start; length-=start;
} }
if (num_exclude_name>=nameallocated) { if (num_exclude_name>=nameallocated) {
struct hostnamestruct *temp; struct hostnamestruct *temp;
nameallocated+=5; nameallocated+=5;
temp=realloc(exclude_name,nameallocated*sizeof(*temp)); temp=realloc(exclude_name,nameallocated*sizeof(*temp));
if (temp==NULL) { if (temp==NULL) {
debuga(_("Not enough memory to store the excluded URLs\n" )); debuga(__FILE__,__LINE__,_("Not enough memory to store th e excluded URLs\n"));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
exclude_name=temp; exclude_name=temp;
} }
item=exclude_name+num_exclude_name; item=exclude_name+num_exclude_name;
num_exclude_name++; num_exclude_name++;
item->url=malloc(length+1); item->url=malloc(length+1);
if (!item->url) { if (!item->url) {
debuga(_("Not enough memory to store the excluded URLs\n")); debuga(__FILE__,__LINE__,_("Not enough memory to store the exclud ed URLs\n"));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
safe_strcpy(item->url,url,length+1); safe_strcpy(item->url,url,length+1);
item->ndots=(ndots>0) ? ndots : -1; item->ndots=(ndots>0) ? ndots : -1;
} }
/*! /*!
Read the file listing the host to exclude from the report. Read the file listing the host to exclude from the report.
\param hexfile The name of the file. \param hexfile The name of the file.
skipping to change at line 195 skipping to change at line 195
{ {
FILE *fp_ex; FILE *fp_ex;
char buf[255]; char buf[255];
int type; int type;
const char *name; const char *name;
unsigned char ipv4[4]; unsigned char ipv4[4];
unsigned short int ipv6[8]; unsigned short int ipv6[8];
int nbits; int nbits;
const char *next; const char *next;
if(access(hexfile, R_OK) != 0) { if (access(hexfile, R_OK) != 0) {
debuga(_("Cannot open file \"%s\": %s\n"),hexfile,strerror(errno) debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),hexfi
); le,strerror(errno));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if(debug) 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) { if ((fp_ex = fopen(hexfile, "r")) == NULL) {
debugapos("gethexclude",_("Cannot open file \"%s\": %s\n"),hexfil e,strerror(errno)); debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),hexfi le,strerror(errno));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
while(fgets(buf,sizeof(buf),fp_ex)!=NULL){ while(fgets(buf,sizeof(buf),fp_ex)!=NULL){
if(buf[0]=='#') if (buf[0]=='#')
continue; continue;
fixendofline(buf); fixendofline(buf);
type=extract_address_mask(buf,&name,ipv4,ipv6,&nbits,&next); type=extract_address_mask(buf,&name,ipv4,ipv6,&nbits,&next);
if (type<0) { if (type<0) {
debuga(_("While reading \"%s\"\n"),hexfile); debuga(__FILE__,__LINE__,_("While reading \"%s\"\n"),hexf ile);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (type==1) { if (type==1) {
store_exclude_url(name,next); store_exclude_url(name,next);
} else if (type==2) { } else if (type==2) {
store_exclude_ip4(ipv4,nbits); store_exclude_ip4(ipv4,nbits);
} else if (type==3) { } else if (type==3) {
store_exclude_ip6(ipv6,nbits); store_exclude_ip6(ipv6,nbits);
} }
} }
fclose(fp_ex); if (fclose(fp_ex)==EOF) {
debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),hexfile,
strerror(errno));
exit(EXIT_FAILURE);
}
return; return;
} }
/*! /*!
Check if the URL is excluded as per the host exclusion list. Check if the URL is excluded as per the host exclusion list.
\param url The URL to check. \param url The URL to check.
\retval 1 Keep the URL. \retval 1 Keep the URL.
\retval 0 Exclude the URL. \retval 0 Exclude the URL.
skipping to change at line 312 skipping to change at line 315
} }
return(1); return(1);
} }
void getuexclude(const char *uexfile, int debug) void getuexclude(const char *uexfile, int debug)
{ {
FILE *fp_ex; FILE *fp_ex;
char buf[255]; char buf[255];
long int nreg=0; long int nreg=0;
if(debug) 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) { if ((fp_ex = fopen(uexfile, "r")) == NULL) {
debugapos("gethexclude",_("Cannot open file \"%s\": %s\n"),uexfil e,strerror(errno)); debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),uexfi le,strerror(errno));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (fseek(fp_ex, 0, SEEK_END)==-1) { if (fseek(fp_ex, 0, SEEK_END)==-1) {
debuga(_("Failed to move till the end of file \"%s\": %s\n"),uexf ile,strerror(errno)); debuga(__FILE__,__LINE__,_("Failed to move till the end of file \ "%s\": %s\n"),uexfile,strerror(errno));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
nreg = ftell(fp_ex); nreg = ftell(fp_ex);
if (nreg<0) { if (nreg<0) {
debuga(_("Cannot get the size of file \"%s\": %s\n"),uexfile,stre rror(errno)); debuga(__FILE__,__LINE__,_("Cannot get the size of file \"%s\"\n" ),uexfile);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
nreg += 11; nreg += 11;
if (fseek(fp_ex, 0, SEEK_SET)==-1) { if (fseek(fp_ex, 0, SEEK_SET)==-1) {
debuga(_("Failed to rewind file \"%s\": %s\n"),uexfile,strerror(e rrno)); debuga(__FILE__,__LINE__,_("Failed to rewind file \"%s\": %s\n"), uexfile,strerror(errno));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if((excludeuser=(char *) malloc(nreg))==NULL){ if ((excludeuser=(char *) malloc(nreg))==NULL){
debuga(_("malloc failed to allocate %ld bytes\n"),nreg); debuga(__FILE__,__LINE__,_("malloc error (%ld bytes required)\n")
,nreg);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
bzero(excludeuser,nreg); memset(excludeuser,0,nreg);
while(fgets(buf,sizeof(buf),fp_ex)!=NULL){ while(fgets(buf,sizeof(buf),fp_ex)!=NULL){
if(strchr(buf,'#') != NULL) if (strchr(buf,'#') != NULL)
continue; continue;
fixendofline(buf); fixendofline(buf);
strcat(excludeuser,buf); strcat(excludeuser,buf);
strcat(excludeuser," "); strcat(excludeuser," ");
} }
strcat(excludeuser,"*END* "); 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; return;
} }
int vuexclude(const char *user) int vuexclude(const char *user)
{ {
const char *wuser; const char *wuser;
int len; int len;
if (excludeuser) { if (excludeuser) {
skipping to change at line 396 skipping to change at line 402
exclude_ip4=NULL; exclude_ip4=NULL;
} }
if (exclude_name) { if (exclude_name) {
for (i=0 ; i<num_exclude_name ; i++) for (i=0 ; i<num_exclude_name ; i++)
if (exclude_name[i].url) free(exclude_name[i].url); if (exclude_name[i].url) free(exclude_name[i].url);
free(exclude_name); free(exclude_name);
exclude_name=NULL; exclude_name=NULL;
} }
if(excludeuser) { if (excludeuser) {
free(excludeuser); free(excludeuser);
excludeuser=NULL; excludeuser=NULL;
} }
} }
 End of changes. 21 change blocks. 
26 lines changed or deleted 37 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)