patches/gaim-08-gnome-keyring.diff
author hawklu
Fri, 17 Nov 2006 07:36:56 +0000
changeset 8587 5a4ef0118d2f
child 19060 92bbc033db49
permissions -rw-r--r--
2006-11-16 Rick Ju <[email protected]> * gaim.spec: add a new patch gaim-08-gnome-keyring.diff. add --enable-gnome-keyring to configure add a new patch gaim-09-gtk-file-chooser.diff * Solaris/SUNWgnome-im-client.spec: fixing the gaim.pc missing bug(#6423188) * patches/gaim-08-gnome-keyring.diff: Added to fix #6439103 gaim must use gnome-keyring * patches/gaim-09-gtk-file-chooser.diff: Added to fix #6430863 #6489148 #6473371 #6491296 #6483844 #6448364

--- 2.0b4-my/configure.ac	2006-11-13 18:29:02.830447000 +0800
+++ 2.0b4-my2/configure.ac	2006-11-13 17:05:20.491984000 +0800
@@ -1783,6 +1783,20 @@
 	LDFLAGS="$orig_LDFLAGS"
 fi
 
+dnl #######################################################################
+dnl # Check for gnome-keyring
+dnl #--enable-gnome-keyring=(yes|no)
+dnl #######################################################################
+AC_ARG_ENABLE(gnome-keyring,
+              AC_HELP_STRING([--enable-gnome-keyring],
+                             [use gnome keyring for storing password [default=no]]),,
+              enable_gnome_keyring=no)
+if test "x$enable_gnome_keyring" = "xyes"; then
+    PKG_CHECK_MODULES(GAIM_KEYRING,
+                      gnome-keyring-1,
+                      AC_DEFINE(VINO_ENABLE_KEYRING, [], [Set if we should use gnome-keyring]))
+fi
+
 AM_BINRELOC
 
 AC_MSG_CHECKING(for me pot o' gold)
--- 2.0b4-my/libgaim/Makefile.am	2006-10-19 01:38:16.000000000 +0800
+++ 2.0b4-my2/libgaim/Makefile.am	2006-11-13 18:28:51.383417000 +0800
@@ -221,6 +221,7 @@
 	$(LIBXML_LIBS) \
 	$(LIBNM_LIBS) \
 	$(STATIC_LINK_LIBS) \
+	$(GAIM_KEYRING_LIBS) \
 	$(INTLLIBS) \
 	-lm
 
@@ -233,5 +234,6 @@
 	$(GLIB_CFLAGS) \
 	$(DEBUG_CFLAGS) \
 	$(DBUS_CFLAGS) \
+	$(GAIM_KEYRING_CFLAGS) \
 	$(LIBXML_CFLAGS) \
 	$(LIBNM_CFLAGS)
--- 2.0b4-my/libgaim/account.c	2006-10-19 01:38:16.000000000 +0800
+++ 2.0b4-my2/libgaim/account.c	2006-11-13 18:26:19.409755000 +0800
@@ -40,6 +40,13 @@
 #include "util.h"
 #include "xmlnode.h"
 
+#ifdef GAIM_ENABLE_KEYRING
+#include <gnome-keyring.h>
+
+static char * gaim_account_get_password_from_keyring (const char *_prpl, const char *_user);
+static gboolean gaim_account_set_password_in_keyring (const char *_prpl, const char *_user, const char *password);
+#endif
+
 /* TODO: Should use GaimValue instead of this?  What about "ui"? */
 typedef struct
 {
@@ -321,8 +328,13 @@
 	if (gaim_account_get_remember_password(account) &&
 		((tmp = gaim_account_get_password(account)) != NULL))
 	{
+#ifdef GAIM_ENABLE_KEYRING
+                gaim_account_set_password_in_keyring( gaim_account_get_protocol_id(account),
+                                          gaim_account_get_username(account), tmp);
+#else
 		child = xmlnode_new_child(node, "password");
 		xmlnode_insert_data(child, tmp, -1);
+#endif
 	}
 
 	if ((tmp = gaim_account_get_alias(account)) != NULL)
@@ -703,17 +715,30 @@
 	}
 
 	ret = gaim_account_new(name, protocol_id);
-	g_free(name);
-	g_free(protocol_id);
-
-	/* Read the password */
-	child = xmlnode_get_child(node, "password");
-	if ((child != NULL) && ((data = xmlnode_get_data(child)) != NULL))
+        gboolean got_pwd = FALSE;
+#ifdef GAIM_ENABLE_KEYRING
+        data = gaim_account_get_password_from_keyring(protocol_id, name);
+        if (data)
 	{
+                got_pwd = TRUE;
 		gaim_account_set_remember_password(ret, TRUE);
 		gaim_account_set_password(ret, data);
 		g_free(data);
 	}
+#endif
+        if (!got_pwd)
+        {
+                /* Read the password */
+                child = xmlnode_get_child(node, "password");
+                if ((child != NULL) && ((data = xmlnode_get_data(child)) != NULL))
+                {
+                        gaim_account_set_remember_password(ret, TRUE);
+                        gaim_account_set_password(ret, data);
+                        g_free(data);
+                }
+        }
+	g_free(name);
+	g_free(protocol_id);
 
 	/* Read the alias */
 	child = xmlnode_get_child(node, "alias");
@@ -2352,3 +2377,60 @@
 
 	gaim_signals_unregister_by_instance(gaim_accounts_get_handle());
 }
+
+#ifdef GAIM_ENABLE_KEYRING
+static char *
+gaim_account_get_password_from_keyring(const char *_prpl, const char *_user)
+{
+  GnomeKeyringNetworkPasswordData *found_item;
+  GnomeKeyringResult               result;
+  GList                           *matches;
+  char                            *password;
+
+  matches = NULL;
+
+  result = gnome_keyring_find_network_password_sync (
+               _user,          /* user     */
+               NULL,           /* domain   */
+               "gaim.local",   /* server   */
+               NULL,           /* object   */
+               _prpl,          /* protocol */
+               NULL,           /* authtype */
+               1863,           /* port     */
+               &matches);
+
+  if (result != GNOME_KEYRING_RESULT_OK)
+    return NULL;
+
+  g_assert (matches != NULL && matches->data != NULL);
+
+  found_item = (GnomeKeyringNetworkPasswordData *) matches->data;
+
+  password = g_strdup (found_item->password);
+
+  gnome_keyring_network_password_list_free (matches);
+
+  return password;
+}
+
+static gboolean
+gaim_account_set_password_in_keyring (const char *_prpl, const char *_user, const char *_password)
+{
+  GnomeKeyringResult result;
+  guint32            item_id;
+
+  result = gnome_keyring_set_network_password_sync (
+                NULL,           /* default keyring */
+                _user,          /* user            */
+                NULL,           /* domain          */
+                "gaim.local",   /* server          */
+                NULL,           /* object          */
+                _prpl,          /* protocol        */
+                NULL,           /* authtype        */
+                1863,           /* port            */
+                _password,       /* password        */
+                &item_id);
+
+  return result == GNOME_KEYRING_RESULT_OK;
+}
+#endif