Commit f8a15842 authored by Tristan Matthews's avatar Tristan Matthews
Browse files

* #9847: SDP: don't use assertions for runtime errors

In the case of errors depending on network input (i.e. not programming
logic errors), we should report errors but not abort the application.
Assertions should be used to validate and document programmer
assumptions. Moreover, if assertions are deactivated at build-time, we
don't want our application to crash.
parent bfaefc88
......@@ -237,6 +237,11 @@ int Sdp::createLocalSession(const CodecOrder &selectedCodecs)
setLocalMediaCapabilities(selectedCodecs);
localSession_ = PJ_POOL_ZALLOC_T(memPool_, pjmedia_sdp_session);
if (!localSession_) {
ERROR("Sdp: Could not create local SDP session");
return !PJ_SUCCESS;
}
localSession_->conn = PJ_POOL_ZALLOC_T(memPool_, pjmedia_sdp_conn);
/* Initialize the fields of the struct */
......@@ -292,7 +297,6 @@ void Sdp::receiveOffer(const pjmedia_sdp_session* remote,
return;
}
DEBUG("SDP: Remote SDP Session:");
printSession(remote);
......@@ -303,27 +307,23 @@ void Sdp::receiveOffer(const pjmedia_sdp_session* remote,
remoteSession_ = pjmedia_sdp_session_clone(memPool_, remote);
pj_status_t status = pjmedia_sdp_neg_create_w_remote_offer(memPool_, localSession_,
remoteSession_, &negotiator_);
assert(status == PJ_SUCCESS);
}
void Sdp::receivingAnswerAfterInitialOffer(const pjmedia_sdp_session* remote)
{
assert(pjmedia_sdp_neg_get_state(negotiator_) == PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER);
assert(pjmedia_sdp_neg_set_remote_answer(memPool_, negotiator_, remote) == PJ_SUCCESS);
assert(pjmedia_sdp_neg_get_state(negotiator_) == PJMEDIA_SDP_NEG_STATE_WAIT_NEGO);
if (pjmedia_sdp_neg_create_w_remote_offer(memPool_, localSession_,
remoteSession_, &negotiator_) != PJ_SUCCESS) {
ERROR("Could not create negotiator with remote offer");
negotiator_ = NULL;
}
}
void Sdp::startNegotiation()
{
if (negotiator_ == NULL) {
ERROR("Sdp: Can't start negotiation with invalid negotiator");
return;
}
const pjmedia_sdp_session *active_local;
const pjmedia_sdp_session *active_remote;
assert(negotiator_);
if (pjmedia_sdp_neg_get_state(negotiator_) != PJMEDIA_SDP_NEG_STATE_WAIT_NEGO)
WARN("SDP: Warning: negotiator not in right state for negotiation");
......@@ -372,12 +372,14 @@ Sdp::~Sdp()
void Sdp::addAttributeToLocalAudioMedia(const char *attr)
{
pjmedia_sdp_media_add_attr(localSession_->media[0], pjmedia_sdp_attr_create(memPool_, attr, NULL));
if (localSession_)
pjmedia_sdp_media_add_attr(localSession_->media[0], pjmedia_sdp_attr_create(memPool_, attr, NULL));
}
void Sdp::removeAttributeFromLocalAudioMedia(const char *attr)
{
pjmedia_sdp_media_remove_all_attr(localSession_->media[0], attr);
if (localSession_)
pjmedia_sdp_media_remove_all_attr(localSession_->media[0], attr);
}
void Sdp::setMediaTransportInfoFromRemoteSdp()
......
......@@ -274,10 +274,9 @@ class Sdp {
std::string getCodecName();
void receivingAnswerAfterInitialOffer(const pjmedia_sdp_session* remote);
private:
NON_COPYABLE(Sdp);
friend class SDPTest;
/**
* The pool to allocate memory, ownership to SipCall
......
......@@ -116,6 +116,12 @@ void SDPTest::tearDown()
pj_pool_release(testPool_);
}
void SDPTest::receiveAnswerAfterInitialOffer(const pjmedia_sdp_session* remote)
{
assert(pjmedia_sdp_neg_get_state(session_->negotiator_) == PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER);
assert(pjmedia_sdp_neg_set_remote_answer(session_->memPool_, session_->negotiator_, remote) == PJ_SUCCESS);
assert(pjmedia_sdp_neg_get_state(session_->negotiator_) == PJMEDIA_SDP_NEG_STATE_WAIT_NEGO);
}
void SDPTest::testInitialOfferFirstCodec()
{
......@@ -141,7 +147,7 @@ void SDPTest::testInitialOfferFirstCodec()
// pjmedia_sdp_parse(testPool_, test[0].offer_answer[0].sdp2, strlen(test[0].offer_answer[0].sdp2), &remoteAnswer);
pjmedia_sdp_parse(testPool_, (char*)sdp_answer1, strlen(sdp_answer1), &remoteAnswer);
session_->receivingAnswerAfterInitialOffer(remoteAnswer);
receiveAnswerAfterInitialOffer(remoteAnswer);
session_->startNegotiation();
session_->setMediaTransportInfoFromRemoteSdp();
......@@ -213,7 +219,7 @@ void SDPTest::testInitialOfferLastCodec()
// pjmedia_sdp_parse(testPool_, test[0].offer_answer[0].sdp2, strlen(test[0].offer_answer[0].sdp2), &remoteAnswer);
pjmedia_sdp_parse(testPool_, (char*)sdp_answer2, strlen(sdp_answer2), &remoteAnswer);
session_->receivingAnswerAfterInitialOffer(remoteAnswer);
receiveAnswerAfterInitialOffer(remoteAnswer);
session_->startNegotiation();
session_->setMediaTransportInfoFromRemoteSdp();
......@@ -287,7 +293,7 @@ void SDPTest::testReinvite()
// pjmedia_sdp_parse(testPool_, test[0].offer_answer[0].sdp2, strlen(test[0].offer_answer[0].sdp2), &remoteAnswer);
pjmedia_sdp_parse(testPool_, (char*)sdp_answer1, strlen(sdp_answer1), &remoteAnswer);
session_->receivingAnswerAfterInitialOffer(remoteAnswer);
receiveAnswerAfterInitialOffer(remoteAnswer);
session_->startNegotiation();
session_->setMediaTransportInfoFromRemoteSdp();
......@@ -298,7 +304,7 @@ void SDPTest::testReinvite()
CPPUNIT_ASSERT(session_->getRemoteIP() == "host.example.com");
CPPUNIT_ASSERT(session_->getSessionMedia()->getMimeSubtype() == "PCMU");
pjmedia_sdp_parse(testPool_, (char*)sdp_reinvite, strlen(sdp_reinvite), &reinviteOffer);
pjmedia_sdp_parse(testPool_, (char*) sdp_reinvite, strlen(sdp_reinvite), &reinviteOffer);
session_->receiveOffer(reinviteOffer, codecSelection);
......
......@@ -118,6 +118,7 @@ class SDPTest : public CppUnit::TestCase {
private:
NON_COPYABLE(SDPTest);
void receiveAnswerAfterInitialOffer(const pjmedia_sdp_session* remote);
Sdp *session_;
pj_pool_t *testPool_;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment