James Kuszmaul | 4a42b18 | 2021-01-17 11:32:46 -0800 | [diff] [blame^] | 1 | #pragma once |
| 2 | #include <rawrtcc/code.h> |
| 3 | #include <re.h> |
| 4 | #include <netinet/in.h> // IPPROTO_UDP, IPPROTO_TCP |
| 5 | |
| 6 | /* |
| 7 | * ICE protocol. |
| 8 | */ |
| 9 | enum rawrtc_ice_protocol { |
| 10 | RAWRTC_ICE_PROTOCOL_UDP = IPPROTO_UDP, |
| 11 | RAWRTC_ICE_PROTOCOL_TCP = IPPROTO_TCP, |
| 12 | }; |
| 13 | |
| 14 | /* |
| 15 | * ICE candidate type. |
| 16 | */ |
| 17 | enum rawrtc_ice_candidate_type { |
| 18 | RAWRTC_ICE_CANDIDATE_TYPE_HOST = ICE_CAND_TYPE_HOST, |
| 19 | RAWRTC_ICE_CANDIDATE_TYPE_SRFLX = ICE_CAND_TYPE_SRFLX, |
| 20 | RAWRTC_ICE_CANDIDATE_TYPE_PRFLX = ICE_CAND_TYPE_PRFLX, |
| 21 | RAWRTC_ICE_CANDIDATE_TYPE_RELAY = ICE_CAND_TYPE_RELAY, |
| 22 | }; |
| 23 | |
| 24 | /* |
| 25 | * ICE TCP candidate type. |
| 26 | */ |
| 27 | enum rawrtc_ice_tcp_candidate_type { |
| 28 | RAWRTC_ICE_TCP_CANDIDATE_TYPE_ACTIVE = ICE_TCP_ACTIVE, |
| 29 | RAWRTC_ICE_TCP_CANDIDATE_TYPE_PASSIVE = ICE_TCP_PASSIVE, |
| 30 | RAWRTC_ICE_TCP_CANDIDATE_TYPE_SO = ICE_TCP_SO, |
| 31 | }; |
| 32 | |
| 33 | /* |
| 34 | * ICE candidate. |
| 35 | */ |
| 36 | struct rawrtc_ice_candidate; |
| 37 | |
| 38 | /* |
| 39 | * ICE candidates. |
| 40 | * Note: Inherits `struct rawrtc_array_container`. |
| 41 | */ |
| 42 | struct rawrtc_ice_candidates { |
| 43 | size_t n_candidates; |
| 44 | struct rawrtc_ice_candidate* candidates[]; |
| 45 | }; |
| 46 | |
| 47 | /* |
| 48 | * Create an ICE candidate. |
| 49 | * `*candidatep` must be unreferenced. |
| 50 | */ |
| 51 | enum rawrtc_code rawrtc_ice_candidate_create( |
| 52 | struct rawrtc_ice_candidate** const candidatep, // de-referenced |
| 53 | char* const foundation, // copied |
| 54 | uint32_t const priority, |
| 55 | char* const ip, // copied |
| 56 | enum rawrtc_ice_protocol const protocol, |
| 57 | uint16_t const port, |
| 58 | enum rawrtc_ice_candidate_type const type, |
| 59 | enum rawrtc_ice_tcp_candidate_type const tcp_type, |
| 60 | char* const related_address, // copied, nullable |
| 61 | uint16_t const related_port); |
| 62 | |
| 63 | /* |
| 64 | * Get the ICE candidate's foundation. |
| 65 | * `*foundationp` will be set to a copy of the IP address that must be |
| 66 | * unreferenced. |
| 67 | */ |
| 68 | enum rawrtc_code rawrtc_ice_candidate_get_foundation( |
| 69 | char** const foundationp, // de-referenced |
| 70 | struct rawrtc_ice_candidate* const candidate); |
| 71 | |
| 72 | /* |
| 73 | * Get the ICE candidate's priority. |
| 74 | */ |
| 75 | enum rawrtc_code rawrtc_ice_candidate_get_priority( |
| 76 | uint32_t* const priorityp, // de-referenced |
| 77 | struct rawrtc_ice_candidate* const candidate); |
| 78 | |
| 79 | /* |
| 80 | * Get the ICE candidate's IP address. |
| 81 | * `*ipp` will be set to a copy of the IP address that must be |
| 82 | * unreferenced. |
| 83 | */ |
| 84 | enum rawrtc_code rawrtc_ice_candidate_get_ip( |
| 85 | char** const ipp, // de-referenced |
| 86 | struct rawrtc_ice_candidate* const candidate); |
| 87 | |
| 88 | /* |
| 89 | * Get the ICE candidate's protocol. |
| 90 | */ |
| 91 | enum rawrtc_code rawrtc_ice_candidate_get_protocol( |
| 92 | enum rawrtc_ice_protocol* const protocolp, // de-referenced |
| 93 | struct rawrtc_ice_candidate* const candidate); |
| 94 | |
| 95 | /* |
| 96 | * Get the ICE candidate's port. |
| 97 | */ |
| 98 | enum rawrtc_code rawrtc_ice_candidate_get_port( |
| 99 | uint16_t* const portp, // de-referenced |
| 100 | struct rawrtc_ice_candidate* const candidate); |
| 101 | |
| 102 | /* |
| 103 | * Get the ICE candidate's type. |
| 104 | */ |
| 105 | enum rawrtc_code rawrtc_ice_candidate_get_type( |
| 106 | enum rawrtc_ice_candidate_type* typep, // de-referenced |
| 107 | struct rawrtc_ice_candidate* const candidate); |
| 108 | |
| 109 | /* |
| 110 | * Get the ICE candidate's TCP type. |
| 111 | * Return `RAWRTC_CODE_NO_VALUE` in case the protocol is not TCP. |
| 112 | */ |
| 113 | enum rawrtc_code rawrtc_ice_candidate_get_tcp_type( |
| 114 | enum rawrtc_ice_tcp_candidate_type* typep, // de-referenced |
| 115 | struct rawrtc_ice_candidate* const candidate); |
| 116 | |
| 117 | /* |
| 118 | * Get the ICE candidate's related IP address. |
| 119 | * `*related_address` will be set to a copy of the related address that |
| 120 | * must be unreferenced. |
| 121 | * |
| 122 | * Return `RAWRTC_CODE_NO_VALUE` in case no related address exists. |
| 123 | */ |
| 124 | enum rawrtc_code rawrtc_ice_candidate_get_related_address( |
| 125 | char** const related_addressp, // de-referenced |
| 126 | struct rawrtc_ice_candidate* const candidate); |
| 127 | |
| 128 | /* |
| 129 | * Get the ICE candidate's related IP address' port. |
| 130 | * `*related_portp` will be set to a copy of the related address' |
| 131 | * port. |
| 132 | * |
| 133 | * Return `RAWRTC_CODE_NO_VALUE` in case no related port exists. |
| 134 | */ |
| 135 | enum rawrtc_code rawrtc_ice_candidate_get_related_port( |
| 136 | uint16_t* const related_portp, // de-referenced |
| 137 | struct rawrtc_ice_candidate* const candidate); |
| 138 | |
| 139 | /* |
| 140 | * Translate a protocol to the corresponding IPPROTO_*. |
| 141 | */ |
| 142 | int rawrtc_ice_protocol_to_ipproto(enum rawrtc_ice_protocol const protocol); |
| 143 | |
| 144 | /* |
| 145 | * Translate a IPPROTO_* to the corresponding protocol. |
| 146 | */ |
| 147 | enum rawrtc_code rawrtc_ipproto_to_ice_protocol( |
| 148 | enum rawrtc_ice_protocol* const protocolp, // de-referenced |
| 149 | int const ipproto); |
| 150 | |
| 151 | /* |
| 152 | * Translate an ICE protocol to str. |
| 153 | */ |
| 154 | char const* rawrtc_ice_protocol_to_str(enum rawrtc_ice_protocol const protocol); |
| 155 | |
| 156 | /* |
| 157 | * Translate a pl to an ICE protocol (case-insensitive). |
| 158 | */ |
| 159 | enum rawrtc_code rawrtc_pl_to_ice_protocol( |
| 160 | enum rawrtc_ice_protocol* const protocolp, // de-referenced |
| 161 | struct pl const* const pl); |
| 162 | |
| 163 | /* |
| 164 | * Translate a str to an ICE protocol (case-insensitive). |
| 165 | */ |
| 166 | enum rawrtc_code rawrtc_str_to_ice_protocol( |
| 167 | enum rawrtc_ice_protocol* const protocolp, // de-referenced |
| 168 | char const* const str); |
| 169 | |
| 170 | /* |
| 171 | * Translate an ICE candidate type to str. |
| 172 | */ |
| 173 | char const* rawrtc_ice_candidate_type_to_str(enum rawrtc_ice_candidate_type const type); |
| 174 | |
| 175 | /* |
| 176 | * Translate a pl to an ICE candidate type (case-insensitive). |
| 177 | */ |
| 178 | enum rawrtc_code rawrtc_pl_to_ice_candidate_type( |
| 179 | enum rawrtc_ice_candidate_type* const typep, // de-referenced |
| 180 | struct pl const* const pl); |
| 181 | |
| 182 | /* |
| 183 | * Translate a str to an ICE candidate type (case-insensitive). |
| 184 | */ |
| 185 | enum rawrtc_code rawrtc_str_to_ice_candidate_type( |
| 186 | enum rawrtc_ice_candidate_type* const typep, // de-referenced |
| 187 | char const* const str); |
| 188 | |
| 189 | /* |
| 190 | * Translate an ICE TCP candidate type to str. |
| 191 | */ |
| 192 | char const* rawrtc_ice_tcp_candidate_type_to_str(enum rawrtc_ice_tcp_candidate_type const type); |
| 193 | |
| 194 | /* |
| 195 | * Translate a str to an ICE TCP candidate type (case-insensitive). |
| 196 | */ |
| 197 | enum rawrtc_code rawrtc_pl_to_ice_tcp_candidate_type( |
| 198 | enum rawrtc_ice_tcp_candidate_type* const typep, // de-referenced |
| 199 | struct pl const* const pl); |
| 200 | |
| 201 | /* |
| 202 | * Translate a str to an ICE TCP candidate type (case-insensitive). |
| 203 | */ |
| 204 | enum rawrtc_code rawrtc_str_to_ice_tcp_candidate_type( |
| 205 | enum rawrtc_ice_tcp_candidate_type* const typep, // de-referenced |
| 206 | char const* const str); |