[asterisk-scf-commits] asterisk-scf/integration/sip.git branch "error-handling" updated.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Thu Dec 22 15:52:18 CST 2011
branch "error-handling" has been updated
via e8d23580c55b5b19f62c6990225ba60efd5b5f4a (commit)
via cb6a99642430f81cb67f26e69154648f36e04f8d (commit)
from ebd73dfcec878ee6d776aa8d2e55180dc9fc31c4 (commit)
Summary of changes:
src/PJSipSessionModule.cpp | 152 ++++++++++++++++++++++++++------------------
src/SipSession.cpp | 28 ++++----
2 files changed, 104 insertions(+), 76 deletions(-)
- Log -----------------------------------------------------------------
commit e8d23580c55b5b19f62c6990225ba60efd5b5f4a
Author: Mark Michelson <mmichelson at digium.com>
Date: Thu Dec 22 15:53:16 2011 -0600
Handle PJSIP errors in PJSipSessionModule.cpp
diff --git a/src/PJSipSessionModule.cpp b/src/PJSipSessionModule.cpp
index e1766ee..a111209 100644
--- a/src/PJSipSessionModule.cpp
+++ b/src/PJSipSessionModule.cpp
@@ -23,6 +23,7 @@
#include "SipStateReplicator.h"
#include "SipTelephonyEventSource.h"
#include "SipReplicationContext.h"
+#include "PJUtil.h"
#include <IceUtil/UUID.h>
#include <boost/lexical_cast.hpp>
@@ -350,14 +351,17 @@ bool PJSipSessionModule::checkAuth(pjsip_rx_data *rdata, pjsip_inv_session *inv,
}
pjsip_tx_data *tdata;
- pjsip_inv_end_session(inv, 401, NULL, &tdata);
-
- authInstance->addDigests(tdata, digests);
+ if (success(pjsip_inv_end_session(inv, 401, NULL, &tdata)))
+ {
+ authInstance->addDigests(tdata, digests);
- pjsip_inv_send_msg(inv, tdata);
+ pjsip_inv_send_msg(inv, tdata);
- mAuthManager->scheduleAuthTimeout(authInstance, sessionAuthTimeout);
- return true;
+ mAuthManager->scheduleAuthTimeout(authInstance, sessionAuthTimeout);
+ return true;
+ }
+ lg(Warning) << "Failed to create authentication challenge";
+ return false;
}
class SessionCreationOperation : public SipQueueableOperation
@@ -394,8 +398,10 @@ protected:
catch (const Ice::Exception& ex)
{
lg(Error) << "Exception caught while trying to create SIP session\n" << ex.what();
- pjsip_inv_end_session(mInv, 500, NULL, &mTdata);
- pjsip_inv_send_msg(mInv, mTdata);
+ if (success(pjsip_inv_end_session(mInv, 500, NULL, &mTdata)))
+ {
+ pjsip_inv_send_msg(mInv, mTdata);
+ }
return Complete;
}
@@ -411,7 +417,7 @@ protected:
pjmedia_sdp_session *sdp;
StreamInformationDict streams;
- if (!mInv->neg || (pjmedia_sdp_neg_get_neg_remote(mInv->neg, &remote_sdp) != PJ_SUCCESS))
+ if (!mInv->neg || fail(pjmedia_sdp_neg_get_neg_remote(mInv->neg, &remote_sdp)))
{
// No SDP was present in the INVITE so we need to create an offer
sdp = mSession->createSDPOffer(StreamInformationDict(), streams);
@@ -426,8 +432,10 @@ protected:
{
// If no SDP was created we can not accept this INVITE
lg(Error) << "No compatible formats found in offer\n";
- pjsip_inv_end_session(mInv, 488, NULL, &mTdata);
- pjsip_inv_send_msg(mInv, mTdata);
+ if (success(pjsip_inv_end_session(mInv, 488, NULL, &mTdata)))
+ {
+ pjsip_inv_send_msg(mInv, mTdata);
+ }
return Complete;
}
@@ -470,8 +478,10 @@ protected:
catch (const Ice::CommunicatorDestroyedException &)
{
// Everything else doesn't really map so they just become internal server errors
- pjsip_inv_end_session(mInv, 500, NULL, &mTdata);
- pjsip_inv_send_msg(mInv, mTdata);
+ if (success(pjsip_inv_end_session(mInv, 500, NULL, &mTdata)))
+ {
+ pjsip_inv_send_msg(mInv, mTdata);
+ }
}
return Complete;
}
@@ -485,13 +495,17 @@ protected:
}
catch (const DestinationNotFoundException &)
{
- pjsip_inv_end_session(mInv, 404, NULL, &mTdata);
- pjsip_inv_send_msg(mInv, mTdata);
+ if (success(pjsip_inv_end_session(mInv, 404, NULL, &mTdata)))
+ {
+ pjsip_inv_send_msg(mInv, mTdata);
+ }
}
catch (...)
{
- pjsip_inv_end_session(mInv, 500, NULL, &mTdata);
- pjsip_inv_send_msg(mInv, mTdata);
+ if (success(pjsip_inv_end_session(mInv, 500, NULL, &mTdata)))
+ {
+ pjsip_inv_send_msg(mInv, mTdata);
+ }
}
return Complete;
}
@@ -798,7 +812,7 @@ void PJSipSessionModule::handleNewInvite(pjsip_rx_data *rdata)
unsigned options = PJSIP_INV_SUPPORT_100REL;
// Verify we can handle this invite request and respond accordingly if we can not
- if (pjsip_inv_verify_request(rdata, &options, NULL, NULL, mEndpoint, &tdata) != PJ_SUCCESS)
+ if (fail(pjsip_inv_verify_request(rdata, &options, NULL, NULL, mEndpoint, &tdata)))
{
if (tdata)
{
@@ -814,7 +828,7 @@ void PJSipSessionModule::handleNewInvite(pjsip_rx_data *rdata)
pjsip_dialog *dlg, *replaced_dlg;
// If this is an attended transfer and something is amuck... respond accordingly
- if (pjsip_replaces_verify_request(rdata, &replaced_dlg, PJ_FALSE, &tdata) != PJ_SUCCESS)
+ if (fail(pjsip_replaces_verify_request(rdata, &replaced_dlg, PJ_FALSE, &tdata)))
{
if (tdata)
{
@@ -827,11 +841,7 @@ void PJSipSessionModule::handleNewInvite(pjsip_rx_data *rdata)
return;
}
- //XXX The NULL parameter should be replaced with
- //An appropriate Contact header. Leaving it NULL makes
- //PJSIP create the contact header for responses based
- //on the To header of the incoming Invite.
- if (pjsip_dlg_create_uas(pjsip_ua_instance(), rdata, NULL, &dlg) != PJ_SUCCESS)
+ if (fail(pjsip_dlg_create_uas(pjsip_ua_instance(), rdata, NULL, &dlg)))
{
lg(Warning) << "Unable to create UAS dialog on incoming INVITE";
return;
@@ -842,7 +852,7 @@ void PJSipSessionModule::handleNewInvite(pjsip_rx_data *rdata)
tsx->mod_data[mModule.id] = (void *)tsx_mod_info;
pjsip_inv_session *inv_session;
- if (pjsip_inv_create_uas(dlg, rdata, NULL, 0, &inv_session) != PJ_SUCCESS)
+ if (fail(pjsip_inv_create_uas(dlg, rdata, NULL, 0, &inv_session)))
{
lg(Warning) << "Unable to create INVITE session";
//Since the inv_session was not created, we need to access the base dialog
@@ -852,7 +862,11 @@ void PJSipSessionModule::handleNewInvite(pjsip_rx_data *rdata)
}
// Add our own module as a dialog usage
- pjsip_dlg_add_usage(dlg, &mModule, NULL);
+ if (fail(pjsip_dlg_add_usage(dlg, &mModule, NULL)))
+ {
+ lg(Warning) << "Unable to establish dialog usage";
+ pjsip_inv_terminate(inv_session, 500, PJ_FALSE);
+ }
PJSipDialogModInfo *dlg_mod_info(new PJSipDialogModInfo(dlg));
dlg->mod_data[mModule.id] = (void *)dlg_mod_info;
@@ -861,7 +875,7 @@ void PJSipSessionModule::handleNewInvite(pjsip_rx_data *rdata)
pjsip_timer_setting_default(&session_timer_settings);
pjsip_timer_init_session(inv_session, &session_timer_settings);
- if (pjsip_inv_initial_answer(inv_session, rdata, 100, NULL, NULL, &tdata) != PJ_SUCCESS)
+ if (fail(pjsip_inv_initial_answer(inv_session, rdata, 100, NULL, NULL, &tdata)))
{
lg(Warning) << "Failed to create 100 Trying response";
pjsip_inv_terminate(inv_session, 500, PJ_FALSE);
@@ -876,7 +890,7 @@ void PJSipSessionModule::handleNewInvite(pjsip_rx_data *rdata)
dlg_mod_info->mDialogState->sessionId = session_mod_info->mSessionState->sessionId;
tsx_mod_info->mTransactionState->sessionId = session_mod_info->mSessionState->sessionId;
- if (pjsip_inv_send_msg(inv_session, tdata) != PJ_SUCCESS)
+ if (fail(pjsip_inv_send_msg(inv_session, tdata)))
{
lg(Warning) << "Failed to send 100 Trying response";
pjsip_inv_terminate(inv_session, 500, PJ_FALSE);
@@ -904,16 +918,20 @@ void PJSipSessionModule::handleNewInvite(pjsip_rx_data *rdata)
if (caller == 0)
{
lg(Warning) << "Unknown calling endpoint " << callerName;
- pjsip_inv_end_session(inv_session, 403, NULL, &tdata);
- pjsip_inv_send_msg(inv_session, tdata);
+ if (success(pjsip_inv_end_session(inv_session, 403, NULL, &tdata)))
+ {
+ pjsip_inv_send_msg(inv_session, tdata);
+ }
return;
}
SipEndpointConfig &config = caller->getConfig();
if (config.sessionConfig.callDirection != BOTH && config.sessionConfig.callDirection != INBOUND)
{
lg(Warning) << "Caller " << callerName << " does not have permission to make inbound calls.";
- pjsip_inv_end_session(inv_session, 403, NULL, &tdata);
- pjsip_inv_send_msg(inv_session, tdata);
+ if (success(pjsip_inv_end_session(inv_session, 403, NULL, &tdata)))
+ {
+ pjsip_inv_send_msg(inv_session, tdata);
+ }
return;
}
@@ -932,8 +950,10 @@ void PJSipSessionModule::handleNewInvite(pjsip_rx_data *rdata)
else
{
//We don't support non-SIP URIs.
- pjsip_inv_end_session(inv_session, 500, NULL, &tdata);
- pjsip_inv_send_msg(inv_session, tdata);
+ if (success(pjsip_inv_end_session(inv_session, 416, NULL, &tdata)))
+ {
+ pjsip_inv_send_msg(inv_session, tdata);
+ }
return;
}
@@ -998,8 +1018,8 @@ void PJSipSessionModule::handleRefer(pjsip_inv_session *inv, pjsip_rx_data *rdat
// We only support SIP URIs, anything else is rubbish to us
if (!PJSIP_URI_SCHEME_IS_SIP(target_uri) && !PJSIP_URI_SCHEME_IS_SIPS(target_uri))
{
- lg(Debug) << "handleRefer() sending 400 due to non-SIP URI. ";
- pjsip_dlg_respond(inv->dlg, rdata, 400, NULL, NULL, NULL);
+ lg(Debug) << "handleRefer() sending 416 due to non-SIP URI. ";
+ pjsip_dlg_respond(inv->dlg, rdata, 416, NULL, NULL, NULL);
return;
}
@@ -1031,9 +1051,7 @@ void PJSipSessionModule::handleRefer(pjsip_inv_session *inv, pjsip_rx_data *rdat
//Create our initial response that we can modify in the queueable operation.
pjsip_tx_data *tdata = 0;
- pj_status_t status = pjsip_dlg_create_response(inv->dlg, rdata, 202, NULL, &tdata);
-
- if (status != PJ_SUCCESS)
+ if (fail(pjsip_dlg_create_response(inv->dlg, rdata, 202, NULL, &tdata)))
{
//Hm, we couldn't create a response. Let's hope this actually works...
lg(Error) << "Unable to create 202 Accepted response in response to REFER (Out of memory?)";
@@ -1259,8 +1277,15 @@ void PJSipSessionModule::handleInfo(pjsip_inv_session *inv, pjsip_rx_data *rdata
pjsip_transaction *tsx = pjsip_rdata_get_tsx(rdata);
pjsip_tx_data *tdata;
- pjsip_dlg_create_response(inv->dlg, rdata, 200, NULL, &tdata);
- enqueueSessionWork(new HandleInfoDTMFOperation(inv, tsx, tdata, session, dtmf, duration), inv);
+ if (success(pjsip_dlg_create_response(inv->dlg, rdata, 200, NULL, &tdata)))
+ {
+ enqueueSessionWork(new HandleInfoDTMFOperation(inv, tsx, tdata, session, dtmf, duration), inv);
+ }
+ else
+ {
+ lg(Error) << "Unable to create response message for INFO";
+ pjsip_dlg_respond(inv->dlg, rdata, 500, NULL, NULL, NULL);
+ }
return;
}
@@ -1483,11 +1508,13 @@ void PJSipSessionModule::handleInviteRejection(pjsip_inv_session* inv,
pjsip_auth_clt_set_credentials(&inv->dlg->auth_sess,
boost::numeric_cast<int>(creds.size()), &creds.front());
pjsip_tx_data *tdata;
- pjsip_auth_clt_reinit_req(&inv->dlg->auth_sess,
- rdata, tsx->last_tx, &tdata);
- //XXX The actual sending of the message should probably be done as
- //a queued operation.
- pjsip_inv_send_msg(inv, tdata);
+ if (success(pjsip_auth_clt_reinit_req(&inv->dlg->auth_sess,
+ rdata, tsx->last_tx, &tdata)))
+ {
+ //XXX The actual sending of the message should probably be done as
+ //a queued operation.
+ pjsip_inv_send_msg(inv, tdata);
+ }
return;
}
}
@@ -1789,11 +1816,13 @@ void PJSipSessionModule::handleNonInviteAuthentication(pjsip_inv_session* inv,
pjsip_auth_clt_set_credentials(&dlg->auth_sess,
boost::numeric_cast<int>(creds.size()), &creds.front());
pjsip_tx_data *tdata;
- pjsip_auth_clt_reinit_req(&dlg->auth_sess,
- rdata, tsx->last_tx, &tdata);
- //XXX The actual sending of the message should probably be done as
- //a queued operation.
- pjsip_dlg_send_request(dlg, tdata, -1, NULL);
+ if (success(pjsip_auth_clt_reinit_req(&dlg->auth_sess,
+ rdata, tsx->last_tx, &tdata)))
+ {
+ //XXX The actual sending of the message should probably be done as
+ //a queued operation.
+ pjsip_dlg_send_request(dlg, tdata, -1, NULL);
+ }
}
return;
}
@@ -1877,14 +1906,14 @@ protected:
{
const pjmedia_sdp_session *remote_sdp;
pj_status_t status;
- if ((status = pjmedia_sdp_neg_get_active_remote(mInv->neg, &remote_sdp)) != PJ_SUCCESS)
+ if (fail(pjmedia_sdp_neg_get_active_remote(mInv->neg, &remote_sdp)))
{
- pjsip_tx_data *packet;
- if (pjsip_inv_end_session(mInv, 488, NULL, &packet) == PJ_SUCCESS)
- {
- pjsip_inv_send_msg(mInv, packet);
- }
- return Complete;
+ pjsip_tx_data *packet;
+ if (success(pjsip_inv_end_session(mInv, 488, NULL, &packet)))
+ {
+ pjsip_inv_send_msg(mInv, packet);
+ }
+ return Complete;
}
PJSipSessionModInfo *session_mod_info = (PJSipSessionModInfo*)mInv->mod_data[mModuleId];
@@ -2016,14 +2045,13 @@ protected:
}
const pjmedia_sdp_session *offer_sdp;
- pj_status_t status;
- if ((status = pjmedia_sdp_neg_get_neg_remote(mInv->neg, &offer_sdp)) != PJ_SUCCESS)
+ if (fail(pjmedia_sdp_neg_get_neg_remote(mInv->neg, &offer_sdp)))
{
return Complete;
}
// Call into the session for the serious work
- session->createSDPAnswer(offer_sdp, mStreamsAdded);
+ session->createSDPAnswer(offer_sdp, mStreamsAdded);
// If no streams were added we can respond to the offer with the SDP we had previously and move on
if (mStreamsAdded.empty())
@@ -2066,7 +2094,7 @@ protected:
// Since that is now done we can set this new SDP as our answer and send a response to the reinvite
pjsip_inv_set_sdp_answer(mInv, sdp);
- pjsip_inv_send_reinvite_response(mInv, mResponse);
+ pjsip_inv_send_reinvite_response(mInv, mResponse);
return Complete;
}
commit cb6a99642430f81cb67f26e69154648f36e04f8d
Author: Mark Michelson <mmichelson at digium.com>
Date: Thu Dec 22 10:32:05 2011 -0600
Use the PJUtil error checking methods in SipSession.cpp
diff --git a/src/SipSession.cpp b/src/SipSession.cpp
index e3fda77..01d4426 100755
--- a/src/SipSession.cpp
+++ b/src/SipSession.cpp
@@ -20,6 +20,7 @@
#include "SipSession.h"
#include "SipTelephonyEventSource.h"
#include "SipTelephonyEventSink.h"
+#include "PJUtil.h"
#include <Ice/Ice.h>
#include <IceUtil/UUID.h>
@@ -639,7 +640,7 @@ public:
// what we really want to do is just update our answer SDP
pjsip_tx_data *packet = NULL;
- if ((pjsip_inv_reinvite(mImplPriv->mInviteSession, NULL, mImplPriv->mSDP, &packet)) == PJ_SUCCESS)
+ if (success(pjsip_inv_reinvite(mImplPriv->mInviteSession, NULL, mImplPriv->mSDP, &packet)))
{
pjsip_inv_send_msg(mImplPriv->mInviteSession, packet);
}
@@ -695,7 +696,7 @@ public:
// Okay, create and send the reinvite!
pjsip_tx_data *packet = NULL;
- if ((pjsip_inv_reinvite(mImplPriv->mInviteSession, NULL, sdp, &packet)) == PJ_SUCCESS)
+ if (success(pjsip_inv_reinvite(mImplPriv->mInviteSession, NULL, sdp, &packet)))
{
pjsip_inv_send_msg(mImplPriv->mInviteSession, packet);
}
@@ -736,7 +737,7 @@ public:
{
pjsip_tx_data *packet = NULL;
- if ((pjsip_inv_reinvite(mImplPriv->mInviteSession, NULL, mImplPriv->mSDP, &packet)) == PJ_SUCCESS)
+ if (success(pjsip_inv_reinvite(mImplPriv->mInviteSession, NULL, mImplPriv->mSDP, &packet)))
{
pjsip_inv_send_msg(mImplPriv->mInviteSession, packet);
}
@@ -948,7 +949,7 @@ public:
pjmedia_sdp_session *sdp = mSession->modifySDPforDirectConnections(mConnections);
pjsip_tx_data *packet = NULL;
- if ((pjsip_inv_reinvite(mSession->getInviteSession(), NULL, sdp, &packet)) == PJ_SUCCESS)
+ if (success(pjsip_inv_reinvite(mSession->getInviteSession(), NULL, sdp, &packet)))
{
pjsip_inv_send_msg(mSession->getInviteSession(), packet);
}
@@ -978,7 +979,7 @@ public:
pjmedia_sdp_session *sdp = mSession->modifySDP(mStreams);
pjsip_tx_data *packet = NULL;
- if ((pjsip_inv_reinvite(mSession->getInviteSession(), NULL, sdp, &packet)) == PJ_SUCCESS)
+ if (success(pjsip_inv_reinvite(mSession->getInviteSession(), NULL, sdp, &packet)))
{
pjsip_inv_send_msg(mSession->getInviteSession(), packet);
}
@@ -1105,8 +1106,7 @@ void SipSession::initializePJSIPStructs()
pj_str_t remote_uri(pj_str(remote));
pjsip_dialog *dialog;
- if ((pjsip_dlg_create_uac(pjsip_ua_instance(), &local_uri, &contact_uri, &remote_uri, &remote_uri, &dialog)) !=
- PJ_SUCCESS)
+ if (fail(pjsip_dlg_create_uac(pjsip_ua_instance(), &local_uri, &contact_uri, &remote_uri, &remote_uri, &dialog)))
{
// What should we do here? Throw an exception?
lg(Error) << "Failed to create a UAC dialog!";
@@ -1118,7 +1118,7 @@ void SipSession::initializePJSIPStructs()
pjsip_tpselector selector;
if (transport->initSelector(selector))
{
- if(pjsip_dlg_set_transport(dialog, &selector) != PJ_SUCCESS)
+ if (fail(pjsip_dlg_set_transport(dialog, &selector)))
{
//
// This would be pretty weird.. I guess if the transport no longer exists at this point.
@@ -1137,7 +1137,7 @@ void SipSession::initializePJSIPStructs()
StreamInformationDict added;
pjmedia_sdp_session *sdp = createSDPOffer(StreamInformationDict(), added);
- if ((pjsip_inv_create_uac(dialog, sdp, 0, &inviteSession)) != PJ_SUCCESS)
+ if (fail(pjsip_inv_create_uac(dialog, sdp, 0, &inviteSession)))
{
lg(Error) << "Failed to create a UAC INVITE session!";
pjsip_dlg_terminate(dialog);
@@ -2035,7 +2035,7 @@ public:
// Create the actual INVITE packet
pjsip_tx_data *packet;
- if ((pjsip_inv_invite(mImplPriv->mInviteSession, &packet)) != PJ_SUCCESS)
+ if (fail(pjsip_inv_invite(mImplPriv->mInviteSession, &packet)))
{
pjsip_inv_terminate(mImplPriv->mInviteSession, 500, 0);
pjsip_dlg_terminate(mImplPriv->mInviteSession->dlg);
@@ -2304,7 +2304,7 @@ public:
// On an outbound call, if we have not received a provisional response yet, then PJSIP will
// set packet NULL but still return PJ_SUCCESS. In this case, if we attempt to call pjsip_inv_send_msg,
// then we will trigger an assertion since the packet we pass in is NULL.
- if (mInviteSession && (pjsip_inv_end_session(mInviteSession, code, NULL, &packet) == PJ_SUCCESS) && packet)
+ if (mInviteSession && success(pjsip_inv_end_session(mInviteSession, code, NULL, &packet)) && packet)
{
pjsip_inv_send_msg(mInviteSession, packet);
}
@@ -3683,7 +3683,7 @@ pjmedia_sdp_session *SipSession::createSDPAnswer(const pjmedia_sdp_session* offe
catch (const AsteriskSCF::Media::RTP::V1::InvalidAddress&)
{
pjsip_tx_data *packet;
- if (pjsip_inv_end_session(mImplPriv->mInviteSession, 488, NULL, &packet) == PJ_SUCCESS)
+ if (success(pjsip_inv_end_session(mImplPriv->mInviteSession, 488, NULL, &packet)))
{
pjsip_inv_send_msg(mImplPriv->mInviteSession, packet);
}
@@ -3822,7 +3822,7 @@ pjmedia_sdp_session *SipSession::createSDPAnswer(const pjmedia_sdp_session* offe
catch (const AsteriskSCF::Network::V1::InvalidAddress&)
{
pjsip_tx_data *packet;
- if (pjsip_inv_end_session(mImplPriv->mInviteSession, 488, NULL, &packet) == PJ_SUCCESS)
+ if (success(pjsip_inv_end_session(mImplPriv->mInviteSession, 488, NULL, &packet)))
{
pjsip_inv_send_msg(mImplPriv->mInviteSession, packet);
}
@@ -4121,7 +4121,7 @@ void SipSession::startMedia(const pjmedia_sdp_session*, const pjmedia_sdp_sessio
// or the client is not supporting it. Let's tear down the session and get out of here.
//
pjsip_tx_data* packet;
- if (pjsip_inv_end_session(mImplPriv->mInviteSession, 488, NULL, &packet) == PJ_SUCCESS)
+ if (success(pjsip_inv_end_session(mImplPriv->mInviteSession, 488, NULL, &packet)))
{
pjsip_inv_send_msg(mImplPriv->mInviteSession, packet);
}
-----------------------------------------------------------------------
--
asterisk-scf/integration/sip.git
More information about the asterisk-scf-commits
mailing list