~noskcaj/ubuntu/saucy/sflphone/merge-1.2.3-2

« back to all changes in this revision

Viewing changes to daemon/src/sip/siptransport.h

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2012-05-19 21:46:37 UTC
  • mfrom: (1.1.7)
  • Revision ID: package-import@ubuntu.com-20120519214637-la8rbrford5kj6m3
Tags: 1.1.0-1
* New upstream release 
  - Fixes "FTBFS with libccrtp-dev/2.0.2 from experimental" (Closes: #663282)
* NEW Maintainer: Debian VoIP Team - Thanks Francois for your work.
  - (Closes: #665789: O: sflphone -- SIP and IAX2 compatible VoIP phone)
* Added Build-Depends: libdbus-c++-bin
* Add gcc47-fixes.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (C) [2004, 2012] Savoir-Faire Linux Inc.
 
3
 *
 
4
 *  Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
 
5
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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.
 
19
 *
 
20
 *  Additional permission under GNU GPL version 3 section 7:
 
21
 *
 
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.
 
30
 */
 
31
 
 
32
#ifndef SIPTRANSPORT_H_
 
33
#define SIPTRANSPORT_H_
 
34
 
 
35
#include <string>
 
36
#include <vector>
 
37
 
 
38
#include <pjsip.h>
 
39
#include <pjlib.h>
 
40
#include <pjsip_ua.h>
 
41
#include <pjlib-util.h>
 
42
#include <pjnath.h>
 
43
#include <pjnath/stun_config.h>
 
44
#include "noncopyable.h"
 
45
 
 
46
class SIPAccount;
 
47
 
 
48
class SipTransport {
 
49
    public:
 
50
        SipTransport(pjsip_endpoint *endpt, pj_caching_pool *cp, pj_pool_t *pool);
 
51
        static std::string getSIPLocalIP();
 
52
 
 
53
        /**
 
54
        * List all the interfaces on the system and return
 
55
        * a vector list containing their name (eth0, eth0:1 ...).
 
56
        * @param void
 
57
        * @return std::vector<std::string> A std::string vector
 
58
        * of interface name available on all of the interfaces on
 
59
        * the system.
 
60
        */
 
61
        static std::vector<std::string> getAllIpInterfaceByName();
 
62
 
 
63
        /**
 
64
         * List all the interfaces on the system and return
 
65
         * a vector list containing their name (eth0, eth0:1 ...).
 
66
         * @param void
 
67
         * @return std::vector<std::string> A std::string vector
 
68
         * of interface name available on all of the interfaces on
 
69
         * the system.
 
70
         */
 
71
        static std::string getInterfaceAddrFromName(const std::string &ifaceName);
 
72
 
 
73
        /**
 
74
         * List all the interfaces on the system and return
 
75
         * a vector list containing their IPV4 address.
 
76
         * @param void
 
77
         * @return std::vector<std::string> A std::string vector
 
78
         * of IPV4 address available on all of the interfaces on
 
79
         * the system.
 
80
         */
 
81
        static std::vector<std::string> getAllIpInterface();
 
82
 
 
83
        void setEndpoint(pjsip_endpoint *endpt) {
 
84
            endpt_ = endpt;
 
85
        }
 
86
 
 
87
        void setCachingPool(pj_caching_pool *cp) {
 
88
            cp_ = cp;
 
89
        }
 
90
 
 
91
        void setPool(pj_pool_t *pool) {
 
92
            pool_ = pool;
 
93
        }
 
94
 
 
95
        pj_status_t destroyStunResolver(const std::string &serverName);
 
96
 
 
97
        /**
 
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.
 
101
         */
 
102
        void createSipTransport(SIPAccount &account);
 
103
 
 
104
        /**
 
105
         * Create the default sip transport on 5060. In case this port is already used
 
106
         * increme
 
107
         */
 
108
        void createDefaultSipUdpTransport();
 
109
 
 
110
        /**
 
111
         * Initialize the transport selector
 
112
         * @param transport             A transport associated with an account
 
113
         *
 
114
         * @return              A pointer to the transport selector structure
 
115
         */
 
116
        pjsip_tpselector *initTransportSelector(pjsip_transport *transport, pj_pool_t *tp_pool) const;
 
117
 
 
118
        /**
 
119
         * This function unset the transport for a given account.
 
120
         */
 
121
        void shutdownSipTransport(SIPAccount &account);
 
122
 
 
123
        /**
 
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.
 
127
         *
 
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
 
130
         */
 
131
        void findLocalAddressFromTransport(pjsip_transport *transport, pjsip_transport_type_e transportType, std::string &address, std::string &port) const;
 
132
 
 
133
        /**
 
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.
 
137
         *
 
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
 
142
         */
 
143
        pjsip_transport *createUdpTransport(const std::string &interface, unsigned int port, const std::string &publicAddr, unsigned int publicPort);
 
144
 
 
145
    private:
 
146
        NON_COPYABLE(SipTransport);
 
147
 
 
148
        pjsip_transport *
 
149
        createStunTransport(SIPAccount &account);
 
150
        /**
 
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
 
156
         */
 
157
        pjsip_transport *
 
158
        createTlsTransport(SIPAccount &account);
 
159
 
 
160
        /**
 
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
 
165
         */
 
166
        pjsip_tpfactory *
 
167
        createTlsListener(SIPAccount &account);
 
168
 
 
169
        /**
 
170
         * Create a new stun resolver. Store it inside the array. Resolve public address for this
 
171
         * server name.
 
172
         * @param serverName The name of the stun server
 
173
         * @param port number
 
174
         */
 
175
        pj_status_t createStunResolver(pj_str_t serverName, pj_uint16_t port);
 
176
 
 
177
        /**
 
178
        * Create SIP UDP transport from account's setting
 
179
        * @param account The account for which a transport must be created.
 
180
        */
 
181
        pjsip_transport *createUdpTransport(const std::string &interface,
 
182
                                            unsigned int port);
 
183
 
 
184
        /**
 
185
         * UDP Transports are stored in this map in order to retreive them in case
 
186
         * several accounts would share the same port number.
 
187
         */
 
188
        std::map<std::string, pjsip_transport*> transportMap_;
 
189
 
 
190
        /**
 
191
         * Stun resolver array
 
192
         */
 
193
        std::map<std::string, pj_stun_sock *> stunSocketMap_;
 
194
 
 
195
        pj_caching_pool *cp_;
 
196
 
 
197
        pj_pool_t *pool_;
 
198
 
 
199
        pjsip_endpoint *endpt_;
 
200
};
 
201
 
 
202
#endif // SIPTRANSPORT_H_