Skip to content
Snippets Groups Projects
Commit f9765155 authored by Yun Liu's avatar Yun Liu
Browse files

other modifications related to pjsip

parent 636f678f
Branches
Tags
No related merge requests found
#include "voiplink.h"
/* /*
* Copyright (C) 2006-2007 Savoir-Faire Linux inc. * Copyright (C) 2006-2007 Savoir-Faire Linux inc.
* Author: Alexandre Bourget <alexandre.bourget@savoirfairelinux.com> * Author: Alexandre Bourget <alexandre.bourget@savoirfairelinux.com>
...@@ -45,11 +48,14 @@ SIPAccount::registerVoIPLink() ...@@ -45,11 +48,14 @@ SIPAccount::registerVoIPLink()
thislink->setStunServer(Manager::instance().getConfigString(_accountID,SIP_STUN_SERVER)); thislink->setStunServer(Manager::instance().getConfigString(_accountID,SIP_STUN_SERVER));
thislink->setUseStun( useStun!=0 ? true : false); thislink->setUseStun( useStun!=0 ? true : false);
//SIPVoIPLink* thislink = dynamic_cast<SIPVoIPLink*> (_link);
_link->init(); _link->init();
// Stuff needed for SIP registration. // Stuff needed for SIP registration.
thislink->setProxy (Manager::instance().getConfigString(_accountID,SIP_PROXY)); thislink->setProxy (Manager::instance().getConfigString(_accountID,SIP_PROXY));
thislink->setAuthName(Manager::instance().getConfigString(_accountID,SIP_USER)); thislink->setAuthName(Manager::instance().getConfigString(_accountID,SIP_USER));
thislink->setPassword(Manager::instance().getConfigString(_accountID,SIP_PASSWORD)); thislink->setPassword(Manager::instance().getConfigString(_accountID,SIP_PASSWORD));
thislink->setSipServer(Manager::instance().getConfigString(_accountID,SIP_HOST));
_link->sendRegister(); _link->sendRegister();
} }
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "account.h" #include "account.h"
class SIPVoIPLink;
/** /**
* @file sipaccount.h * @file sipaccount.h
......
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
#include "sipcall.h" #include "sipcall.h"
#include <sstream> // for ostringstream #include <sstream> // for ostringstream
#include "sipaccount.h" #include "sipaccount.h"
#include "sipmanager.h"
#include "audio/audiortp.h"
#include "manager.h" #include "manager.h"
#include "user_cfg.h" // SIGNALISATION / PULSE #define #include "user_cfg.h" // SIGNALISATION / PULSE #define
...@@ -56,7 +58,7 @@ ...@@ -56,7 +58,7 @@
SIPVoIPLink::SIPVoIPLink(const AccountID& accountID) SIPVoIPLink::SIPVoIPLink(const AccountID& accountID)
: VoIPLink(accountID), _localExternAddress("") , eXosip_running( false ) : VoIPLink(accountID), _localExternAddress("") , eXosip_running( false )
{ {
_evThread = new EventThread(this); _evThread = NULL;//new EventThread(this);
_nMsgVoicemail = 0; _nMsgVoicemail = 0;
...@@ -65,6 +67,7 @@ SIPVoIPLink::SIPVoIPLink(const AccountID& accountID) ...@@ -65,6 +67,7 @@ SIPVoIPLink::SIPVoIPLink(const AccountID& accountID)
_nbTryListenAddr = 2; // number of times to try to start SIP listener _nbTryListenAddr = 2; // number of times to try to start SIP listener
_localExternPort = 0; _localExternPort = 0;
_audiortp = new AudioRtp();
// to get random number for RANDOM_PORT // to get random number for RANDOM_PORT
srand (time(NULL)); srand (time(NULL));
} }
...@@ -78,14 +81,14 @@ SIPVoIPLink::~SIPVoIPLink() ...@@ -78,14 +81,14 @@ SIPVoIPLink::~SIPVoIPLink()
bool bool
SIPVoIPLink::init() SIPVoIPLink::init()
{ {
if( eXosip_running ){ /*if( eXosip_running ){
delete _evThread; delete _evThread;
_evThread=0; _evThread=0;
_evThread= new EventThread( this ); _evThread= new EventThread( this );
eXosip_quit(); eXosip_quit();
} }*/
if (!_initDone) { /*if (!_initDone) {
if (0 != eXosip_init()) { if (0 != eXosip_init()) {
_debug("! SIP Failure: Could not initialize eXosip\n"); _debug("! SIP Failure: Could not initialize eXosip\n");
return false; return false;
...@@ -152,15 +155,16 @@ SIPVoIPLink::init() ...@@ -152,15 +155,16 @@ SIPVoIPLink::init()
} }
_initDone = true; _initDone = true;
eXosip_running = true; eXosip_running = true;*/
// Useless _regc = NULL;
_initDone = true;
return true; return true;
} }
void void
SIPVoIPLink::terminate() SIPVoIPLink::terminate()
{ {
terminateSIPCall(); //terminateSIPCall();
// TODO The next line makes the daemon crash on // TODO The next line makes the daemon crash on
// account delete if at least one account is registered. // account delete if at least one account is registered.
// It should called only when the last account // It should called only when the last account
...@@ -201,16 +205,16 @@ SIPVoIPLink::loadSIPLocalIP() ...@@ -201,16 +205,16 @@ SIPVoIPLink::loadSIPLocalIP()
{ {
bool returnValue = true; bool returnValue = true;
if (_localIPAddress == "127.0.0.1") { if (_localIPAddress == "127.0.0.1") {
char* myIPAddress = new char[65]; pj_sockaddr ip_addr;
if (eXosip_guess_localip(AF_INET, myIPAddress, 64) == EXOSIP_ERROR_STD) { if (pj_gethostip(pj_AF_INET(), &ip_addr) != PJ_SUCCESS) {
// Update the registration state if no network capabilities found // Update the registration state if no network capabilities found
_debug("Get host ip failed!\n");
setRegistrationState( ErrorNetwork ); setRegistrationState( ErrorNetwork );
returnValue = false; returnValue = false;
} else { } else {
_localIPAddress = std::string(myIPAddress); _localIPAddress = std::string(pj_inet_ntoa(ip_addr.ipv4.sin_addr));
_debug(" SIP Info: Checking network, setting local IP address to: %s\n", myIPAddress); _debug(" SIP Info: Checking network, setting local IP address to: %s\n", _localIPAddress.data());
} }
delete [] myIPAddress; myIPAddress = NULL;
} }
return returnValue; return returnValue;
} }
...@@ -218,6 +222,7 @@ SIPVoIPLink::loadSIPLocalIP() ...@@ -218,6 +222,7 @@ SIPVoIPLink::loadSIPLocalIP()
void void
SIPVoIPLink::getEvent() SIPVoIPLink::getEvent()
{ {
#ifdef AAAAA
char* tmp2; char* tmp2;
eXosip_event_t* event = eXosip_event_wait(0, 50); eXosip_event_t* event = eXosip_event_wait(0, 50);
eXosip_lock(); eXosip_lock();
...@@ -438,72 +443,29 @@ SIPVoIPLink::getEvent() ...@@ -438,72 +443,29 @@ SIPVoIPLink::getEvent()
break; break;
} }
eXosip_event_free(event); eXosip_event_free(event);
#endif
} }
bool bool
SIPVoIPLink::sendRegister() SIPVoIPLink::sendRegister()
{ {
int expire_value = Manager::instance().getRegistrationExpireValue(); AccountID id = getAccountID();
_debug("SIP Registration Expire Value = %i\n" , expire_value); pj_status_t status;
if (_eXosipRegID != EXOSIP_ERROR_STD) {
return false;
}
std::string hostname = getHostName();
if (hostname.empty()) {
return false;
}
if (_authname.empty()) {
return false;
}
std::string proxy = "sip:" + _proxy;
hostname = "sip:" + hostname;
std::string from = SIPFromHeader(_authname, getHostName());
osip_message_t *reg = NULL;
eXosip_lock();
if (!_proxy.empty()) {
_debug("* SIP Info: Register from: %s to %s\n", from.data(), proxy.data());
_eXosipRegID = eXosip_register_build_initial_register(from.data(),
proxy.data(), NULL, expire_value, &reg);
} else {
_debug("* SIP Info: Register from: %s to %s\n", from.data(), hostname.data());
_eXosipRegID = eXosip_register_build_initial_register(from.data(),
hostname.data(), NULL, expire_value, &reg);
}
eXosip_unlock();
if (_eXosipRegID < EXOSIP_ERROR_NO ) {
return false;
}
if (!sendSIPAuthentification()) { if(_regc) {
_debug("* SIP Info: register without authentication\n"); pjsip_regc_destroy(_regc);
return false; _regc = NULL;
} }
osip_message_set_header (reg, "Event", "Registration"); int expire_value = Manager::instance().getRegistrationExpireValue();
osip_message_set_header (reg, "Allow-Events", "presence"); _debug("SIP Registration Expire Value = %i\n" , expire_value);
eXosip_lock();
int eXosipErr = eXosip_register_send_register(_eXosipRegID, reg);
if (eXosipErr == EXOSIP_ERROR_BUILDING) {
_debug("! SIP Failure: Cannot build registration, check the setup\n");
eXosip_unlock();
return false;
}
if (eXosipErr == EXOSIP_ERROR_STD) {
_debug("! SIP Failure: Registration sending failed\n");
eXosip_unlock();
return false;
}
setRegistrationState(Trying); setRegistrationState(Trying);
eXosip_unlock();
return true; SIPManager *sipManager = Manager::instance().getSipManager();
_debug("Get manager of sip\n");
return sipManager->addAccount(id, _regc, _server, _authname, _password, expire_value);
} }
std::string std::string
...@@ -572,6 +534,7 @@ SIPVoIPLink::newOutgoingCall(const CallID& id, const std::string& toUrl) ...@@ -572,6 +534,7 @@ SIPVoIPLink::newOutgoingCall(const CallID& id, const std::string& toUrl)
SIPCall* call = new SIPCall(id, Call::Outgoing); SIPCall* call = new SIPCall(id, Call::Outgoing);
if (call) { if (call) {
call->setPeerNumber(toUrl); call->setPeerNumber(toUrl);
_debug("Try to make a call to: %s with call ID: %s\n", toUrl.data(), id.data());
// we have to add the codec before using it in SIPOutgoingInvite... // we have to add the codec before using it in SIPOutgoingInvite...
call->setCodecMap(Manager::instance().getCodecDescriptorMap()); call->setCodecMap(Manager::instance().getCodecDescriptorMap());
if ( SIPOutgoingInvite(call) ) { if ( SIPOutgoingInvite(call) ) {
...@@ -596,38 +559,16 @@ SIPVoIPLink::answer(const CallID& id) ...@@ -596,38 +559,16 @@ SIPVoIPLink::answer(const CallID& id)
return false; return false;
} }
// Send 200 OK int i = Manager::instance().getSipManager()->answer(call);
osip_message_t *answerMessage = NULL;
eXosip_lock();
int i = eXosip_call_build_answer(call->getTid(), SIP_OK, &answerMessage);
if (i != 0) { if (i != 0) {
_debug("< SIP Building Error: send 400 Bad Request\n"); _debug("< SIP Building Error: send 400 Bad Request\n");
eXosip_call_send_answer (call->getTid(), SIP_BAD_REQUEST, NULL); //eXosip_call_send_answer (call->getTid(), SIP_BAD_REQUEST, NULL);
} else { } else {
// use exosip, bug locked // use exosip, bug locked
i = 0; i = 0;
sdp_message_t *remote_sdp = eXosip_get_remote_sdp(call->getDid());
if (remote_sdp!=NULL) {
i = call->sdp_complete_message(remote_sdp, answerMessage);
if (i!=0) {
osip_message_free(answerMessage);
}
sdp_message_free(remote_sdp);
}
if (i != 0) {
_debug("< SIP Error: send 415 Unsupported Media Type\n");
eXosip_call_send_answer (call->getTid(), SIP_UNSUPPORTED_MEDIA_TYPE, NULL);
} else {
_debug("< SIP send 200 OK\n");
eXosip_call_send_answer (call->getTid(), SIP_OK, answerMessage);
}
}
eXosip_unlock();
if(i==0) {
// Incoming call is answered, start the sound thread.
_debug("* SIP Info: Starting AudioRTP when answering\n"); _debug("* SIP Info: Starting AudioRTP when answering\n");
if (_audiortp.createNewSession(call) >= 0) { if (_audiortp->createNewSession(call) >= 0) {
call->setAudioStart(true); call->setAudioStart(true);
call->setConnectionState(Call::Connected); call->setConnectionState(Call::Connected);
call->setState(Call::Active); call->setState(Call::Active);
...@@ -646,16 +587,17 @@ SIPVoIPLink::hangup(const CallID& id) ...@@ -646,16 +587,17 @@ SIPVoIPLink::hangup(const CallID& id)
SIPCall* call = getSIPCall(id); SIPCall* call = getSIPCall(id);
if (call==0) { _debug("! SIP Error: Call doesn't exist\n"); return false; } if (call==0) { _debug("! SIP Error: Call doesn't exist\n"); return false; }
_debug("- SIP Action: Hang up call %s [cd: %3d %3d]\n", id.data(), call->getCid(), call->getDid()); //_debug("- SIP Action: Hang up call %s [cd: %3d %3d]\n", id.data(), call->getCid(), call->getDid());
// Release SIP stack. // Release SIP stack.
eXosip_lock(); //eXosip_lock();
eXosip_call_terminate(call->getCid(), call->getDid()); //eXosip_call_terminate(call->getCid(), call->getDid());
eXosip_unlock(); //eXosip_unlock();
Manager::instance().getSipManager()->hangup();
// Release RTP thread // Release RTP thread
if (Manager::instance().isCurrentCall(id)) { if (Manager::instance().isCurrentCall(id)) {
_debug("* SIP Info: Stopping AudioRTP for hangup\n"); _debug("* SIP Info: Stopping AudioRTP for hangup\n");
_audiortp.closeRtpSession(); _audiortp->closeRtpSession();
} }
removeCall(id); removeCall(id);
return true; return true;
...@@ -683,15 +625,19 @@ SIPVoIPLink::onhold(const CallID& id) ...@@ -683,15 +625,19 @@ SIPVoIPLink::onhold(const CallID& id)
SIPCall* call = getSIPCall(id); SIPCall* call = getSIPCall(id);
if (call==0) { _debug("! SIP Error: call doesn't exist\n"); return false; } if (call==0) { _debug("! SIP Error: call doesn't exist\n"); return false; }
// Stop sound // Stop sound
call->setAudioStart(false); call->setAudioStart(false);
call->setState(Call::Hold); call->setState(Call::Hold);
_debug("* SIP Info: Stopping AudioRTP for onhold action\n"); _debug("* SIP Info: Stopping AudioRTP for onhold action\n");
_audiortp.closeRtpSession(); _audiortp->closeRtpSession();
int did = call->getDid(); //int did = call->getDid();
Manager::instance().getSipManager()->onhold(call);
/*
eXosip_lock (); eXosip_lock ();
sdp_message_t *local_sdp = eXosip_get_local_sdp(did); sdp_message_t *local_sdp = eXosip_get_local_sdp(did);
eXosip_unlock (); eXosip_unlock ();
...@@ -712,8 +658,9 @@ SIPVoIPLink::onhold(const CallID& id) ...@@ -712,8 +658,9 @@ SIPVoIPLink::onhold(const CallID& id)
_debug("! SIP Failure: unable to build invite method to hold call\n"); _debug("! SIP Failure: unable to build invite method to hold call\n");
return false; return false;
} }
*/
/* add sdp body */ /* add sdp body */
/*
{ {
char *tmp = NULL; char *tmp = NULL;
...@@ -743,7 +690,7 @@ SIPVoIPLink::onhold(const CallID& id) ...@@ -743,7 +690,7 @@ SIPVoIPLink::onhold(const CallID& id)
eXosip_lock (); eXosip_lock ();
exosipErr = eXosip_call_send_request (did, invite); exosipErr = eXosip_call_send_request (did, invite);
eXosip_unlock (); eXosip_unlock ();
*/
return true; return true;
} }
...@@ -753,6 +700,9 @@ SIPVoIPLink::offhold(const CallID& id) ...@@ -753,6 +700,9 @@ SIPVoIPLink::offhold(const CallID& id)
SIPCall* call = getSIPCall(id); SIPCall* call = getSIPCall(id);
if (call==0) { _debug("! SIP Error: Call doesn't exist\n"); return false; } if (call==0) { _debug("! SIP Error: Call doesn't exist\n"); return false; }
Manager::instance().getSipManager()->offhold(call);
/*
int did = call->getDid(); int did = call->getDid();
eXosip_lock (); eXosip_lock ();
...@@ -774,8 +724,9 @@ SIPVoIPLink::offhold(const CallID& id) ...@@ -774,8 +724,9 @@ SIPVoIPLink::offhold(const CallID& id)
sdp_message_free(local_sdp); sdp_message_free(local_sdp);
return EXOSIP_ERROR_STD; return EXOSIP_ERROR_STD;
} }
*/
/* add sdp body */ /* add sdp body */
/*
{ {
char *tmp = NULL; char *tmp = NULL;
...@@ -803,12 +754,12 @@ SIPVoIPLink::offhold(const CallID& id) ...@@ -803,12 +754,12 @@ SIPVoIPLink::offhold(const CallID& id)
eXosip_lock (); eXosip_lock ();
exosipErr = eXosip_call_send_request (did, invite); exosipErr = eXosip_call_send_request (did, invite);
eXosip_unlock (); eXosip_unlock ();
*/
// Enable audio // Enable audio
_debug("* SIP Info: Starting AudioRTP when offhold\n"); _debug("* SIP Info: Starting AudioRTP when offhold\n");
call->setState(Call::Active); call->setState(Call::Active);
// it's sure that this is the current call id... // it's sure that this is the current call id...
if (_audiortp.createNewSession(call) < 0) { if (_audiortp->createNewSession(call) < 0) {
_debug("! SIP Failure: Unable to start sound (%s:%d)\n", __FILE__, __LINE__); _debug("! SIP Failure: Unable to start sound (%s:%d)\n", __FILE__, __LINE__);
return false; return false;
} }
...@@ -826,7 +777,8 @@ SIPVoIPLink::transfer(const CallID& id, const std::string& to) ...@@ -826,7 +777,8 @@ SIPVoIPLink::transfer(const CallID& id, const std::string& to)
tmp_to = tmp_to + "@" + getHostName(); tmp_to = tmp_to + "@" + getHostName();
} }
osip_message_t *refer; _debug("In transfer, tmp_to is %s\n", tmp_to.data());
/*osip_message_t *refer;
eXosip_lock(); eXosip_lock();
// Build transfer request // Build transfer request
int exosipErr = eXosip_call_build_refer(call->getDid(), (char*)tmp_to.data(), &refer); int exosipErr = eXosip_call_build_refer(call->getDid(), (char*)tmp_to.data(), &refer);
...@@ -835,14 +787,22 @@ SIPVoIPLink::transfer(const CallID& id, const std::string& to) ...@@ -835,14 +787,22 @@ SIPVoIPLink::transfer(const CallID& id, const std::string& to)
_debug("< SIP send transfer request to %s\n", tmp_to.data()); _debug("< SIP send transfer request to %s\n", tmp_to.data());
exosipErr = eXosip_call_send_request(call->getDid(), refer); exosipErr = eXosip_call_send_request(call->getDid(), refer);
} }
eXosip_unlock(); eXosip_unlock();*/
_audiortp.closeRtpSession(); Manager::instance().getSipManager()->transfer(call, tmp_to);
//_audiortp->closeRtpSession();
// shall we delete the call? // shall we delete the call?
//removeCall(id); //removeCall(id);
return true; return true;
} }
bool SIPVoIPLink::transferStep2()
{
_audiortp->closeRtpSession();
return true;
}
bool bool
SIPVoIPLink::refuse (const CallID& id) SIPVoIPLink::refuse (const CallID& id)
{ {
...@@ -856,15 +816,16 @@ SIPVoIPLink::refuse (const CallID& id) ...@@ -856,15 +816,16 @@ SIPVoIPLink::refuse (const CallID& id)
return false; return false;
} }
Manager::instance().getSipManager()->refuse();
osip_message_t *answerMessage = NULL; /*osip_message_t *answerMessage = NULL;
eXosip_lock(); eXosip_lock();
// not BUSY.. where decline the invitation! // not BUSY.. where decline the invitation!
int exosipErr = eXosip_call_build_answer(call->getTid(), SIP_DECLINE, &answerMessage); int exosipErr = eXosip_call_build_answer(call->getTid(), SIP_DECLINE, &answerMessage);
if (exosipErr == 0) { if (exosipErr == 0) {
exosipErr = eXosip_call_send_answer(call->getTid(), SIP_DECLINE, answerMessage); exosipErr = eXosip_call_send_answer(call->getTid(), SIP_DECLINE, answerMessage);
} }
eXosip_unlock(); eXosip_unlock();*/
return true; return true;
} }
...@@ -1049,20 +1010,24 @@ SIPVoIPLink::SIPStartCall(SIPCall* call, const std::string& subject) ...@@ -1049,20 +1010,24 @@ SIPVoIPLink::SIPStartCall(SIPCall* call, const std::string& subject)
if (!call) return false; if (!call) return false;
std::string to = getSipTo(call->getPeerNumber()); std::string to = getSipTo(call->getPeerNumber());
std::string from = getSipFrom();
std::string route = getSipRoute(); std::string route = getSipRoute();
_debug(" From: %s\n", from.data()); _debug(" To: %s\n", to.data());
_debug(" Route: %s\n", route.data()); _debug(" Route: %s\n", route.data());
if (!SIPCheckUrl(from)) { /*if (!SIPCheckUrl(from)) {
_debug("! SIP Error: Source address is invalid %s\n", from.data()); _debug("! SIP Error: Source address is invalid %s\n", from.data());
return false; return false;
} }
if (!SIPCheckUrl(to)) { if (!SIPCheckUrl(to)) {
return false; return false;
} }*/
osip_message_t *invite; //setCallAudioLocal(call);
AccountID accId = getAccountID();
Manager::instance().getSipManager()->makeOutgoingCall(to, call, accId);
/*osip_message_t *invite;
eXosip_lock(); eXosip_lock();
int eXosipError = eXosip_call_build_initial_invite (&invite, (char*)to.data(), int eXosipError = eXosip_call_build_initial_invite (&invite, (char*)to.data(),
(char*)from.data(), (char*)from.data(),
...@@ -1074,7 +1039,6 @@ SIPVoIPLink::SIPStartCall(SIPCall* call, const std::string& subject) ...@@ -1074,7 +1039,6 @@ SIPVoIPLink::SIPStartCall(SIPCall* call, const std::string& subject)
return false; // error when building the invite return false; // error when building the invite
} }
setCallAudioLocal(call);
std::ostringstream media_audio; std::ostringstream media_audio;
std::ostringstream rtpmap_attr; std::ostringstream rtpmap_attr;
...@@ -1104,14 +1068,14 @@ SIPVoIPLink::SIPStartCall(SIPCall* call, const std::string& subject) ...@@ -1104,14 +1068,14 @@ SIPVoIPLink::SIPStartCall(SIPCall* call, const std::string& subject)
} }
// go to next codec // go to next codec
//*iter++; //*iter++;
} }*/
// http://www.antisip.com/documentation/eXosip2/group__howto1__initialize.html // http://www.antisip.com/documentation/eXosip2/group__howto1__initialize.html
// tell sip if we support SIP extension like 100rel // tell sip if we support SIP extension like 100rel
// osip_message_set_supported (invite, "100rel"); // osip_message_set_supported (invite, "100rel");
/* add sdp body */ /* add sdp body */
{ /*{
char tmp[4096]; char tmp[4096];
snprintf (tmp, 4096, snprintf (tmp, 4096,
"v=0\r\n" "v=0\r\n"
...@@ -1141,7 +1105,7 @@ SIPVoIPLink::SIPStartCall(SIPCall* call, const std::string& subject) ...@@ -1141,7 +1105,7 @@ SIPVoIPLink::SIPStartCall(SIPCall* call, const std::string& subject)
_debug("* SIP Info: Outgoing callID is %s, cid=%d\n", call->getCallId().data(), cid); _debug("* SIP Info: Outgoing callID is %s, cid=%d\n", call->getCallId().data(), cid);
eXosip_call_set_reference (cid, NULL); eXosip_call_set_reference (cid, NULL);
} }
eXosip_unlock(); eXosip_unlock();*/
return true; return true;
} }
...@@ -1160,10 +1124,10 @@ SIPVoIPLink::getSipFrom() { ...@@ -1160,10 +1124,10 @@ SIPVoIPLink::getSipFrom() {
std::string std::string
SIPVoIPLink::getSipTo(const std::string& to_url) { SIPVoIPLink::getSipTo(const std::string& to_url) {
// Form the From header field basis on configuration panel // Form the From header field basis on configuration panel
bool isRegistered = (_eXosipRegID == EXOSIP_ERROR_STD) ? false : true; //bool isRegistered = (_eXosipRegID == EXOSIP_ERROR_STD) ? false : true;
// add a @host if we are registered and there is no one inside the url // add a @host if we are registered and there is no one inside the url
if (to_url.find("@") == std::string::npos && isRegistered) { if (to_url.find("@") == std::string::npos) {// && isRegistered) {
std::string host = getHostName(); std::string host = getHostName();
if(!host.empty()) { if(!host.empty()) {
return SIPToHeader(to_url + "@" + host); return SIPToHeader(to_url + "@" + host);
...@@ -1239,33 +1203,6 @@ SIPVoIPLink::setCallAudioLocal(SIPCall* call) ...@@ -1239,33 +1203,6 @@ SIPVoIPLink::setCallAudioLocal(SIPCall* call)
void void
SIPVoIPLink::SIPCallInvite(eXosip_event_t *event) SIPVoIPLink::SIPCallInvite(eXosip_event_t *event)
{ {
_debug("> INVITE (receive)\n");
CallID id = Manager::instance().getNewCallID();
SIPCall* call = new SIPCall(id, Call::Incoming);
if (!call) {
_debug("! SIP Failure: unable to create an incoming call");
return;
}
setCallAudioLocal(call);
call->setCodecMap(Manager::instance().getCodecDescriptorMap());
call->setConnectionState(Call::Progressing);
if (call->SIPCallInvite(event)) {
if (Manager::instance().incomingCall(call, getAccountID())) {
addCall(call);
} else {
delete call; call = 0;
}
} else {
delete call; call = 0;
}
// Send 180 RINGING
_debug("< Send 180 Ringing\n");
eXosip_lock ();
eXosip_call_send_answer(event->tid, 180, NULL);
eXosip_unlock ();
call->setConnectionState(Call::Ringing);
} }
void void
...@@ -1286,7 +1223,7 @@ SIPVoIPLink::SIPCallReinvite(eXosip_event_t *event) ...@@ -1286,7 +1223,7 @@ SIPVoIPLink::SIPCallReinvite(eXosip_event_t *event)
Manager::instance().stopTone(true); Manager::instance().stopTone(true);
// STOP old rtp session // STOP old rtp session
_debug("* SIP Info: Stopping AudioRTP when reinvite\n"); _debug("* SIP Info: Stopping AudioRTP when reinvite\n");
_audiortp.closeRtpSession(); _audiortp->closeRtpSession();
call->setAudioStart(false); call->setAudioStart(false);
} }
call->SIPCallReinvite(event); call->SIPCallReinvite(event);
...@@ -1310,18 +1247,18 @@ SIPVoIPLink::SIPCallRinging(eXosip_event_t *event) ...@@ -1310,18 +1247,18 @@ SIPVoIPLink::SIPCallRinging(eXosip_event_t *event)
} }
void void
SIPVoIPLink::SIPCallAnswered(eXosip_event_t *event) SIPVoIPLink::SIPCallAnswered(SIPCall *call, pjsip_rx_data *rdata)
{ {
SIPCall* call = findSIPCallWithCid(event->cid); //SIPCall* call = dynamic_cast<SIPCall *>(theCall);//findSIPCallWithCid(event->cid);
if (!call) { if (!call) {
_debug("! SIP Failure: unknown call\n"); _debug("! SIP Failure: unknown call\n");
return; return;
} }
call->setDid(event->did); //call->setDid(event->did);
if (call->getConnectionState() != Call::Connected) { if (call->getConnectionState() != Call::Connected) {
call->SIPCallAnswered(event); //call->SIPCallAnswered(event);
call->SIPCallAnsweredWithoutHold(event); call->SIPCallAnsweredWithoutHold(rdata);
call->setConnectionState(Call::Connected); call->setConnectionState(Call::Connected);
call->setState(Call::Active); call->setState(Call::Active);
...@@ -1329,7 +1266,7 @@ SIPVoIPLink::SIPCallAnswered(eXosip_event_t *event) ...@@ -1329,7 +1266,7 @@ SIPVoIPLink::SIPCallAnswered(eXosip_event_t *event)
Manager::instance().peerAnsweredCall(call->getCallId()); Manager::instance().peerAnsweredCall(call->getCallId());
if (Manager::instance().isCurrentCall(call->getCallId())) { if (Manager::instance().isCurrentCall(call->getCallId())) {
_debug("* SIP Info: Starting AudioRTP when answering\n"); _debug("* SIP Info: Starting AudioRTP when answering\n");
if ( _audiortp.createNewSession(call) < 0) { if ( _audiortp->createNewSession(call) < 0) {
_debug("RTP Failure: unable to create new session\n"); _debug("RTP Failure: unable to create new session\n");
} else { } else {
call->setAudioStart(true); call->setAudioStart(true);
...@@ -1337,7 +1274,7 @@ SIPVoIPLink::SIPCallAnswered(eXosip_event_t *event) ...@@ -1337,7 +1274,7 @@ SIPVoIPLink::SIPCallAnswered(eXosip_event_t *event)
} }
} else { } else {
_debug("* SIP Info: Answering call (on/off hold to send ACK)\n"); _debug("* SIP Info: Answering call (on/off hold to send ACK)\n");
call->SIPCallAnswered(event); //call->SIPCallAnswered(event);
} }
} }
...@@ -1401,21 +1338,22 @@ SIPVoIPLink::SIPCallRequestFailure(eXosip_event_t *event) ...@@ -1401,21 +1338,22 @@ SIPVoIPLink::SIPCallRequestFailure(eXosip_event_t *event)
} }
void void
SIPVoIPLink::SIPCallServerFailure(eXosip_event_t *event) SIPVoIPLink::SIPCallServerFailure(SIPCall *call)
{ {
if (!event->response) { return; } //if (!event->response) { return; }
switch(event->response->status_code) { //switch(event->response->status_code) {
case SIP_SERVICE_UNAVAILABLE: // 500 //case SIP_SERVICE_UNAVAILABLE: // 500
case SIP_BUSY_EVRYWHERE: // 600 //case SIP_BUSY_EVRYWHERE: // 600
case SIP_DECLINE: // 603 //case SIP_DECLINE: // 603
SIPCall* call = findSIPCallWithCid(event->cid); //SIPCall* call = findSIPCallWithCid(event->cid);
if (call != 0) { if (call != 0) {
_debug("Server error!\n");
CallID id = call->getCallId(); CallID id = call->getCallId();
Manager::instance().callFailure(id); Manager::instance().callFailure(id);
removeCall(id); removeCall(id);
} }
break; //break;
} //}
} }
void void
...@@ -1449,7 +1387,7 @@ SIPVoIPLink::SIPCallAck(eXosip_event_t *event) ...@@ -1449,7 +1387,7 @@ SIPVoIPLink::SIPCallAck(eXosip_event_t *event)
if (!call->isAudioStarted()) { if (!call->isAudioStarted()) {
if (Manager::instance().isCurrentCall(call->getCallId())) { if (Manager::instance().isCurrentCall(call->getCallId())) {
_debug("* SIP Info: Starting AudioRTP when ack\n"); _debug("* SIP Info: Starting AudioRTP when ack\n");
if ( _audiortp.createNewSession(call) ) { if ( _audiortp->createNewSession(call) ) {
call->setAudioStart(true); call->setAudioStart(true);
} }
} }
...@@ -1488,29 +1426,29 @@ SIPVoIPLink::SIPCallMessageNew(eXosip_event_t *event) ...@@ -1488,29 +1426,29 @@ SIPVoIPLink::SIPCallMessageNew(eXosip_event_t *event)
} }
void void
SIPVoIPLink::SIPCallClosed(eXosip_event_t *event) SIPVoIPLink::SIPCallClosed(SIPCall *call)
{ {
// it was without did before // it was without did before
SIPCall* call = findSIPCallWithCid(event->cid); //SIPCall* call = findSIPCallWithCid(event->cid);
if (!call) { return; } if (!call) { return; }
CallID id = call->getCallId(); CallID id = call->getCallId();
call->setDid(event->did); //call->setDid(event->did);
if (Manager::instance().isCurrentCall(id)) { if (Manager::instance().isCurrentCall(id)) {
call->setAudioStart(false); call->setAudioStart(false);
_debug("* SIP Info: Stopping AudioRTP when closing\n"); _debug("* SIP Info: Stopping AudioRTP when closing\n");
_audiortp.closeRtpSession(); _audiortp->closeRtpSession();
} }
Manager::instance().peerHungupCall(id); Manager::instance().peerHungupCall(id);
removeCall(id); removeCall(id);
} }
void void
SIPVoIPLink::SIPCallReleased(eXosip_event_t *event) SIPVoIPLink::SIPCallReleased(SIPCall *call)
{ {
// do cleanup if exists // do cleanup if exists
// only cid because did is always 0 in these case.. // only cid because did is always 0 in these case..
SIPCall* call = findSIPCallWithCid(event->cid); //SIPCall* call = findSIPCallWithCid(event->cid);
if (!call) { return; } if (!call) { return; }
// if we are here.. something when wrong before... // if we are here.. something when wrong before...
...@@ -1790,3 +1728,36 @@ SIPVoIPLink::sdp_off_hold_call (sdp_message_t * sdp) ...@@ -1790,3 +1728,36 @@ SIPVoIPLink::sdp_off_hold_call (sdp_message_t * sdp)
return 0; return 0;
} }
void SIPVoIPLink::setAuthName(const std::string& authname)
{
_authname = authname;
//_cred.username = pj_str((char *)authname.data());
}
void SIPVoIPLink::setPassword(const std::string& password)
{
_password = password;
/*_cred.data_type = PJSIP_CRED_DATA_PLAIN_PASSWD;
_cred.data = pj_str((char *)password.data());
_cred.realm = pj_str("*");
_cred.scheme = pj_str("digest");*/
}
void SIPVoIPLink::setSipServer(const std::string& sipServer)
{
//std::string tmp;
_debug("Set sip server %s\n", sipServer.data());
_server = sipServer;
//_registrar = pj_str((char *)tmp.data());
//_user = "<sip:" + _authname + "@" + sipServer + ">";
//_user = pj_str((char *)tmp.data());
}
pj_str_t SIPVoIPLink::string2PJStr(const std::string &value)
{
char tmp[256];
strcpy(tmp, value.data());
return pj_str(tmp);
}
...@@ -24,11 +24,15 @@ ...@@ -24,11 +24,15 @@
#include "voiplink.h" #include "voiplink.h"
#include <string> #include <string>
#include <eXosip2/eXosip.h> #include <eXosip2/eXosip.h>
#include "audio/audiortp.h"
#include <osip2/osip_mt.h> #include <osip2/osip_mt.h>
struct pjsip_regc;
struct pj_str_t;
struct pjmedia_sdp_session;
class EventThread; class EventThread;
class SIPCall; class SIPCall;
class AudioRtp;
/** /**
* @file sipvoiplink.h * @file sipvoiplink.h
...@@ -139,6 +143,9 @@ class SIPVoIPLink : public VoIPLink ...@@ -139,6 +143,9 @@ class SIPVoIPLink : public VoIPLink
*/ */
bool transfer(const CallID& id, const std::string& to); bool transfer(const CallID& id, const std::string& to);
/** Handle the incoming refer msg, not finished yet */
bool transferStep2();
/** /**
* Refuse the call * Refuse the call
* @param id The call identifier * @param id The call identifier
...@@ -187,15 +194,19 @@ class SIPVoIPLink : public VoIPLink ...@@ -187,15 +194,19 @@ class SIPVoIPLink : public VoIPLink
* Set the authentification name * Set the authentification name
* @param authname The authentification name * @param authname The authentification name
*/ */
void setAuthName(const std::string& authname) { _authname = authname; } void setAuthName(const std::string& authname); //{ _authname = authname; }
/** /**
* Set the password * Set the password
* @param password Password * @param password Password
*/ */
void setPassword(const std::string& password) { _password = password; } void setPassword(const std::string& password); //{ _password = password; }
private: void setSipServer(const std::string& sipServer);
//void setS
public:
/** /**
* Terminate every call not hangup | brutal | Protected by mutex * Terminate every call not hangup | brutal | Protected by mutex
...@@ -305,6 +316,7 @@ class SIPVoIPLink : public VoIPLink ...@@ -305,6 +316,7 @@ class SIPVoIPLink : public VoIPLink
* @param event eXosip Event * @param event eXosip Event
*/ */
void SIPCallAnswered(eXosip_event_t *event); void SIPCallAnswered(eXosip_event_t *event);
void SIPCallAnswered(SIPCall *call, pjsip_rx_data *rdata);
/** /**
* Handling 4XX error * Handling 4XX error
...@@ -316,7 +328,7 @@ class SIPVoIPLink : public VoIPLink ...@@ -316,7 +328,7 @@ class SIPVoIPLink : public VoIPLink
* Handling 5XX/6XX error * Handling 5XX/6XX error
* @param event eXosip Event * @param event eXosip Event
*/ */
void SIPCallServerFailure(eXosip_event_t *event); void SIPCallServerFailure(SIPCall *call);
/** /**
* Handle registration failure cases ( SIP_FORBIDDEN , SIP_UNAUTHORIZED ) * Handle registration failure cases ( SIP_FORBIDDEN , SIP_UNAUTHORIZED )
...@@ -346,14 +358,14 @@ class SIPVoIPLink : public VoIPLink ...@@ -346,14 +358,14 @@ class SIPVoIPLink : public VoIPLink
* Peer close the connection * Peer close the connection
* @param event eXosip Event * @param event eXosip Event
*/ */
void SIPCallClosed(eXosip_event_t *event); void SIPCallClosed(SIPCall *call);
/** /**
* The call pointer was released * The call pointer was released
* If the call was not cleared before, report an error * If the call was not cleared before, report an error
* @param event eXosip Event * @param event eXosip Event
*/ */
void SIPCallReleased(eXosip_event_t *event); void SIPCallReleased(SIPCall *call);
/** /**
* Receive a new Message request * Receive a new Message request
...@@ -428,7 +440,12 @@ class SIPVoIPLink : public VoIPLink ...@@ -428,7 +440,12 @@ class SIPVoIPLink : public VoIPLink
std::string _password; std::string _password;
/** Starting sound */ /** Starting sound */
AudioRtp _audiortp; AudioRtp* _audiortp;
pj_str_t string2PJStr(const std::string &value);
private:
pjsip_regc *_regc;
std::string _server;
}; };
#endif #endif
...@@ -29,6 +29,8 @@ ...@@ -29,6 +29,8 @@
class AudioCodec; class AudioCodec;
struct pjsip_rx_data;
/** Define AccountID type */ /** Define AccountID type */
typedef std::string AccountID; typedef std::string AccountID;
...@@ -277,7 +279,8 @@ class VoIPLink { ...@@ -277,7 +279,8 @@ class VoIPLink {
*/ */
int _registrationError; int _registrationError;
protected: //protected:
public:
/** Add a call to the call map (protected by mutex) /** Add a call to the call map (protected by mutex)
* @param call A call pointer with a unique pointer * @param call A call pointer with a unique pointer
* @return bool True if the call was unique and added * @return bool True if the call was unique and added
...@@ -296,6 +299,8 @@ class VoIPLink { ...@@ -296,6 +299,8 @@ class VoIPLink {
*/ */
bool clearCallMap(); bool clearCallMap();
protected:
/** Contains all the calls for this Link, protected by mutex */ /** Contains all the calls for this Link, protected by mutex */
CallMap _callMap; CallMap _callMap;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment