Esempio n. 1
0
/**
 * Process the synchronization message, when the contact list or the personal info
 * changed, the server will push this message to tell the client to update its
 * local cache file, well, we will not update the local cache file, we keep the
 * old version numbers, and reload it after the next logining.
 */
static void
process_sync_info(fetion_account *ac, const gchar *sipmsg)
{
    GSList       *list;
    gchar        *sid;
    fetion_buddy *buddy;
    HybridBuddy  *hb;

    hybrid_debug_info("fetion", "sync info,recv:\n%s", sipmsg);

    if (!(list = sip_parse_sync(ac, sipmsg))) {
        return;
    }

    while (list) {
        buddy = (fetion_buddy*)list->data;

        list = g_slist_remove(list, buddy);

        if (buddy->status == 0) {
            continue;
        }

        if (!(hb = hybrid_blist_find_buddy(ac->account, buddy->userid))) {
            continue;
        }

        if (buddy->status == 1) {

            hybrid_blist_set_buddy_status(hb, TRUE);

        } else {
            hybrid_blist_set_buddy_status(hb, FALSE);
        }

        sid = get_sid_from_sipuri(buddy->sipuri);

        hybrid_message_box_show(HYBRID_MESSAGE_INFO,
                _("Buddy <b>%s</b> has %s your add-buddy request."),
                buddy->localname && *(buddy->localname) != '\0' ?
                buddy->localname : sid,
                buddy->status == 1 ? _("accepted") : _("declined"));
    }

}
Esempio n. 2
0
static gboolean
fx_chat_start(HybridAccount *account, HybridBuddy *buddy)
{
    fetion_account *ac;

    ac = hybrid_account_get_protocol_data(account);

    if (!hybrid_blist_get_buddy_authorized(buddy)) {

        hybrid_message_box_show(HYBRID_MESSAGE_WARNING,
                "This buddy hasn't been authorized, you can't\n"
                "start a chat with him.");

        return FALSE;
    }

    return TRUE;
}
Esempio n. 3
0
static void
xmpp_stream_process_presence(XmppStream *stream, xmlnode *root)
{
    xmlnode   *node;
    XmppBuddy *buddy;
    gchar     *value;
    gchar     *full_jid;
    gchar     *bare_jid;
    gchar     *show;
    gchar     *status;
    gchar     *photo;

    if (!xmlnode_has_prop(root, "from")) {
        hybrid_debug_error("xmpp", "invalid presence.");
        return;
    }

    full_jid = xmlnode_prop(root, "from");
    bare_jid = get_bare_jid(full_jid);

    if (xmlnode_has_prop(root, "type")) {

        value = xmlnode_prop(root, "type");
        if (g_strcmp0(value, "unavailable") == 0) {

            if (!(buddy = xmpp_buddy_find(stream->account, bare_jid))) {
                goto presence_over;
            }

            xmpp_buddy_set_show(buddy, full_jid, value);
            g_free(value);
            goto presence_over;

        } else if (g_strcmp0(value, "subscribed") == 0) {
            
            hybrid_message_box_show(HYBRID_MESSAGE_INFO, 
                    "(<b>%s</b>) has accepted your request.", bare_jid);
            g_free(value);
            goto presence_over;

        } else if (g_strcmp0(value, "subscribe") == 0) {

            hybrid_buddy_request_window_create(stream->account->account,
                    full_jid, NULL);
            g_free(value);
            goto presence_over;
        }

        g_free(value);
    }

    if (!(buddy = xmpp_buddy_find(stream->account, bare_jid))) {
        goto presence_over;
    }

    /*
     * If the presence message doesn't have a <show> label,
     * then it means the current status of the buddy is 'avaiable'.
     */
    if ((node = xmlnode_find(root, "show"))) {

        show = xmlnode_content(node);
        xmpp_buddy_set_show(buddy, full_jid, show);
        g_free(show);

    } else {
        xmpp_buddy_set_show(buddy, full_jid, "avaiable");
    }

    if ((node = xmlnode_find(root, "status"))) {

        status = xmlnode_content(node);
        xmpp_buddy_set_status(buddy, full_jid, status);
        g_free(status);

    } 
    /*
     * Check whether it has a photo label, then we can
     * determine whether to fetch the buddy's photo.
     */
    if ((node = xmlnode_find(root, "photo"))) {

        photo = xmlnode_content(node);

        if (g_strcmp0(photo, buddy->photo) != 0) {

            xmpp_buddy_set_photo(buddy, photo);
            xmpp_buddy_get_info(stream, buddy->jid,
                    (trans_callback)buddy_get_info_cb, buddy);
        }

        g_free(photo);
    }
    
presence_over:
    g_free(full_jid);
    g_free(bare_jid);
}
Esempio n. 4
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;
}