Mercurial > pidgin
comparison libpurple/protocols/msn/msn.c @ 29894:ec89b1d8571a
Implement [gs]et_public_alias in MSN.
author | Elliott Sales de Andrade <qulogic@pidgin.im> |
---|---|
date | Mon, 10 May 2010 23:14:05 +0000 |
parents | 193a8e64e373 |
children | d6f9f4320bf1 f8ec889c5bce |
comparison
equal
deleted
inserted
replaced
29893:ba0571f18075 | 29894:ec89b1d8571a |
---|---|
193 purple_prpl_send_attention(gc, username, MSN_NUDGE); | 193 purple_prpl_send_attention(gc, username, MSN_NUDGE); |
194 | 194 |
195 return PURPLE_CMD_RET_OK; | 195 return PURPLE_CMD_RET_OK; |
196 } | 196 } |
197 | 197 |
198 struct public_alias_closure | |
199 { | |
200 PurpleAccount *account; | |
201 gpointer success_cb; | |
202 gpointer failure_cb; | |
203 }; | |
204 | |
205 static gboolean | |
206 set_public_alias_length_error(gpointer data) | |
207 { | |
208 struct public_alias_closure *closure = data; | |
209 PurpleSetPublicAliasFailureCallback failure_cb = closure->failure_cb; | |
210 | |
211 failure_cb(closure->account, _("Your new MSN friendly name is too long.")); | |
212 g_free(closure); | |
213 | |
214 return FALSE; | |
215 } | |
216 | |
217 static void | |
218 prp_success_cb(MsnCmdProc *cmdproc, MsnCommand *cmd) | |
219 { | |
220 const char *type, *friendlyname; | |
221 struct public_alias_closure *closure; | |
222 | |
223 g_return_if_fail(cmd->param_count >= 3); | |
224 type = cmd->params[1]; | |
225 g_return_if_fail(!strcmp(type, "MFN")); | |
226 | |
227 closure = cmd->trans->data; | |
228 friendlyname = purple_url_decode(cmd->params[2]); | |
229 | |
230 msn_update_contact(cmdproc->session, "Me", MSN_UPDATE_DISPLAY, friendlyname); | |
231 | |
232 purple_connection_set_display_name( | |
233 purple_account_get_connection(closure->account), | |
234 friendlyname); | |
235 purple_account_set_string(closure->account, "display-name", friendlyname); | |
236 | |
237 if (closure->success_cb) { | |
238 PurpleSetPublicAliasSuccessCallback success_cb = closure->success_cb; | |
239 success_cb(closure->account, friendlyname); | |
240 } | |
241 } | |
242 | |
243 static void | |
244 prp_error_cb(MsnCmdProc *cmdproc, MsnTransaction *trans, int error) | |
245 { | |
246 struct public_alias_closure *closure = trans->data; | |
247 PurpleSetPublicAliasFailureCallback failure_cb = closure->failure_cb; | |
248 gboolean debug; | |
249 const char *error_text; | |
250 | |
251 error_text = msn_error_get_text(error, &debug); | |
252 failure_cb(closure->account, error_text); | |
253 } | |
254 | |
255 static void | |
256 prp_timeout_cb(MsnCmdProc *cmdproc, MsnTransaction *trans) | |
257 { | |
258 struct public_alias_closure *closure = trans->data; | |
259 PurpleSetPublicAliasFailureCallback failure_cb = closure->failure_cb; | |
260 failure_cb(closure->account, _("Connection Timeout")); | |
261 } | |
262 | |
198 void | 263 void |
264 msn_set_public_alias(PurpleConnection *pc, const char *alias, | |
265 PurpleSetPublicAliasSuccessCallback success_cb, | |
266 PurpleSetPublicAliasFailureCallback failure_cb) | |
267 { | |
268 MsnCmdProc *cmdproc; | |
269 MsnSession *session; | |
270 PurpleAccount *account; | |
271 const char *real_alias; | |
272 MsnTransaction *trans; | |
273 struct public_alias_closure *closure; | |
274 | |
275 session = purple_connection_get_protocol_data(pc); | |
276 cmdproc = session->notification->cmdproc; | |
277 account = purple_connection_get_account(pc); | |
278 | |
279 if (alias && *alias) | |
280 { | |
281 char *tmp = g_strdup(alias); | |
282 real_alias = purple_url_encode(g_strstrip(tmp)); | |
283 g_free(tmp); | |
284 } | |
285 else | |
286 real_alias = ""; | |
287 | |
288 if (strlen(real_alias) > BUDDY_ALIAS_MAXLEN) | |
289 { | |
290 if (failure_cb) { | |
291 struct public_alias_closure *closure = | |
292 g_new0(struct public_alias_closure, 1); | |
293 closure->account = account; | |
294 closure->failure_cb = failure_cb; | |
295 purple_timeout_add(0, set_public_alias_length_error, closure); | |
296 } else { | |
297 purple_notify_error(pc, NULL, | |
298 _("Your new MSN friendly name is too long."), | |
299 NULL); | |
300 } | |
301 return; | |
302 } | |
303 | |
304 if (*real_alias == '\0') { | |
305 real_alias = purple_url_encode(purple_account_get_username(account)); | |
306 } | |
307 | |
308 closure = g_new0(struct public_alias_closure, 1); | |
309 closure->account = account; | |
310 closure->success_cb = success_cb; | |
311 closure->failure_cb = failure_cb; | |
312 | |
313 trans = msn_transaction_new(cmdproc, "PRP", "MFN %s", real_alias); | |
314 msn_transaction_set_data(trans, closure); | |
315 msn_transaction_set_data_free(trans, g_free); | |
316 msn_transaction_add_cb(trans, "PRP", prp_success_cb); | |
317 if (failure_cb) { | |
318 msn_transaction_set_error_cb(trans, prp_error_cb); | |
319 msn_transaction_set_timeout_cb(trans, prp_timeout_cb); | |
320 } | |
321 msn_cmdproc_send_trans(cmdproc, trans); | |
322 } | |
323 | |
324 static gboolean | |
325 get_public_alias_cb(gpointer data) | |
326 { | |
327 struct public_alias_closure *closure = data; | |
328 PurpleGetPublicAliasSuccessCallback success_cb = closure->success_cb; | |
329 const char *alias; | |
330 | |
331 alias = purple_account_get_string(closure->account, "display-name", | |
332 purple_account_get_username(closure->account)); | |
333 success_cb(closure->account, alias); | |
334 g_free(closure); | |
335 | |
336 return FALSE; | |
337 } | |
338 | |
339 static void | |
340 msn_get_public_alias(PurpleConnection *pc, | |
341 PurpleGetPublicAliasSuccessCallback success_cb, | |
342 PurpleGetPublicAliasFailureCallback failure_cb) | |
343 { | |
344 struct public_alias_closure *closure = g_new0(struct public_alias_closure, 1); | |
345 PurpleAccount *account = purple_connection_get_account(pc); | |
346 | |
347 closure->account = account; | |
348 closure->success_cb = success_cb; | |
349 purple_timeout_add(0, get_public_alias_cb, closure); | |
350 } | |
351 | |
352 static void | |
199 msn_act_id(PurpleConnection *gc, const char *entry) | 353 msn_act_id(PurpleConnection *gc, const char *entry) |
200 { | 354 { |
201 MsnCmdProc *cmdproc; | 355 msn_set_public_alias(gc, entry, NULL, NULL); |
202 MsnSession *session; | |
203 PurpleAccount *account; | |
204 const char *alias; | |
205 | |
206 session = gc->proto_data; | |
207 cmdproc = session->notification->cmdproc; | |
208 account = purple_connection_get_account(gc); | |
209 | |
210 if (entry && *entry) | |
211 { | |
212 char *tmp = g_strdup(entry); | |
213 alias = purple_url_encode(g_strstrip(tmp)); | |
214 g_free(tmp); | |
215 } | |
216 else | |
217 alias = ""; | |
218 | |
219 if (strlen(alias) > BUDDY_ALIAS_MAXLEN) | |
220 { | |
221 purple_notify_error(gc, NULL, | |
222 _("Your new MSN friendly name is too long."), NULL); | |
223 return; | |
224 } | |
225 | |
226 if (*alias == '\0') { | |
227 alias = purple_url_encode(purple_account_get_username(account)); | |
228 } | |
229 | |
230 msn_cmdproc_send(cmdproc, "PRP", "MFN %s", alias); | |
231 } | 356 } |
232 | 357 |
233 static void | 358 static void |
234 msn_set_prp(PurpleConnection *gc, const char *type, const char *entry) | 359 msn_set_prp(PurpleConnection *gc, const char *type, const char *entry) |
235 { | 360 { |
2741 sizeof(PurplePluginProtocolInfo), /* struct_size */ | 2866 sizeof(PurplePluginProtocolInfo), /* struct_size */ |
2742 msn_get_account_text_table, /* get_account_text_table */ | 2867 msn_get_account_text_table, /* get_account_text_table */ |
2743 NULL, /* initiate_media */ | 2868 NULL, /* initiate_media */ |
2744 NULL, /* get_media_caps */ | 2869 NULL, /* get_media_caps */ |
2745 NULL, /* get_moods */ | 2870 NULL, /* get_moods */ |
2746 NULL, /* set_public_alias */ | 2871 msn_set_public_alias, /* set_public_alias */ |
2747 NULL /* get_public_alias */ | 2872 msn_get_public_alias /* get_public_alias */ |
2748 }; | 2873 }; |
2749 | 2874 |
2750 static PurplePluginInfo info = | 2875 static PurplePluginInfo info = |
2751 { | 2876 { |
2752 PURPLE_PLUGIN_MAGIC, | 2877 PURPLE_PLUGIN_MAGIC, |