[pisa-src] r1373 - in trunk: include/util.h libpisa/util.c

  • From: Thomas Jansen <mithi@xxxxxxxxx>
  • To: pisa-src@xxxxxxxxxxxxx
  • Date: Wed, 28 Oct 2009 13:00:53 +0100

Author: tjansen
Date: Wed Oct 28 13:00:52 2009
New Revision: 1373

Log:
Removed unused functions pisa_for_each_hosts_file_line,
pisa_map_first_ip_to_hostname_from_hosts,
pisa_map_first_hostname_to_hit_from_hosts, and pisa_xfrm_ipv4_to_hit.

Modified:
   trunk/include/util.h
   trunk/libpisa/util.c

Modified: trunk/include/util.h
==============================================================================
--- trunk/include/util.h        Wed Oct 28 12:57:37 2009        (r1372)
+++ trunk/include/util.h        Wed Oct 28 13:00:52 2009        (r1373)
@@ -144,16 +144,6 @@
 
 int pisa_read_nameserver(struct in_addr *dnsaddr, const char *resolvconf);
 
-int pisa_for_each_hosts_file_line(char *hosts_file,
-                                int (*func)(const struct pisa_hosts_file_line 
*line,
-                                            const void *arg,
-                                            void *result),
-                                void *arg, void *result);
-int pisa_map_first_ip_to_hostname_from_hosts(const struct pisa_hosts_file_line 
*entry,
-                                       const void *arg, void *result);
-int pisa_map_first_hostname_to_hit_from_hosts(const struct 
pisa_hosts_file_line *entry,
-                                       const void *arg, void *result);
-int pisa_xfrm_ipv4_to_hit(struct in6_addr *mapped_hit, struct in_addr 
*ipv4addr);
 int pisa_check_and_create_dir(char *dirname, mode_t mode);
 
 int pisa_convert_string_to_address(const char *str, struct in6_addr *ip6);

Modified: trunk/libpisa/util.c
==============================================================================
--- trunk/libpisa/util.c        Wed Oct 28 12:57:37 2009        (r1372)
+++ trunk/libpisa/util.c        Wed Oct 28 13:00:52 2009        (r1373)
@@ -704,195 +704,6 @@
 
 }
 
-
-int pisa_for_each_hosts_file_line(char *hosts_file,
-                                int (*func)(const struct pisa_hosts_file_line 
*line,
-                                            const void *arg,
-                                            void *result),
-                                void *arg, void *result) {
-       FILE *hip_hosts = NULL;
-       Pisa_List mylist;
-       char line[500];
-       int err = 0, lineno = 0;
-       struct in_addr in_addr;
-       struct pisa_hosts_file_line entry;
-       char *hostname = NULL, *alias = NULL, *addr_ptr = NULL;
-
-       memset(line, 0, sizeof(line));
-
-       /* check whether  given hit_str is actually a HIT */
-
-       hip_hosts = fopen(hosts_file, "r");
-
-       if (!hip_hosts) {
-               PISA_ERROR("Cannot open the hosts_file %s.\n", hosts_file);
-               return -1;
-       }
-
-
-       /* For each line in the given hosts file, convert the line into binary 
format and
-        * call the given the handler  */
-
-       err = 1;
-       while (fgets(line, sizeof(line) - 1, hip_hosts) != NULL) {
-               char *eofline, *c, *comment;
-               int len;
-
-               lineno++;
-               c = line;
-
-               /* Remove whitespace */
-               while (*c == ' ' || *c == '\t')
-                       c++;
-
-               /* Line is a comment or empty */
-               if (*c =='#' || *c =='\n' || *c == '\0')
-                       continue;
-
-               eofline = strchr(c, '\n');
-               if (eofline)
-                       *eofline = '\0';
-
-               /* Terminate before (the first) trailing comment */
-               comment = strchr(c, '#');
-               if (comment)
-                       *comment = '\0';
-
-               /* shortest hostname: ":: a" = 4 */
-               if ((len = strnlen(c, sizeof(line))) < 4) {
-                       PISA_DEBUG("skip line\n");
-                       continue;
-               }
-
-               /* Split line into list */
-               initlist(&mylist);
-               extractsubstrings(c, &mylist);
-
-               len = length(&mylist);
-               if (len < 2 || len > 3) {
-                       PISA_ERROR("Bad number of items on line %d in %s, 
skipping\n",
-                               lineno, hosts_file);
-                       continue;
-               }
-
-               /* The list contains hosts line in reverse order. Let's sort 
it. */
-               if (len == 2) {
-                       hostname = getitem(&mylist, 0);
-                       addr_ptr = getitem(&mylist, 1);
-               } else if (len == 3) {
-                       alias = getitem(&mylist, 0);
-                       hostname = getitem(&mylist, 1);
-                       addr_ptr = getitem(&mylist, 2);
-               }
-
-               /* Initialize entry */
-
-               memset(&entry, 0, sizeof(entry));
-
-/*                PISA_ASSERT(addr_ptr);*/
-               err = inet_pton(AF_INET6, addr_ptr, &entry.id);
-               if (err <= 0) {
-                       err = inet_pton(AF_INET, addr_ptr, &in_addr);
-                       if (err <= 0) {
-                               PISA_ERROR("Bad address %s on line %d in %s, 
skipping\n",
-                                       addr_ptr, lineno, hosts_file);
-                               continue;
-                       }
-                       IPV4_TO_IPV6_MAP(&in_addr, &entry.id);
-               }
-
-               entry.hostname = hostname;
-/*                PISA_ASSERT(entry.hostname)*/
-
-               entry.alias = alias;
-               entry.lineno = lineno;
-
-               /* Finally, call the handler function to handle the line */
-
-               if (func(&entry, arg, result) == 0) {
-/*                        _PISA_DEBUG("Match on line %d in %s\n", lineno, 
hosts_file);*/
-                       err = 0;
-                       break;
-               }
-
-               memset(line, 0, sizeof(line));
-               destroy(&mylist);
-       }
-
-       if (hip_hosts)
-               fclose(hip_hosts);
-
-       return err;
-}
-
-int pisa_map_first_ip_to_hostname_from_hosts(const struct pisa_hosts_file_line 
*entry,
-                                       const void *arg, void *result)
-{
-       int err = 1;
-       struct in6_addr np;
-
-       IPV4_TO_IPV6_MAP((struct in_addr *)arg, &np);
-
-       if (pisa_ipv6_cmp(&np, &entry->id) == 0) {
-               PISA_DEBUG("Match on line %d\n", entry->lineno);
-               memcpy(result, entry->hostname, strnlen(entry->hostname, 
HOST_NAME_MAX));
-               err = 0;
-       }
-
-       return err;
-}
-
-int pisa_map_first_hostname_to_hit_from_hosts(const struct 
pisa_hosts_file_line *entry,
-                                       const void *arg, void *result)
-{
-       int err = 1;
-
-       if (strncmp(arg, entry->hostname, HOST_NAME_MAX) == 0 ||
-               (entry->alias && strncmp(arg, entry->alias, HOST_NAME_MAX) == 
0)) {
-/*                PISA_DEBUG("Match on line %d\n", entry->lineno);*/
-               pisa_ipv6_copy(result, &entry->id);
-               err = 0;
-       }
-
-       return err;
-}
-
-/**
- * Transform an IPv4 address to a HIT, reading /etc/hosts and /etc/hip/hosts.
- * This works with the reverse way of hip_map_id_to_ip_from_hosts_file()
- * in HIPL.
- *
- * @param mapped_hit  [out] HIT to be returned
- * @param ipv4addr    [in] IPv4 address to be transformed
- * @return 0 if normal, <0 otherwise
- */
-int pisa_xfrm_ipv4_to_hit(struct in6_addr *mapped_hit, struct in_addr 
*ipv4addr)
-{
-       int err = 0;
-       uint8_t hostname[HOST_NAME_MAX];
-
-       memset(hostname, 0, sizeof(hostname));
-
-       err = pisa_for_each_hosts_file_line(HOSTS_FILE,
-                       pisa_map_first_ip_to_hostname_from_hosts,
-                       ipv4addr, hostname);
-       if (err < 0) {
-               PISA_ERROR("Failed to map IP to hostname.\n");
-               return -1;
-       }
-
-       err = pisa_for_each_hosts_file_line(HIPD_HOSTS_FILE,
-                       pisa_map_first_hostname_to_hit_from_hosts,
-                       hostname, mapped_hit);
-
-       if (err < 0) {
-               PISA_ERROR("Failed to map hostname to HIT.\n");
-               return -1;
-       }
-
-       return 0;
-}
-
 /**
  * Daemonize the running process.
  */

Other related posts:

  • » [pisa-src] r1373 - in trunk: include/util.h libpisa/util.c - Thomas Jansen