예제 #1
0
파일: fx_msg.c 프로젝트: chenyukang/hybrid
/**
 * Callback function to handle the new-chat connecting event.
 * The message is:
 *
 * R fetion.com.cn SIP-C/4.0
 * F: 547264589
 * I: 5
 * Q: 2 R
 * A: TICKS auth="2051600954.830102111"
 * K: text/html-fragment
 * K: multiparty
 * K: nudge
 */
static gint
invite_connect_cb(gint sk, gpointer user_data)
{
	fetion_transaction *trans;
	fetion_account *account;
	fetion_sip *sip;
	invite_data *data;
	gchar *credential;
	gchar *sip_text;

	sip_header *aheader;
	sip_header *theader;
	sip_header *mheader;
	sip_header *nheader;

	data       = (invite_data*)user_data;
	trans      = data->trans;
	credential = data->credential;
	account    = trans->data;

	g_free(data);

	sip = account->sip;
	account->sk = sk;

	/* listen for this thread */
	account->source = hybrid_event_add(sk, HYBRID_EVENT_READ,
						hybrid_push_cb, account);

	fetion_sip_set_type(sip, SIP_REGISTER);
	aheader = sip_credential_header_create(credential);
	theader = sip_header_create("K", "text/html-fragment");
	mheader = sip_header_create("K", "multiparty");
	nheader = sip_header_create("K", "nudge");
	
	transaction_set_callid(trans, sip->callid);
	transaction_set_callback(trans, chat_reg_cb);
	transaction_add(account, trans);

	fetion_sip_add_header(sip, aheader);
	fetion_sip_add_header(sip, theader);
	fetion_sip_add_header(sip, mheader);
	fetion_sip_add_header(sip, nheader);

	sip_text = fetion_sip_to_string(sip, NULL);

	hybrid_debug_info("fetion", "register, send:\n%s", sip_text);
	
	if (send(sk, sip_text, strlen(sip_text), 0) == -1) {

		hybrid_debug_error("fetion", "register to the new chat channel failed");

		return HYBRID_ERROR;
	}

	g_free(sip_text);
	g_free(credential);

	return HYBRID_OK;
}
예제 #2
0
파일: fx_msg.c 프로젝트: chenyukang/hybrid
/**
 * Callback function to handle the invite-connect event, when we
 * get this acknowledge message, we should start to invite the buddy
 * to the conversation.
 *
 * The message received is:
 *
 * SIP-C/4.0 200 OK
 * I: 5
 * Q: 2 R
 * XI: 3d2ef745db9741a8946a57c40b0eb4d5
 * X: 1200
 * K: text/plain
 * K: text/html-fragment
 * K: multiparty
 * K: nudge
 *
 * then we send out invite-buddy request:
 */
static gint
chat_reg_cb(fetion_account *account, const gchar *sipmsg,
			fetion_transaction *trans)
{
	fetion_sip *sip;
	sip_header *eheader;
	gchar *body;
	gchar *sip_text;
	fetion_transaction *new_trans;
	fetion_buddy *buddy;

	sip = account->sip;

	fetion_sip_set_type(sip, SIP_SERVICE);

	if (!(buddy = fetion_buddy_find_by_userid(account, trans->userid))) {

		hybrid_debug_error("fetion", "invite new buddy failed");

		return HYBRID_ERROR;
	}

	eheader = sip_event_header_create(SIP_EVENT_INVITEBUDDY);
	fetion_sip_add_header(sip, eheader);

	body = generate_invite_buddy_body(buddy->sipuri);

	new_trans = transaction_clone(trans);
	transaction_set_callid(new_trans, sip->callid);
	transaction_set_callback(new_trans, invite_buddy_cb);
	transaction_add(account, new_trans);

	sip_text = fetion_sip_to_string(sip, body);
	g_free(body);

	hybrid_debug_info("fetion", "invite new buddy,send:\n%s", sip_text);

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

		hybrid_debug_error("fetion", "invite new buddy failed");

		return HYBRID_ERROR;
	}

	g_free(sip_text);

	return HYBRID_OK;
}
예제 #3
0
void
fetion_buddy_handle_request(fetion_account *ac, const gchar *sipuri,
		const gchar *userid, const gchar *alias, const gchar *groupid,
		gboolean accept)
{
	fetion_sip *sip;
	sip_header *eheader;
	gchar *body;
	gchar *sip_text;
	fetion_transaction *trans;

	g_return_if_fail(ac != NULL);
	g_return_if_fail(sipuri != NULL);
	g_return_if_fail(userid != NULL);
	g_return_if_fail(groupid != NULL);

	sip = ac->sip;
	
	fetion_sip_set_type(sip, SIP_SERVICE);
	eheader = sip_event_header_create(SIP_EVENT_HANDLECONTACTREQUEST);

	if (accept) {
		trans = transaction_create();
		transaction_set_callid(trans, sip->callid);
		transaction_set_userid(trans, userid);
		transaction_set_callback(trans, handle_request_cb);
		transaction_add(ac, trans);
	}

	fetion_sip_add_header(sip, eheader);
	body = generate_handle_request_body(sipuri, userid, alias, groupid, accept);

	sip_text = fetion_sip_to_string(sip, body);
	g_free(body);

	if (send(ac->sk, sip_text, strlen(sip_text), 0) == -1) {

		hybrid_debug_error("fetion", "handle buddy request failed.");
		g_free(sip_text);

		return;
	}

	g_free(sip_text);
}
예제 #4
0
파일: fx_msg.c 프로젝트: chenyukang/hybrid
gint
fetion_message_send_to_me(fetion_account *account, const gchar *text)
{
	sip_header *toheader;
	sip_header *eheader;
	gchar *sip_text;
	fetion_sip *sip;
	fetion_transaction *trans;

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

	sip = account->sip;

	fetion_sip_set_type(sip, SIP_MESSAGE);

	toheader = sip_header_create("T", account->sipuri);
	eheader  = sip_event_header_create(SIP_EVENT_SENDCATMESSAGE);

	fetion_sip_add_header(sip, toheader);
	fetion_sip_add_header(sip, eheader);

	trans = transaction_create();
	transaction_set_callid(trans, sip->callid);
	transaction_set_callback(trans, sms_to_me_cb);
	transaction_add(account, trans);

	sip_text = fetion_sip_to_string(sip, text);

	hybrid_debug_info("fetion", "send sms to youself,send:\n%s", sip_text);

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

		hybrid_debug_error("fetion", "send message to yourself error.");

		return HYBRID_ERROR;
	}

	g_free(sip_text);

	return HYBRID_OK;
}
예제 #5
0
gint
fetion_buddy_add(fetion_account *account, const gchar *groupid,
					const gchar *no, const gchar *alias)
{
	fetion_sip *sip;
	sip_header *eheader;
	fetion_transaction *trans;
	gchar *body;
	gchar *sip_text;

	g_return_val_if_fail(account != NULL, HYBRID_ERROR);
	g_return_val_if_fail(groupid != NULL, HYBRID_ERROR);
	g_return_val_if_fail(no != NULL, HYBRID_ERROR);

	sip = account->sip;

	fetion_sip_set_type(sip, SIP_SERVICE);
	eheader = sip_event_header_create(SIP_EVENT_ADDBUDDY);
	fetion_sip_add_header(sip, eheader);

	trans = transaction_create();
	transaction_set_callid(trans, sip->callid);
	transaction_set_callback(trans, buddy_add_cb);
	transaction_add(account, trans);

	body = generate_buddy_add_body(no, groupid, alias, account->nickname);
	sip_text = fetion_sip_to_string(sip, body);
	g_free(body);

	hybrid_debug_info("fetion", "add buddy,send:\n%s", sip_text);

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

		hybrid_debug_error("fetion", "add buddy failed");

		return HYBRID_ERROR;
	}

	g_free(sip_text);

	return HYBRID_OK;
}
예제 #6
0
파일: fx_msg.c 프로젝트: chenyukang/hybrid
gint
fetion_message_new_chat(fetion_account *account, const gchar *userid,
								const gchar *text)
{
	fetion_sip *sip;
	sip_header *eheader;
	fetion_transaction *trans;
	gchar *sip_text;

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

	sip = account->sip;

	/*start chat*/
	fetion_sip_set_type(sip, SIP_SERVICE);
	eheader = sip_event_header_create(SIP_EVENT_STARTCHAT);
	fetion_sip_add_header(sip, eheader);

	trans = transaction_create();
	transaction_set_callid(trans, sip->callid);
	transaction_set_userid(trans, userid);
	transaction_set_msg(trans, text);
	transaction_set_callback(trans, new_chat_cb);
	transaction_add(account, trans);

	sip_text = fetion_sip_to_string(sip, NULL);

	hybrid_debug_info("fetion", "new chat,send:\n%s", sip_text);

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

		hybrid_debug_error("fetion", "new chat failed");

		return HYBRID_ERROR;
	}
	
	g_free(sip_text); 

	return HYBRID_OK;
}
예제 #7
0
gint
fetion_buddy_get_info(fetion_account *ac, const gchar *userid,
		TransCallback callback, gpointer data)
{
	fetion_transaction *trans;
	fetion_sip *sip;
	sip_header *eheader;
	gchar *body;
	gchar *res;

	g_return_val_if_fail(ac != NULL, HYBRID_ERROR);
	g_return_val_if_fail(userid != NULL, HYBRID_ERROR);

	sip = ac->sip;

	fetion_sip_set_type(sip , SIP_SERVICE);
	eheader = sip_event_header_create(SIP_EVENT_GETCONTACTINFO);

	trans = transaction_create();
	transaction_set_callid(trans, sip->callid);
	transaction_set_userid(trans, userid);
	transaction_set_callback(trans, callback);
	transaction_set_data(trans, data);
	transaction_add(ac, trans);

	fetion_sip_add_header(sip, eheader);
	body = generate_get_info_body(userid);
	res = fetion_sip_to_string(sip, body);
	g_free(body);

	hybrid_debug_info("fetion", "send:\n%s", res);

	if (send(ac->sk, res, strlen(res), 0) == -1) {
		g_free(res);
		return HYBRID_ERROR;
	}

	g_free(res);

	return HYBRID_OK;
}
예제 #8
0
파일: fx_msg.c 프로젝트: chenyukang/hybrid
gint
fetion_message_send(fetion_account *account, const gchar *userid,
						const gchar *text)
{
	fetion_sip *sip;
	sip_header *toheader;
	sip_header *cheader;
	sip_header *kheader;
	sip_header *nheader;
	gchar *sip_text;
	fetion_buddy *buddy;

	g_return_val_if_fail(account != NULL, HYBRID_ERROR);
	g_return_val_if_fail(userid != NULL && *userid != '\0', HYBRID_ERROR);
	g_return_val_if_fail(text != NULL, HYBRID_ERROR);

	sip = account->sip;

	if (!(buddy = fetion_buddy_find_by_userid(account, userid))) {
		hybrid_debug_error("fetion", "FATAL, can't find specified buddy");

		return HYBRID_ERROR;
	}

	fetion_transaction *trans = transaction_create();

	transaction_set_userid(trans, userid);
	transaction_set_msg(trans, text);

	if (!account->channel_ready) {
		/* If the channel is not ready, make the transaction to wait
		 * until the transaction is ready */
		transaction_wait(account, trans);

		hybrid_debug_info("fetion", "channel not ready, transaction sleep.");

		return HYBRID_OK;
	}

	fetion_sip_set_type(sip, SIP_MESSAGE);

	nheader  = sip_event_header_create(SIP_EVENT_CATMESSAGE);
	toheader = sip_header_create("T", buddy->sipuri);
	cheader  = sip_header_create("C", "text/plain");
	kheader  = sip_header_create("K", "SaveHistory");
	fetion_sip_add_header(sip, toheader);
	fetion_sip_add_header(sip, cheader);
	fetion_sip_add_header(sip, kheader);
	fetion_sip_add_header(sip, nheader);

	transaction_set_callid(trans, sip->callid);
	transaction_set_callback(trans, sms_response_cb);

	transaction_set_data(trans, account);
	transaction_set_timeout(trans, (GSourceFunc)sms_timeout_cb, trans);
	transaction_add(account, trans);

	sip_text = fetion_sip_to_string(sip, text);

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

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

		return HYBRID_ERROR;
	}

	g_free(sip_text);

	return HYBRID_OK;
}
예제 #9
0
파일: fx_login.c 프로젝트: GCrean/hybrid
/**
 * Start sipc authencation with the response string.
 *
 * @param response It is generated by generate_response().
 */
static gint
sipc_aut_action(gint sk, fetion_account *ac, const gchar *response)
{
    gchar              *sipmsg;
    gchar              *body;
    sip_header         *aheader;
    sip_header         *akheader;
    sip_header         *ackheader;
    fetion_transaction *trans;
    fetion_sip         *sip = ac->sip;

    ac->sk = sk;

    hybrid_debug_info("fetion", "sipc authencation action");

    hybrid_account_set_connection_string(ac->account,
                                         _("start sipc authentication..."));

    body = generate_auth_body(ac);

    fetion_sip_set_type(sip, SIP_REGISTER);

    aheader     = sip_authentication_header_create(response);
    akheader = sip_header_create("AK", "ak-value");

    trans = transaction_create();
    transaction_set_callid(trans, sip->callid);
    transaction_set_callback(trans, sipc_auth_cb);
    transaction_add(ac, trans);

    fetion_sip_add_header(sip, aheader);
    fetion_sip_add_header(sip, akheader);

    if(ac->verification != NULL && ac->verification->algorithm != NULL)    {
        ackheader = sip_ack_header_create(ac->verification->code,
                                          ac->verification->algorithm,
                                          ac->verification->type,
                                          ac->verification->guid);
        fetion_sip_add_header(sip , ackheader);
    }
    fetion_verification_destroy(ac->verification);
    ac->verification = NULL;

    sipmsg = fetion_sip_to_string(sip, body);

    g_free(body);

    hybrid_debug_info("fetion", "Start sipc authentication , with ak-value");
    hybrid_debug_info("fetion", "send:\n%s", sipmsg);

    if(send(sk, sipmsg, strlen(sipmsg), 0) == -1) {
        hybrid_debug_error("fetion", "send sipc auth request:%s\n",
                strerror(errno));
        g_free(sipmsg);

        return HYBRID_ERROR;
    }
    g_free(sipmsg);

    return 0;
}