Skip to content
Snippets Groups Projects
Commit 5065f89a authored by yanmorin's avatar yanmorin
Browse files

Correcting checkNetwork
parent b02e54b4
No related branches found
No related tags found
No related merge requests found
...@@ -194,25 +194,33 @@ SipCall::newIncomingCall (eXosip_event_t *event) { ...@@ -194,25 +194,33 @@ SipCall::newIncomingCall (eXosip_event_t *event) {
/* negotiate payloads */ /* negotiate payloads */
sdp_message_t *remote_sdp = NULL; sdp_message_t *remote_sdp = NULL;
if (event->request != NULL) { if (event->request != NULL) {
eXosip_lock();
remote_sdp = eXosip_get_sdp_info (event->request); remote_sdp = eXosip_get_sdp_info (event->request);
eXosip_unlock();
} }
if (remote_sdp == NULL) { if (remote_sdp == NULL) {
_debug("SipCall::newIncomingCall: No remote SDP in INVITE request. Sending 400 BAD REQUEST\n"); _debug("SipCall::newIncomingCall: No remote SDP in INVITE request. Sending 400 BAD REQUEST\n");
// Send 400 BAD REQUEST // Send 400 BAD REQUEST
eXosip_lock();
eXosip_call_send_answer (_tid, 400, NULL); eXosip_call_send_answer (_tid, 400, NULL);
eXosip_unlock();
return 0; return 0;
} }
/* TODO: else build an offer */ /* TODO: else build an offer */
// Remote Media IP // Remote Media IP
eXosip_lock();
sdp_connection_t *conn = eXosip_get_audio_connection (remote_sdp); sdp_connection_t *conn = eXosip_get_audio_connection (remote_sdp);
eXosip_unlock();
if (conn != NULL && conn->c_addr != NULL) { if (conn != NULL && conn->c_addr != NULL) {
snprintf (_remote_sdp_audio_ip, 49, "%s", conn->c_addr); snprintf (_remote_sdp_audio_ip, 49, "%s", conn->c_addr);
_debug(" Remote Audio IP: %s\n", _remote_sdp_audio_ip); _debug(" Remote Audio IP: %s\n", _remote_sdp_audio_ip);
} }
// Remote Media Port // Remote Media Port
eXosip_lock();
sdp_media_t *remote_med = eXosip_get_audio_media (remote_sdp); sdp_media_t *remote_med = eXosip_get_audio_media (remote_sdp);
eXosip_unlock();
if (remote_med == NULL || remote_med->m_port == NULL) { if (remote_med == NULL || remote_med->m_port == NULL) {
// no audio media proposed // no audio media proposed
_debug("< Sending 415 Unsupported media type\n"); _debug("< Sending 415 Unsupported media type\n");
...@@ -397,18 +405,23 @@ SipCall::answeredCall_without_hold (eXosip_event_t *event) ...@@ -397,18 +405,23 @@ SipCall::answeredCall_without_hold (eXosip_event_t *event)
{ {
if (event->response == NULL ) { return; } if (event->response == NULL ) { return; }
// TODO: understand this code..
if (_cid!=0) { if (_cid!=0) {
eXosip_lock();
sdp_message_t *sdp = eXosip_get_sdp_info (event->response); sdp_message_t *sdp = eXosip_get_sdp_info (event->response);
eXosip_unlock();
if (sdp != NULL) { if (sdp != NULL) {
/* audio is started and session has just been modified */ /* audio is started and session has just been modified */
sdp_message_free (sdp); sdp_message_free (sdp);
} }
} }
if (event->request != NULL) { /* audio is started */ if (event->request != NULL) { /* audio is started */
eXosip_lock();
sdp_message_t *local_sdp = eXosip_get_sdp_info (event->request); sdp_message_t *local_sdp = eXosip_get_sdp_info (event->request);
sdp_message_t *remote_sdp = eXosip_get_sdp_info (event->response); sdp_message_t *remote_sdp = eXosip_get_sdp_info (event->response);
eXosip_unlock();
sdp_media_t *remote_med = NULL; sdp_media_t *remote_med = NULL;
char *tmp = NULL; char *tmp = NULL;
...@@ -416,6 +429,7 @@ SipCall::answeredCall_without_hold (eXosip_event_t *event) ...@@ -416,6 +429,7 @@ SipCall::answeredCall_without_hold (eXosip_event_t *event)
_debug("SipCall::answeredCall_without_hold: No remote SDP body found for call\n"); _debug("SipCall::answeredCall_without_hold: No remote SDP body found for call\n");
/* TODO: remote_sdp = retreive from ack above */ /* TODO: remote_sdp = retreive from ack above */
} else { } else {
eXosip_lock();
sdp_connection_t *conn = eXosip_get_audio_connection (remote_sdp); sdp_connection_t *conn = eXosip_get_audio_connection (remote_sdp);
if (conn != NULL && conn->c_addr != NULL) { if (conn != NULL && conn->c_addr != NULL) {
snprintf (_remote_sdp_audio_ip, 49, "%s", conn->c_addr); snprintf (_remote_sdp_audio_ip, 49, "%s", conn->c_addr);
...@@ -425,6 +439,7 @@ SipCall::answeredCall_without_hold (eXosip_event_t *event) ...@@ -425,6 +439,7 @@ SipCall::answeredCall_without_hold (eXosip_event_t *event)
if (remote_med != NULL && remote_med->m_port != NULL) { if (remote_med != NULL && remote_med->m_port != NULL) {
_remote_sdp_audio_port = atoi (remote_med->m_port); _remote_sdp_audio_port = atoi (remote_med->m_port);
} }
eXosip_unlock();
if (_remote_sdp_audio_port > 0 && _remote_sdp_audio_ip[0] != '\0' && if (_remote_sdp_audio_port > 0 && _remote_sdp_audio_ip[0] != '\0' &&
remote_med != NULL) { remote_med != NULL) {
...@@ -444,7 +459,9 @@ SipCall::answeredCall_without_hold (eXosip_event_t *event) ...@@ -444,7 +459,9 @@ SipCall::answeredCall_without_hold (eXosip_event_t *event)
if (remote_sdp != NULL && local_sdp != NULL) { if (remote_sdp != NULL && local_sdp != NULL) {
int audio_port = 0; int audio_port = 0;
eXosip_lock();
sdp_media_t *local_med = eXosip_get_audio_media (local_sdp); sdp_media_t *local_med = eXosip_get_audio_media (local_sdp);
eXosip_unlock();
if (local_med != NULL && local_med->m_port != NULL) { if (local_med != NULL && local_med->m_port != NULL) {
audio_port = atoi (local_med->m_port); audio_port = atoi (local_med->m_port);
} }
...@@ -494,6 +511,7 @@ SipCall::sdp_complete_message(sdp_message_t * remote_sdp, ...@@ -494,6 +511,7 @@ SipCall::sdp_complete_message(sdp_message_t * remote_sdp,
return -1; return -1;
} }
// this exosip is locked and is protected by other function
eXosip_guess_localip (AF_INET, localip, 128); eXosip_guess_localip (AF_INET, localip, 128);
snprintf (buf, 4096, snprintf (buf, 4096,
"v=0\r\n" "v=0\r\n"
......
...@@ -65,15 +65,15 @@ SipVoIPLink::terminate(void) ...@@ -65,15 +65,15 @@ SipVoIPLink::terminate(void)
{ {
} }
bool bool
SipVoIPLink::checkNetwork (void) SipVoIPLink::checkNetwork (void)
{ {
// Set IP address // Set IP address
return getSipLocalIp(); return getSipLocalIp();
} }
int int
SipVoIPLink::init (void) SipVoIPLink::init(void)
{ {
std::string tmp; std::string tmp;
tmp = std::string(PROGNAME) + "/" + std::string(SFLPHONED_VERSION); tmp = std::string(PROGNAME) + "/" + std::string(SFLPHONED_VERSION);
...@@ -110,6 +110,7 @@ SipVoIPLink::init (void) ...@@ -110,6 +110,7 @@ SipVoIPLink::init (void)
eXosip_set_user_agent(tmp.data()); eXosip_set_user_agent(tmp.data());
} }
checkNetwork();
_debug("SIP VoIP Link: listen to SIP Events\n"); _debug("SIP VoIP Link: listen to SIP Events\n");
_evThread->start(); _evThread->start();
return 1; return 1;
...@@ -145,18 +146,20 @@ SipVoIPLink::subscribeMessageSummary() ...@@ -145,18 +146,20 @@ SipVoIPLink::subscribeMessageSummary()
// return 0 if no error // return 0 if no error
// the first from is the to... but we send the same // the first from is the to... but we send the same
eXosip_lock();
int error = eXosip_subscribe_build_initial_request(&subscribe, to.c_str(), from.c_str(), route, event, expires); int error = eXosip_subscribe_build_initial_request(&subscribe, to.c_str(), from.c_str(), route, event, expires);
eXosip_unlock();
if (error == 0) { if (error == 0) {
// Accept: application/simple-message-summary // Accept: application/simple-message-summary
osip_message_set_header (subscribe, "Accept", "application/simple-message-summary"); osip_message_set_header (subscribe, "Accept", "application/simple-message-summary");
_debug("Sending Message-summary subscription"); _debug("Sending Message-summary subscription");
eXosip_lock();
// return 0 if ok // return 0 if ok
eXosip_lock();
error = eXosip_subscribe_send_initial_request (subscribe); error = eXosip_subscribe_send_initial_request (subscribe);
_debug(" and return %d\n", error);
eXosip_unlock(); eXosip_unlock();
_debug(" and return %d\n", error);
} }
} }
...@@ -277,6 +280,7 @@ SipVoIPLink::setUnregister (void) ...@@ -277,6 +280,7 @@ SipVoIPLink::setUnregister (void)
int int
SipVoIPLink::outgoingInvite (CALLID id, const std::string& to_url) SipVoIPLink::outgoingInvite (CALLID id, const std::string& to_url)
{ {
bool has_ip = checkNetwork();
std::string from; std::string from;
std::string to; std::string to;
...@@ -301,7 +305,7 @@ SipVoIPLink::outgoingInvite (CALLID id, const std::string& to_url) ...@@ -301,7 +305,7 @@ SipVoIPLink::outgoingInvite (CALLID id, const std::string& to_url)
if (manager.getConfigString(SIGNALISATION, PROXY).empty()) { if (manager.getConfigString(SIGNALISATION, PROXY).empty()) {
// If no SIP proxy setting for direct call with only IP address // If no SIP proxy setting for direct call with only IP address
if (checkNetwork()) { if (has_ip) {
if (startCall(id, from, to, "", "") <= 0) { if (startCall(id, from, to, "", "") <= 0) {
_debug("Warning SipVoIPLink: call not started\n"); _debug("Warning SipVoIPLink: call not started\n");
return -1; return -1;
...@@ -315,7 +319,7 @@ SipVoIPLink::outgoingInvite (CALLID id, const std::string& to_url) ...@@ -315,7 +319,7 @@ SipVoIPLink::outgoingInvite (CALLID id, const std::string& to_url)
// If SIP proxy setting // If SIP proxy setting
std::string route = "<sip:" + std::string route = "<sip:" +
manager.getConfigString(SIGNALISATION, PROXY) + ";lr>"; manager.getConfigString(SIGNALISATION, PROXY) + ";lr>";
if (checkNetwork()) { if (has_ip) {
if (startCall(id, from, to, "", route) <= 0) { if (startCall(id, from, to, "", route) <= 0) {
_debug("Warning SipVoIPLink: call not started\n"); _debug("Warning SipVoIPLink: call not started\n");
return -1; return -1;
...@@ -361,6 +365,7 @@ SipVoIPLink::answer (CALLID id) ...@@ -361,6 +365,7 @@ SipVoIPLink::answer (CALLID id)
// Send 400 BAD_REQUEST // Send 400 BAD_REQUEST
eXosip_call_send_answer (ca->getTid(), BAD_REQ, NULL); eXosip_call_send_answer (ca->getTid(), BAD_REQ, NULL);
} else { } else {
// use exosip, bug locked
i = sdp_complete_200ok (ca->getDid(), answerMessage, port); i = sdp_complete_200ok (ca->getDid(), answerMessage, port);
if (i != 0) { if (i != 0) {
osip_message_free (answerMessage); osip_message_free (answerMessage);
...@@ -508,8 +513,8 @@ SipVoIPLink::offhold (CALLID id) ...@@ -508,8 +513,8 @@ SipVoIPLink::offhold (CALLID id)
return -1; return -1;
} }
eXosip_lock ();
// Build INVITE_METHOD for put call off-hold // Build INVITE_METHOD for put call off-hold
eXosip_lock ();
i = eXosip_call_build_request (did, INVITE_METHOD, &invite); i = eXosip_call_build_request (did, INVITE_METHOD, &invite);
eXosip_unlock (); eXosip_unlock ();
...@@ -541,8 +546,8 @@ SipVoIPLink::offhold (CALLID id) ...@@ -541,8 +546,8 @@ SipVoIPLink::offhold (CALLID id)
osip_message_set_content_type (invite, "application/sdp"); osip_message_set_content_type (invite, "application/sdp");
} }
eXosip_lock ();
// Send request // Send request
eXosip_lock ();
i = eXosip_call_send_request (did, invite); i = eXosip_call_send_request (did, invite);
eXosip_unlock (); eXosip_unlock ();
...@@ -670,7 +675,9 @@ SipVoIPLink::getEvent (void) ...@@ -670,7 +675,9 @@ SipVoIPLink::getEvent (void)
} }
} }
} else { } else {
eXosip_lock();
eXosip_call_send_answer(event->tid, 488, NULL); eXosip_call_send_answer(event->tid, 488, NULL);
eXosip_unlock();
} }
break; break;
...@@ -1154,6 +1161,7 @@ SipVoIPLink::sdp_complete_200ok (int did, osip_message_t * answerMessage, int po ...@@ -1154,6 +1161,7 @@ SipVoIPLink::sdp_complete_200ok (int did, osip_message_t * answerMessage, int po
bzero(port_tmp, 64); bzero(port_tmp, 64);
snprintf(port_tmp, 63, "%d", port); snprintf(port_tmp, 63, "%d", port);
// thus exosip call is protected by an extern lock
remote_sdp = eXosip_get_remote_sdp (did); remote_sdp = eXosip_get_remote_sdp (did);
if (remote_sdp == NULL) { if (remote_sdp == NULL) {
return -1; /* no existing body? */ return -1; /* no existing body? */
...@@ -1263,10 +1271,12 @@ SipVoIPLink::getSipLocalIp (void) ...@@ -1263,10 +1271,12 @@ SipVoIPLink::getSipLocalIp (void)
bool returnValue = true; bool returnValue = true;
if (getLocalIpAddress() == "127.0.0.1") { if (getLocalIpAddress() == "127.0.0.1") {
char* myIPAddress = new char[65]; char* myIPAddress = new char[65];
if (eXosip_guess_localip (AF_INET, myIPAddress, 64) == -1) { if (eXosip_guess_localip(AF_INET, myIPAddress, 64) == -1) {
returnValue = false; returnValue = false;
} else {
setLocalIpAddress(std::string(myIPAddress));
_debug("Checking network, setting local ip address to: %s\n", myIPAddress);
} }
setLocalIpAddress(std::string(myIPAddress));
delete [] myIPAddress; myIPAddress = NULL; delete [] myIPAddress; myIPAddress = NULL;
} }
return returnValue; return returnValue;
...@@ -1373,11 +1383,14 @@ SipVoIPLink::startCall (CALLID id, const std::string& from, const std::string& t ...@@ -1373,11 +1383,14 @@ SipVoIPLink::startCall (CALLID id, const std::string& from, const std::string& t
sipcall->setLocalAudioPort(_localPort); sipcall->setLocalAudioPort(_localPort);
sipcall->setLocalIp(getLocalIpAddress()); sipcall->setLocalIp(getLocalIpAddress());
eXosip_lock();
int i = eXosip_call_build_initial_invite (&invite, (char*)to.data(), int i = eXosip_call_build_initial_invite (&invite, (char*)to.data(),
(char*)from.data(), (char*)from.data(),
(char*)route.data(), (char*)route.data(),
(char*)subject.data()); (char*)subject.data());
if (i != 0) { if (i != 0) {
eXosip_unlock();
return -1; // error when building the invite return -1; // error when building the invite
} }
...@@ -1416,32 +1429,27 @@ SipVoIPLink::startCall (CALLID id, const std::string& from, const std::string& t ...@@ -1416,32 +1429,27 @@ SipVoIPLink::startCall (CALLID id, const std::string& from, const std::string& t
/* add sdp body */ /* add sdp body */
{ {
char tmp[4096]; char tmp[4096];
char localip[128];
eXosip_guess_localip (AF_INET, localip, 128);
char port[64];
bzero (port, 64);
snprintf (port, 63, "%d", getLocalPort());
snprintf (tmp, 4096, snprintf (tmp, 4096,
"v=0\r\n" "v=0\r\n"
"o=SFLphone 0 0 IN IP4 %s\r\n" "o=SFLphone 0 0 IN IP4 %s\r\n"
"s=call\r\n" "s=call\r\n"
"c=IN IP4 %s\r\n" "c=IN IP4 %s\r\n"
"t=0 0\r\n" "t=0 0\r\n"
"m=audio %s RTP/AVP %s\r\n" "m=audio %d RTP/AVP %s\r\n"
"%s", "%s",
localip, localip, port, media_audio, rtpmap_attr); getLocalIpAddress().c_str(), getLocalIpAddress().c_str(), getLocalPort(), media_audio, rtpmap_attr);
// media_audio should be one, two or three numbers? // media_audio should be one, two or three numbers?
osip_message_set_body (invite, tmp, strlen (tmp)); osip_message_set_body (invite, tmp, strlen (tmp));
osip_message_set_content_type (invite, "application/sdp"); osip_message_set_content_type (invite, "application/sdp");
} }
eXosip_lock();
// this is the cid (call id from exosip) // this is the cid (call id from exosip)
int cid = eXosip_call_send_initial_invite (invite); int cid = eXosip_call_send_initial_invite (invite);
_debug("> Start a new Call: Send INVITE\n");
_debug(" Local IP:port: %s:%d\n", getLocalIpAddress().c_str(), getLocalPort());
_debug(" Payload: %s\n", media_audio);
// Keep the cid in case of cancelling // Keep the cid in case of cancelling
sipcall->setCid(cid); sipcall->setCid(cid);
...@@ -1451,7 +1459,6 @@ SipVoIPLink::startCall (CALLID id, const std::string& from, const std::string& t ...@@ -1451,7 +1459,6 @@ SipVoIPLink::startCall (CALLID id, const std::string& from, const std::string& t
} else { } else {
eXosip_call_set_reference (cid, NULL); eXosip_call_set_reference (cid, NULL);
} }
eXosip_unlock(); eXosip_unlock();
return cid; // this is the Cid return cid; // this is the Cid
......
...@@ -90,5 +90,5 @@ VoIPLink::initConstructor(void) ...@@ -90,5 +90,5 @@ VoIPLink::initConstructor(void)
Manager::instance().getConfigString(SIGNALISATION,FULL_NAME Manager::instance().getConfigString(SIGNALISATION,FULL_NAME
) ; ) ;
_hostname = Manager::instance().getConfigString(SIGNALISATION,HOST_PART); _hostname = Manager::instance().getConfigString(SIGNALISATION,HOST_PART);
_localIpAddress = ""; _localIpAddress = "127.0.0.1"; // sipvoip require this value to check network
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment