]> git.ipfire.org Git - thirdparty/sarg.git/blobdiff - url.c
Rename configure.in as configure.ac
[thirdparty/sarg.git] / url.c
diff --git a/url.c b/url.c
index 2f0de542fc93c8c3a1745964949d3e1d7c29d913..8c55610c57fb574762b15007b5ae5bd80f42ca2b 100644 (file)
--- a/url.c
+++ b/url.c
@@ -1,6 +1,6 @@
 /*
  * SARG Squid Analysis Report Generator      http://sarg.sourceforge.net
- *                                                            1998, 2013
+ *                                                            1998, 2015
  *
  * SARG donations:
  *      please look at http://sarg.sourceforge.net/donations.php
@@ -147,14 +147,14 @@ static int Alias_StoreName(const char *name,const char *next)
                NameEnd=++str;
                while (str<next && (unsigned char)*str>' ') {
                        if (*str=='*') {
-                               debuga(_("Host name alias \"%s*%s\" contains too many wildcards (*)\n"),NameBegin,NameEnd);
+                               debuga(__FILE__,__LINE__,_("Host name alias \"%s*%s\" contains too many wildcards (*)\n"),NameBegin,NameEnd);
                                return(-1);
                        }
                        str++;
                }
                NameEndE=str;
                if (NameEnd==NameEndE) {
-                       debuga(_("Host name alias \"%*s\" must not end with a wildcard\n"),(int)(next-name),name);
+                       debuga(__FILE__,__LINE__,_("Host name alias \"%*s\" must not end with a wildcard\n"),(int)(next-name),name);
                        return(-1);
                }
        } else {
@@ -181,7 +181,7 @@ static int Alias_StoreName(const char *name,const char *next)
                len=(int)(NameBeginE-NameBegin);
                tmp=malloc(len+1);
                if (!tmp) {
-                       debuga(_("Not enough memory to store the host name aliasing directives\n"));
+                       debuga(__FILE__,__LINE__,_("Not enough memory to store the host name aliasing directives\n"));
                        return(-1);
                }
                memcpy(tmp,NameBegin,len);
@@ -193,7 +193,7 @@ static int Alias_StoreName(const char *name,const char *next)
                tmp=malloc(len+1);
                if (!tmp) {
                        if (NameBegin) free((void*)NameBegin);
-                       debuga(_("Not enough memory to store the host name aliasing directives\n"));
+                       debuga(__FILE__,__LINE__,_("Not enough memory to store the host name aliasing directives\n"));
                        return(-1);
                }
                memcpy(tmp,NameEnd,len);
@@ -217,7 +217,7 @@ static int Alias_StoreName(const char *name,const char *next)
        if (!new_alias) {
                if (NameBegin) free((void*)NameBegin);
                if (NameEnd) free((void*)NameEnd);
-               debuga(_("Not enough memory to store the host name aliasing directives\n"));
+               debuga(__FILE__,__LINE__,_("Not enough memory to store the host name aliasing directives\n"));
                return(-1);
        }
        new_alias->MinLen=0;
@@ -241,7 +241,7 @@ static int Alias_StoreName(const char *name,const char *next)
                len=(int)(ReplaceE-Replace);
                tmp=malloc(len+2);
                if (!tmp) {
-                       debuga(_("Not enough memory to store the host name aliasing directives\n"));
+                       debuga(__FILE__,__LINE__,_("Not enough memory to store the host name aliasing directives\n"));
                        return(-1);
                }
                tmp[0]=ALIAS_PREFIX;
@@ -251,7 +251,7 @@ static int Alias_StoreName(const char *name,const char *next)
        } else {
                tmp=malloc(new_alias->MinLen+2);
                if (!tmp) {
-                       debuga(_("Not enough memory to store the host name aliasing directives\n"));
+                       debuga(__FILE__,__LINE__,_("Not enough memory to store the host name aliasing directives\n"));
                        return(-1);
                }
                tmp[0]=ALIAS_PREFIX;
@@ -317,7 +317,7 @@ static int Alias_StoreIpv4(unsigned char *ipv4,int nbits,const char *next)
        // insert into the list
        new_alias=malloc(sizeof(*new_alias));
        if (!new_alias) {
-               debuga(_("Not enough memory to store the host name aliasing directives\n"));
+               debuga(__FILE__,__LINE__,_("Not enough memory to store the host name aliasing directives\n"));
                return(-1);
        }
        memcpy(new_alias->Ip,ipv4,4);
@@ -326,7 +326,7 @@ static int Alias_StoreIpv4(unsigned char *ipv4,int nbits,const char *next)
                len=(int)(ReplaceE-Replace);
                tmp=malloc(len+2);
                if (!tmp) {
-                       debuga(_("Not enough memory to store the host name aliasing directives\n"));
+                       debuga(__FILE__,__LINE__,_("Not enough memory to store the host name aliasing directives\n"));
                        return(-1);
                }
                tmp[0]=ALIAS_PREFIX;
@@ -336,7 +336,7 @@ static int Alias_StoreIpv4(unsigned char *ipv4,int nbits,const char *next)
        } else {
                tmp=malloc(5*4+1);
                if (!tmp) {
-                       debuga(_("Not enough memory to store the host name aliasing directives\n"));
+                       debuga(__FILE__,__LINE__,_("Not enough memory to store the host name aliasing directives\n"));
                        return(-1);
                }
                sprintf(tmp,"%c%d.%d.%d.%d/%d",ALIAS_PREFIX,ipv4[0],ipv4[1],ipv4[2],ipv4[3],nbits);
@@ -399,7 +399,7 @@ static int Alias_StoreIpv6(unsigned short *ipv6,int nbits,const char *next)
        // insert into the list
        new_alias=malloc(sizeof(*new_alias));
        if (!new_alias) {
-               debuga(_("Not enough memory to store the host name aliasing directives\n"));
+               debuga(__FILE__,__LINE__,_("Not enough memory to store the host name aliasing directives\n"));
                return(-1);
        }
        memcpy(new_alias->Ip,ipv6,8*sizeof(unsigned short int));
@@ -408,7 +408,7 @@ static int Alias_StoreIpv6(unsigned short *ipv6,int nbits,const char *next)
                len=ReplaceE-Replace;
                tmp=malloc(len+2);
                if (!tmp) {
-                       debuga(_("Not enough memory to store the host name aliasing directives\n"));
+                       debuga(__FILE__,__LINE__,_("Not enough memory to store the host name aliasing directives\n"));
                        return(-1);
                }
                tmp[0]=ALIAS_PREFIX;
@@ -418,7 +418,7 @@ static int Alias_StoreIpv6(unsigned short *ipv6,int nbits,const char *next)
        } else {
                tmp=malloc(5*8+5);
                if (!tmp) {
-                       debuga(_("Not enough memory to store the host name aliasing directives\n"));
+                       debuga(__FILE__,__LINE__,_("Not enough memory to store the host name aliasing directives\n"));
                        return(-1);
                }
                sprintf(tmp,"%c%x:%x:%x:%x:%x:%x:%x:%x/%d",ALIAS_PREFIX,ipv6[0],ipv6[1],ipv6[2],ipv6[3],ipv6[4],ipv6[5],ipv6[6],ipv6[7],nbits);
@@ -462,14 +462,14 @@ static int Alias_StoreRegexp(char *buf)
        for (End=buf ; *End && *End!=Delimiter ; End++) {
                if (*End=='\\') {
                        if (End[1]=='\0') {
-                               debuga(_("Invalid NUL character found in regular expression\n"));
+                               debuga(__FILE__,__LINE__,_("Invalid NUL character found in regular expression\n"));
                                return(-1);
                        }
                        End++; //ignore the escaped character
                }
        }
        if (*End!=Delimiter) {
-               debuga(_("Unterminated regular expression\n"));
+               debuga(__FILE__,__LINE__,_("Unterminated regular expression\n"));
                return(-1);
        }
        *End++='\0';
@@ -482,20 +482,20 @@ static int Alias_StoreRegexp(char *buf)
        // store it
        new_alias=malloc(sizeof(*new_alias));
        if (!new_alias) {
-               debuga(_("Not enough memory to store the host name aliasing directives\n"));
+               debuga(__FILE__,__LINE__,_("Not enough memory to store the host name aliasing directives\n"));
                return(-1);
        }
        new_alias->Next=NULL;
        new_alias->Re=pcre_compile(buf,0,&PcreError,&ErrorOffset,NULL);
        if (new_alias->Re==NULL) {
-               debuga(_("Failed to compile the regular expression \"%s\": %s\n"),buf,PcreError);
+               debuga(__FILE__,__LINE__,_("Failed to compile the regular expression \"%s\": %s\n"),buf,PcreError);
                free(new_alias);
                return(-1);
        }
        len=strlen(Replace);
        tmp=malloc(len+2);
        if (!tmp) {
-               debuga(_("Not enough memory to store the host name aliasing directives\n"));
+               debuga(__FILE__,__LINE__,_("Not enough memory to store the host name aliasing directives\n"));
                pcre_free(new_alias->Re);
                return(-1);
        }
@@ -547,7 +547,7 @@ static int Alias_Store(char *buf)
                        return(-1);
                return(0);
 #else
-               debuga(_("PCRE not compiled in therefore the regular expressions are not available in the host alias file\n"));
+               debuga(__FILE__,__LINE__,_("PCRE not compiled in therefore the regular expressions are not available in the host alias file\n"));
                return(-1);
 #endif
        }
@@ -578,47 +578,50 @@ void read_hostalias(const char *Filename)
        longline line;
        char *buf;
 
-       if (debug) debuga(_("Reading host alias file \"%s\"\n"),Filename);
+       if (debug) debuga(__FILE__,__LINE__,_("Reading host alias file \"%s\"\n"),Filename);
        fi=fopen(Filename,"rt");
        if (!fi) {
-               debuga(_("Cannot read host name alias file \"%s\" - %s\n"),Filename,strerror(errno));
+               debuga(__FILE__,__LINE__,_("Cannot read host name alias file \"%s\": %s\n"),Filename,strerror(errno));
                exit(EXIT_FAILURE);
        }
 
        if ((line=longline_create())==NULL) {
-               debuga(_("Not enough memory to read the host name aliases\n"));
+               debuga(__FILE__,__LINE__,_("Not enough memory to read file \"%s\"\n"),Filename);
                exit(EXIT_FAILURE);
        }
 
        while ((buf=longline_read(fi,line)) != NULL) {
                if (Alias_Store(buf)<0) {
-                       debuga(_("While reading \"%s\"\n"),Filename);
+                       debuga(__FILE__,__LINE__,_("While reading \"%s\"\n"),Filename);
                        exit(EXIT_FAILURE);
                }
        }
 
        longline_destroy(&line);
-       fclose(fi);
+       if (fclose(fi)==EOF) {
+               debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),Filename,strerror(errno));
+               exit(EXIT_FAILURE);
+       }
 
        if (debug) {
                struct hostalias_name *alias1;
                struct hostalias_ipv4 *alias4;
                struct hostalias_ipv6 *alias6;
 
-               debuga(_("List of host names to alias:\n"));
+               debuga(__FILE__,__LINE__,_("List of host names to alias:\n"));
                for (alias1=FirstAliasName ; alias1 ; alias1=alias1->Next) {
                        if (alias1->HostName_Prefix && alias1->HostName_Suffix)
-                               debuga(_("  %s*%s => %s\n"),alias1->HostName_Prefix,alias1->HostName_Suffix,alias1->Alias);
+                               debuga(__FILE__,__LINE__,_("  %s*%s => %s\n"),alias1->HostName_Prefix,alias1->HostName_Suffix,alias1->Alias);
                        else if (alias1->HostName_Prefix)
-                               debuga(_("  %s => %s\n"),alias1->HostName_Prefix,alias1->Alias);
+                               debuga(__FILE__,__LINE__,_("  %s => %s\n"),alias1->HostName_Prefix,alias1->Alias);
                        else
-                               debuga(_("  *%s => %s\n"),alias1->HostName_Suffix,alias1->Alias);
+                               debuga(__FILE__,__LINE__,_("  *%s => %s\n"),alias1->HostName_Suffix,alias1->Alias);
                }
                for (alias4=FirstAliasIpv4 ; alias4 ; alias4=alias4->Next) {
-                       debuga(_("  %d.%d.%d.%d/%d => %s\n"),alias4->Ip[0],alias4->Ip[1],alias4->Ip[2],alias4->Ip[3],alias4->NBits,alias4->Alias);
+                       debuga(__FILE__,__LINE__,_("  %d.%d.%d.%d/%d => %s\n"),alias4->Ip[0],alias4->Ip[1],alias4->Ip[2],alias4->Ip[3],alias4->NBits,alias4->Alias);
                }
                for (alias6=FirstAliasIpv6 ; alias6 ; alias6=alias6->Next) {
-                       debuga(_("  %x:%x:%x:%x:%x:%x:%x:%x/%d => %s\n"),alias6->Ip[0],alias6->Ip[1],alias6->Ip[2],alias6->Ip[3],
+                       debuga(__FILE__,__LINE__,_("  %x:%x:%x:%x:%x:%x:%x:%x/%d => %s\n"),alias6->Ip[0],alias6->Ip[1],alias6->Ip[2],alias6->Ip[3],
                                alias6->Ip[4],alias6->Ip[5],alias6->Ip[6],alias6->Ip[7],alias6->NBits,alias6->Alias);
                }
        }