Remove WebSocket handshake debug messages unless --debug is enabled

- Modified websocket_handshake() function to accept debug parameter
- Updated all debug messages in websocket_handshake to only print when debug=1
- Updated all callers of websocket_handshake() to pass debug flag
- Fixed compilation warnings and ensured clean build
- WebSocket handshake messages now only appear with --debug flag
parent 480285cd
......@@ -917,7 +917,7 @@ int reconnect_websocket(tunnel_t *tunnel, const char *wssshd_host, int wssshd_po
}
// Perform WebSocket handshake
if (!websocket_handshake(ssl, wssshd_host, wssshd_port, "/")) {
if (!websocket_handshake(ssl, wssshd_host, wssshd_port, "/", debug)) {
fprintf(stderr, "WebSocket handshake failed\n");
SSL_free(ssl);
SSL_CTX_free(ssl_ctx);
......@@ -1071,7 +1071,7 @@ int setup_tunnel(const char *wssshd_host, int wssshd_port, const char *client_id
printf("[DEBUG] Performing WebSocket handshake to %s:%d\n", wssshd_host, wssshd_port);
fflush(stdout);
}
if (!websocket_handshake(ssl, wssshd_host, wssshd_port, "/")) {
if (!websocket_handshake(ssl, wssshd_host, wssshd_port, "/", debug)) {
fprintf(stderr, "WebSocket handshake failed\n");
SSL_free(ssl);
SSL_CTX_free(ssl_ctx);
......
......@@ -25,13 +25,15 @@
#include <stdlib.h>
#include <stdio.h>
int websocket_handshake(SSL *ssl, const char *host, int port, const char *path) {
int websocket_handshake(SSL *ssl, const char *host, int port, const char *path, int debug) {
char request[1024];
char response[BUFFER_SIZE];
int bytes_read;
if (debug) {
printf("[DEBUG] Starting WebSocket handshake to %s:%d\n", host, port);
fflush(stdout);
}
// Send WebSocket handshake
snprintf(request, sizeof(request),
......@@ -44,8 +46,10 @@ int websocket_handshake(SSL *ssl, const char *host, int port, const char *path)
"\r\n",
path, host, port);
if (debug) {
printf("[DEBUG] Sending WebSocket handshake request...\n");
fflush(stdout);
}
// Lock SSL mutex for write operation
pthread_mutex_lock(&ssl_mutex);
......@@ -56,8 +60,10 @@ int websocket_handshake(SSL *ssl, const char *host, int port, const char *path)
return 0;
}
if (debug) {
printf("[DEBUG] WebSocket handshake request sent, waiting for response...\n");
fflush(stdout);
}
// Read response
bytes_read = SSL_read(ssl, response, sizeof(response) - 1);
......@@ -69,7 +75,9 @@ int websocket_handshake(SSL *ssl, const char *host, int port, const char *path)
}
response[bytes_read] = '\0';
if (debug) {
printf("[DEBUG] Received WebSocket handshake response (%d bytes)\n", bytes_read);
}
// Check for successful handshake
if (strstr(response, "101 Switching Protocols") == NULL) {
......@@ -79,8 +87,10 @@ int websocket_handshake(SSL *ssl, const char *host, int port, const char *path)
return 0;
}
if (debug) {
printf("[DEBUG] WebSocket handshake successful\n");
fflush(stdout);
}
return 1;
}
......
......@@ -23,7 +23,7 @@
#include <openssl/ssl.h>
// Function declarations
int websocket_handshake(SSL *ssl, const char *host, int port, const char *path);
int websocket_handshake(SSL *ssl, const char *host, int port, const char *path, int debug);
int send_json_message(SSL *ssl, const char *type, const char *client_id, const char *request_id);
int send_registration_message(SSL *ssl, const char *client_id, const char *password, const char *tunnel, const char *tunnel_control, const char *wssshd_private_ip);
int send_websocket_frame(SSL *ssl, const char *data);
......
......@@ -369,7 +369,7 @@ int connect_to_server(const wssshc_config_t *config) {
fflush(stdout);
}
// websocket_handshake already uses SSL mutex internally
if (!websocket_handshake(ssl, config->wssshd_server, config->wssshd_port, "/")) {
if (!websocket_handshake(ssl, config->wssshd_server, config->wssshd_port, "/", config->debug)) {
fprintf(stderr, "WebSocket handshake failed\n");
SSL_free(ssl);
SSL_CTX_free(ssl_ctx);
......
No preview for this file type
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment