changeset 1391:e20ab87c4c4c

The command /room ban can be used with a nickname If the parameter doesn't look like a jid, check if it is a room member nickname.
author Mikael Berthe <mikael@lilotux.net>
date Wed, 05 Dec 2007 22:05:41 +0100
parents 753a348c65c1
children 3d4963c8ce87
files mcabber/src/commands.c mcabber/src/jab_priv.h mcabber/src/jabglue.h
diffstat 3 files changed, 30 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/src/commands.c	Wed Dec 05 19:31:07 2007 +0100
+++ b/mcabber/src/commands.c	Wed Dec 05 22:05:41 2007 +0100
@@ -2201,7 +2201,8 @@
 static void room_ban(gpointer bud, char *arg)
 {
   char **paramlst;
-  gchar *fjid;
+  gchar *fjid, *bjid;
+  const gchar *banjid;
   gchar *jid_utf8, *reason_utf8;
   struct role_affil ra;
   const char *roomid = buddy_getjid(bud);
@@ -2219,12 +2220,35 @@
   ra.type = type_affil;
   ra.val.affil = affil_outcast;
 
-  jid_utf8 = to_utf8(fjid);
+  bjid = jidtodisp(fjid);
+  jid_utf8 = to_utf8(bjid);
+
+  // If the argument doesn't look like a jid, we'll try to find a matching
+  // nickname.
+  if (!strchr(bjid, JID_DOMAIN_SEPARATOR) || check_jid_syntax(bjid)) {
+    const gchar *tmp;
+    // We want the initial argument, so the fjid variable, because
+    // we don't want to strip a resource-like string from the nickname!
+    g_free(jid_utf8);
+    jid_utf8 = to_utf8(fjid);
+    tmp = buddy_getrjid(bud, jid_utf8);
+    if (!tmp) {
+      scr_LogPrint(LPRINT_NORMAL, "Wrong JID or nickname");
+      goto room_ban_return;
+    }
+    banjid = jidtodisp(tmp);
+  } else
+    banjid = jid_utf8;
+
+  scr_LogPrint(LPRINT_NORMAL, "Requesting a ban for %s", banjid);
+
   reason_utf8 = to_utf8(arg);
-  jb_room_setattrib(roomid, jid_utf8, NULL, ra, reason_utf8);
+  jb_room_setattrib(roomid, banjid, NULL, ra, reason_utf8);
+  g_free(reason_utf8);
+
+room_ban_return:
+  g_free(bjid);
   g_free(jid_utf8);
-  g_free(reason_utf8);
-
   free_arg_lst(paramlst);
 }
 
--- a/mcabber/src/jab_priv.h	Wed Dec 05 19:31:07 2007 +0100
+++ b/mcabber/src/jab_priv.h	Wed Dec 05 22:05:41 2007 +0100
@@ -38,7 +38,6 @@
 
 extern time_t iqlast;           /* last message/status change time */
 
-char *jidtodisp(const char *fjid);
 void handle_packet_iq(jconn conn, char *type, char *from, xmlnode xmldata);
 void display_server_error(xmlnode x);
 eviqs *iqs_new(guint8 type, const char *ns, const char *prefix, time_t timeout);
--- a/mcabber/src/jabglue.h	Wed Dec 05 19:31:07 2007 +0100
+++ b/mcabber/src/jabglue.h	Wed Dec 05 22:05:41 2007 +0100
@@ -42,6 +42,7 @@
   gchar *text;
 };
 
+char *jidtodisp(const char *fjid);
 char *compose_jid(const char *username, const char *servername,
                   const char *resource);
 jconn jb_connect(const char *fjid, const char *server, unsigned int port,