Пример #1
0
PurpleAccount *
purple_accounts_find_ext(const char *name, const char *protocol_id,
                         gboolean (*account_test)(const PurpleAccount *account))
{
    PurpleAccount *result = NULL;
    GList *l;
    char *who;

    if (name)
        who = g_strdup(purple_normalize(NULL, name));
    else
        who = NULL;

    for (l = purple_accounts_get_all(); l != NULL; l = l->next) {
        PurpleAccount *account = (PurpleAccount *)l->data;

        if (who && strcmp(purple_normalize(NULL, purple_account_get_username(account)), who))
            continue;

        if (protocol_id && strcmp(account->protocol_id, protocol_id))
            continue;

        if (account_test && !account_test(account))
            continue;

        result = account;
        break;
    }

    g_free(who);

    return result;
}
Пример #2
0
void
_purple_conversations_update_cache(PurpleConversation *conv, const char *name,
		PurpleAccount *account)
{
	PurpleAccount *old_account;
	struct _purple_hconv *hc;

	g_return_if_fail(conv != NULL);
	g_return_if_fail(account != NULL || name != NULL);

	old_account = purple_conversation_get_account(conv);

	hc = g_new(struct _purple_hconv, 1);
	hc->im = PURPLE_IS_IM_CONVERSATION(conv);
	hc->account = old_account;
	hc->name = (gchar *)purple_normalize(old_account,
				purple_conversation_get_name(conv));

	g_hash_table_remove(conversation_cache, hc);

	if (account)
		hc->account = account;
	if (name)
		hc->name = g_strdup(purple_normalize(hc->account, name));

	g_hash_table_insert(conversation_cache, hc, conv);
}
Пример #3
0
gboolean
purple_privacy_check(PurpleAccount *account, const char *who)
{
	GSList *list;

	switch (account->perm_deny) {
		case PURPLE_PRIVACY_ALLOW_ALL:
			return TRUE;

		case PURPLE_PRIVACY_DENY_ALL:
			return FALSE;

		case PURPLE_PRIVACY_ALLOW_USERS:
			who = purple_normalize(account, who);
			for (list=account->permit; list!=NULL; list=list->next) {
				if (!purple_utf8_strcasecmp(who, (char *)list->data))
					return TRUE;
			}
			return FALSE;

		case PURPLE_PRIVACY_DENY_USERS:
			who = purple_normalize(account, who);
			for (list=account->deny; list!=NULL; list=list->next) {
				if (!purple_utf8_strcasecmp(who, (char *)list->data ))
					return FALSE;
			}
			return TRUE;

		case PURPLE_PRIVACY_ALLOW_BUDDYLIST:
			return (purple_find_buddy(account, who) != NULL);

		default:
			g_return_val_if_reached(TRUE);
	}
}
Пример #4
0
char *
gevo_get_email_for_buddy(PurpleBuddy *buddy)
{
	EContact *contact;
	char *mail = NULL;

	contact = gevo_search_buddy_in_contacts(buddy, NULL);

	if (contact != NULL)
	{
		mail = g_strdup(e_contact_get(contact, E_CONTACT_EMAIL_1));
		g_object_unref(contact);
	}

	if (mail == NULL)
	{
		PurpleAccount *account = purple_buddy_get_account(buddy);
		const char *prpl_id = purple_account_get_protocol_id(account);

		if (!strcmp(prpl_id, "prpl-msn"))
		{
			mail = g_strdup(purple_normalize(account,
										   purple_buddy_get_name(buddy)));
		}
		else if (!strcmp(prpl_id, "prpl-yahoo"))
		{
			mail = g_strdup_printf("*****@*****.**",
								   purple_normalize(account,
												  purple_buddy_get_name(buddy)));
		}
	}

	return mail;
}
Пример #5
0
static gboolean log_viewer_equal(gconstpointer y, gconstpointer z)
{
	const struct log_viewer_hash_t *a, *b;
	int ret;
	char *normal;

	a = y;
	b = z;

	if (a->contact != NULL) {
		if (b->contact != NULL)
			return (a->contact == b->contact);
		else
			return FALSE;
	} else {
		if (b->contact != NULL)
			return FALSE;
	}

	normal = g_strdup(purple_normalize(a->account, a->screenname));
	ret = (a->account == b->account) &&
		!strcmp(normal, purple_normalize(b->account, b->screenname));
	g_free(normal);

	return ret;
}
Пример #6
0
PurplePounce *
purple_find_pounce(const PurpleAccount *pouncer, const char *pouncee,
				 PurplePounceEvent events)
{
	PurplePounce *pounce = NULL;
	GList *l;
	char *norm_pouncee;

	g_return_val_if_fail(pouncer != NULL, NULL);
	g_return_val_if_fail(pouncee != NULL, NULL);
	g_return_val_if_fail(events  != PURPLE_POUNCE_NONE, NULL);

	norm_pouncee = g_strdup(purple_normalize(pouncer, pouncee));

	for (l = purple_pounces_get_all(); l != NULL; l = l->next)
	{
		pounce = (PurplePounce *)l->data;

		if ((purple_pounce_get_events(pounce) & events) &&
			(purple_pounce_get_pouncer(pounce) == pouncer) &&
			!purple_utf8_strcasecmp(purple_normalize(pouncer, purple_pounce_get_pouncee(pounce)),
								  norm_pouncee))
		{
			break;
		}

		pounce = NULL;
	}

	g_free(norm_pouncee);

	return pounce;
}
Пример #7
0
static gboolean
chat_nick_matches_name(PurpleConversation *conv, const char *aname)
{
	PurpleConvChat *chat = NULL;
	char *nick = NULL;
	char *name = NULL;
	gboolean ret = FALSE;
	PurpleAccount *account;

	chat = purple_conversation_get_chat_data(conv);
	if (chat == NULL)
		return ret;

	account = purple_conversation_get_account(conv);
	nick = g_strdup(purple_normalize(account, chat->nick));
	name = g_strdup(purple_normalize(account, aname));

	if (g_utf8_collate(nick, name) == 0)
		ret = TRUE;

	g_free(nick);
	g_free(name);

	return ret;
}
Пример #8
0
static TwitterConvIcon *twitter_conv_icon_find(PurpleAccount * account, const char *who)
{
    PurpleConnection *gc = purple_account_get_connection(account);
    PurpleBuddyIcon *buddy_icon;
    TwitterConvIcon *conv_icon;
    TwitterConnectionData *twitter;

    if (!gc) {
        return NULL;
    }
    twitter = gc->proto_data;

    if (!twitter) {
        return NULL;
    }

    purple_debug_info(PLUGIN_ID, "Looking up %s\n", who);
    conv_icon = g_hash_table_lookup(twitter->icons, purple_normalize(account, who));
    if ((!conv_icon || !conv_icon->pixbuf) && (buddy_icon = purple_buddy_icons_find(account, who))) {
        if (!conv_icon) {
            if ((conv_icon = buddy_icon_to_conv_icon(buddy_icon)))
                g_hash_table_insert(twitter->icons, g_strdup(purple_normalize(account, who)), conv_icon);
        } else {
            conv_icon_set_buddy_icon_data(conv_icon, buddy_icon);
        }
        purple_buddy_icon_unref(buddy_icon);
    }
    return conv_icon;                            //may be NULL
}
static void
yahoo_xfer_init_15(PurpleXfer *xfer)
{
	struct yahoo_xfer_data *xfer_data;
	PurpleConnection *gc;
	PurpleAccount *account;
	YahooData *yd;
	struct yahoo_packet *pkt;

	xfer_data = purple_xfer_get_protocol_data(xfer);
	gc = xfer_data->gc;
	yd = purple_connection_get_protocol_data(gc);
	account = purple_connection_get_account(gc);

	if (purple_xfer_get_xfer_type(xfer) == PURPLE_XFER_TYPE_SEND)	{
		gchar *filename;
		filename = g_path_get_basename(purple_xfer_get_local_filename(xfer));
		pkt = yahoo_packet_new(YAHOO_SERVICE_FILETRANS_15,
							   YAHOO_STATUS_AVAILABLE,
							   yd->session_id);
		yahoo_packet_hash(pkt, "sssiiiisiii",
			1, purple_normalize(account, purple_account_get_username(account)),
			5, purple_xfer_get_remote_user(xfer),
			265, xfer_data->xfer_peer_idstring,
			222, 1,
			266, 1,
			302, 268,
			300, 268,
			27,  filename,
			28,  (int)purple_xfer_get_size(xfer),
			301, 268,
			303, 268);
		g_free(filename);
	} else {
		if(xfer_data->firstoflist == TRUE) {
			pkt = yahoo_packet_new(YAHOO_SERVICE_FILETRANS_15,
				YAHOO_STATUS_AVAILABLE, yd->session_id);

			yahoo_packet_hash(pkt, "sssi",
				1, purple_normalize(account, purple_account_get_username(account)),
				5, purple_xfer_get_remote_user(xfer),
				265, xfer_data->xfer_peer_idstring,
				222, 3);
		} else {
			pkt = yahoo_packet_new(YAHOO_SERVICE_FILETRANS_ACC_15,
				YAHOO_STATUS_AVAILABLE, yd->session_id);

			yahoo_packet_hash(pkt, "sssi",
				1, purple_normalize(account, purple_account_get_username(account)),
				5, purple_xfer_get_remote_user(xfer),
				265, xfer_data->xfer_peer_idstring,
				271, 1);
		}
	}
	yahoo_packet_send_and_free(pkt, yd);
}
Пример #10
0
static void
yahoo_xfer_cancel_recv(PurpleXfer *xfer)
{
	struct yahoo_xfer_data *xfer_data;

	xfer_data = purple_xfer_get_protocol_data(xfer);

	if(purple_xfer_get_status(xfer) == PURPLE_XFER_STATUS_CANCEL_LOCAL)
	{

		PurpleConnection *gc;
		PurpleAccount *account;
		YahooData *yd;
		struct yahoo_packet *pkt;

		gc = xfer_data->gc;
		yd = purple_connection_get_protocol_data(gc);
		account = purple_connection_get_account(gc);
		if(!xfer_data->xfer_idstring_for_relay) /* hack to see if file trans acc/info packet has been received */
		{
			pkt = yahoo_packet_new(YAHOO_SERVICE_FILETRANS_15,
								   YAHOO_STATUS_AVAILABLE,
								   yd->session_id);
			yahoo_packet_hash(pkt, "sssi",
				1, purple_normalize(account, purple_account_get_username(account)),
				5, purple_xfer_get_remote_user(xfer),
				265, xfer_data->xfer_peer_idstring,
				222, 4);
		}
		else
		{
			pkt = yahoo_packet_new(YAHOO_SERVICE_FILETRANS_15,
								   YAHOO_STATUS_DISCONNECTED,
								   yd->session_id);
			yahoo_packet_hash(pkt, "sssi",
				1, purple_normalize(account, purple_account_get_username(account)),
				5, purple_xfer_get_remote_user(xfer),
				265, xfer_data->xfer_peer_idstring,
				66, -1);
		}
		yahoo_packet_send_and_free(pkt, yd);
	}

	if (xfer_data) {
		purple_http_conn_cancel(xfer_data->hc);
		yahoo_xfer_data_free(xfer_data);
	}
	purple_xfer_set_protocol_data(xfer, NULL);
}
Пример #11
0
static PurpleXmlNode *
pounce_to_xmlnode(PurplePounce *pounce)
{
	PurpleXmlNode *node, *child;
	PurpleAccount *pouncer;
	PurplePounceEvent events;
	PurplePounceOption options;

	pouncer = purple_pounce_get_pouncer(pounce);
	events  = purple_pounce_get_events(pounce);
	options = purple_pounce_get_options(pounce);

	node = purple_xmlnode_new("pounce");
	purple_xmlnode_set_attrib(node, "ui", pounce->ui_type);

	child = purple_xmlnode_new_child(node, "account");
	purple_xmlnode_set_attrib(child, "protocol", purple_account_get_protocol_id(pouncer));
	purple_xmlnode_insert_data(child,
			purple_normalize(pouncer, purple_account_get_username(pouncer)), -1);

	child = purple_xmlnode_new_child(node, "pouncee");
	purple_xmlnode_insert_data(child, purple_pounce_get_pouncee(pounce), -1);

	/* Write pounce options */
	child = purple_xmlnode_new_child(node, "options");
	if (options & PURPLE_POUNCE_OPTION_AWAY)
		add_option_to_xmlnode(child, "on-away");

	/* Write pounce events */
	child = purple_xmlnode_new_child(node, "events");
	if (events & PURPLE_POUNCE_SIGNON)
		add_event_to_xmlnode(child, "sign-on");
	if (events & PURPLE_POUNCE_SIGNOFF)
		add_event_to_xmlnode(child, "sign-off");
	if (events & PURPLE_POUNCE_AWAY)
		add_event_to_xmlnode(child, "away");
	if (events & PURPLE_POUNCE_AWAY_RETURN)
		add_event_to_xmlnode(child, "return-from-away");
	if (events & PURPLE_POUNCE_IDLE)
		add_event_to_xmlnode(child, "idle");
	if (events & PURPLE_POUNCE_IDLE_RETURN)
		add_event_to_xmlnode(child, "return-from-idle");
	if (events & PURPLE_POUNCE_TYPING)
		add_event_to_xmlnode(child, "start-typing");
	if (events & PURPLE_POUNCE_TYPED)
		add_event_to_xmlnode(child, "typed");
	if (events & PURPLE_POUNCE_TYPING_STOPPED)
		add_event_to_xmlnode(child, "stop-typing");
	if (events & PURPLE_POUNCE_MESSAGE_RECEIVED)
		add_event_to_xmlnode(child, "message-received");

	/* Write pounce actions */
	child = purple_xmlnode_new_child(node, "actions");
	g_hash_table_foreach(pounce->actions, action_parameter_list_to_xmlnode, child);

	if (purple_pounce_get_save(pounce))
		purple_xmlnode_new_child(node, "save");

	return node;
}
Пример #12
0
static char *
userinfo_hash(PurpleAccount *account, const char *who)
{
	char key[256];
	g_snprintf(key, sizeof(key), "%s - %s", purple_account_get_username(account), purple_normalize(account, who));
	return g_utf8_strup(key, -1);
}
Пример #13
0
static TwitterConvIcon *twitter_conv_icon_new(PurpleAccount * account, const gchar * username)
{
    TwitterConvIcon *conv_icon = g_new0(TwitterConvIcon, 1);
    conv_icon->username = g_strdup(purple_normalize(account, username));
    purple_debug_info(PLUGIN_ID, "Created conv icon %s\n", conv_icon->username);
    return conv_icon;
}
Пример #14
0
void twitter_conv_icon_got_buddy_icon(PurpleAccount * account, const char *user_name, PurpleBuddyIcon * buddy_icon)
{
    PurpleConnection *gc = purple_account_get_connection(account);
    TwitterConnectionData *twitter;
    TwitterConvIcon *conv_icon;

    if (!gc) {
        return;
    }

    twitter = gc->proto_data;

    if (!twitter) {
        return;
    }
    conv_icon = g_hash_table_lookup(twitter->icons, purple_normalize(account, user_name));

    if (!conv_icon) {
        return;
    }

    if (!conv_icon->request_list) {
        conv_icon_clear(conv_icon);
    } else {
        conv_icon_set_buddy_icon_data(conv_icon, buddy_icon);
    }

    if (conv_icon->pixbuf)
        insert_requested_icon(conv_icon);
}
Пример #15
0
void
purple_conversations_add(PurpleConversation *conv)
{
	PurpleAccount *account;
	struct _purple_hconv *hc;

	g_return_if_fail(conv != NULL);

	if (g_list_find(conversations, conv) != NULL)
		return;

	conversations = g_list_prepend(conversations, conv);

	if (PURPLE_IS_IM_CONVERSATION(conv))
		ims = g_list_prepend(ims, conv);
	else
		chats = g_list_prepend(chats, conv);

	account = purple_conversation_get_account(conv);

	hc = g_new(struct _purple_hconv, 1);
	hc->name = g_strdup(purple_normalize(account,
				purple_conversation_get_name(conv)));
	hc->account = account;
	hc->im = PURPLE_IS_IM_CONVERSATION(conv);

	g_hash_table_insert(conversation_cache, hc, conv);
}
Пример #16
0
void msn_sbconn_send_part(MsnSlpLink *slplink, MsnSlpMessagePart *part)
{
	MsnMessage *msg;
	const char *passport;
	char *data;
	size_t size;

	msg = msn_message_new_msnslp();

	passport = purple_normalize(slplink->session->account, slplink->remote_user);
	msn_message_set_header(msg, "P2P-Dest", passport);

	msg->part = msn_slpmsgpart_ref(part);
	data = msn_slpmsgpart_serialize(part, &size);
	msn_message_set_bin_data(msg, data, size);
	g_free(data);

	if (slplink->swboard == NULL)
	{
		slplink->swboard = msn_session_get_swboard(slplink->session,
				slplink->remote_user, MSN_SB_FLAG_FT);

		g_return_if_fail(slplink->swboard != NULL);

		/* If swboard is destroyed we will be too */
		slplink->swboard->slplinks = g_list_prepend(slplink->swboard->slplinks, slplink);
	}

	msn_switchboard_send_msg(slplink->swboard, msg, TRUE);
	msn_message_unref(msg);
}
Пример #17
0
GList *
otrg_conversation_get_contexts(PurpleConversation *conv)
{
	PurpleAccount *account;
	const gchar *accountname, *protocol;
	gchar *username;
	ConnContext *it = NULL;
	GList *contexts = NULL;

	g_return_val_if_fail(conv != NULL, NULL);

	g_return_val_if_fail(PURPLE_IS_IM_CONVERSATION(conv), NULL);

	account = purple_conversation_get_account(conv);
	accountname = purple_account_get_username(account);
	protocol = purple_account_get_protocol_id(account);
	username = g_strdup(purple_normalize(account,
		purple_conversation_get_name(conv)));

	for (it = otrg_plugin_userstate->context_root; it; it = it->next) {
		if (g_strcmp0(it->accountname, accountname) != 0)
			continue;
		if (g_strcmp0(it->protocol, protocol) != 0)
			continue;
		if (g_strcmp0(it->username, username) != 0)
			continue;
		contexts = g_list_append(contexts, it);
	}

	g_free(username);

	return contexts;
}
Пример #18
0
void twitter_conv_icon_got_user_icon(PurpleAccount * account, const char *user_name, const gchar * url, time_t icon_time)
{
    /* look local icon cache for the requested icon */
    PurpleConnection *gc = purple_account_get_connection(account);
    TwitterConnectionData *twitter = gc->proto_data;
    TwitterConvIcon *conv_icon = NULL;
    GHashTable     *hash = twitter->icons;

    if (!hash)
        return;

    /* since this function is called after mark_icon_for_user(), data
     * must exist here. */
    conv_icon = twitter_conv_icon_find(account, user_name);
    if (!conv_icon) {
        conv_icon = twitter_conv_icon_new(account, user_name);
        g_hash_table_insert(hash, g_strdup(purple_normalize(account, user_name)), conv_icon);
        conv_icon->mtime = icon_time;
    } else {
        //A new icon is one posted with a tweet later than the current saved icon time
        //and with a different url
        gboolean        new_icon = !conv_icon->icon_url || (strcmp(url, conv_icon->icon_url) && icon_time > conv_icon->mtime);

        purple_debug_info(PLUGIN_ID, "Have icon %s (%lld) for user %s, looking for %s (%lld)\n", conv_icon->icon_url, (long long int) conv_icon->mtime, user_name, url, (long long int) icon_time);

        if (icon_time > conv_icon->mtime)
            conv_icon->mtime = icon_time;

        //Return if the image is cached already and it's the same one
        if (conv_icon->pixbuf && !new_icon)
            return;

        /* Return if user's icon has been requested already. */
        if (conv_icon->requested && !new_icon)
            return;

        //If we're already requesting, but it's a different url, cancel the fetch
        if (conv_icon->fetch_data)
            purple_util_fetch_url_cancel(conv_icon->fetch_data);

        conv_icon_clear(conv_icon);
    }

    conv_icon->icon_url = g_strdup(url);

    //For buddies, we don't want to retrieve the icon here, we'll
    //let the twitter_buddy fetch the icon and let us know when it's done
    if (purple_find_buddy(account, user_name))
        return;

    conv_icon->requested = TRUE;

    /* Create the URL for an user's icon. */
    if (url) {
        BuddyIconContext *ctx = twitter_buddy_icon_context_new(account, user_name, url);
        purple_debug_info(PLUGIN_ID, "requesting %s for %s\n", url, user_name);
        conv_icon->fetch_data = purple_util_fetch_url_request_len_with_account(account, url, TRUE, NULL, FALSE, NULL, TRUE, -1, got_page_cb, ctx);
    }
}
Пример #19
0
static BuddyIconContext *twitter_buddy_icon_context_new(PurpleAccount * account, const gchar * buddy_name, const gchar * url)
{
    BuddyIconContext *ctx = g_new0(BuddyIconContext, 1);
    ctx->account = account;
    ctx->buddy_name = g_strdup(purple_normalize(account, buddy_name));
    ctx->url = g_strdup(url);
    return ctx;
}
Пример #20
0
void
purple_pounce_execute(const PurpleAccount *pouncer, const char *pouncee,
					PurplePounceEvent events)
{
	PurplePounce *pounce;
	PurplePounceHandler *handler;
	PurplePresence *presence;
	GList *l, *l_next;
	char *norm_pouncee;

	g_return_if_fail(pouncer != NULL);
	g_return_if_fail(pouncee != NULL);
	g_return_if_fail(events  != PURPLE_POUNCE_NONE);

	norm_pouncee = g_strdup(purple_normalize(pouncer, pouncee));

	for (l = purple_pounces_get_all(); l != NULL; l = l_next)
	{
		pounce = (PurplePounce *)l->data;
		l_next = l->next;

		presence = purple_account_get_presence(pouncer);

		if ((purple_pounce_get_events(pounce) & events) &&
			(purple_pounce_get_pouncer(pounce) == pouncer) &&
			!purple_utf8_strcasecmp(purple_normalize(pouncer, purple_pounce_get_pouncee(pounce)),
								  norm_pouncee) &&
			(pounce->options == PURPLE_POUNCE_OPTION_NONE ||
			 (pounce->options & PURPLE_POUNCE_OPTION_AWAY &&
			  !purple_presence_is_available(presence))))
		{
			handler = g_hash_table_lookup(pounce_handlers, pounce->ui_type);

			if (handler != NULL && handler->cb != NULL)
			{
				handler->cb(pounce, events, purple_pounce_get_data(pounce));

				if (!purple_pounce_get_save(pounce))
					purple_pounce_destroy(pounce);
			}
		}
	}

	g_free(norm_pouncee);
}
Пример #21
0
static void
msn_slplink_release_slpmsg(MsnSlpLink *slplink, MsnSlpMessage *slpmsg)
{
	MsnMessage *msg;
	const char *passport;

	slpmsg->msg = msg = msn_message_new_msnslp();

	if (slpmsg->flags == 0x0)
	{
		msg->msnslp_header.session_id = slpmsg->session_id;
		msg->msnslp_header.ack_id = rand() % 0xFFFFFF00;
	}
	else if (slpmsg->flags == 0x2)
	{
		msg->msnslp_header.session_id = slpmsg->session_id;
		msg->msnslp_header.ack_id = slpmsg->ack_id;
		msg->msnslp_header.ack_size = slpmsg->ack_size;
		msg->msnslp_header.ack_sub_id = slpmsg->ack_sub_id;
	}
	else if (slpmsg->flags == 0x20 ||
	         slpmsg->flags == 0x1000020 || slpmsg->flags == 0x1000030)
	{
		MsnSlpCall *slpcall;
		slpcall = slpmsg->slpcall;

		g_return_if_fail(slpcall != NULL);
		msg->msnslp_header.session_id = slpcall->session_id;
		msg->msnslp_footer.value = slpcall->app_id;
		msg->msnslp_header.ack_id = rand() % 0xFFFFFF00;
	}
	else if (slpmsg->flags == 0x100)
	{
		msg->msnslp_header.ack_id     = slpmsg->ack_id;
		msg->msnslp_header.ack_sub_id = slpmsg->ack_sub_id;
		msg->msnslp_header.ack_size   = slpmsg->ack_size;
	}

	msg->msnslp_header.id = slpmsg->id;
	msg->msnslp_header.flags = slpmsg->flags;

	msg->msnslp_header.total_size = slpmsg->size;

	passport = purple_normalize(slplink->session->account, slplink->remote_user);
	msn_message_set_attr(msg, "P2P-Dest", passport);

	msg->ack_cb = msg_ack;
	msg->nak_cb = msg_nak;
	msg->ack_data = slpmsg;

	msn_slplink_send_msgpart(slplink, slpmsg);

	msn_message_destroy(msg);
}
Пример #22
0
static void twitter_conv_icon_displayed_chat_cb(PurpleAccount * account, const char *who, char *message, PurpleConversation * conv, PurpleMessageFlags flags, void *account_signal)
{
    GtkIMHtml      *imhtml;
    GtkTextBuffer  *text_buffer;
    GtkTextIter     insertion_point;
    gint            linenumber;
    TwitterConvIcon *conv_icon;
    PurpleConnection *gc;
    TwitterConnectionData *twitter;

    if (account != account_signal)
        return;

    gc = purple_account_get_connection(account);
    if (!gc) {
        return;
    }

    twitter = gc->proto_data;

    purple_debug_info(PLUGIN_ID, "%s\n", G_STRFUNC);

    /* insert icon */
    imhtml = GTK_IMHTML(PIDGIN_CONVERSATION(conv)->imhtml);
    text_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(imhtml));

    /* get GtkTextIter in the target line */
    linenumber = GPOINTER_TO_INT(purple_conversation_get_data(conv, PLUGIN_ID "-icon-ln"));
    gtk_text_buffer_get_iter_at_line(text_buffer, &insertion_point, linenumber);

    conv_icon = twitter_conv_icon_find(account, who);

    /* if we don't have the icon for this user, put a mark instead and
     * request the icon */
    if (!conv_icon) {
        conv_icon = twitter_conv_icon_new(account, who);
        twitter_conv_icon_add_conv(conv_icon, conv);
        g_hash_table_insert(twitter->icons, g_strdup(purple_normalize(account, who)), conv_icon);
        mark_icon_for_user(gtk_text_buffer_create_mark(text_buffer, NULL, &insertion_point, FALSE), conv_icon);
        return;
    }
    twitter_conv_icon_add_conv(conv_icon, conv);

    /* if we have the icon for this user, insert the icon immediately */
    if (TRUE) {
        if (conv_icon->pixbuf) {
            gtk_text_buffer_insert_pixbuf(text_buffer, &insertion_point, conv_icon->pixbuf);
        } else {
            mark_icon_for_user(gtk_text_buffer_create_mark(text_buffer, NULL, &insertion_point, FALSE), conv_icon);
        }
    }

    purple_debug_info(PLUGIN_ID, "end %s\n", G_STRFUNC);
}
Пример #23
0
gboolean
purple_privacy_deny_add(PurpleAccount *account, const char *who,
					  gboolean local_only)
{
	GSList *l;
	char *name;
	PurpleBuddy *buddy;

	g_return_val_if_fail(account != NULL, FALSE);
	g_return_val_if_fail(who     != NULL, FALSE);

	name = g_strdup(purple_normalize(account, who));

	for (l = account->deny; l != NULL; l = l->next) {
		if (!purple_utf8_strcasecmp(name, purple_normalize(account, (char *)l->data)))
			break;
	}

	if (l != NULL)
	{
		g_free(name);
		return FALSE;
	}

	account->deny = g_slist_append(account->deny, name);

	if (!local_only && purple_account_is_connected(account))
		serv_add_deny(purple_account_get_connection(account), who);

	if (privacy_ops != NULL && privacy_ops->deny_added != NULL)
		privacy_ops->deny_added(account, who);

	purple_blist_schedule_save();

	buddy = purple_find_buddy(account, name);
	if (buddy != NULL) {
		purple_signal_emit(purple_blist_get_handle(),
                "buddy-privacy-changed", buddy);
	}
	return TRUE;
}
Пример #24
0
static gboolean
chat_nick_matches_name(PurpleChatConversation *chat, const char *aname)
{
	char *nick = NULL;
	char *name = NULL;
	gboolean ret = FALSE;

	if (chat==NULL)
		return ret;

	nick = g_strdup(purple_normalize(purple_conversation_get_account(
			PURPLE_CONVERSATION(chat)), purple_chat_conversation_get_nick(chat)));
	name = g_strdup(purple_normalize(purple_conversation_get_account(
			PURPLE_CONVERSATION(chat)), aname));

	if (g_utf8_collate(nick, name) == 0)
		ret = TRUE;

	g_free(nick);
	g_free(name);

	return ret;
}
Пример #25
0
xmlnode * _h_elim_send_file ( const char *name ,
                              const char *id   ,
                              SEXP_VALUE *args ,
                              gpointer data    )
{
    ASSERT_ALISTP( args, id, name );

    elim_ping();
    
    const char *aname = ALIST_VAL_STR( args, "account-name" );
    const char *proto = ALIST_VAL_STR( args, "im-protocol"  );
    gpointer    auid  = ALIST_VAL_PTR( args, "account-uid"  );
    
    PurpleAccount *acct = 
      auid ? find_acct_by_uid( auid ) : purple_accounts_find( aname, proto );

    if( !acct )
    {
        sexp_val_free( args );
        return response_error( ENXIO, id, name, "unknown account" );
    }

    PurpleConnection *conn = purple_account_get_connection( acct );

    if( !conn )
    {
        sexp_val_free( args );
        return response_error( ENXIO, id, name, "account not online" );
    }

    // file can be NULL, but that's Ok, it just triggers a req to the user:
    const char *b_arg = ALIST_VAL_STRING( args, "recipient" );
    const char *file  = ALIST_VAL_STRING( args, "filename"  );

    serv_send_file( conn, b_arg, file );

    // bname is a static buf allocated in purple_normalize: don't free it!
    // also, this means that bname is volatile, so use it immediately after
    // acquiring it, if you make any calls into libpurple they might invalidate
    // its state:
    const char *bname = purple_normalize( acct, b_arg );
    xmlnode    *rval  = xnode_new( "alist" );
    AL_PTR( rval, "account-uid" , acct  );
    AL_STR( rval, "recipient"   , bname );

    sexp_val_free( args );
    return response_value( 0, id, name, rval );
}
/*static void
toggle_nickchange_pref(const char *name, PurplePrefType type, gconstpointer val, gpointer data)
{
	
}*/
static void nickchange_chat_rename_user
(PurpleConversation *conv, const char *old_user, const char *new_user, const char *new_alias)
{
	if (!should_hide_notice(conv, old_user, userstable)) {
		PurpleConvChat *chat = PURPLE_CONV_CHAT(conv);
		char tmp[2048];
		
		if (purple_strequal(chat->nick, purple_normalize(conv->account, old_user))) {
			// Its me!
			char *escaped = g_markup_escape_text(new_user, -1);
			g_snprintf(tmp, sizeof(tmp),
					_("You are now known as %s"), escaped);
			g_free(escaped);
		} else {
			const char *old_alias = old_user;
			const char *new_alias = new_user;
			char *escaped;
			char *escaped2;
			PurpleConnection *gc = purple_conversation_get_gc(conv);
			PurplePluginProtocolInfo *prpl_info;
			
			prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(purple_connection_get_prpl(gc));
			if (prpl_info && !(prpl_info->options & OPT_PROTO_UNIQUE_CHATNAME)) {
				PurpleBuddy *buddy;

				if ((buddy = purple_find_buddy(gc->account, old_user)) != NULL)
					old_alias = purple_buddy_get_contact_alias(buddy);
				if ((buddy = purple_find_buddy(gc->account, new_user)) != NULL)
					new_alias = purple_buddy_get_contact_alias(buddy);
			}

			escaped = g_markup_escape_text(old_alias, -1);
			escaped2 = g_markup_escape_text(new_alias, -1);
			g_snprintf(tmp, sizeof(tmp),
					_("%s is now known as %s"), escaped, escaped2);
			g_free(escaped);
			g_free(escaped2);
		}

		purple_conversation_write(conv, NULL, tmp,
				PURPLE_MESSAGE_SYSTEM | PURPLE_MESSAGE_NO_LINKIFY,
				time(NULL));
	}
	
	if (orig_chat_rename_user)
		return orig_chat_rename_user(conv, old_user, new_user, new_alias);
}
Пример #27
0
PurpleChatConversation *
purple_conversations_find_chat_with_account(const char *name,
		const PurpleAccount *account)
{
	PurpleChatConversation *c = NULL;
	struct _purple_hconv hc;

	g_return_val_if_fail(name != NULL, NULL);

	hc.name = (gchar *)purple_normalize(account, name);
	hc.account = account;
	hc.im = FALSE;

	c = g_hash_table_lookup(conversation_cache, &hc);

	return c;
}
Пример #28
0
PurpleIMConversation *
purple_conversations_find_im_with_account(const char *name,
		const PurpleAccount *account)
{
	PurpleIMConversation *im = NULL;
	struct _purple_hconv hc;

	g_return_val_if_fail(name != NULL, NULL);

	hc.name = (gchar *)purple_normalize(account, name);
	hc.account = account;
	hc.im = TRUE;

	im = g_hash_table_lookup(conversation_cache, &hc);

	return im;
}
Пример #29
0
gboolean
purple_privacy_permit_remove(PurpleAccount *account, const char *who,
						   gboolean local_only)
{
	GSList *l;
	const char *name;
	PurpleBuddy *buddy;
	char *del;

	g_return_val_if_fail(account != NULL, FALSE);
	g_return_val_if_fail(who     != NULL, FALSE);

	name = purple_normalize(account, who);

	for (l = account->permit; l != NULL; l = l->next) {
		if (!purple_utf8_strcasecmp(name, (char *)l->data))
			break;
	}

	if (l == NULL)
		return FALSE;

	/* We should not free l->data just yet. There can be occasions where
	 * l->data == who. In such cases, freeing l->data here can cause crashes
	 * later when who is used. */
	del = l->data;
	account->permit = g_slist_delete_link(account->permit, l);

	if (!local_only && purple_account_is_connected(account))
		serv_rem_permit(purple_account_get_connection(account), who);

	if (privacy_ops != NULL && privacy_ops->permit_removed != NULL)
		privacy_ops->permit_removed(account, who);

	purple_blist_schedule_save();

	buddy = purple_find_buddy(account, name);
	if (buddy != NULL) {
		purple_signal_emit(purple_blist_get_handle(),
                "buddy-privacy-changed", buddy);
	}
	g_free(del);
	return TRUE;
}
Пример #30
0
void
msn_session_finish_login(MsnSession *session)
{
	PurpleAccount *account;
	PurpleConnection *gc;
	PurpleStoredImage *img;
	const char *passport;

	if (session->logged_in) {
		/* We are probably here because of a mid-session notification server XFR
		 * We must send a CHG now, otherwise the servers default to invisible,
		 * and prevent things happening, like sending IMs */
		msn_change_status(session);
		return;
	}

	account = session->account;
	gc = purple_account_get_connection(account);

	img = purple_buddy_icons_find_account_icon(session->account);
	msn_user_set_buddy_icon(session->user, img);
	purple_imgstore_unref(img);

	session->logged_in = TRUE;

	msn_change_status(session);

	purple_connection_set_state(gc, PURPLE_CONNECTED);

	/* Sync users */
	msn_session_sync_users(session);
	/* It seems that some accounts that haven't accessed hotmail for a while
	 * and @msn.com accounts don't automatically get the initial email
	 * notification so we always request it on login
	 */

	passport = purple_normalize(account, purple_account_get_username(account));

	if ((strstr(passport, "@hotmail.") != NULL) ||
		(strstr(passport, "@msn.com") != NULL))
	{
		msn_cmdproc_send(session->notification->cmdproc, "URL", "%s", "INBOX");
	}
}