static void process_sipc_cb(fetion_account *ses, const gchar *sipmsg) { gchar callid[16]; gint callid0; struct transaction *trans; GSList *trans_cur; fetion_sip_get_attr(sipmsg, "I", callid); callid0 = atoi(callid); trans_cur = ses->trans; while(trans_cur) { trans = (struct transaction*)(trans_cur->data); if(trans->callid == callid0) { if(trans->callback) (trans->callback)(ses, sipmsg, trans); transaction_remove(ses, trans); break; } trans_cur = g_slist_next(trans_cur); } }
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; } }