1 /* 2 Copyright (c) 2007, Adobe Systems, Incorporated 3 All rights reserved. 4 5 Redistribution and use in source and binary forms, with or without 6 modification, are permitted provided that the following conditions are 7 met: 8 9 * Redistributions of source code must retain the above copyright 10 notice, this list of conditions and the following disclaimer. 11 12 * Redistributions in binary form must reproduce the above copyright 13 notice, this list of conditions and the following disclaimer in the 14 documentation and/or other materials provided with the distribution. 15 16 * Neither the name of Adobe Systems, Network Resonance nor the names of its 17 contributors may be used to endorse or promote products derived from 18 this software without specific prior written permission. 19 20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 34 35 #ifndef _ice_socket_h 36 #define _ice_socket_h 37 #ifdef __cplusplus 38 using namespace std; 39 extern "C" { 40 #endif /* __cplusplus */ 41 42 typedef struct nr_ice_stun_ctx_ { 43 int type; 44 #define NR_ICE_STUN_NONE 0 /* Deregistered */ 45 #define NR_ICE_STUN_CLIENT 1 46 #define NR_ICE_STUN_SERVER 2 47 #define NR_ICE_TURN_CLIENT 3 48 49 union { 50 nr_stun_client_ctx *client; 51 nr_stun_server_ctx *server; 52 struct { 53 nr_turn_client_ctx *turn_client; 54 nr_socket *turn_sock; /* The nr_socket_turn wrapped around 55 turn_client */ 56 } turn_client; 57 } u; 58 59 TAILQ_ENTRY(nr_ice_stun_ctx_) entry; 60 } nr_ice_stun_ctx; 61 62 63 typedef struct nr_ice_socket_ { 64 int type; 65 #define NR_ICE_SOCKET_TYPE_DGRAM 1 66 #define NR_ICE_SOCKET_TYPE_STREAM_TURN 2 67 #define NR_ICE_SOCKET_TYPE_STREAM_TCP 3 68 69 nr_socket *sock; 70 nr_ice_ctx *ctx; 71 72 nr_ice_candidate_head candidates; 73 nr_ice_component *component; 74 75 TAILQ_HEAD(nr_ice_stun_ctx_head_,nr_ice_stun_ctx_) stun_ctxs; 76 77 nr_stun_server_ctx *stun_server; 78 void *stun_server_handle; 79 80 STAILQ_ENTRY(nr_ice_socket_) entry; 81 } nr_ice_socket; 82 83 typedef STAILQ_HEAD(nr_ice_socket_head_,nr_ice_socket_) nr_ice_socket_head; 84 85 int nr_ice_socket_create(struct nr_ice_ctx_ *ctx, struct nr_ice_component_ *comp, nr_socket *nsock, int type, nr_ice_socket **sockp); 86 int nr_ice_socket_destroy(nr_ice_socket **isock); 87 int nr_ice_socket_close(nr_ice_socket *isock); 88 int nr_ice_socket_register_stun_client(nr_ice_socket *sock, nr_stun_client_ctx *srv,void **handle); 89 int nr_ice_socket_register_stun_server(nr_ice_socket *sock, nr_stun_server_ctx *srv,void **handle); 90 int nr_ice_socket_register_turn_client(nr_ice_socket *sock, nr_turn_client_ctx *srv,nr_socket *turn_socket, void **handle); 91 int nr_ice_socket_deregister(nr_ice_socket *sock, void *handle); 92 93 #ifdef __cplusplus 94 } 95 #endif /* __cplusplus */ 96 #endif 97 98