Browse code

dsm:mod_dlg: dlg.relayError to send reply in B2B leg

Stefan Sayer authored on 10/11/2013 18:27:02
Showing 3 changed files
... ...
@@ -56,6 +56,7 @@ MOD_ACTIONEXPORT_BEGIN(MOD_CLS_NAME) {
56 56
   DEF_CMD("dlg.getRtpRelayMode", DLGGetRtpRelayModeAction)
57 57
 
58 58
   DEF_CMD("dlg.refer", DLGReferAction);
59
+  DEF_CMD("dlg.relayError", DLGB2BRelayErrorAction);
59 60
 
60 61
 } MOD_ACTIONEXPORT_END;
61 62
 
... ...
@@ -459,7 +460,6 @@ EXEC_ACTION_START(DLGGetRtpRelayModeAction) {
459 460
   DBG("get RTP relay mode: %s='%s'\n", varname.c_str(), sc_sess->var[varname].c_str());
460 461
 } EXEC_ACTION_END;
461 462
 
462
-
463 463
 CONST_ACTION_2P(DLGReferAction, ',', true);
464 464
 EXEC_ACTION_START(DLGReferAction) {
465 465
 
... ...
@@ -492,3 +492,35 @@ EXEC_ACTION_START(DLGReferAction) {
492 492
     sc_sess->CLR_ERRNO;
493 493
   }
494 494
 } EXEC_ACTION_END;
495
+
496
+
497
+#define GET_B2B_SESSION(action)						\
498
+  AmB2BSession* b2b_sess = dynamic_cast<AmB2BSession*>(sess);		\
499
+  if (NULL == b2b_sess) {						\
500
+    throw DSMException("sbc", "type", "param", "cause",			\
501
+		       #action " used on non-b2b-session");		\
502
+  }
503
+
504
+CONST_ACTION_2P(DLGB2BRelayErrorAction, ',', false);
505
+EXEC_ACTION_START(DLGB2BRelayErrorAction) {
506
+  DSMSipRequest* sip_req;
507
+
508
+  AVarMapT::iterator it = sc_sess->avar.find(DSM_AVAR_REQUEST);
509
+  if (it == sc_sess->avar.end() ||
510
+      !isArgAObject(it->second) || 
511
+      !(sip_req = dynamic_cast<DSMSipRequest*>(it->second.asObject()))) {
512
+    throw DSMException("dlg", "cause", "no request");
513
+  }
514
+  GET_B2B_SESSION(dlg.refer);
515
+
516
+  string code = resolveVars(par1, sess, sc_sess, event_params);
517
+  string reason = resolveVars(par2, sess, sc_sess, event_params);
518
+  unsigned int code_i;
519
+  if (str2i(code, code_i)) {
520
+    ERROR("decoding reply code '%s'\n", code.c_str());
521
+    sc_sess->SET_ERRNO(DSM_ERRNO_UNKNOWN_ARG);
522
+    EXEC_ACTION_STOP;
523
+  }
524
+
525
+  b2b_sess->relayError(sip_req->req->method, sip_req->req->cseq, true, code_i, reason.c_str());
526
+} EXEC_ACTION_END;
... ...
@@ -52,5 +52,5 @@ DEF_ACTION_1P(DLGGetOtherIdAction);
52 52
 DEF_ACTION_1P(DLGGetRtpRelayModeAction);
53 53
 
54 54
 DEF_ACTION_2P(DLGReferAction);
55
-
55
+DEF_ACTION_2P(DLGB2BRelayErrorAction);
56 56
 #endif
... ...
@@ -79,6 +79,11 @@ dlg.getRtpRelayMode(varname)
79 79
 dlg.refer(string refer_to [, int expires=0])
80 80
    refer to refer_to, optionally with expires
81 81
 
82
+dlg.relayError(code,reason);  -  relay reply (>=200) to B2B request (sbc)
83
+  reply to B2B request (in avar[DSM_AVAR_REQUEST]) with code and reason
84
+  sbc: set(#StopProcessing="true") to prevent B2B request to be relayed
85
+       after replying from DSM script
86
+
82 87
 Request/Reply Body handling in sipRequest/sipReply events:
83 88
 ----------------------------------------------------------
84 89
 actions (applicable only in sipRequest/sipReply event handling blocks):