Module: sems Branch: master Commit: 4f11a5e4d04e00a04afa00abf6275c0d6d55b2e0 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sems/?a=commit;h=4f11a5e4d04e00a04afa00abf6275c0d6d55b2e0
Author: Stefan Sayer <[email protected]> Committer: Stefan Sayer <[email protected]> Date: Tue Mar 11 17:25:46 2014 +0100 sbc:dsm: dlg.addReplyBodyPart to modify reply in B2B call based on code by Juha Heinanen --- apps/dsm/DSMSession.h | 19 +++++++++++++++++++ apps/dsm/mods/mod_dlg/ModDlg.cpp | 25 +++++++++++++++++++++++++ apps/dsm/mods/mod_dlg/ModDlg.h | 2 ++ apps/sbc/call_control/dsm/SBCDSMInstance.cpp | 4 ++-- 4 files changed, 48 insertions(+), 2 deletions(-) diff --git a/apps/dsm/DSMSession.h b/apps/dsm/DSMSession.h index 5315578..c33fa62 100644 --- a/apps/dsm/DSMSession.h +++ b/apps/dsm/DSMSession.h @@ -207,6 +207,16 @@ class DSMSipRequest ~DSMSipRequest() { } }; +class DSMMutableSipRequest +: public DSMSipRequest { + public: + AmSipRequest* mutable_req; + + DSMMutableSipRequest(AmSipRequest* req) + : DSMSipRequest(req), mutable_req(req) { } + ~DSMMutableSipRequest() { } +}; + class DSMSipReply : public AmObject { public: @@ -217,6 +227,15 @@ class DSMSipReply ~DSMSipReply() { } }; +class DSMMutableSipReply +: public DSMSipReply { + public: + AmSipReply* mutable_reply; + + DSMMutableSipReply(AmSipReply* reply) + : DSMSipReply(reply), mutable_reply(reply) { } + ~DSMMutableSipReply() { } +}; #define DSM_EVENT_ID -10 /** generic event for passing events between DSM sessions */ diff --git a/apps/dsm/mods/mod_dlg/ModDlg.cpp b/apps/dsm/mods/mod_dlg/ModDlg.cpp index 2e8e375..84c4e55 100644 --- a/apps/dsm/mods/mod_dlg/ModDlg.cpp +++ b/apps/dsm/mods/mod_dlg/ModDlg.cpp @@ -58,6 +58,8 @@ MOD_ACTIONEXPORT_BEGIN(MOD_CLS_NAME) { DEF_CMD("dlg.refer", DLGReferAction); DEF_CMD("dlg.relayError", DLGB2BRelayErrorAction); + DEF_CMD("dlg.addReplyBodyPart", DLGAddReplyBodyPartAction); + } MOD_ACTIONEXPORT_END; //MOD_CONDITIONEXPORT_NONE(MOD_CLS_NAME); @@ -524,3 +526,26 @@ EXEC_ACTION_START(DLGB2BRelayErrorAction) { b2b_sess->relayError(sip_req->req->method, sip_req->req->cseq, true, code_i, reason.c_str()); } EXEC_ACTION_END; + +CONST_ACTION_2P(DLGAddReplyBodyPartAction, ',', false); +EXEC_ACTION_START(DLGAddReplyBodyPartAction) { + DSMMutableSipReply* sip_reply; + + AVarMapT::iterator it = sc_sess->avar.find(DSM_AVAR_REPLY); + if (it == sc_sess->avar.end() || + !isArgAObject(it->second) || + !(sip_reply = dynamic_cast<DSMMutableSipReply*>(it->second.asObject()))) { + throw DSMException("dlg", "cause", "no reply"); + } + + string content_type = resolveVars(par1, sess, sc_sess, event_params); + string body_part = resolveVars(par2, sess, sc_sess, event_params); + + AmMimeBody* new_part; + + new_part = sip_reply->mutable_reply->body.addPart(content_type); + new_part->setPayload((const unsigned char*)body_part.c_str(), + body_part.length()); + DBG("added to reply body part %s='%s'\n", + content_type.c_str(), body_part.c_str()); +} EXEC_ACTION_END; diff --git a/apps/dsm/mods/mod_dlg/ModDlg.h b/apps/dsm/mods/mod_dlg/ModDlg.h index deccc9e..2b07afb 100644 --- a/apps/dsm/mods/mod_dlg/ModDlg.h +++ b/apps/dsm/mods/mod_dlg/ModDlg.h @@ -53,4 +53,6 @@ DEF_ACTION_1P(DLGGetRtpRelayModeAction); DEF_ACTION_2P(DLGReferAction); DEF_ACTION_2P(DLGB2BRelayErrorAction); + +DEF_ACTION_2P(DLGAddReplyBodyPartAction); #endif diff --git a/apps/sbc/call_control/dsm/SBCDSMInstance.cpp b/apps/sbc/call_control/dsm/SBCDSMInstance.cpp index 38b073f..1d54d42 100644 --- a/apps/sbc/call_control/dsm/SBCDSMInstance.cpp +++ b/apps/sbc/call_control/dsm/SBCDSMInstance.cpp @@ -304,7 +304,7 @@ CCChainProcessing SBCDSMInstance::onEvent(SBCCallLeg* call, AmEvent* event) { B2BSipRequestEvent* b2b_req_ev = dynamic_cast<B2BSipRequestEvent*>(b2b_ev); if (b2b_req_ev) { VarMapT event_params; - DSMSipRequest sip_req(&b2b_req_ev->req); + DSMMutableSipRequest sip_req(&b2b_req_ev->req); extractRequestParameters(event_params, avar, &sip_req); event_params["forward"] = b2b_req_ev->forward?"true":"false"; engine.runEvent(call, this, DSMCondition::B2BOtherRequest, &event_params); @@ -315,7 +315,7 @@ CCChainProcessing SBCDSMInstance::onEvent(SBCCallLeg* call, AmEvent* event) { B2BSipReplyEvent* b2b_reply_ev = dynamic_cast<B2BSipReplyEvent*>(b2b_ev); if (b2b_reply_ev) { VarMapT event_params; - DSMSipReply dsm_reply(&b2b_reply_ev->reply); + DSMMutableSipReply dsm_reply(&b2b_reply_ev->reply); extractReplyParameters(event_params, avar, &dsm_reply); event_params["forward"] = b2b_reply_ev->forward?"true":"false"; event_params["trans_method"] = b2b_reply_ev->trans_method; _______________________________________________ Semsdev mailing list [email protected] http://lists.iptel.org/mailman/listinfo/semsdev
