Example #1
0
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;
}
Example #2
0
/**
 * Get the contact list from the xmlnode with name 'contact-list',
 * note that this node can either be a child node of the sipc
 * response xml message , or a child node of the local xml file.
 */
static void
get_contact_list(fetion_account *ac, xmlnode *contact_node)
{
    gchar        *temp;
    gchar        *temp1;
    xmlnode      *node;
    fetion_group *group;
    fetion_buddy *buddy;
    gboolean      has_ungroup = FALSE;

    g_return_if_fail(ac != NULL);
    g_return_if_fail(contact_node != NULL);

    /* group list */
    node = xmlnode_find(contact_node, "buddy-lists");
    node = xmlnode_child(node);

    while (node) {
        temp  = xmlnode_prop(node, "name");
        temp1 = xmlnode_prop(node, "id");

        group      = fetion_group_create(atoi(temp1), temp);
        ac->groups = g_slist_append(ac->groups, group);

        g_free(temp);
        g_free(temp1);

        node = node->next;
    }

    /* contact list  */
    node = xmlnode_find(contact_node, "buddies");
    node = xmlnode_child(node);

    while (node) {
        buddy            = fetion_buddy_create();
        buddy->userid    = xmlnode_prop(node, "i");
        buddy->sipuri    = xmlnode_prop(node, "u");
        buddy->localname = xmlnode_prop(node, "n");
        buddy->groups    = xmlnode_prop(node, "l");
        buddy->sid       = get_sid_from_sipuri(buddy->sipuri);

        if (xmlnode_has_prop(node, "r")) {

            temp = xmlnode_prop(node, "r");
            buddy->status = atoi(temp);
            g_free(temp);

        } else {
            buddy->status = 0;
        }

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

        /* ungrouped */
        if (*(buddy->groups) == '\0' || buddy->groups[0] == '0') {
            g_free(buddy->groups);
            buddy->groups = g_strdup("0");

            if (!has_ungroup) { /**< add an "ungroup" group */
                group      = fetion_group_create(0, _("Ungrouped"));
                ac->groups = g_slist_append(ac->groups, group);

                has_ungroup = TRUE;
            }
        }

        node = node->next;
    }
}
Example #3
0
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;
}