2
* Copyright (C) [2004, 2012] Savoir-Faire Linux Inc.
4
* Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
6
* This program 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 3 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
* Additional permission under GNU GPL version 3 section 7:
22
* If you modify this program, or any covered work, by linking or
23
* combining it with the OpenSSL project's OpenSSL library (or a
24
* modified version of that library), containing parts covered by the
25
* terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
26
* grants you additional permission to convey the resulting work.
27
* Corresponding Source for a non-source form of such a combination
28
* shall include the source code for the parts of OpenSSL used as well
29
* as that of the covered work.
32
#ifndef SIPTRANSPORT_H_
33
#define SIPTRANSPORT_H_
41
#include <pjlib-util.h>
43
#include <pjnath/stun_config.h>
44
#include "noncopyable.h"
50
SipTransport(pjsip_endpoint *endpt, pj_caching_pool *cp, pj_pool_t *pool);
51
static std::string getSIPLocalIP();
54
* List all the interfaces on the system and return
55
* a vector list containing their name (eth0, eth0:1 ...).
57
* @return std::vector<std::string> A std::string vector
58
* of interface name available on all of the interfaces on
61
static std::vector<std::string> getAllIpInterfaceByName();
64
* List all the interfaces on the system and return
65
* a vector list containing their name (eth0, eth0:1 ...).
67
* @return std::vector<std::string> A std::string vector
68
* of interface name available on all of the interfaces on
71
static std::string getInterfaceAddrFromName(const std::string &ifaceName);
74
* List all the interfaces on the system and return
75
* a vector list containing their IPV4 address.
77
* @return std::vector<std::string> A std::string vector
78
* of IPV4 address available on all of the interfaces on
81
static std::vector<std::string> getAllIpInterface();
83
void setEndpoint(pjsip_endpoint *endpt) {
87
void setCachingPool(pj_caching_pool *cp) {
91
void setPool(pj_pool_t *pool) {
95
pj_status_t destroyStunResolver(const std::string &serverName);
98
* General Sip transport creation method according to the
99
* transport type specified in account settings
100
* @param account The account for which a transport must be created.
102
void createSipTransport(SIPAccount &account);
105
* Create the default sip transport on 5060. In case this port is already used
108
void createDefaultSipUdpTransport();
111
* Initialize the transport selector
112
* @param transport A transport associated with an account
114
* @return A pointer to the transport selector structure
116
pjsip_tpselector *initTransportSelector(pjsip_transport *transport, pj_pool_t *tp_pool) const;
119
* This function unset the transport for a given account.
121
void shutdownSipTransport(SIPAccount &account);
124
* Get the correct address to use (ie advertised) from
125
* a uri. The corresponding transport that should be used
126
* with that uri will be discovered.
128
* @param uri The uri from which we want to discover the address to use
129
* @param transport The transport to use to discover the address
131
void findLocalAddressFromTransport(pjsip_transport *transport, pjsip_transport_type_e transportType, std::string &address, std::string &port) const;
134
* Create a new udp transport specifying the bound address AND the published address.
135
* The published address is the address to appears in the sip VIA header. This is used
136
* essentially when the client is behind a trafic routing device.
138
* @param The interface to bind this transport with
139
* @param The requested udp port number
140
* @param The public address for this transport
141
* @param The public port for this transport
143
pjsip_transport *createUdpTransport(const std::string &interface, unsigned int port, const std::string &publicAddr, unsigned int publicPort);
146
NON_COPYABLE(SipTransport);
149
createStunTransport(SIPAccount &account);
151
* Create a connection oriented TLS transport and register to the specified remote address.
152
* First, initialize the TLS listener sole instance. This means that, for the momment, only one TLS transport
153
* is allowed to be created in the application. Any subsequent account attempting to
154
* register a new using this transport even if new settings are specified.
155
* @param the account that is creating the TLS transport
158
createTlsTransport(SIPAccount &account);
161
* Create The default TLS listener which is global to the application. This means that
162
* only one TLS connection can be established for the momment.
163
* @param the SIPAccount for which we are creating the TLS listener
164
* @return a pointer to the new listener
167
createTlsListener(SIPAccount &account);
170
* Create a new stun resolver. Store it inside the array. Resolve public address for this
172
* @param serverName The name of the stun server
175
pj_status_t createStunResolver(pj_str_t serverName, pj_uint16_t port);
178
* Create SIP UDP transport from account's setting
179
* @param account The account for which a transport must be created.
181
pjsip_transport *createUdpTransport(const std::string &interface,
185
* UDP Transports are stored in this map in order to retreive them in case
186
* several accounts would share the same port number.
188
std::map<std::string, pjsip_transport*> transportMap_;
191
* Stun resolver array
193
std::map<std::string, pj_stun_sock *> stunSocketMap_;
195
pj_caching_pool *cp_;
199
pjsip_endpoint *endpt_;
202
#endif // SIPTRANSPORT_H_