]> git.ipfire.org Git - thirdparty/sarg.git/blobdiff - ip2name.c
Rename configure.in as configure.ac
[thirdparty/sarg.git] / ip2name.c
index 3f6b3e5175ec88f1a009b4d2f845cb295d1ae6b3..d30f3f787d73c798a3a87b76d7f0bcbeaedda227 100644 (file)
--- a/ip2name.c
+++ b/ip2name.c
@@ -1,6 +1,6 @@
 /*
  * SARG Squid Analysis Report Generator      http://sarg.sourceforge.net
- *                                                            1998, 2012
+ *                                                            1998, 2015
  *
  * SARG donations:
  *      please look at http://sarg.sourceforge.net/donations.php
@@ -62,18 +62,18 @@ static void ip2name_chainmodule(struct Ip2NameProcess *Module)
 {
        struct Ip2NameProcess *Chain;
        struct Ip2NameProcess *Last;
-       
-       if (debug) debuga(_("Chaining IP resolving module \"%s\"\n"),Module->Name);
-       
+
+       if (debug) debuga(__FILE__,__LINE__,_("Chaining IP resolving module \"%s\"\n"),Module->Name);
+
        Last=NULL;
        for (Chain=FirstModule ; Chain ; Chain=Chain->Next) {
                if (Chain==Module) {
-                       debuga(_("Ignoring duplicate module \"%s\" to resolve an IP address\n"),Module->Name);
+                       debuga(__FILE__,__LINE__,_("Ignoring duplicate module \"%s\" to resolve an IP address\n"),Module->Name);
                        return;
                }
                Last=Chain;
        }
-       
+
        if (Last)
                Last->Next=Module;
        else {
@@ -92,7 +92,7 @@ static void ip2name_buildmoduleslist(const char *list)
        const char *candidate;
        int length;
        int ModuleIdx;
-       
+
        while (*list) {
                candidate=list;
                while (*candidate && (unsigned char)*candidate<=' ') candidate++;
@@ -106,7 +106,7 @@ static void ip2name_buildmoduleslist(const char *list)
                        }
                }
                if (ModuleIdx>=sizeof(ModulesList)/sizeof(*ModulesList)) {
-                       debuga(_("Unknown module \"%.*s\" to resolve the IP addresses\n"),length,candidate);
+                       debuga(__FILE__,__LINE__,_("Unknown module \"%.*s\" to resolve the IP addresses\n"),length,candidate);
                        exit(EXIT_FAILURE);
                }
                list=candidate+length;
@@ -123,14 +123,14 @@ static void ip2name_configmodule(const char *module)
 {
        int length;
        unsigned int ModuleIdx;
-       
+
        for (length=0 ; module[length] && (unsigned char)module[length]>' ' ; length++);
        for (ModuleIdx=0 ; ModuleIdx<sizeof(ModulesList)/sizeof(*ModulesList) ; ModuleIdx++) {
                if (strncasecmp(module,ModulesList[ModuleIdx].Name,length)==0 && ModulesList[ModuleIdx].Name[length]=='\0') {
                        // module found
                        if (ModulesList[ModuleIdx].Process) {
                                if (!ModulesList[ModuleIdx].Process->Configure) {
-                                       debuga(_("No option to configure for module %s\n"),ModulesList[ModuleIdx].Name);
+                                       debuga(__FILE__,__LINE__,_("No option to configure for module %s\n"),ModulesList[ModuleIdx].Name);
                                        exit(EXIT_FAILURE);
                                }
                                while (module[length] && (unsigned char)module[length]<=' ') length++;
@@ -157,13 +157,13 @@ int ip2name_config(const char *param)
                ip2name_buildmoduleslist(param);
                return(1);
        }
-       
+
        // parameter for a module?
        if (*param=='_') {
                ip2name_configmodule(param+1);
                return(1);
        }
-       
+
        return(0);
 }
 
@@ -176,7 +176,7 @@ void ip2name_forcedns(void)
        int i;
        struct Ip2NameProcess *Chain;
        struct Ip2NameProcess *Last;
-       
+
        // find the dns module
        for (i=0 ; i<sizeof(ModulesList)/sizeof(*ModulesList) ; i++) {
                if (strcmp("dns",ModulesList[i].Name)==0) {
@@ -186,16 +186,16 @@ void ip2name_forcedns(void)
                }
        }
        if (!DnsModule) {
-               if (debugz) debuga(_("No known module to resolve an IP address using the DNS\n"));
+               if (debugz>=LogLevel_Process) debuga(__FILE__,__LINE__,_("No known module to resolve an IP address using the DNS\n"));
                exit(EXIT_FAILURE);
        }
-       
+
        // add the module to the list if it isn't there yet
        Last=NULL;
        for (Chain=FirstModule ; Chain && Chain!=DnsModule ; Chain=Chain->Next) {
                Last=Chain;
        }
-       if (debug) debuga(_("Chaining IP resolving module \"%s\"\n"),DnsModule->Name);
+       if (debug) debuga(__FILE__,__LINE__,_("Chaining IP resolving module \"%s\"\n"),DnsModule->Name);
        if (Last)
                Last->Next=DnsModule;
        else {
@@ -219,21 +219,21 @@ void ip2name(char *ip,int ip_len)
        enum ip2name_retcode Status;
        const char *Name;
        char OrigIp[80];
-       
+
        if (!KnownIp) {
                KnownIp=Dichotomic_Create();
                if (!KnownIp) {
-                       debuga(_("Not enough memory to store the names corresponding to the IP address\n"));
+                       debuga(__FILE__,__LINE__,_("Not enough memory to store the names corresponding to the IP address\n"));
                        exit(EXIT_FAILURE);
                }
        }
-       
+
        Name=Dichotomic_Search(KnownIp,ip);
        if (Name) {
                safe_strcpy(ip,Name,ip_len);
                return;
        }
-       
+
        safe_strcpy(OrigIp,ip,sizeof(OrigIp));
        for (Module=FirstModule ; Module ; Module=Module->Next) {
                if (Module->Resolve) {
@@ -276,14 +276,14 @@ void name2ip(char *name,int name_size)
        error=getaddrinfo(addr,NULL,NULL,&res);
        if (error) {
                freeaddrinfo(res);
-               debuga(_("Cannot resolve host name %s: %s\n"),name,gai_strerror(error));
+               debuga(__FILE__,__LINE__,_("Cannot resolve host name %s: %s\n"),name,gai_strerror(error));
                exit(EXIT_FAILURE);
        }
        if (res->ai_family==AF_INET) {
                struct sockaddr_in *s4=(struct sockaddr_in *)res->ai_addr;
                struct in_addr *sa=&s4->sin_addr;
                if (res->ai_addrlen<sizeof(*s4)) {
-                       debuga(_("Short structure returned by getaddrinfo for an IPv4 address: %d bytes instead of %d\n"),res->ai_addrlen,(int)sizeof(*s4));
+                       debuga(__FILE__,__LINE__,_("Short structure returned by getaddrinfo for an IPv4 address: %d bytes instead of %d\n"),res->ai_addrlen,(int)sizeof(*s4));
                        exit(EXIT_FAILURE);
                }
                inet_ntop(res->ai_family,sa,name,name_size);
@@ -291,12 +291,12 @@ void name2ip(char *name,int name_size)
                struct sockaddr_in6 *s6=(struct sockaddr_in6 *)res->ai_addr;
                struct in6_addr *sa6=&s6->sin6_addr;
                if (res->ai_addrlen<sizeof(*s6)) {
-                       debuga(_("Short structure returned by getaddrinfo for an IPv6 address: %d bytes instead of %d\n"),res->ai_addrlen,(int)sizeof(*s6));
+                       debuga(__FILE__,__LINE__,_("Short structure returned by getaddrinfo for an IPv6 address: %d bytes instead of %d\n"),res->ai_addrlen,(int)sizeof(*s6));
                        exit(EXIT_FAILURE);
                }
                inet_ntop(res->ai_family,sa6,name,name_size);
        } else {
-               debuga(_("Invalid address type %d returned when resolving host name \"%s\"\n"),res->ai_family,name);
+               debuga(__FILE__,__LINE__,_("Invalid address type %d returned when resolving host name \"%s\"\n"),res->ai_family,name);
        }
        freeaddrinfo(res);
 #else
@@ -320,7 +320,7 @@ void name2ip(char *name,int name_size)
        getword_start(&gwarea,inet_ntoa(ia));
        if (getword(n4,sizeof(n4),&gwarea,'.')<0 || getword(n3,sizeof(n3),&gwarea,'.')<0 ||
            getword(n2,sizeof(n2),&gwarea,'.')<0 || getword(n1,sizeof(n1),&gwarea,0)<0) {
-               printf("SARG: Maybe you have a broken record or garbage in your %s ip address.\n",gwarea.beginning);
+               debuga(__FILE__,__LINE__,_("Invalid IPv4 address \"%s\"\n"),gwarea.beginning);
                exit(EXIT_FAILURE);
        }
        snprintf(name,name_size,"%s.%s.%s.%s",n1,n2,n3,n4);