ascii-chat
Binary v0.15.83-53-gb711d8720
Library lib/v0.3.2-701-gb711d8720
Video chat in your terminal
Loading...
Searching...
No Matches
network/webrtc/config.c
Go to the documentation of this file.
2#include <libplatform/compiler.h>
3#include <libplatform/system.h>
4#include <libplatform/terminal.h>
7#include <string.h>
8
9asciichat_error_t webrtc_turn_servers_parse(const char *csv_urls, const char *username, const char *credential,
10 turn_server_t *servers, size_t capacity, size_t *count_out) {
11 if (!csv_urls || !username || !credential || !servers || !count_out || capacity == 0)
12 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid TURN server configuration");
13
14 *count_out = 0;
15 if (!csv_urls[0] || !username[0] || !credential[0])
16 return ASCIICHAT_OK;
17
18 char copy[OPTIONS_BUFF_SIZE];
19 SAFE_STRNCPY(copy, csv_urls, sizeof(copy));
20 char *saveptr = NULL;
21 char *token = platform_strtok_r(copy, ",", &saveptr);
22 while (token && *count_out < capacity) {
23 while (*token == ' ' || *token == '\t')
24 token++;
25 size_t len = strlen(token);
26 while (len && (token[len - 1] == ' ' || token[len - 1] == '\t'))
27 token[--len] = '\0';
28 if (len >= sizeof(servers[*count_out].url))
29 return SET_ERRNO(ERROR_INVALID_PARAM, "TURN URL is too long");
30 if (len) {
31 turn_server_t *server = &servers[*count_out];
32 server->url_len = (uint8_t)len;
33 SAFE_STRNCPY(server->url, token, sizeof(server->url));
34 SAFE_STRNCPY(server->username, username, sizeof(server->username));
35 server->username_len = (uint8_t)strlen(server->username);
36 SAFE_STRNCPY(server->credential, credential, sizeof(server->credential));
37 server->credential_len = (uint8_t)strlen(server->credential);
38 (*count_out)++;
39 }
40 token = platform_strtok_r(NULL, ",", &saveptr);
41 }
42 return ASCIICHAT_OK;
43}
#define SET_ERRNO(code,...)
#define SAFE_STRNCPY(dst, src, size)
Definition common.h:423
unsigned char uint8_t
Definition common.h:60
asciichat_error_t
Error and exit codes - unified status values (0-255).
Definition error_codes.h:44
@ ASCIICHAT_OK
Definition error_codes.h:46
@ ERROR_INVALID_PARAM
#define OPTIONS_BUFF_SIZE
Buffer size for option string values.
Definition options.h:310
turn_server_t
Definition turn.h:106
asciichat_error_t webrtc_turn_servers_parse(const char *csv_urls, const char *username, const char *credential, turn_server_t *servers, size_t capacity, size_t *count_out)
⚙️ Unified options parsing system for ascii-chat with builder pattern and lock-free access
🔤 String Manipulation and Shell Escaping Utilities