void AmB2ABCalleeSession::onB2ABEvent(B2ABEvent* ev) { if(ev->event_id == B2ABConnectLeg){ try { B2ABConnectLegEvent* co_ev = dynamic_cast<B2ABConnectLegEvent*>(ev); assert(co_ev); MONITORING_LOG4(getLocalTag().c_str(), "b2b_leg", other_id.c_str(), "from", co_ev->local_party.c_str(), "to", co_ev->remote_party.c_str(), "ruri", co_ev->remote_uri.c_str()); dlg.local_party = co_ev->local_party; dlg.local_uri = co_ev->local_uri; dlg.remote_party = co_ev->remote_party; dlg.remote_uri = co_ev->remote_uri; setCallgroup(co_ev->callgroup); setNegotiateOnReply(true); if (sendInvite(co_ev->headers)) { throw string("INVITE could not be sent\n"); } return; } catch(const AmSession::Exception& e){ ERROR("%i %s\n",e.code,e.reason.c_str()); relayEvent(new B2ABConnectOtherLegExceptionEvent(e.code,e.reason)); setStopped(); } catch(const string& err){ ERROR("startSession: %s\n",err.c_str()); relayEvent(new B2ABConnectOtherLegExceptionEvent(500,err)); setStopped(); } catch(...){ ERROR("unexpected exception\n"); relayEvent(new B2ABConnectOtherLegExceptionEvent(500,"unexpected exception")); setStopped(); } } AmB2ABSession::onB2ABEvent(ev); }
void AmB2BCallerSession::createCalleeSession() { AmB2BCalleeSession* callee_session = newCalleeSession(); if (NULL == callee_session) return; AmSipDialog* callee_dlg = callee_session->dlg; setOtherId(AmSession::getNewId()); callee_dlg->setLocalTag(getOtherId()); if (callee_dlg->getCallid().empty()) callee_dlg->setCallid(AmSession::getNewId()); callee_dlg->setLocalParty(dlg->getRemoteParty()); callee_dlg->setRemoteParty(dlg->getLocalParty()); callee_dlg->setRemoteUri(dlg->getLocalUri()); if (AmConfig::LogSessions) { INFO("Starting B2B callee session %s\n", callee_session->getLocalTag().c_str()); } MONITORING_LOG4(getOtherId().c_str(), "dir", "out", "from", callee_dlg->getLocalParty().c_str(), "to", callee_dlg->getRemoteParty().c_str(), "ruri", callee_dlg->getRemoteUri().c_str()); try { initializeRTPRelay(callee_session); } catch (...) { delete callee_session; throw; } AmSessionContainer* sess_cont = AmSessionContainer::instance(); sess_cont->addSession(getOtherId(),callee_session); callee_session->start(); }
void AmSessionContainer::startSessionUAS(AmSipRequest& req) { try { // Call-ID and From-Tag are unknown: it's a new session auto_ptr<AmSession> session; string app_name; session.reset(createSession(req,app_name)); if(session.get() != 0){ // update session's local tag (ID) if not already set session->setLocalTag(); const string& local_tag = session->getLocalTag(); // by default each session is in its own callgroup session->setCallgroup(local_tag); if (AmConfig::LogSessions) { INFO("Starting UAS session %s\n", local_tag.c_str()); } switch(addSession(req.callid,req.from_tag,local_tag, req.via_branch,session.get())) { case AmSessionContainer::Inserted: // successful case break; case AmSessionContainer::ShutDown: throw AmSession::Exception(AmConfig::ShutdownModeErrCode, AmConfig::ShutdownModeErrReason); case AmSessionContainer::AlreadyExist: throw AmSession::Exception(482, SIP_REPLY_LOOP_DETECTED); default: ERROR("adding session to session container\n"); throw string(SIP_REPLY_SERVER_INTERNAL_ERROR); } MONITORING_LOG4(local_tag.c_str(), "dir", "in", "from", req.from.c_str(), "to", req.to.c_str(), "ruri", req.r_uri.c_str()); try { session->start(); } catch (...) { AmEventDispatcher::instance()-> delEventQueue(local_tag); throw; } session->postEvent(new AmSipRequestEvent(req)); session.release(); } } catch(const AmSession::Exception& e){ ERROR("%i %s %s\n",e.code,e.reason.c_str(), e.hdrs.c_str()); AmSipDialog::reply_error(req,e.code,e.reason, e.hdrs); } catch(const string& err){ ERROR("startSession: %s\n",err.c_str()); AmSipDialog::reply_error(req,500,err); } catch(...){ ERROR("unexpected exception\n"); AmSipDialog::reply_error(req,500,"unexpected exception"); } }