Files
banban/ql-application/threadx/interface/custom_app/talkingq_wss.c
T
chenjintao 3e463f57b6 Add verified WSS transport for legacy boards
Configure the default WSS endpoint and ISRG Root X2 trust anchor, preserve device authentication, enforce TLS and WebSocket handshake validation, and handle partial I/O and connection cleanup. Add host tests, server probes, package verification and integration documentation. Backend 443 /ws still returns HTTP 404; on-device validation remains pending.
2026-09-16 11:23:33 +08:00

54 lines
1.9 KiB
C

#include "talkingq_wss.h"
#include <string.h>
int talkingq_is_legacy_ws_url(const char *url)
{
return url && (!strcmp(url, "ws://101.35.224.118:8080") ||
!strcmp(url, "ws://101.35.224.118:8080/ws") ||
!strcmp(url, "ws://api.talkingq.com:8080") ||
!strcmp(url, "ws://175.24.73.253:80"));
}
int talkingq_parse_wss_url(const char *url, char *host, size_t host_size,
int *port, char *path, size_t path_size)
{
const char *begin, *end, *colon, *cursor, *resource;
size_t length;
unsigned int value = 0;
if (!url || !host || !port || !path || strncmp(url, "wss://", 6))
return -1;
begin = url + 6;
end = strchr(begin, '/');
if (!end) end = begin + strlen(begin);
colon = memchr(begin, ':', (size_t)(end - begin));
length = (size_t)((colon ? colon : end) - begin);
if (!length || length >= host_size) return -1;
for (cursor = begin; cursor < begin + length; ++cursor) {
char c = *cursor;
if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ||
(c >= '0' && c <= '9') || c == '.' || c == '-')) return -1;
}
if (colon) {
if (colon + 1 == end) return -1;
for (cursor = colon + 1; cursor < end; ++cursor) {
if (*cursor < '0' || *cursor > '9') return -1;
value = value * 10 + (unsigned int)(*cursor - '0');
if (value > 65535) return -1;
}
if (!value) return -1;
} else {
value = 443;
}
resource = *end ? end : "/ws";
if (strlen(resource) >= path_size) return -1;
for (cursor = resource; *cursor; ++cursor) {
if ((unsigned char)*cursor <= 32 || *cursor == '#' ||
(unsigned char)*cursor >= 127) return -1;
}
memcpy(host, begin, length);
host[length] = '\0';
strcpy(path, resource);
*port = (int)value;
return 0;
}