summaryrefslogtreecommitdiff
path: root/pjnath/include/pjnath/turn_udp.h
blob: 2c701590fc9e25c60445927271919c122a1adebd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/* $Id$ */
/* 
 * Copyright (C) 2003-2007 Benny Prijono <benny@prijono.org>
 *
 * 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
 * the Free Software Foundation; either version 2 of the License, or
 * (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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 */
#ifndef __PJNATH_TURN_UDP_H__
#define __PJNATH_TURN_UDP_H__

/**
 * @file turn_udp.h
 * @brief TURN relay using UDP client as transport protocol
 */
#include <pjnath/turn_session.h>


PJ_BEGIN_DECL


/* **************************************************************************/
/**
 * @defgroup PJNATH_TURN_UDP TURN UDP client
 * @brief TURN relay using UDP client as transport protocol
 * @ingroup PJNATH_STUN
 * @{
 */


/** 
 * Opaque declaration for TURN UDP client.
 */
typedef struct pj_turn_udp pj_turn_udp;


typedef struct pj_turn_udp_cb
{
    /**
     * Notification when incoming data has been received, either through
     * Data indication or ChannelData message from the TURN server.
     *
     * This callback is mandatory.
     */
    void (*on_rx_data)(pj_turn_udp *udp_rel,
		       const pj_uint8_t *pkt,
		       unsigned pkt_len,
		       const pj_sockaddr_t *peer_addr,
		       unsigned addr_len);

    /**
     * Notification when TURN session state has changed. Application should
     * implement this callback to know that the TURN session is no longer
     * available.
     */
    void (*on_state)(pj_turn_udp *udp_rel, pj_turn_state_t old_state,
		     pj_turn_state_t new_state);

} pj_turn_udp_cb;


/**
 * Create.
 */
PJ_DECL(pj_status_t) pj_turn_udp_create(pj_stun_config *cfg,
					int af,
					const pj_turn_udp_cb *cb,
					unsigned options,
					void *user_data,
					pj_turn_udp **p_udp_rel);

/**
 * Destroy.
 */
PJ_DECL(void) pj_turn_udp_destroy(pj_turn_udp *udp_rel);

/**
 * Set user data.
 */
PJ_DECL(pj_status_t) pj_turn_udp_set_user_data(pj_turn_udp *udp_rel,
					       void *user_data);

/**
 * Get user data.
 */
PJ_DECL(void*) pj_turn_udp_get_user_data(pj_turn_udp *udp_rel);


/**
 * Get info.
 */
PJ_DECL(pj_status_t) pj_turn_udp_get_info(pj_turn_udp *udp_rel,
					  pj_turn_session_info *info);

/**
 * Initialize.
 */
PJ_DECL(pj_status_t) pj_turn_udp_init(pj_turn_udp *udp_rel,
				      const pj_str_t *domain,
				      int default_port,
				      pj_dns_resolver *resolver,
				      const pj_stun_auth_cred *cred,
				      const pj_turn_alloc_param *param);

/**
 * Send packet.
 */ 
PJ_DECL(pj_status_t) pj_turn_udp_sendto(pj_turn_udp *udp_rel,
					const pj_uint8_t *pkt,
					unsigned pkt_len,
					const pj_sockaddr_t *addr,
					unsigned addr_len);

/**
 * Bind a peer address to a channel number.
 */
PJ_DECL(pj_status_t) pj_turn_udp_bind_channel(pj_turn_udp *udp_rel,
					      const pj_sockaddr_t *peer,
					      unsigned addr_len);


/**
 * @}
 */


PJ_END_DECL


#endif	/* __PJNATH_TURN_UDP_H__ */