Example #1
0
static void
xmpp_stream_process_message(XmppStream *stream, xmlnode *root)
{
    gchar         *value;
    gchar         *bare_jid;
    xmlnode       *node;
    HybridAccount *account;

    g_return_if_fail(stream != NULL);
    g_return_if_fail(root != NULL);

    account = stream->account->account;

    if (!xmlnode_has_prop(root, "type")) {
        hybrid_debug_error("xmpp", 
                "invalid message received without a type property.");
        return;
    }

    value = xmlnode_prop(root, "type");

    if (g_strcmp0(value, "chat") != 0) {

        hybrid_debug_error("xmpp", "unsupported message type.");
        g_free(value);

        return;
    }

    g_free(value);

    if (!xmlnode_has_prop(root, "from")) {
        
        hybrid_debug_error("xmpp", "invalid message without a from property.");
        return;
    }

    value = xmlnode_prop(root, "from");
    bare_jid = get_bare_jid(value);
    g_free(value);

    if ((node = xmlnode_find(root, "composing"))) {
        hybrid_conv_got_inputing(account, bare_jid, FALSE);
    }

    if ((node = xmlnode_find(root, "active"))) {
        hybrid_conv_clear_inputing(account, bare_jid);
    }

    if ((node = xmlnode_find(root, "paused"))) {
        hybrid_conv_stop_inputing(account, bare_jid);
    }

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

        value = xmlnode_content(node);
        hybrid_conv_got_message(account, bare_jid, value, time(NULL));
        g_free(value);

        return;
    }

}
Example #2
0
gint
fetion_process_message(fetion_account *account, const gchar *sipmsg)
{
	gchar *from;
	gchar *sid;
	gchar *callid;
	gchar *sequence;
	gchar *sendtime;
	gchar *text;
	gchar *sip_text;
	fetion_buddy *buddy;

	g_return_val_if_fail(account != NULL, HYBRID_ERROR);
	g_return_val_if_fail(sipmsg != NULL, HYBRID_ERROR);

	if (!(text = strstr(sipmsg, "\r\n\r\n"))) {
		hybrid_debug_error("fetion", "invalid message received\n");

		return HYBRID_ERROR;
	}

	text += 4;

	from     = sip_header_get_attr(sipmsg, "F");
	callid   = sip_header_get_attr(sipmsg, "I");
	sendtime = sip_header_get_attr(sipmsg, "D");
	sequence = sip_header_get_attr(sipmsg, "Q");

	sip_text = g_strdup_printf(
					"SIP-C/4.0 200 OK\r\n"
					"I: %s\r\n"
					"Q: %s\r\n"
					"F: %s\r\n\r\n", callid, sequence, from);
	g_free(callid);
	g_free(sendtime);
	g_free(sequence);

	hybrid_debug_info("fetion", "message response, send:\n%s", sip_text);

	if (send(account->sk, sip_text, strlen(sip_text), 0) == -1) {
		g_free(sip_text);
		g_free(from);

		return HYBRID_ERROR;
	}

	g_free(sip_text);

	sid = get_sid_from_sipuri(from);
	g_free(from);

	if (!(buddy = fetion_buddy_find_by_sid(account, sid))) {

		hybrid_debug_error("fetion", "invalid message received\n");
		g_free(sid);

		return HYBRID_ERROR;
	}

	hybrid_conv_got_message(account->account, buddy->userid, text, time(NULL));

	g_free(sid);


	return HYBRID_OK;
}