示例#1
0
static gboolean ggp_roster_send_update_contact_remove(PurpleConnection *gc,
	ggp_roster_change *change)
{
	PurpleAccount *account = purple_connection_get_account(gc);
	ggp_roster_content *content = ggp_roster_get_rdata(gc)->content;
	uin_t uin = change->data.uin;
	PurpleBuddy *buddy;
	PurpleXmlNode *buddy_node;

	g_return_val_if_fail(change->type == GGP_ROSTER_CHANGE_CONTACT_REMOVE,
		FALSE);

	buddy = purple_blist_find_buddy(account, ggp_uin_to_str(uin));
	if (buddy) {
		purple_debug_info("gg", "ggp_roster_send_update_contact_remove:"
			" contact %u re-added\n", uin);
		return TRUE;
	}

	buddy_node = g_hash_table_lookup(content->contact_nodes,
		GINT_TO_POINTER(uin));
	if (!buddy_node) /* already removed */
		return TRUE;

	purple_debug_info("gg", "ggp_roster_send_update_contact_remove: "
		"removing %u\n", uin);
	purple_xmlnode_free(buddy_node);
	g_hash_table_remove(content->contact_nodes, GINT_TO_POINTER(uin));

	return TRUE;
}
示例#2
0
void
skypeweb_search_results_add_buddy(PurpleConnection *pc, GList *row, void *user_data)
{
	PurpleAccount *account = purple_connection_get_account(pc);

	if (!purple_blist_find_buddy(account, g_list_nth_data(row, 0)))
		purple_blist_request_add_buddy(account, g_list_nth_data(row, 0), "Skype", g_list_nth_data(row, 1));
}
示例#3
0
PurpleBuddy *
otrg_purple_conversation_get_buddy(PurpleConversation *conv)
{
	if (!PURPLE_IS_IM_CONVERSATION(conv))
		return NULL;

	return purple_blist_find_buddy(
		purple_conversation_get_account(conv),
		purple_conversation_get_name(conv));
}
示例#4
0
const char * ggp_buddylist_get_buddy_name(PurpleConnection *gc, const uin_t uin)
{
	const char *uin_s = ggp_uin_to_str(uin);
	PurpleBuddy *buddy = purple_blist_find_buddy(
		purple_connection_get_account(gc), uin_s);

	if (buddy != NULL)
		return purple_buddy_get_alias(buddy);
	else
		return uin_s;
}
示例#5
0
/*------------------------------------------------------------------------
 * This gets called when a new chat conversation is opened by the user
 *
 *  @param conv				The conversation object
 *  @param session			The MXit session object
 */
static void mxit_cb_chat_created( PurpleConversation* conv, struct MXitSession* session )
{
	PurpleConnection*	gc;
	struct contact*		contact;
	PurpleBuddy*		buddy;
	const char*			who;
	char*				tmp;

	gc = purple_conversation_get_connection( conv );
	if ( session->con != gc ) {
		/* not our conversation */
		return;
	}
	else if ( !PURPLE_IS_IM_CONVERSATION( conv ) ) {
		/* wrong type of conversation */
		return;
	}

	/* get the contact name */
	who = purple_conversation_get_name( conv );
	if ( !who )
		return;

	purple_debug_info( MXIT_PLUGIN_ID, "Conversation started with '%s'\n", who );

	/* find the buddy object */
	buddy = purple_blist_find_buddy( session->acc, who );
	if ( !buddy )
		return;

	contact = purple_buddy_get_protocol_data( buddy );
	if ( !contact )
		return;

	/* we ignore all conversations with which we have chatted with in this session */
	if ( find_active_chat( session->active_chats, who ) )
		return;

	/* determine if this buddy is a MXit service */
	switch ( contact->type ) {
		case MXIT_TYPE_BOT :
		case MXIT_TYPE_CHATROOM :
		case MXIT_TYPE_GALLERY :
		case MXIT_TYPE_INFO :
				tmp = g_strdup_printf("<font color=\"#999999\">%s</font>\n", _( "Loading menu..." ));
				purple_serv_got_im( session->con, who, tmp, PURPLE_MESSAGE_NOTIFY, time( NULL ) );
				g_free( tmp );
				mxit_send_message( session, who, " ", FALSE, FALSE );
		default :
				break;
	}
}
示例#6
0
文件: msg.c 项目: Distrotech/pidgin
static void
datacast_inform_user(MsnSwitchBoard *swboard, const char *who,
                     const char *msg, const char *filename)
{
	char *username, *str;
	PurpleAccount *account;
	PurpleBuddy *b;
	PurpleConnection *pc;
	gboolean chat;

	account = swboard->session->account;
	pc = purple_account_get_connection(account);

	if ((b = purple_blist_find_buddy(account, who)) != NULL)
		username = g_markup_escape_text(purple_buddy_get_alias(b), -1);
	else
		username = g_markup_escape_text(who, -1);
	str = g_strdup_printf(msg, username, filename);
	g_free(username);

	swboard->flag |= MSN_SB_FLAG_IM;
	if (swboard->current_users > 1)
		chat = TRUE;
	else
		chat = FALSE;

	if (swboard->conv == NULL) {
		if (chat)
			swboard->conv = PURPLE_CONVERSATION(purple_conversations_find_chat(
					purple_account_get_connection(account), swboard->chat_id));
		else {
			swboard->conv = PURPLE_CONVERSATION(purple_conversations_find_im_with_account(
									who, account));
			if (swboard->conv == NULL)
				swboard->conv = PURPLE_CONVERSATION(purple_im_conversation_new(account, who));
		}
	}

	if (chat)
		purple_serv_got_chat_in(pc,
		                 purple_chat_conversation_get_id(PURPLE_CHAT_CONVERSATION(swboard->conv)),
		                 who, PURPLE_MESSAGE_RECV|PURPLE_MESSAGE_SYSTEM, str,
		                 time(NULL));
	else
		purple_serv_got_im(pc, who, str, PURPLE_MESSAGE_RECV|PURPLE_MESSAGE_SYSTEM,
		            time(NULL));
	g_free(str);

}
示例#7
0
static void ggp_avatar_buddy_update_received(PurpleHttpConnection *http_conn,
        PurpleHttpResponse *response, gpointer _pending_update)
{
    ggp_avatar_buddy_update_req *pending_update = _pending_update;
    PurpleBuddy *buddy;
    PurpleAccount *account;
    PurpleConnection *gc = pending_update->gc;
    ggp_avatar_session_data *avdata;
    gchar timestamp_str[20];
    const gchar *got_data;
    size_t got_len;

    PURPLE_ASSERT_CONNECTION_IS_VALID(gc);

    avdata = ggp_avatar_get_avdata(gc);
    g_assert(pending_update == avdata->current_update);
    avdata->current_update = NULL;

    if (!purple_http_response_is_successful(response)) {
        purple_debug_error("gg", "ggp_avatar_buddy_update_received: bad"
                           " response while getting avatar for %u: %s\n",
                           pending_update->uin,
                           purple_http_response_get_error(response));
        g_free(pending_update);
        return;
    }

    account = purple_connection_get_account(gc);
    buddy = purple_blist_find_buddy(account, ggp_uin_to_str(pending_update->uin));

    if (!buddy) {
        purple_debug_warning("gg", "ggp_avatar_buddy_update_received: "
                             "buddy %u disappeared\n", pending_update->uin);
        g_free(pending_update);
        return;
    }

    g_snprintf(timestamp_str, sizeof(timestamp_str), "%lu",
               pending_update->timestamp);
    got_data = purple_http_response_get_data(response, &got_len);
    purple_buddy_icons_set_for_user(account, purple_buddy_get_name(buddy),
                                    g_memdup(got_data, got_len), got_len, timestamp_str);

    purple_debug_info("gg", "ggp_avatar_buddy_update_received: "
                      "got avatar for buddy %u [ts=%lu]\n", pending_update->uin,
                      pending_update->timestamp);
    g_free(pending_update);
}
示例#8
0
gboolean ggp_edisc_xfer_can_receive_file(PurpleConnection *gc,
	const char *who)
{
	PurpleBuddy *buddy;

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

	buddy = purple_blist_find_buddy(purple_connection_get_account(gc), who);
	if (buddy == NULL)
		return FALSE;

	/* TODO: check, if this buddy have us on his list */

	return PURPLE_BUDDY_IS_ONLINE(buddy);
}
示例#9
0
int ggp_message_send_im(PurpleConnection *gc, const char *who,
	const char *message, PurpleMessageFlags flags)
{
	GGPInfo *info = purple_connection_get_protocol_data(gc);
	PurpleIMConversation *im;
	ggp_buddy_data *buddy_data;
	gchar *gg_msg;
	gboolean succ;

	/* TODO: return -ENOTCONN, if not connected */

	if (message == NULL || message[0] == '\0')
		return 0;

	buddy_data = ggp_buddy_get_data(purple_blist_find_buddy(
		purple_connection_get_account(gc), who));

	if (buddy_data->blocked)
		return -1;

	im = purple_conversations_find_im_with_account(
		who, purple_connection_get_account(gc));

	gg_msg = ggp_message_format_to_gg(PURPLE_CONVERSATION(im), message);

	/* TODO: splitting messages */
	if (strlen(gg_msg) > GG_MSG_MAXSIZE) {
		g_free(gg_msg);
		return -E2BIG;
	}

#if GGP_ENABLE_GG11
	succ = (gg_send_message_html(info->session, GG_CLASS_CHAT,
		ggp_str_to_uin(who), (unsigned char *)gg_msg) >= 0);
#else
	{
		gchar *plain = purple_markup_strip_html(gg_msg);
		succ = (gg_send_message(info->session, GG_CLASS_CHAT,
			ggp_str_to_uin(who), (unsigned char *)plain) >= 0);
		g_free(plain);
	}
#endif

	g_free(gg_msg);

	return succ ? 1 : -1;
}
示例#10
0
/*------------------------------------------------------------------------
 * Return the list of media capabilities this contact supports.
 *
 *  @param account		The MXit account object
 *  @param who			The username of the contact.
 *  @return				The media capabilities supported
 */
PurpleMediaCaps mxit_media_caps(PurpleAccount *account, const char *who)
{
	struct MXitSession*	session	= purple_connection_get_protocol_data(purple_account_get_connection(account));
	PurpleBuddy*		buddy;
	struct contact*		contact;
	PurpleMediaCaps		capa	= PURPLE_MEDIA_CAPS_NONE;

	purple_debug_info(MXIT_PLUGIN_ID, "mxit_media_caps: buddy '%s'\n", who);

	/* We need to have a voice/video server */
	if (!*session->voip_server)
		return PURPLE_MEDIA_CAPS_NONE;

	/* find the buddy information for this contact (reference: "libpurple/buddylist.h") */
	buddy = purple_blist_find_buddy(account, who);
	if (!buddy) {
		purple_debug_warning(MXIT_PLUGIN_ID, "mxit_media_caps: unable to find the buddy '%s'\n", who);
		return PURPLE_MEDIA_CAPS_NONE;
	}

	contact = purple_buddy_get_protocol_data(buddy);
	if (!contact)
		return PURPLE_MEDIA_CAPS_NONE;

	/* can only communicate with MXit users */
	if (contact->type != MXIT_TYPE_MXIT)
		return PURPLE_MEDIA_CAPS_NONE;

	/* and only with contacts in the 'Both' subscription state */
	if (contact->subtype != MXIT_SUBTYPE_BOTH)
		return PURPLE_MEDIA_CAPS_NONE;

	/* and only when they're online */
	if (contact->presence == MXIT_PRESENCE_OFFLINE)
		return PURPLE_MEDIA_CAPS_NONE;

	/* they support voice-only */
	if (contact->capabilities & MXIT_PFLAG_VOICE)
		capa |= PURPLE_MEDIA_CAPS_AUDIO;

	/* they support voice-and-video */
	if (contact->capabilities & MXIT_PFLAG_VIDEO)
		capa |= (PURPLE_MEDIA_CAPS_AUDIO | PURPLE_MEDIA_CAPS_VIDEO | PURPLE_MEDIA_CAPS_AUDIO_VIDEO);

	return capa;
}
示例#11
0
void ggp_roster_alias_buddy(PurpleConnection *gc, const char *who,
	const char *alias)
{
	PurpleBuddy *buddy;

	g_return_if_fail(who != NULL);

	if (!ggp_roster_enabled())
		return;

	purple_debug_misc("gg", "ggp_roster_alias_buddy(\"%s\", \"%s\")\n",
		who, alias);

	buddy = purple_blist_find_buddy(purple_connection_get_account(gc), who);
	g_return_if_fail(buddy != NULL);

	ggp_roster_set_synchronized(gc, buddy, FALSE);
}
示例#12
0
/*------------------------------------------------------------------------
 * Send a typing indicator event.
 *
 *  @param gc		The connection object
 *  @param name		The username of the contact
 *  @param state	The typing state to be reported.
 */
static unsigned int mxit_send_typing( PurpleConnection *gc, const char *name, PurpleIMTypingState state )
{
	PurpleAccount*		account		= purple_connection_get_account( gc );
	struct MXitSession*	session		= purple_connection_get_protocol_data( gc );
	PurpleBuddy*		buddy;
	struct contact*		contact;
	gchar*				messageId	= NULL;

	/* find the buddy information for this contact (reference: "libpurple/buddylist.h") */
	buddy = purple_blist_find_buddy( account, name );
	if ( !buddy ) {
		purple_debug_warning( MXIT_PLUGIN_ID, "mxit_send_typing: unable to find the buddy '%s'\n", name );
		return 0;
	}

	contact = purple_buddy_get_protocol_data( buddy );
	if ( !contact )
		return 0;

	/* does this contact support and want typing notification? */
	if ( ! ( contact->capabilities & MXIT_PFLAG_TYPING ) )
		return 0;

	messageId = purple_uuid_random();		/* generate a unique message id */

	switch ( state ) {
		case PURPLE_IM_TYPING :		/* currently typing */
			mxit_send_msgevent( session, name, messageId, CP_MSGEVENT_TYPING );
			break;

		case PURPLE_IM_TYPED :			/* stopped typing */
		case PURPLE_IM_NOT_TYPING :	/* not typing / erased all text */
			mxit_send_msgevent( session, name, messageId, CP_MSGEVENT_STOPPED );
			break;

		default:
			break;
	}

	g_free( messageId );

	return 0;
}
示例#13
0
static void discover_status(PurpleConnection *from, PurpleConnection *to,
                            gpointer userdata) {
  const char *from_username = purple_account_get_username(purple_connection_get_account(from));
  const char *to_username = purple_account_get_username(purple_connection_get_account(to));

  if (purple_blist_find_buddy(purple_connection_get_account(from), to_username)) {
    PurpleStatus *status = purple_account_get_active_status(purple_connection_get_account(to));
    const char *status_id = purple_status_get_id(status);
    const char *message = purple_status_get_attr_string(status, "message");

    if (!strcmp(status_id, NULL_STATUS_ONLINE) ||
        !strcmp(status_id, NULL_STATUS_AWAY) ||
        !strcmp(status_id, NULL_STATUS_OFFLINE)) {
      purple_debug_info("nullprpl", "%s sees that %s is %s: %s\n",
                        from_username, to_username, status_id, message);
      purple_prpl_got_user_status(purple_connection_get_account(from), to_username, status_id,
                                  (message) ? "message" : NULL, message, NULL);
    } else {
      purple_debug_error("nullprpl",
                         "%s's buddy %s has an unknown status: %s, %s",
                         from_username, to_username, status_id, message);
    }
  }
}
示例#14
0
/* sent-im-msg */
static void sent_im_msg(PurpleAccount *account, PurpleMessage *msg, gpointer _unused)
{
	PurpleBuddy *buddy;
	guint interval, words;
	CapStatistics *stats = NULL;

	buddy = purple_blist_find_buddy(account, purple_message_get_recipient(msg));

	if (buddy == NULL)
		return;

	interval = purple_prefs_get_int("/plugins/gtk/cap/max_msg_difference") * 60;
	words = word_count(purple_message_get_contents(msg));

	stats = get_stats_for(buddy);

	insert_word_count(purple_account_get_username(account), purple_message_get_recipient(msg), words);
	stats->last_message = time(NULL);
	stats->last_message_status_id = purple_status_get_id(get_status_for(buddy));
	if(stats->timeout_source_id != 0)
		purple_timeout_remove(stats->timeout_source_id);

	stats->timeout_source_id = purple_timeout_add_seconds(interval, max_message_difference_cb, stats);
}
示例#15
0
/* return TRUE if avatar update was performed or there is no new requests,
   FALSE if we can request another one immediately */
static gboolean ggp_avatar_buddy_update_next(PurpleConnection *gc)
{
    PurpleHttpRequest *req;
    ggp_avatar_session_data *avdata = ggp_avatar_get_avdata(gc);
    GList *pending_update_it;
    ggp_avatar_buddy_update_req *pending_update;
    PurpleBuddy *buddy;
    PurpleAccount *account = purple_connection_get_account(gc);
    time_t old_timestamp;
    const char *old_timestamp_str;

    pending_update_it = g_list_first(avdata->pending_updates);
    if (pending_update_it == NULL)
        return TRUE;

    pending_update = pending_update_it->data;
    avdata->pending_updates = g_list_remove(avdata->pending_updates,
                                            pending_update);
    buddy = purple_blist_find_buddy(account, ggp_uin_to_str(pending_update->uin));

    if (!buddy) {
        if (ggp_str_to_uin(purple_account_get_username(account)) ==
                pending_update->uin)
        {
            purple_debug_misc("gg",
                              "ggp_avatar_buddy_update_next(%p): own "
                              "avatar update requested, but we don't have "
                              "ourselves on buddy list\n", gc);
        } else {
            purple_debug_warning("gg",
                                 "ggp_avatar_buddy_update_next(%p): "
                                 "%u update requested, but he's not on buddy "
                                 "list\n", gc, pending_update->uin);
        }
        return FALSE;
    }

    old_timestamp_str = purple_buddy_icons_get_checksum_for_user(buddy);
    old_timestamp = old_timestamp_str ? g_ascii_strtoull(
                        old_timestamp_str, NULL, 10) : 0;
    if (old_timestamp == pending_update->timestamp) {
        if (purple_debug_is_verbose()) {
            purple_debug_misc("gg",
                              "ggp_avatar_buddy_update_next(%p): "
                              "%u have up to date avatar with ts=%lu\n", gc,
                              pending_update->uin, pending_update->timestamp);
        }
        return FALSE;
    }
    if (old_timestamp > pending_update->timestamp) {
        purple_debug_warning("gg",
                             "ggp_avatar_buddy_update_next(%p): "
                             "saved timestamp for %u is newer than received "
                             "(%lu > %lu)\n", gc, pending_update->uin, old_timestamp,
                             pending_update->timestamp);
    }

    purple_debug_info("gg",
                      "ggp_avatar_buddy_update_next(%p): "
                      "updating %u with ts=%lu...\n", gc, pending_update->uin,
                      pending_update->timestamp);

    pending_update->gc = gc;
    avdata->current_update = pending_update;

    req = purple_http_request_new(NULL);
    purple_http_request_set_url_printf(req, GGP_AVATAR_BUDDY_URL,
                                       pending_update->uin);
    purple_http_request_header_set(req, "User-Agent", GGP_AVATAR_USERAGENT);
    purple_http_request_set_max_len(req, GGP_AVATAR_SIZE_MAX);
    pending_update->request = purple_http_request(gc, req,
                              ggp_avatar_buddy_update_received, pending_update);
    purple_http_request_unref(req);

    return TRUE;
}
示例#16
0
static gboolean ggp_roster_send_update_contact_update(PurpleConnection *gc,
	ggp_roster_change *change)
{
	PurpleAccount *account = purple_connection_get_account(gc);
	ggp_roster_content *content = ggp_roster_get_rdata(gc)->content;
	uin_t uin = change->data.uin;
	PurpleBuddy *buddy;
	PurpleXmlNode *buddy_node, *contact_groups;
	gboolean succ = TRUE;
	const char *group_id;

	g_return_val_if_fail(change->type == GGP_ROSTER_CHANGE_CONTACT_UPDATE,
		FALSE);

	buddy = purple_blist_find_buddy(account, ggp_uin_to_str(uin));
	if (!buddy)
		return TRUE;
	buddy_node = g_hash_table_lookup(content->contact_nodes,
		GINT_TO_POINTER(uin));

	group_id = ggp_roster_send_update_group_add(content,
		ggp_purplew_buddy_get_group_only(buddy));

	if (buddy_node) { /* update existing */
		purple_debug_misc("gg", "ggp_roster_send_update_contact_update:"
			" updating %u...\n", uin);

		succ &= ggp_xml_set_string(buddy_node, "ShowName",
			purple_buddy_get_alias(buddy));

		contact_groups = purple_xmlnode_get_child(buddy_node, "Groups");
		g_assert(contact_groups);
		ggp_xmlnode_remove_children(contact_groups);
		succ &= ggp_xml_set_string(contact_groups, "GroupId", group_id);

		g_return_val_if_fail(succ, FALSE);

		return TRUE;
	}

	/* add new */
	purple_debug_misc("gg", "ggp_roster_send_update_contact_update: "
		"adding %u...\n", uin);
	buddy_node = purple_xmlnode_new_child(content->contacts_node, "Contact");
	succ &= ggp_xml_set_string(buddy_node, "Guid", purple_uuid_random());
	succ &= ggp_xml_set_uint(buddy_node, "GGNumber", uin);
	succ &= ggp_xml_set_string(buddy_node, "ShowName",
		purple_buddy_get_alias(buddy));

	contact_groups = purple_xmlnode_new_child(buddy_node, "Groups");
	g_assert(contact_groups);
	succ &= ggp_xml_set_string(contact_groups, "GroupId", group_id);

	purple_xmlnode_new_child(buddy_node, "Avatars");
	succ &= ggp_xml_set_bool(buddy_node, "FlagBuddy", TRUE);
	succ &= ggp_xml_set_bool(buddy_node, "FlagNormal", TRUE);
	succ &= ggp_xml_set_bool(buddy_node, "FlagFriend", TRUE);

	/* we don't use Guid, so update is not needed
	 * content->needs_update = TRUE;
	 */

	g_hash_table_insert(content->contact_nodes, GINT_TO_POINTER(uin),
		buddy_node);

	g_return_val_if_fail(succ, FALSE);

	return TRUE;
}
示例#17
0
static void ggp_pubdir_get_info_protocol_got(PurpleConnection *gc,
	int records_count, const ggp_pubdir_record *records, int next_offset,
	void *_uin_p)
{
	uin_t uin = *((uin_t*)_uin_p);
	PurpleNotifyUserInfo *info = purple_notify_user_info_new();
	const ggp_pubdir_record *record = &records[0];
	PurpleBuddy *buddy;

	g_free(_uin_p);

	if (records_count < 1) {
		purple_debug_error("gg", "ggp_pubdir_get_info_protocol_got: "
			"couldn't get info for %u\n", uin);
		purple_notify_user_info_add_pair_plaintext(info, NULL,
			_("Cannot get user information"));
		purple_notify_userinfo(gc, ggp_uin_to_str(uin), info,
			NULL, NULL);
		purple_notify_user_info_destroy(info);
		return;
	}

	purple_debug_info("gg", "ggp_pubdir_get_info_protocol_got: %u\n", uin);
	g_assert(uin == record->uin);
	g_assert(records_count == 1);

	buddy = purple_blist_find_buddy(purple_connection_get_account(gc),
		ggp_uin_to_str(uin));
	if (buddy) {
		const char *alias;
		PurpleStatus *status;
		gchar *status_message;

		alias = purple_buddy_get_alias_only(buddy);
		if (alias)
			purple_notify_user_info_add_pair_plaintext(info,
				_("Alias"), alias);

		status = purple_presence_get_active_status(
			purple_buddy_get_presence(buddy));
		ggp_status_from_purplestatus(status, &status_message);
		purple_notify_user_info_add_pair_plaintext(info, _("Status"),
			purple_status_get_name(status));
		if (status_message) {
			purple_notify_user_info_add_pair_plaintext(info,
				_("Message"), status_message);
		}
	}

	if (record->nickname) {
		purple_notify_user_info_add_pair_plaintext(info,
			_("Nickname"), record->nickname);
	}
	if (record->first_name) {
		purple_notify_user_info_add_pair_plaintext(info,
			_("First name"), record->first_name);
	}
	if (record->last_name) {
		purple_notify_user_info_add_pair_plaintext(info,
			_("Last name"), record->last_name);
	}
	if (record->gender != GGP_PUBDIR_GENDER_UNSPECIFIED) {
		purple_notify_user_info_add_pair_plaintext(info, _("Gender"),
			record->gender == GGP_PUBDIR_GENDER_FEMALE ?
			_("Female") : _("Male"));
	}
	if (record->city) {
		purple_notify_user_info_add_pair_plaintext(info, _("City"),
			record->city);
	}
	if (record->birth) {
		purple_notify_user_info_add_pair_plaintext(info, _("Birthday"),
			ggp_date_strftime("%Y-%m-%d", record->birth));
	} else if (record->age) {
		gchar *age_s = g_strdup_printf("%d", record->age);
		purple_notify_user_info_add_pair_plaintext(info, _("Age"),
			age_s);
		g_free(age_s);
	}

	purple_notify_userinfo(gc, ggp_uin_to_str(uin), info, NULL, NULL);
	purple_notify_user_info_destroy(info);
}
示例#18
0
/* void ggp_buddylist_load(PurpleConnection *gc, char *buddylist) {{{ */
void ggp_buddylist_load(PurpleConnection *gc, char *buddylist)
{
	PurpleBuddy *buddy;
	PurpleGroup *group;
	gchar **users_tbl;
	int i;
	char *utf8buddylist = ggp_convert_from_cp1250(buddylist);

	/* Don't limit the number of records in a buddylist. */
	users_tbl = g_strsplit(utf8buddylist, "\r\n", -1);

	for (i = 0; users_tbl[i] != NULL; i++) {
		gchar **data_tbl;
		gchar *name, *show, *g;

		if (!*users_tbl[i])
			continue;

		data_tbl = g_strsplit(users_tbl[i], ";", 8);
		if (g_strv_length(data_tbl) < 8) {
			purple_debug_warning("gg",
				"Something is wrong on line %d of the buddylist. Skipping.\n",
				i + 1);
			continue;
		}

		show = data_tbl[F_NICKNAME];
		name = data_tbl[F_UIN];
		if ('\0' == *name || !atol(name)) {
			purple_debug_warning("gg",
				"Identifier on line %d of the buddylist is not a number. Skipping.\n",
				i + 1);
			continue;
		}

		if ('\0' == *show) {
			show = name;
		}

		purple_debug_info("gg", "got buddy: name=%s; show=%s\n", name, show);

		if (purple_blist_find_buddy(purple_connection_get_account(gc), name)) {
			g_strfreev(data_tbl);
			continue;
		}

		g = g_strdup("Gadu-Gadu");

		if ('\0' != data_tbl[F_GROUP]) {
			/* XXX: Probably buddy should be added to all the groups. */
			/* Hard limit to at most 50 groups */
			gchar **group_tbl = g_strsplit(data_tbl[F_GROUP], ",", 50);
			if (g_strv_length(group_tbl) > 0) {
				g_free(g);
				g = g_strdup(group_tbl[0]);
			}
			g_strfreev(group_tbl);
		}

		buddy = purple_buddy_new(purple_connection_get_account(gc),
			name, strlen(show) ? show : NULL);

		if (!(group = purple_blist_find_group(g))) {
			group = purple_group_new(g);
			purple_blist_add_group(group, NULL);
		}

		purple_blist_add_buddy(buddy, NULL, group, NULL);
		g_free(g);

		g_strfreev(data_tbl);
	}
	g_strfreev(users_tbl);
	g_free(utf8buddylist);

	ggp_buddylist_send(gc);
}
示例#19
0
void IMInvoker::send(void *userdata, const std::string event) {
	// we are in the thread that manages all of libpurple
	EventContext* ctx = (EventContext*)userdata;

	if (!ctx)
		return;

	if (!ctx->instance || !ctx->instance->_account) {
		ctx->instance->returnErrorExecution("No account available");
		delete(ctx);
		return;
	}

	if (iequals(ctx->sendReq.name, "im.send")) {
		std::string receiver;
		Event::getParam(ctx->sendReq.params, "receiver", receiver);

		Data data;
		Event::getParam(ctx->sendReq.params, "data", data);

#if LIBPURPLE_VERSION_MAJOR >= 3
		PurpleIMConversation* conv = purple_im_conversation_new(ctx->instance->_account, receiver.c_str());
		if (ctx->sendReq.content.length() > 0)
			purple_conversation_send(PURPLE_CONVERSATION(conv), ctx->sendReq.content.c_str());
#else
		PurpleConversation* conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, ctx->instance->_account, receiver.c_str());
		if (ctx->sendReq.content.length() > 0)
			purple_conv_im_send(purple_conversation_get_im_data(conv), ctx->sendReq.content.c_str());
#endif

#if 0
		if (data.binary) {
			PurpleConnection *gc = purple_account_get_connection(ctx->instance->_account);
			PurplePlugin *prpl;
			PurplePluginProtocolInfo *prpl_info;


			if (gc) {
				prpl = purple_connection_get_prpl(gc);
				prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);

//					if (prpl_info && prpl_info->new_xfer) {
//						PurpleXfer* xfer = (prpl_info->new_xfer)(purple_account_get_connection(ctx->instance->_account), receiver.c_str());
//						purple_xfer_set_local_filename(xfer, "/Users/sradomski/Documents/W3C Standards.pdf");
//						purple_xfer_set_filename(xfer, "asdfadsf.pdf");
//						purple_xfer_request(xfer);
//						purple_xfer_request_accepted(xfer, "/Users/sradomski/Documents/W3C Standards.pdf");
//					}

				//Set the filename
//					purple_xfer_set_local_filename(xfer, [[fileTransfer localFilename] UTF8String]);
//					purple_xfer_set_filename(xfer, [[[fileTransfer localFilename] lastPathComponent] UTF8String]);
//					xfer->ui_data
//					purple_xfer_request(xfer);

				serv_send_file(gc, "sradomski@localhost", "/Users/sradomski/Documents/W3C Standards.pdf");
//					if (prpl_info->send_file && (prpl_info->can_receive_file && prpl_info->can_receive_file(gc, receiver.c_str()))) {
//						prpl_info->send_file(gc, receiver.c_str(), "/Users/sradomski/Documents/W3C Standards.pdf");
//					}
//						prpl_info->send_raw(gc, data.binary->data, data.binary->size);
			}

		}
#endif
	} else if (iequals(ctx->sendReq.name, "im.buddy.add")) {
		std::string buddyName;
		Event::getParam(ctx->sendReq.params, "name", buddyName);

		std::string reqMsg;
		Event::getParam(ctx->sendReq.params, "msg", reqMsg);

		PurpleBuddy* buddy = purple_buddy_new(ctx->instance->_account, buddyName.c_str(), NULL);
		purple_blist_add_buddy(buddy, NULL, NULL, NULL);
#if LIBPURPLE_VERSION_MAJOR >= 3
		purple_account_add_buddy(ctx->instance->_account, buddy, reqMsg.c_str());
#else
		purple_account_add_buddy(ctx->instance->_account, buddy);
#endif

	} else if (iequals(ctx->sendReq.name, "im.buddy.remove")) {
		std::string buddyName;
		Event::getParam(ctx->sendReq.params, "name", buddyName);

#if LIBPURPLE_VERSION_MAJOR >= 3
		PurpleBuddy* buddy = purple_blist_find_buddy(ctx->instance->_account, buddyName.c_str());
		if (PURPLE_IS_BUDDY(buddy)) {
			purple_account_remove_buddy(ctx->instance->_account, buddy, purple_buddy_get_group(buddy));
			purple_blist_remove_buddy(buddy);
		}
#else
		PurpleBuddy* buddy = purple_find_buddy(ctx->instance->_account, buddyName.c_str());
		purple_account_remove_buddy(ctx->instance->_account, buddy, purple_buddy_get_group(buddy));
		purple_blist_remove_buddy(buddy);

#endif
	}

	delete(ctx);
}
示例#20
0
static gboolean ggp_roster_reply_list_read_buddy(PurpleConnection *gc,
	PurpleXmlNode *node, ggp_roster_content *content, GHashTable *remove_buddies)
{
	gchar *alias, *group_name = NULL;
	uin_t uin;
	gboolean succ = TRUE;
	PurpleXmlNode *group_list, *group_elem;
	PurpleBuddy *buddy = NULL;
	PurpleGroup *group = NULL;
	PurpleGroup *currentGroup;
	gboolean alias_changed;
	PurpleAccount *account = purple_connection_get_account(gc);

	succ &= ggp_xml_get_string(node, "ShowName", &alias);
	succ &= ggp_xml_get_uint(node, "GGNumber", &uin);

	group_list = purple_xmlnode_get_child(node, "Groups");
	succ &= (group_list != NULL);

	if (!succ) {
		g_free(alias);
		g_return_val_if_reached(FALSE);
	}

	g_hash_table_insert(content->contact_nodes, GINT_TO_POINTER(uin), node);

	/* check, if alias is set */
	if (strlen(alias) == 0 ||
		strcmp(alias, ggp_uin_to_str(uin)) == 0)
	{
		g_free(alias);
		alias = NULL;
	}

	/* getting (eventually creating) group */
	group_elem = purple_xmlnode_get_child(group_list, "GroupId");
	while (group_elem != NULL) {
		gchar *id;
		gboolean isbot;

		if (!ggp_xml_get_string(group_elem, NULL, &id))
			continue;
		isbot = (0 == g_strcmp0(id, content->bots_group_id));
		group_name = g_hash_table_lookup(content->group_names, id);
		g_free(id);

		/* we don't want to import bots;
		 * they are inserted to roster by default
		 */
		if (isbot) {
			g_free(alias);
			return TRUE;
		}

		if (group_name != NULL)
			break;

		group_elem = purple_xmlnode_get_next_twin(group_elem);
	}
	if (group_name) {
		group = purple_blist_find_group(group_name);
		if (!group) {
			group = purple_group_new(group_name);
			purple_blist_add_group(group, NULL);
		}
	}

	/* add buddy, if doesn't exists */
	buddy = purple_blist_find_buddy(account, ggp_uin_to_str(uin));
	g_hash_table_remove(remove_buddies, GINT_TO_POINTER(uin));
	if (!buddy) {
		purple_debug_info("gg", "ggp_roster_reply_list_read_buddy: "
			"adding %u (%s) to buddy list\n", uin, alias);
		buddy = purple_buddy_new(account, ggp_uin_to_str(uin), alias);
		purple_blist_add_buddy(buddy, NULL, group, NULL);
		ggp_roster_set_synchronized(gc, buddy, TRUE);

		g_free(alias);
		return TRUE;
	}

	/* buddy exists, but is not synchronized - local list has priority */
	if (!ggp_roster_is_synchronized(buddy)) {
		purple_debug_misc("gg", "ggp_roster_reply_list_read_buddy: "
			"ignoring not synchronized %u (%s)\n",
			uin, purple_buddy_get_name(buddy));
		g_free(alias);
		return TRUE;
	}

	currentGroup = ggp_purplew_buddy_get_group_only(buddy);
	alias_changed =
		(0 != g_strcmp0(alias, purple_buddy_get_alias_only(buddy)));

	if (currentGroup == group && !alias_changed) {
		g_free(alias);
		return TRUE;
	}

	purple_debug_misc("gg", "ggp_roster_reply_list_read_buddy: "
		"updating %u (%s) - alias=\"%s\"->\"%s\", group=%p->%p (%s)\n",
		uin, purple_buddy_get_name(buddy),
		purple_buddy_get_alias(buddy), alias,
		currentGroup, group, group_name);
	if (alias_changed)
		purple_buddy_set_local_alias(buddy, alias);
	if (currentGroup != group)
		purple_blist_add_buddy(buddy, NULL, group, NULL);

	g_free(alias);
	return TRUE;
}