changeset 584:414fbf558f1e

jb_room_setattrib()
author Mikael Berthe <mikael@lilotux.net>
date Fri, 09 Dec 2005 19:49:58 +0100
parents 32ae027a3238
children 7eff2c1481fa
files mcabber/src/commands.c mcabber/src/jabglue.c mcabber/src/jabglue.h mcabber/src/roster.c mcabber/src/roster.h
diffstat 5 files changed, 55 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/src/commands.c	Tue Dec 06 21:13:03 2005 +0100
+++ b/mcabber/src/commands.c	Fri Dec 09 19:49:58 2005 +0100
@@ -1251,6 +1251,7 @@
 {
   char **paramlst;
   gchar *jid;
+  struct role_affil ra;
   const char *roomid = buddy_getjid(bud);
 
   paramlst = split_arg(arg, 2, 1); // jid, [reason]
@@ -1263,7 +1264,10 @@
     return;
   }
 
-  jb_room_setaffil(roomid, jid, NULL, affil_outcast, arg);
+  ra.type = type_affil;
+  ra.val.affil = affil_outcast;
+
+  jb_room_setattrib(roomid, jid, NULL, ra, arg);
 
   free_arg_lst(paramlst);
 }
@@ -1273,6 +1277,7 @@
 {
   char **paramlst;
   gchar *nick;
+  struct role_affil ra;
   const char *roomid = buddy_getjid(bud);
 
   paramlst = split_arg(arg, 2, 1); // nickname, [reason]
@@ -1285,7 +1290,10 @@
     return;
   }
 
-  jb_room_setaffil(roomid, NULL, nick, affil_none, arg);
+  ra.type = type_role;
+  ra.val.affil = role_none;
+
+  jb_room_setattrib(roomid, NULL, nick, ra, arg);
 
   free_arg_lst(paramlst);
 }
--- a/mcabber/src/jabglue.c	Tue Dec 06 21:13:03 2005 +0100
+++ b/mcabber/src/jabglue.c	Fri Dec 09 19:49:58 2005 +0100
@@ -570,23 +570,21 @@
   jb_reset_keepalive();
 }
 
-// Kick or ban a MUC room member
+// Change role or affiliation of a MUC user
 // room syntax: "room@server"
 // Either the jid or the nickname must be set (when banning, only the jid is
 // allowed)
-// affil: new affiliation (ex. affil_none for kick, affil_outcast for ban...)
+// ra: new role or affiliation
+//     (ex. role none for kick, affil outcast for ban...)
 // The reason can be null
 // Return 0 if everything is ok
-int jb_room_setaffil(const char *roomid, const char *jid, const char *nick,
-                     enum imaffiliation affil, const char *reason)
+int jb_room_setattrib(const char *roomid, const char *jid, const char *nick,
+                      struct role_affil ra, const char *reason)
 {
   xmlnode x, y, z;
 
   if (!online || !roomid) return 1;
-
-  // Only none & outcast at the moment
-  if (affil != affil_none && affil != affil_outcast)
-    return 1;
+  if (!jid && !nick) return 1;
 
   if (check_jid_syntax((char*)roomid)) {
     scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber id", roomid);
@@ -597,27 +595,28 @@
     return 1;
   }
 
-  if (affil == affil_outcast && !jid)
+  if (ra.type == type_affil && ra.val.affil == affil_outcast && !jid)
     return 1; // Shouldn't happen (jid mandatory when banning)
 
   x = jutil_iqnew(JPACKET__SET, "http://jabber.org/protocol/muc#admin");
-  xmlnode_put_attrib(x, "id", "kick1"); // XXX
+  xmlnode_put_attrib(x, "id", "roleaffil1"); // XXX
   xmlnode_put_attrib(x, "to", roomid);
   xmlnode_put_attrib(x, "type", "set");
   y = xmlnode_get_tag(x, "query");
   z = xmlnode_insert_tag(y, "item");
 
-  if (!jid) {
+  if (jid) {
+    xmlnode_put_attrib(z, "jid", jid);
+  } else { // nick
     gchar *utf8_nickname = to_utf8(nick);
     xmlnode_put_attrib(z, "nick", utf8_nickname);
     g_free(utf8_nickname);
-  } else {
-    xmlnode_put_attrib(z, "jid", jid);
-    if (affil == affil_outcast)
-      xmlnode_put_attrib(z, "affiliation", "outcast");
   }
-  if (affil == affil_none)
-    xmlnode_put_attrib(z, "role", "none");
+
+  if (ra.type == type_affil)
+    xmlnode_put_attrib(z, "affiliation", straffil[ra.val.affil]);
+  else if (ra.type == type_role)
+    xmlnode_put_attrib(z, "role", strrole[ra.val.role]);
 
   if (reason) {
     gchar *utf8_reason = to_utf8(reason);
--- a/mcabber/src/jabglue.h	Tue Dec 06 21:13:03 2005 +0100
+++ b/mcabber/src/jabglue.h	Fri Dec 09 19:49:58 2005 +0100
@@ -48,8 +48,8 @@
 void jb_room_join(const char *room, const char *nickname);
 void jb_room_unlock(const char *room);
 void jb_room_invite(const char *room, const char *jid, const char *reason);
-int  jb_room_setaffil(const char *roomid, const char *jid, const char *nick,
-                      enum imaffiliation, const char *reason);
+int  jb_room_setattrib(const char *roomid, const char *jid, const char *nick,
+                       struct role_affil ra, const char *reason);
 
 #endif /* __JABGLUE_H__ */
 
--- a/mcabber/src/roster.c	Tue Dec 06 21:13:03 2005 +0100
+++ b/mcabber/src/roster.c	Fri Dec 09 19:49:58 2005 +0100
@@ -25,6 +25,21 @@
 #include "roster.h"
 
 
+char *strrole[] = { /* Should match enum in roster.h */
+  "none",
+  "moderator",
+  "participant",
+  "visitor"
+};
+
+char *straffil[] = { /* Should match enum roster.h */
+  "none",
+  "owner",
+  "admin",
+  "memeber",
+  "outcast"
+};
+
 /* Resource structure */
 
 typedef struct {
--- a/mcabber/src/roster.h	Tue Dec 06 21:13:03 2005 +0100
+++ b/mcabber/src/roster.h	Fri Dec 09 19:49:58 2005 +0100
@@ -21,6 +21,8 @@
   role_visitor
 };
 
+extern char *strrole[]; // Should match enum above
+
 enum imaffiliation {
   affil_none,
   affil_owner,
@@ -29,6 +31,8 @@
   affil_outcast
 };
 
+extern char *straffil[]; // Should match enum above
+
 enum subscr {
   sub_none,
   sub_to,
@@ -41,6 +45,14 @@
   namesearch
 };
 
+struct role_affil {
+  enum { type_role, type_affil } type;
+  union {
+    enum imrole role;
+    enum imaffiliation affil;
+  } val;
+};
+
 // Roster_type is a set of flags, so values should be 2^n
 #define ROSTER_TYPE_USER    1
 #define ROSTER_TYPE_GROUP   2