cpw.qulogic.msnp16: 0dd72b39: Allow saving extended capabilities and e...

qulogic at pidgin.im qulogic at pidgin.im
Mon Dec 14 02:27:01 EST 2009


-----------------------------------------------------------------
Revision: 0dd72b39dc215f9563f1150d6e990b1e7d6f0e04
Ancestor: 5ea4e913663e67ac8f47d220af8939e542c269d6
Author: qulogic at pidgin.im
Date: 2009-12-09T21:08:24
Branch: im.pidgin.cpw.qulogic.msnp16
URL: http://d.pidgin.im/viewmtn/revision/info/0dd72b39dc215f9563f1150d6e990b1e7d6f0e04

Modified files:
        libpurple/protocols/msn/user.c
        libpurple/protocols/msn/user.h

ChangeLog: 

Allow saving extended capabilities and endpoint-specific data in an MSN
user structure.

-------------- next part --------------
============================================================
--- libpurple/protocols/msn/user.c	2ddbc85af8b002a2f1e56eb917f2fbb162e56c1b
+++ libpurple/protocols/msn/user.c	11c641bfbf2155f6e83a3b4c08ccd91df4e05934
@@ -39,6 +39,8 @@ msn_user_new(MsnUserList *userlist, cons
 	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 @@ msn_user_destroy(MsnUser *user)
 {
 	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
 }
 
 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
 }
 
 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 @@ msn_user_get_clientid(const MsnUser *use
 	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 @@ msn_user_get_invite_message(const MsnUse
 	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;
+}
+
+
============================================================
--- libpurple/protocols/msn/user.h	9eeb35d1e130ada46705650bb6f4199d6f68ae17
+++ libpurple/protocols/msn/user.h	a4cd55aed78ff3e069cf8c018b29fa0537ae642c
@@ -72,6 +72,7 @@ struct _MsnUser
 	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 @@ struct _MsnUser
 	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 @@ struct _MsnUser
 	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, con
 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
 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(co
 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 MsnUse
 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_unset_op(MsnUser *user, in
 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);
+
 /*@}*/
 
 


More information about the Commits mailing list