From d09611c984eceda458095fb48462a79c771d3b59 Mon Sep 17 00:00:00 2001 From: Stefan Sayer Date: Sun, 12 Aug 2007 12:14:49 +0000 Subject: [PATCH] enables IVR in b2bua to set the From in the callee leg git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@423 8eb893ce-cfd4-0310-b710-fb5ebe64c474 --- apps/ivr/Ivr.cpp | 42 ++++++++++++++++++++++++++++++++++++++ apps/ivr/Ivr.h | 8 ++++++++ apps/ivr/IvrDialogBase.cpp | 12 +++++++---- doc/Readme.ivr | 23 ++++++++++++++++++--- 4 files changed, 78 insertions(+), 7 deletions(-) diff --git a/apps/ivr/Ivr.cpp b/apps/ivr/Ivr.cpp index d4468195..c32c2b02 100644 --- a/apps/ivr/Ivr.cpp +++ b/apps/ivr/Ivr.cpp @@ -28,6 +28,8 @@ #include "IvrUAC.h" #include "Ivr.h" +#include "AmSessionContainer.h" + #include "AmConfigReader.h" #include "AmConfig.h" #include "log.h" @@ -760,3 +762,43 @@ void IvrDialog::process(AmEvent* event) return; } + +void IvrDialog::connectCallee(const string& remote_party, const string& remote_uri, + const string& from_party, const string& from_uri) { + b2b_callee_from_party = from_party; + b2b_callee_from_uri = from_uri; + AmB2BCallerSession::connectCallee(remote_party, remote_uri); +} + +void IvrDialog::createCalleeSession() +{ + AmB2BCalleeSession* callee_session = new AmB2BCalleeSession(this); + AmSipDialog& callee_dlg = callee_session->dlg; + + other_id = AmSession::getNewId(); + + callee_dlg.local_tag = other_id; + callee_dlg.callid = AmSession::getNewId() + "@" + AmConfig::LocalIP; + + // this will be overwritten by ConnectLeg event + callee_dlg.remote_party = dlg.local_party; + callee_dlg.remote_uri = dlg.local_uri; + + if (b2b_callee_from_party.empty() && b2b_callee_from_uri.empty()) { + // default: use the original To as From in the callee leg + callee_dlg.local_party = dlg.remote_party; + callee_dlg.local_uri = dlg.remote_uri; + } else { + // if given as parameters, use these + callee_dlg.local_party = b2b_callee_from_party; + callee_dlg.local_uri = b2b_callee_from_uri; + } + + DBG("Created B2BUA callee leg, From: %s\n", + callee_dlg.local_party.c_str()); + + callee_session->start(); + + AmSessionContainer* sess_cont = AmSessionContainer::instance(); + sess_cont->addSession(other_id,callee_session); +} diff --git a/apps/ivr/Ivr.h b/apps/ivr/Ivr.h index 60739908..918fa160 100644 --- a/apps/ivr/Ivr.h +++ b/apps/ivr/Ivr.h @@ -122,6 +122,10 @@ class IvrDialog : public AmB2BCallerSession void process(AmEvent* event); + string b2b_callee_from_party; + string b2b_callee_from_uri; + + void createCalleeSession(); public: AmDynInvoke* user_timer; AmPlaylist playlist; @@ -146,6 +150,10 @@ public: void onSipRequest(const AmSipRequest& r); void onRtpTimeout(); + + void connectCallee(const string& remote_party, const string& remote_uri, + const string& from_party, const string& from_uri); + }; #endif diff --git a/apps/ivr/IvrDialogBase.cpp b/apps/ivr/IvrDialogBase.cpp index dbb24e74..fcb30380 100644 --- a/apps/ivr/IvrDialogBase.cpp +++ b/apps/ivr/IvrDialogBase.cpp @@ -312,7 +312,7 @@ static PyObject* IvrDialogBase_b2b_connectCallee(IvrDialogBase* self, PyObject* { assert(self->p_dlg); - string remote_party, remote_uri; + string remote_party, remote_uri, local_party, local_uri; PyObject* py_o; @@ -322,16 +322,20 @@ static PyObject* IvrDialogBase_b2b_connectCallee(IvrDialogBase* self, PyObject* remote_uri = self->p_dlg->getOriginalRequest().r_uri; } else { DBG("args != Py_None\n"); - char* rp = 0; char* ru = 0; - if(!PyArg_ParseTuple(args,"ss",&rp, &ru)) + char* rp = 0; char* ru = 0; char* lp = 0; char* lu = 0; + if(!PyArg_ParseTuple(args,"ss|ss",&rp, &ru, &lp, &lu)) return NULL; else { remote_party = string(rp); remote_uri = string(ru); + if (lp && lu) { + local_party = string(lp); + local_uri = string(lu); + } } } - self->p_dlg->connectCallee(remote_party, remote_uri); + self->p_dlg->connectCallee(remote_party, remote_uri, local_party, local_uri); Py_INCREF(Py_None); return Py_None; diff --git a/doc/Readme.ivr b/doc/Readme.ivr index d2c43324..84f18ccb 100644 --- a/doc/Readme.ivr +++ b/doc/Readme.ivr @@ -159,9 +159,26 @@ class IvrDialogBase: B2BMode = False # call given party as (new) callee - # if remote_party and remote_uri are empty (None), - # we will connect to the callee of the initial caller request - def connectCallee(self,remote_party,remote_uri): + # local_party and local_uri are optional: + # if not present, the From of caller leg will be used + # for the From of the callee leg. + # Another options is connectCallee(None), then the callee + # of the initial caller request is connected + # + # remote_party and local_party will be used as To/From headers. + # remote_uri and local_uri is only provided for the application. + # + # Examples: + # self.connectCallee(None) + # # connect To of caller leg with From of caller leg + # + # self.connectCallee('', 'sip:conference@serverip') + # # connect conference@serverip with From of caller leg + # + # self.connectCallee('', 'sip:otheruser@domain',\ + # 'FunkyApp ', 'sip:funkyapp@domain') + # # connect otheruser@domain from funkyapp. + def connectCallee(self,remote_party,remote_uri,local_party,local_uri): pass # terminate the callee's call