blob: 0b1ac90569e0320ffb695face0af08821c65a01f [file] [log] [blame]
James Kuszmaul4a42b182021-01-17 11:32:46 -08001#include "server.h"
2#include <rawrtc/ice_gather_options.h>
3#include <rawrtc/ice_server.h>
4#include <re.h>
5
6/*
7 * Get the corresponding name for an ICE server type.
8 */
9static char const* ice_server_type_to_name(enum rawrtc_ice_server_type const type) {
10 switch (type) {
11 case RAWRTC_ICE_SERVER_TYPE_STUN:
12 return "stun";
13 case RAWRTC_ICE_SERVER_TYPE_TURN:
14 return "turn";
15 default:
16 return "???";
17 }
18}
19
20/*
21 * Get the corresponding name for an ICE server transport.
22 */
23static char const* ice_server_transport_to_name(enum rawrtc_ice_server_transport const transport) {
24 switch (transport) {
25 case RAWRTC_ICE_SERVER_TRANSPORT_UDP:
26 return "udp";
27 case RAWRTC_ICE_SERVER_TRANSPORT_TCP:
28 return "tcp";
29 case RAWRTC_ICE_SERVER_TRANSPORT_DTLS:
30 return "dtls";
31 case RAWRTC_ICE_SERVER_TRANSPORT_TLS:
32 return "tls";
33 default:
34 return "???";
35 }
36}
37
38/*
39 * Get the corresponding name for an ICE credential type.
40 */
41static char const* ice_credential_type_to_name(enum rawrtc_ice_credential_type const type) {
42 switch (type) {
43 case RAWRTC_ICE_CREDENTIAL_TYPE_NONE:
44 return "n/a";
45 case RAWRTC_ICE_CREDENTIAL_TYPE_PASSWORD:
46 return "password";
47 case RAWRTC_ICE_CREDENTIAL_TYPE_TOKEN:
48 return "token";
49 default:
50 return "???";
51 }
52}
53
54/*
55 * Print debug information for an ICE server.
56 */
57int rawrtc_ice_server_debug(
58 struct re_printf* const pf, struct rawrtc_ice_server const* const server) {
59 int err = 0;
60 struct le* le;
61
62 // Check arguments
63 if (!server) {
64 return 0;
65 }
66
67 err |= re_hprintf(pf, " ICE Server <%p>:\n", server);
68
69 // Credential type
70 err |= re_hprintf(
71 pf, " credential_type=%s\n", ice_credential_type_to_name(server->credential_type));
72 if (server->credential_type != RAWRTC_ICE_CREDENTIAL_TYPE_NONE) {
73 // Username
74 err |= re_hprintf(pf, " username=");
75 if (server->username) {
76 err |= re_hprintf(pf, "\"%s\"\n", server->username);
77 } else {
78 err |= re_hprintf(pf, "n/a\n");
79 }
80
81 // Credential
82 err |= re_hprintf(pf, " credential=");
83 if (server->credential) {
84 err |= re_hprintf(pf, "\"%s\"\n", server->credential);
85 } else {
86 err |= re_hprintf(pf, "n/a\n");
87 }
88 }
89
90 // URLs
91 for (le = list_head(&server->urls); le != NULL; le = le->next) {
92 struct rawrtc_ice_server_url* const url = le->data;
93
94 // URL, STUN/TURN, transport, currently gathering?
95 err |= re_hprintf(
96 pf, " URL=\"%s\" type=%s transport=%s resolved=%s\n", url->url,
97 ice_server_type_to_name(url->type), ice_server_transport_to_name(url->transport),
98 sa_is_any(&url->resolved_address) ? "no" : "yes");
99 }
100
101 // Done
102 return err;
103}