Implement USERHOST and ISON. (#99)
authorJelmer Vernooij <jelmer@samba.org>
Sun, 18 Mar 2007 16:36:17 +0000 (17:36 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Sun, 18 Mar 2007 16:36:17 +0000 (17:36 +0100)
NEWS
src/admin.c

diff --git a/NEWS b/NEWS
index 462707cf7e6f785b97fb477c05e291070b6312d4..0eeef65ab48b42173100d37ed72d47ec923bde8e 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -52,6 +52,8 @@ Ctrlproxy 3.0.2 UNRELEASED
     * Remove is_private from line struct (#12).
                (patch by Emanuele Giaquinta <e.giaquinta@glauco.it>)
 
+       * Implement ISON, USERHOST for admin networks. (#99)
+
   PORTABILITY
 
     * Looks for check using pkg-config now.
index c0621f9de78c4ef7c26d858c5057e6235c11b819..b6332878c9925a2a80882d4fcdf2c5ef229c190c 100644 (file)
@@ -525,33 +525,80 @@ static gboolean admin_net_init(struct network *n)
 
 static gboolean admin_to_server (struct network *n, struct client *c, const struct line *l)
 {
-       struct admin_handle ah;
+       if (!g_strcasecmp(l->args[0], "PRIVMSG") && 
+               !g_strcasecmp(l->args[0], "NOTICE")) {
+               struct admin_handle ah;
 
-       if (g_strcasecmp(l->args[0], "PRIVMSG") && 
-               g_strcasecmp(l->args[0], "NOTICE")) {
-               log_global(LOG_TRACE, "Unhandled command `%s' to admin network", 
-                                  l->args[0]);
-               return TRUE;
-       }
+               if (g_strcasecmp(l->args[0], n->state->me.nick) == 0) {
+                       virtual_network_recv_args(c->network, n->state->me.hostmask, l->args[0], l->args[1], NULL);
+                       return TRUE;
+               }
 
-       if (g_strcasecmp(l->args[0], n->state->me.nick) == 0) {
-               virtual_network_recv_args(c->network, n->state->me.hostmask, l->args[0], l->args[1], NULL);
-               return TRUE;
-       }
+               if (g_strcasecmp(l->args[1], ADMIN_CHANNEL) && 
+                       g_strcasecmp(l->args[1], "ctrlproxy")) {
+                       virtual_network_recv_response(c->network, ERR_NOSUCHNICK, l->args[1], "No such nick/channel", NULL);
+                       return TRUE;
+               }
+
+               ah.send_fn = network_admin_out;
+               ah.user_data = NULL;
+               ah.client = c;
+               ah.network = n;
+               ah.global = n->global;
+
+               return process_cmd(&ah, l->args[2]);
+       } else if (!g_strcasecmp(l->args[0], "ISON")) {
+               int i;
+               char *tmp;
+               GList *gl = NULL;
+
+               if (l->args[1] == NULL) {
+                       virtual_network_recv_response(c->network, ERR_NEEDMOREPARAMS, l->args[0], "Not enough params", NULL);
+                       return TRUE;
+               }
 
-       if (g_strcasecmp(l->args[1], ADMIN_CHANNEL) && 
-               g_strcasecmp(l->args[1], "ctrlproxy")) {
-               virtual_network_recv_args(c->network, NULL, "401", l->args[1], "No such nick/channel", NULL);
+               for (i = 1; l->args[i]; i++) {
+                       if (!g_strcasecmp(l->args[i], "ctrlproxy") ||
+                               !g_strcasecmp(l->args[i], n->state->me.nick)) {
+                               gl = g_list_append(gl, l->args[i]);
+                       }
+               }
+               virtual_network_recv_response(n, RPL_ISON, tmp = list_make_string(gl), NULL);
+               g_free(tmp);
+               g_list_free(gl);
                return TRUE;
-       }
+       } else if (!g_strcasecmp(l->args[0], "USERHOST")) {
+               GList *gl = NULL;
+               char *tmp;
+               int i;
 
-       ah.send_fn = network_admin_out;
-       ah.user_data = NULL;
-       ah.client = c;
-       ah.network = n;
-       ah.global = n->global;
+               if (l->args[1] == NULL) {
+                       virtual_network_recv_response(c->network, ERR_NEEDMOREPARAMS, l->args[0], "Not enough params", NULL);
+                       return TRUE;
+               }
+
+               for (i = 1; l->args[i]; i++) {
+                       if (!g_strcasecmp(l->args[i], "ctrlproxy")) {
+                               gl = g_list_append(gl, g_strdup_printf("%s=+%s", l->args[i], get_my_hostname()));
+                       }
+                       if (!g_strcasecmp(l->args[i], c->network->state->me.nick)) {
+                               gl = g_list_append(gl, g_strdup_printf("%s=+%s", l->args[i], c->network->state->me.hostname));
+                       }
+               }
 
-       return process_cmd(&ah, l->args[2]);
+               virtual_network_recv_response(n, RPL_ISON, tmp = list_make_string(gl), NULL);
+               g_free(tmp);
+               while (gl) {
+                       g_free(gl->data);
+                       gl = g_list_remove(gl, gl->data);
+               }
+               return TRUE;
+       } else {
+               virtual_network_recv_response(c->network, ERR_UNKNOWNCOMMAND, l->args[0], "Unknown command", NULL);
+               log_global(LOG_TRACE, "Unhandled command `%s' to admin network", 
+                                  l->args[0]);
+               return TRUE;
+       }
 }
 
 struct virtual_network_ops admin_network = {