changeset 2138:f063e36425a2

Use bookmarked password (if any) when using "/room join" (The password was only used when auto-joining.)
author Mikael Berthe <mikael@lilotux.net>
date Sun, 06 Jul 2014 13:24:06 +0200
parents 0bfc4bfc127c
children 5afdfac67964
files mcabber/mcabber/commands.c mcabber/mcabber/xmpp.c mcabber/mcabber/xmpp.h
diffstat 3 files changed, 28 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/mcabber/commands.c	Sun Jul 06 13:12:10 2014 +0200
+++ b/mcabber/mcabber/commands.c	Sun Jul 06 13:24:06 2014 +0200
@@ -2608,6 +2608,12 @@
 
   pass_utf8 = to_utf8(pass);
 
+  if (!pass) {
+    const char *roompass = xmpp_get_bookmark_password(roomname);
+    if (roompass)
+      pass_utf8 = g_strdup(roompass);
+  }
+
   xmpp_room_join(roomname, nick, pass_utf8);
 
   scr_LogPrint(LPRINT_LOGNORM, "Sent a join request to <%s>...", roomname);
--- a/mcabber/mcabber/xmpp.c	Sun Jul 06 13:12:10 2014 +0200
+++ b/mcabber/mcabber/xmpp.c	Sun Jul 06 13:24:06 2014 +0200
@@ -2243,6 +2243,27 @@
   return NULL;
 }
 
+//  xmpp_get_bookmark_password(roomjid)
+// Return the room password if it is present in a bookmark.
+const char *xmpp_get_bookmark_password(const char *bjid)
+{
+  LmMessageNode *x;
+
+  if (!bookmarks || !bjid)
+    return NULL;
+
+  // Walk through the storage bookmark tags
+  for (x = bookmarks->children ; x; x = x->next) {
+    // If the node is a conference item, check the jid.
+    if (x->name && !strcmp(x->name, "conference")) {
+      const char *fjid = lm_message_node_get_attribute(x, "jid");
+      if (fjid && !strcasecmp(bjid, fjid))
+        return lm_message_node_get_child_value(x, "password");
+    }
+  }
+  return NULL;
+}
+
 int xmpp_get_bookmark_autojoin(const char *bjid)
 {
   LmMessageNode *x;
--- a/mcabber/mcabber/xmpp.h	Sun Jul 06 13:12:10 2014 +0200
+++ b/mcabber/mcabber/xmpp.h	Sun Jul 06 13:24:06 2014 +0200
@@ -80,6 +80,7 @@
 void xmpp_set_storage_rosternotes(const char *barejid, const char *note);
 guint xmpp_is_bookmarked(const char *bjid);
 const char *xmpp_get_bookmark_nick(const char *bjid);
+const char *xmpp_get_bookmark_password(const char *bjid);
 int xmpp_get_bookmark_autojoin(const char *bjid);
 
 void xmpp_request(const char *fjid, enum iqreq_type reqtype);