sipvoiplink.h 7.54 KB
Newer Older
jpbl's avatar
jpbl committed
1
/*
yanmorin's avatar
   
yanmorin committed
2
 *  Copyright (C) 2004-2006 Savoir-Faire Linux inc.
jpbl's avatar
jpbl committed
3
 *  Author: Yan Morin <yan.morin@savoirfairelinux.com>
4
 *  Author: Laurielle Lea <laurielle.lea@savoirfairelinux.com>
jpbl's avatar
jpbl committed
5
6
7
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; either version 3 of the License, or
jpbl's avatar
jpbl committed
9
10
11
12
13
14
15
16
17
18
19
 *  (at your option) any later version.
 *
 *  This program 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., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
yanmorin's avatar
   
yanmorin committed
20
21
#ifndef SIPVOIPLINK_H
#define SIPVOIPLINK_H
jpbl's avatar
jpbl committed
22

23
#include "voiplink.h"
yanmorin's avatar
   
yanmorin committed
24
25
#include <string>
#include <eXosip2/eXosip.h>
jpbl's avatar
jpbl committed
26
#include "audio/audiortp.h"
Emmanuel Milou's avatar
nothing    
Emmanuel Milou committed
27
#include <osip2/osip_mt.h>
jpbl's avatar
jpbl committed
28

yanmorin's avatar
   
yanmorin committed
29
30
class EventThread;
class SIPCall;
jpbl's avatar
jpbl committed
31

yanmorin's avatar
   
yanmorin committed
32
/**
Alexandre Bourget's avatar
Alexandre Bourget committed
33
 * Specific VoIPLink for SIP (SIP core for incoming and outgoing events)
yanmorin's avatar
   
yanmorin committed
34
 */
Alexandre Bourget's avatar
Alexandre Bourget committed
35

yanmorin's avatar
   
yanmorin committed
36
37
class SIPVoIPLink : public VoIPLink
{
jpbl's avatar
jpbl committed
38
public:
Alexandre Bourget's avatar
Alexandre Bourget committed
39
  SIPVoIPLink(const AccountID& accountID);
yanmorin's avatar
   
yanmorin committed
40

Alexandre Bourget's avatar
Alexandre Bourget committed
41
  ~SIPVoIPLink();
yanmorin's avatar
   
yanmorin committed
42
43
44
45
46
47
48

  /** try to initiate the eXosip engine/thread and set config */
  bool init(void);
  void terminate(void);
  bool checkNetwork(void);
  void getEvent(void);

49
50
  bool sendRegister(void);
  bool sendUnregister(void);
yanmorin's avatar
   
yanmorin committed
51
52
53
54
55
56
57
58
59
60
61
62

  Call* newOutgoingCall(const CallID& id, const std::string& toUrl);
  bool answer(const CallID& id);

  bool hangup(const CallID& id);
  bool cancel(const CallID& id);
  bool onhold(const CallID& id);
  bool offhold(const CallID& id);
  bool transfer(const CallID& id, const std::string& to);
  bool refuse (const CallID& id);
  bool carryingDTMFdigits(const CallID& id, char code);
  bool sendMessage(const std::string& to, const std::string& body);
63
64
65
66
67
68
  bool isContactPresenceSupported();
  void subscribePresenceForContact(Contact* contact);
  void publishPresenceStatus(std::string status);
  
  // TODO Not used yet
  void sendMessageToContact(const CallID& id, const std::string& message);
yanmorin's avatar
   
yanmorin committed
69
70

  // SIP Specific
Alexandre Bourget's avatar
Alexandre Bourget committed
71

yanmorin's avatar
   
yanmorin committed
72
73
74
75
  /** If set to true, we check for a firewall
   * @param use true if we use STUN
   */
  void setUseStun(bool use) { _useStun = use; }
Alexandre Bourget's avatar
Alexandre Bourget committed
76
77
78
79

  /** The name of the STUN server
   * @param server Server FQDN/IP
   */
yanmorin's avatar
   
yanmorin committed
80
  void setStunServer(const std::string& server) { _stunServer = server; }
Alexandre Bourget's avatar
Alexandre Bourget committed
81
82
83
84

  /** Set the SIP proxy
   * @param proxy Proxy FQDN/IP
   */
yanmorin's avatar
   
yanmorin committed
85
86
87
88
89
90
  void setProxy(const std::string& proxy) { _proxy = proxy; }
  void setUserPart(const std::string& userpart) { _userpart = userpart; }
  void setAuthName(const std::string& authname) { _authname = authname; }
  void setPassword(const std::string& password) { _password = password; }


jpbl's avatar
jpbl committed
91
private:
yanmorin's avatar
   
yanmorin committed
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
  /** Terminate every call not hangup | brutal | Protected by mutex */
  void terminateSIPCall(); 

  /**
  * Get the local Ip by eXosip 
  * only if the local ip address is to his default value: 127.0.0.1
  * setLocalIpAdress
  * @return false if not found
  */
  bool loadSIPLocalIP();

  /**
   * send SIP authentification
   * @return true if sending succeed
   */
  bool sendSIPAuthentification();

  /**
   * Get a SIP From header ("fullname" <sip:userpart@hostpart>)
   * @param userpart
   * @param hostpart
   * @return SIP URI for from Header
   */
  std::string SIPFromHeader(const std::string& userpart, const std::string& hostpart);
Emmanuel Milou's avatar
nothing    
Emmanuel Milou committed
116
  std::string SIPFromHeaderAlternate(const std::string& userpart, const std::string& hostpart);
yanmorin's avatar
   
yanmorin committed
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136

  /**
   * Build a sip address with the number that you want to call
   * Example: sip:124@domain.com
   * @return result as a string
   */
  std::string SIPToHeader(const std::string& to);

  /**
   * Check if an url is sip-valid
   * @return true if osip tell that is valid
   */
  bool SIPCheckUrl(const std::string& url);


  /**
   * SIPOutgoingInvite do SIPStartCall
   * @return true if all is correct
   */
  bool SIPOutgoingInvite(SIPCall* call);
jpbl's avatar
jpbl committed
137

yanmorin's avatar
   
yanmorin committed
138
139
140
141
142
  /**
   * Start a SIP Call
   * @return true if all is correct
   */
  bool SIPStartCall(SIPCall* call, const std::string& subject);
jpbl's avatar
jpbl committed
143
144
145
146
  std::string getSipFrom();
  std::string getSipRoute();
  std::string getSipTo(const std::string& to_url);

yanmorin's avatar
   
yanmorin committed
147
148
149
150
151
152
153
  /**
   * Set audio (SDP) configuration for a call
   * localport, localip, localexternalport
   * @param call a SIPCall valid pointer
   * @return true
   */
  bool setCallAudioLocal(SIPCall* call);
jpbl's avatar
jpbl committed
154

yanmorin's avatar
   
yanmorin committed
155
156
157
158
159
  /**
   * Create a new call and send a incoming call notification to the user
   * @param event eXosip Event
   */
  void SIPCallInvite(eXosip_event_t *event);
jpbl's avatar
jpbl committed
160

yanmorin's avatar
   
yanmorin committed
161
162
163
164
165
  /**
   * Use a exisiting call to restart the audio
   * @param event eXosip Event
   */
  void SIPCallReinvite(eXosip_event_t *event);
jpbl's avatar
jpbl committed
166

yanmorin's avatar
   
yanmorin committed
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
  /**
   * Tell the user that the call is ringing
   * @param event eXosip Event
   */
  void SIPCallRinging(eXosip_event_t *event);

  /**
   * Tell the user that the call was answered
   * @param event eXosip Event
   */
  void SIPCallAnswered(eXosip_event_t *event);

  /**
   * Handling 4XX error
   * @param event eXosip Event
   */
  void SIPCallRequestFailure(eXosip_event_t *event);

  /**
   * Handling 5XX/6XX error
   * @param event eXosip Event
   */
  void SIPCallServerFailure(eXosip_event_t *event);
jpbl's avatar
jpbl committed
190
191

  /**
yanmorin's avatar
   
yanmorin committed
192
193
   * Handling ack (restart audio if reinvite)
   * @param event eXosip Event
jpbl's avatar
jpbl committed
194
   */
yanmorin's avatar
   
yanmorin committed
195
  void SIPCallAck(eXosip_event_t *event);
jpbl's avatar
jpbl committed
196
197

  /**
yanmorin's avatar
   
yanmorin committed
198
199
   * Handling message inside a call (like dtmf)
   * @param event eXosip Event
jpbl's avatar
jpbl committed
200
   */
yanmorin's avatar
   
yanmorin committed
201
202
  void SIPCallMessageNew(eXosip_event_t *event);
  bool handleDtmfRelay(eXosip_event_t *event);
jpbl's avatar
jpbl committed
203
204

  /**
yanmorin's avatar
   
yanmorin committed
205
206
   * Peer close the connection
   * @param event eXosip Event
jpbl's avatar
jpbl committed
207
   */
yanmorin's avatar
   
yanmorin committed
208
  void SIPCallClosed(eXosip_event_t *event);
jpbl's avatar
jpbl committed
209
210

  /**
yanmorin's avatar
   
yanmorin committed
211
212
213
   * The call pointer was released
   * If the call was not cleared before, report an error
   * @param event eXosip Event
jpbl's avatar
jpbl committed
214
   */
yanmorin's avatar
   
yanmorin committed
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
  void SIPCallReleased(eXosip_event_t *event);

  /**
   * Receive a new Message request
   * Option/Notify/Message
   * @param event eXosip Event
   */
  void SIPMessageNew(eXosip_event_t *event);

  /**
  * Find a SIPCall with cid from eXosip Event
  * Explication there is no DID when the dialog is not establish...
  * @param cid call ID
  * @return 0 or SIPCall pointer
  */
  SIPCall* findSIPCallWithCid(int cid);

  /**
  * Find a SIPCall with cid and did from eXosip Event
  * @param cid call ID
  * @param did domain ID
  * @return 0 or SIPCall pointer
  */
  SIPCall* findSIPCallWithCidDid(int cid, int did);
  SIPCall* getSIPCall(const CallID& id);

  /** To build sdp when call is on-hold */
  int sdp_hold_call (sdp_message_t * sdp);
  /** To build sdp when call is off-hold */
  int sdp_off_hold_call (sdp_message_t * sdp);

  /** EventThread get every incoming events */
  EventThread* _evThread;
  /** Tell if eXosip was stared (eXosip_init) */
249
  bool _initDone;
Alexandre Bourget's avatar
Alexandre Bourget committed
250

yanmorin's avatar
   
yanmorin committed
251
252
  /** Registration identifier, needed by unregister to build message */
  int _eXosipRegID;
Alexandre Bourget's avatar
Alexandre Bourget committed
253

yanmorin's avatar
   
yanmorin committed
254
255
256
257
258
259
260
261
  /** Number of voicemail */
  int _nMsgVoicemail;

  /** when we init the listener, how many times we try to bind a port? */
  int _nbTryListenAddr;

  /** Do we use stun? */
  bool _useStun;
Alexandre Bourget's avatar
Alexandre Bourget committed
262

yanmorin's avatar
   
yanmorin committed
263
264
  /** What is the stun server? */
  std::string _stunServer;
yanmorin's avatar
   
yanmorin committed
265

Alexandre Bourget's avatar
Alexandre Bourget committed
266
  /** Local Extern Address is the IP address seen by peers for SIP listener */
yanmorin's avatar
   
yanmorin committed
267
268
  std::string _localExternAddress;

Alexandre Bourget's avatar
Alexandre Bourget committed
269
  /** Local Extern Port is the port seen by peers for SIP listener */
yanmorin's avatar
   
yanmorin committed
270
271
272
273
  unsigned int _localExternPort;  

  /** SIP Proxy URL */
  std::string _proxy;
Alexandre Bourget's avatar
Alexandre Bourget committed
274

yanmorin's avatar
   
yanmorin committed
275
276
  /** SIP UserPart */
  std::string _userpart;
jpbl's avatar
jpbl committed
277

yanmorin's avatar
   
yanmorin committed
278
279
  /** SIP Authenfication name */
  std::string _authname;
jpbl's avatar
jpbl committed
280

yanmorin's avatar
   
yanmorin committed
281
282
  /** SIP Authenfication password */
  std::string _password; 
jpbl's avatar
jpbl committed
283

yanmorin's avatar
   
yanmorin committed
284
285
  /** Starting sound */
  AudioRtp _audiortp;
jpbl's avatar
jpbl committed
286
287
};

yanmorin's avatar
   
yanmorin committed
288
#endif