Пример #1
0
void
process_incoming_invite(struct fetion_account_data *sip, struct sipmsg *msg)
{
        /* Plato Wu,2010/09/29: update it for SIP/C 4.0 protocol*/
#if 1
        gchar *body, *hdr;
        const char *auth, *to, *callid;
        char* ipaddress = NULL;
	char* credential = NULL;
        int port;
	struct group_chat *g_chat;
	struct fetion_buddy *buddy = NULL;

        auth = g_strdup_printf(sipmsg_find_header(msg, "A"));
	callid = sipmsg_find_header(msg, "I");
	to = sipmsg_find_header(msg, "F");

        sipmsg_remove_header(msg, "K");
        sipmsg_remove_header(msg, "XI");
        sipmsg_remove_header(msg, "AL");
        sipmsg_remove_header(msg, "A");
        purple_debug_info("plato:", "Received a conversation invitation");
        send_sip_response(sip->gc, msg, 200, "OK", NULL);

        fetion_sip_get_auth_attr(auth , &ipaddress , &port , &credential);
        purple_debug_info("plato:", "ipaddress is %s, port is %d, credential is %s", ipaddress, port, credential);
        /* Plato Wu,2010/09/29: TODO Openfetion new a TCP connection here, but I don't
         * know how to do in pidgin.*/
        /* purple_proxy_connect(sip->gc, sip->account, ipaddress, port, invite_cb, sip->gc); */
        /* Plato Wu,2010/09/29: TODO, R command should be sent into new connection. */
       hdr = g_strdup_printf("A: TICKS auth=\"%s\"\r\n", credential);
//"       K: text/html-fragment\r\nK: multiparty\r\nK: nudge\r\n"

       send_sip_request(sip->gc, "R", "", "", hdr, NULL, NULL, NULL);

       purple_debug_info("plato:", "start free");
       
	if (strncmp(to, "sip:TG", 6) != 0) {
		buddy = g_hash_table_lookup(sip->buddies, to);
		if (buddy == NULL) {
			buddy = g_new0(struct fetion_buddy, 1);
			buddy->name = g_strdup(to);
			g_hash_table_insert(sip->buddies, buddy->name, buddy);
		}
Пример #2
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;
	}
}