Beispiel #1
0
/**
 * 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;
}
Beispiel #2
0
int fetion_conversation_send_sms_to_myself_with_reply(Conversation* conversation,
			   	const char* message)
{
	SipHeader *toheader = NULL;
	SipHeader *eheader = NULL;
	char       *res = NULL;
	char        rep[1024];
	int         code;
	FetionSip  *sip = conversation->currentUser->sip;

	fetion_sip_set_type(sip , SIP_MESSAGE);
	toheader = fetion_sip_header_new("T" , conversation->currentUser->sipuri);
	eheader  = fetion_sip_event_header_new(SIP_EVENT_SENDCATMESSAGE);
	fetion_sip_add_header(sip , toheader);
	fetion_sip_add_header(sip , eheader);
	res = fetion_sip_to_string(sip , message);
	debug_info("Sent a message to myself" , conversation->currentContact->sipuri);
	tcp_connection_send(sip->tcp , res , strlen(res));
	sal_free(res);
	memset(rep, 0, sizeof(rep));
	tcp_connection_recv(sip->tcp , rep , sizeof(rep));
	code = fetion_sip_get_code(rep);
	if(code == 200 || code == 280){
		return 1;
	}else{
		return -1;
	}
}
Beispiel #3
0
int pg_group_get_list(User *user)
{
	FetionSip *sip;
	SipHeader *eheader;
	const char *body = "<args><group-list /></args>";
	char *res;
	extern int callid;

	sip = user->sip;

	eheader = fetion_sip_event_header_new(SIP_EVENT_PGGETGROUPLIST);
	if(eheader == NULL){
		return -1;
	}
	
	fetion_sip_set_type(sip , SIP_SERVICE);	
	fetion_sip_add_header(sip , eheader);

	user->pgGroupCallId = callid;

	res = fetion_sip_to_string(sip , body);
	if(res == NULL){
		return -1;
	}

	int ret = tcp_connection_send(sip->tcp , res , strlen(res));

	free(res);
	return ret;
}
Beispiel #4
0
int fetion_buddylist_delete(User* user , int id)
{
	FetionSip* sip = user->sip;
	SipHeader* eheader;
	char *res , *body;
	int ret;
	fetion_sip_set_type(sip , SIP_SERVICE);
	eheader = fetion_sip_event_header_new(SIP_EVENT_DELETEBUDDYLIST);
	fetion_sip_add_header(sip , eheader);
	body = generate_delete_buddylist_body(id);
	res = fetion_sip_to_string(sip , body);
	free(body);
	tcp_connection_send(sip->tcp , res , strlen(res));
	free(res);
	res = fetion_sip_get_response(sip);
	ret = fetion_sip_get_code(res);
	free(res);
	if(ret == 200)
	{
		fetion_group_remove(user->groupList , id);
		debug_info("Delete buddy list success");
		return 1;
	}
	else
	{
		debug_error("Delete buddy list failed , errno:%d" , ret);
		return -1;
	}
}
Beispiel #5
0
int fetion_buddylist_create(User* user , const char* name)
{
	FetionSip* sip = user->sip;
	SipHeader* eheader;
	char *res , *body;
	int ret;
	fetion_sip_set_type(sip , SIP_SERVICE);
	eheader = fetion_sip_event_header_new(SIP_EVENT_CREATEBUDDYLIST);
	fetion_sip_add_header(sip , eheader);
	body = generate_create_buddylist_body(name);
	res = fetion_sip_to_string(sip , body);
	free(body);
	tcp_connection_send(sip->tcp , res , strlen(res));
	free(res) ; 
	res = fetion_sip_get_response(sip);
	ret = fetion_sip_get_code(res);
	if(ret == 200)
	{
		ret = parse_create_buddylist_response(user , res);
		free(res);
		debug_info("Create buddy list success");
		return ret;
	}
	else
	{
		free(res);
		debug_error("Create buddy list failed , errno :" , ret);
		return -1;
	}
}
Beispiel #6
0
gint
fetion_buddy_scribe(fetion_account *ac)
{
	gchar *res, *body;
	fetion_sip *sip;
	sip_header *eheader;

	sip = ac->sip;
	fetion_sip_set_type(sip, SIP_SUBSCRIPTION);

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

	body = generate_subscribe_body();

	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;
}
Beispiel #7
0
gint
fetion_buddy_move_to(fetion_account *ac, const gchar *userid,
		const gchar *groupid)
{
	fetion_sip *sip;
	sip_header *eheader;
	gchar *res, *body;

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

	sip = ac->sip;

	fetion_sip_set_type(sip, SIP_SERVICE);

	eheader = sip_event_header_create(SIP_EVENT_SETCONTACTINFO);

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

	hybrid_debug_info("fetion", "%s moved to group %s, send:\n%s",
					userid, groupid, res);

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

	g_free(res);

	return HYBRID_OK;
}
Beispiel #8
0
gint
fetion_buddy_rename(fetion_account *ac, const gchar *userid,
		const gchar *newname)
{
	fetion_sip *sip;
	sip_header *eheader;
	gchar *res;
	gchar *body;

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

	sip = ac->sip;

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

	body = generate_rename_buddy_body(userid, newname);
	res = fetion_sip_to_string(sip, body);
	g_free(body);

	if (send(ac->sk, res, strlen(res), 0) == -1) {
		hybrid_debug_error("fetion", "rename buddy %s", userid);

		return HYBRID_ERROR;
	}

	g_free(res);

	return HYBRID_OK;
}
Beispiel #9
0
int fetion_buddylist_edit(User* user , int id , const char* name)
{
	FetionSip* sip = user->sip;
	SipHeader* eheader;
	char *res , *body;
	int ret;
	fetion_sip_set_type(sip , SIP_SERVICE);
	eheader = fetion_sip_event_header_new(SIP_EVENT_SETBUDDYLISTINFO);
	fetion_sip_add_header(sip , eheader);
	body = generate_edit_buddylist_body(id , name);
	res = fetion_sip_to_string(sip , body);
	free(body);
	tcp_connection_send(sip->tcp , res , strlen(res));
	free(res);
	res = fetion_sip_get_response(sip);
	ret = fetion_sip_get_code(res);
	free(res);
	if(ret == 200)
	{
		debug_info("Set buddy list name to %s success" , name);
		return 1;
	}
	else
	{
		debug_error("Set buddy list name to %s failed , errno:%d" , name , ret);
		return -1;
	}
}
Beispiel #10
0
/**
 * 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;
}
Beispiel #11
0
gint fetion_buddylist_create(User *user, const gchar *name)
{
	fetion_sip* sip = user->sip;
	SipHeader* eheader;
	gchar *res , *body;
	fetion_sip_set_type(sip , SIP_SERVICE);
	eheader = fetion_sip_event_header_new(SIP_EVENT_CREATEBUDDYLIST);
	fetion_sip_add_header(sip , eheader);
	body = generate_create_buddylist_body(name);
	res = fetion_sip_to_string(sip , body);
	g_free(body);

	g_free(res);

	return 0;
}
Beispiel #12
0
gint fetion_buddylist_edit(fetion_account *ac, gint id, const gchar *name)
{
	fetion_sip *sip = ac->user->sip;
	SipHeader *eheader;
	gchar     *res, *body;

	fetion_sip_set_type(sip , SIP_SERVICE);
	eheader = fetion_sip_event_header_new(SIP_EVENT_SETBUDDYLISTINFO);
	fetion_sip_add_header(sip , eheader);
	body = generate_edit_buddylist_body(id , name);
	res = fetion_sip_to_string(sip , body);
	g_free(body);
	if(send(ac->sk, res, strlen(res), 0) == -1) { g_free(res); return -1; }
	g_free(res);

	return 0;
}
Beispiel #13
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);
}
Beispiel #14
0
/**
 * This function starts to register to the sipc server, since we have
 * got the ip address and port from the cfg string in the last step.
 */
static gboolean
sipc_reg_action(gint sk, gpointer user_data)
{
    gchar          *sipmsg;
    gchar          *cnouce = generate_cnouce();
    fetion_account *ac     = (fetion_account*)user_data;
    fetion_sip     *sip    = ac->sip;

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

    hybrid_account_set_connection_string(ac->account,
            _("start registering to the sipc server."));

    /* Now we start to register to the sipc server. */
    fetion_sip_set_type(sip, SIP_REGISTER);

    sip_header *cheader = sip_header_create("CN", cnouce);
    sip_header *client  = sip_header_create("CL", "type=\"pc\""
                                            " ,version=\""PROTO_VERSION"\"");

    fetion_sip_add_header(sip, cheader);
    fetion_sip_add_header(sip, client);

    g_free(cnouce);

    sipmsg = fetion_sip_to_string(sip, NULL);

    hybrid_debug_info("fetion", "start registering to sip server(%s:%d)",
            ac->sipc_proxy_ip, ac->sipc_proxy_port);

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

    if (send(sk, sipmsg, strlen(sipmsg), 0) == -1) {
        hybrid_account_error_reason(ac->account, _("sipc reg error"));
        g_free(sipmsg);
        return FALSE;
    }

    hybrid_event_add(sk, HYBRID_EVENT_READ, sipc_reg_cb, ac);

    g_free(sipmsg);

    return FALSE;
}
Beispiel #15
0
int fetion_conversation_send_sms_with_reply(Conversation *conv, const char *msg)
{
	char       rep[1024];

	FetionSip* sip = conv->currentSip == NULL ?
		   	conv->currentUser->sip : conv->currentSip;
	SipHeader *toheader , *cheader , *kheader , *nheader;
	Message *message;
	char* res;
	struct tm *now;
	struct tm now_copy;

	fetion_sip_set_type(sip , SIP_MESSAGE);
	nheader  = fetion_sip_event_header_new(SIP_EVENT_CATMESSAGE);
	toheader = fetion_sip_header_new("T" , conv->currentContact->sipuri);
	cheader  = fetion_sip_header_new("C" , "text/plain");
	kheader  = fetion_sip_header_new("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);
	/* add message to list */
	now = get_currenttime();
	now_copy = *now;
	message = fetion_message_new();
	fetion_message_set_sipuri(message , conv->currentContact->sipuri);
	fetion_message_set_time(message , now_copy);
	fetion_message_set_message(message , msg);
	fetion_message_set_callid(message , sip->callid);

	res = fetion_sip_to_string(sip , msg);
	debug_info("Sent a message to %s" , conv->currentContact->sipuri);
	tcp_connection_send(sip->tcp , res , strlen(res));
	sal_free(res);

	memset(rep , 0 , sizeof(rep));
	tcp_connection_recv(sip->tcp , rep , sizeof(rep));

	if(fetion_sip_get_code(rep) == 280 || fetion_sip_get_code(rep) == 200){
		return 1;
	}else{
		return -1;
	}
}
Beispiel #16
0
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;
}
Beispiel #17
0
int fetion_conversation_send_sms_to_phone_with_reply(Conversation* conversation
		, const char* message , int* daycount , int* monthcount)
{
	
	SipHeader *toheader , *eheader , *aheader;
	char* res;
	char* xml;
	User *user = conversation->currentUser;
	FetionSip* sip = user->sip;
	char astr[256] , rep[1024];
	char* sipuri = conversation->currentContact->sipuri;

	fetion_sip_set_type(sip , SIP_MESSAGE);
	toheader = fetion_sip_header_new("T" , sipuri);
	eheader  = fetion_sip_event_header_new(SIP_EVENT_SENDCATMESSAGE);
	fetion_sip_add_header(sip , toheader);
	if(user->verification != NULL){
		sprintf(astr , "Verify algorithm=\"picc\",chid=\"%s\",response=\"%s\""
				, user->verification->guid
				, user->verification->code);
		aheader = fetion_sip_header_new("A" , astr);
		fetion_sip_add_header(sip , aheader);
	}
	fetion_sip_add_header(sip , eheader);
	res = fetion_sip_to_string(sip , message);
	debug_info("Sent a message to (%s)`s mobile phone" , sipuri);
	tcp_connection_send(sip->tcp , res , strlen(res));
	sal_free(res);

	memset(rep , 0 , sizeof(rep));
	tcp_connection_recv(sip->tcp , rep , sizeof(rep));

	if(fetion_sip_get_code(rep) == 280){
		xml = strstr(rep , "\r\n\r\n") + 4;
		fetion_conversation_parse_send_sms(xml , daycount , monthcount);
		return 1;
	}else{
		debug_error("Send a message to (%s)`s mobile phone failed",
				sipuri);
		return -1;
	}
}
Beispiel #18
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;
}
Beispiel #19
0
static void fetion_start_transfer(FetionSip *sip){
	
	SipHeader *kheader = NULL;
	SipHeader *theader = NULL;
	char *res = NULL;
	char buf[2048];

	fetion_sip_set_type(sip , SIP_SERVICE);
	
	kheader = fetion_sip_header_new("N" , "StartTransfer");
	theader = fetion_sip_header_new("XI" , SESSIONID);
	fetion_sip_add_header(sip , kheader);
	fetion_sip_add_header(sip , theader);
	res = fetion_sip_to_string(sip , NULL);
	tcp_connection_send(sip->tcp , res , strlen(res));
	free(res);
	memset(buf, 0, sizeof(buf));
	tcp_connection_recv(sip->tcp , buf , sizeof(buf));
	printf("%s\n" , buf);
}
Beispiel #20
0
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;
}
Beispiel #21
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;
}
Beispiel #22
0
int fetion_conversation_send_sms(Conversation* conversation , const char* msg)
{
	FetionSip* sip = conversation->currentSip == NULL ?
		   	conversation->currentUser->sip : conversation->currentSip;
	SipHeader *toheader , *cheader , *kheader , *nheader;
	Message *message;
	struct unacked_list *unacked;
	char* res;
	struct tm *now;
	struct tm now_copy;

	fetion_sip_set_type(sip , SIP_MESSAGE);
	nheader  = fetion_sip_event_header_new(SIP_EVENT_CATMESSAGE);
	toheader = fetion_sip_header_new("T" , conversation->currentContact->sipuri);
	cheader  = fetion_sip_header_new("C" , "text/plain");
	kheader  = fetion_sip_header_new("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);
	/* add message to list */
	now = get_currenttime();
	now_copy = *now;
	message = fetion_message_new();
	fetion_message_set_sipuri(message , conversation->currentContact->sipuri);
	fetion_message_set_time(message , now_copy);
	fetion_message_set_message(message , msg);
	fetion_message_set_callid(message , sip->callid);
	unacked = unacked_list_new(message);
	unacked_list_append(unackedlist , unacked);

	res = fetion_sip_to_string(sip , msg);
	debug_info("Sent a message to %s" , conversation->currentContact->sipuri);
	if(tcp_connection_send(sip->tcp , res , strlen(res)) == -1){
		sal_free(res);
		return -1;
	}
	sal_free(res);
	return 1;
}
Beispiel #23
0
int fetion_conversation_send_sms_to_phone(Conversation* conversation,
			   	const char* message)
{
	
	SipHeader *toheader = NULL;
	SipHeader *eheader = NULL;
	SipHeader *aheader = NULL;
	User *user = conversation->currentUser;
	char* res = NULL;
	FetionSip* sip = user->sip;
	char* sipuri = conversation->currentContact->sipuri;
	char astr[256] , rep[1024];
	int code;

	fetion_sip_set_type(sip , SIP_MESSAGE);
	toheader = fetion_sip_header_new("T" , sipuri);
	eheader  = fetion_sip_event_header_new(SIP_EVENT_SENDCATMESSAGE);
	fetion_sip_add_header(sip , toheader);
	if(user->verification != NULL){
		memset(astr, 0, sizeof(astr));
		sprintf(astr , "Verify algorithm=\"picc\",chid=\"%s\",response=\"%s\""
				, user->verification->guid
				, user->verification->code);
		aheader = fetion_sip_header_new("A" , astr);
		fetion_sip_add_header(sip , aheader);
	}
	fetion_sip_add_header(sip , eheader);
	res = fetion_sip_to_string(sip , message);
	debug_info("Sent a message to (%s)`s mobile phone" , sipuri);
	tcp_connection_send(sip->tcp , res , strlen(res));
	sal_free(res);
	memset(rep, 0, sizeof(rep));
	tcp_connection_recv(sip->tcp , rep , sizeof(rep));
	code = fetion_sip_get_code(rep);
	if(code == 420 || code == 421){
		return -1;
	}else{
		return 1;
	}
}
Beispiel #24
0
int fetion_conversation_send_nudge(Conversation* conversation)
{
	SipHeader *toheader = NULL;
	char* res = NULL;
	char* body = NULL;
	FetionSip* sip = conversation->currentSip;
	if(sip == NULL)
	{
		debug_error("Did not start a chat chanel , can not send a nudge");
		return -1;
	}
	char* sipuri = conversation->currentContact->sipuri;
	fetion_sip_set_type(sip , SIP_INCOMING);
	toheader = fetion_sip_header_new("T" , sipuri);
	fetion_sip_add_header(sip , toheader);
	body = generate_send_nudge_body();
	res = fetion_sip_to_string(sip , body);
	sal_free(body);
	debug_info("Sent a nudge to (%s)" , sipuri);
	tcp_connection_send(sip->tcp , res , strlen(res));
	sal_free(res);
/*	res = fetion_sip_get_response(sip);
	if(fetion_sip_get_code(res) == 280)
	{
		sal_free(res);
		return 1;
	}
	else
	{
		printf("%s\n" , res);
		sal_free(res);
		debug_error("Send nuge failed");
		return -1;
	}*/
	return 1;

}
Beispiel #25
0
int fetion_conversation_send_sms_to_myself(Conversation* conversation,
			   	const char* message)
{
	SipHeader *toheader = NULL;
	SipHeader *eheader = NULL;
	char* res = NULL;
	FetionSip* sip = conversation->currentUser->sip;

	fetion_sip_set_type(sip , SIP_MESSAGE);
	toheader = fetion_sip_header_new("T" , conversation->currentUser->sipuri);
	eheader  = fetion_sip_event_header_new(SIP_EVENT_SENDCATMESSAGE);
	fetion_sip_add_header(sip , toheader);
	fetion_sip_add_header(sip , eheader);
	res = fetion_sip_to_string(sip , message);
	debug_info("Sent a message to myself" , conversation->currentContact->sipuri);
	if(tcp_connection_send(sip->tcp , res , strlen(res)) == -1) {
		sal_free(res);
		return -1;
	}
	sal_free(res);
	res = fetion_sip_get_response(sip);
	sal_free(res);
	return 1;
}
Beispiel #26
0
void fetion_share_request(FetionSip *sip , Share *share)
{
	SipHeader *kheader = NULL;
	SipHeader *theader = NULL;
	char *res = NULL;
	char *body = NULL;
	char buf[2048];

	fetion_sip_set_type(sip , SIP_OPTION);
	
	kheader = fetion_sip_header_new("K" , "ShareContent");
	theader = fetion_sip_header_new("T" , share->sipuri);
	fetion_sip_add_header(sip , kheader);
	fetion_sip_add_header(sip , theader);
	body = generate_share_request_body(share);
	res = fetion_sip_to_string(sip , body);
	tcp_connection_send(sip->tcp , res , strlen(res));
	free(res);
	memset(buf, 0, sizeof(buf));
	tcp_connection_recv(sip->tcp , buf , sizeof(buf));
	printf("%s\n" , buf);

	fetion_start_transfer(sip);
}
Beispiel #27
0
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;
}
Beispiel #28
0
int fetion_conversation_invite_friend(Conversation* conversation)
{
	FetionSip* sip = conversation->currentUser->sip;
	char *res , *ip , *credential , auth[256] , *body;
	int port , ret;
	FetionConnection* conn;
	Proxy *proxy = conversation->currentUser->config->proxy;
	SipHeader *eheader , *theader , *mheader , *nheader , *aheader;


	/*start chat*/
	fetion_sip_set_type(sip , SIP_SERVICE);
	eheader = fetion_sip_event_header_new(SIP_EVENT_STARTCHAT);
	fetion_sip_add_header(sip , eheader);
	res = fetion_sip_to_string(sip , NULL);
	tcp_connection_send(sip->tcp , res , strlen(res));
	sal_free(res); res = NULL;
	res = fetion_sip_get_response(sip);
	if(!res)
		return -1;

	memset(auth , 0 , sizeof(auth));
	fetion_sip_get_attr(res , "A" , auth);
	if(auth==NULL)
		return -1;

	fetion_sip_get_auth_attr(auth , &ip , &port , &credential);
	sal_free(res); res = NULL;
	conn = tcp_connection_new();

	if(proxy != NULL && proxy->proxyEnabled)
		ret = tcp_connection_connect_with_proxy(conn , ip , port , proxy);
	else
		ret = tcp_connection_connect(conn , ip , port);

	if(ret == -1)
		return -1;

	/*clone sip*/
	conversation->currentSip = fetion_sip_clone(conversation->currentUser->sip);
	memset(conversation->currentSip->sipuri, 0 , sizeof(conversation->currentSip->sipuri));
	strcpy(conversation->currentSip->sipuri , conversation->currentContact->sipuri);
	fetion_sip_set_connection(conversation->currentSip , conn);
	sal_free(ip); ip = NULL;
	/*register*/
	sip = conversation->currentSip;
	fetion_sip_set_type(sip , SIP_REGISTER);
	aheader = fetion_sip_credential_header_new(credential);
	theader = fetion_sip_header_new("K" , "text/html-fragment");
	mheader = fetion_sip_header_new("K" , "multiparty");
	nheader = fetion_sip_header_new("K" , "nudge");
	fetion_sip_add_header(sip , aheader);
	fetion_sip_add_header(sip , theader);
	fetion_sip_add_header(sip , mheader);
	fetion_sip_add_header(sip , nheader);
	res = fetion_sip_to_string(sip , NULL);
	tcp_connection_send(conn , res , strlen(res));
	sal_free(res);res = NULL;
	sal_free(credential); credential = NULL;
	res = fetion_sip_get_response(sip);
	sal_free(res); res = NULL;
	/*invite buddy*/
	fetion_sip_set_type(sip , SIP_SERVICE);
	eheader = fetion_sip_event_header_new(SIP_EVENT_INVITEBUDDY);
	fetion_sip_add_header(sip , eheader);
	body = generate_invite_friend_body(conversation->currentContact->sipuri);
	res = fetion_sip_to_string(sip , body);	
	sal_free(body); body = NULL;
	tcp_connection_send(sip->tcp , res , strlen(res));
	sal_free(res); res = NULL;
	res = fetion_sip_get_response(sip);

	if(fetion_sip_get_code(res) == 200)	{
		sal_free(res);
		res = (char*)sal_malloc(2048);
		memset(res , 0 , 2048);
		tcp_connection_recv(sip->tcp , res , 2048);
		//res = fetion_sip_get_response(sip);
		sal_free(res);
		return 1;
	}else{
		sal_free(res);
		return -1;
	}
}
Beispiel #29
0
static gint
process_invite_conn_cb(gint sk, gpointer user_data)
{
	invite_conn_data *data;
	fetion_account *account;
	fetion_sip *sip;
	gchar *credential;
	gchar *sip_text;
	sip_header *aheader;
	sip_header *theader;
	sip_header *mheader;
	sip_header *nheader;

	data = (invite_conn_data*)user_data;
	account = data->account;
	credential = data->credential;
	g_free(data);

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

	account->source = hybrid_event_add(sk, HYBRID_EVENT_READ,
							hybrid_push_cb, account);

	if (account->source == 0) {

		hybrid_debug_error("fetion", "add read event error");

		return HYBRID_ERROR;
	}

	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");

	g_free(credential);

	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("feiton", "register to a new channel:\n%s", sip_text);

	if (send(sk, sip_text, strlen(sip_text), 0) == -1) {
		
		hybrid_debug_error("fetion", "register to new channel error.");

		g_free(sip_text);

		return HYBRID_ERROR;
	}

	g_free(sip_text);

	return HYBRID_OK;
}
Beispiel #30
0
/**
 * 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;
}