patches/pidgin-01-gnome-keyring.diff
author rickju
Fri, 07 Dec 2007 05:29:45 +0000
changeset 11300 3060d2518108
parent 11157 a01e32482ce3
child 12337 75eef8aa34d6
permissions -rw-r--r--
2007-12-06 Rick Ju <[email protected]> * SUNWgnome-im-client.spec: * base-specs/pidgin.spec: * patches/pidgin-01-gnome-keyring.diff: * patches/pidgin-04-jabber-msg.diff: Bump to pidgin 2.3.0

--- 2.0b4-my/libpurple/Makefile.am	2006-10-19 01:38:16.000000000 +0800
+++ 2.0b4-my2/libpurple/Makefile.am	2006-11-13 18:28:51.383417000 +0800
@@ -230,6 +230,7 @@
 	$(GLIB_LIBS) \
 	$(LIBXML_LIBS) \
 	$(LIBNM_LIBS) \
+	$(GAIM_KEYRING_LIBS) \
 	$(INTLLIBS) \
 	-lm
 
@@ -242,5 +243,6 @@
 	$(GLIB_CFLAGS) \
 	$(DEBUG_CFLAGS) \
 	$(DBUS_CFLAGS) \
+	$(GAIM_KEYRING_CFLAGS) \
 	$(LIBXML_CFLAGS) \
 	$(LIBNM_CFLAGS)
--- pidgin-2.3.0/libpurple/account.c	2007-11-25 03:05:51.000000000 +0800
+++ pidgin-2.3.0-my/libpurple/account.c	2007-12-06 11:35:30.201708000 +0800
@@ -49,6 +49,13 @@
 #define PURPLE_ACCOUNT_GET_PRIVATE(account) \
 	((PurpleAccountPrivate *) (account->priv))
 
+#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 PurpleValue instead of this?  What about "ui"? */
 typedef struct
 {
@@ -363,8 +370,13 @@
 	if (purple_account_get_remember_password(account) &&
 		((tmp = purple_account_get_password(account)) != NULL))
 	{
+#ifdef GAIM_ENABLE_KEYRING
+                gaim_account_set_password_in_keyring( purple_account_get_protocol_id(account),
+                                          purple_account_get_username(account), tmp);
+#else
 		child = xmlnode_new_child(node, "password");
 		xmlnode_insert_data(child, tmp, -1);
+#endif
 	}
 
 	if ((tmp = purple_account_get_alias(account)) != NULL)
@@ -778,17 +790,30 @@
 	}
 
 	ret = purple_account_new(name, _purple_oscar_convert(name, protocol_id)); /* XXX: */
-	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))
-	{
-		purple_account_set_remember_password(ret, TRUE);
-		purple_account_set_password(ret, data);
-		g_free(data);
-	}
+        gboolean got_pwd = FALSE;
+#ifdef GAIM_ENABLE_KEYRING
+        data = gaim_account_get_password_from_keyring(protocol_id, name);
+        if (data)
+        {
+                got_pwd = TRUE;
+                purple_account_set_remember_password(ret, TRUE);
+                purple_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))
+		{
+			purple_account_set_remember_password(ret, TRUE);
+			purple_account_set_password(ret, data);
+			g_free(data);
+		}
+        }
+        g_free(name);
+        g_free(protocol_id);
 
 	/* Read the alias */
 	child = xmlnode_get_child(node, "alias");
@@ -2698,3 +2723,61 @@
 	purple_signals_disconnect_by_handle(handle);
 	purple_signals_unregister_by_instance(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;
+
+  if (matches == NULL || matches->data == NULL)
+    return 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
--- pidgin-2.0.0/configure.ac-ori	2007-05-24 14:26:55.133319000 +0800
+++ pidgin-2.0.0/configure.ac	2007-05-24 14:27:12.141394000 +0800
@@ -1914,6 +1914,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(GAIM_ENABLE_KEYRING, [], [Set if we should use gnome-keyring]))
+fi
+
 AC_MSG_CHECKING(for me pot o' gold)
 AC_MSG_RESULT(no)
 AC_CHECK_FUNCS(gethostid lrand48)
--- old/pidgin/gtkmain.c	Wed Oct 24 04:55:59 2007
+++ new/pidgin/gtkmain.c	Fri Nov  9 10:12:22 2007
@@ -67,6 +67,10 @@
 #include "pidginstock.h"
 #include "gtkwhiteboard.h"
 
+#ifdef GAIM_ENABLE_KEYRING
+#include <gnome-keyring.h>
+#endif
+
 #ifdef HAVE_SIGNAL_H
 # include <signal.h>
 #endif
@@ -680,6 +684,12 @@
 	gtk_rc_add_default_file(search_path);
 	g_free(search_path);
 
+#ifdef  GAIM_ENABLE_KEYRING
+	GnomeKeyringResult rtn = gnome_keyring_unlock_sync(NULL, NULL);
+	// if (rtn == GNOME_KEYRING_RESULT_DENIED)
+	//   return 0;
+#endif
+
 	gui_check = gtk_init_check(&argc, &argv);
 	if (!gui_check) {
 		char *display = gdk_get_display();
--- old/pidgin/Makefile.am	2007-08-21 02:12:53.000000000 +0800
+++ new/pidgin/Makefile.am	2007-09-18 14:55:09.688398000 +0800
@@ -185,6 +185,7 @@
 	$(GTKSPELL_LIBS) \
 	$(STARTUP_NOTIFICATION_LIBS) \
 	$(LIBXML_LIBS) \
+	$(GAIM_KEYRING_LIBS) \
 	$(GTK_LIBS) \
 	$(top_builddir)/libpurple/libpurple.la
 
@@ -204,6 +205,7 @@
 	$(GSTREAMER_CFLAGS) \
 	$(DEBUG_CFLAGS) \
 	$(GTK_CFLAGS) \
+	$(GAIM_KEYRING_CFLAGS) \
 	$(DBUS_CFLAGS) \
 	$(GTKSPELL_CFLAGS) \
 	$(STARTUP_NOTIFICATION_CFLAGS) \