Add create-implicit option.
authorJelmer Vernooij <jelmer@samba.org>
Sun, 27 Apr 2008 14:30:46 +0000 (15:30 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Sun, 27 Apr 2008 14:30:46 +0000 (15:30 +0100)
NEWS
config.example
lib/client.c
lib/transport.c
src/linestack_file.c
src/listener.c
src/settings.c
src/settings.h

diff --git a/NEWS b/NEWS
index 21e3f08fefd01442b6a3fdb97e54647a515d9d08..c7199f9d6943c831445c8d983aef95af59ddb8a9 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,10 @@ Unless otherwise indicated, all changes made by Jelmer Vernooij.
 
 Ctrlproxy 3.0.7 UNRELEASED
 
+  FEATURES
+
+    * Add 'create-implicit' option.
+
   BUG FIXES
 
     * Handle client-specific admin commands being run without a client 
index 7a0f26fd2325391f0b21ac8df2e7aba7bb56dee7..1feb916c12058f5c66b31ccdb8588baa74199eba 100644 (file)
@@ -34,6 +34,11 @@ password=secret
 # Override motd-file location
 #motd-file = /tmp/my-motd
 
+# Whether or not to automatically connect to a network if a client requests
+# a connection. If disabled, it is only possible to connect to networks 
+# listed in the configuration
+# create-implicit = true
+
 # Save state to configuration file on exit
 autosave = true
 
index f5b918bc3b64916d3a084e24be369ffdfbfaf211..6d9c4d1f44ed55d1c70b108bec69a40143d3059c 100644 (file)
@@ -348,7 +348,7 @@ static gboolean process_from_pending_client(struct irc_client *client,
                }
 
                client->network = network_ref(find_network_by_hostname(my_global, 
-                               l->args[1], l->args[2]?atoi(l->args[2]):6667, TRUE));
+                               l->args[1], l->args[2]?atoi(l->args[2]):6667, my_global->config->create_implicit));
 
                if (client->network == NULL) {
                        client_log(LOG_ERROR, client, 
index f08465c2d8d217dbcaffecbdbb40444327fe94a4..643e134efd56d1a0236225c2aefefed4e5f291ec 100644 (file)
@@ -250,6 +250,8 @@ static gboolean transport_send_queue(GIOChannel *ioc, GIOCondition cond,
                case G_IO_STATUS_ERROR:
                        transport->callbacks->log(transport, l, error);
                        break;
+               case G_IO_STATUS_EOF:
+                       g_assert_not_reached();
                }
                free_line(l);
        }
@@ -304,6 +306,8 @@ gboolean transport_send_line(struct irc_transport *transport,
        case G_IO_STATUS_ERROR:
                transport->callbacks->log(transport, l, error);
                return FALSE;
+       case G_IO_STATUS_EOF:
+               g_assert_not_reached();
        }
 
        return TRUE;
index 74ca9dd45e71ef769f2a992940f9f0a41fe6dc3f..11fdfb8c9a0cdaeb44eef5aa02bfd5d1c5fb8704 100644 (file)
@@ -229,7 +229,7 @@ static gboolean marshall_int(struct irc_network_state *nst, const char *name, in
 static gboolean marshall_time(struct irc_network_state *nst, const char *name, int level, enum marshall_mode m, GIOChannel *t, time_t *n)
 {
        if (m == MARSHALL_PUSH) {
-               char tmp[20];
+               char tmp[30];
                GError *error = NULL;
                GIOStatus status;
                g_snprintf(tmp, sizeof(tmp), "%lu", *n);
index 33a18807138b02cf6051bf685025a2768a8940f9..c1051d90bef4ba244ff53cef92d8474b0d124306 100644 (file)
@@ -75,7 +75,8 @@ gboolean default_socks_connect_fqdn (struct pending_client *cl, const char *host
        
        listener_log(LOG_INFO, cl->listener, "Request to connect to %s:%d", hostname, port);
 
-       result = find_network_by_hostname(cl->listener->global, hostname, port, TRUE);
+       result = find_network_by_hostname(cl->listener->global, hostname, port, 
+                                                                         cl->listener->global->config->create_implicit);
 
        if (result == NULL) {
                listener_log(LOG_WARNING, cl->listener, "Unable to return network matching %s:%d", hostname, port);
@@ -179,7 +180,7 @@ static gboolean handle_client_line(struct pending_client *pc, const struct irc_l
 
                        if (networkname != NULL) {
                                n = find_network_by_hostname(pc->listener->global, 
-                                                                                        networkname, 6667, TRUE);
+                                                                                        networkname, 6667, pc->listener->global->config->create_implicit);
                                if (n == NULL) {
                                        irc_sendf(pc->connection, pc->listener->iconv, NULL, ":%s %d %s :Password error: unable to find network", 
                                                          get_my_hostname(), ERR_PASSWDMISMATCH, "*");
index 0f104a90f0fd844ac0e78a5e80774617133e6fa1..596a65b9a698097040e7cdd069482b7f2531e37b 100644 (file)
@@ -56,6 +56,7 @@ static const char *builtin_known_keys[] = {
        "auto-away-nick",
        "auto-away-client-limit",
        "auto-away-time",
+       "create-implicit",
        "max_who_age",
        "replication",
        "linestack",
@@ -403,6 +404,9 @@ void save_configuration(struct ctrlproxy_config *cfg, const char *configuration_
                !cfg->learn_network_name)
                g_key_file_set_boolean(cfg->keyfile, "global", "learn-network-name", cfg->learn_network_name);
 
+       if (g_key_file_has_key(cfg->keyfile, "global", "create-implicit", NULL) || !cfg->create_implicit)
+               g_key_file_set_boolean(cfg->keyfile, "global", "create-implicit", cfg->create_implicit);
+
        if (cfg->client_charset != NULL)
                g_key_file_set_string(cfg->keyfile, "global", "default-client-charset", cfg->client_charset);
        
@@ -1207,6 +1211,11 @@ struct ctrlproxy_config *load_configuration(const char *dir)
     else 
            cfg->learn_network_name = TRUE;
 
+       if (g_key_file_has_key(kf, "global", "create-implicit", NULL))
+               cfg->create_implicit = g_key_file_get_boolean(kf, "global", "create-implicit", NULL);
+       else
+               cfg->create_implicit = TRUE;
+
        if (!g_file_test(cfg->motd_file, G_FILE_TEST_EXISTS))
                log_global(LOG_ERROR, "Can't open MOTD file '%s' for reading", cfg->motd_file);
 
index 2152fd44c9d5a2398cd472884b1c279ad7cbed31..51c5f34c30d11c5433ec3237c069801b9c46939d 100644 (file)
@@ -177,6 +177,9 @@ struct ctrlproxy_config {
        char *network_socket;
        char *admin_socket;
 
+       /** Whether to create networks that don't exist yet. */
+       gboolean create_implicit;
+
        /** Name of replication backend, or NULL for default. */
        char *replication;