Module: sems Branch: master Commit: a31067cbb967c98e0b57cda876f7db00b1a662e0 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sems/?a=commit;h=a31067cbb967c98e0b57cda876f7db00b1a662e0
Author: Stefan Sayer <[email protected]> Committer: Stefan Sayer <[email protected]> Date: Mon Nov 3 17:48:12 2014 +0100 dsm:mod_zrtp for simple ZRTP support --- apps/dsm/DSMCall.cpp | 26 ++++++++++++ apps/dsm/DSMCall.h | 7 +++- apps/dsm/DSMSession.h | 2 + apps/dsm/DSMStateEngine.h | 5 ++ apps/dsm/mods/Makefile | 4 ++ apps/dsm/mods/mod_zrtp/Makefile | 10 +++++ apps/dsm/mods/mod_zrtp/ModZrtp.cpp | 79 ++++++++++++++++++++++++++++++++++++ apps/dsm/mods/mod_zrtp/ModZrtp.h | 40 ++++++++++++++++++ doc/src/doc_applications.h | 6 +++ 9 files changed, 178 insertions(+), 1 deletions(-) diff --git a/apps/dsm/DSMCall.cpp b/apps/dsm/DSMCall.cpp index 589d93a..d02f6ff 100644 --- a/apps/dsm/DSMCall.cpp +++ b/apps/dsm/DSMCall.cpp @@ -449,6 +449,32 @@ void DSMCall::onBeforeDestroy() { engine.onBeforeDestroy(this, this); } +#ifdef WITH_ZRTP +void DSMCall::onZRTPProtocolEvent(zrtp_protocol_event_t event, zrtp_stream_t *stream_ctx) { + DBG("DSMCall::onZRTPProtocolEvent: %s\n", zrtp_protocol_event_desc(event)); + + if (checkVar(DSM_ENABLE_ZRTP_EVENTS, DSM_TRUE)) { + map<string, string> params; + params["event"] = zrtp_protocol_event_desc(event); + params["event_id"] = int2str(event); + engine.runEvent(this, this, DSMCondition::ZRTPProtocolEvent, ¶ms); + } + +} + +void DSMCall::onZRTPSecurityEvent(zrtp_security_event_t event, zrtp_stream_t *stream_ctx) { + DBG("DSMCall::onZRTPSecurityEvent: %s\n", zrtp_security_event_desc(event)); + + if (checkVar(DSM_ENABLE_ZRTP_EVENTS, DSM_TRUE)) { + map<string, string> params; + params["event"] = zrtp_security_event_desc(event); + params["event_id"] = int2str(event); + engine.runEvent(this, this, DSMCondition::ZRTPSecurityEvent, ¶ms); + } + +} +#endif + void DSMCall::process(AmEvent* event) { diff --git a/apps/dsm/DSMCall.h b/apps/dsm/DSMCall.h index 0aafbf8..70b36de 100644 --- a/apps/dsm/DSMCall.h +++ b/apps/dsm/DSMCall.h @@ -98,10 +98,15 @@ public: bool getSdpOffer(AmSdp& offer); bool getSdpAnswer(const AmSdp& offer, AmSdp& answer); - virtual void onNoAck(unsigned int cseq); + void onNoAck(unsigned int cseq); void onSystemEvent(AmSystemEvent* ev); +#ifdef WITH_ZRTP + void onZRTPProtocolEvent(zrtp_protocol_event_t event, zrtp_stream_t *stream_ctx); + void onZRTPSecurityEvent(zrtp_security_event_t event, zrtp_stream_t *stream_ctx); +#endif + void process(AmEvent* event); UACAuthCred* getCredentials(); diff --git a/apps/dsm/DSMSession.h b/apps/dsm/DSMSession.h index c33fa62..4fd007b 100644 --- a/apps/dsm/DSMSession.h +++ b/apps/dsm/DSMSession.h @@ -58,6 +58,8 @@ using std::map; #define DSM_ENABLE_REQUEST_EVENTS "enable_request_events" #define DSM_ENABLE_REPLY_EVENTS "enable_reply_events" +#define DSM_ENABLE_ZRTP_EVENTS "enable_zrtp_events" + #define DSM_B2B_RELAYED_INVITE "b2b_relayed_invite" #define DSM_B2B_LOCAL_PARTY "b2b_local_party" // From in outgoing call #define DSM_B2B_LOCAL_URI "b2b_local_uri" diff --git a/apps/dsm/DSMStateEngine.h b/apps/dsm/DSMStateEngine.h index 36a5b9d..6c0b9f1 100644 --- a/apps/dsm/DSMStateEngine.h +++ b/apps/dsm/DSMStateEngine.h @@ -121,6 +121,11 @@ class DSMCondition RelayOnSipReply, RelayOnB2BRequest, RelayOnB2BReply + +#ifdef WITH_ZRTP + , ZRTPProtocolEvent, + ZRTPSecurityEvent +#endif }; bool invert; diff --git a/apps/dsm/mods/Makefile b/apps/dsm/mods/Makefile index a89f9e3..cc3cdf7 100644 --- a/apps/dsm/mods/Makefile +++ b/apps/dsm/mods/Makefile @@ -10,6 +10,10 @@ ifneq ($(USE_MONITORING), yes) exclude_dsm_modules += mod_monitoring endif +ifneq ($(WITH_ZRTP), yes) +exclude_dsm_modules += mod_zrtp +endif + $(info exclude_dsm_modules: $(exclude_dsm_modules)) dsm_modules = $(filter-out $(subst ;, ,$(exclude_dsm_modules))\ $(wildcard Makefile*) lib CMakeLists.txt, \ diff --git a/apps/dsm/mods/mod_zrtp/Makefile b/apps/dsm/mods/mod_zrtp/Makefile new file mode 100644 index 0000000..b28285b --- /dev/null +++ b/apps/dsm/mods/mod_zrtp/Makefile @@ -0,0 +1,10 @@ +plug_in_name = mod_zrtp + +DSMPATH ?= ../.. + +module_ldflags = +module_cflags = -DMOD_NAME=\"$(plug_in_name)\" -I$(DSMPATH) + +COREPATH ?=$(DSMPATH)/../../core +lib_full_name = $(DSMPATH)/mods/lib/$(lib_name) +include $(DSMPATH)/mods/Makefile.dsm_module diff --git a/apps/dsm/mods/mod_zrtp/ModZrtp.cpp b/apps/dsm/mods/mod_zrtp/ModZrtp.cpp new file mode 100644 index 0000000..43b251c --- /dev/null +++ b/apps/dsm/mods/mod_zrtp/ModZrtp.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2014 Stefan Sayer + * + * This file is part of SEMS, a free SIP media server. + * + * SEMS is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. This program is released under + * the GPL with the additional exemption that compiling, linking, + * and/or using OpenSSL is allowed. + * + * For a license to use the SEMS software under conditions + * other than those described here, or to purchase support for this + * software, please contact iptel.org by e-mail at the following addresses: + * [email protected] + * + * SEMS is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include "ModZrtp.h" +#include "log.h" +#include "AmUtils.h" + +#include "DSMSession.h" +#include "DSMCoreModule.h" + +SC_EXPORT(MOD_CLS_NAME); + + +MOD_ACTIONEXPORT_BEGIN(MOD_CLS_NAME) { + +#ifdef WITH_ZRTP + DEF_CMD("zrtp.setEnabled", ZRTPSetEnabledAction); +#endif + +} MOD_ACTIONEXPORT_END; + +MOD_CONDITIONEXPORT_BEGIN(MOD_CLS_NAME) { +#ifdef WITH_ZRTP + + if (cmd == "zrtp.protocolEvent") + return new TestDSMCondition(params, DSMCondition::ZRTPProtocolEvent); + + if (cmd == "zrtp.securityEvent") + return new TestDSMCondition(params, DSMCondition::ZRTPSecurityEvent); + +#endif +} MOD_CONDITIONEXPORT_END; + +#ifdef WITH_ZRTP + +EXEC_ACTION_START(ZRTPSetEnabledAction) { + bool b = resolveVars(arg, sess, sc_sess, event_params) == DSM_TRUE; + DBG("setting ZRTP to %sabled\n", b?"en":"dis"); + sess->enable_zrtp = b; +} EXEC_ACTION_END; + + +#endif + +// CONST_ACTION_2P(DLGReplyAction, ',', true); +// EXEC_ACTION_START(DLGReplyAction) { + +// if (!sc_sess->last_req.get()) { +// ERROR("no last request to reply\n"); +// sc_sess->SET_ERRNO(DSM_ERRNO_GENERAL); +// sc_sess->SET_STRERROR("no last request to reply"); +// return false; +// } + +// replyRequest(sc_sess, sess, event_params, par1, par2, *sc_sess->last_req.get()); +// } EXEC_ACTION_END; diff --git a/apps/dsm/mods/mod_zrtp/ModZrtp.h b/apps/dsm/mods/mod_zrtp/ModZrtp.h new file mode 100644 index 0000000..056c0a6 --- /dev/null +++ b/apps/dsm/mods/mod_zrtp/ModZrtp.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2014 Stefan Sayer + * + * This file is part of SEMS, a free SIP media server. + * + * SEMS is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. This program is released under + * the GPL with the additional exemption that compiling, linking, + * and/or using OpenSSL is allowed. + * + * For a license to use the SEMS software under conditions + * other than those described here, or to purchase support for this + * software, please contact iptel.org by e-mail at the following addresses: + * [email protected] + * + * SEMS is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef _MOD_ZRTP_H +#define _MOD_ZRTP_H +#include "DSMModule.h" + +#define MOD_CLS_NAME ZRTPModule + +DECLARE_MODULE_BEGIN(MOD_CLS_NAME); +DECLARE_MODULE_END; + +#ifdef WITH_ZRTP +DEF_ACTION_1P(ZRTPSetEnabledAction); +#endif // WITH_ZRTP + +#endif diff --git a/doc/src/doc_applications.h b/doc/src/doc_applications.h index 53e28a7..929e2e8 100644 --- a/doc/src/doc_applications.h +++ b/doc/src/doc_applications.h @@ -443,6 +443,12 @@ \verbinclude Readme.mod_xml.txt </p> + + \subsection dsm_mod_zrtp mod_zrtp - ZRTP support functions + <p> + \verbinclude Readme.mod_zrtp.txt + </p> + * * \section Links * Back to \ref AppDoc, to \ref AppDocExample. _______________________________________________ Semsdev mailing list [email protected] http://lists.iptel.org/mailman/listinfo/semsdev
