void AmSession::onSipReply(const AmSipReply& reply) { CALL_EVENT_H(onSipReply,reply); int status = dlg.getStatus(); dlg.updateStatus(reply); if (status != dlg.getStatus()) DBG("Dialog status changed %s -> %s (stopped=%s) \n", AmSipDialog::status2str[status], AmSipDialog::status2str[dlg.getStatus()], sess_stopped.get() ? "true" : "false"); else DBG("Dialog status stays %s (stopped=%s)\n", AmSipDialog::status2str[status], sess_stopped.get() ? "true" : "false"); if (negotiate_onreply) { if(status < AmSipDialog::Connected){ switch(dlg.getStatus()){ case AmSipDialog::Connected: try { acceptAudio(reply.body,reply.hdrs); if(detached.get() && !getStopped()){ onSessionStart(reply); if(input || output) AmMediaProcessor::instance()->addSession(this, callgroup); else { ERROR("missing audio input and/or ouput.\n"); } } }catch(const AmSession::Exception& e){ ERROR("could not connect audio!!!\n"); ERROR("%i %s\n",e.code,e.reason.c_str()); dlg.bye(); setStopped(); break; } break; case AmSipDialog::Pending: switch(reply.code){ case 180: break;//TODO: local ring tone. case 183: break;//TODO: remote ring tone. default: break;// continue waiting. } } } } }
void Click2TransSession::onSipReply(const AmSipReply& reply, int old_dlg_status, const string& trans_method) { DBG("sip reply: code=%i; reason=%s; status=%i", reply.code, reply.reason.c_str(), dlg.getStatus()); if(dialog->isOutgoing() || dialog->isTransferring()) { DBG("sip reply for outgoing invite"); switch(dlg.getStatus()) { case AmSipDialog::Connected: { DBG("connected: connecting audio"); acceptAudio(reply.body, reply.hdrs); //bridge media Click2TransSession* otherLeg = dialog->getOtherLeg(this); AmMediaProcessor::instance()->removeSession(otherLeg); dialog->connectSession(this); dialog->connectSession(otherLeg); AmMediaProcessor::instance()->addSession(this, callgroup); AmMediaProcessor::instance()->addSession(otherLeg, callgroup); if(dialog->isTransferring()) { //sunny day transfer complete dialog->outgoing(); DBG("sending bye to tranferer"); Click2TransSession* t = dialog->removeTransferer(); t->dlg.bye(); DBG("setting tranferer to stopped"); t->setStopped(); } break; } default: { DBG("TODO not implemented");//nothing to do } } } else if(dialog->isTerminated()) { DBG("setting session to stopped"); setStopped(); } else { DBG("TODO expected isOutgoing() to be true");//never called } AmSession::onSipReply(reply, old_dlg_status, trans_method); }
void AmSession::onInvite(const AmSipRequest& req) { try { string sdp_reply; acceptAudio(req.body,req.hdrs,&sdp_reply); if(dlg.reply(req,200,"OK", "application/sdp",sdp_reply) != 0) throw AmSession::Exception(500,"could not send response"); }catch(const AmSession::Exception& e){ ERROR("%i %s\n",e.code,e.reason.c_str()); setStopped(); AmSipDialog::reply_error(req,e.code,e.reason); } }
void GWSession::onSessionStart(const AmSipRequest& req) { DBG("GWSession::onSessionStart\n"); try { string sdp_reply; acceptAudio(req.body,req.hdrs,&sdp_reply); if(dlg.reply(req,200,"OK Isdn side state is: CONNECTED", "application/sdp",sdp_reply) != 0) throw AmSession::Exception(500,"could not send response"); }catch(const AmSession::Exception& e){ ERROR("%i %s\n",e.code,e.reason.c_str()); setStopped(); dlg.reply(req,e.code,e.reason); return; } DBG("GWSession::onSessionStart Setting Audio\n"); setInOut((AmAudio *)(m_OtherLeg),(AmAudio *)(m_OtherLeg)); AmSession::onSessionStart(req); AmMediaProcessor::instance()->addSession(this, callgroup); }
void Click2TransSession::onSessionStart(const AmSipRequest& req) { if(dialog->isIncoming()) { DBG("incoming session"); try { std::string sdp_reply; acceptAudio(req.body,req.hdrs,&sdp_reply); if(dlg.reply(req, 200,"OK INVITER IS CONNECTED", "application/sdp", sdp_reply) != 0) { throw AmSession::Exception(500,"could not send response"); } } catch(const AmSession::Exception& e) { ERROR("%i %s\n",e.code,e.reason.c_str()); setStopped(); dlg.reply(req,e.code,e.reason); return; } DBG("playing ringtone to inviter"); setInOut(NULL,ringTone.get()); AmSession::onSessionStart(req); AmMediaProcessor::instance()->addSession(this, callgroup); postEvent(new DialoutEvent(DoConnect));//TODO cleanup this allocation? } else if(dialog->isOutgoing()) { DBG("outgoing session"); //nothing to do } }
void EarlyAnnounceDialog::onInvite(const AmSipRequest& req) { try { string sdp_reply; acceptAudio(req.body,req.hdrs,&sdp_reply); if(dlg.reply(req,183,"Session Progress", "application/sdp",sdp_reply) != 0){ throw AmSession::Exception(500,"could not reply"); } else { invite_req = req; } } catch(const AmSession::Exception& e) { ERROR("%i %s\n",e.code,e.reason.c_str()); setStopped(); AmSipDialog::reply_error(req,e.code,e.reason); } }
void ConferenceDialog::onSipReply(const AmSipReply& reply) { int status = dlg.getStatus(); AmSession::onSipReply(reply); DBG("ConferenceDialog::onSipReply: code = %i, reason = %s\n, status = %i\n", reply.code,reply.reason.c_str(),dlg.getStatus()); if(!dialedout && !transfer_req.get()) return; if(status < AmSipDialog::Connected){ switch(dlg.getStatus()){ case AmSipDialog::Connected: // connected! try { acceptAudio(reply.body,reply.hdrs); if(getDetached() && !getStopped()){ setupAudio(); if(getInput() || getOutput()) AmMediaProcessor::instance()->addSession(this, getCallgroup()); else { ERROR("missing audio input and/or ouput.\n"); return; } if(!transfer_req.get()){ // send connect event AmSessionContainer::instance() ->postEvent(dialout_channel->getConfID(), new DialoutConfEvent(DoConfConnect, dialout_channel->getConfID())); } else { dlg.reply(*(transfer_req.get()),202,"Accepted"); transfer_req.reset(0); connectMainChannel(); } } } catch(const AmSession::Exception& e){ ERROR("%i %s\n",e.code,e.reason.c_str()); dlg.bye(); setStopped(); } break; case AmSipDialog::Pending: switch(reply.code){ case 180: // send ringing event AmSessionContainer::instance() ->postEvent(dialout_channel->getConfID(), new DialoutConfEvent(DoConfRinging, dialout_channel->getConfID())); break; case 183: break;//TODO: remote ring tone. default: break;// continue waiting. } break; case AmSipDialog::Disconnected: if(!transfer_req.get()){ disconnectDialout(); //switch(reply.code){ //default: AmSessionContainer::instance() ->postEvent(dialout_channel->getConfID(), new DialoutConfEvent(DoConfError, dialout_channel->getConfID())); //} } else { dlg.reply(*(transfer_req.get()),reply.code,reply.reason); transfer_req.reset(0); setStopped(); } break; default: break; } } }