Also recognize bind setting in global network configuration.
authorJelmer Vernooij <jelmer@samba.org>
Thu, 3 Apr 2008 16:53:50 +0000 (18:53 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Thu, 3 Apr 2008 16:53:50 +0000 (18:53 +0200)
NEWS
lib/network.c
src/admin.c
src/network.c
src/settings.c
src/settings.h

diff --git a/NEWS b/NEWS
index 1a89963bd849838282768789fe752e1b0afb9c41..d11433b164f7aacb911053b6d8b2e673fbed4a0f 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,4 @@
- Otherwise indicated differently, all changes made by 
-     Jelmer Vernooij.
+Unless otherwise indicated, all changes made by Jelmer Vernooij.
 
 Ctrlproxy 3.0.6 UNRELEASED
 
@@ -30,6 +29,9 @@ Ctrlproxy 3.0.6 UNRELEASED
        * The pid file is now read to check whether another instance of 
          ctrlproxy is already running.
 
+       * ``bind'' is now also accepted in the global section of the network 
+         configuration. (#194)
+
   BUG FIXES
 
     * Improve handling of empty pid files. (#186)
index f059ac4cc7e961347a70624d85d776012c2a0b79..60ca93f952ffb9a49208ac082e9a733480d39dc6 100644 (file)
@@ -199,13 +199,13 @@ static struct tcp_server_config *network_get_next_tcp_server(struct irc_network
        
        g_assert(n);
        g_assert(n->config);
-       cur = g_list_find(n->config->type_settings.tcp_servers, n->connection.data.tcp.current_server);
+       cur = g_list_find(n->config->type_settings.tcp.servers, n->connection.data.tcp.current_server);
 
        /* Get next available server */
        if (cur != NULL && cur->next != NULL) 
                cur = cur->next; 
        else 
-               cur = n->config->type_settings.tcp_servers;
+               cur = n->config->type_settings.tcp.servers;
 
        if (cur != NULL) 
                return cur->data; 
@@ -587,6 +587,8 @@ static gboolean connect_current_tcp_server(struct irc_network *s)
 
                if (cs->bind_address)
                        bindsock(s, sock, res, cs->bind_address, NULL);
+               else if (s->config->type_settings.tcp.default_bind_address)
+                       bindsock(s, sock, res, s->config->type_settings.tcp.default_bind_address, NULL);
 
                ioc = g_io_channel_unix_new(sock);
                g_io_channel_set_flags(ioc, G_IO_FLAG_NONBLOCK, NULL);
index b31d03e3d99bddf357da5a5f8a1a4909e569d989..f748c4dd3e99e19380f0c185fd2d0c4caab83f35 100644 (file)
@@ -222,7 +222,7 @@ static void cmd_add_server (admin_handle h, char **args, void *userdata)
        s->ssl = FALSE;
        s->password = args[3]?g_strdup(args[3]):NULL;
 
-       n->config->type_settings.tcp_servers = g_list_append(n->config->type_settings.tcp_servers, s);
+       n->config->type_settings.tcp.servers = g_list_append(n->config->type_settings.tcp.servers, s);
 
        admin_out(h, "Server added to `%s'", args[1]);
 }
index 8e175b19d1bd37b4e85214667a9bea8303a68d99..2faa8921fdac165d656205292f8566f02004977d 100644 (file)
@@ -222,7 +222,7 @@ struct irc_network *find_network_by_hostname(struct global *global,
                g_assert(n->config);
                if (n->config->type == NETWORK_TCP) 
                {
-                       for (sv = n->config->type_settings.tcp_servers; sv; sv = sv->next)
+                       for (sv = n->config->type_settings.tcp.servers; sv; sv = sv->next)
                        {
                                struct tcp_server_config *server = sv->data;
                                struct servent *sv_serv = getservbyname(server->port, "tcp");
@@ -256,7 +256,7 @@ struct irc_network *find_network_by_hostname(struct global *global,
                s->host = g_strdup(hostname);
                s->port = portname;
 
-               nc->type_settings.tcp_servers = g_list_append(nc->type_settings.tcp_servers, s);
+               nc->type_settings.tcp.servers = g_list_append(nc->type_settings.tcp.servers, s);
 
                n = load_network(global, nc);
                network_set_log_fn(n, (network_log_fn)handle_network_log, n);
index fca76043b11c99b94dcccdd33a3267dfe1d8adbe..1a2d7b0872ff94ab86396171d908555067a7d5cc 100644 (file)
@@ -143,9 +143,9 @@ static void config_save_tcp_servers(struct network_config *n, GKeyFile *kf)
 {
        GList *gl;
        int i = 0; 
-       gchar **values = g_new0(gchar *, g_list_length(n->type_settings.tcp_servers)+1);
+       gchar **values = g_new0(gchar *, g_list_length(n->type_settings.tcp.servers)+1);
        
-       for (gl = n->type_settings.tcp_servers; gl; gl = gl->next) {
+       for (gl = n->type_settings.tcp.servers; gl; gl = gl->next) {
                struct tcp_server_config *ts = gl->data;
                char *name = irc_create_url(ts->host, ts->port, ts->ssl);
 
@@ -200,6 +200,11 @@ static void config_save_network(const char *dir, struct network_config *n, GList
                break;
        case NETWORK_TCP:
                config_save_tcp_servers(n, kf);
+               if (n->type_settings.tcp.default_bind_address != NULL)
+                       g_key_file_set_string(kf, "global", "bind", 
+                                                                 n->type_settings.tcp.default_bind_address);
+               else
+                       g_key_file_remove_key(kf, "global", "bind", NULL);
                break;
        default:break;
        }
@@ -485,7 +490,7 @@ static void config_load_servers(struct network_config *n)
 
                s->bind_address = g_key_file_get_string(n->keyfile, servers[i], "bind", NULL);
 
-               n->type_settings.tcp_servers = g_list_append(n->type_settings.tcp_servers, s);
+               n->type_settings.tcp.servers = g_list_append(n->type_settings.tcp.servers, s);
 
                g_key_file_remove_group(n->keyfile, servers[i], NULL);
        }
@@ -589,6 +594,7 @@ static struct network_config *config_load_network(struct ctrlproxy_config *cfg,
 
        switch (n->type) {
        case NETWORK_TCP:
+               n->type_settings.tcp.default_bind_address = g_key_file_get_string(kf, "global", "bind", NULL);
                config_load_servers(n);
                break;
        case NETWORK_PROGRAM:
@@ -652,7 +658,7 @@ static struct network_config *find_create_network_config(struct ctrlproxy_config
                if (nc->type != NETWORK_TCP) 
                        continue;
 
-               for (gl1 = nc->type_settings.tcp_servers; gl1; gl1 = gl1->next) {
+               for (gl1 = nc->type_settings.tcp.servers; gl1; gl1 = gl1->next) {
                        char *tmp;
                        struct tcp_server_config *sc = gl1->data;
 
@@ -678,7 +684,7 @@ static struct network_config *find_create_network_config(struct ctrlproxy_config
        nc->type = NETWORK_TCP;
        tc = g_new0(struct tcp_server_config, 1);
        irc_parse_url(name, &tc->host, &tc->port, &tc->ssl);
-       nc->type_settings.tcp_servers = g_list_append(nc->type_settings.tcp_servers, tc);
+       nc->type_settings.tcp.servers = g_list_append(nc->type_settings.tcp.servers, tc);
 
        cfg->networks = g_list_append(cfg->networks, nc);
 
@@ -1300,15 +1306,16 @@ void free_config(struct ctrlproxy_config *cfg)
                }
                switch (nc->type) {
                case NETWORK_TCP: 
-                       while (nc->type_settings.tcp_servers) {
-                               struct tcp_server_config *tc = nc->type_settings.tcp_servers->data;
+                       while (nc->type_settings.tcp.servers) {
+                               struct tcp_server_config *tc = nc->type_settings.tcp.servers->data;
                                g_free(tc->host);
                                g_free(tc->port);
                                g_free(tc->bind_address);
                                g_free(tc->password);
-                               nc->type_settings.tcp_servers = g_list_remove(nc->type_settings.tcp_servers, tc);
+                               nc->type_settings.tcp.servers = g_list_remove(nc->type_settings.tcp.servers, tc);
                                g_free(tc);
                        }
+                       g_free(nc->type_settings.tcp.default_bind_address);
                        break;
                case NETWORK_VIRTUAL:
                        g_free(nc->type_settings.virtual_type);
index 3e1cba0e4fea76ee97dff6333bd865992385a2a4..393a115f65cecdb292a2776804b8f5cf4457a80e 100644 (file)
@@ -100,7 +100,10 @@ struct network_config
        union {
                char *virtual_type;
                char *program_location;
-               GList *tcp_servers;
+               struct { 
+                       char *default_bind_address;
+                       GList *servers;
+               } tcp;
        } type_settings; 
 };