1 /*
2  * Copyright (C) 2008 iptego GmbH
3  *
4  * This file is part of SEMS, a free SIP media server.
5  *
6  * SEMS is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version. This program is released under
10  * the GPL with the additional exemption that compiling, linking,
11  * and/or using OpenSSL is allowed.
12  *
13  * For a license to use the SEMS software under conditions
14  * other than those described here, or to purchase support for this
15  * software, please contact iptel.org by e-mail at the following addresses:
16  *    info@iptel.org
17  *
18  * SEMS is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26  */
27 
28 #ifndef _AM_ZRTP_H
29 #define _AM_ZRTP_H
30 
31 #ifdef WITH_ZRTP
32 
33 #include "libzrtp/zrtp.h"
34 #include "AmThread.h"
35 #include "AmEvent.h"
36 
37 #include <string>
38 
39 class AmSession;
40 
41 struct AmZRTPSecurityEvent : public AmEvent {
42   zrtp_stream_t* stream_ctx;
AmZRTPSecurityEventAmZRTPSecurityEvent43  AmZRTPSecurityEvent(int event_id, zrtp_stream_t* stream_ctx)
44    : AmEvent(event_id), stream_ctx(stream_ctx) { }
~AmZRTPSecurityEventAmZRTPSecurityEvent45   ~AmZRTPSecurityEvent() { }
46 };
47 
48 struct AmZRTPProtocolEvent : public AmEvent {
49   zrtp_stream_t* stream_ctx;
AmZRTPProtocolEventAmZRTPProtocolEvent50  AmZRTPProtocolEvent(int event_id, zrtp_stream_t* stream_ctx)
51    : AmEvent(event_id), stream_ctx(stream_ctx) { }
~AmZRTPProtocolEventAmZRTPProtocolEvent52   ~AmZRTPProtocolEvent() { }
53 };
54 
55 
56 struct AmZRTP {
57   static int zrtp_cache_save_cntr;
58   static std::string cache_path;
59   static std::string entropy_path;
60   static AmMutex zrtp_cache_mut;
61   static int init();
62   static int shut_down();
63   static zrtp_global_t* zrtp_global;
64   static zrtp_config_t zrtp_config;
65   static zrtp_zid_t zrtp_instance_zid;
66 
67   static int on_send_packet(const zrtp_stream_t *stream, char *packet, unsigned int length);
68   static void on_zrtp_secure(zrtp_stream_t *stream);
69   static void on_zrtp_security_event(zrtp_stream_t *stream, zrtp_security_event_t event);
70   static void on_zrtp_protocol_event(zrtp_stream_t *stream, zrtp_protocol_event_t event);
71 };
72 
73 struct AmZRTPSessionState {
74 
75   AmZRTPSessionState();
76   ~AmZRTPSessionState();
77 
78   int initSession(AmSession* s);
79   void freeSession();
80 
81   int startStreams(uint32_t ssrc);
82   int stopStreams();
83 
84   zrtp_session_t* zrtp_session; // ZRTP session
85   zrtp_stream_t*  zrtp_audio;   // ZRTP stream for audio
86 };
87 
88 const char* zrtp_protocol_event_desc(zrtp_protocol_event_t e);
89 const char* zrtp_security_event_desc(zrtp_security_event_t e);
90 
91 #if defined(__cplusplus)
92 extern "C" {
93 #endif
94 
95   void zrtp_get_cache_path(char *path, uint32_t length);
96   zrtp_status_t zrtp_cache_user_down();
97 
98 #if defined(__cplusplus)
99 }
100 #endif
101 
102 #endif // WITH_ZRTP
103 
104 #endif //_AM_ZRTP_H
105