1
/* $Id: sip_transport_udp.h 3553 2011-05-05 06:14:19Z nanang $ */
3
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
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 2 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
#ifndef __PJSIP_TRANSPORT_UDP_H__
21
#define __PJSIP_TRANSPORT_UDP_H__
24
* @file sip_transport_udp.h
25
* @brief SIP UDP Transport.
28
#include <pjsip/sip_transport.h>
33
* @defgroup PJSIP_TRANSPORT_UDP UDP Transport
34
* @ingroup PJSIP_TRANSPORT
35
* @brief API to create and register UDP transport.
37
* The functions below are used to create UDP transport and register
38
* the transport to the framework.
42
* Flag that can be specified when calling #pjsip_udp_transport_pause() or
43
* #pjsip_udp_transport_restart().
48
* This flag tells the transport to keep the existing/internal socket
51
PJSIP_UDP_TRANSPORT_KEEP_SOCKET = 1,
54
* This flag tells the transport to destroy the existing/internal socket
55
* handle. Naturally this flag and PJSIP_UDP_TRANSPORT_KEEP_SOCKET are
58
PJSIP_UDP_TRANSPORT_DESTROY_SOCKET = 2
63
* Start UDP transport.
65
* @param endpt The SIP endpoint.
66
* @param local Optional local address to bind. If this argument
67
* is NULL, the UDP transport will be bound to arbitrary
69
* @param a_name Published address (only the host and port portion is
70
* used). If this argument is NULL, then the bound address
71
* will be used as the published address.
72
* @param async_cnt Number of simultaneous async operations.
73
* @param p_transport Pointer to receive the transport.
75
* @return PJ_SUCCESS when the transport has been successfully
76
* started and registered to transport manager, or
77
* the appropriate error code.
79
PJ_DECL(pj_status_t) pjsip_udp_transport_start(pjsip_endpoint *endpt,
80
const pj_sockaddr_in *local,
81
const pjsip_host_port *a_name,
83
pjsip_transport **p_transport);
86
* Start IPv6 UDP transport.
88
PJ_DECL(pj_status_t) pjsip_udp_transport_start6(pjsip_endpoint *endpt,
89
const pj_sockaddr_in6 *local,
90
const pjsip_host_port *a_name,
92
pjsip_transport **p_transport);
96
* Attach IPv4 UDP socket as a new transport and start the transport.
98
* @param endpt The SIP endpoint.
99
* @param sock UDP socket to use.
100
* @param a_name Published address (only the host and port portion is
102
* @param async_cnt Number of simultaneous async operations.
103
* @param p_transport Pointer to receive the transport.
105
* @return PJ_SUCCESS when the transport has been successfully
106
* started and registered to transport manager, or
107
* the appropriate error code.
109
PJ_DECL(pj_status_t) pjsip_udp_transport_attach(pjsip_endpoint *endpt,
111
const pjsip_host_port *a_name,
113
pjsip_transport **p_transport);
117
* Attach IPv4 or IPv6 UDP socket as a new transport and start the transport.
119
* @param endpt The SIP endpoint.
120
* @param type Transport type, which is PJSIP_TRANSPORT_UDP for IPv4
121
* or PJSIP_TRANSPORT_UDP6 for IPv6 socket.
122
* @param sock UDP socket to use.
123
* @param a_name Published address (only the host and port portion is
125
* @param async_cnt Number of simultaneous async operations.
126
* @param p_transport Pointer to receive the transport.
128
* @return PJ_SUCCESS when the transport has been successfully
129
* started and registered to transport manager, or
130
* the appropriate error code.
132
PJ_DECL(pj_status_t) pjsip_udp_transport_attach2(pjsip_endpoint *endpt,
133
pjsip_transport_type_e type,
135
const pjsip_host_port *a_name,
137
pjsip_transport **p_transport);
140
* Retrieve the internal socket handle used by the UDP transport. Note
141
* that this socket normally is registered to ioqueue, so if application
142
* wants to make use of this socket, it should temporarily pause the
145
* @param transport The UDP transport.
147
* @return The socket handle, or PJ_INVALID_SOCKET if no socket
148
* is currently being used (for example, when transport
151
PJ_DECL(pj_sock_t) pjsip_udp_transport_get_socket(pjsip_transport *transport);
155
* Temporarily pause or shutdown the transport. When transport is being
156
* paused, it cannot be used by the SIP stack to send or receive SIP
159
* Two types of operations are supported by this function:
160
* - to temporarily make this transport unavailable for SIP uses, but
161
* otherwise keep the socket handle intact. Application then can
162
* retrieve the socket handle with #pjsip_udp_transport_get_socket()
163
* and use it to send/receive application data (for example, STUN
164
* messages). In this case, application should specify
165
* PJSIP_UDP_TRANSPORT_KEEP_SOCKET when calling this function, and
166
* also to specify this flag when calling #pjsip_udp_transport_restart()
168
* - to temporarily shutdown the transport, including closing down
169
* the internal socket handle. This is useful for example to
170
* temporarily suspend the application for an indefinite period. In
171
* this case, application should specify PJSIP_UDP_TRANSPORT_DESTROY_SOCKET
172
* flag when calling this function, and specify a new socket when
173
* calling #pjsip_udp_transport_restart().
175
* @param transport The UDP transport.
176
* @param option Pause option.
178
* @return PJ_SUCCESS if transport is paused successfully,
179
* or the appropriate error code.
181
PJ_DECL(pj_status_t) pjsip_udp_transport_pause(pjsip_transport *transport,
185
* Restart the transport. Several operations are supported by this function:
186
* - if transport was made temporarily unavailable to SIP stack with
187
* pjsip_udp_transport_pause() and PJSIP_UDP_TRANSPORT_KEEP_SOCKET,
188
* application can make the transport available to the SIP stack
189
* again, by specifying PJSIP_UDP_TRANSPORT_KEEP_SOCKET flag here.
190
* - if application wants to replace the internal socket with a new
191
* socket, it must specify PJSIP_UDP_TRANSPORT_DESTROY_SOCKET when
192
* calling this function, so that the internal socket will be destroyed
193
* if it hasn't been closed. In this case, application has two choices
194
* on how to create the new socket: 1) to let the transport create
195
* the new socket, in this case the \a sock option should be set
196
* to \a PJ_INVALID_SOCKET and optionally the \a local parameter can be
197
* filled with the desired address and port where the new socket
198
* should be bound to, or 2) to specify its own socket to be used
199
* by this transport, by specifying a valid socket in \a sock argument
200
* and set the \a local argument to NULL. In both cases, application
201
* may specify the published address of the socket in \a a_name
204
* @param transport The UDP transport.
205
* @param option Restart option.
206
* @param sock Optional socket to be used by the transport.
207
* @param local The address where the socket should be bound to.
208
* If this argument is NULL, socket will be bound
209
* to any available port.
210
* @param a_name Optionally specify the published address for
211
* this transport. If the socket is not replaced
212
* (PJSIP_UDP_TRANSPORT_KEEP_SOCKET flag is
213
* specified), then if this argument is NULL, the
214
* previous value will be used. If the socket is
215
* replaced and this argument is NULL, the bound
216
* address will be used as the published address
219
* @return PJ_SUCCESS if transport can be restarted, or
220
* the appropriate error code.
222
PJ_DECL(pj_status_t) pjsip_udp_transport_restart(pjsip_transport *transport,
225
const pj_sockaddr_in *local,
226
const pjsip_host_port *a_name);
235
#endif /* __PJSIP_TRANSPORT_UDP_H__ */