void msn_user_update(MsnUser *user) { PurpleAccount *account; gboolean offline; g_return_if_fail(user != NULL); account = user->userlist->session->account; offline = (user->status == NULL); if (!offline) { purple_prpl_got_user_status(account, user->passport, user->status, "message", user->statusline, NULL); } else { if (user->mobile) { purple_prpl_got_user_status(account, user->passport, "mobile", NULL); purple_prpl_got_user_status(account, user->passport, "available", NULL); } else { purple_prpl_got_user_status(account, user->passport, "offline", NULL); } } if (!offline || !user->mobile) { purple_prpl_got_user_status_deactive(account, user->passport, "mobile"); } if (!offline && user->extinfo && user->extinfo->media_type != CURRENT_MEDIA_UNKNOWN) { if (user->extinfo->media_type == CURRENT_MEDIA_MUSIC) { purple_prpl_got_user_status(account, user->passport, "tune", PURPLE_TUNE_ARTIST, user->extinfo->media_artist, PURPLE_TUNE_ALBUM, user->extinfo->media_album, PURPLE_TUNE_TITLE, user->extinfo->media_title, NULL); } else if (user->extinfo->media_type == CURRENT_MEDIA_GAMES) { purple_prpl_got_user_status(account, user->passport, "tune", "game", user->extinfo->media_title, NULL); } else if (user->extinfo->media_type == CURRENT_MEDIA_OFFICE) { purple_prpl_got_user_status(account, user->passport, "tune", "office", user->extinfo->media_title, NULL); } else { purple_debug_warning("msn", "Got CurrentMedia with unknown type %d.\n", user->extinfo->media_type); } } else { purple_prpl_got_user_status_deactive(account, user->passport, "tune"); } if (user->idle) purple_prpl_got_user_idle(account, user->passport, TRUE, -1); else purple_prpl_got_user_idle(account, user->passport, FALSE, 0); }
void jabber_presence_fake_to_self(JabberStream *js, PurpleStatus *status) { PurpleAccount *account; PurplePresence *presence; JabberBuddy *jb; JabberBuddyResource *jbr; const char *username; JabberBuddyState state; char *msg; int priority; g_return_if_fail(js->user != NULL); account = purple_connection_get_account(js->gc); username = purple_connection_get_display_name(js->gc); presence = purple_account_get_presence(account); if (status == NULL) status = purple_presence_get_active_status(presence); purple_status_to_jabber(status, &state, &msg, &priority); jb = js->user_jb; if (state == JABBER_BUDDY_STATE_UNAVAILABLE || state == JABBER_BUDDY_STATE_UNKNOWN) { jabber_buddy_remove_resource(jb, js->user->resource); } else { jbr = jabber_buddy_track_resource(jb, js->user->resource, priority, state, msg); jbr->idle = purple_presence_is_idle(presence) ? purple_presence_get_idle_time(presence) : 0; } /* * While we need to track the status of this resource, the core * only cares if we're on our own buddy list. */ if (purple_find_buddy(account, username)) { jbr = jabber_buddy_find_resource(jb, NULL); if (jbr) { purple_prpl_got_user_status(account, username, jabber_buddy_state_get_status_id(jbr->state), "priority", jbr->priority, jbr->status ? "message" : NULL, jbr->status, NULL); purple_prpl_got_user_idle(account, username, jbr->idle, jbr->idle); } else { purple_prpl_got_user_status(account, username, "offline", msg ? "message" : NULL, msg, NULL); } } g_free(msg); }
static gboolean handle_presence_contact(JabberStream *js, JabberPresence *presence) { JabberBuddyResource *jbr; PurpleAccount *account; PurpleBuddy *b; char *buddy_name; PurpleConversation *conv; buddy_name = jabber_id_get_bare_jid(presence->jid_from); account = purple_connection_get_account(js->gc); b = purple_find_buddy(account, buddy_name); /* * Unbind/unlock from sending messages to a specific resource on * presence changes. This is locked to a specific resource when * receiving a message (in message.c). */ conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, buddy_name, account); if (conv) { purple_debug_info("jabber", "Changed conversation binding from %s to %s\n", purple_conversation_get_name(conv), buddy_name); purple_conversation_set_name(conv, buddy_name); } if (b == NULL) { if (presence->jb != js->user_jb) { purple_debug_warning("jabber", "Got presence for unknown buddy %s on account %s (%p)\n", buddy_name, purple_account_get_username(account), account); g_free(buddy_name); return FALSE; } else { /* this is a different resource of our own account. Resume even when this account isn't on our blist */ } } if (b && presence->vcard_avatar_hash) { const char *ah = presence->vcard_avatar_hash[0] != '\0' ? presence->vcard_avatar_hash : NULL; const char *ah2 = purple_buddy_icons_get_checksum_for_user(b); if (!purple_strequal(ah, ah2)) { /* XXX this is a crappy way of trying to prevent * someone from spamming us with presence packets * and causing us to DoS ourselves...what we really * need is a queue system that can throttle itself, * but i'm too tired to write that right now */ if(!g_slist_find(js->pending_avatar_requests, presence->jb)) { JabberIq *iq; xmlnode *vcard; js->pending_avatar_requests = g_slist_prepend(js->pending_avatar_requests, presence->jb); iq = jabber_iq_new(js, JABBER_IQ_GET); xmlnode_set_attrib(iq->node, "to", buddy_name); vcard = xmlnode_new_child(iq->node, "vCard"); xmlnode_set_namespace(vcard, "vcard-temp"); jabber_iq_set_callback(iq, jabber_vcard_parse_avatar, NULL); jabber_iq_send(iq); } } } if (presence->state == JABBER_BUDDY_STATE_ERROR || presence->type == JABBER_PRESENCE_UNAVAILABLE || presence->type == JABBER_PRESENCE_UNSUBSCRIBED) { jabber_buddy_remove_resource(presence->jb, presence->jid_from->resource); } else { jbr = jabber_buddy_track_resource(presence->jb, presence->jid_from->resource, presence->priority, presence->state, presence->status); jbr->idle = presence->idle ? time(NULL) - presence->idle : 0; } jbr = jabber_buddy_find_resource(presence->jb, NULL); if (jbr) { jabber_google_presence_incoming(js, buddy_name, jbr); purple_prpl_got_user_status(account, buddy_name, jabber_buddy_state_get_status_id(jbr->state), "priority", jbr->priority, "message", jbr->status, NULL); purple_prpl_got_user_idle(account, buddy_name, jbr->idle, jbr->idle); if (presence->nickname) serv_got_alias(js->gc, buddy_name, presence->nickname); } else { purple_prpl_got_user_status(account, buddy_name, jabber_buddy_state_get_status_id(JABBER_BUDDY_STATE_UNAVAILABLE), presence->status ? "message" : NULL, presence->status, NULL); } g_free(buddy_name); return TRUE; }
/** * If the buddy does not yet exist, then create it and add it to * our buddy list. In either case we set the correct status for * the buddy. */ void bonjour_buddy_add_to_purple(BonjourBuddy *bonjour_buddy) { PurpleBuddy *buddy; PurpleGroup *group; PurpleAccount *account = bonjour_buddy->account; const char *status_id, *old_hash, *new_hash; /* Translate between the Bonjour status and the Purple status */ if (bonjour_buddy->status != NULL && g_ascii_strcasecmp("dnd", bonjour_buddy->status) == 0) status_id = BONJOUR_STATUS_ID_AWAY; else status_id = BONJOUR_STATUS_ID_AVAILABLE; /* * TODO: Figure out the idle time by getting the "away" * field from the DNS SD. */ /* Make sure the Bonjour group exists in our buddy list */ group = purple_find_group(BONJOUR_GROUP_NAME); /* Use the buddy's domain, instead? */ if (group == NULL) { group = purple_group_new(BONJOUR_GROUP_NAME); purple_blist_add_group(group, NULL); } /* Make sure the buddy exists in our buddy list */ buddy = purple_find_buddy(account, bonjour_buddy->name); if (buddy == NULL) { buddy = purple_buddy_new(account, bonjour_buddy->name, NULL); buddy->proto_data = bonjour_buddy; purple_blist_node_set_flags((PurpleBlistNode *)buddy, PURPLE_BLIST_NODE_FLAG_NO_SAVE); purple_blist_add_buddy(buddy, NULL, group, NULL); } /* Create the alias for the buddy using the first and the last name */ if (bonjour_buddy->nick) serv_got_alias(purple_account_get_connection(account), buddy->name, bonjour_buddy->nick); else { gchar *alias = NULL; const char *first, *last; first = bonjour_buddy->first; last = bonjour_buddy->last; if ((first && *first) || (last && *last)) alias = g_strdup_printf("%s%s%s", (first && *first ? first : ""), (first && *first && last && *last ? " " : ""), (last && *last ? last : "")); serv_got_alias(purple_account_get_connection(account), buddy->name, alias); g_free(alias); } /* Set the user's status */ if (bonjour_buddy->msg != NULL) purple_prpl_got_user_status(account, buddy->name, status_id, "message", bonjour_buddy->msg, NULL); else purple_prpl_got_user_status(account, buddy->name, status_id, NULL); purple_prpl_got_user_idle(account, buddy->name, FALSE, 0); /* TODO: Because we don't save Bonjour buddies in blist.xml, * we will always have to look up the buddy icon at login time. * I think we should figure out a way to do something about this. */ /* Deal with the buddy icon */ old_hash = purple_buddy_icons_get_checksum_for_user(buddy); new_hash = (bonjour_buddy->phsh && *(bonjour_buddy->phsh)) ? bonjour_buddy->phsh : NULL; if (new_hash && (!old_hash || strcmp(old_hash, new_hash) != 0)) { /* Look up the new icon data */ /* TODO: Make sure the hash assigned to the retrieved buddy icon is the same * as what we looked up. */ bonjour_dns_sd_retrieve_buddy_icon(bonjour_buddy); } else if (!new_hash) purple_buddy_icons_set_for_user(account, buddy->name, NULL, 0, NULL); }
static gboolean stress_event_cb(gpointer data) { StressBuddy *sb = (StressBuddy *)data; PurpleAccount *account = purple_buddy_get_account(sb->buddy); PurpleStatus *status = NULL; gint event = rand() % nevents; const gchar *name = purple_buddy_get_name(sb->buddy), *sevent = NULL; gchar *msg = NULL; /* increment our event counter */ sb->nevents++; event = GPOINTER_TO_INT(g_list_nth_data(events, event)); switch(event) { case STRESS_EVENT_SIGN_ON: sevent = "signon"; break; case STRESS_EVENT_SIGN_OFF: sevent = "signoff"; break; case STRESS_EVENT_IDLE: sevent = "idle"; break; case STRESS_EVENT_UNIDLE: sevent = "unidle"; break; case STRESS_EVENT_AWAY: sevent = "away"; break; case STRESS_EVENT_BACK: sevent = "back"; break; case STRESS_EVENT_TYPING: sevent = "typing"; break; case STRESS_EVENT_STOPPED_TYPING: sevent = "stopped typing"; break; case STRESS_EVENT_SEND_MESSAGE: sevent = "message"; break; } purple_debug_info("stress", "firing '%s' for '%s' (event %d of %d)\n", sevent, name, sb->nevents, sb->maxevents); switch(event) { case STRESS_EVENT_SIGN_ON: case STRESS_EVENT_BACK: purple_prpl_got_user_status(account, name, "available", NULL); break; case STRESS_EVENT_SIGN_OFF: purple_prpl_got_user_status(account, name, "offline", NULL); break; case STRESS_EVENT_IDLE: purple_prpl_got_user_idle(account, name, TRUE, 0); break; case STRESS_EVENT_UNIDLE: purple_prpl_got_user_idle(account, name, FALSE, 0); break; case STRESS_EVENT_AWAY: purple_prpl_got_user_status(account, name, "away", NULL); break; case STRESS_EVENT_SEND_MESSAGE: stress_send_im(account, sb->buddy, name); break; } msg = g_strdup_printf("event %d of %d", sb->nevents, sb->maxevents); status = purple_presence_get_active_status(sb->buddy->presence); purple_status_set_attr_string(status, "message", msg); g_free(msg); if(sb->maxevents > 0 && sb->nevents >= sb->maxevents) { purple_prpl_got_user_status(account, name, "available", "message", _("Done"), NULL); purple_prpl_got_user_idle(account, name, FALSE, 0); stress_close_convs(account, name); return FALSE; } return TRUE; }