Module: sems
Branch: master
Commit: f6baef3cf1dce19060d49b03bda8be0f37cf838a
URL:    
http://git.sip-router.org/cgi-bin/gitweb.cgi/sems/?a=commit;h=f6baef3cf1dce19060d49b03bda8be0f37cf838a

Author: Stefan Sayer <[email protected]>
Committer: Raphael Coeffic <[email protected]>
Date:   Fri Feb 17 14:22:31 2012 +0100

multi-mime: dsm: mod_dlg: actions/conditions for explicit body handling 
(sipRequest/sipReply)

---

 apps/dsm/DSMCall.cpp             |    7 ---
 apps/dsm/mods/mod_dlg/ModDlg.cpp |  106 +++++++++++++++++++++++++++++++++++++-
 apps/dsm/mods/mod_dlg/ModDlg.h   |    5 ++
 doc/dsm/mods/Readme.mod_dlg.txt  |   21 +++++++-
 4 files changed, 130 insertions(+), 9 deletions(-)

diff --git a/apps/dsm/DSMCall.cpp b/apps/dsm/DSMCall.cpp
index ce86ab5..869e924 100644
--- a/apps/dsm/DSMCall.cpp
+++ b/apps/dsm/DSMCall.cpp
@@ -273,13 +273,6 @@ void DSMCall::onSipRequest(const AmSipRequest& req) {
     params["from"] = req.from;
     params["to"] = req.to;
     params["hdrs"] = req.hdrs;
-
-    //TODO: find some sort of solution for this one....
-    //      Stefan? any clue?????
-    //
-    //params["content_type"] = req.content_type;
-    //params["body"] = req.body;
-
     params["cseq"] = int2str(req.cseq);
 
     // pass AmSipRequest for use by mod_dlg
diff --git a/apps/dsm/mods/mod_dlg/ModDlg.cpp b/apps/dsm/mods/mod_dlg/ModDlg.cpp
index d51648a..e6ec87e 100644
--- a/apps/dsm/mods/mod_dlg/ModDlg.cpp
+++ b/apps/dsm/mods/mod_dlg/ModDlg.cpp
@@ -49,9 +49,21 @@ MOD_ACTIONEXPORT_BEGIN(MOD_CLS_NAME) {
   DEF_CMD("dlg.connectCalleeRelayed", DLGConnectCalleeRelayedAction);
   DEF_CMD("dlg.dialout", DLGDialoutAction);
 
+  DEF_CMD("dlg.getRequestBody", DLGGetRequestBodyAction)
+  DEF_CMD("dlg.getReplyBody", DLGGetReplyBodyAction)
 } MOD_ACTIONEXPORT_END;
 
-MOD_CONDITIONEXPORT_NONE(MOD_CLS_NAME);
+//MOD_CONDITIONEXPORT_NONE(MOD_CLS_NAME);
+
+
+MOD_CONDITIONEXPORT_BEGIN(MOD_CLS_NAME) {
+  if (cmd == "dlg.replyHasContentType")
+    return new DLGReplyHasContentTypeCondition(params, false);
+
+  if (cmd == "dlg.requestHasContentType")
+    return new DLGRequestHasContentTypeCondition(params, false);
+
+} MOD_CONDITIONEXPORT_END;
 
 bool DLGModule::onInvite(const AmSipRequest& req, DSMSession* sess) {
   // save inivital invite to last_req 
@@ -290,3 +302,95 @@ EXEC_ACTION_START(DLGDialoutAction) {
   }
 
 } EXEC_ACTION_END;
+
+MATCH_CONDITION_START(DLGReplyHasContentTypeCondition) {
+  AVarMapT::iterator it = sc_sess->avar.find(DSM_AVAR_REPLY);
+  if (it == sc_sess->avar.end()) {
+    ERROR("DSM script error: dlg.replyHasContentType condition used for "
+         "other event than sipReply event\n");
+    return false;
+  }
+
+  DSMSipReply* dsm_reply = NULL;
+  if (!isArgAObject(sc_sess->avar[DSM_AVAR_REPLY]) ||
+      (NULL ==
+       (dsm_reply = 
dynamic_cast<DSMSipReply*>(sc_sess->avar[DSM_AVAR_REPLY].asObject())))) {
+    ERROR("internal: DSM could not get DSMSipReply\n");
+    return false;
+  }
+
+  bool res = dsm_reply->reply->body.hasContentType(arg);
+
+  DBG("checking for content_type '%s': %s\n", arg.c_str(), res?"has 
it":"doesn't have it");
+  return res;
+} MATCH_CONDITION_END;
+
+MATCH_CONDITION_START(DLGRequestHasContentTypeCondition) {
+  AVarMapT::iterator it = sc_sess->avar.find(DSM_AVAR_REQUEST);
+  if (it == sc_sess->avar.end()) {
+    ERROR("DSM script error: dlg.requestHasContentType condition used for "
+         "other event than sipRequest event\n");
+    return false;
+  }
+
+  DSMSipRequest* dsm_req = NULL;
+  if (!isArgAObject(sc_sess->avar[DSM_AVAR_REQUEST]) ||
+      (NULL ==
+       (dsm_req = 
dynamic_cast<DSMSipRequest*>(sc_sess->avar[DSM_AVAR_REQUEST].asObject())))) {
+    ERROR("internal: DSM could not get DSMSipRequest\n");
+    return false;
+  }
+
+  bool res = dsm_req->req->body.hasContentType(arg);
+
+  DBG("checking for content_type '%s': %s\n", arg.c_str(), res?"has 
it":"doesn't have it");
+  return res;
+} MATCH_CONDITION_END;
+
+CONST_ACTION_2P(DLGGetRequestBodyAction, ',', false);
+EXEC_ACTION_START(DLGGetRequestBodyAction) {
+  DSMSipRequest* sip_req;
+
+  AVarMapT::iterator it = sc_sess->avar.find(DSM_AVAR_REQUEST);
+  if (it == sc_sess->avar.end() ||
+      !isArgAObject(it->second) ||
+      !(sip_req = dynamic_cast<DSMSipRequest*>(it->second.asObject()))) {
+    throw DSMException("dlg", "cause", "no request");
+  }
+
+  string content_type = resolveVars(par1, sess, sc_sess, event_params);
+  string dstvar = resolveVars(par2, sess, sc_sess, event_params);
+
+  const AmMimeBody* msg_body = sip_req->req->body.hasContentType(content_type);
+  if (NULL == msg_body) {
+    DBG("body with content_type %s not found\n", content_type.c_str());
+    sc_sess->var.erase(dstvar);
+  } else {
+    sc_sess->var[dstvar] = string((const char*)msg_body->getPayload());
+    DBG("set $%s='%s'\n", dstvar.c_str(), sc_sess->var[dstvar].c_str());
+  }
+} EXEC_ACTION_END;
+
+CONST_ACTION_2P(DLGGetReplyBodyAction, ',', false);
+EXEC_ACTION_START(DLGGetReplyBodyAction) {
+  DSMSipReply* sip_req;
+
+  AVarMapT::iterator it = sc_sess->avar.find(DSM_AVAR_REPLY);
+  if (it == sc_sess->avar.end() ||
+      !isArgAObject(it->second) ||
+      !(sip_req = dynamic_cast<DSMSipReply*>(it->second.asObject()))) {
+    throw DSMException("dlg", "cause", "no reply");
+  }
+
+  string content_type = resolveVars(par1, sess, sc_sess, event_params);
+  string dstvar = resolveVars(par2, sess, sc_sess, event_params);
+
+  const AmMimeBody* msg_body = 
sip_req->reply->body.hasContentType(content_type);
+  if (NULL == msg_body) {
+    DBG("body with content_type %s not found\n", content_type.c_str());
+    sc_sess->var.erase(dstvar);
+  } else {
+    sc_sess->var[dstvar] = string((const char*)msg_body->getPayload());
+    DBG("set $%s='%s'\n", dstvar.c_str(), sc_sess->var[dstvar].c_str());
+  }
+} EXEC_ACTION_END;
diff --git a/apps/dsm/mods/mod_dlg/ModDlg.h b/apps/dsm/mods/mod_dlg/ModDlg.h
index 978288b..9a8a06c 100644
--- a/apps/dsm/mods/mod_dlg/ModDlg.h
+++ b/apps/dsm/mods/mod_dlg/ModDlg.h
@@ -40,4 +40,9 @@ DEF_ACTION_2P(DLGAcceptInviteAction);
 DEF_ACTION_2P(DLGConnectCalleeRelayedAction);
 DEF_ACTION_1P(DLGByeAction);
 DEF_ACTION_1P(DLGDialoutAction);
+
+DEF_SCCondition(DLGReplyHasContentTypeCondition);
+DEF_SCCondition(DLGRequestHasContentTypeCondition);
+DEF_ACTION_2P(DLGGetRequestBodyAction);
+DEF_ACTION_2P(DLGGetReplyBodyAction);
 #endif
diff --git a/doc/dsm/mods/Readme.mod_dlg.txt b/doc/dsm/mods/Readme.mod_dlg.txt
index 3c12ff3..d5d865a 100644
--- a/doc/dsm/mods/Readme.mod_dlg.txt
+++ b/doc/dsm/mods/Readme.mod_dlg.txt
@@ -3,7 +3,12 @@
 * set connect_session to 0 with set(connect_session=0)
   if you want to reply with other than the standard 200 OK 
   to initial INVITE received.
-* for processing of other requests, use enable_request_events and replyRequest
+* for processing of other requests, use set($enable_request_events="true") and 
replyRequest
+* for processing of other requests, use set($enable_reply_events="true") and 
replyRequest
+
+* Request/Reply body handling with 
+ dlg.requestHasContentType condition and dlg.getRequestBody action
+ dlg.replyHasContentType condition and dlg.getReplyBody action
 
 dlg.reply(code,reason);
  reply to the request in DSMSession::last_req 
@@ -56,6 +61,20 @@ dlg.dialout(string arrayname)
 
   returns $arrayname_ltag (if successful) and sets ERRNO.
    
+Request/Reply Body handling in sipRequest/sipReply events:
+
+actions (applicable only in sipRequest/sipReply event handling blocks):
+dlg.getRequestBody(content_type, dstvar)  - get body of content_type in $dstvar
+dlg.getReplyBody(content_type, dstvar)    - get body of content_type in $dstvar
+
+conditions: 
+  dlg.replyHasContentType(content_type) and 
dlg.requestHasContentType(content_type)
 
+  checks whether request/reply has a certain content type
 
+ example: 
 
+transition "msg recvd" A - sipRequest; 
dlg.requestHasContentType(application/ISUP) / {
+  dlg.getRequestBody(application/ISUP, isup_body);
+  ... do sth with $isup_body ...
+} -> B;

_______________________________________________
Semsdev mailing list
[email protected]
http://lists.iptel.org/mailman/listinfo/semsdev

Reply via email to