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 #ifndef _DSM_SESSION_H 28 #define _DSM_SESSION_H 29 30 #include "AmArg.h" 31 #include "AmEvent.h" 32 #include "AmSipMsg.h" 33 #include "AmAudioFile.h" 34 35 #include <string> 36 using std::string; 37 #include <vector> 38 using std::vector; 39 #include <map> 40 using std::map; 41 #include <memory> 42 43 #define DSM_TRUE "true" 44 #define DSM_FALSE "false" 45 46 #define DSM_PROCESSED "processed" 47 #define DSM_CONNECT "connect" 48 49 #define DSM_CONNECT_SESSION "connect_session" // todo: rethink these names 50 #define DSM_CONNECT_SESSION_FALSE "0" 51 52 #define DSM_ACCEPT_EARLY_SESSION "accept_early_session" // todo: rethink these names 53 #define DSM_ACCEPT_EARLY_SESSION_FALSE "0" 54 55 #define DSM_CONNECT_EARLY_SESSION "connect_early_session" // todo: rethink these names 56 #define DSM_CONNECT_EARLY_SESSION_FALSE "0" 57 58 #define DSM_ENABLE_REQUEST_EVENTS "enable_request_events" 59 #define DSM_ENABLE_REPLY_EVENTS "enable_reply_events" 60 61 #define DSM_ENABLE_ZRTP_EVENTS "enable_zrtp_events" 62 63 #define DSM_B2B_RELAYED_INVITE "b2b_relayed_invite" 64 #define DSM_B2B_LOCAL_PARTY "b2b_local_party" // From in outgoing call 65 #define DSM_B2B_LOCAL_URI "b2b_local_uri" 66 #define DSM_B2B_AUTH_USER "b2b_auth_user" 67 #define DSM_B2B_AUTH_PWD "b2b_auth_pwd" 68 69 #define DSM_B2B_CALLID "b2b_callid" 70 71 #define DSM_AVAR_REQUEST "request" 72 #define DSM_AVAR_REPLY "reply" 73 74 #define DSM_AVAR_JSONRPCREQUESTDATA "JsonRpcRequestParameters" 75 #define DSM_AVAR_JSONRPCRESPONSEDATA "JsonRpcResponseParameters" 76 #define DSM_AVAR_JSONRPCRESPONSEUDATA "JsonRpcResponseUData" 77 78 #define DSM_AVAR_SIPSUBSCRIPTION_BODY "SipSubscriptionBody" 79 80 #define DSM_ERRNO_FILE "file" 81 #define DSM_ERRNO_UNKNOWN_ARG "arg" 82 #define DSM_ERRNO_SCRIPT "script" 83 #define DSM_ERRNO_CONFIG "config" 84 #define DSM_ERRNO_INTERNAL "internal" 85 #define DSM_ERRNO_GENERAL "general" 86 87 88 #define DSM_ERRNO_OK "" 89 90 #define SET_ERRNO(new_errno) \ 91 var["errno"] = new_errno 92 93 #define CLR_ERRNO \ 94 var["errno"] = DSM_ERRNO_OK; 95 96 #define SET_STRERROR(new_str) \ 97 var["strerror"] = new_str 98 99 #define CLR_STRERROR \ 100 var["strerror"] = ""; 101 102 #define SET_ERROR(s, errno, errstr) \ 103 do { \ 104 s->SET_ERRNO(errno); \ 105 s->SET_STRERROR(errstr); \ 106 } while (0) 107 108 #define CLR_ERROR(s) \ 109 do { \ 110 s->CLR_ERRNO; \ 111 s->CLR_STRERROR; \ 112 } while (0) 113 114 typedef map<string, string> VarMapT; 115 typedef map<string, AmArg> AVarMapT; 116 117 class DSMDisposable; 118 struct AmPlaylistItem; 119 120 class DSMSession { 121 122 public: 123 DSMSession(); 124 virtual ~DSMSession(); 125 126 virtual void playPrompt(const string& name, bool loop = false, bool front = false) = 0; 127 virtual void playFile(const string& name, bool loop, bool front = false) = 0; 128 virtual void playSilence(unsigned int length, bool front = false) = 0; 129 virtual void playRingtone(int length, int on, int off, int f, int f2, bool front) = 0; 130 131 virtual void recordFile(const string& name) = 0; 132 virtual unsigned int getRecordLength() = 0; 133 virtual unsigned int getRecordDataSize() = 0; 134 virtual void stopRecord() = 0; 135 virtual void setInOutPlaylist() = 0; 136 virtual void setInputPlaylist() = 0; 137 virtual void setOutputPlaylist() = 0; 138 139 virtual void addToPlaylist(AmPlaylistItem* item, bool front = false) = 0; 140 virtual void flushPlaylist() = 0; 141 virtual void setPromptSet(const string& name) = 0; 142 virtual void addSeparator(const string& name, bool front = false) = 0; 143 virtual void connectMedia() = 0; 144 virtual void disconnectMedia() = 0; 145 virtual void mute() = 0; 146 virtual void unmute() = 0; 147 148 /** B2BUA functions */ 149 virtual void B2BconnectCallee(const string& remote_party, 150 const string& remote_uri, 151 bool relayed_invite = false) = 0; 152 virtual void B2BterminateOtherLeg() = 0; 153 154 /** insert request in list of received ones */ 155 virtual void B2BaddReceivedRequest(const AmSipRequest& req) = 0; 156 157 /** enable early media relay as reinvite */ 158 virtual void B2BsetRelayEarlyMediaSDP(bool enabled) = 0; 159 160 /** set headers of outgoing INVITE */ 161 virtual void B2BsetHeaders(const string& hdr, bool replaceCRLF) = 0; 162 163 /** set headers of outgoing INVITE */ 164 virtual void B2BclearHeaders() = 0; 165 166 /** add a header to the headers of the outgoing INVITE */ 167 virtual void B2BaddHeader(const string& hdr) = 0; 168 169 /** remove a header to the headers of the outgoing INVITE */ 170 virtual void B2BremoveHeader(const string& hdr) = 0; 171 172 /** transfer ownership of object to this session instance */ 173 virtual void transferOwnership(DSMDisposable* d) = 0; 174 175 /** release ownership of object from this session instance */ 176 virtual void releaseOwnership(DSMDisposable* d) = 0; 177 178 /* holds variables which are accessed by $varname */ 179 VarMapT var; 180 181 /* holds AmArg variables. todo(?): merge var with these */ 182 AVarMapT avar; 183 184 /* result of the last DI call */ 185 AmArg di_res; 186 187 /* last received request */ 188 std::unique_ptr<AmSipRequest> last_req; 189 }; 190 191 class DSMStateDiagramCollection; 192 193 struct DSMScriptConfig { 194 DSMStateDiagramCollection* diags; 195 map<string,string> config_vars; 196 197 bool RunInviteEvent; 198 bool SetParamVariables; 199 }; 200 201 class DSMDisposable { 202 public: DSMDisposable()203 DSMDisposable() { } ~DSMDisposable()204 virtual ~DSMDisposable() { } 205 }; 206 207 class DSMDisposableAudioFile 208 : public DSMDisposable, 209 public AmAudioFile 210 { 211 public: DSMDisposableAudioFile()212 DSMDisposableAudioFile() { } ~DSMDisposableAudioFile()213 ~DSMDisposableAudioFile() { } 214 }; 215 216 class DSMSipRequest 217 : public AmObject { 218 public: 219 const AmSipRequest* req; 220 DSMSipRequest(const AmSipRequest * req)221 DSMSipRequest(const AmSipRequest* req) 222 : req(req) { } ~DSMSipRequest()223 ~DSMSipRequest() { } 224 }; 225 226 class DSMMutableSipRequest 227 : public DSMSipRequest { 228 public: 229 AmSipRequest* mutable_req; 230 DSMMutableSipRequest(AmSipRequest * req)231 DSMMutableSipRequest(AmSipRequest* req) 232 : DSMSipRequest(req), mutable_req(req) { } ~DSMMutableSipRequest()233 ~DSMMutableSipRequest() { } 234 }; 235 236 class DSMSipReply 237 : public AmObject { 238 public: 239 const AmSipReply* reply; 240 DSMSipReply(const AmSipReply * reply)241 DSMSipReply(const AmSipReply* reply) 242 : reply(reply) { } ~DSMSipReply()243 ~DSMSipReply() { } 244 }; 245 246 class DSMMutableSipReply 247 : public DSMSipReply { 248 public: 249 AmSipReply* mutable_reply; 250 DSMMutableSipReply(AmSipReply * reply)251 DSMMutableSipReply(AmSipReply* reply) 252 : DSMSipReply(reply), mutable_reply(reply) { } ~DSMMutableSipReply()253 ~DSMMutableSipReply() { } 254 }; 255 256 #define DSM_EVENT_ID -10 257 /** generic event for passing events between DSM sessions */ 258 struct DSMEvent : public AmEvent { DSMEventDSMEvent259 DSMEvent() : AmEvent(DSM_EVENT_ID) { } ~DSMEventDSMEvent260 ~DSMEvent() { } 261 map<string, string> params; 262 }; 263 264 #endif 265