ascii-chat
Binary v0.16.114-28-gf5913657f
Library lib/v0.3.2-3302-gf5913657f
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>
6#include <options/options.h>
7#include <string.h>
8
9asciichat_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) {
10 if (!csv_urls || !username || !credential || !servers || !count_out || capacity == 0)
11 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid TURN server configuration");
12
13 *count_out = 0;
14 if (!csv_urls[0] || !username[0] || !credential[0])
15 return ASCIICHAT_OK;
16
17 char copy[OPTIONS_BUFF_SIZE];
18 SAFE_STRNCPY(copy, csv_urls, sizeof(copy));
19 char *saveptr = NULL;
20 char *token = platform_strtok_r(copy, ",", &saveptr);
21 while (token && *count_out < capacity) {
22 while (*token == ' ' || *token == '\t')
23 token++;
24 size_t len = strlen(token);
25 while (len && (token[len - 1] == ' ' || token[len - 1] == '\t'))
26 token[--len] = '\0';
27 if (len >= sizeof(servers[*count_out].url))
28 return SET_ERRNO(ERROR_INVALID_PARAM, "TURN URL is too long");
29 if (len) {
30 turn_server_t *server = &servers[*count_out];
31 server->url_len = (uint8_t)len;
32 SAFE_STRNCPY(server->url, token, sizeof(server->url));
33 SAFE_STRNCPY(server->username, username, sizeof(server->username));
34 server->username_len = (uint8_t)strlen(server->username);
35 SAFE_STRNCPY(server->credential, credential, sizeof(server->credential));
36 server->credential_len = (uint8_t)strlen(server->credential);
37 (*count_out)++;
38 }
39 token = platform_strtok_r(NULL, ",", &saveptr);
40 }
41 return ASCIICHAT_OK;
42}
#define SET_ERRNO(code,...)
#define SAFE_STRNCPY(dst, src, size)
unsigned char uint8_t
asciichat_error_t
Error and exit codes - unified status values (0-255).
Definition error_codes.h:48
@ ASCIICHAT_OK
Definition error_codes.h:50
@ ERROR_INVALID_PARAM
#define OPTIONS_BUFF_SIZE
Buffer size for option string values.
Definition options.h:305
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