Browse code

sbc:dsm: dlg.addReplyBodyPart to modify reply in B2B call

based on code by Juha Heinanen

Stefan Sayer authored on 11/03/2014 16:25:46
Showing 4 changed files
... ...
@@ -207,6 +207,16 @@ class DSMSipRequest
207 207
   ~DSMSipRequest() { }
208 208
 };
209 209
 
210
+class DSMMutableSipRequest
211
+: public DSMSipRequest {
212
+ public:
213
+  AmSipRequest* mutable_req;
214
+
215
+  DSMMutableSipRequest(AmSipRequest* req)
216
+    : DSMSipRequest(req), mutable_req(req) { }
217
+  ~DSMMutableSipRequest() { }
218
+};
219
+
210 220
 class DSMSipReply
211 221
 : public AmObject {
212 222
  public: 
... ...
@@ -217,6 +227,15 @@ class DSMSipReply
217 227
   ~DSMSipReply() { }
218 228
 };
219 229
 
230
+class DSMMutableSipReply
231
+: public DSMSipReply {
232
+ public:
233
+  AmSipReply* mutable_reply;
234
+
235
+  DSMMutableSipReply(AmSipReply* reply)
236
+    : DSMSipReply(reply), mutable_reply(reply) { }
237
+  ~DSMMutableSipReply() { }
238
+};
220 239
 
221 240
 #define DSM_EVENT_ID -10
222 241
 /**  generic event for passing events between DSM sessions */
... ...
@@ -58,6 +58,8 @@ MOD_ACTIONEXPORT_BEGIN(MOD_CLS_NAME) {
58 58
   DEF_CMD("dlg.refer", DLGReferAction);
59 59
   DEF_CMD("dlg.relayError", DLGB2BRelayErrorAction);
60 60
 
61
+  DEF_CMD("dlg.addReplyBodyPart", DLGAddReplyBodyPartAction);
62
+
61 63
 } MOD_ACTIONEXPORT_END;
62 64
 
63 65
 //MOD_CONDITIONEXPORT_NONE(MOD_CLS_NAME);
... ...
@@ -524,3 +526,26 @@ EXEC_ACTION_START(DLGB2BRelayErrorAction) {
524 526
 
525 527
   b2b_sess->relayError(sip_req->req->method, sip_req->req->cseq, true, code_i, reason.c_str());
526 528
 } EXEC_ACTION_END;
529
+
530
+CONST_ACTION_2P(DLGAddReplyBodyPartAction, ',', false);
531
+EXEC_ACTION_START(DLGAddReplyBodyPartAction) {
532
+  DSMMutableSipReply* sip_reply;
533
+
534
+  AVarMapT::iterator it = sc_sess->avar.find(DSM_AVAR_REPLY);
535
+  if (it == sc_sess->avar.end() ||
536
+      !isArgAObject(it->second) ||
537
+      !(sip_reply = dynamic_cast<DSMMutableSipReply*>(it->second.asObject()))) {
538
+    throw DSMException("dlg", "cause", "no reply");
539
+  }
540
+
541
+  string content_type = resolveVars(par1, sess, sc_sess, event_params);
542
+  string body_part = resolveVars(par2, sess, sc_sess, event_params);
543
+
544
+  AmMimeBody* new_part;
545
+
546
+  new_part = sip_reply->mutable_reply->body.addPart(content_type);
547
+  new_part->setPayload((const unsigned char*)body_part.c_str(),
548
+		       body_part.length());
549
+  DBG("added to reply body part %s='%s'\n",
550
+      content_type.c_str(), body_part.c_str());
551
+} EXEC_ACTION_END;
... ...
@@ -53,4 +53,6 @@ DEF_ACTION_1P(DLGGetRtpRelayModeAction);
53 53
 
54 54
 DEF_ACTION_2P(DLGReferAction);
55 55
 DEF_ACTION_2P(DLGB2BRelayErrorAction);
56
+
57
+DEF_ACTION_2P(DLGAddReplyBodyPartAction);
56 58
 #endif
... ...
@@ -304,7 +304,7 @@ CCChainProcessing SBCDSMInstance::onEvent(SBCCallLeg* call, AmEvent* event) {
304 304
     B2BSipRequestEvent* b2b_req_ev = dynamic_cast<B2BSipRequestEvent*>(b2b_ev);
305 305
     if (b2b_req_ev) {
306 306
       VarMapT event_params;
307
-      DSMSipRequest sip_req(&b2b_req_ev->req);
307
+      DSMMutableSipRequest sip_req(&b2b_req_ev->req);
308 308
       extractRequestParameters(event_params, avar, &sip_req);
309 309
       event_params["forward"] = b2b_req_ev->forward?"true":"false";
310 310
       engine.runEvent(call, this, DSMCondition::B2BOtherRequest, &event_params);
... ...
@@ -315,7 +315,7 @@ CCChainProcessing SBCDSMInstance::onEvent(SBCCallLeg* call, AmEvent* event) {
315 315
       B2BSipReplyEvent* b2b_reply_ev = dynamic_cast<B2BSipReplyEvent*>(b2b_ev);
316 316
       if (b2b_reply_ev) {
317 317
 	VarMapT event_params;
318
-	DSMSipReply dsm_reply(&b2b_reply_ev->reply);
318
+	DSMMutableSipReply dsm_reply(&b2b_reply_ev->reply);
319 319
 	extractReplyParameters(event_params, avar, &dsm_reply);
320 320
 	event_params["forward"] = b2b_reply_ev->forward?"true":"false";
321 321
 	event_params["trans_method"] = b2b_reply_ev->trans_method;