changeset 31489:ff2a8a839dbd

Extensions to the user profile.
author andrew.victor@mxit.com
date Tue, 22 Mar 2011 21:56:30 +0000
parents df716c39f698
children 671113b90ff6
files libpurple/protocols/mxit/actions.c libpurple/protocols/mxit/mxit.c libpurple/protocols/mxit/profile.c libpurple/protocols/mxit/profile.h libpurple/protocols/mxit/protocol.c libpurple/protocols/mxit/protocol.h
diffstat 6 files changed, 146 insertions(+), 64 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/mxit/actions.c	Mon Mar 21 21:07:47 2011 +0000
+++ b/libpurple/protocols/mxit/actions.c	Tue Mar 22 21:56:30 2011 +0000
@@ -186,6 +186,43 @@
 		g_string_append( attributes, attrib );
 		acount++;
 
+#if 0
+		/* update about me */
+		name = purple_request_fields_get_string( fields, "aboutme" );
+		if ( !name )
+			profile->aboutme[0] = '\0';
+		else
+			g_strlcpy( profile->aboutme, name, sizeof( profile->aboutme ) );
+		g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%s", CP_PROFILE_ABOUTME, CP_PROFILE_TYPE_UTF8, profile->aboutme );
+		g_string_append( attributes, attrib );
+		acount++;
+
+		/* update where am i */
+		name = purple_request_fields_get_string( fields, "whereami" );
+		if ( !name)
+			profile->whereami[0] = '\0';
+		else
+			g_strlcpy( profile->whereami, name, sizeof( profile->whereami ) );
+		g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%s", CP_PROFILE_WHEREAMI, CP_PROFILE_TYPE_UTF8, profile->whereami );
+		g_string_append( attributes, attrib );
+		acount++;
+#endif
+
+		/* update flags */
+		field = purple_request_fields_get_field( fields, "searchable" );
+		if ( purple_request_field_bool_get_value( field ) )		/* is searchable -> clear not-searchable flag */
+			profile->flags &= ~CP_PROF_NOT_SEARCHABLE;
+		else
+			profile->flags |= CP_PROF_NOT_SEARCHABLE;
+		field = purple_request_fields_get_field( fields, "suggestable" );
+		if ( purple_request_field_bool_get_value( field ) )		/* is suggestable -> clear not-suggestable flag */
+			profile->flags &= ~CP_PROF_NOT_SUGGESTABLE;
+		else
+			profile->flags |= CP_PROF_NOT_SUGGESTABLE;
+		g_snprintf( attrib, sizeof( attrib ), "\01%s\01%i\01%i", CP_PROFILE_FLAGS, CP_PROFILE_TYPE_LONG, profile->flags);
+		g_string_append( attributes, attrib );
+		acount++;
+
 		/* send the profile update to MXit */
 		mxit_send_extprofile_update( session, session->encpwd, acount, attributes->str );
 		g_string_free( attributes, TRUE );
@@ -209,7 +246,6 @@
 	struct MXitProfile*			profile	= session->profile;
 
 	PurpleRequestFields*		fields	= NULL;
-	PurpleRequestFieldGroup*	group	= NULL;
 	PurpleRequestField*			field	= NULL;
 
 	purple_debug_info( MXIT_PLUGIN_ID, "mxit_cb_action_profile\n" );
@@ -222,65 +258,92 @@
 	}
 
 	fields = purple_request_fields_new();
-	group = purple_request_field_group_new( NULL );
-	purple_request_fields_add_group( fields, group );
+
+	/* Security information - PIN, etc */
+	{
+		PurpleRequestFieldGroup* security_group = purple_request_field_group_new( "PIN" );
 
-#if	0
-	/* UID (read-only) */
-	if ( session->uid ) {
-		field = purple_request_field_string_new( "mxitid", _( "Your UID" ), session->uid, FALSE );
-		purple_request_field_string_set_editable( field, FALSE );
-		purple_request_field_group_add_field( group, field );
+		/* pin */
+		field = purple_request_field_string_new( "pin", _( "PIN" ), session->acc->password, FALSE );
+		purple_request_field_string_set_masked( field, TRUE );
+		purple_request_field_group_add_field( security_group, field );
+
+		field = purple_request_field_string_new( "pin2", _( "Verify PIN" ), session->acc->password, FALSE );
+		purple_request_field_string_set_masked( field, TRUE );
+		purple_request_field_group_add_field( security_group, field );
+
+		purple_request_fields_add_group( fields, security_group );
 	}
-#endif
 
-	/* pin */
-	field = purple_request_field_string_new( "pin", _( "PIN" ), session->acc->password, FALSE );
-	purple_request_field_string_set_masked( field, TRUE );
-	purple_request_field_group_add_field( group, field );
-	field = purple_request_field_string_new( "pin2", _( "Verify PIN" ), session->acc->password, FALSE );
-	purple_request_field_string_set_masked( field, TRUE );
-	purple_request_field_group_add_field( group, field );
+	/* Public information - what other users can see */
+	{
+		PurpleRequestFieldGroup* public_group = purple_request_field_group_new( "Public information" );
+
+		/* display name */
+		field = purple_request_field_string_new( "name", _( "Display Name" ), profile->nickname, FALSE );
+		purple_request_field_group_add_field( public_group, field );
 
-	/* display name */
-	field = purple_request_field_string_new( "name", _( "Display Name" ), profile->nickname, FALSE );
-	purple_request_field_group_add_field( group, field );
+		/* birthday */
+		field = purple_request_field_string_new( "bday", _( "Birthday" ), profile->birthday, FALSE );
+		purple_request_field_group_add_field( public_group, field );
+		if ( profile->flags & CP_PROF_DOBLOCKED )
+			purple_request_field_string_set_editable( field, FALSE );
 
-	/* birthday */
-	field = purple_request_field_string_new( "bday", _( "Birthday" ), profile->birthday, FALSE );
-	purple_request_field_group_add_field( group, field );
-	if ( profile->flags & CP_PROF_DOBLOCKED )
-		purple_request_field_string_set_editable( field, FALSE );
+		/* gender */
+		field = purple_request_field_choice_new( "male", _( "Gender" ), ( profile->male ) ? 1 : 0 );
+		purple_request_field_choice_add( field, _( "Female" ) );		/* 0 */
+		purple_request_field_choice_add( field, _( "Male" ) );			/* 1 */
+		purple_request_field_group_add_field( public_group, field );
+
+		/* first name */
+		field = purple_request_field_string_new( "firstname", _( "First Name" ), profile->firstname, FALSE );
+		purple_request_field_group_add_field( public_group, field );
 
-	/* gender */
-	field = purple_request_field_choice_new( "male", _( "Gender" ), ( profile->male ) ? 1 : 0 );
-	purple_request_field_choice_add( field, _( "Female" ) );		/* 0 */
-	purple_request_field_choice_add( field, _( "Male" ) );			/* 1 */
-	purple_request_field_group_add_field( group, field );
+		/* last name */
+		field = purple_request_field_string_new( "lastname", _( "Last Name" ), profile->lastname, FALSE );
+		purple_request_field_group_add_field( public_group, field );
+
+		/* about me */
+		field = purple_request_field_string_new( "aboutme", _( "About Me" ), profile->aboutme, FALSE);
+		purple_request_field_group_add_field( public_group, field );
 
-	/* hidden */
-	field = purple_request_field_bool_new( "hidden", _( "Hide my number" ), profile->hidden );
-	purple_request_field_group_add_field( group, field );
+		/* where I live */
+		field = purple_request_field_string_new( "whereami", _( "Where I Live" ), profile->whereami, FALSE);
+		purple_request_field_group_add_field( public_group, field );
+
+		purple_request_fields_add_group( fields, public_group );
+	}
 
-	/* title */
-	field = purple_request_field_string_new( "title", _( "Title" ), profile->title, FALSE );
-	purple_request_field_group_add_field( group, field );
+	/* Private information - what only MXit can see */
+	{
+		PurpleRequestFieldGroup* private_group = purple_request_field_group_new( "Private information" );
+
+		/* title */
+		field = purple_request_field_string_new( "title", _( "Title" ), profile->title, FALSE );
+		purple_request_field_group_add_field( private_group, field );
 
-	/* first name */
-	field = purple_request_field_string_new( "firstname", _( "First Name" ), profile->firstname, FALSE );
-	purple_request_field_group_add_field( group, field );
+		/* email */
+		field = purple_request_field_string_new( "email", _( "Email" ), profile->email, FALSE );
+		purple_request_field_group_add_field( private_group, field );
 
-	/* last name */
-	field = purple_request_field_string_new( "lastname", _( "Last Name" ), profile->lastname, FALSE );
-	purple_request_field_group_add_field( group, field );
+		/* mobile number */
+		field = purple_request_field_string_new( "mobilenumber", _( "Mobile Number" ), profile->mobilenr, FALSE );
+		purple_request_field_group_add_field( private_group, field );
 
-	/* email */
-	field = purple_request_field_string_new( "email", _( "Email" ), profile->email, FALSE );
-	purple_request_field_group_add_field( group, field );
+		/* hidden number */
+		field = purple_request_field_bool_new( "hidden", _( "Hide my number" ), profile->hidden );
+		purple_request_field_group_add_field( private_group, field );
 
-	/* mobile number */
-	field = purple_request_field_string_new( "mobilenumber", _( "Mobile Number" ), profile->mobilenr, FALSE );
-	purple_request_field_group_add_field( group, field );
+		/* is searchable */
+		field = purple_request_field_bool_new( "searchable", _( "Can be searched" ), ( ( profile->flags & CP_PROF_NOT_SEARCHABLE ) == 0) );
+		purple_request_field_group_add_field( private_group, field );
+
+		/* is suggestable */
+		field = purple_request_field_bool_new( "suggestable", _( "Can be suggested" ), ( ( profile->flags & CP_PROF_NOT_SUGGESTABLE ) == 0 ) );
+		purple_request_field_group_add_field( private_group, field );
+
+		purple_request_fields_add_group( fields, private_group );
+	}
 
 	/* (reference: "libpurple/request.h") */
 	purple_request_fields( gc, _( "Profile" ), _( "Update your Profile" ), _( "Here you can update your MXit profile" ), fields, _( "Set" ),
@@ -314,7 +377,7 @@
 {
 	char	version[256];
 
-	g_snprintf( version, sizeof( version ), 
+	g_snprintf( version, sizeof( version ),
 											"MXit Client Protocol v%i.%i\n\n"
 											"Author:\nPieter Loubser\n\n"
 											"Contributors:\nAndrew Victor\n\n"
--- a/libpurple/protocols/mxit/mxit.c	Mon Mar 21 21:07:47 2011 +0000
+++ b/libpurple/protocols/mxit/mxit.c	Tue Mar 22 21:56:30 2011 +0000
@@ -565,7 +565,7 @@
 	struct MXitSession*		session			= (struct MXitSession*) gc->proto_data;
 	const char*				profilelist[]	= { CP_PROFILE_BIRTHDATE, CP_PROFILE_GENDER, CP_PROFILE_FULLNAME,
 												CP_PROFILE_FIRSTNAME, CP_PROFILE_LASTNAME, CP_PROFILE_REGCOUNTRY, CP_PROFILE_LASTSEEN,
-												CP_PROFILE_STATUS, CP_PROFILE_AVATAR };
+												CP_PROFILE_STATUS, CP_PROFILE_AVATAR, CP_PROFILE_WHEREAMI, CP_PROFILE_ABOUTME };
 
 	purple_debug_info( MXIT_PLUGIN_ID, "mxit_get_info: '%s'\n", who );
 
--- a/libpurple/protocols/mxit/profile.c	Mon Mar 21 21:07:47 2011 +0000
+++ b/libpurple/protocols/mxit/profile.c	Tue Mar 22 21:56:30 2011 +0000
@@ -146,6 +146,11 @@
 	purple_notify_user_info_add_pair( info, _( "Last Name" ), profile->lastname );
 	purple_notify_user_info_add_pair( info, _( "Country" ), profile->regcountry );
 
+	if ( strlen( profile->aboutme ) > 0 )
+		purple_notify_user_info_add_pair( info, _( "About Me" ), profile->aboutme );
+	if ( strlen( profile->whereami ) > 0 )
+		purple_notify_user_info_add_pair( info, _( "Where I Live" ), profile->whereami );
+
 	purple_notify_user_info_add_section_break( info );
 
 	if ( contact ) {
--- a/libpurple/protocols/mxit/profile.h	Mon Mar 21 21:07:47 2011 +0000
+++ b/libpurple/protocols/mxit/profile.h	Tue Mar 22 21:56:30 2011 +0000
@@ -32,21 +32,23 @@
 struct MXitProfile {
 	/* required */
 	char		loginname[64];						/* name user uses to log into MXit with (aka 'mxitid') */
-	char		nickname[64];						/* user's own display name (aka 'nickname', aka 'fullname', aka 'alias') in MXit */
+	char		nickname[51];						/* user's own display name (aka 'nickname', aka 'fullname', aka 'alias') in MXit */
 	char		birthday[16];						/* user's birthday "YYYY-MM-DD" */
 	gboolean	male;								/* true if the user's gender is male (otherwise female) */
 	char		pin[16];							/* user's password */
 
 	/* optional */
-	char		title[32];							/* user's title */
-	char		firstname[64];						/* user's first name */
-	char		lastname[64];						/* user's last name (aka 'surname') */
+	char		title[21];							/* user's title */
+	char		firstname[51];						/* user's first name */
+	char		lastname[51];						/* user's last name (aka 'surname') */
 	char		email[64];							/* user's email address */
 	char		mobilenr[21];						/* user's mobile number */
 	char		regcountry[3];						/* user's registered country code */
-	gint64		flags;								/* user's profile flags */
+	char		whereami[51];						/* where am I / where I live */
+	char		aboutme[513];						/* about me */
+
+	int			flags;								/* user's profile flags */
 	gint64		lastonline;							/* user's last-online timestamp */
-
 	gboolean	hidden;								/* set if the user's msisdn should remain hidden */
 };
 
--- a/libpurple/protocols/mxit/protocol.c	Mon Mar 21 21:07:47 2011 +0000
+++ b/libpurple/protocols/mxit/protocol.c	Tue Mar 22 21:56:30 2011 +0000
@@ -844,7 +844,7 @@
  *  @param session		The MXit session object
  *  @param password		The new password to be used for logging in (optional)
  *	@param nr_attrib	The number of attributes
- *	@param attributes	String containing the attributes and settings seperated by '0x01'
+ *	@param attributes	String containing the attribute-name, attribute-type and value (seperated by '\01')
  */
 void mxit_send_extprofile_update( struct MXitSession* session, const char* password, unsigned int nr_attrib, const char* attributes )
 {
@@ -853,7 +853,7 @@
 	int				datalen;
 	unsigned int	i;
 
-	parts = g_strsplit( attributes, "\01", ( MXIT_MAX_ATTRIBS * 3 ) );
+	parts = g_strsplit( attributes, "\01", 1 + ( nr_attrib * 3 ) );
 
 	/* convert the packet to a byte stream */
 	datalen = snprintf( data, sizeof( data ),
@@ -1442,7 +1442,7 @@
 	const char*		statusmsg;
 	const char*		profilelist[] = { CP_PROFILE_BIRTHDATE, CP_PROFILE_GENDER, CP_PROFILE_HIDENUMBER, CP_PROFILE_FULLNAME,
 									CP_PROFILE_TITLE, CP_PROFILE_FIRSTNAME, CP_PROFILE_LASTNAME, CP_PROFILE_EMAIL,
-									CP_PROFILE_MOBILENR, CP_PROFILE_FLAGS };
+									CP_PROFILE_MOBILENR, CP_PROFILE_WHEREAMI, CP_PROFILE_ABOUTME, CP_PROFILE_FLAGS };
 
 	purple_account_set_int( session->acc, MXIT_CONFIG_STATE, MXIT_STATE_LOGIN );
 
@@ -1851,6 +1851,14 @@
 			/* last seen online */
 			profile->lastonline = strtoll( fvalue, NULL, 10 );
 		}
+		else if ( strcmp( CP_PROFILE_WHEREAMI, fname ) == 0 ) {
+			/* where am I */
+			g_strlcpy( profile->whereami, fvalue, sizeof( profile->whereami ) );
+		}
+		else if ( strcmp( CP_PROFILE_ABOUTME, fname ) == 0) {
+			/* about me */
+			g_strlcpy( profile->aboutme, fvalue, sizeof( profile->aboutme ) );
+		}
 		else {
 			/* invalid profile attribute */
 			purple_debug_error( MXIT_PLUGIN_ID, "Invalid profile attribute received '%s' \n", fname );
--- a/libpurple/protocols/mxit/protocol.h	Mon Mar 21 21:07:47 2011 +0000
+++ b/libpurple/protocols/mxit/protocol.h	Tue Mar 22 21:56:30 2011 +0000
@@ -110,7 +110,6 @@
 /* Client settings */
 #define		MAX_QUEUE_SIZE			( 1 << 5 )				/* tx queue size (32 packets) */
 #define		MXIT_POPUP_WIN_NAME		"MXit Notification"		/* popup window name */
-#define		MXIT_MAX_ATTRIBS		10						/* maximum profile attributes supported */
 #define		MXIT_DEFAULT_LOCALE		"en"					/* default locale setting */
 #define		MXIT_DEFAULT_LOC		"planetpurple"			/* the default location for registration */
 
@@ -194,14 +193,19 @@
 #define		CP_PROFILE_REGCOUNTRY	"registeredcountry"		/* Registered Country Code (UTF8 String) */
 #define		CP_PROFILE_FLAGS		"flags"					/* Profile flags (Bitset) */
 #define		CP_PROFILE_LASTSEEN		"lastseen"				/* Last-Online timestamp */
+#define		CP_PROFILE_WHEREAMI		"whereami"				/* Where am I / Where I live */
+#define		CP_PROFILE_ABOUTME		"aboutme"				/* About me */
 
 /* extended profile field types */
-#define		CP_PROFILE_TYPE_BOOL	0x02					/* boolean profile attribute type */
-#define		CP_PROFILE_TYPE_INT		0x05					/* integer profile attribute type */
-#define		CP_PROFILE_TYPE_UTF8	0x0A					/* UTF8 string profile attribute type */
-#define		CP_PROFILE_TYPE_DATE	0x0B					/* date-time profile attribute type */
+#define		CP_PROFILE_TYPE_BOOL	0x02					/* boolean (0 or 1) */
+#define		CP_PROFILE_TYPE_INT		0x05					/* integer (32-bit) */
+#define		CP_PROFILE_TYPE_LONG	0x06					/* long (64-bit) */
+#define		CP_PROFILE_TYPE_UTF8	0x0A					/* UTF8 string */
+#define		CP_PROFILE_TYPE_DATE	0x0B					/* date-time (ISO 8601 format) */
 
 /* profile flags */
+#define		CP_PROF_NOT_SEARCHABLE	0x02					/* user cannot be searched for */
+#define		CP_PROF_NOT_SUGGESTABLE	0x08					/* user cannot be suggested as friend */
 #define		CP_PROF_DOBLOCKED		0x40					/* date-of-birth cannot be changed */
 
 /* suggestion types */