changeset 20442:a1c6206f0205

Make the MsnUser type an enum so we have fewer magic numbers
author Stu Tomlinson <stu@nosnilmot.com>
date Sun, 27 May 2007 21:13:37 +0000
parents 9053156d016a
children 45e3739de7fd
files libpurple/protocols/msn/contact.c libpurple/protocols/msn/notification.c libpurple/protocols/msn/user.c libpurple/protocols/msn/user.h
diffstat 4 files changed, 25 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/msn/contact.c	Sun May 27 18:02:52 2007 +0000
+++ b/libpurple/protocols/msn/contact.c	Sun May 27 21:13:37 2007 +0000
@@ -105,16 +105,16 @@
 msn_get_user_type(char * type)
 {
 	if(!strcmp(type,"Regular")){
-		return 1;
+		return MSN_USER_TYPE_PASSPORT;
 	}
 	if(!strcmp(type,"Live")){
-		return 1;
+		return MSN_USER_TYPE_PASSPORT;
 	}
 	if(!strcmp(type,"LivePending")){
-		return 1;
+		return MSN_USER_TYPE_PASSPORT;
 	}
 
-	return 0;
+	return MSN_USER_TYPE_UNKNOWN;
 }
 
 /*parse contact list*/
--- a/libpurple/protocols/msn/notification.c	Sun May 27 18:02:52 2007 +0000
+++ b/libpurple/protocols/msn/notification.c	Sun May 27 21:13:37 2007 +0000
@@ -40,7 +40,7 @@
 
 static void msn_notification_fqy_yahoo(MsnSession *session, const char *passport);
 static void msn_notification_post_adl(MsnCmdProc *cmdproc, const char *payload, int payload_len);
-static void msn_add_contact_xml(xmlnode *mlNode, const char *passport, int list_op, int type);
+static void msn_add_contact_xml(xmlnode *mlNode, const char *passport, int list_op, MsnUserType type);
 
 /**************************************************************************
  * Main
@@ -586,7 +586,7 @@
  **************************************************************************/
 /* add contact to xmlnode */
 static void 
-msn_add_contact_xml(xmlnode *mlNode,const char *passport,int list_op,int type)
+msn_add_contact_xml(xmlnode *mlNode,const char *passport,int list_op, MsnUserType type)
 {
 	xmlnode *d_node,*c_node;
 	char **tokens;
@@ -633,10 +633,10 @@
 	xmlnode_set_attrib(c_node,"t",type_str);
 #else
 	if(g_strrstr(domain,"yahoo") != NULL){
-		type_str = g_strdup_printf("32");
+		type_str = g_strdup_printf("%d", MSN_USER_TYPE_YAHOO);
 	}else{
 		/*passport*/
-		type_str = g_strdup_printf("1");
+		type_str = g_strdup_printf("%d", MSN_USER_TYPE_PASSPORT);
 	}
 	/*mobile*/
 	//type_str = g_strdup_printf("4");
@@ -1864,7 +1864,7 @@
 	adl_node = xmlnode_new("ml");
 	adl_node->child = NULL;
 
-	msn_add_contact_xml(adl_node,who,1,1);
+	msn_add_contact_xml(adl_node,who,1,MSN_USER_TYPE_PASSPORT);
 
 	payload = xmlnode_to_str(adl_node,&payload_len);
 	xmlnode_free(adl_node);
@@ -1894,7 +1894,7 @@
 	rml_node = xmlnode_new("ml");
 	rml_node->child = NULL;
 
-	msn_add_contact_xml(rml_node,who,1,1);
+	msn_add_contact_xml(rml_node,who,1,MSN_USER_TYPE_PASSPORT);
 
 	payload = xmlnode_to_str(rml_node,&payload_len);
 	xmlnode_free(rml_node);
--- a/libpurple/protocols/msn/user.c	Sun May 27 18:02:52 2007 +0000
+++ b/libpurple/protocols/msn/user.c	Sun May 27 21:13:37 2007 +0000
@@ -202,7 +202,7 @@
 }
 
 void
-msn_user_set_type(MsnUser *user, int type)
+msn_user_set_type(MsnUser *user, MsnUserType type)
 {
 	g_return_if_fail(user != NULL);
 
--- a/libpurple/protocols/msn/user.h	Sun May 27 18:02:52 2007 +0000
+++ b/libpurple/protocols/msn/user.h	Sun May 27 21:13:37 2007 +0000
@@ -31,6 +31,17 @@
 
 #include "userlist.h"
 
+typedef enum
+{
+	MSN_USER_TYPE_UNKNOWN  = 0x00,
+	MSN_USER_TYPE_PASSPORT = 0x01,
+	MSN_USER_TYPE_UNKNOWN1 = 0x02,
+	MSN_USER_TYPE_MOBILE   = 0x04,
+	MSN_USER_TYPE_UNKNOWN2 = 0x08,
+	MSN_USER_TYPE_UNKNOWN3 = 0x10,
+	MSN_USER_TYPE_YAHOO    = 0x20
+} MsnUserType;
+
 /**
  * A user.
  */
@@ -70,8 +81,8 @@
 
 	GHashTable *clientcaps; /**< The client's capabilities.     */
 
-	int type;
-	int list_op;
+	MsnUserType type;       /**< The user type                  */
+	int list_op;            /**< Which lists the user is in     */
 };
 
 /**************************************************************************/
@@ -205,7 +216,7 @@
 void msn_user_set_work_phone(MsnUser *user, const char *number);
 
 void msn_user_set_uid(MsnUser *user, const char *uid);
-void msn_user_set_type(MsnUser *user,int type);
+void msn_user_set_type(MsnUser *user, MsnUserType type);
 
 /**
  * Sets the mobile phone number for a user.