pidgin: f6cdf877: Implement [gs]et_public_alias in MSN.

qulogic at pidgin.im qulogic at pidgin.im
Mon May 10 19:15:49 EDT 2010


-----------------------------------------------------------------
Revision: f6cdf8776559775f9a4a72563e69741e139518bd
Ancestor: d6897a8a61faae4393d8add4b7812674a6534684
Author: qulogic at pidgin.im
Date: 2010-05-10T23:14:05
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/f6cdf8776559775f9a4a72563e69741e139518bd

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

ChangeLog: 

Implement [gs]et_public_alias in MSN.

-------------- next part --------------
============================================================
--- libpurple/protocols/msn/msn.c	55b4b51e7c7471ff7971e6b0bf4b17097194c9b5
+++ libpurple/protocols/msn/msn.c	b1aa68e61aaf53380507593a1729d1c7f61f11fa
@@ -195,42 +195,167 @@ msn_cmd_nudge(PurpleConversation *conv, 
 	return PURPLE_CMD_RET_OK;
 }
 
+struct public_alias_closure
+{
+	PurpleAccount *account;
+	gpointer success_cb;
+	gpointer failure_cb;
+};
+
+static gboolean
+set_public_alias_length_error(gpointer data)
+{
+	struct public_alias_closure *closure = data;
+	PurpleSetPublicAliasFailureCallback failure_cb = closure->failure_cb;
+
+	failure_cb(closure->account, _("Your new MSN friendly name is too long."));
+	g_free(closure);
+
+	return FALSE;
+}
+
+static void
+prp_success_cb(MsnCmdProc *cmdproc, MsnCommand *cmd)
+{
+	const char *type, *friendlyname;
+	struct public_alias_closure *closure;
+	
+	g_return_if_fail(cmd->param_count >= 3);
+	type = cmd->params[1];
+	g_return_if_fail(!strcmp(type, "MFN"));
+
+	closure = cmd->trans->data;
+	friendlyname = purple_url_decode(cmd->params[2]);
+
+	msn_update_contact(cmdproc->session, "Me", MSN_UPDATE_DISPLAY, friendlyname);
+
+	purple_connection_set_display_name(
+		purple_account_get_connection(closure->account),
+		friendlyname);
+	purple_account_set_string(closure->account, "display-name", friendlyname);
+
+	if (closure->success_cb) {
+		PurpleSetPublicAliasSuccessCallback success_cb = closure->success_cb;
+		success_cb(closure->account, friendlyname);
+	}
+}
+
+static void
+prp_error_cb(MsnCmdProc *cmdproc, MsnTransaction *trans, int error)
+{
+	struct public_alias_closure *closure = trans->data;
+	PurpleSetPublicAliasFailureCallback failure_cb = closure->failure_cb;
+	gboolean debug;
+	const char *error_text;
+
+	error_text = msn_error_get_text(error, &debug);
+	failure_cb(closure->account, error_text);
+}
+
+static void
+prp_timeout_cb(MsnCmdProc *cmdproc, MsnTransaction *trans)
+{
+	struct public_alias_closure *closure = trans->data;
+	PurpleSetPublicAliasFailureCallback failure_cb = closure->failure_cb;
+	failure_cb(closure->account, _("Connection Timeout"));
+}
+
 void
-msn_act_id(PurpleConnection *gc, const char *entry)
+msn_set_public_alias(PurpleConnection *pc, const char *alias,
+                     PurpleSetPublicAliasSuccessCallback success_cb,
+                     PurpleSetPublicAliasFailureCallback failure_cb)
 {
 	MsnCmdProc *cmdproc;
 	MsnSession *session;
 	PurpleAccount *account;
-	const char *alias;
+	const char *real_alias;
+	MsnTransaction *trans;
+	struct public_alias_closure *closure;
 
-	session = gc->proto_data;
+	session = purple_connection_get_protocol_data(pc);
 	cmdproc = session->notification->cmdproc;
-	account = purple_connection_get_account(gc);
+	account = purple_connection_get_account(pc);
 
-	if (entry && *entry)
+	if (alias && *alias)
 	{
-		char *tmp = g_strdup(entry);
-		alias = purple_url_encode(g_strstrip(tmp));
+		char *tmp = g_strdup(alias);
+		real_alias = purple_url_encode(g_strstrip(tmp));
 		g_free(tmp);
 	}
 	else
-		alias = "";
+		real_alias = "";
 
-	if (strlen(alias) > BUDDY_ALIAS_MAXLEN)
+	if (strlen(real_alias) > BUDDY_ALIAS_MAXLEN)
 	{
-		purple_notify_error(gc, NULL,
-						  _("Your new MSN friendly name is too long."), NULL);
+		if (failure_cb) {
+			struct public_alias_closure *closure =
+				g_new0(struct public_alias_closure, 1);
+			closure->account = account;
+			closure->failure_cb = failure_cb;
+			purple_timeout_add(0, set_public_alias_length_error, closure);
+		} else {
+			purple_notify_error(pc, NULL,
+			                    _("Your new MSN friendly name is too long."),
+			                    NULL);
+		}
 		return;
 	}
 
-	if (*alias == '\0') {
-		alias = purple_url_encode(purple_account_get_username(account));
+	if (*real_alias == '\0') {
+		real_alias = purple_url_encode(purple_account_get_username(account));
 	}
 
-	msn_cmdproc_send(cmdproc, "PRP", "MFN %s", alias);
+	closure = g_new0(struct public_alias_closure, 1);
+	closure->account = account;
+	closure->success_cb = success_cb;
+	closure->failure_cb = failure_cb;
+
+	trans = msn_transaction_new(cmdproc, "PRP", "MFN %s", real_alias);
+	msn_transaction_set_data(trans, closure);
+	msn_transaction_set_data_free(trans, g_free);
+	msn_transaction_add_cb(trans, "PRP", prp_success_cb);
+	if (failure_cb) {
+		msn_transaction_set_error_cb(trans, prp_error_cb);
+		msn_transaction_set_timeout_cb(trans, prp_timeout_cb);
+	}
+	msn_cmdproc_send_trans(cmdproc, trans);
 }
 
+static gboolean
+get_public_alias_cb(gpointer data)
+{
+	struct public_alias_closure *closure = data;
+	PurpleGetPublicAliasSuccessCallback success_cb = closure->success_cb;
+	const char *alias;
+
+	alias = purple_account_get_string(closure->account, "display-name",
+	                                  purple_account_get_username(closure->account));
+	success_cb(closure->account, alias);
+	g_free(closure);
+
+	return FALSE;
+}
+
 static void
+msn_get_public_alias(PurpleConnection *pc,
+                     PurpleGetPublicAliasSuccessCallback success_cb,
+                     PurpleGetPublicAliasFailureCallback failure_cb)
+{
+	struct public_alias_closure *closure = g_new0(struct public_alias_closure, 1);
+	PurpleAccount *account = purple_connection_get_account(pc);
+
+	closure->account = account;
+	closure->success_cb = success_cb;
+	purple_timeout_add(0, get_public_alias_cb, closure);
+}
+
+static void
+msn_act_id(PurpleConnection *gc, const char *entry)
+{
+	msn_set_public_alias(gc, entry, NULL, NULL);
+}
+
+static void
 msn_set_prp(PurpleConnection *gc, const char *type, const char *entry)
 {
 	MsnCmdProc *cmdproc;
@@ -2743,8 +2868,8 @@ static PurplePluginProtocolInfo prpl_inf
 	NULL,                               /* initiate_media */
 	NULL,                               /* get_media_caps */
 	NULL,                               /* get_moods */
-	NULL,                               /* set_public_alias */
-	NULL                                /* get_public_alias */
+	msn_set_public_alias,               /* set_public_alias */
+	msn_get_public_alias                /* get_public_alias */
 };
 
 static PurplePluginInfo info =
============================================================
--- libpurple/protocols/msn/msn.h	34d5f36337b69f918c1432c5bacb9d383d3a2c92
+++ libpurple/protocols/msn/msn.h	f0811947106e72e5155b52a68eb9a4808c9183b9
@@ -144,7 +144,10 @@ gboolean msn_email_is_valid(const char *
 #define MSN_CLIENT_EXT_ID 0
 
 gboolean msn_email_is_valid(const char *passport);
-void msn_act_id(PurpleConnection *gc, const char *entry);
+void
+msn_set_public_alias(PurpleConnection *gc, const char *alias,
+                     PurpleSetPublicAliasSuccessCallback success_cb,
+                     PurpleSetPublicAliasFailureCallback failure_cb);
 void msn_send_privacy(PurpleConnection *gc);
 void msn_send_im_message(MsnSession *session, MsnMessage *msg);
 
============================================================
--- libpurple/protocols/msn/notification.c	90baf87c28e4227f9d0d4d290b028939458df20b
+++ libpurple/protocols/msn/notification.c	96e2dea68635eefb85d3eeac2f5f0d6b2de53839
@@ -567,6 +567,7 @@ msn_notification_dump_contact(MsnSession
 	int payload_len;
 	int adl_count = 0;
 	int fqy_count = 0;
+	PurpleConnection *pc;
 	const char *display_name;
 
 	adl_node = xmlnode_new("ml");
@@ -673,11 +674,12 @@ msn_notification_dump_contact(MsnSession
 	xmlnode_free(adl_node);
 	xmlnode_free(fqy_node);
 
-	display_name = purple_connection_get_display_name(session->account->gc);
+	pc = purple_account_get_connection(session->account);
+	display_name = purple_connection_get_display_name(pc);
 	if (display_name
 	    && strcmp(display_name,
 		      purple_account_get_username(session->account))) {
-		msn_act_id(session->account->gc, display_name);
+		msn_set_public_alias(pc, display_name, NULL, NULL);
 	}
 
 }
@@ -1292,11 +1294,11 @@ prp_cmd(MsnCmdProc *cmdproc, MsnCommand 
 prp_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
 {
 	MsnSession *session = cmdproc->session;
-	const char *type, *value, *friendlyname;
+	const char *type, *value;
 
 	g_return_if_fail(cmd->param_count >= 3);
 
-	type  = cmd->params[2];
+	type = cmd->params[2];
 
 	if (cmd->param_count == 4)
 	{
@@ -1316,19 +1318,6 @@ prp_cmd(MsnCmdProc *cmdproc, MsnCommand 
 			msn_user_set_work_phone(session->user, NULL);
 		else if (!strcmp(type, "PHM"))
 			msn_user_set_mobile_phone(session->user, NULL);
-		else {
-			type = cmd->params[1];
-			if (!strcmp(type, "MFN")) {
-				friendlyname = purple_url_decode(cmd->params[2]);
-
-				msn_update_contact(session, "Me", MSN_UPDATE_DISPLAY, friendlyname);
-
-				purple_connection_set_display_name(
-					purple_account_get_connection(session->account),
-					friendlyname);
-				purple_account_set_string(session->account, "display-name", friendlyname);
-			}
-		}
 	}
 }
 


More information about the Commits mailing list