nip 17, and 59

This commit is contained in:
2025-10-03 04:25:10 -04:00
parent 54a6044083
commit 6b95ad37c5
32 changed files with 2605 additions and 24009 deletions

View File

@@ -131,7 +131,7 @@ static void init_openssl(void) {
nostr_ws_client_t* nostr_ws_connect(const char* url) {
if (!url) return NULL;
// Initialize OpenSSL
init_openssl();
@@ -781,32 +781,35 @@ static int ws_perform_handshake(nostr_ws_client_t* client, const char* key) {
// Read response
char response[MAX_HEADER_SIZE];
int total_received = 0;
while ((size_t)total_received < sizeof(response) - 1) {
int received = client->transport->recv(&client->transport_ctx,
response + total_received,
sizeof(response) - total_received - 1,
client->timeout_ms);
int received = client->transport->recv(&client->transport_ctx,
response + total_received,
sizeof(response) - total_received - 1,
client->timeout_ms);
if (received <= 0) {
return -1;
}
total_received += received;
response[total_received] = '\0';
// Check if we have complete headers
if (strstr(response, "\r\n\r\n")) break;
if (strstr(response, "\r\n\r\n")) {
break;
}
}
// Check if response starts with the correct HTTP status line
if (strncmp(response, "HTTP/1.1 101 Switching Protocols\r\n", 34) != 0) {
return -1;
}
if (!strstr(response, "Upgrade: websocket") && !strstr(response, "upgrade: websocket")) {
if (!strstr(response, "Upgrade: websocket") && !strstr(response, "upgrade: websocket") &&
!strstr(response, "Upgrade: WebSocket") && !strstr(response, "upgrade: WebSocket")) {
return -1;
}
return 0;
}