cpw.darkrain42.xmpp.disco: dc3c9682: Hide the structs, add accessors, and fix...

paul at darkrain42.org paul at darkrain42.org
Sat Apr 25 16:17:44 EDT 2009


-----------------------------------------------------------------
Revision: dc3c968203aeaf603de5e94624c2c2512ef84d0f
Ancestor: e7e886dc821874598f0b74f7bf000ef3b97b48cd
Author: paul at darkrain42.org
Date: 2009-03-30T00:42:15
Branch: im.pidgin.cpw.darkrain42.xmpp.disco
URL: http://d.pidgin.im/viewmtn/revision/info/dc3c968203aeaf603de5e94624c2c2512ef84d0f

Modified files:
        libpurple/disco.c libpurple/disco.h
        libpurple/protocols/jabber/disco.c pidgin/gtkdisco.c

ChangeLog: 

Hide the structs, add accessors, and fix various smaller things:
  * Make the flags an enum instead of #defines
  * There were two sets of _in_progress functions, removed one.
  * Adjusted a few return types to match usage
  * Move the fetch_count into the prpl's protocol_data (which is no longer
    the JabberStream but a dedicated struct)

-------------- next part --------------
============================================================
--- libpurple/disco.c	f50e8ef193cbac22c0efcb20aa687463bba57eab
+++ libpurple/disco.c	0438d84c60892a12efbce72df0fd51f6eb662927
@@ -29,6 +29,37 @@
 
 #include "disco.h"
 
+/**************************************************************************/
+/* Main structures, members and constants                                 */
+/**************************************************************************/
+
+/**
+ * Represents a list of services for a given connection on a given protocol.
+ */
+struct _PurpleDiscoList {
+	PurpleAccount *account; /**< The account this list belongs to. */
+	GList *services; /**< The list of services. */
+
+	gboolean in_progress;
+
+	gpointer ui_data; /**< UI private data. */
+	gpointer proto_data; /** Prpl private data. */
+	guint ref; /**< The reference count. */
+};
+
+/**
+ * Represents a list of services for a given connection on a given protocol.
+ */
+struct _PurpleDiscoService {
+	PurpleDiscoList *list;
+	gchar *name; /**< The name of the service. */
+	gchar *description; /**< The name of the service. */
+
+	PurpleDiscoServiceCategory category; /**< The category of service. */
+	PurpleDiscoServiceType type; /**< The type of service. */
+	PurpleDiscoServiceFlags flags;
+};
+
 static PurpleDiscoUiOps *ops = NULL;
 
 PurpleDiscoList *purple_disco_list_new(PurpleAccount *account, void *ui_data)
@@ -48,12 +79,14 @@ PurpleDiscoList *purple_disco_list_new(P
 	return list;
 }
 
-void purple_disco_list_ref(PurpleDiscoList *list)
+PurpleDiscoList *purple_disco_list_ref(PurpleDiscoList *list)
 {
-	g_return_if_fail(list != NULL);
+	g_return_val_if_fail(list != NULL, NULL);
 
 	list->ref++;
 	purple_debug_misc("disco", "reffing list, ref count now %d\n", list->ref);
+
+	return list;
 }
 
 static void purple_disco_list_service_destroy(PurpleDiscoList *list, PurpleDiscoService *r)
@@ -106,11 +139,12 @@ PurpleDiscoService *purple_disco_list_se
 }
 
 PurpleDiscoService *purple_disco_list_service_new(PurpleDiscoServiceCategory category, const gchar *name,
-		PurpleDiscoServiceType type, const gchar *description, int flags)
+		PurpleDiscoServiceType type, const gchar *description, PurpleDiscoServiceFlags flags)
 {
 	PurpleDiscoService *s;
 
 	g_return_val_if_fail(name != NULL, NULL);
+	g_return_val_if_fail(category != PURPLE_DISCO_SERVICE_CAT_UNSET, NULL);
 
 	s = g_new0(PurpleDiscoService, 1);
 	s->category = category;
@@ -122,20 +156,25 @@ PurpleDiscoService *purple_disco_list_se
 	return s;
 }
 
-void purple_disco_get_list(PurpleConnection *gc, PurpleDiscoList *list)
+void purple_disco_get_list(PurpleDiscoList *list)
 {
+	PurpleConnection *pc = NULL;
 	PurplePlugin *prpl = NULL;
 	PurplePluginProtocolInfo *prpl_info = NULL;
 
-	g_return_if_fail(gc != NULL);
+	g_return_if_fail(list != NULL);
 
-	prpl = purple_connection_get_prpl(gc);
+	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_get_list))
-		prpl_info->disco_get_list(gc, list);
+		prpl_info->disco_get_list(pc, list);
 }
 
 void purple_disco_cancel_get_list(PurpleDiscoList *list)
@@ -160,94 +199,123 @@ void purple_disco_cancel_get_list(Purple
 		prpl_info->disco_cancel(list);
 }
 
-int purple_disco_service_register(PurpleConnection *gc, PurpleDiscoService *service)
+void purple_disco_service_register(PurpleDiscoService *service)
 {
+	PurpleConnection *pc;
 	PurplePlugin *prpl = NULL;
 	PurplePluginProtocolInfo *prpl_info = NULL;
 
-	g_return_val_if_fail(gc != NULL, -EINVAL);
+	g_return_if_fail(service != NULL);
+	
+	pc = purple_account_get_connection(service->list->account);
 
-	prpl = purple_connection_get_prpl(gc);
+	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))
-		return prpl_info->disco_service_register(gc, service);
+		prpl_info->disco_service_register(pc, service);
+}
 
-	return -EINVAL;
+const gchar *purple_disco_service_get_name(PurpleDiscoService *service)
+{
+	g_return_val_if_fail(service != NULL, NULL);
+
+	return service->name;
 }
 
-void purple_disco_set_in_progress(PurpleDiscoList *list, gboolean in_progress)
+const gchar *purple_disco_service_get_description(PurpleDiscoService *service)
 {
-	g_return_if_fail(list != NULL);
+	g_return_val_if_fail(service != NULL, NULL);
 
-	list->in_progress = in_progress;
+	return service->description;
+}
 
-	if (ops && ops->in_progress)
-		ops->in_progress(list, in_progress);
+PurpleDiscoServiceCategory
+purple_disco_service_get_category(PurpleDiscoService *service)
+{
+	g_return_val_if_fail(service != NULL, PURPLE_DISCO_SERVICE_CAT_UNSET);
+
+	return service->category;
 }
 
-gboolean purple_disco_get_in_progress(PurpleDiscoList *list)
+PurpleDiscoServiceType
+purple_disco_service_get_type(PurpleDiscoService *service)
 {
-	g_return_val_if_fail(list != NULL, FALSE);
+	g_return_val_if_fail(service != NULL, PURPLE_DISCO_SERVICE_TYPE_NONE);
 
-	return list->in_progress;
+	return service->type;
 }
 
-void purple_disco_list_set_account(PurpleDiscoList *list, PurpleAccount *account)
+PurpleDiscoServiceFlags
+purple_disco_service_get_flags(PurpleDiscoService *service)
 {
-	list->account = account;
+	g_return_val_if_fail(service != NULL, PURPLE_DISCO_NONE);
+
+	return service->flags;
 }
 
 PurpleAccount* purple_disco_list_get_account(PurpleDiscoList *list)
 {
+	g_return_val_if_fail(list != NULL, NULL);
+
 	return list->account;
 }
 
-GList* spurple_disco_list_get_services(PurpleDiscoList *dl)
+GList* purple_disco_list_get_services(PurpleDiscoList *list)
 {
-	return dl->services;
+	g_return_val_if_fail(list != NULL, NULL);
+
+	return list->services;
 }
 
 void purple_disco_list_set_ui_data(PurpleDiscoList *list, gpointer ui_data)
 {
+	g_return_if_fail(list != NULL);
+
 	list->ui_data = ui_data;
 }
 
 gpointer purple_disco_list_get_ui_data(PurpleDiscoList *list)
 {
+	g_return_val_if_fail(list != NULL, NULL);
+
 	return list->ui_data;
 }
 
-void purple_disco_list_set_in_progress(PurpleDiscoList *list, gboolean in_progress)
+void purple_disco_list_set_in_progress(PurpleDiscoList *list,
+                                       gboolean in_progress)
 {
+	g_return_if_fail(list != NULL);
+
 	list->in_progress = in_progress;
+
+	if (ops && ops->in_progress)
+		ops->in_progress(list, in_progress);
 }
 
 gboolean purple_disco_list_get_in_progress(PurpleDiscoList *list) 
 {
+	g_return_val_if_fail(list != NULL, FALSE);
+
 	return list->in_progress;
 }
 
-void purple_disco_list_set_fetch_count(PurpleDiscoList *list, gint fetch_count)
+void purple_disco_list_set_protocol_data(PurpleDiscoList *list,
+                                         gpointer proto_data)
 {
-	list->fetch_count = fetch_count;
-	purple_debug_info("disco", "fetch_count = %d\n", fetch_count);
-}
+	g_return_if_fail(list != NULL);
 
-gint purple_disco_list_get_fetch_count(PurpleDiscoList *list)
-{
-	return list->fetch_count;
-}
-
-void purple_disco_list_set_proto_data(PurpleDiscoList *list, gpointer proto_data)
-{
 	list->proto_data = proto_data;
 }
 
-gpointer purple_disco_list_get_proto_data(PurpleDiscoList *list)
+gpointer purple_disco_list_get_protocol_data(PurpleDiscoList *list)
 {
+	g_return_val_if_fail(list != NULL, NULL);
+
 	return list->proto_data;
 }
 
============================================================
--- libpurple/disco.h	c681311b65457246b7e67378f5231ec4abe26a27
+++ libpurple/disco.h	8c37b7006bd5085f8f3d7e591f1c4a33910a5db6
@@ -35,19 +35,6 @@ typedef struct _PurpleDiscoUiOps PurpleD
 #include "account.h"
 
 /**
- * Represents a list of services for a given connection on a given protocol.
- */
-struct _PurpleDiscoList {
-	PurpleAccount *account; /**< The account this list belongs to. */
-	GList *services; /**< The list of services. */
-	gpointer *ui_data; /**< UI private data. */
-	gboolean in_progress;
-	gint fetch_count; /**< Uses in fetch processes */
-	gpointer proto_data; /** Prpl private data. */
-	guint ref; /**< The reference count. */
-};
-
-/**
  * The categories of services.
  */
 typedef enum
@@ -81,23 +68,14 @@ typedef enum
 /**
  * The flags of services.
  */
-#define PURPLE_DISCO_FLAG_NONE			0
-#define PURPLE_DISCO_FLAG_ADD			1 << 0
-#define PURPLE_DISCO_FLAG_BROWSE		1 << 1
-#define PURPLE_DISCO_FLAG_REGISTER		1 << 2
+typedef enum
+{
+	PURPLE_DISCO_NONE          = 0x0000,
+	PURPLE_DISCO_ADD           = 0x0001, /**< Supports an 'add' operation */
+	PURPLE_DISCO_BROWSE        = 0x0002, /**< Supports browsing */
+	PURPLE_DISCO_REGISTER      = 0x0004  /**< Supports a 'register' operation */
+} PurpleDiscoServiceFlags;
 
-/**
- * Represents a list of services for a given connection on a given protocol.
- */
-struct _PurpleDiscoService {
-	PurpleDiscoList *list;
-	PurpleDiscoServiceCategory category; /**< The category of service. */
-	gchar *name; /**< The name of the service. */
-	PurpleDiscoServiceType type; /**< The type of service. */
-	guint flags;
-	gchar *description; /**< The name of the service. */
-};
-
 struct _PurpleDiscoUiOps {
 	/** Ask the UI to display a dialog for the specified account.
 	 */
@@ -131,9 +109,9 @@ PurpleDiscoList *purple_disco_list_new(P
 /**
  * Increases the reference count on the service discovery list.
  *
- * @param list The object to ref.
+ * @param list The disco list to ref.
  */
-void purple_disco_list_ref(PurpleDiscoList *list);
+PurpleDiscoList *purple_disco_list_ref(PurpleDiscoList *list);
 
 /**
  * Decreases the reference count on the service discovery list.
@@ -148,10 +126,8 @@ void purple_disco_list_unref(PurpleDisco
 /**
  * Instructs the prpl to start fetching the list.
  *
- * @param gc The PurpleConnection to have get a list.
- *
  */
-void purple_disco_get_list(PurpleConnection *gc, PurpleDiscoList *list);
+void purple_disco_get_list(PurpleDiscoList *list);
 
 /**
  * Tells the prpl to stop fetching the list.
@@ -167,7 +143,7 @@ PurpleDiscoService *purple_disco_list_se
  * Create new service object
  */
 PurpleDiscoService *purple_disco_list_service_new(PurpleDiscoServiceCategory category, const gchar *name,
-		PurpleDiscoServiceType type, const gchar *description, int flags);
+		PurpleDiscoServiceType type, const gchar *description, PurpleDiscoServiceFlags flags);
 
 /**
  * Add service to list
@@ -175,6 +151,103 @@ void purple_disco_list_service_add(Purpl
 void purple_disco_list_service_add(PurpleDiscoList *list, PurpleDiscoService *service, PurpleDiscoService *parent);
 
 /**
+ * Register service
+ * @param service The service that will be registered
+ */
+void purple_disco_service_register(PurpleDiscoService *service);
+
+/**
+ * Returns a service's name.
+ *
+ * @param service The service.
+ * @return The name.
+ *
+ * @since TODO
+ */
+const gchar *purple_disco_service_get_name(PurpleDiscoService *service);
+
+/**
+ * Return a service's description.
+ *
+ * @param service The service.
+ * @return The description.
+ *
+ * @since TODO
+ */
+const gchar* purple_disco_service_get_description(PurpleDiscoService *service);
+
+/**
+ * Return a service's category.
+ *
+ * @param service The service.
+ * @return The category.
+ *
+ * @since TODO
+ */
+PurpleDiscoServiceCategory purple_disco_service_get_category(PurpleDiscoService *service);
+
+/**
+ * Return a service's type.
+ *
+ * @param service The service.
+ * @return The type.
+ *
+ * @since TODO
+ */
+PurpleDiscoServiceType purple_disco_service_get_type(PurpleDiscoService *service);
+
+/**
+ * Return a service's flags.
+ *
+ * @param service The service.
+ * @return The flags.
+ *
+ * @since TODO
+ */
+PurpleDiscoServiceFlags purple_disco_service_get_flags(PurpleDiscoService *service);
+/**
+ * Get the account associated with a service list.
+ *
+ * @param list  The service list.
+ * @return      The account
+ *
+ * @since TODO
+ */
+PurpleAccount* purple_disco_list_get_account(PurpleDiscoList *list);
+
+/**
+ * Get a list of the services associated with this service list.
+ *
+ * @param dl The serivce list.
+ * @returns    A list of PurpleDiscoService items.
+ *
+ * @since TODO
+ */
+GList* purple_disco_list_get_services(PurpleDiscoList *dl);
+
+/**
+ * Set the service list's UI data.
+ *
+ * @param list  The service list.
+ * @param data  The data.
+ *
+ * @see purple_disco_list_get_ui_data()
+ * @since TODO
+ */
+void purple_disco_list_set_ui_data(PurpleDiscoList *list, gpointer data);
+
+/**
+ * Get the service list's UI data.
+ *
+ * @param list  The service list.
+ * @return      The data.
+ *
+ * @see purple_disco_list_set_ui_data()
+ * @since TODO
+ */
+gpointer purple_disco_list_get_ui_data(PurpleDiscoList *list);
+
+/**
  * Set the "in progress" state of the Service Discovery.
  *
  * The UI is encouraged to somehow hint to the user
@@ -182,8 +255,11 @@ void purple_disco_list_service_add(Purpl
  *
  * @param list The service list.
  * @param in_progress We're downloading it, or we're not.
+ *
+ * @see purple_disco_list_get_in_progress()
+ * @since TODO
  */
-void purple_disco_set_in_progress(PurpleDiscoList *list, gboolean in_progress);
+void purple_disco_list_set_in_progress(PurpleDiscoList *list, gboolean in_progress);
 
 /**
  * Gets the "in progress" state of the Service Discovery.
@@ -193,14 +269,44 @@ void purple_disco_set_in_progress(Purple
  *
  * @param list The service list.
  * @return True if we're downloading it, or false if we're not.
+ *
+ * @see purple_disco_list_set_in_progress()
+ * @since TODO
  */
-gboolean purple_disco_get_in_progress(PurpleDiscoList *list);
+gboolean purple_disco_list_get_in_progress(PurpleDiscoList *list);
 
+/**
+ * Sets the disco list's protocol-specific data.
+ *
+ * This should only be called from the associated prpl.
+ *
+ * @param list The disco list.
+ * @param data The protocol data.
+ *
+ * @see purple_disco_list_get_protocol_data()
+ * @since TODO
+ */
+void purple_disco_list_set_protocol_data(PurpleDiscoList *list, gpointer data);
 
 /**
+ * Returns the disco list's protocol-specific data.
+ *
+ * This should only be called from the associated prpl.
+ *
+ * @param list The disco list.
+ * @return     The protocol data.
+ *
+ * @see purple_disco_list_set_protocol_data()
+ * @since TODO
+ */
+gpointer purple_disco_list_get_protocol_data(PurpleDiscoList *list);
+
+/**
  * Sets the UI operations structure to be used in all purple service discovery.
  *
  * @param ops The UI operations structure.
+ *
+ * @since TODO
  */
 void purple_disco_set_ui_ops(PurpleDiscoUiOps *ui_ops);
 
@@ -208,39 +314,11 @@ void purple_disco_set_ui_ops(PurpleDisco
  * Returns the service discovery UI operations structure.
  *
  * @return A filled-out PurpleDiscoUiOps structure.
+ *
+ * @since TODO
  */
 PurpleDiscoUiOps *purple_disco_get_ui_ops(void);
 
-/**
- * Register service
- * @param gc Connection
- * @param service The service that will be registered
- */
-int purple_disco_service_register(PurpleConnection *gc, PurpleDiscoService *service);
-
-/**< Set/Get the account this list belongs to. */
-void purple_disco_list_set_account(PurpleDiscoList *list, PurpleAccount *account);
-PurpleAccount* purple_disco_list_get_account(PurpleDiscoList *list);
-
-/**< The list of services. */
-GList* spurple_disco_list_get_services(PurpleDiscoList *dl);
-
-/**< Set/Get UI private data. */
-void purple_disco_list_set_ui_data(PurpleDiscoList *list, gpointer ui_data);
-gpointer purple_disco_list_get_ui_data(PurpleDiscoList *list);
-
-/** Set/Get in progress flag */ 
-void purple_disco_list_set_in_progress(PurpleDiscoList *list, gboolean in_progress);
-gboolean purple_disco_list_get_in_progress(PurpleDiscoList *list);
-
-/** Set/Get fetch counter */
-void purple_disco_list_set_fetch_count(PurpleDiscoList *list, gint fetch_count);
-gint purple_disco_list_get_fetch_count(PurpleDiscoList *list);
-
-/** Set/Get prpl private data. */
-void purple_disco_list_set_proto_data(PurpleDiscoList *list, gpointer proto_data);
-gpointer purple_disco_list_get_proto_data(PurpleDiscoList *list);
-
 #ifdef __cplusplus
 }
 #endif
============================================================
--- libpurple/protocols/jabber/disco.c	af969afb5a168212b09766f300374838de94a767
+++ libpurple/protocols/jabber/disco.c	c868471a37a915a966655d923a4345334470452d
@@ -47,6 +47,11 @@ struct _jabber_disco_info_cb_data {
 	xmlnode_set_attrib(feature, "var", x); \
 }
 
+struct jabber_disco_list_data {
+	char *server;
+	int fetch_count;
+};
+
 static void
 jabber_disco_bytestream_server_cb(JabberStream *js, xmlnode *packet, gpointer data) {
 	JabberBytestreamsStreamhost *sh = data;
@@ -570,6 +575,15 @@ void jabber_disco_info_do(JabberStream *
 	jabber_iq_send(iq);
 }
 
+static void
+jabber_disco_list_data_destroy(struct jabber_disco_list_data *data)
+{
+	g_return_if_fail(data != NULL);
+
+	g_free(data->server);
+	g_free(data);
+}
+
 static PurpleDiscoServiceCategory
 jabber_disco_category_from_string(const gchar *str)
 {
@@ -617,6 +631,7 @@ jabber_disco_service_items_cb(JabberStre
 jabber_disco_service_items_cb(JabberStream *js, xmlnode *packet, gpointer data)
 {
 	struct _disco_data *disco_data = data;
+	struct jabber_disco_list_data *list_data;
 	PurpleDiscoList *list = disco_data->list;
 	PurpleDiscoService *parent = disco_data->parent;
 	const char *parent_node = disco_data->node;
@@ -626,13 +641,17 @@ jabber_disco_service_items_cb(JabberStre
 	xmlnode *child;
 	gboolean has_items = FALSE;
 
-	purple_disco_list_set_fetch_count(list, purple_disco_list_get_fetch_count(list) - 1);
+	list_data = purple_disco_list_get_protocol_data(list);
+	--list_data->fetch_count;
 
-	if (!from || !result || !query || (strcmp(result, "result")
-			|| !purple_disco_list_get_proto_data(list))) {
-		if (!purple_disco_list_get_fetch_count(list))
-			purple_disco_set_in_progress(list, FALSE);
+	if (!from || !result || !query || strcmp(result, "result") != 0) {
+		if (list_data->fetch_count == 0) {
+			jabber_disco_list_data_destroy(list_data);
+			purple_disco_list_set_protocol_data(list, NULL);
 
+			purple_disco_list_set_in_progress(list, FALSE);
+		}
+
 		purple_disco_list_unref(list);
 		return;
 	}
@@ -647,7 +666,7 @@ jabber_disco_service_items_cb(JabberStre
 		struct _disco_data *disco_data;
 		char *full_node;
 
-		if(!(jid = xmlnode_get_attrib(child, "jid")) || !purple_disco_list_get_proto_data(list))
+		if(!(jid = xmlnode_get_attrib(child, "jid")) || !purple_disco_list_get_protocol_data(list))
 			continue;
 
 		node = xmlnode_get_attrib(child, "node");
@@ -671,7 +690,7 @@ jabber_disco_service_items_cb(JabberStre
 		disco_data->node = full_node;
 
 		has_items = TRUE;
-		purple_disco_list_set_fetch_count(list, purple_disco_list_get_fetch_count(list) + 1);
+		++list_data->fetch_count;
 		purple_disco_list_ref(list);
 		iq = jabber_iq_new_query(js, JABBER_IQ_GET, "http://jabber.org/protocol/disco#info");
 		xmlnode_set_attrib(iq->node, "to", jid);
@@ -682,8 +701,13 @@ jabber_disco_service_items_cb(JabberStre
 		jabber_iq_send(iq);
 	}
 
-	if (!purple_disco_list_get_fetch_count(list))
-		purple_disco_set_in_progress(list, FALSE);
+	if (list_data->fetch_count == 0) {
+		jabber_disco_list_data_destroy(list_data);
+		purple_disco_list_set_protocol_data(list, NULL);
+
+		purple_disco_list_set_in_progress(list, FALSE);
+	}
+
 	purple_disco_list_unref(list);
 
 	g_free(disco_data->node);
@@ -694,6 +718,7 @@ jabber_disco_service_info_cb(JabberStrea
 jabber_disco_service_info_cb(JabberStream *js, xmlnode *packet, gpointer data)
 {
 	struct _disco_data *disco_data = data;
+	struct jabber_disco_list_data *list_data;
 	PurpleDiscoList *list = disco_data->list;
 	PurpleDiscoService *parent = disco_data->parent;
 	char *node = g_strdup(disco_data->node);
@@ -705,18 +730,24 @@ jabber_disco_service_info_cb(JabberStrea
 	PurpleDiscoService *s;
 	PurpleDiscoServiceCategory cat;
 	PurpleDiscoServiceType type;
-	int flags = PURPLE_DISCO_FLAG_ADD;
+	PurpleDiscoServiceFlags flags = PURPLE_DISCO_ADD;
 
 	g_free(disco_data->node);
 	g_free(disco_data);
-	purple_disco_list_set_fetch_count(list, purple_disco_list_get_fetch_count(list) - 1);
 
-	if (!from || !result || (strcmp(result, "result") || !purple_disco_list_get_proto_data(list))
+	list_data = purple_disco_list_get_protocol_data(list);
+	--list_data->fetch_count;
+
+	if (!from || !result || strcmp(result, "result") != 0
 			|| (!(query = xmlnode_get_child(packet, "query")))
 			|| (!(ident = xmlnode_get_child(query, "identity")))) {
-		if (!purple_disco_list_get_fetch_count(list))
-			purple_disco_set_in_progress(list, FALSE);
+		if (list_data->fetch_count == 0) {
+			jabber_disco_list_data_destroy(list_data);
+			purple_disco_list_set_protocol_data(list, NULL);
 
+			purple_disco_list_set_in_progress(list, FALSE);
+		}
+
 		purple_disco_list_unref(list);
 		return;
 	}
@@ -745,10 +776,10 @@ jabber_disco_service_info_cb(JabberStrea
 			continue;
 		
 		if (!strcmp(var, "jabber:iq:register"))
-			flags |= PURPLE_DISCO_FLAG_REGISTER;
+			flags |= PURPLE_DISCO_REGISTER;
 		
 		if (!strcmp(var, "http://jabber.org/protocol/disco#items"))
-			flags |= PURPLE_DISCO_FLAG_BROWSE;
+			flags |= PURPLE_DISCO_BROWSE;
 
 		if (!strcmp(var, "http://jabber.org/protocol/muc"))
 			cat = PURPLE_DISCO_SERVICE_CAT_MUC;
@@ -767,8 +798,8 @@ jabber_disco_service_info_cb(JabberStrea
 	{
 		xmlnode *q;
 		JabberIq *iq = jabber_iq_new_query(js, JABBER_IQ_GET, "http://jabber.org/protocol/disco#items");
-			
-		purple_disco_list_set_fetch_count(list, purple_disco_list_get_fetch_count(list) + 1);
+
+		++list_data->fetch_count;
 		purple_disco_list_ref(list);
 		disco_data = g_new0(struct _disco_data, 1);
 		disco_data->list = list;
@@ -781,9 +812,13 @@ jabber_disco_service_info_cb(JabberStrea
 		jabber_iq_send(iq);
 	}
 
-	if (!purple_disco_list_get_fetch_count(list))
-		purple_disco_set_in_progress(list, FALSE);
+	if (list_data->fetch_count == 0) {
+		jabber_disco_list_data_destroy(list_data);
+		purple_disco_list_set_protocol_data(list, NULL);
 
+		purple_disco_list_set_in_progress(list, FALSE);
+	}
+
 	purple_disco_list_unref(list);
 
 	g_free(aname);
@@ -794,6 +829,7 @@ jabber_disco_server_items_cb(JabberStrea
 jabber_disco_server_items_cb(JabberStream *js, xmlnode *packet, gpointer data)
 {
 	PurpleDiscoList *list = data;
+	struct jabber_disco_list_data *list_data;
 	xmlnode *query, *child;
 	const char *from = xmlnode_get_attrib(packet, "from");
 	const char *type = xmlnode_get_attrib(packet, "type");
@@ -805,6 +841,8 @@ jabber_disco_server_items_cb(JabberStrea
 	if (strcmp(type, "result"))
 		return;
 
+	list_data = purple_disco_list_get_protocol_data(list);
+
 	query = xmlnode_get_child(packet, "query");
 
 	for(child = xmlnode_get_child(query, "item"); child;
@@ -813,14 +851,14 @@ jabber_disco_server_items_cb(JabberStrea
 		const char *jid;
 		struct _disco_data *disco_data;
 
-		if(!(jid = xmlnode_get_attrib(child, "jid")) || !purple_disco_list_get_proto_data(list))
+		if(!(jid = xmlnode_get_attrib(child, "jid")) || !purple_disco_list_get_protocol_data(list))
 			continue;
 
 		disco_data = g_new0(struct _disco_data, 1);
 		disco_data->list = list;
 
 		has_items = TRUE;
-		purple_disco_list_set_fetch_count(list, purple_disco_list_get_fetch_count(list) + 1);
+		++list_data->fetch_count;
 		purple_disco_list_ref(list);
 		iq = jabber_iq_new_query(js, JABBER_IQ_GET, "http://jabber.org/protocol/disco#info");
 		xmlnode_set_attrib(iq->node, "to", jid);
@@ -830,7 +868,7 @@ jabber_disco_server_items_cb(JabberStrea
 	}
 
 	if (!has_items)
-		purple_disco_set_in_progress(list, FALSE);
+		purple_disco_list_set_in_progress(list, FALSE);
 
 	purple_disco_list_unref(list);
 }
@@ -846,14 +884,14 @@ jabber_disco_server_info_cb(JabberStream
 		xmlnode_set_attrib(iq->node, "to", who);
 		jabber_iq_set_callback(iq, jabber_disco_server_items_cb, list);
 	
-		if (purple_disco_list_get_proto_data(list))
+		if (purple_disco_list_get_protocol_data(list))
 			jabber_iq_send(iq);
 		else
 			purple_disco_list_unref(list);
 	
 	} else {
 		purple_notify_error(NULL, _("Error"), _("Server doesn't support service discovery"), NULL); 
-		purple_disco_set_in_progress(list, FALSE);
+		purple_disco_list_set_in_progress(list, FALSE);
 		purple_disco_list_unref(list);
 	}
 }
@@ -861,19 +899,20 @@ jabber_disco_server_cb(PurpleDiscoList *
 static void
 jabber_disco_server_cb(PurpleDiscoList *list, PurpleRequestFields *fields)
 {
+	PurpleAccount *account;
+	PurpleConnection *gc;
 	JabberStream *js;
 	const char *server_name;
 
 	server_name = purple_request_fields_get_string(fields, "server");
 
-	js = purple_disco_list_get_proto_data(list);
-	if (!js) {
-		purple_debug_error("jabber", "Service discovery requested for %s "
-		                             "without proto_data", server_name);
+	account = purple_disco_list_get_account(list);
+	gc = purple_account_get_connection(account);
+	if (!gc)
 		return;
-	}
+	js = purple_connection_get_protocol_data(gc);
 
-	purple_disco_set_in_progress(list, TRUE);
+	purple_disco_list_set_in_progress(list, TRUE);
 	purple_debug_misc("jabber", "Service discovery for %s\n", server_name);
 	if (js->last_disco_server)
 		g_free(js->last_disco_server);
@@ -889,18 +928,20 @@ jabber_disco_get_list(PurpleConnection *
 	PurpleRequestFieldGroup *g;
 	PurpleRequestField *f;
 	JabberStream *js;
+	struct jabber_disco_list_data *disco_list_data;
 	const char *last_server;
-	
+
 	purple_debug_misc("disco.c", "get_list\n");
 
 	js = purple_connection_get_protocol_data(gc);
-	purple_disco_list_set_proto_data(list, js);
 
+	disco_list_data = g_new0(struct jabber_disco_list_data, 1);
+	purple_disco_list_set_protocol_data(list, disco_list_data);
+
 	last_server = js->last_disco_server;
 	if (last_server == NULL)
 		last_server = js->user->domain;
 
-
 	fields = purple_request_fields_new();
 	g = purple_request_field_group_new(NULL);
 	f = purple_request_field_string_new("server", _("Server"), 
@@ -917,24 +958,25 @@ jabber_disco_get_list(PurpleConnection *
 		NULL,
 		fields,
 		_("OK"), G_CALLBACK(jabber_disco_server_cb),
-		_("Cancel"), NULL,
+		_("Cancel"), G_CALLBACK(jabber_disco_cancel),
 		purple_connection_get_account(gc), NULL, NULL, list);
 }
 
 void
 jabber_disco_cancel(PurpleDiscoList *list)
 {
-	purple_disco_list_set_proto_data(list, NULL);
-	purple_disco_set_in_progress(list, FALSE);	
+	jabber_disco_list_data_destroy(purple_disco_list_get_protocol_data(list));
+	purple_disco_list_set_protocol_data(list, NULL);
+	purple_disco_list_set_in_progress(list, FALSE);	
 }
 
 int
 jabber_disco_service_register(PurpleConnection *gc, PurpleDiscoService *service)
 {
-	JabberStream *js = gc->proto_data;
-	
-	jabber_register_gateway(js, service->name);
+	JabberStream *js = purple_connection_get_protocol_data(gc);
 
+	jabber_register_gateway(js, purple_disco_service_get_name(service));
+
 	return 0;
 }
 
============================================================
--- pidgin/gtkdisco.c	c62f1a9fb4e639c7ea3c53b9de79881543493b4a
+++ pidgin/gtkdisco.c	8cbbb19f3b9dfdc4481ac3517fd31e97944d889e
@@ -74,9 +74,13 @@ static void register_button_cb(GtkButton
 static void register_button_cb(GtkButton *button, PidginDiscoDialog *dialog)
 {
 	struct _menu_cb_info *info = g_object_get_data(G_OBJECT(button), "disco-info");
-	PurpleConnection *gc = purple_account_get_connection(info->list->account);
+	PurpleAccount *account;
+	PurpleConnection *gc;
 
-	purple_disco_service_register(gc, info->service);
+	account = purple_disco_list_get_account(info->list);
+	gc = purple_account_get_connection(account);
+
+	purple_disco_service_register(info->service);
 }
 
 static void list_button_cb(GtkButton *button, PidginDiscoDialog *dialog)
@@ -92,25 +96,31 @@ static void list_button_cb(GtkButton *bu
 	
 	dialog->discolist = purple_disco_list_new(dialog->account, (void*) dialog);
 
-	purple_disco_get_list(gc, dialog->discolist);
+	purple_disco_get_list(dialog->discolist);
 }
 
 static void add_room_to_blist_cb(GtkButton *button, PidginDiscoDialog *dialog)
 {
 	struct _menu_cb_info *info = g_object_get_data(G_OBJECT(button), "disco-info");
+	PurpleAccount *account;
+	const char *name;
 
-	if (info) {
-		if (info->service->category == PURPLE_DISCO_SERVICE_CAT_MUC)
-			purple_blist_request_add_chat(info->list->account, NULL, NULL, info->service->name);
-		else
-			purple_blist_request_add_buddy(info->list->account, info->service->name, NULL, NULL);
-	}
+	g_return_if_fail(info != NULL);
+
+	account = purple_disco_list_get_account(info->list);
+	name = purple_disco_service_get_name(info->service);
+
+	if (purple_disco_service_get_category(info->service) == PURPLE_DISCO_SERVICE_CAT_MUC)
+		purple_blist_request_add_chat(account, NULL, NULL, name);
+	else
+		purple_blist_request_add_buddy(account, name, NULL, NULL);
 }
 
 static void
 selection_changed_cb(GtkTreeSelection *selection, PidginDiscoDialog *dialog) 
 {
 	PurpleDiscoService *service;
+	PurpleDiscoServiceFlags flags;
 	GtkTreeIter iter;
 	GValue val;
 	static struct _menu_cb_info *info;
@@ -132,8 +142,10 @@ selection_changed_cb(GtkTreeSelection *s
 		g_object_set_data(G_OBJECT(dialog->add_button), "disco-info", info);
 		g_object_set_data(G_OBJECT(dialog->register_button), "disco-info", info);
 
-		gtk_widget_set_sensitive(dialog->add_button, service->flags & PURPLE_DISCO_FLAG_ADD);
-		gtk_widget_set_sensitive(dialog->register_button, service->flags & PURPLE_DISCO_FLAG_REGISTER);
+		flags = purple_disco_service_get_flags(service);
+
+		gtk_widget_set_sensitive(dialog->add_button, flags & PURPLE_DISCO_ADD);
+		gtk_widget_set_sensitive(dialog->register_button, flags & PURPLE_DISCO_REGISTER);
 	} else {
 		gtk_widget_set_sensitive(dialog->add_button, FALSE);
 		gtk_widget_set_sensitive(dialog->register_button, FALSE);
@@ -367,8 +379,10 @@ pidgin_disco_create(PurpleDiscoList *lis
 static void
 pidgin_disco_create(PurpleDiscoList *list)
 {
-	PidginDiscoDialog *dialog = (PidginDiscoDialog *) list->ui_data;
+	PidginDiscoDialog *dialog;
 
+	dialog = purple_disco_list_get_ui_data(list);
+
 	dialog->cats = g_hash_table_new_full(NULL, NULL, NULL, (GDestroyNotify)gtk_tree_row_reference_free);
 }
 
@@ -376,14 +390,18 @@ pidgin_disco_destroy(PurpleDiscoList *li
 static void
 pidgin_disco_destroy(PurpleDiscoList *list)
 {
-	PidginDiscoDialog *dialog = (PidginDiscoDialog *) list->ui_data;
+	PidginDiscoDialog *dialog;
+	
+	dialog = purple_disco_list_get_ui_data(list);
 
 	g_hash_table_destroy(dialog->cats);
 }
 
 static void pidgin_disco_in_progress(PurpleDiscoList *list, gboolean in_progress)
 {
-	PidginDiscoDialog *dialog = (PidginDiscoDialog *) list->ui_data;
+	PidginDiscoDialog *dialog;
+	
+	dialog = purple_disco_list_get_ui_data(list);
 
 	if (!dialog)
 		return;
@@ -405,15 +423,19 @@ static void pidgin_disco_add_service(Pur
 
 static void pidgin_disco_add_service(PurpleDiscoList *list, PurpleDiscoService *service, PurpleDiscoService *parent)
 {
-	PidginDiscoDialog *dialog = (PidginDiscoDialog *) list->ui_data;
+	PidginDiscoDialog *dialog;
+	PurpleDiscoServiceCategory category;
+	PurpleDiscoServiceType type;
 	GtkTreeIter iter, parent_iter;
 	GtkTreeRowReference *rr;
 	GtkTreePath *path;
 	char *filename = NULL;
 	GdkPixbuf *pixbuf = NULL;
 
-	purple_debug_info("disco", "Add_service \"%s\"\n", service->name);
+	dialog = purple_disco_list_get_ui_data(list);
 
+	purple_debug_info("disco", "Add_service \"%s\"\n", purple_disco_service_get_name(service));
+
 	gtk_progress_bar_pulse(GTK_PROGRESS_BAR(dialog->progress));
 
 	if (parent) {
@@ -426,28 +448,31 @@ static void pidgin_disco_add_service(Pur
 	}
 
 	gtk_tree_store_append(dialog->model, &iter, (parent ? &parent_iter : NULL));
-	
-	if (service->type == PURPLE_DISCO_SERVICE_TYPE_XMPP)
+
+	category = purple_disco_service_get_category(service);
+	type = purple_disco_service_get_type(service);
+
+	if (type == PURPLE_DISCO_SERVICE_TYPE_XMPP)
 		filename = g_build_filename(DATADIR, "pixmaps", "pidgin", "protocols", "22", "jabber.png", NULL);
-	else if (service->type == PURPLE_DISCO_SERVICE_TYPE_ICQ)
+	else if (type == PURPLE_DISCO_SERVICE_TYPE_ICQ)
 		filename = g_build_filename(DATADIR, "pixmaps", "pidgin", "protocols", "22", "icq.png", NULL);
-	else if (service->type == PURPLE_DISCO_SERVICE_TYPE_YAHOO)
+	else if (type == PURPLE_DISCO_SERVICE_TYPE_YAHOO)
 		filename = g_build_filename(DATADIR, "pixmaps", "pidgin", "protocols", "22", "yahoo.png", NULL);
-	else if (service->type == PURPLE_DISCO_SERVICE_TYPE_GTALK)
+	else if (type == PURPLE_DISCO_SERVICE_TYPE_GTALK)
 		filename = g_build_filename(DATADIR, "pixmaps", "pidgin", "protocols", "22", "google-talk.png", NULL);
-	else if (service->type == PURPLE_DISCO_SERVICE_TYPE_IRC)
+	else if (type == PURPLE_DISCO_SERVICE_TYPE_IRC)
 		filename = g_build_filename(DATADIR, "pixmaps", "pidgin", "protocols", "22", "irc.png", NULL);
-	else if (service->type == PURPLE_DISCO_SERVICE_TYPE_GG)
+	else if (type == PURPLE_DISCO_SERVICE_TYPE_GG)
 		filename = g_build_filename(DATADIR, "pixmaps", "pidgin", "protocols", "22", "gadu-gadu.png", NULL);
-	else if (service->type == PURPLE_DISCO_SERVICE_TYPE_AIM)
+	else if (type == PURPLE_DISCO_SERVICE_TYPE_AIM)
 		filename = g_build_filename(DATADIR, "pixmaps", "pidgin", "protocols", "22", "aim.png", NULL);
-	else if (service->type == PURPLE_DISCO_SERVICE_TYPE_QQ)
+	else if (type == PURPLE_DISCO_SERVICE_TYPE_QQ)
 		filename = g_build_filename(DATADIR, "pixmaps", "pidgin", "protocols", "22", "qq.png", NULL);
-	else if (service->type == PURPLE_DISCO_SERVICE_TYPE_MSN)
+	else if (type == PURPLE_DISCO_SERVICE_TYPE_MSN)
 		filename = g_build_filename(DATADIR, "pixmaps", "pidgin", "protocols", "22", "msn.png", NULL);
-	else if (service->type == PURPLE_DISCO_SERVICE_TYPE_USER)
+	else if (type == PURPLE_DISCO_SERVICE_TYPE_USER)
 		filename = g_build_filename(DATADIR, "pixmaps", "pidgin", "status", "22", "person.png", NULL);
-	else if (service->category == PURPLE_DISCO_SERVICE_CAT_MUC)
+	else if (category == PURPLE_DISCO_SERVICE_CAT_MUC)
 		filename = g_build_filename(DATADIR, "pixmaps", "pidgin", "status", "22", "chat.png", NULL);
 
 	if (filename) {
@@ -457,8 +482,8 @@ static void pidgin_disco_add_service(Pur
 
 	gtk_tree_store_set(dialog->model, &iter,
 			PIXBUF_COLUMN, pixbuf,
-			NAME_COLUMN, service->name,
-			DESCRIPTION_COLUMN, service->description,
+			NAME_COLUMN, purple_disco_service_get_name(service),
+			DESCRIPTION_COLUMN, purple_disco_service_get_description(service),
 			SERVICE_COLUMN, service,
 			-1);
 


More information about the Commits mailing list