Beispiel #1
0
/*
 * Subtypes 0x000b (SNAC_SUBTYPE_BUDDY_ONCOMING) and 0x000c (SNAC_SUBTYPE_BUDDY_OFFGOING) - Change in buddy status
 *
 * Oncoming Buddy notifications contain a subset of the
 * user information structure.  It's close enough to run
 * through aim_info_extract() however.
 *
 * Although the offgoing notification contains no information,
 * it is still in a format parsable by aim_info_extract().
 *
 */
static int
buddychange(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
{
	int ret = 0;
	aim_userinfo_t userinfo;
	aim_rxcallback_t userfunc;

	aim_info_extract(od, bs, &userinfo);

	if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
		ret = userfunc(od, conn, frame, &userinfo);

	if (snac->subtype == SNAC_SUBTYPE_BUDDY_ONCOMING &&
	    userinfo.capabilities & OSCAR_CAPABILITY_XTRAZ) {
		PurpleAccount *account = purple_connection_get_account(od->gc);
		PurpleBuddy *buddy = purple_find_buddy(account, userinfo.bn);

		if (buddy) {
			PurplePresence *presence = purple_buddy_get_presence(buddy);

			if (purple_presence_is_status_primitive_active(presence, PURPLE_STATUS_MOOD))
				icq_im_xstatus_request(od, userinfo.bn);
		}
	}
	aim_info_free(&userinfo);

	return ret;
}
Beispiel #2
0
static void request_set_buddy_icon(PurpleConnection *gc, gint face_num)
{
	PurpleAccount *account = purple_connection_get_account(gc);
	PurplePresence *presence = purple_account_get_presence(account);
	qq_data *qd = (qq_data *) gc->proto_data;
	gint offset;

	if(purple_presence_is_status_primitive_active(presence, PURPLE_STATUS_INVISIBLE)) {
		offset = 2;
	} else if(purple_presence_is_status_primitive_active(presence, PURPLE_STATUS_AWAY)
			|| purple_presence_is_status_primitive_active(presence, PURPLE_STATUS_EXTENDED_AWAY)) {
		offset = 1;
	} else {
		offset = 0;
	}

	qd->my_icon = 3 * (face_num - 1) + offset;
	qq_request_buddy_info(gc, qd->uid, 0, QQ_BUDDY_INFO_SET_ICON);
}
Beispiel #3
0
/**
 * Set the currently playing song artist and or title.
 *
 * @param user User associated with the now playing information.
 *
 * @param new_artist New artist to set, or NULL/empty to not change artist.
 *
 * @param new_title New title to set, or NULL/empty to not change title.
 *
 * If new_artist and new_title are NULL/empty, deactivate PURPLE_STATUS_TUNE.
 *
 * This function is useful because it lets you set the artist or title
 * individually, which purple_prpl_got_user_status() doesn't do.
 */
static void msim_set_artist_or_title(MsimUser *user, const char *new_artist, const char *new_title)
{
    PurplePresence *presence;
    const char *prev_artist, *prev_title;

    if (user->buddy == NULL)
        /* User not on buddy list so nothing to do */
        return;

    prev_artist = NULL;
    prev_title = NULL;

    if (new_artist && !*new_artist)
        new_artist = NULL;
    if (new_title && !*new_title)
        new_title = NULL;

    if (!new_artist && !new_title) {
        purple_prpl_got_user_status_deactive(user->buddy->account, user->buddy->name, "tune");
        return;
    }

    presence = purple_buddy_get_presence(user->buddy);

    if (purple_presence_is_status_primitive_active(presence, PURPLE_STATUS_TUNE)) {
        PurpleStatus *status;

        status = purple_presence_get_status(presence, "tune");
        prev_title = purple_status_get_attr_string(status, PURPLE_TUNE_TITLE);
        prev_artist = purple_status_get_attr_string(status, PURPLE_TUNE_ARTIST);
    }

    if (!new_artist)
        new_artist = prev_artist;

    if (!new_title)
        new_title = prev_title;

    purple_prpl_got_user_status(user->buddy->account, user->buddy->name, "tune",
                                PURPLE_TUNE_TITLE, new_title,
                                PURPLE_TUNE_ARTIST, new_artist,
                                NULL);
}
Beispiel #4
0
Data IMInvoker::buddyToData(PurpleBuddy *buddy) {
	Data data;
	std::string buddyName = purple_buddy_get_name(buddy);

	if (purple_buddy_get_name(buddy))          data.compound["name"] = Data(purple_buddy_get_name(buddy), Data::VERBATIM);
	if (purple_buddy_get_alias(buddy))         data.compound["alias"] = Data(purple_buddy_get_alias(buddy), Data::VERBATIM);
	if (purple_buddy_get_alias_only(buddy))    data.compound["aliasOnly"] = Data(purple_buddy_get_alias_only(buddy), Data::VERBATIM);
	if (purple_buddy_get_server_alias(buddy))  data.compound["server"] = Data(purple_buddy_get_server_alias(buddy), Data::VERBATIM);

	PurpleGroup* group = purple_buddy_get_group(buddy);
	if (group) {
		if (purple_group_get_name(group))        data.compound["group"] = Data(purple_group_get_name(group), Data::VERBATIM);
	}

	PurpleBuddyIcon* icon = purple_buddy_get_icon(buddy);
	if (icon) {
		size_t iconSize = 0;
		gconstpointer iconData = purple_buddy_icon_get_data(icon, &iconSize);
		data.compound["icon"] = Data((char*)iconData, iconSize, "application/octet-stream", false);
	}

	PurplePresence* presence = purple_buddy_get_presence(buddy);

	if (presence) {
		GList *statusElem;
		GList *statusList = purple_presence_get_statuses(presence);
		PurpleStatus* status;

		for(statusElem = statusList; statusElem; statusElem = statusElem->next) {
			status = (PurpleStatus*)statusElem->data;
			const char* statusId = purple_status_get_id(status);
			PurpleStatusPrimitive statusPrimitive = purple_primitive_get_type_from_id(statusId);

			// only include active states
			if(statusPrimitive == PURPLE_STATUS_UNSET || !purple_presence_is_status_primitive_active(presence, statusPrimitive))
				continue;
			data.compound["status"].compound[statusId] = statusToData(status);
		}
	}

	return data;
}
Beispiel #5
0
static void qq_login(PurpleAccount *account)
{
	PurpleConnection *gc;
	qq_data *qd;
	PurplePresence *presence;
	const gchar *version_str;

	g_return_if_fail(account != NULL);

	gc = purple_account_get_connection(account);
	g_return_if_fail(gc != NULL);

	gc->flags |= PURPLE_CONNECTION_HTML | PURPLE_CONNECTION_NO_BGCOLOR | PURPLE_CONNECTION_AUTO_RESP;

	qd = g_new0(qq_data, 1);
	memset(qd, 0, sizeof(qq_data));
	qd->gc = gc;
	gc->proto_data = qd;

	presence = purple_account_get_presence(account);
	if(purple_presence_is_status_primitive_active(presence, PURPLE_STATUS_INVISIBLE)) {
		qd->login_mode = QQ_LOGIN_MODE_HIDDEN;
	} else if(purple_presence_is_status_primitive_active(presence, PURPLE_STATUS_AWAY)
			|| purple_presence_is_status_primitive_active(presence, PURPLE_STATUS_EXTENDED_AWAY)) {
		qd->login_mode = QQ_LOGIN_MODE_AWAY;
	} else {
		qd->login_mode = QQ_LOGIN_MODE_NORMAL;
	}

	server_list_create(account);
	purple_debug_info("QQ", "Server list has %d\n", g_list_length(qd->servers));

	version_str = purple_account_get_string(account, "client_version", NULL);
	qd->client_tag = QQ_CLIENT_2227;	/* set default as QQ2011 */
	qd->client_version = 2011;
	if (version_str != NULL && strlen(version_str) != 0) {
		if (strcmp(version_str, "qq2010") == 0) {
			qd->client_tag = QQ_CLIENT_1E0D;
			qd->client_version = 2010;
		}
		if (strcmp(version_str, "qq2011") == 0) {
			qd->client_tag = QQ_CLIENT_2227;
			qd->client_version = 2011;
		}
		if (strcmp(version_str, "qq2012") == 0) {
			qd->client_tag = QQ_CLIENT_2227;
			qd->client_version = 2012;
		}
	}


	qd->is_show_notice = purple_account_get_bool(account, "show_notice", TRUE);
	qd->is_show_news = purple_account_get_bool(account, "show_news", TRUE);
	qd->is_show_chat = purple_account_get_bool(account, "show_chat", TRUE);

	qd->resend_times = purple_prefs_get_int("/plugins/prpl/qq/resend_times");
	if (qd->resend_times <= 1) qd->itv_config.resend = 4;

	qd->itv_config.resend = purple_prefs_get_int("/plugins/prpl/qq/resend_interval");
	if (qd->itv_config.resend <= 0) qd->itv_config.resend = 4;
	purple_debug_info("QQ", "Resend interval %d, retries %d\n",
			qd->itv_config.resend, qd->resend_times);

	qd->itv_config.keep_alive = purple_account_get_int(account, "keep_alive_interval", 60);
	if (qd->itv_config.keep_alive < 30) qd->itv_config.keep_alive = 40;
	qd->itv_config.keep_alive /= qd->itv_config.resend;
	qd->itv_count.keep_alive = qd->itv_config.keep_alive;

	qd->itv_config.update = purple_account_get_int(account, "update_interval", 300);
	if (qd->itv_config.update > 0) {
		if (qd->itv_config.update < qd->itv_config.keep_alive) {
			qd->itv_config.update = qd->itv_config.keep_alive;
		}
		qd->itv_config.update /= qd->itv_config.resend;
		qd->itv_count.update = qd->itv_config.update;
	} else {
		qd->itv_config.update = 0;
	}

	qd->connect_watcher = purple_timeout_add_seconds(0, qq_connect_later, gc);
}
Beispiel #6
0
/**
 * Append user information to a PurpleNotifyUserInfo, given an MsimUser.
 * Used by msim_tooltip_text() and msim_get_info_cb() to show a user's profile.
 */
void
msim_append_user_info(MsimSession *session, PurpleNotifyUserInfo *user_info, MsimUser *user, gboolean full)
{
    PurplePresence *presence;
    gchar *str;
    guint cv;

    /* Useful to identify the account the tooltip refers to.
     *  Other prpls show this. */
    if (user->username) {
        purple_notify_user_info_add_pair(user_info, _("User"), user->username);
    }

    /* a/s/l...the vitals */
    if (user->age) {
        char age[16];
        g_snprintf(age, sizeof(age), "%d", user->age);
        purple_notify_user_info_add_pair(user_info, _("Age"), age);
    }

    if (user->gender && *user->gender) {
        purple_notify_user_info_add_pair(user_info, _("Gender"), user->gender);
    }

    if (user->location && *user->location) {
        purple_notify_user_info_add_pair(user_info, _("Location"), user->location);
    }

    /* Other information */
    if (user->headline && *user->headline) {
        purple_notify_user_info_add_pair(user_info, _("Headline"), user->headline);
    }

    if (user->buddy != NULL) {
        presence = purple_buddy_get_presence(user->buddy);

        if (purple_presence_is_status_primitive_active(presence, PURPLE_STATUS_TUNE)) {
            PurpleStatus *status;
            const char *artist, *title;

            status = purple_presence_get_status(presence, "tune");
            title = purple_status_get_attr_string(status, PURPLE_TUNE_TITLE);
            artist = purple_status_get_attr_string(status, PURPLE_TUNE_ARTIST);

            str = msim_format_now_playing(artist, title);
            if (str && *str) {
                purple_notify_user_info_add_pair(user_info, _("Song"), str);
            }
            g_free(str);
        }
    }

    /* Note: total friends only available if looked up by uid, not username. */
    if (user->total_friends) {
        char friends[16];
        g_snprintf(friends, sizeof(friends), "%d", user->total_friends);
        purple_notify_user_info_add_pair(user_info, _("Total Friends"), friends);
    }

    if (full) {
        /* Client information */
        char *client = NULL;

        str = user->client_info;
        cv = user->client_cv;

        if (str && cv != 0) {
            client = g_strdup_printf("%s (build %d)", str, cv);
        } else if (str) {
            client = g_strdup(str);
        } else if (cv) {
            client = g_strdup_printf("Build %d", cv);
        }
        if (client && *client)
            purple_notify_user_info_add_pair(user_info, _("Client Version"), client);
        g_free(client);
    }

    if (full && user->id) {
        /* TODO: link to username, if available */
        char *profile;
        purple_notify_user_info_add_section_break(user_info);
        if (user->buddy != NULL)
            profile = g_strdup_printf("<a href=\"http://myspace.com/%s\">%s</a>",
                                      purple_buddy_get_name(user->buddy), _("View web profile"));
        else
            profile = g_strdup_printf("<a href=\"http://myspace.com/%d\">%s</a>",
                                      user->id, _("View web profile"));
        purple_notify_user_info_add_pair(user_info, NULL, profile);
        g_free(profile);
    }
}