changeset 26678:1de01f9594c8

Use per-PurpleDiscoList ops for canceling a disco and registering.
author Paul Aurich <paul@darkrain42.org>
date Sat, 11 Apr 2009 21:46:12 +0000
parents 30221bc3da0e
children 89bbb4360df2
files libpurple/dbus-analyze-functions.py libpurple/disco.c libpurple/disco.h libpurple/protocols/jabber/disco.c libpurple/protocols/jabber/disco.h libpurple/protocols/jabber/libxmpp.c libpurple/prpl.h
diffstat 7 files changed, 88 insertions(+), 84 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/dbus-analyze-functions.py	Sat Apr 11 18:32:51 2009 +0000
+++ b/libpurple/dbus-analyze-functions.py	Sat Apr 11 21:46:12 2009 +0000
@@ -31,6 +31,11 @@
     "purple_account_unregister",
     "purple_connection_new_unregister",
 
+    # Similar to all the above:
+    "purple_disco_list_set_cancel_func",
+    "purple_disco_list_set_protocol_data",
+    "purple_disco_list_set_register_func",
+
     # This is excluded because this script treats PurpleLogReadFlags*
     # as pointer to a struct, instead of a pointer to an enum.  This
     # causes a compilation error. Someone should fix this script.
--- a/libpurple/disco.c	Sat Apr 11 18:32:51 2009 +0000
+++ b/libpurple/disco.c	Sat Apr 11 21:46:12 2009 +0000
@@ -44,8 +44,13 @@
 
 	gpointer ui_data; /**< UI private data. */
 	gpointer proto_data; /**< Prpl private data. */
-	PurpleDiscoCloseCallback close_cb; /**< Callback to free the prpl data */
 	guint ref; /**< The reference count. */
+
+	struct {
+		PurpleDiscoCancelFunc cancel_cb;
+		PurpleDiscoCloseFunc close_cb; /**< Callback to free the prpl data */
+		PurpleDiscoRegisterFunc register_cb;
+	} ops;
 };
 
 /**
@@ -106,8 +111,8 @@
 	if (ops && ops->destroy)
 		ops->destroy(list);
 
-	if (list->close_cb)
-		list->close_cb(list);
+	if (list->ops.close_cb)
+		list->ops.close_cb(list);
 
 	for (l = list->services; l; l = l->next) {
 		PurpleDiscoService *s = l->data;
@@ -178,47 +183,28 @@
 
 void purple_disco_cancel_get_list(PurpleDiscoList *list)
 {
-	PurplePlugin *prpl = NULL;
-	PurplePluginProtocolInfo *prpl_info = NULL;
-	PurpleConnection *gc;
-
 	g_return_if_fail(list != NULL);
 
-	gc = purple_account_get_connection(list->account);
-
-	g_return_if_fail(gc != NULL);
-
-	if (gc)
-		prpl = purple_connection_get_prpl(gc);
-
-	if (prpl)
-		prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);
-
-	if (prpl_info && PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(prpl_info, disco_cancel))
-		prpl_info->disco_cancel(list);
+	if (list->ops.cancel_cb)
+		list->ops.cancel_cb(list);
 
 	purple_disco_list_set_in_progress(list, FALSE);
 }
 
 void purple_disco_service_register(PurpleDiscoService *service)
 {
+	PurpleDiscoList *list;
 	PurpleConnection *pc;
-	PurplePlugin *prpl = NULL;
-	PurplePluginProtocolInfo *prpl_info = NULL;
 
 	g_return_if_fail(service != NULL);
-	
-	pc = purple_account_get_connection(service->list->account);
+
+	list = service->list;
+	pc = purple_account_get_connection(list->account);
 
 	g_return_if_fail(pc != NULL);
 
-	prpl = purple_connection_get_prpl(pc);
-
-	if (prpl != NULL)
-		prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);
-
-	if (prpl_info && PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(prpl_info, disco_service_register))
-		prpl_info->disco_service_register(pc, service);
+	if (list->ops.register_cb)
+		list->ops.register_cb(pc, service);
 }
 
 const gchar *purple_disco_service_get_name(PurpleDiscoService *service)
@@ -314,12 +300,12 @@
 
 void purple_disco_list_set_protocol_data(PurpleDiscoList *list,
                                          gpointer proto_data,
-                                         PurpleDiscoCloseCallback cb)
+                                         PurpleDiscoCloseFunc cb)
 {
 	g_return_if_fail(list != NULL);
 
-	list->proto_data = proto_data;
-	list->close_cb   = cb;
+	list->proto_data   = proto_data;
+	list->ops.close_cb = cb;
 }
 
 gpointer purple_disco_list_get_protocol_data(PurpleDiscoList *list)
--- a/libpurple/disco.h	Sat Apr 11 18:32:51 2009 +0000
+++ b/libpurple/disco.h	Sat Apr 11 21:46:12 2009 +0000
@@ -33,11 +33,36 @@
 typedef struct _PurpleDiscoUiOps PurpleDiscoUiOps;
 
 #include "account.h"
+#include "connection.h"
+
+/**
+ * A prpl callback called to tell the prpl to cancel creating the list.
+ * The prpl must implement this and must not add services to the
+ * PurpleDiscoList after this is called.
+ *
+ * @param list  The disco list.
+ */
+typedef void (*PurpleDiscoCancelFunc)(PurpleDiscoList *list);
 
 /**
+ * A prpl callback called to tell the prpl to tell it to destroy
+ * prpl-specific data relating to this PurpleDiscoList (which will be
+ * destroyed imminently).
+ *
+ * @param list  The disco list.
+ */
+typedef void (*PurpleDiscoCloseFunc)(PurpleDiscoList *list);
+
+/**
+ * A prpl callback called to initiate registration with the specificed
+ * service.
+ *
+ * @param pc       The connection.
+ * @param service  The service to which to register.
  *
  */
-typedef void  (*PurpleDiscoCloseCallback) (PurpleDiscoList *list);
+typedef void (*PurpleDiscoRegisterFunc)(PurpleConnection *pc,
+                                        PurpleDiscoService *service);
 
 /**
  * The types of services.
@@ -310,7 +335,7 @@
  * @since TODO
  */
 void purple_disco_list_set_protocol_data(PurpleDiscoList *list, gpointer data,
-                                         PurpleDiscoCloseCallback cb);
+                                         PurpleDiscoCloseFunc cb);
 
 /**
  * Returns the disco list's protocol-specific data.
@@ -325,6 +350,9 @@
  */
 gpointer purple_disco_list_get_protocol_data(PurpleDiscoList *list);
 
+void purple_disco_list_set_cancel_func(PurpleDiscoList *list, PurpleDiscoCancelFunc cb);
+void purple_disco_list_set_register_func(PurpleDiscoList *list, PurpleDiscoRegisterFunc cb);
+
 /**
  * Sets the UI operations structure to be used in all purple service discovery.
  *
--- a/libpurple/protocols/jabber/disco.c	Sat Apr 11 18:32:51 2009 +0000
+++ b/libpurple/protocols/jabber/disco.c	Sat Apr 11 21:46:12 2009 +0000
@@ -957,37 +957,7 @@
 	jabber_disco_info_do(js, list_data->server, jabber_disco_server_info_cb, list_data);
 }
 
-PurpleDiscoList *
-jabber_disco_get_list(PurpleConnection *gc)
-{
-	PurpleAccount *account;
-	PurpleDiscoList *list;
-	JabberStream *js;
-	struct jabber_disco_list_data *disco_list_data;
-
-	account = purple_connection_get_account(gc);
-	js = purple_connection_get_protocol_data(gc);
-
-	/* We start with a ref */
-	list = purple_disco_list_new(account);
-
-	disco_list_data = g_new0(struct jabber_disco_list_data, 1);
-	disco_list_data->list = list;
-	disco_list_data->js = js;
-	purple_disco_list_set_protocol_data(list, disco_list_data, disco_proto_data_destroy_cb);
-
-	purple_request_input(gc, _("Server name request"), _("Enter an XMPP Server"),
-			_("Select an XMPP server to query"),
-			js->last_disco_server ? js->last_disco_server : js->user->domain,
-			FALSE, FALSE, NULL,
-			_("Find Services"), PURPLE_CALLBACK(discolist_ok_cb),
-			_("Cancel"), PURPLE_CALLBACK(discolist_cancel_cb),
-			account, NULL, NULL, disco_list_data);
-
-	return list;
-}
-
-void
+static void
 jabber_disco_cancel(PurpleDiscoList *list)
 {
 	struct jabber_disco_list_data *list_data = purple_disco_list_get_protocol_data(list);
@@ -1008,14 +978,45 @@
 	}
 }
 
-int
+static void
 jabber_disco_service_register(PurpleConnection *gc, PurpleDiscoService *service)
 {
 	JabberStream *js = purple_connection_get_protocol_data(gc);
 
 	jabber_register_gateway(js, purple_disco_service_get_name(service));
+}
 
-	return 0;
+
+PurpleDiscoList *
+jabber_disco_get_list(PurpleConnection *gc)
+{
+	PurpleAccount *account;
+	PurpleDiscoList *list;
+	JabberStream *js;
+	struct jabber_disco_list_data *disco_list_data;
+
+	account = purple_connection_get_account(gc);
+	js = purple_connection_get_protocol_data(gc);
+
+	/* We start with a ref */
+	list = purple_disco_list_new(account);
+
+	disco_list_data = g_new0(struct jabber_disco_list_data, 1);
+	disco_list_data->list = list;
+	disco_list_data->js = js;
+	purple_disco_list_set_protocol_data(list, disco_list_data, disco_proto_data_destroy_cb);
+	purple_disco_list_set_cancel_func(list, jabber_disco_cancel);
+	purple_disco_list_set_register_func(list, jabber_disco_service_register);
+
+	purple_request_input(gc, _("Server name request"), _("Enter an XMPP Server"),
+			_("Select an XMPP server to query"),
+			js->last_disco_server ? js->last_disco_server : js->user->domain,
+			FALSE, FALSE, NULL,
+			_("Find Services"), PURPLE_CALLBACK(discolist_ok_cb),
+			_("Cancel"), PURPLE_CALLBACK(discolist_cancel_cb),
+			account, NULL, NULL, disco_list_data);
+
+	return list;
 }
 
 static void
--- a/libpurple/protocols/jabber/disco.h	Sat Apr 11 18:32:51 2009 +0000
+++ b/libpurple/protocols/jabber/disco.h	Sat Apr 11 21:46:12 2009 +0000
@@ -47,10 +47,6 @@
 		JabberDiscoInfoCallback *callback, gpointer data);
 
 PurpleDiscoList *jabber_disco_get_list(PurpleConnection *gc);
-void jabber_disco_cancel(PurpleDiscoList *list);
-
-int jabber_disco_service_register(PurpleConnection *gc, PurpleDiscoService *service);
-
 
 void jabber_disco_items_do(JabberStream *js, const char *jid, const char *node,
 		JabberDiscoItemsCallback *callback, gpointer data);
--- a/libpurple/protocols/jabber/libxmpp.c	Sat Apr 11 18:32:51 2009 +0000
+++ b/libpurple/protocols/jabber/libxmpp.c	Sat Apr 11 21:46:12 2009 +0000
@@ -124,8 +124,6 @@
 	jabber_initiate_media,          /* initiate_media */
 	jabber_get_media_caps,                  /* get_media_caps */
 	jabber_disco_get_list,			/* disco_get_list */
-	jabber_disco_cancel,			/* disco_cancel */
-	jabber_disco_service_register	/* disco_service_register */
 };
 
 static gboolean load_plugin(PurplePlugin *plugin)
--- a/libpurple/prpl.h	Sat Apr 11 18:32:51 2009 +0000
+++ b/libpurple/prpl.h	Sat Apr 11 21:46:12 2009 +0000
@@ -487,16 +487,6 @@
 	 * Service discovery prpl callbacks
 	 */
 	PurpleDiscoList *(*disco_get_list)(PurpleConnection *gc);
-
-	/**
-	 * Cancel fetching service list
-	 */
-	void (*disco_cancel)(PurpleDiscoList *list);
-
-	/**
-	 * Register service
-	 */
-	int (*disco_service_register)(PurpleConnection *gc, PurpleDiscoService *service);
 };
 
 #define PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(prpl, member) \