Browse code

dsm:mod_zrtp for simple ZRTP support

Stefan Sayer authored on 03/11/2014 16:48:12
Showing 9 changed files
... ...
@@ -449,6 +449,32 @@ void DSMCall::onBeforeDestroy() {
449 449
   engine.onBeforeDestroy(this, this);
450 450
 }
451 451
 
452
+#ifdef WITH_ZRTP
453
+void DSMCall::onZRTPProtocolEvent(zrtp_protocol_event_t event, zrtp_stream_t *stream_ctx) {
454
+  DBG("DSMCall::onZRTPProtocolEvent: %s\n", zrtp_protocol_event_desc(event));
455
+
456
+  if (checkVar(DSM_ENABLE_ZRTP_EVENTS, DSM_TRUE)) {
457
+    map<string, string> params;
458
+    params["event"] = zrtp_protocol_event_desc(event);
459
+    params["event_id"] = int2str(event);
460
+    engine.runEvent(this, this, DSMCondition::ZRTPProtocolEvent, &params);
461
+  }
462
+
463
+}
464
+
465
+void DSMCall::onZRTPSecurityEvent(zrtp_security_event_t event, zrtp_stream_t *stream_ctx) {
466
+  DBG("DSMCall::onZRTPSecurityEvent: %s\n", zrtp_security_event_desc(event));
467
+
468
+  if (checkVar(DSM_ENABLE_ZRTP_EVENTS, DSM_TRUE)) {
469
+    map<string, string> params;
470
+    params["event"] = zrtp_security_event_desc(event);
471
+    params["event_id"] = int2str(event);
472
+    engine.runEvent(this, this, DSMCondition::ZRTPSecurityEvent, &params);
473
+  }
474
+
475
+}
476
+#endif
477
+
452 478
 void DSMCall::process(AmEvent* event)
453 479
 {
454 480
 
... ...
@@ -98,10 +98,15 @@ public:
98 98
   bool getSdpOffer(AmSdp& offer);
99 99
   bool getSdpAnswer(const AmSdp& offer, AmSdp& answer);
100 100
 
101
-  virtual void onNoAck(unsigned int cseq);
101
+  void onNoAck(unsigned int cseq);
102 102
 
103 103
   void onSystemEvent(AmSystemEvent* ev);
104 104
 
105
+#ifdef WITH_ZRTP
106
+  void onZRTPProtocolEvent(zrtp_protocol_event_t event, zrtp_stream_t *stream_ctx);
107
+  void onZRTPSecurityEvent(zrtp_security_event_t event, zrtp_stream_t *stream_ctx);
108
+#endif
109
+
105 110
   void process(AmEvent* event);
106 111
 
107 112
   UACAuthCred* getCredentials();
... ...
@@ -58,6 +58,8 @@ using std::map;
58 58
 #define DSM_ENABLE_REQUEST_EVENTS  "enable_request_events"
59 59
 #define DSM_ENABLE_REPLY_EVENTS    "enable_reply_events"
60 60
 
61
+#define DSM_ENABLE_ZRTP_EVENTS     "enable_zrtp_events"
62
+
61 63
 #define DSM_B2B_RELAYED_INVITE     "b2b_relayed_invite"
62 64
 #define DSM_B2B_LOCAL_PARTY  "b2b_local_party" // From in outgoing call
63 65
 #define DSM_B2B_LOCAL_URI    "b2b_local_uri"
... ...
@@ -121,6 +121,11 @@ class DSMCondition
121 121
     RelayOnSipReply,
122 122
     RelayOnB2BRequest,
123 123
     RelayOnB2BReply
124
+
125
+#ifdef WITH_ZRTP
126
+    , ZRTPProtocolEvent,
127
+    ZRTPSecurityEvent
128
+#endif
124 129
   };
125 130
 
126 131
   bool invert; 
... ...
@@ -10,6 +10,10 @@ ifneq ($(USE_MONITORING), yes)
10 10
 exclude_dsm_modules += mod_monitoring
11 11
 endif
12 12
 
13
+ifneq ($(WITH_ZRTP), yes)
14
+exclude_dsm_modules += mod_zrtp
15
+endif
16
+
13 17
 $(info exclude_dsm_modules: $(exclude_dsm_modules))
14 18
 dsm_modules = $(filter-out $(subst ;, ,$(exclude_dsm_modules))\
15 19
 		$(wildcard Makefile*) lib CMakeLists.txt, \
16 20
new file mode 100644
... ...
@@ -0,0 +1,10 @@
0
+plug_in_name = mod_zrtp
1
+
2
+DSMPATH ?= ../..
3
+
4
+module_ldflags =
5
+module_cflags  = -DMOD_NAME=\"$(plug_in_name)\" -I$(DSMPATH)
6
+
7
+COREPATH ?=$(DSMPATH)/../../core
8
+lib_full_name = $(DSMPATH)/mods/lib/$(lib_name)
9
+include $(DSMPATH)/mods/Makefile.dsm_module
0 10
new file mode 100644
... ...
@@ -0,0 +1,79 @@
0
+/*
1
+ * Copyright (C) 2014 Stefan Sayer
2
+ *
3
+ * This file is part of SEMS, a free SIP media server.
4
+ *
5
+ * SEMS is free software; you can redistribute it and/or modify
6
+ * it under the terms of the GNU General Public License as published by
7
+ * the Free Software Foundation; either version 2 of the License, or
8
+ * (at your option) any later version. This program is released under
9
+ * the GPL with the additional exemption that compiling, linking,
10
+ * and/or using OpenSSL is allowed.
11
+ *
12
+ * For a license to use the SEMS software under conditions
13
+ * other than those described here, or to purchase support for this
14
+ * software, please contact iptel.org by e-mail at the following addresses:
15
+ *    info@iptel.org
16
+ *
17
+ * SEMS is distributed in the hope that it will be useful,
18
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+ * GNU General Public License for more details.
21
+ *
22
+ * You should have received a copy of the GNU General Public License 
23
+ * along with this program; if not, write to the Free Software 
24
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
+ */
26
+#include "ModZrtp.h"
27
+#include "log.h"
28
+#include "AmUtils.h"
29
+
30
+#include "DSMSession.h"
31
+#include "DSMCoreModule.h"
32
+
33
+SC_EXPORT(MOD_CLS_NAME);
34
+
35
+
36
+MOD_ACTIONEXPORT_BEGIN(MOD_CLS_NAME) {
37
+
38
+#ifdef WITH_ZRTP
39
+  DEF_CMD("zrtp.setEnabled", ZRTPSetEnabledAction);
40
+#endif
41
+
42
+} MOD_ACTIONEXPORT_END;
43
+
44
+MOD_CONDITIONEXPORT_BEGIN(MOD_CLS_NAME) {
45
+#ifdef WITH_ZRTP
46
+
47
+  if (cmd == "zrtp.protocolEvent")
48
+    return new TestDSMCondition(params, DSMCondition::ZRTPProtocolEvent);
49
+
50
+  if (cmd == "zrtp.securityEvent")
51
+    return new TestDSMCondition(params, DSMCondition::ZRTPSecurityEvent);
52
+
53
+#endif
54
+} MOD_CONDITIONEXPORT_END;
55
+
56
+#ifdef WITH_ZRTP
57
+
58
+EXEC_ACTION_START(ZRTPSetEnabledAction) {
59
+  bool b = resolveVars(arg, sess, sc_sess, event_params) == DSM_TRUE;
60
+  DBG("setting ZRTP to %sabled\n", b?"en":"dis");
61
+  sess->enable_zrtp = b;
62
+} EXEC_ACTION_END;
63
+
64
+
65
+#endif
66
+
67
+// CONST_ACTION_2P(DLGReplyAction, ',', true);
68
+// EXEC_ACTION_START(DLGReplyAction) {
69
+
70
+//   if (!sc_sess->last_req.get()) {
71
+//     ERROR("no last request to reply\n");
72
+//     sc_sess->SET_ERRNO(DSM_ERRNO_GENERAL);
73
+//     sc_sess->SET_STRERROR("no last request to reply");
74
+//     return false;
75
+//   }
76
+
77
+//   replyRequest(sc_sess, sess, event_params, par1, par2, *sc_sess->last_req.get());
78
+// } EXEC_ACTION_END;
0 79
new file mode 100644
... ...
@@ -0,0 +1,40 @@
0
+/*
1
+ * Copyright (C) 2014 Stefan Sayer
2
+ *
3
+ * This file is part of SEMS, a free SIP media server.
4
+ *
5
+ * SEMS is free software; you can redistribute it and/or modify
6
+ * it under the terms of the GNU General Public License as published by
7
+ * the Free Software Foundation; either version 2 of the License, or
8
+ * (at your option) any later version. This program is released under
9
+ * the GPL with the additional exemption that compiling, linking,
10
+ * and/or using OpenSSL is allowed.
11
+ *
12
+ * For a license to use the SEMS software under conditions
13
+ * other than those described here, or to purchase support for this
14
+ * software, please contact iptel.org by e-mail at the following addresses:
15
+ *    info@iptel.org
16
+ *
17
+ * SEMS is distributed in the hope that it will be useful,
18
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
+ * GNU General Public License for more details.
21
+ *
22
+ * You should have received a copy of the GNU General Public License 
23
+ * along with this program; if not, write to the Free Software 
24
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25
+ */
26
+#ifndef _MOD_ZRTP_H
27
+#define _MOD_ZRTP_H
28
+#include "DSMModule.h"
29
+
30
+#define MOD_CLS_NAME ZRTPModule 
31
+
32
+DECLARE_MODULE_BEGIN(MOD_CLS_NAME);
33
+DECLARE_MODULE_END;
34
+
35
+#ifdef WITH_ZRTP
36
+DEF_ACTION_1P(ZRTPSetEnabledAction);
37
+#endif // WITH_ZRTP
38
+
39
+#endif
... ...
@@ -443,6 +443,12 @@
443 443
    \verbinclude Readme.mod_xml.txt
444 444
    </p>
445 445
 
446
+
447
+   \subsection dsm_mod_zrtp mod_zrtp - ZRTP support functions
448
+   <p>
449
+   \verbinclude Readme.mod_zrtp.txt
450
+   </p>
451
+
446 452
  * 
447 453
  *  \section Links
448 454
  *  Back to \ref AppDoc, to \ref AppDocExample.