コード例 #1
0
ファイル: roster.c プロジェクト: cuckoohello/telepathy-fetion
static void
fetion_contact_list_request_subscription_async (
        TpBaseContactList *contact_list,
        TpHandleSet *contacts,
        const gchar *message,
        GAsyncReadyCallback callback,
        gpointer user_data)
{
    FetionContactList *self = FETION_CONTACT_LIST (contact_list);
    FetionConnection *conn = FETION_CONNECTION (self->priv->conn);
    HybridAccount* account = conn->priv->account;

    TpIntsetFastIter iter;
    TpHandle member;

    tp_intset_fast_iter_init (&iter, tp_handle_set_peek (contacts));

    while (tp_intset_fast_iter_next (&iter, &member))
    {
        HybridBuddy* buddy = hybrid_blist_find_buddy_by_handle(account,member);

        /* if they already authorized us, it's a no-op */
        if (buddy != NULL)
            continue;
        HybridGroup *default_group = hybrid_blist_find_group(account, "0"); 
        g_assert (default_group != NULL);

        account->proto->info->im_ops->buddy_add(account,default_group,tp_handle_inspect(account->contact_repo,member),NULL,message);

    }

    tp_simple_async_report_success_in_idle ((GObject *) self, callback,
            user_data, fetion_contact_list_request_subscription_async);
}
コード例 #2
0
ファイル: roster.c プロジェクト: cuckoohello/telepathy-fetion
    static void
fetion_contact_list_remove_from_group_async (TpBaseContactList *contact_list,
        const gchar *group,
        TpHandleSet *contacts,
        GAsyncReadyCallback callback,
        gpointer user_data)
{
    FetionContactList *self = FETION_CONTACT_LIST (contact_list);
    FetionConnection *conn =
        FETION_CONNECTION (self->priv->conn);
    HybridAccount *account = conn->priv->account;
    HybridGroup *origin_group = hybrid_blist_find_group_by_name(account, group);
    HybridGroup *default_group = hybrid_blist_find_group(account, "0");
    g_assert (default_group != NULL);


    TpHandleSet *changed = tp_handle_set_new (account->contact_repo);
    TpIntsetFastIter iter;
    TpHandle member;

    tp_intset_fast_iter_init (&iter, tp_handle_set_peek (contacts));

    while (tp_intset_fast_iter_next (&iter, &member))
    {
        HybridBuddy* buddy = hybrid_blist_find_buddy_by_handle(account,member);
        if(buddy == NULL)
            continue;
        HybridGroup *current_group = buddy->parent;
        if (current_group != origin_group)
            continue;
        if(!account->proto->info->im_ops->buddy_move(account,buddy,default_group))
            continue;

        tp_handle_set_add (changed, member);
    }

    if (!tp_handle_set_is_empty (changed))
        tp_base_contact_list_groups_changed (contact_list, changed, NULL, 0,
                &group, 1);

    tp_handle_set_destroy (changed);
    tp_simple_async_report_success_in_idle ((GObject *) self, callback,
            user_data, fetion_contact_list_remove_from_group_async);
}
コード例 #3
0
ファイル: fx_buddy.c プロジェクト: chenyukang/hybrid
void
fetion_buddies_init(fetion_account *ac)
{
	GSList *pos;
	gchar *start, *stop, *id;
	fetion_buddy *buddy;
	HybridGroup *imgroup;
	HybridBuddy *imbuddy;

	for (pos = ac->buddies; pos; pos = pos->next) {
		buddy = (fetion_buddy*)pos->data;

		start = buddy->groups;
		stop = buddy->groups;

		while (*stop) {
			for (; *stop && *stop != ';'; stop ++);
			id = g_strndup(start, stop - start);

			imgroup = hybrid_blist_find_group(ac->account, id);

			imbuddy = hybrid_blist_add_buddy(ac->account, imgroup,
					buddy->userid, buddy->localname);

			if (*(imbuddy->name) == '\0') {
				hybrid_blist_set_buddy_name(imbuddy, buddy->sid);
			}

			hybrid_blist_set_buddy_status(imbuddy, buddy->status == 1 ? TRUE : FALSE);

			g_free(id);

			if (*stop) {
				stop ++;
				start = stop;

			} else {
				break;
			}
		}
	}
}
コード例 #4
0
ファイル: fx_buddy.c プロジェクト: chenyukang/hybrid
static gint
handle_request_cb(fetion_account *account, const gchar *sipmsg,
			fetion_transaction *trans)
{
	gchar *pos;
	gchar *value;
	fetion_buddy *buddy;
	xmlnode *root;
	xmlnode *node;
	HybridGroup *group;
	HybridBuddy *bd;
	gchar *name;

	if (!(pos = strstr(sipmsg, "\r\n\r\n"))) {
		return HYBRID_ERROR;
	}

	pos += 4;

	if (!(root = xmlnode_root(pos, strlen(pos)))) {
		return HYBRID_ERROR;
	}

	if (!(node = xmlnode_find(root, "buddy"))) {
		return HYBRID_ERROR;
	}

	if (!xmlnode_has_prop(node, "uri") ||
		!xmlnode_has_prop(node, "user-id")) {
		return HYBRID_ERROR;
	}

	buddy = fetion_buddy_create();
	buddy->sipuri = xmlnode_prop(node, "uri");
	buddy->userid = xmlnode_prop(node, "user-id");
	buddy->sid = get_sid_from_sipuri(buddy->sipuri);

	account->buddies = g_slist_append(account->buddies, buddy);

	if (xmlnode_has_prop(node, "local-name")) {
		buddy->localname = xmlnode_prop(node, "localname");
	}

	if (xmlnode_has_prop(node, "buddy-lists")) {
		buddy->groups = xmlnode_prop(node, "buddy-lists");

	} else {
		buddy->groups = "0";
	}

	if (xmlnode_has_prop(node, "relation-status")) {
		value = xmlnode_prop(node, "relation-status");
		buddy->status = atoi(value);
		g_free(value);

	} else {
		buddy->status = 0;
	}

	if (!(group = hybrid_blist_find_group(account->account, buddy->groups))) {
		account->buddies = g_slist_remove(account->buddies, buddy);
		fetion_buddy_destroy(buddy);
		return HYBRID_ERROR;
	}

	if (buddy->localname && *(buddy->localname) == '\0') {
		name = get_sid_from_sipuri(buddy->sipuri);

	} else {
		name = g_strdup(buddy->localname);
	}

	bd = hybrid_blist_add_buddy(account->account, group, buddy->userid, name);
	hybrid_blist_set_buddy_status(bd, buddy->status == 1 ? TRUE: FALSE);

	g_free(name);

	return HYBRID_OK;
}
コード例 #5
0
ファイル: fx_buddy.c プロジェクト: chenyukang/hybrid
static gint
buddy_add_cb(fetion_account *account, const gchar *sipmsg,
			fetion_transaction *trans)
{
	gint code;
	gchar *pos;
	gchar *value;
	gchar *name;
	fetion_buddy *buddy;
	HybridGroup *group;
	HybridBuddy *bd;
	xmlnode *root;
	xmlnode *node;

	hybrid_debug_info("fetion", "add buddy, recv:\n%s", sipmsg);

	if ((code = fetion_sip_get_code(sipmsg)) != 200) {

		hybrid_message_box_show(HYBRID_MESSAGE_WARNING,
				"Add buddy error. Server response with %d", code);

		return HYBRID_ERROR;
	}

	if (!(pos = strstr(sipmsg, "\r\n\r\n"))) {
		goto add_buddy_unknown_err;
	}

	pos += 4;

	if (!(root = xmlnode_root(pos, strlen(pos)))) {
		goto add_buddy_unknown_err;
	}

	if (!(node = xmlnode_find(root, "buddy"))) {

		xmlnode_free(root);

		goto add_buddy_unknown_err;
	}

	if (xmlnode_has_prop(node, "status-code")) {
		
		value = xmlnode_prop(node, "status-code");

		code = atoi(value);

		g_free(value);

		if (code == 200) {
			goto add_buddy_ok;
		}

		xmlnode_free(node);

		if (code == 521) {

			hybrid_message_box_show(HYBRID_MESSAGE_WARNING,
					"The buddy has already been in your buddy list,\n"
					"Please don't add it duplicately.");

			return HYBRID_ERROR;
		}

		if (code == 404) {

			hybrid_message_box_show(HYBRID_MESSAGE_WARNING,
					"The buddy you try to add doesn't exist.");

			return HYBRID_ERROR;
		}

		if (code == 486) {
			
			hybrid_message_box_show(HYBRID_MESSAGE_WARNING,
					"You have reached the daily limit of adding buddies,\n"
					"please try another day.");

			return HYBRID_ERROR;
		}

		goto add_buddy_unknown_err;
	}

add_buddy_ok:

	if (!xmlnode_has_prop(node, "user-id") ||
		!xmlnode_has_prop(node, "local-name") ||
		!xmlnode_has_prop(node, "uri") ||
		!xmlnode_has_prop(node, "buddy-lists")) {

		xmlnode_free(root);

		goto add_buddy_unknown_err;
	}

	buddy = fetion_buddy_create();

	buddy->userid    = xmlnode_prop(node, "user-id");
	buddy->localname = xmlnode_prop(node, "local-name");
	buddy->sipuri    = xmlnode_prop(node, "uri");
	buddy->groups    = xmlnode_prop(node, "buddy-lists");

	xmlnode_free(root);

	account->buddies = g_slist_append(account->buddies, buddy);

	if (!(group = hybrid_blist_find_group(account->account, buddy->groups))) {
		fetion_buddy_destroy(buddy);
		account->buddies = g_slist_remove(account->buddies, buddy);

		goto add_buddy_unknown_err;
	}

	if (buddy->localname && *(buddy->localname) == '\0') {
		name = get_sid_from_sipuri(buddy->sipuri);

	} else {
		name = g_strdup(buddy->localname);
	}

	bd = hybrid_blist_add_buddy(account->account, group, buddy->userid, name);
	hybrid_blist_set_buddy_status(bd, FALSE);

	g_free(name);

	return HYBRID_OK;

add_buddy_unknown_err:
	hybrid_message_box_show(HYBRID_MESSAGE_WARNING,
			"Add buddy error. Unknown reason.");
	
	return HYBRID_ERROR;
}