libpurple/protocols/myspace/myspace.c

branch
next.minor
changeset 25847
a1c8c5a23b6d
parent 25197
077b4d6fc595
parent 25846
a93cb1380fae
child 25848
b6320ffda294
equal deleted inserted replaced
25197:077b4d6fc595 25847:a1c8c5a23b6d
204 uid = atol(username); 204 uid = atol(username);
205 } else { 205 } else {
206 /* Next, see if on buddy list and know uid. */ 206 /* Next, see if on buddy list and know uid. */
207 buddy = purple_find_buddy(session->account, username); 207 buddy = purple_find_buddy(session->account, username);
208 if (buddy) { 208 if (buddy) {
209 uid = purple_blist_node_get_int(&buddy->node, "UserID"); 209 uid = purple_blist_node_get_int(PURPLE_BLIST_NODE(buddy), "UserID");
210 } else { 210 } else {
211 uid = 0; 211 uid = 0;
212 } 212 }
213 213
214 if (!buddy || !uid) { 214 if (!buddy || !uid) {
317 const gchar *name; 317 const gchar *name;
318 318
319 /* See finch/gnthistory.c */ 319 /* See finch/gnthistory.c */
320 buddy = cur->data; 320 buddy = cur->data;
321 321
322 uid = purple_blist_node_get_int(&buddy->node, "UserID"); 322 uid = purple_blist_node_get_int(PURPLE_BLIST_NODE(buddy), "UserID");
323 name = purple_buddy_get_name(buddy); 323 name = purple_buddy_get_name(buddy);
324 324
325 if (uid == wanted_uid) 325 if (uid == wanted_uid)
326 { 326 {
327 ret = name; 327 ret = name;
389 msim_status_text(PurpleBuddy *buddy) 389 msim_status_text(PurpleBuddy *buddy)
390 { 390 {
391 MsimSession *session; 391 MsimSession *session;
392 MsimUser *user; 392 MsimUser *user;
393 const gchar *display_name, *headline; 393 const gchar *display_name, *headline;
394 PurpleAccount *account;
395 PurpleConnection *gc;
394 396
395 g_return_val_if_fail(buddy != NULL, NULL); 397 g_return_val_if_fail(buddy != NULL, NULL);
396 398
397 user = msim_get_user_from_buddy(buddy); 399 user = msim_get_user_from_buddy(buddy);
398 400
399 session = (MsimSession *)buddy->account->gc->proto_data; 401 account = purple_buddy_get_account(buddy);
402 gc = purple_account_get_connection(account);
403 session = (MsimSession *)gc->proto_data;
404
400 g_return_val_if_fail(MSIM_SESSION_VALID(session), NULL); 405 g_return_val_if_fail(MSIM_SESSION_VALID(session), NULL);
401 406
402 display_name = headline = NULL; 407 display_name = headline = NULL;
403 408
404 /* Retrieve display name and/or headline, depending on user preference. */ 409 /* Retrieve display name and/or headline, depending on user preference. */
441 446
442 user = msim_get_user_from_buddy(buddy); 447 user = msim_get_user_from_buddy(buddy);
443 448
444 if (PURPLE_BUDDY_IS_ONLINE(buddy)) { 449 if (PURPLE_BUDDY_IS_ONLINE(buddy)) {
445 MsimSession *session; 450 MsimSession *session;
446 451 PurpleAccount *account = purple_buddy_get_account(buddy);
447 session = (MsimSession *)buddy->account->gc->proto_data; 452 PurpleConnection *gc = purple_account_get_connection(account);
453
454 session = (MsimSession *)gc->proto_data;
448 455
449 g_return_if_fail(MSIM_SESSION_VALID(session)); 456 g_return_if_fail(MSIM_SESSION_VALID(session));
450 457
451 /* TODO: if (full), do something different? */ 458 /* TODO: if (full), do something different? */
452 459
1023 /* 3. Update buddy information */ 1030 /* 3. Update buddy information */
1024 user = msim_get_user_from_buddy(buddy); 1031 user = msim_get_user_from_buddy(buddy);
1025 1032
1026 user->id = uid; 1033 user->id = uid;
1027 /* Keep track of the user ID across sessions */ 1034 /* Keep track of the user ID across sessions */
1028 purple_blist_node_set_int(&buddy->node, "UserID", uid); 1035 purple_blist_node_set_int(PURPLE_BLIST_NODE(buddy), "UserID", uid);
1029 1036
1030 /* Stores a few fields in the MsimUser, relevant to the buddy itself. 1037 /* Stores a few fields in the MsimUser, relevant to the buddy itself.
1031 * AvatarURL, Headline, ContactID. */ 1038 * AvatarURL, Headline, ContactID. */
1032 msim_store_user_info(session, contact_info, NULL); 1039 msim_store_user_info(session, contact_info, NULL);
1033 1040
1350 1357
1351 user = msim_get_user_from_buddy(buddy); 1358 user = msim_get_user_from_buddy(buddy);
1352 user->id = msim_msg_get_integer(msg, "f"); 1359 user->id = msim_msg_get_integer(msg, "f");
1353 1360
1354 /* Keep track of the user ID across sessions */ 1361 /* Keep track of the user ID across sessions */
1355 purple_blist_node_set_int(&buddy->node, "UserID", user->id); 1362 purple_blist_node_set_int(PURPLE_BLIST_NODE(buddy), "UserID", user->id);
1356 1363
1357 msim_store_user_info(session, msg, NULL); 1364 msim_store_user_info(session, msg, NULL);
1358 } else { 1365 } else {
1359 purple_debug_info("msim", "msim_status: found buddy %s\n", username); 1366 purple_debug_info("msim", "msim_status: found buddy %s\n", username);
1360 } 1367 }
2564 { 2571 {
2565 MsimSession *session; 2572 MsimSession *session;
2566 MsimMessage *msg; 2573 MsimMessage *msg;
2567 MsimMessage *msg_persist; 2574 MsimMessage *msg_persist;
2568 MsimMessage *body; 2575 MsimMessage *body;
2576 const char *name, *gname;
2577
2569 2578
2570 session = (MsimSession *)gc->proto_data; 2579 session = (MsimSession *)gc->proto_data;
2580 name = purple_buddy_get_name(buddy);
2581 gname = group ? purple_group_get_name(group) : NULL;
2582
2571 purple_debug_info("msim", "msim_add_buddy: want to add %s to %s\n", 2583 purple_debug_info("msim", "msim_add_buddy: want to add %s to %s\n",
2572 buddy->name, (group && group->name) ? group->name : "(no group)"); 2584 name, gname ? gname : "(no group)");
2573 2585
2574 msg = msim_msg_new( 2586 msg = msim_msg_new(
2575 "addbuddy", MSIM_TYPE_BOOLEAN, TRUE, 2587 "addbuddy", MSIM_TYPE_BOOLEAN, TRUE,
2576 "sesskey", MSIM_TYPE_INTEGER, session->sesskey, 2588 "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
2577 /* "newprofileid" will be inserted here with uid. */ 2589 /* "newprofileid" will be inserted here with uid. */
2578 "reason", MSIM_TYPE_STRING, g_strdup(""), 2590 "reason", MSIM_TYPE_STRING, g_strdup(""),
2579 NULL); 2591 NULL);
2580 2592
2581 if (!msim_postprocess_outgoing(session, msg, buddy->name, "newprofileid", "reason")) { 2593 if (!msim_postprocess_outgoing(session, msg, name, "newprofileid", "reason")) {
2582 purple_notify_error(NULL, NULL, _("Failed to add buddy"), _("'addbuddy' command failed.")); 2594 purple_notify_error(NULL, NULL, _("Failed to add buddy"), _("'addbuddy' command failed."));
2583 msim_msg_free(msg); 2595 msim_msg_free(msg);
2584 return; 2596 return;
2585 } 2597 }
2586 msim_msg_free(msg); 2598 msim_msg_free(msg);
2588 /* TODO: if addbuddy fails ('error' message is returned), delete added buddy from 2600 /* TODO: if addbuddy fails ('error' message is returned), delete added buddy from
2589 * buddy list since Purple adds it locally. */ 2601 * buddy list since Purple adds it locally. */
2590 2602
2591 body = msim_msg_new( 2603 body = msim_msg_new(
2592 "ContactID", MSIM_TYPE_STRING, g_strdup("<uid>"), 2604 "ContactID", MSIM_TYPE_STRING, g_strdup("<uid>"),
2593 "GroupName", MSIM_TYPE_STRING, g_strdup(group->name), 2605 "GroupName", MSIM_TYPE_STRING, g_strdup(gname),
2594 "Position", MSIM_TYPE_INTEGER, 1000, 2606 "Position", MSIM_TYPE_INTEGER, 1000,
2595 "Visibility", MSIM_TYPE_INTEGER, 1, 2607 "Visibility", MSIM_TYPE_INTEGER, 1,
2596 "NickName", MSIM_TYPE_STRING, g_strdup(""), 2608 "NickName", MSIM_TYPE_STRING, g_strdup(""),
2597 "NameSelect", MSIM_TYPE_INTEGER, 0, 2609 "NameSelect", MSIM_TYPE_INTEGER, 0,
2598 NULL); 2610 NULL);
2609 /* TODO: Use msim_new_reply_callback to get rid. */ 2621 /* TODO: Use msim_new_reply_callback to get rid. */
2610 "rid", MSIM_TYPE_INTEGER, session->next_rid++, 2622 "rid", MSIM_TYPE_INTEGER, session->next_rid++,
2611 "body", MSIM_TYPE_DICTIONARY, body, 2623 "body", MSIM_TYPE_DICTIONARY, body,
2612 NULL); 2624 NULL);
2613 2625
2614 if (!msim_postprocess_outgoing(session, msg_persist, buddy->name, "body", NULL)) 2626 if (!msim_postprocess_outgoing(session, msg_persist, name, "body", NULL))
2615 { 2627 {
2616 purple_notify_error(NULL, NULL, _("Failed to add buddy"), _("persist command failed")); 2628 purple_notify_error(NULL, NULL, _("Failed to add buddy"), _("persist command failed"));
2617 msim_msg_free(msg_persist); 2629 msim_msg_free(msg_persist);
2618 return; 2630 return;
2619 } 2631 }
2629 MsimSession *session; 2641 MsimSession *session;
2630 MsimMessage *delbuddy_msg; 2642 MsimMessage *delbuddy_msg;
2631 MsimMessage *persist_msg; 2643 MsimMessage *persist_msg;
2632 MsimMessage *blocklist_msg; 2644 MsimMessage *blocklist_msg;
2633 GList *blocklist_updates; 2645 GList *blocklist_updates;
2646 const char *name;
2634 2647
2635 session = (MsimSession *)gc->proto_data; 2648 session = (MsimSession *)gc->proto_data;
2649 name = purple_buddy_get_name(buddy);
2636 2650
2637 delbuddy_msg = msim_msg_new( 2651 delbuddy_msg = msim_msg_new(
2638 "delbuddy", MSIM_TYPE_BOOLEAN, TRUE, 2652 "delbuddy", MSIM_TYPE_BOOLEAN, TRUE,
2639 "sesskey", MSIM_TYPE_INTEGER, session->sesskey, 2653 "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
2640 /* 'delprofileid' with uid will be inserted here. */ 2654 /* 'delprofileid' with uid will be inserted here. */
2641 NULL); 2655 NULL);
2642 2656
2643 if (!msim_postprocess_outgoing(session, delbuddy_msg, buddy->name, "delprofileid", NULL)) { 2657 if (!msim_postprocess_outgoing(session, delbuddy_msg, name, "delprofileid", NULL)) {
2644 purple_notify_error(NULL, NULL, _("Failed to remove buddy"), _("'delbuddy' command failed")); 2658 purple_notify_error(NULL, NULL, _("Failed to remove buddy"), _("'delbuddy' command failed"));
2645 msim_msg_free(delbuddy_msg); 2659 msim_msg_free(delbuddy_msg);
2646 return; 2660 return;
2647 } 2661 }
2648 msim_msg_free(delbuddy_msg); 2662 msim_msg_free(delbuddy_msg);
2657 "rid", MSIM_TYPE_INTEGER, session->next_rid++, 2671 "rid", MSIM_TYPE_INTEGER, session->next_rid++,
2658 /* <uid> will be replaced by postprocessing */ 2672 /* <uid> will be replaced by postprocessing */
2659 "body", MSIM_TYPE_STRING, g_strdup("ContactID=<uid>"), 2673 "body", MSIM_TYPE_STRING, g_strdup("ContactID=<uid>"),
2660 NULL); 2674 NULL);
2661 2675
2662 if (!msim_postprocess_outgoing(session, persist_msg, buddy->name, "body", NULL)) { 2676 if (!msim_postprocess_outgoing(session, persist_msg, name, "body", NULL)) {
2663 purple_notify_error(NULL, NULL, _("Failed to remove buddy"), _("persist command failed")); 2677 purple_notify_error(NULL, NULL, _("Failed to remove buddy"), _("persist command failed"));
2664 msim_msg_free(persist_msg); 2678 msim_msg_free(persist_msg);
2665 return; 2679 return;
2666 } 2680 }
2667 msim_msg_free(persist_msg); 2681 msim_msg_free(persist_msg);
2679 /* TODO: MsimMessage lists. Currently <uid> isn't replaced in lists. */ 2693 /* TODO: MsimMessage lists. Currently <uid> isn't replaced in lists. */
2680 /* "idlist", MSIM_TYPE_STRING, g_strdup("a-|<uid>|b-|<uid>"), */ 2694 /* "idlist", MSIM_TYPE_STRING, g_strdup("a-|<uid>|b-|<uid>"), */
2681 "idlist", MSIM_TYPE_LIST, blocklist_updates, 2695 "idlist", MSIM_TYPE_LIST, blocklist_updates,
2682 NULL); 2696 NULL);
2683 2697
2684 if (!msim_postprocess_outgoing(session, blocklist_msg, buddy->name, "idlist", NULL)) { 2698 if (!msim_postprocess_outgoing(session, blocklist_msg, name, "idlist", NULL)) {
2685 purple_notify_error(NULL, NULL, _("Failed to remove buddy"), _("blocklist command failed")); 2699 purple_notify_error(NULL, NULL, _("Failed to remove buddy"), _("blocklist command failed"));
2686 msim_msg_free(blocklist_msg); 2700 msim_msg_free(blocklist_msg);
2687 return; 2701 return;
2688 } 2702 }
2689 msim_msg_free(blocklist_msg); 2703 msim_msg_free(blocklist_msg);

mercurial