Browse code

apps/dsm/mods/mod_dlg: added dlg.info action

Juha Heinanen authored on 08/05/2014 18:35:47
Showing 2 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.info", DLGInfoAction);
59 60
   DEF_CMD("dlg.relayError", DLGB2BRelayErrorAction);
60 61
 
61 62
   DEF_CMD("dlg.addReplyBodyPart", DLGAddReplyBodyPartAction);
... ...
@@ -496,6 +497,50 @@ EXEC_ACTION_START(DLGReferAction) {
496 497
   }
497 498
 } EXEC_ACTION_END;
498 499
 
500
+CONST_ACTION_2P(DLGInfoAction, ',', true);
501
+EXEC_ACTION_START(DLGInfoAction) {
502
+
503
+  AmSession* b2b_sess = dynamic_cast<AmSession*>(sess);
504
+  if (NULL == b2b_sess) {
505
+    throw DSMException("sbc", "type", "param", "cause",
506
+		       "dlg.info used on non-session");
507
+  }
508
+
509
+  string content_type = resolveVars(par1, sess, sc_sess, event_params);
510
+  string body_str = resolveVars(par2, sess, sc_sess, event_params);
511
+
512
+  if (NULL == b2b_sess->dlg) {
513
+    throw DSMException("sbc", "type", "param", "cause",
514
+		       "call doesn't have SIP dialog (OOPS!)");
515
+  }
516
+
517
+  string body_crlf = body_str;
518
+  AmMimeBody *body = new AmMimeBody();
519
+  if (!content_type.empty()) {
520
+    DBG("body_crlf is '%s'\n", body_crlf.c_str());
521
+    while (true) {
522
+      size_t p = body_crlf.find("\\r\\n");
523
+      if (p==string::npos)
524
+	break;
525
+      body_crlf.replace(p, 4, "\r\n");
526
+    }
527
+    DBG("-> body_crlf is '%s'\n", body_crlf.c_str());
528
+    if (body->parse(content_type,
529
+		    reinterpret_cast<const unsigned char*>(body_crlf.c_str()),
530
+		    body_crlf.length())) {
531
+      throw DSMException("sbc", "type", "param", "cause",
532
+			 "parsing of INFO body failed");
533
+    }
534
+  }
535
+
536
+  if (b2b_sess->dlg->info("", body)) {
537
+    sc_sess->SET_ERRNO(DSM_ERRNO_DLG);
538
+    sc_sess->SET_STRERROR("sending INFO failed");
539
+  } else {
540
+    sc_sess->CLR_ERRNO;
541
+  }
542
+
543
+} EXEC_ACTION_END;
499 544
 
500 545
 #define GET_B2B_SESSION(action)						\
501 546
   AmB2BSession* b2b_sess = dynamic_cast<AmB2BSession*>(sess);		\
... ...
@@ -562,8 +607,8 @@ EXEC_ACTION_START(DLGDeleteReplyBodyPartAction) {
562 607
   }
563 608
 
564 609
   if (sip_reply->mutable_reply->body.deletePart(arg)) {
565
-    INFO("failed to delete reply body part '%s'\n", arg.c_str());
610
+    DBG("failed to delete reply body part '%s'\n", arg.c_str());
566 611
   } else {
567
-    INFO("deleted reply body part '%s'\n", arg.c_str());
612
+    DBG("deleted reply body part '%s'\n", arg.c_str());
568 613
   }
569 614
 } EXEC_ACTION_END;
... ...
@@ -79,6 +79,9 @@ 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.info(content_type, body)
83
+   send INFO request; use \r\n for crlf in body
84
+
82 85
 dlg.relayError(code,reason);  -  relay reply (>=200) to B2B request (sbc)
83 86
   reply to B2B request (in avar[DSM_AVAR_REQUEST]) with code and reason
84 87
   sbc: set(#StopProcessing="true") to prevent B2B request to be relayed