From: Daniel Wagner <daniel.wag...@bmw-carit.de>

Remove resolver module support.
---
 include/resolver.h |   17 ---
 src/connman.h      |    8 +-
 src/dnsproxy.c     |   29 +---
 src/main.c         |    6 +-
 src/resolver.c     |  400 +++++++++++++++++++++-------------------------------
 5 files changed, 172 insertions(+), 288 deletions(-)

diff --git a/include/resolver.h b/include/resolver.h
index 0d11cad..c7c6b53 100644
--- a/include/resolver.h
+++ b/include/resolver.h
@@ -45,23 +45,6 @@ int connman_resolver_remove_public_server(const char 
*server);
 
 void connman_resolver_flush(void);
 
-#define CONNMAN_RESOLVER_PRIORITY_LOW      -100
-#define CONNMAN_RESOLVER_PRIORITY_DEFAULT     0
-#define CONNMAN_RESOLVER_PRIORITY_HIGH      100
-
-struct connman_resolver {
-       const char *name;
-       int priority;
-       int (*append) (const char *interface, const char *domain,
-                                                       const char *server);
-       int (*remove) (const char *interface, const char *domain,
-                                                       const char *server);
-       void (*flush) (void);
-};
-
-int connman_resolver_register(struct connman_resolver *resolver);
-void connman_resolver_unregister(struct connman_resolver *resolver);
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/connman.h b/src/connman.h
index a278006..7aaaac4 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -123,8 +123,10 @@ void __connman_rfkill_cleanup(void);
 
 #include <connman/resolver.h>
 
-int __connman_resolver_init(void);
+int __connman_resolver_init(connman_bool_t dnsproxy);
 void __connman_resolver_cleanup(void);
+int __connman_resolvfile_append(const char *interface, const char *domain, 
const char *server);
+int __connman_resolvfile_remove(const char *interface, const char *domain, 
const char *server);
 
 #include <connman/storage.h>
 
@@ -611,4 +613,6 @@ int __connman_iptables_commit(const char *table_name);
 
 int __connman_dnsproxy_init(void);
 void __connman_dnsproxy_cleanup(void);
-
+int __connman_dnsproxy_append(const char *interface, const char *domain, const 
char *server);
+int __connman_dnsproxy_remove(const char *interface, const char *domain, const 
char *server);
+void __connman_dnsproxy_flush(void);
diff --git a/src/dnsproxy.c b/src/dnsproxy.c
index cbd07c3..aabf3df 100644
--- a/src/dnsproxy.c
+++ b/src/dnsproxy.c
@@ -859,7 +859,7 @@ static void append_domain(const char *interface, const char 
*domain)
        }
 }
 
-static int dnsproxy_append(const char *interface, const char *domain,
+int __connman_dnsproxy_append(const char *interface, const char *domain,
                                                        const char *server)
 {
        struct server_data *data;
@@ -903,7 +903,7 @@ static void remove_server(const char *interface, const char 
*domain,
        destroy_server(data);
 }
 
-static int dnsproxy_remove(const char *interface, const char *domain,
+int __connman_dnsproxy_remove(const char *interface, const char *domain,
                                                        const char *server)
 {
        DBG("interface %s server %s", interface, server);
@@ -920,7 +920,7 @@ static int dnsproxy_remove(const char *interface, const 
char *domain,
        return 0;
 }
 
-static void dnsproxy_flush(void)
+void __connman_dnsproxy_flush(void)
 {
        GSList *list;
 
@@ -938,14 +938,6 @@ static void dnsproxy_flush(void)
        }
 }
 
-static struct connman_resolver dnsproxy_resolver = {
-       .name           = "dnsproxy",
-       .priority       = CONNMAN_RESOLVER_PRIORITY_HIGH,
-       .append         = dnsproxy_append,
-       .remove         = dnsproxy_remove,
-       .flush          = dnsproxy_flush,
-};
-
 static void dnsproxy_offline_mode(connman_bool_t enabled)
 {
        GSList *list;
@@ -1400,7 +1392,7 @@ static int create_listener(void)
                return err;
        }
 
-       connman_resolver_append("lo", NULL, "127.0.0.1");
+       __connman_resolvfile_append("lo", NULL, "127.0.0.1");
 
        return 0;
 }
@@ -1409,7 +1401,7 @@ static void destroy_listener(void)
 {
        GSList *list;
 
-       connman_resolver_remove_all("lo");
+       __connman_resolvfile_remove("lo", NULL, "127.0.0.1");
 
        for (list = request_pending_list; list; list = list->next) {
                struct request_data *req = list->data;
@@ -1455,19 +1447,12 @@ int __connman_dnsproxy_init(void)
        if (err < 0)
                return err;
 
-       err = connman_resolver_register(&dnsproxy_resolver);
-       if (err < 0)
-               goto destroy;
-
        err = connman_notifier_register(&dnsproxy_notifier);
        if (err < 0)
-               goto unregister;
+               goto destroy;
 
        return 0;
 
-unregister:
-       connman_resolver_unregister(&dnsproxy_resolver);
-
 destroy:
        destroy_listener();
 
@@ -1478,7 +1463,5 @@ void __connman_dnsproxy_cleanup(void)
 {
        connman_notifier_unregister(&dnsproxy_notifier);
 
-       connman_resolver_unregister(&dnsproxy_resolver);
-
        destroy_listener();
 }
diff --git a/src/main.c b/src/main.c
index b167b5c..2b179d1 100644
--- a/src/main.c
+++ b/src/main.c
@@ -227,9 +227,7 @@ int main(int argc, char *argv[])
        __connman_config_init();
        __connman_stats_init();
 
-       if (option_dnsproxy == TRUE)
-               __connman_dnsproxy_init();
-       __connman_resolver_init();
+       __connman_resolver_init(option_dnsproxy);
        __connman_ipconfig_init();
        __connman_rtnl_init();
        __connman_task_init();
@@ -266,8 +264,6 @@ int main(int argc, char *argv[])
        __connman_rtnl_cleanup();
        __connman_ipconfig_cleanup();
        __connman_resolver_cleanup();
-       if (option_dnsproxy == TRUE)
-               __connman_dnsproxy_cleanup();
 
        __connman_stats_cleanup();
        __connman_config_cleanup();
diff --git a/src/resolver.c b/src/resolver.c
index 6ee4d48..0c0bc3c 100644
--- a/src/resolver.c
+++ b/src/resolver.c
@@ -36,7 +36,6 @@
 #define RESOLVER_FLAG_PUBLIC (1 << 0)
 
 struct entry_data {
-       struct connman_resolver *resolver;
        char *interface;
        char *domain;
        char *server;
@@ -45,99 +44,187 @@ struct entry_data {
 };
 
 static GSList *entry_list = NULL;
-static GSList *resolver_list = NULL;
+static connman_bool_t dnsproxy_enabled = FALSE;
 
-static void remove_entries(GSList *entries)
+struct resolvfile_entry {
+       char *interface;
+       char *domain;
+       char *server;
+};
+
+static GList *resolvfile_list = NULL;
+
+static void resolvfile_remove_entries(GList *entries)
 {
-       GSList *list;
+       GList *list;
 
        for (list = entries; list; list = list->next) {
-               struct entry_data *entry = list->data;
-               struct connman_resolver *resolver = entry->resolver;
-
-               entry_list = g_slist_remove(entry_list, entry);
+               struct resolvfile_entry *entry = list->data;
 
-               if (resolver && resolver->remove)
-                       resolver->remove(entry->interface, entry->domain,
-                                                               entry->server);
+               resolvfile_list = g_list_remove(resolvfile_list, entry);
 
-               if (entry->timeout)
-                       g_source_remove(entry->timeout);
                g_free(entry->server);
                g_free(entry->domain);
                g_free(entry->interface);
                g_free(entry);
        }
 
-       g_slist_free(entries);
+       g_list_free(entries);
 }
 
-static gint compare_priority(gconstpointer a, gconstpointer b)
+static int resolvfile_export(void)
 {
-       const struct connman_resolver *resolver1 = a;
-       const struct connman_resolver *resolver2 = b;
+       GList *list;
+       GString *content;
+       int fd, err;
+       unsigned int count;
+       mode_t old_umask;
 
-       return resolver2->priority - resolver1->priority;
-}
+       content = g_string_new("# Generated by Connection Manager\n");
 
-/**
- * connman_resolver_register:
- * @resolver: resolver module
- *
- * Register a new resolver module
- *
- * Returns: %0 on success
- */
-int connman_resolver_register(struct connman_resolver *resolver)
-{
-       GSList *list;
+       /*
+        * Domains and nameservers are added in reverse so that the most
+        * recently appended entry is the primary one. No more than
+        * MAXDNSRCH/MAXNS entries are used.
+        */
 
-       DBG("resolver %p name %s", resolver, resolver->name);
+       for (count = 0, list = g_list_last(resolvfile_list);
+                                               list && (count < MAXDNSRCH);
+                                               list = g_list_previous(list)) {
+               struct resolvfile_entry *entry = list->data;
 
-       resolver_list = g_slist_insert_sorted(resolver_list, resolver,
-                                                       compare_priority);
+               if (!entry->domain)
+                       continue;
 
-       if (resolver->append == NULL)
-               return 0;
+               if (count == 0)
+                       g_string_append_printf(content, "search ");
 
-       for (list = entry_list; list; list = list->next) {
-               struct entry_data *entry = list->data;
+               g_string_append_printf(content, "%s ", entry->domain);
+               count++;
+       }
+
+       if (count)
+               g_string_append_printf(content, "\n");
 
-               if (entry->resolver)
+       for (count = 0, list = g_list_last(resolvfile_list);
+                                               list && (count < MAXNS);
+                                               list = g_list_previous(list)) {
+               struct resolvfile_entry *entry = list->data;
+
+               if (!entry->server)
                        continue;
 
-               if (resolver->append(entry->interface, entry->domain,
-                                                       entry->server) == 0)
-                       entry->resolver = resolver;
+               g_string_append_printf(content, "nameserver %s\n",
+                                                               entry->server);
+               count++;
        }
 
-       return 0;
+       old_umask = umask(022);
+
+       fd = open("/etc/resolv.conf", O_RDWR | O_CREAT,
+                                       S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+       if (fd < 0) {
+               err = -errno;
+               goto done;
+       }
+
+       if (ftruncate(fd, 0) < 0) {
+               err = -errno;
+               goto failed;
+       }
+
+       err = 0;
+
+       if (write(fd, content->str, content->len) < 0)
+               err = -errno;
+
+failed:
+       close(fd);
+
+done:
+       g_string_free(content, TRUE);
+       umask(old_umask);
+
+       return err;
 }
 
-/**
- * connman_resolver_unregister:
- * @resolver: resolver module
- *
- * Remove a previously registered resolver module
- */
-void connman_resolver_unregister(struct connman_resolver *resolver)
+int __connman_resolvfile_append(const char *interface, const char *domain,
+                                                       const char *server)
 {
-       GSList *list, *matches = NULL;
+       struct resolvfile_entry *entry;
 
-       DBG("resolver %p name %s", resolver, resolver->name);
+       DBG("interface %s server %s", interface, server);
 
-       resolver_list = g_slist_remove(resolver_list, resolver);
+       if (interface == NULL)
+               return -ENOENT;
 
-       for (list = entry_list; list; list = list->next) {
-               struct entry_data *entry = list->data;
+       entry = g_try_new0(struct resolvfile_entry, 1);
+       if (entry == NULL)
+               return -ENOMEM;
+
+       entry->interface = g_strdup(interface);
+       entry->domain = g_strdup(domain);
+       entry->server = g_strdup(server);
+
+       resolvfile_list = g_list_append(resolvfile_list, entry);
+
+       return resolvfile_export();
+}
+
+int __connman_resolvfile_remove(const char *interface, const char *domain,
+                                                       const char *server)
+{
+       GList *list, *matches = NULL;
+
+       DBG("interface %s server %s", interface, server);
+
+       for (list = resolvfile_list; list; list = g_list_next(list)) {
+               struct resolvfile_entry *entry = list->data;
 
-               if (entry->resolver != resolver)
+               if (interface != NULL &&
+                               g_strcmp0(entry->interface, interface) != 0)
                        continue;
 
-               matches = g_slist_append(matches, entry);
+               if (domain != NULL && g_strcmp0(entry->domain, domain) != 0)
+                       continue;
+
+               if (g_strcmp0(entry->server, server) != 0)
+                       continue;
+
+               matches = g_list_append(matches, entry);
        }
 
-       remove_entries(matches);
+       resolvfile_remove_entries(matches);
+
+       return resolvfile_export();
+}
+
+static void remove_entries(GSList *entries)
+{
+       GSList *list;
+
+       for (list = entries; list; list = list->next) {
+               struct entry_data *entry = list->data;
+
+               entry_list = g_slist_remove(entry_list, entry);
+
+               if (dnsproxy_enabled == TRUE) {
+                       __connman_dnsproxy_remove(entry->interface, 
entry->domain,
+                                                       entry->server);
+               } else {
+                       __connman_resolvfile_remove(entry->interface, 
entry->domain,
+                                                       entry->server);
+               }
+
+               if (entry->timeout)
+                       g_source_remove(entry->timeout);
+               g_free(entry->server);
+               g_free(entry->domain);
+               g_free(entry->interface);
+               g_free(entry);
+       }
+
+       g_slist_free(entries);
 }
 
 static gboolean resolver_expire_cb(gpointer user_data)
@@ -159,7 +246,6 @@ static int append_resolver(const char *interface, const 
char *domain,
                           unsigned int flags)
 {
        struct entry_data *entry;
-       GSList *list;
 
        DBG("interface %s domain %s server %s lifetime %d flags %d",
            interface, domain, server, lifetime, flags);
@@ -182,17 +268,10 @@ static int append_resolver(const char *interface, const 
char *domain,
 
        entry_list = g_slist_append(entry_list, entry);
 
-       for (list = resolver_list; list; list = list->next) {
-               struct connman_resolver *resolver = list->data;
-
-               if (resolver->append == NULL)
-                       continue;
-
-               if (resolver->append(interface, domain, server) == 0) {
-                       entry->resolver = resolver;
-                       break;
-               }
-       }
+       if (dnsproxy_enabled == TRUE)
+               __connman_dnsproxy_append(interface, domain, server);
+       else
+               __connman_resolvfile_append(interface, domain, server);
 
        return 0;
 }
@@ -206,7 +285,7 @@ static int append_resolver(const char *interface, const 
char *domain,
  * Append resolver server address to current list
  */
 int connman_resolver_append(const char *interface, const char *domain,
-                                                       const char *server)
+                                               const char *server)
 {
        DBG("interface %s domain %s server %s", interface, domain, server);
 
@@ -358,190 +437,29 @@ int connman_resolver_remove_public_server(const char 
*server)
  */
 void connman_resolver_flush(void)
 {
-       GSList *list;
-
-       for (list = resolver_list; list; list = list->next) {
-               struct connman_resolver *resolver = list->data;
-
-               if (resolver->flush == NULL)
-                       continue;
-
-               resolver->flush();
-       }
+       if (dnsproxy_enabled == TRUE)
+               __connman_dnsproxy_flush();
 
        return;
 }
 
-struct resolvfile_entry {
-       char *interface;
-       char *domain;
-       char *server;
-};
-
-static GList *resolvfile_list = NULL;
-
-static void resolvfile_remove_entries(GList *entries)
+int __connman_resolver_init(connman_bool_t dnsproxy)
 {
-       GList *list;
-
-       for (list = entries; list; list = list->next) {
-               struct resolvfile_entry *entry = list->data;
-
-               resolvfile_list = g_list_remove(resolvfile_list, entry);
-
-               g_free(entry->server);
-               g_free(entry->domain);
-               g_free(entry->interface);
-               g_free(entry);
-       }
-
-       g_list_free(entries);
-}
-
-static int resolvfile_export(void)
-{
-       GList *list;
-       GString *content;
-       int fd, err;
-       unsigned int count;
-       mode_t old_umask;
+       int err = 0;
 
-       content = g_string_new("# Generated by Connection Manager\n");
+       DBG("dnsproxy %d", dnsproxy);
 
-       /*
-        * Domains and nameservers are added in reverse so that the most
-        * recently appended entry is the primary one. No more than
-        * MAXDNSRCH/MAXNS entries are used.
-        */
-
-       for (count = 0, list = g_list_last(resolvfile_list);
-                                               list && (count < MAXDNSRCH);
-                                               list = g_list_previous(list)) {
-               struct resolvfile_entry *entry = list->data;
-
-               if (!entry->domain)
-                       continue;
-
-               if (count == 0)
-                       g_string_append_printf(content, "search ");
-
-               g_string_append_printf(content, "%s ", entry->domain);
-               count++;
-       }
-
-       if (count)
-               g_string_append_printf(content, "\n");
-
-       for (count = 0, list = g_list_last(resolvfile_list);
-                                               list && (count < MAXNS);
-                                               list = g_list_previous(list)) {
-               struct resolvfile_entry *entry = list->data;
-
-               if (!entry->server)
-                       continue;
-
-               g_string_append_printf(content, "nameserver %s\n",
-                                                               entry->server);
-               count++;
-       }
-
-       old_umask = umask(022);
-
-       fd = open("/etc/resolv.conf", O_RDWR | O_CREAT,
-                                       S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
-       if (fd < 0) {
-               err = -errno;
-               goto done;
-       }
-
-       if (ftruncate(fd, 0) < 0) {
-               err = -errno;
-               goto failed;
-       }
-
-       err = 0;
-
-       if (write(fd, content->str, content->len) < 0)
-               err = -errno;
-
-failed:
-       close(fd);
-
-done:
-       g_string_free(content, TRUE);
-       umask(old_umask);
+       dnsproxy_enabled = dnsproxy;
+       if (dnsproxy_enabled == TRUE)
+               err = __connman_dnsproxy_init();
 
        return err;
 }
 
-static int resolvfile_append(const char *interface, const char *domain,
-                                                       const char *server)
-{
-       struct resolvfile_entry *entry;
-
-       DBG("interface %s server %s", interface, server);
-
-       if (interface == NULL)
-               return -ENOENT;
-
-       entry = g_try_new0(struct resolvfile_entry, 1);
-       if (entry == NULL)
-               return -ENOMEM;
-
-       entry->interface = g_strdup(interface);
-       entry->domain = g_strdup(domain);
-       entry->server = g_strdup(server);
-
-       resolvfile_list = g_list_append(resolvfile_list, entry);
-
-       return resolvfile_export();
-}
-
-static int resolvfile_remove(const char *interface, const char *domain,
-                                                       const char *server)
-{
-       GList *list, *matches = NULL;
-
-       DBG("interface %s server %s", interface, server);
-
-       for (list = resolvfile_list; list; list = g_list_next(list)) {
-               struct resolvfile_entry *entry = list->data;
-
-               if (interface != NULL &&
-                               g_strcmp0(entry->interface, interface) != 0)
-                       continue;
-
-               if (domain != NULL && g_strcmp0(entry->domain, domain) != 0)
-                       continue;
-
-               if (g_strcmp0(entry->server, server) != 0)
-                       continue;
-
-               matches = g_list_append(matches, entry);
-       }
-
-       resolvfile_remove_entries(matches);
-
-       return resolvfile_export();
-}
-
-static struct connman_resolver resolvfile_resolver = {
-       .name           = "resolvfile",
-       .priority       = CONNMAN_RESOLVER_PRIORITY_LOW,
-       .append         = resolvfile_append,
-       .remove         = resolvfile_remove,
-};
-
-int __connman_resolver_init(void)
-{
-       DBG("");
-
-       return connman_resolver_register(&resolvfile_resolver);
-}
-
 void __connman_resolver_cleanup(void)
 {
        DBG("");
 
-       connman_resolver_unregister(&resolvfile_resolver);
+       if (dnsproxy_enabled == TRUE)
+               __connman_dnsproxy_cleanup();
 }
-- 
1.7.3.4

_______________________________________________
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman

Reply via email to