Пример #1
0
/* char *ggp_buddylist_dump(PurpleAccount *account) {{{ */
char *ggp_buddylist_dump(PurpleAccount *account)
{
	GSList *buddies;
	GString *buddylist = g_string_sized_new(1024);
	char *ptr;

	for (buddies = purple_blist_find_buddies(account, NULL); buddies;
		buddies = g_slist_delete_link(buddies, buddies))
	{
		PurpleBuddy *buddy = buddies->data;
		PurpleGroup *group = purple_buddy_get_group(buddy);
		const char *bname = purple_buddy_get_name(buddy);
		const char *gname = purple_group_get_name(group);
		const char *alias = purple_buddy_get_alias(buddy);

		if (alias == NULL)
			alias = bname;

		g_string_append_printf(buddylist,
				"%s;%s;%s;%s;%s;%s;%s;%s%s\r\n",
				alias, alias, alias, alias,
				"", gname, bname, "", "");
	}

	ptr = ggp_convert_to_cp1250(buddylist->str);
	g_string_free(buddylist, TRUE);
	return ptr;
}
Пример #2
0
void jabber_roster_remove_buddy(PurpleConnection *gc, PurpleBuddy *buddy,
		PurpleGroup *group) {
	GSList *buddies = purple_find_buddies(gc->account, buddy->name);

	buddies = g_slist_remove(buddies, buddy);
	if(buddies != NULL) {
		PurpleBuddy *tmpbuddy;
		PurpleGroup *tmpgroup;
		GSList *groups = NULL;

		while(buddies) {
			tmpbuddy = buddies->data;
			tmpgroup = purple_buddy_get_group(tmpbuddy);
			groups = g_slist_append(groups, tmpgroup->name);
			buddies = g_slist_remove(buddies, tmpbuddy);
		}

		jabber_roster_update(gc->proto_data, buddy->name, groups);
		g_slist_free(groups);
	} else {
		JabberIq *iq = jabber_iq_new_query(gc->proto_data, JABBER_IQ_SET,
				"jabber:iq:roster");
		xmlnode *query = xmlnode_get_child(iq->node, "query");
		xmlnode *item = xmlnode_new_child(query, "item");

		xmlnode_set_attrib(item, "jid", buddy->name);
		xmlnode_set_attrib(item, "subscription", "remove");

		jabber_iq_send(iq);
	}
}
Пример #3
0
void jabber_roster_group_change(PurpleConnection *gc, const char *name,
		const char *old_group, const char *new_group)
{
	GSList *buddies, *groups = NULL;
	PurpleBuddy *b;
	PurpleGroup *g;
	const char *gname;

	if(!old_group || !new_group || !strcmp(old_group, new_group))
		return;

	buddies = purple_find_buddies(gc->account, name);
	while(buddies) {
		b = buddies->data;
		g = purple_buddy_get_group(b);
		gname = purple_group_get_name(g);
		if(!strcmp(gname, old_group))
			groups = g_slist_append(groups, (char*)new_group); /* ick */
		else
			groups = g_slist_append(groups, (char*)gname);
		buddies = g_slist_remove(buddies, b);
	}

	purple_debug_info("jabber", "jabber_roster_group_change(): Moving %s from %s to %s\n",
	                  name, old_group, new_group);

	jabber_roster_update(gc->proto_data, name, groups);
}
Пример #4
0
static void prplcb_blist_update( PurpleBuddyList *list, PurpleBlistNode *node )
{
	if( node->type == PURPLE_BLIST_BUDDY_NODE )
	{
		PurpleBuddy *bud = (PurpleBuddy*) node;
		PurpleGroup *group = purple_buddy_get_group( bud );
		struct im_connection *ic = purple_ic_by_pa( bud->account );
		PurpleStatus *as;
		int flags = 0;
		
		if( ic == NULL )
			return;
		
		if( bud->server_alias )
			imcb_rename_buddy( ic, bud->name, bud->server_alias );
		else if( bud->alias )
			imcb_rename_buddy( ic, bud->name, bud->alias );
		
		if( group )
			imcb_add_buddy( ic, bud->name, purple_group_get_name( group ) );
		
		flags |= purple_presence_is_online( bud->presence ) ? OPT_LOGGED_IN : 0;
		flags |= purple_presence_is_available( bud->presence ) ? 0 : OPT_AWAY;
		
		as = purple_presence_get_active_status( bud->presence );
		
		imcb_buddy_status( ic, bud->name, flags, purple_status_get_name( as ),
		                   purple_status_get_attr_string( as, "message" ) );
		
		imcb_buddy_times( ic, bud->name,
		                  purple_presence_get_login_time( bud->presence ),
		                  purple_presence_get_idle_time( bud->presence ) );
	}
}
Пример #5
0
void
purple_events_ui_menu_add(PurpleBlistNode *node, GList **menu, PurpleEventsContext *context)
{
    PurpleBlistNode *group = NULL;

    node = _purple_events_ui_get_good_node(node);
    if ( ( node == NULL ) || ( ( purple_blist_node_get_flags(node) & PURPLE_BLIST_NODE_FLAG_NO_SAVE ) > 0 ) )
        return;

    if ( PURPLE_BLIST_NODE_IS_CONTACT(node) )
        group = PURPLE_BLIST_NODE(purple_buddy_get_group(purple_contact_get_priority_buddy(PURPLE_CONTACT(node))));


    gint current = purple_blist_node_get_int(node, "events");
    GList *actions = NULL;
    PurpleMenuAction *action = NULL;

    const gchar *label = "";
    if ( current != 0 )
    {
        if ( PURPLE_BLIST_NODE_IS_GROUP(node) || ( purple_blist_node_get_int(group, "events") == 0 ) )
            label = _("Use global settings");
        else
            label = _("Use group settings");
        action = purple_menu_action_new(label, (PurpleCallback)_purple_events_ui_reset_setting, NULL, NULL);
        actions = g_list_prepend(actions, action);
    }
    if ( current >= 0 )
    {
        action = purple_menu_action_new(_("Disable all events"), (PurpleCallback)_purple_events_ui_disable_all_events, NULL, NULL);
        actions = g_list_prepend(actions, action);
    }

    action = purple_menu_action_new(_("Select events"), (PurpleCallback)_purple_events_ui_events_selection_dialog, context, NULL);
    actions = g_list_prepend(actions, action);

    switch ( current )
    {
    case -1:
        label = _("Current events: all disabled");
    break;
    case 0:
        if ( PURPLE_BLIST_NODE_IS_GROUP(node) || ( purple_blist_node_get_int(group, "events") == 0 ) )
            label = _("Current events: global settings");
        else
            label = _("Current events: group settings");
    break;
    case 1:
        label = _("Current events: selection");
    break;
    }
    actions = g_list_prepend(actions, NULL);
    action = purple_menu_action_new(label, NULL, NULL, NULL);
    actions = g_list_prepend(actions, action);

    *menu = g_list_append(*menu, NULL);
    action = purple_menu_action_new(_("Events"), NULL, NULL, actions);
    *menu = g_list_append(*menu, action);
}
Пример #6
0
PurpleBuddy * qq_buddy_find_or_new( PurpleConnection *gc, guint32 uid, guint8 group_id)
{
	PurpleBuddy *buddy;
	qq_buddy_data *bd;
	qq_data *qd;
	GSList *l;
	qq_group * g;
	PurpleGroup * old_group;
	g_return_val_if_fail(gc->account != NULL && uid != 0, NULL);

	qd = (qq_data *)gc->proto_data;

	buddy = qq_buddy_find(gc, uid);
	/* group_id==0xFF only when add an unknown stranger */
	if (group_id==0xFF) {
		if (buddy)	goto buddy_data_check;
		else group_id=0;		//add stranger to group 0
	}

	/* find input group_id */
	for (l=qd->group_list; l; l=l->next)
	{
		if (((qq_group *)(l->data))->group_id == group_id) break;
	}

	/* if group_id found */
	if (l)	{
		if (buddy)		//if buddy already exist, we need check if he is in new group
		{	
			old_group = purple_buddy_get_group(buddy);
			g = (qq_group *)l->data;
			if (old_group != purple_find_group(g->group_name))
			{
				qq_buddy_free(buddy);
			} else	goto buddy_data_check;
		}
		old_group = purple_find_group(((qq_group *)(l->data))->group_name);
		buddy = qq_buddy_new(gc, uid, old_group);
	} else {
		if (group_id==0)
		{
			if (!buddy)
				buddy = qq_buddy_new(gc, uid, NULL);
			goto buddy_data_check;
		}
		purple_debug_error("QQ","cannot find group id: %u", group_id);
		return NULL;
	}

buddy_data_check:
	if (purple_buddy_get_protocol_data(buddy) != NULL)
		return buddy;

	bd = qq_buddy_data_new(uid);
	purple_buddy_set_protocol_data(buddy, bd);
	return buddy;
}
Пример #7
0
const char *PurpleContactListMngr::FindBuddyGroup(PurpleBuddy *gBuddy)
{
	PurpleGroup *gGroup = purple_buddy_get_group(gBuddy);
	
	if (gGroup)
		return gGroup->name;
	else
		return NULL;
}
Пример #8
0
static void jabber_roster_update(JabberStream *js, const char *name,
		GSList *grps)
{
	PurpleBuddy *b;
	PurpleGroup *g;
	GSList *groups = NULL, *l;
	JabberIq *iq;
	xmlnode *query, *item, *group;

	if (js->currently_parsing_roster_push)
		return;

	if(!(b = purple_find_buddy(js->gc->account, name)))
		return;

	if(grps) {
		groups = grps;
	} else {
		GSList *buddies = purple_find_buddies(js->gc->account, name);
		if(!buddies)
			return;
		while(buddies) {
			b = buddies->data;
			g = purple_buddy_get_group(b);
			groups = g_slist_append(groups, g->name);
			buddies = g_slist_remove(buddies, b);
		}
	}

	iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:roster");

	query = xmlnode_get_child(iq->node, "query");
	item = xmlnode_new_child(query, "item");

	xmlnode_set_attrib(item, "jid", name);

	xmlnode_set_attrib(item, "name", b->alias ? b->alias : "");

	for(l = groups; l; l = l->next) {
		group = xmlnode_new_child(item, "group");
		xmlnode_insert_data(group, l->data, -1);
	}

	if(!grps)
		g_slist_free(groups);
	
	if (js->server_caps & JABBER_CAP_GOOGLE_ROSTER) {
		jabber_google_roster_outgoing(js, query, item);
		xmlnode_set_attrib(query, "xmlns:gr", "google:roster");
		xmlnode_set_attrib(query, "gr:ext", "2");
	}
	jabber_iq_send(iq);
}
Пример #9
0
static void
msn_session_sync_users(MsnSession *session)
{
	PurpleConnection *gc = purple_account_get_connection(session->account);
	GList *to_remove = NULL;
	GSList *buddies;

	g_return_if_fail(gc != NULL);

	/* The core used to use msn_add_buddy to add all buddies before
	 * being logged in. This no longer happens, so we manually iterate
	 * over the whole buddy list to identify sync issues.
	 */
	for (buddies = purple_blist_find_buddies(session->account, NULL); buddies;
			buddies = g_slist_delete_link(buddies, buddies)) {
		PurpleBuddy *buddy = buddies->data;
		const gchar *buddy_name = purple_buddy_get_name(buddy);
		const gchar *group_name = purple_group_get_name(purple_buddy_get_group(buddy));
		MsnUser *remote_user;
		gboolean found = FALSE;

		remote_user = msn_userlist_find_user(session->userlist, buddy_name);
		if (remote_user && remote_user->list_op & MSN_LIST_FL_OP) {
			GList *l;
			for (l = remote_user->group_ids; l; l = l->next) {
				const char *name = msn_userlist_find_group_name(remote_user->userlist, l->data);
				if (name && !g_ascii_strcasecmp(group_name, name)) {
					found = TRUE;
					break;
				}
			}

			/* We don't care if they're in a different group, as long as they're on the
			 * list somewhere. If we check for the group, we cause pain, agony and
			 * suffering for people who decide to re-arrange their buddy list elsewhere.
			 */
			if (!found) {
				if ((remote_user == NULL) || !(remote_user->list_op & MSN_LIST_FL_OP)) {
					/* The user is not on the server list */
					msn_error_sync_issue(session, buddy_name, group_name);
				} else {
					/* The user is not in that group on the server list */
					to_remove = g_list_prepend(to_remove, buddy);
				}
			}
		}
	}

	if (to_remove != NULL) {
		g_list_foreach(to_remove, (GFunc)purple_blist_remove_buddy, NULL);
		g_list_free(to_remove);
	}
}
Пример #10
0
static void purple_remove_buddy( struct im_connection *ic, char *who, char *group )
{
	PurpleBuddy *pb;
	
	pb = purple_find_buddy( (PurpleAccount*) ic->proto_data, who );
	if( pb != NULL )
	{
		PurpleGroup *group;
		
		group = purple_buddy_get_group( pb );
		purple_account_remove_buddy( (PurpleAccount*) ic->proto_data, pb, group );
		
		purple_blist_remove_buddy( pb );
	}

	purple_gg_buddylist_export( ((PurpleAccount*)ic->proto_data)->gc );
}
Пример #11
0
void BuddyListBuddy::BuddyContextMenu::removeResponseHandler(
    CppConsUI::MessageDialog& /*activator*/,
    CppConsUI::AbstractDialog::ResponseType response)
{
  if (response != CppConsUI::AbstractDialog::RESPONSE_OK)
    return;

  PurpleBuddy *buddy = parent_buddy->getPurpleBuddy();
  purple_account_remove_buddy(purple_buddy_get_account(buddy), buddy,
      purple_buddy_get_group(buddy));

  /* Close the context menu before the buddy is deleted because its deletion
   * can lead to destruction of this object. */
  close();

  purple_blist_remove_buddy(buddy);
}
Пример #12
0
void
oscar_user_info_append_extra_info(PurpleConnection *gc, PurpleNotifyUserInfo *user_info, PurpleBuddy *b, aim_userinfo_t *userinfo)
{
	OscarData *od;
	PurpleAccount *account;
	PurplePresence *presence = NULL;
	PurpleStatus *status = NULL;
	PurpleGroup *g = NULL;
	struct buddyinfo *bi = NULL;
	char *tmp;
	const char *bname = NULL, *gname = NULL;

	od = purple_connection_get_protocol_data(gc);
	account = purple_connection_get_account(gc);

	if ((user_info == NULL) || ((b == NULL) && (userinfo == NULL)))
		return;

	if (userinfo == NULL)
		userinfo = aim_locate_finduserinfo(od, purple_buddy_get_name(b));

	if (b == NULL)
		b = purple_find_buddy(account, userinfo->bn);

	if (b != NULL) {
		bname = purple_buddy_get_name(b);
		g = purple_buddy_get_group(b);
		gname = purple_group_get_name(g);
		presence = purple_buddy_get_presence(b);
		status = purple_presence_get_active_status(presence);
	}

	if (userinfo != NULL)
		bi = g_hash_table_lookup(od->buddyinfo, purple_normalize(account, userinfo->bn));

	if ((bi != NULL) && (bi->ipaddr != 0)) {
		tmp =  g_strdup_printf("%hhu.%hhu.%hhu.%hhu",
						(bi->ipaddr & 0xff000000) >> 24,
						(bi->ipaddr & 0x00ff0000) >> 16,
						(bi->ipaddr & 0x0000ff00) >> 8,
						(bi->ipaddr & 0x000000ff));
		oscar_user_info_add_pair(user_info, _("IP Address"), tmp);
		g_free(tmp);
	}
Пример #13
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;
}
void rc_push_contact(PurpleAccount *acct,
    const char * buddyname)
{
  PurpleGroup * grp = purple_find_group(GROUP_NAME);
  if (!grp) {
    trace("Group %s Not Found. Create one.", GROUP_NAME);
    grp = purple_group_new(GROUP_NAME);
  }

  PurpleBuddy * buddy;
  // if we can find it in 'Recent Contacts', skip
  if ((buddy = purple_find_buddy_in_group(acct, buddyname, grp)) != NULL) {
    trace("Buddy %s is already in %s", buddyname, GROUP_NAME);
    purple_blist_add_buddy(buddy, NULL, grp, NULL);
    return;
  }

  buddy = purple_find_buddy(acct, buddyname);
  if (!buddy) {
    trace("Buddy %s Not Found. You SUCK!", buddyname);
    return;
  }

  PurpleBlistNode * node = PURPLE_BLIST_NODE(buddy); 

  // back up group info
  PurpleGroup * orig_grp = 	purple_buddy_get_group(buddy);
  purple_blist_node_set_string(node, NODE_GROUP_KEY, orig_grp->name);

  // back up offline info
  gboolean offline = purple_blist_node_get_bool(node, NODE_OFFLINE_KEY);
  purple_blist_node_set_bool(node, NODE_ORIG_OFFLINE_KEY, offline);
  purple_blist_node_set_bool(node, NODE_OFFLINE_KEY, TRUE);

  // Add to Recent Contacts Group
  trace(">>>>>>> Add %s", buddyname);
  purple_blist_add_buddy(buddy, NULL, grp, NULL);

  // Clean up old group if needed
  rc_pop_contacts(grp);
}
Пример #15
0
/* stupid libpurple's local contact list, we don't need you! */
static void
sync_users (MsnSession *session)
{
    PurpleAccount *account;
    GSList *buddies;
    GList *to_remove = NULL;

    account = msn_session_get_user_data(session);

    for (buddies = purple_find_buddies(account, NULL); buddies;
         buddies = g_slist_delete_link(buddies, buddies))
    {
        PurpleBuddy *buddy = buddies->data;
        const gchar *buddy_name = purple_buddy_get_name(buddy);
        const gchar *group_name = purple_group_get_name(purple_buddy_get_group(buddy));
        struct pn_contact *contact;
        gboolean found = FALSE;

        contact = pn_contactlist_find_contact(session->contactlist, buddy_name);

        if (contact && contact->list_op & MSN_LIST_FL_OP) {
            struct pn_group *group;

            group = pn_contactlist_find_group_with_name(session->contactlist,
                                                        group_name);

            found = pn_contact_is_in_group(contact, group);
        }

        if (!found) {
            pn_warning("synchronization issue; buddy %s not found in group %s: removing",
                       purple_buddy_get_name(buddy), group_name);
            to_remove = g_list_prepend(to_remove, buddy);
        }
    }
    if (to_remove) {
        g_list_foreach(to_remove, (GFunc) purple_blist_remove_buddy, NULL);
        g_list_free(to_remove);
    }
}
Пример #16
0
/* When you ask other people for authorization */
void
oscar_auth_sendrequest(PurpleConnection *gc, const char *bname, const char *msg)
{
	OscarData *od;
	PurpleAccount *account;
	PurpleBuddy *buddy;
	PurpleGroup *group;
	const char *gname;

	od = purple_connection_get_protocol_data(gc);
	account = purple_connection_get_account(gc);
	buddy = purple_find_buddy(account, bname);
	if (buddy != NULL)
		group = purple_buddy_get_group(buddy);
	else
		group = NULL;

	if (group != NULL)
	{
		gname = purple_group_get_name(group);
		purple_debug_info("oscar", "ssi: adding buddy %s to group %s\n",
				   bname, gname);
		aim_ssi_sendauthrequest(od, bname, msg ? msg : _("Please authorize me so I can add you to my buddy list."));
		if (!aim_ssi_itemlist_finditem(od->ssi.local, gname, bname, AIM_SSI_TYPE_BUDDY))
		{
			aim_ssi_addbuddy(od, bname, gname, NULL, purple_buddy_get_alias_only(buddy), NULL, NULL, TRUE);

			/* Mobile users should always be online */
			if (bname[0] == '+') {
				purple_prpl_got_user_status(account,
						purple_buddy_get_name(buddy),
						OSCAR_STATUS_ID_AVAILABLE, NULL);
				purple_prpl_got_user_status(account,
						purple_buddy_get_name(buddy),
						OSCAR_STATUS_ID_MOBILE, NULL);
			}
		}
	}
}
Пример #17
0
void jabber_roster_group_change(PurpleConnection *gc, const char *name,
		const char *old_group, const char *new_group)
{
	GSList *buddies, *groups = NULL;
	PurpleBuddy *b;
	PurpleGroup *g;

	if(!old_group || !new_group || !strcmp(old_group, new_group))
		return;

	buddies = purple_find_buddies(gc->account, name);
	while(buddies) {
		b = buddies->data;
		g = purple_buddy_get_group(b);
		if(!strcmp(g->name, old_group))
			groups = g_slist_append(groups, (char*)new_group); /* ick */
		else
			groups = g_slist_append(groups, g->name);
		buddies = g_slist_remove(buddies, b);
	}
	jabber_roster_update(gc->proto_data, name, groups);
	g_slist_free(groups);
}
Пример #18
0
void jabber_roster_remove_buddy(PurpleConnection *gc, PurpleBuddy *buddy,
		PurpleGroup *group) {
	const char *name = purple_buddy_get_name(buddy);
	GSList *buddies = purple_find_buddies(purple_connection_get_account(gc), name);

	buddies = g_slist_remove(buddies, buddy);
	if(buddies != NULL) {
		PurpleBuddy *tmpbuddy;
		PurpleGroup *tmpgroup;
		GSList *groups = NULL;

		while(buddies) {
			tmpbuddy = buddies->data;
			tmpgroup = purple_buddy_get_group(tmpbuddy);
			groups = g_slist_append(groups, (char *)purple_group_get_name(tmpgroup));
			buddies = g_slist_remove(buddies, tmpbuddy);
		}

		purple_debug_info("jabber", "jabber_roster_remove_buddy(): Removing %s from %s\n",
		                  purple_buddy_get_name(buddy), purple_group_get_name(group));

		jabber_roster_update(gc->proto_data, name, groups);
	} else {
		JabberIq *iq = jabber_iq_new_query(gc->proto_data, JABBER_IQ_SET,
				"jabber:iq:roster");
		xmlnode *query = xmlnode_get_child(iq->node, "query");
		xmlnode *item = xmlnode_new_child(query, "item");

		xmlnode_set_attrib(item, "jid", name);
		xmlnode_set_attrib(item, "subscription", "remove");

		purple_debug_info("jabber", "jabber_roster_remove_buddy(): Removing %s\n",
		                  purple_buddy_get_name(buddy));

		jabber_iq_send(iq);
	}
}
Пример #19
0
	void Buddy::Update ()
	{
		if (Name_ != GetEntryName ())
		{
			Name_ = GetEntryName ();
			emit nameChanged (Name_);
		}

		auto purpleStatus = purple_presence_get_active_status (Buddy_->presence);
		const auto& status = FromPurpleStatus (Account_->GetPurpleAcc (), purpleStatus);
		if (status != Status_)
		{
			Status_ = status;
			emit statusChanged (Status_, QString ());
		}

		auto groupNode = purple_buddy_get_group (Buddy_);
		const auto& newGroup = groupNode ? QString::fromUtf8 (groupNode->name) : QString ();
		if (newGroup != Group_)
		{
			Group_ = newGroup;
			emit groupsChanged ({ Group_ });
		}
	}
Пример #20
0
//End VoxOx
static void add_purple_buddies_to_groups(JabberStream *js, const char *jid,
		const char *alias, GSList *groups)
{
	GSList *buddies, *g2, *l;
	gchar *my_bare_jid;
	GList *pool = NULL;

	buddies = purple_find_buddies(js->gc->account, jid);

	g2 = groups;

	if(!groups) {
		if(!buddies)
			g2 = g_slist_append(g2, g_strdup(_("Buddies")));
		else {
			g_slist_free(buddies);
			return;
		}
	}

	my_bare_jid = g_strdup_printf("%s@%s", js->user->node, js->user->domain);

	while(buddies) {
		PurpleBuddy *b = buddies->data;
		PurpleGroup *g = purple_buddy_get_group(b);

		buddies = g_slist_remove(buddies, b);

		if((l = g_slist_find_custom(g2, g->name, (GCompareFunc)strcmp))) {
			const char *servernick;

			/* Previously stored serverside / buddy-supplied alias */
			if((servernick = purple_blist_node_get_string((PurpleBlistNode*)b, "servernick")))
				serv_got_alias(js->gc, jid, servernick);

			/* Alias from our roster retrieval */
			if(alias && (!b->alias || strcmp(b->alias, alias)))
				purple_serv_got_private_alias(js->gc, jid, alias);
			g_free(l->data);
			g2 = g_slist_delete_link(g2, l);
		} else {
			pool = g_list_prepend(pool, b);
		}
	}

	while(g2) {
		PurpleGroup *g = purple_find_group(g2->data);
		PurpleBuddy *b = NULL;

		if (pool) {
			b = pool->data;
			pool = g_list_delete_link(pool, pool);
		} else {			
			b = purple_buddy_new(js->gc->account, jid, alias);
		}

		if(!g) {
			g = purple_group_new(g2->data);
			purple_blist_add_group(g, NULL);
		}

		purple_blist_add_buddy(b, NULL, g, NULL);
		purple_blist_alias_buddy(b, alias);

		/* If we just learned about ourself, then fake our status,
		 * because we won't be receiving a normal presence message
		 * about ourself. */
		if(!strcmp(b->name, my_bare_jid)) {
			PurplePresence *gpresence;
			PurpleStatus *status;

			gpresence = purple_account_get_presence(js->gc->account);
			status = purple_presence_get_active_status(gpresence);
			jabber_presence_fake_to_self(js, status);
		}

		g_free(g2->data);
		g2 = g_slist_delete_link(g2, g2);
	}

	while (pool) {
		PurpleBuddy *b = pool->data;
		purple_blist_remove_buddy(b);
		pool = g_list_delete_link(pool, pool);
	}

	g_free(my_bare_jid);
	g_slist_free(buddies);
}
Пример #21
0
GList *fb_get_buddies_friend_list (FacebookAccount *fba,
		const gchar *uid, JsonArray *friend_list_ids)
{
	GSList *buddies;
	GSList *cur;       
	GHashTable *cur_groups;
	int i;
	GList *final_buddies, *cur_buddy;
	PurpleGroup *fb_group;
	PurpleBuddy *buddy;

	final_buddies = NULL;
	buddies = purple_find_buddies(fba->account, uid);

	// If we're already in the buddy list, stop.  Ignore FB info because
	// it will be incorrect.
	if (atoll(uid) == fba->uid && buddies != NULL) {
		purple_debug_info("facebook",
			"already have buddies for self, not adding\n");
		for (cur = buddies; cur != NULL; cur = cur->next)
		{
			final_buddies = g_list_append(
				final_buddies, cur->data);
		}
		g_slist_free(buddies);
		return final_buddies;
	}
	
	//Do we want to ignore groups?
	if (!purple_account_get_bool(fba->account, "facebook_use_groups", TRUE))
	{
		if (buddies != NULL) {
			//Copy the slist into the list
			for (cur = buddies; cur != NULL; cur = cur->next)
			{
				final_buddies = g_list_append(
					final_buddies, cur->data);
			}
			g_slist_free(buddies);
			return final_buddies;
		} else {
			buddy = purple_buddy_new(fba->account, uid, NULL);
			fb_group = purple_find_group(DEFAULT_GROUP_NAME);
			if (fb_group == NULL)
			{
				fb_group = purple_group_new(DEFAULT_GROUP_NAME);
				purple_blist_add_group(fb_group, NULL);
			}
			purple_blist_add_buddy(buddy, NULL, fb_group, NULL);
			final_buddies = g_list_append(final_buddies, buddy);
			return final_buddies;
		}
	}
	
	// Determine what buddies exist and what groups they are in.
	cur_groups = g_hash_table_new_full(g_str_hash, g_str_equal,
		g_free, NULL);
	for (cur = buddies; cur != NULL; cur = cur->next)
	{
		const gchar *group_name;

		group_name = purple_group_get_name(purple_buddy_get_group(
					(PurpleBuddy *)cur->data));
		group_name = purple_normalize_nocase(NULL, group_name);
		
		g_hash_table_insert(cur_groups, g_strdup(group_name), cur->data);
	}
	g_slist_free(buddies);

	// Create/insert necessary buddies
	if (friend_list_ids) {
		for (i = 0; i < json_array_get_length(friend_list_ids); i++)
		{
			const gchar *friend_list_id;

			friend_list_id = json_node_get_string(
				json_array_get_element(friend_list_ids, i));

			buddy = add_buddy(fba, friend_list_id, uid, cur_groups);

			final_buddies = g_list_append(final_buddies, buddy);
		}
	} else {
		// No friend list data, so we use the default group.
		final_buddies = g_list_append(final_buddies,
			add_buddy(fba, "-1", uid, cur_groups));
	}

	// Figure out which groups/buddies are not represented.
	for (cur_buddy = final_buddies; cur_buddy != NULL;
	     cur_buddy = cur_buddy->next)
	{
		const gchar *group_name = purple_group_get_name(purple_buddy_get_group(
					(PurpleBuddy *)cur_buddy->data));
		g_hash_table_remove(cur_groups, purple_normalize_nocase(NULL, group_name));
	}

	// Delete remaining buddies to maintain sync state with server.
	g_hash_table_foreach(cur_groups, destroy_buddy, fba);

	// Cleanup!
	g_hash_table_destroy(cur_groups);

	return final_buddies;
}
Пример #22
0
static void add_purple_buddy_to_groups(JabberStream *js, const char *jid,
		const char *alias, GSList *groups)
{
	GSList *buddies, *l;
	PurpleAccount *account = purple_connection_get_account(js->gc);

	buddies = purple_find_buddies(js->gc->account, jid);

	if(!groups) {
		if(!buddies)
			groups = g_slist_append(groups, g_strdup(_("Buddies")));
		else {
			/* TODO: What should we do here? Removing the local buddies
			 * is wrong, but so is letting the group state get out of sync with
			 * the server.
			 */
			g_slist_free(buddies);
			return;
		}
	}

	while(buddies) {
		PurpleBuddy *b = buddies->data;
		PurpleGroup *g = purple_buddy_get_group(b);

		buddies = g_slist_delete_link(buddies, buddies);

		/* XMPP groups are case-sensitive, but libpurple groups are
		 * case-insensitive. We treat a buddy in both "Friends" and "friends"
		 * as only being in one group, but if we push changes about the buddy
		 * to the server, the buddy will be dropped from one of the groups.
		 * Not optimal, but better than the alternative, I think.
		 */
		if((l = g_slist_find_custom(groups, purple_group_get_name(g), (GCompareFunc)purple_utf8_strcasecmp))) {
			/* The buddy is already on the local list. Update info. */
			const char *servernick, *balias;

			/* Previously stored serverside / buddy-supplied alias */
			if((servernick = purple_blist_node_get_string((PurpleBlistNode*)b, "servernick")))
				serv_got_alias(js->gc, jid, servernick);

			/* Alias from our roster retrieval */
			balias = purple_buddy_get_local_buddy_alias(b);
			if(alias && !purple_strequal(alias, balias))
				purple_serv_got_private_alias(js->gc, jid, alias);
			g_free(l->data);
			groups = g_slist_delete_link(groups, l);
		} else {
			/* This buddy isn't in the group on the server anymore */
			purple_debug_info("jabber", "jabber_roster_parse(): Removing %s "
			                  "from group '%s' on the local list\n",
			                  purple_buddy_get_name(b),
			                  purple_group_get_name(g));
			purple_blist_remove_buddy(b);
		}
	}

	if (groups) {
		char *tmp = roster_groups_join(groups);
		purple_debug_info("jabber", "jabber_roster_parse(): Adding %s to "
		                  "groups: %s\n", jid, tmp);
		g_free(tmp);
	}

	while(groups) {
		PurpleGroup *g = purple_find_group(groups->data);
		PurpleBuddy *b = purple_buddy_new(account, jid, alias);

		if(!g) {
			g = purple_group_new(groups->data);
			purple_blist_add_group(g, NULL);
		}

		purple_blist_add_buddy(b, NULL, g, NULL);
		purple_blist_alias_buddy(b, alias);

		g_free(groups->data);
		groups = g_slist_delete_link(groups, groups);
	}

	g_slist_free(buddies);
}
Пример #23
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);
}
Пример #24
0
/* jabber_roster_update frees the GSList* passed in */
static void jabber_roster_update(JabberStream *js, const char *name,
		GSList *groups)
{
	PurpleBuddy *b;
	PurpleGroup *g;
	GSList *l;
	JabberIq *iq;
	xmlnode *query, *item, *group;
	const char *balias;

	if (js->currently_parsing_roster_push)
		return;

	if(!(b = purple_find_buddy(js->gc->account, name)))
		return;

	if (groups) {
		char *tmp = roster_groups_join(groups);

		purple_debug_info("jabber", "jabber_roster_update(%s): [Source: "
		                  "groups]: groups: %s\n", name, tmp);
		g_free(tmp);
	} else {
		GSList *buddies = purple_find_buddies(js->gc->account, name);
		char *tmp;

		if(!buddies)
			return;
		while(buddies) {
			b = buddies->data;
			g = purple_buddy_get_group(b);
			groups = g_slist_append(groups, (char *)purple_group_get_name(g));
			buddies = g_slist_remove(buddies, b);
		}

		tmp = roster_groups_join(groups);
		purple_debug_info("jabber", "jabber_roster_update(%s): [Source: local blist]: groups: %s\n",
		                  name, tmp);
		g_free(tmp);
	}

	iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:roster");

	query = xmlnode_get_child(iq->node, "query");
	item = xmlnode_new_child(query, "item");

	xmlnode_set_attrib(item, "jid", name);

	balias = purple_buddy_get_local_buddy_alias(b);
	xmlnode_set_attrib(item, "name", balias ? balias : "");

	for(l = groups; l; l = l->next) {
		group = xmlnode_new_child(item, "group");
		xmlnode_insert_data(group, l->data, -1);
	}

	g_slist_free(groups);

	if (js->server_caps & JABBER_CAP_GOOGLE_ROSTER) {
		jabber_google_roster_outgoing(js, query, item);
		xmlnode_set_attrib(query, "xmlns:gr", "google:roster");
		xmlnode_set_attrib(query, "gr:ext", "2");
	}
	jabber_iq_send(iq);
}
Пример #25
0
std::string SpectrumBuddy::getGroup() {
	return purple_group_get_name(purple_buddy_get_group(m_buddy)) ? std::string(purple_group_get_name(purple_buddy_get_group(m_buddy))) : std::string("Buddies");
}
Пример #26
0
xmlnode * _h_elim_remove_buddy ( const char *name ,
                                 const char *id   ,
                                 SEXP_VALUE *args ,
                                 gpointer data    )
{
    ASSERT_ALISTP( args, id, name );

    fprintf( stderr, "(elim-remove-buddy)\n" );

    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  = NULL;

    gpointer       b_uid = ALIST_VAL_PTR( args, "bnode-uid" );
    const char    *b_arg = NULL;
    const char    *bname = NULL;
    const char    *gname = NULL; 
    PurpleGroup   *group = NULL; 
    PurpleBuddy   *buddy = NULL;
    gboolean       gone  = FALSE;

    if( b_uid )
    {
        PurpleBlistNodeType type = PURPLE_BLIST_OTHER_NODE;
        PurpleBlistNode    *node = find_blist_node_by_uid( b_uid , TRUE );

        if( !node )
        {
            sexp_val_free( args );
            return response_error( EINVAL, id, name, "rogue buddy pointer" );
        }
        type = purple_blist_node_get_type( node );

        // ===========================================================
        // groups, contacts and chats can safely be removed here:
        // buddies should instead be noted for removal in the next
        // block of code as they require client<->server interaction:
        switch( type )
        {
          case PURPLE_BLIST_GROUP_NODE  :
            purple_blist_remove_group  ( (PurpleGroup   *)node );
            gone = TRUE;
            break;
          case PURPLE_BLIST_CONTACT_NODE:
            purple_blist_remove_contact( (PurpleContact *)node );
            gone = TRUE;
            break;
          case PURPLE_BLIST_CHAT_NODE   :
            FIND_ACCOUNT( args, id, name, acct, auid, aname, proto );
            BNODE_ACCOUNT_CHECK(chat,(PurpleChat *)node, acct, args, id, name);
            purple_blist_remove_chat   ( (PurpleChat    *)node );
            gone = TRUE;
            break;
          case PURPLE_BLIST_BUDDY_NODE  :
            buddy = (PurpleBuddy *)node;
            FIND_ACCOUNT( args, id, name, acct, auid, aname, proto );
            BNODE_ACCOUNT_CHECK( buddy, buddy, acct, args, id, name );
            b_arg = purple_buddy_get_name( buddy );
            bname = purple_normalize( acct, b_arg );
            break;
          default:
            sexp_val_free( args );
            return response_error( EINVAL, id, name, 
                                   "Unknown buddy list node type" );
        }

        if( gone )
        {
            xmlnode *rval = xnode_new( "alist" );
            if( acct )
            {
                AL_STR( rval, "account-name", aname );
                AL_STR( rval, "im-protocol" , proto );
                AL_PTR( rval, "account-uid" , acct  );
            }
            AL_PTR ( rval, "bnode-uid" , buddy );
            AL_ENUM( rval, "bnode-type", type  , ":blist-node-type" );

            sexp_val_free( args );
            return response_value( 0, id, name, rval );
        }
    }
    else
    {
        b_arg = ALIST_VAL_STRING( args, "bnode-name" );
        FIND_ACCOUNT( args, id, name, acct, auid, aname, proto );

        if( b_arg )
        {
            bname = purple_normalize( acct, b_arg   );
            gname = ALIST_VAL_STRING( args, "group" );
            group = ( gname && *gname ) ? purple_find_group( gname ) : NULL;
            buddy = ( group ?
                      purple_find_buddy_in_group( acct, bname, group ) :
                      purple_find_buddy         ( acct, bname        ) );
        }
    }

    if( !b_arg || !*b_arg )
    {
        sexp_val_free( args );
        return response_error( EINVAL, id, name, "buddy not specified" );
    }

    // buddy must be in our local list or libpurple won't remove it from the
    // server list ( determined empirically, confirmed by inspecting code ):
    if( !buddy )
    {
        buddy = purple_buddy_new( acct, bname, bname );
        purple_blist_add_buddy  ( buddy, NULL, NULL, NULL );
    }

    if( buddy )
    {
        // the order of the remove operations is important: it has to be
        // this way round, as noted above: account buddy removal won't 
        // happen if the buddy is not in the blist when we try:
        if( !group ) group = purple_buddy_get_group( buddy );
        // is this correct? what if we have more than one copy of said buddy?
        // potentially confusing. dunno what the right thing to do is here.
        purple_account_remove_buddy( acct, buddy, group );
        purple_blist_remove_buddy( buddy );
    }
    else 
    {
        sexp_val_free( args );
        return response_error( ENXIO, id, name, "no such buddy" );
    }
    
    xmlnode *rval = xnode_new( "alist" );
    AL_STR ( rval, "account-name", purple_account_get_username   ( acct ) );
    AL_STR ( rval, "im-protocol" , purple_account_get_protocol_id( acct ) );
    AL_PTR ( rval, "account-uid" , acct  );
    AL_PTR ( rval, "bnode-uid"   , buddy );
    AL_ENUM( rval, "bnode-type", PURPLE_BLIST_BUDDY_NODE, ":blist-node-type" );
    sexp_val_free( args );
    return response_value( 0, id, name, rval );
}
Пример #27
0
xmlnode * _h_elim_add_buddy ( const char *name ,
                              const char *id   ,
                              SEXP_VALUE *args ,
                              gpointer data    )
{
    ASSERT_ALISTP( args, id, name );

    elim_ping();
    
    int         loopc = 0;
    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" );
    }

    const char *b_arg = ALIST_VAL_STRING( args, "bnode-name" );
    const char *bname = purple_normalize( acct, b_arg        );
    const char *gname = ALIST_VAL_STRING( args, "group"      );
    if( !gname || !*gname ) gname = "Buddies";

    PurpleGroup *group = purple_group_new( gname );
    PurpleBuddy *buddy = purple_buddy_new( acct, bname, b_arg );
    PurpleBuddy *clone = NULL;
    //fprintf( stderr, "add-buddy( b: %p, g: %p )\n", buddy, group );
    // remove other references to this buddy
    purple_blist_add_buddy  ( buddy, NULL, group, NULL );
    purple_account_add_buddy( acct , buddy );
    while( ( clone = (PurpleBuddy*)find_blist_node_clone( buddy ) ) )
    {
        if( loopc++ > 99   ) 
        {
            fprintf( stderr, "ARGH! clone reaping looped: %d\n", loopc );
            break;
        }
        if( clone == buddy ) 
        { 
            fprintf( stderr, "ARGH! %p not a clone of %p\n", buddy, clone );
            break;
        }
        fprintf( stderr, "(removing clone %p %ld (of buddy: %p)\n", 
                 clone, (long)clone, buddy );
        fprintf( stderr, "   name : %s\n", purple_buddy_get_name(clone) );
        fprintf( stderr, "   group: %s)\n", 
                 purple_group_get_name( purple_buddy_get_group(clone) ) );
        purple_blist_remove_buddy( clone );
    }

    xmlnode *rval = xnode_new( "alist" );
    AL_PTR( rval, "account-uid" , acct  );
    AL_PTR( rval, "bnode-uid"   , buddy );
    AL_PTR( rval, "group-uid"   , group );
    AL_STR( rval, "bnode-name"  , purple_buddy_get_name         ( buddy ) );
    AL_STR( rval, "bnode-alias" , purple_buddy_get_alias        ( buddy ) );
    AL_STR( rval, "account-name", purple_account_get_username   ( acct  ) );
    AL_STR( rval, "im-protocol" , purple_account_get_protocol_id( acct  ) );
    AL_STR( rval, "group-name"  , purple_group_get_name         ( group ) );

    sexp_val_free( args );
    return response_value( 0, id, name, rval );
}
Пример #28
0
void SpectrumRosterManager::handleSubscription(const Subscription &subscription) {
	std::string remote_user = purpleUsername(subscription.to().username());
	if (remote_user.empty()) {
		Log(m_user->jid(), "handleSubscription: Remote user is EMPTY!");
		return;
	}

	if (m_user->isConnected()) {
		PurpleBuddy *buddy = NULL;

		// Try to get PurpleBuddy from SpectrumBuddy at first, because SpectrumBuddy
		// uses normalized username (buddy->name could be "User", but remote_user is normalized
		// so it's "user" for example).
		AbstractSpectrumBuddy *s_buddy = getRosterItem(remote_user);
		if (s_buddy)
			buddy = s_buddy->getBuddy();
		else
			buddy = purple_find_buddy(m_user->account(), remote_user.c_str());

		if (subscription.subtype() == Subscription::Subscribed) {
			// Accept authorize request.
			if (hasAuthRequest(remote_user)) {
				Log(m_user->jid(), "subscribed presence for authRequest arrived => accepting the request");
				m_authRequests[remote_user]->authorize_cb(m_authRequests[remote_user]->user_data);
				removeAuthRequest(remote_user);
			}

			if (!isInRoster(remote_user, "both")) {
				if (buddy) {
					Log(m_user->jid(), "adding this user to local roster and sending presence");
					if (s_buddy == NULL) {
						// There is PurpleBuddy, but not SpectrumBuddy (that should not happen, but this
						// code doesn't break anything).
						addRosterItem(buddy);
						Transport::instance()->sql()->addBuddy(m_user->storageId(), remote_user, "both");
						storeBuddy(buddy);
					}
					else {
						// Update subscription.
						s_buddy->setSubscription("both");
						Transport::instance()->sql()->updateBuddySubscription(m_user->storageId(), remote_user, "both");
						storeBuddy(buddy);
					}
				} else {
					Log(m_user->jid(), "user is not in legacy network contact lists => nothing to be subscribed");
				}
			}

			// XMPP user is able to get the first status presence just after "subscribed" presence.
			if (s_buddy) {
				sendPresence(s_buddy);
			}
			return;
		}
		else if (subscription.subtype() == Subscription::Subscribe) {
			// User is in roster, so that's probably response for RIE.
			if (s_buddy) {
				Log(m_user->jid(), "subscribe presence; user is already in roster => sending subscribed");

				s_buddy->setSubscription("to");
				Tag *reply = new Tag("presence");
				reply->addAttribute( "to", subscription.from().bare() );
				reply->addAttribute( "from", subscription.to().bare() );
				reply->addAttribute( "type", "subscribe" );
				Transport::instance()->send( reply );

				reply = new Tag("presence");
				reply->addAttribute( "to", subscription.from().bare() );
				reply->addAttribute( "from", subscription.to().bare() );
				reply->addAttribute( "type", "subscribed" );
				Transport::instance()->send( reply );

				// Sometimes there is "subscribed" request for new user received before "subscribe",
				// so s_buddy could be already there, but purple_account_add_buddy has not been called.
				if (buddy) {
					Log(m_user->jid(), "Trying to purple_account_add_buddy just to be sure.");
					purple_account_add_buddy(m_user->account(), buddy);
				}
			}
			// User is not in roster, so that's probably new subscribe request.
			else {
				Log(m_user->jid(), "subscribe presence; user is not in roster => adding to legacy network");
				// Disable handling new-buddy event, because we're going to create new buddy by Spectrum, not
				// by libpurple (so we don't want to add it to RIE queue and send back to XMPP user).
				m_loadingFromDB = true;
				PurpleBuddy *buddy = purple_buddy_new(m_user->account(), remote_user.c_str(), remote_user.c_str());
#ifndef TESTS
				SpectrumBuddy *s_buddy = new SpectrumBuddy(-1, buddy);
				buddy->node.ui_data = (void *) s_buddy;
				s_buddy->setSubscription("to");
				if (usesJidEscaping(subscription.to().username()))
					s_buddy->setFlags(s_buddy->getFlags() | SPECTRUM_BUDDY_JID_ESCAPING);
				addRosterItem(s_buddy);
#endif
				// Add newly created buddy to legacy network roster.
				purple_blist_add_buddy(buddy, NULL, NULL ,NULL);
				purple_account_add_buddy(m_user->account(), buddy);
				m_loadingFromDB = false;
			}
			return;
		} else if (subscription.subtype() == Subscription::Unsubscribe || subscription.subtype() == Subscription::Unsubscribed) {
			if (subscription.subtype() == Subscription::Unsubscribed) {
				// Reject authorize request.
				if (hasAuthRequest(remote_user)) {
					Log(m_user->jid(), "unsubscribed presence for authRequest arrived => rejecting the request");
					m_authRequests[remote_user]->deny_cb(m_authRequests[remote_user]->user_data);
					removeAuthRequest(remote_user);
					return;
				}
			}

			// Buddy is in legacy network roster, so we can remove it.
			if (buddy) {
				Log(m_user->jid(), "unsubscribed presence => removing this contact from legacy network");
				// Remove buddy from database, if he's already there.
				if (s_buddy) {
					long id = s_buddy->getId();
					Transport::instance()->sql()->removeBuddy(m_user->storageId(), remote_user, id);
				}

				// Remove buddy from legacy network roster.
				purple_account_remove_buddy(m_user->account(), buddy, purple_buddy_get_group(buddy));
				purple_blist_remove_buddy(buddy);
			} else {
				// this buddy is not in legacy network roster, so there is nothing to remove...
			}

			removeFromLocalRoster(remote_user);

			// inform user about removing this buddy
			Tag *tag = new Tag("presence");
			tag->addAttribute("to", subscription.from().bare());
			tag->addAttribute("from", subscription.to().username() + "@" + Transport::instance()->jid() + "/bot");
			if(subscription.subtype() == Subscription::Unsubscribe) {
				tag->addAttribute( "type", "unsubscribe" );
			} else {
				tag->addAttribute( "type", "unsubscribed" );
			}
			Transport::instance()->send( tag );
			return;
		}
	}
	else {
		Log(subscription.from().full(), "Subscribe presence received, but is not connected to legacy network yet.");
	}
}
static void received_im_msg_cb(PurpleAccount *account, char *who, char *buffer,
    PurpleConversation *conv, PurpleMessageFlags flags, void *data) {
    // A workaround to avoid skipping of the first message as a result on NULL-conv:
    if (conv == NULL) conv = purple_conversation_new(PURPLE_CONV_TYPE_IM,
        account, who); 
    PurpleBuddy *buddy = purple_find_buddy(account, who);
    PurplePresence *presence = purple_buddy_get_presence(buddy);
    msg_metadata_t msg;

    //Get message
    msg.text = purple_markup_strip_html(buffer);
    msg.remote_username = who;

    //LOCAL USER:
    msg.local_alias = purple_account_get_alias(account);
    msg.local_username = (char *) purple_account_get_name_for_display(account);

    //REMOTE USER (Buddy):
    //Get buddy alias
    msg.remote_alias = purple_buddy_get_alias(buddy);
    if(msg.remote_alias == NULL) msg.remote_alias = "";

    //Get buddy group
    PurpleGroup *group = purple_buddy_get_group(buddy);
    //return empty string if not in group
    msg.remote_from_group = group != NULL ? purple_group_get_name(group) : ""; 

    //Get protocol ID
    msg.protocol_id = purple_account_get_protocol_id(account);
    //trim out PROTOCOL_PREFIX (eg.: "prpl-irc" => "irc")
    if(!strncmp(msg.protocol_id,PROTOCOL_PREFIX,strlen(PROTOCOL_PREFIX))) 
        msg.protocol_id += strlen(PROTOCOL_PREFIX); 

    //Get status
    PurpleStatus *status = purple_account_get_active_status(account);
    PurpleStatusType *type = purple_status_get_type(status);
    //remote
    PurpleStatus *r_status = purple_presence_get_active_status(presence);
    PurpleStatusType *r_status_type =	purple_status_get_type(r_status);

    //Get status id
    msg.local_status_id = NULL;
    msg.local_status_id = purple_primitive_get_id_from_type(
        purple_status_type_get_primitive(type));
    //remote
    msg.remote_status_id = NULL;
    msg.remote_status_id = purple_primitive_get_id_from_type(
        purple_status_type_get_primitive(r_status_type));

    //Get status message
    msg.local_status_msg = NULL;
    if (purple_status_type_get_attr(type, "message") != NULL) {
        msg.local_status_msg = purple_status_get_attr_string(status, "message");
    } else {
        PurpleSavedStatus *savedstatus = purple_savedstatus_get_current();
        if(savedstatus)
            msg.local_status_msg = purple_savedstatus_get_message(savedstatus);
    }
    //remote
    msg.remote_status_msg = NULL;
    if (purple_status_type_get_attr(r_status_type, "message") != NULL) {
        msg.remote_status_msg = purple_status_get_attr_string(r_status, "message");
    } else {
        msg.remote_status_msg = "";
    }

    run_lua(conv, msg);
}
Пример #30
0
static void
send_online_buddy_cb (PurpleBlistNode *cnode, gpointer data)
{
	PurplePlugin *plugin = (PurplePlugin *)data;
	PurpleConnection *gc;
   GSList *blist;
   PurpleBlistNode *gnode, *node;
   PurpleBuddy *b, *buddy;
   PurpleGroup *g, *check_group;
   const char *name, *gname, *receiver;
   int count = 0;
   PurpleAccount *account;
	PurpleIMConversation *im;
	gchar *buddylist = NULL;
	int total, flag = 0, counter = 0;
	gchar *group_info;

   const gchar *groupname = purple_group_get_name(data);
	purple_debug_info("send-option", "The group selected is: %s", groupname);

   buddy = (PurpleBuddy *)cnode;
	purple_debug_info("send-option", "Inside send_online_buddy_cb");
	receiver = purple_buddy_get_name(buddy); 
	purple_debug_info("send-option", "Receiver name: %s", receiver);
	account = purple_buddy_get_account(buddy);
	gc = purple_account_get_connection(account);

	im = purple_conversations_find_im_with_account(receiver, purple_connection_get_account(gc));
       if(im)
	      purple_debug_info("send-option", "Yayy, IM!");
       else
         purple_debug_info("send-option", "Boo! No IM :(");
	if (im == NULL)
      im = purple_im_conversation_new(purple_connection_get_account(gc), receiver);

   for(gnode = purple_blist_get_buddy_list()->root;
       gnode != NULL;
       gnode = gnode->next)
   {
	    if (PURPLE_IS_GROUP(gnode)) {
         g = (PurpleGroup*)gnode; 
		 /*fishy. It says g may be uninitiliazed here. What can I initilalie g to in the else, to get rid of the warning*/  	
         if (g != data)
			   continue;
			else
            break;
       }
	}

   gname = purple_group_get_name(g);
	total = purple_counting_node_get_online_count(PURPLE_COUNTING_NODE(g));;
   purple_debug_info("send-option", "%s (%d): \n",gname, total);
   group_info = g_strdup_printf("%s (%d):\n",gname, total);
	buddylist = g_strconcat(group_info, "\t","\t", NULL);
			 
   for (blist = purple_blist_get_buddies(); 
	  	  blist != NULL;
		  blist = blist->next)
   {
       node = blist->data;

       if (PURPLE_IS_BUDDY(node)) {
		 b = (PurpleBuddy*)node;
       name = purple_buddy_get_alias(b);                  
       check_group = purple_buddy_get_group(b);
                  
       if (data == check_group && PURPLE_BUDDY_IS_ONLINE(b)) {
          ++count;
			 ++counter;

	       if (flag == 1 && counter != total) {
             buddylist = g_strconcat(name, ",\t", NULL);
             flag = 0;
          } else if (flag == 1 && counter == total) {
             buddylist = g_strconcat(name, ".\t", NULL);
				 purple_debug_info(NULL, "%s", buddylist);	
             purple_conversation_send(PURPLE_CONVERSATION(im), buddylist); 
				 buddylist = NULL;
				 count = 0;
			 } else{
				 if (count <= 20 && counter != total) {
				  buddylist = g_strconcat(buddylist, name, ",\t", NULL);	/*fishy cant insert newline*/	
				 } else {
					if (counter == total)
						 buddylist = g_strconcat(buddylist, name, ".\t", NULL);
					else
                   buddylist = g_strconcat(buddylist, name, ",\t", NULL);
						 
                   purple_debug_info(NULL, "%s", buddylist);	
                   purple_conversation_send(PURPLE_CONVERSATION(im), buddylist); 
						 buddylist = NULL;
						 count = 0;
						 flag = 1;
             }
	       }
          }
	    }
	}
   purple_debug_info("send-option", "The counter is (%d): \n",counter);
   
   purple_notify_message (plugin, PURPLE_NOTIFY_MSG_INFO,
		    "Send online buddies", "Successfully sent your online buddies :)", NULL, NULL,
		     NULL, NULL);
	
	g_free(buddylist);
}