changeset 31097:88c48bcb5455

Allow saving extended capabilities and endpoint-specific data in an MSN user structure.
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Wed, 09 Dec 2009 21:08:24 +0000
parents ed838ad00173
children 4cdea258b143
files libpurple/protocols/msn/user.c libpurple/protocols/msn/user.h
diffstat 2 files changed, 131 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/msn/user.c	Wed Dec 02 02:46:59 2009 +0000
+++ b/libpurple/protocols/msn/user.c	Wed Dec 09 21:08:24 2009 +0000
@@ -39,6 +39,8 @@
 	msn_user_set_passport(user, passport);
 	msn_user_set_friendly_name(user, friendly_name);
 
+	user->endpoints = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
+
 	return user;
 }
 
@@ -48,6 +50,9 @@
 {
 	g_return_if_fail(user != NULL);
 
+	if (user->endpoints != NULL)
+		g_hash_table_destroy(user->endpoints);
+
 	if (user->clientcaps != NULL)
 		g_hash_table_destroy(user->clientcaps);
 
@@ -229,6 +234,27 @@
 }
 
 void
+msn_user_set_endpoint_data(MsnUser *user, char *endpoint, MsnUserEndpoint *data)
+{
+	MsnUserEndpoint *new;
+	g_return_if_fail(user != NULL);
+
+	if (data == NULL) {
+		g_hash_table_remove(user->endpoints, endpoint);
+		return;
+	}
+
+	new = g_hash_table_lookup(user->endpoints, endpoint);
+	if (!new) {
+		new = g_new0(MsnUserEndpoint, 1);
+		g_hash_table_insert(user->endpoints, g_strdup(endpoint), new);
+	}
+
+	new->clientid = data->clientid;
+	new->extcaps = data->extcaps;
+}
+
+void
 msn_user_set_op(MsnUser *user, int list_op)
 {
 	g_return_if_fail(user != NULL);
@@ -397,6 +423,14 @@
 }
 
 void
+msn_user_set_extcaps(MsnUser *user, guint extcaps)
+{
+	g_return_if_fail(user != NULL);
+
+	user->extcaps = extcaps;
+}
+
+void
 msn_user_set_network(MsnUser *user, MsnNetwork network)
 {
 	g_return_if_fail(user != NULL);
@@ -487,6 +521,22 @@
 	return user->clientid;
 }
 
+guint
+msn_user_get_extcaps(const MsnUser *user)
+{
+	g_return_val_if_fail(user != NULL, 0);
+
+	return user->extcaps;
+}
+
+MsnUserEndpoint *
+msn_user_get_endpoint_data(MsnUser *user, char *endpoint)
+{
+	g_return_val_if_fail(user != NULL, NULL);
+
+	return g_hash_table_lookup(user->endpoints, endpoint);
+}
+
 MsnObject *
 msn_user_get_object(const MsnUser *user)
 {
@@ -511,3 +561,22 @@
 	return user->invite_message;
 }
 
+gboolean
+msn_user_is_capable(MsnUser *user, char *endpoint, guint capability, guint extcap)
+{
+	g_return_val_if_fail(user != NULL, FALSE);
+
+	if (endpoint != NULL) {
+		MsnUserEndpoint *ep = g_hash_table_lookup(user->endpoints, endpoint);
+		if (ep != NULL)
+			return (ep->clientid & capability) == capability
+			    && (ep->extcaps & extcap) == extcap;
+		else
+			return FALSE;
+	}
+
+	return (user->clientid & capability) == capability
+	    && (user->extcaps & extcap) == extcap;
+}
+
+
--- a/libpurple/protocols/msn/user.h	Wed Dec 02 02:46:59 2009 +0000
+++ b/libpurple/protocols/msn/user.h	Wed Dec 09 21:08:24 2009 +0000
@@ -72,6 +72,7 @@
 	char *friendly_name;    /**< The friendly name.             */
 
 	char * uid;				/*< User Id							*/
+	GHashTable *endpoints;	/*< Endpoint-specific data          */
 
 	const char *status;     /**< The state of the user.         */
 	char *statusline;       /**< The state of the user.         */
@@ -98,6 +99,7 @@
 	GHashTable *clientcaps; /**< The client's capabilities.     */
 
 	guint clientid;         /**< The client's ID                */
+	guint extcaps;			/**< The client's extended capabilities */
 
 	MsnNetwork networkid;   /**< The user's network             */
 
@@ -109,6 +111,15 @@
 	char *invite_message;   /**< Invite message of user request */
 };
 
+/**
+ * A specific user endpoint.
+ */
+typedef struct MsnUserEndpoint {
+	guint clientid;         /**< The client's ID                   */
+	guint extcaps;			/**< The client's extended capabilites */
+
+} MsnUserEndpoint;
+
 /**************************************************************************
  ** @name User API                                                        *
  **************************************************************************/
@@ -253,6 +264,16 @@
 void msn_user_set_uid(MsnUser *user, const char *uid);
 
 /**
+ * Sets endpoint data for a user.
+ *
+ * @param user     The user.
+ * @param endpoint The endpoint.
+ * @param data     The endpoint data.
+ */
+void
+msn_user_set_endpoint_data(MsnUser *user, char *endpoint, MsnUserEndpoint *data);
+
+/**
  * Sets the client id for a user.
  *
  * @param user     The user.
@@ -261,6 +282,14 @@
 void msn_user_set_clientid(MsnUser *user, guint clientid);
 
 /**
+ * Sets the client id for a user.
+ *
+ * @param user     The user.
+ * @param extcaps  The client's extended capabilities.
+ */
+void msn_user_set_extcaps(MsnUser *user, guint extcaps);
+
+/**
  * Sets the network id for a user.
  *
  * @param user    The user.
@@ -347,6 +376,17 @@
 const char *msn_user_get_mobile_phone(const MsnUser *user);
 
 /**
+ * Gets endpoint data for a user.
+ *
+ * @param user     The user.
+ * @param endpoint The endpoint.
+ *
+ * @return The user's endpoint data.
+ */
+MsnUserEndpoint *
+msn_user_get_endpoint_data(MsnUser *user, char *endpoint);
+
+/**
  * Returns the client id for a user.
  *
  * @param user    The user.
@@ -356,6 +396,15 @@
 guint msn_user_get_clientid(const MsnUser *user);
 
 /**
+ * Returns the extended capabilities for a user.
+ *
+ * @param user    The user.
+ *
+ * @return The user's extended capabilities.
+ */
+guint msn_user_get_extcaps(const MsnUser *user);
+
+/**
  * Returns the network id for a user.
  *
  * @param user    The user.
@@ -406,6 +455,19 @@
 void msn_user_set_op(MsnUser *user, int list_op);
 void msn_user_unset_op(MsnUser *user, int list_op);
 
+/**
+ * Checks whether a user is capable of some task.
+ *
+ * @param user       The user.
+ * @param endpoint   The endpoint. Can be @NULL to check overall capabilities.
+ * @param capability The capability (including client version).
+ * @param extcap     The extended capability.
+ *
+ * @return Whether the user supports the capability.
+ */
+gboolean
+msn_user_is_capable(MsnUser *user, char *endpoint, guint capability, guint extcap);
+
 /*@}*/