Cosmetics
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
#define SNI_HOSTNAME "myserver.local" // Default SNI hostname; override in config.h if needed
|
||||
#endif
|
||||
|
||||
Transport* InitTransport(const char* domain, unsigned short port) {
|
||||
Transport* InitTransport(char* domain, unsigned short port) {
|
||||
#if USE_SCHANNEL
|
||||
return InitSchannelTransport(domain, port, SNI_HOSTNAME);
|
||||
#elif USE_WOLFSSL
|
||||
@@ -23,7 +23,7 @@ void CleanupTransport(Transport* transport) {
|
||||
}
|
||||
|
||||
char* GetNextDomain() {
|
||||
static unsigned short currentDomain = 0;
|
||||
unsigned short currentDomain = 0;
|
||||
char* domain = serverDomains[currentDomain];
|
||||
currentDomain = (currentDomain + 1) % domainCount;
|
||||
return domain;
|
||||
|
||||
@@ -6,22 +6,22 @@
|
||||
// Transport abstraction
|
||||
typedef struct {
|
||||
void* handle; // Opaque pointer to underlying connection (WOLFSSL* or SOCKET or Schannel context)
|
||||
int (*send) (void* handle, const char* data, size_t len);
|
||||
int (*send) (void* handle, char* data, size_t len);
|
||||
int (*recv) (void* handle, char* buffer, size_t len);
|
||||
void (*cleanup) (void* handle);
|
||||
} Transport;
|
||||
|
||||
Transport* InitTransport(const char* domain, unsigned short port);
|
||||
Transport* InitTransport(char* domain, unsigned short port);
|
||||
void CleanupTransport(Transport* transport);
|
||||
char* GetNextDomain();
|
||||
|
||||
#if USE_SCHANNEL
|
||||
extern Transport* InitSchannelTransport(const char* domain, unsigned short port, const char* sni_hostname);
|
||||
extern Transport* InitSchannelTransport(char* domain, unsigned short port, char* sni_hostname);
|
||||
#endif
|
||||
#if USE_WOLFSSL
|
||||
extern Transport* InitWolfSSLTransport(const char* domain, unsigned short port);
|
||||
extern Transport* InitWolfSSLTransport(char* domain, unsigned short port);
|
||||
#else
|
||||
extern Transport* InitTCPTransport(const char* domain, unsigned short port);
|
||||
extern Transport* InitTCPTransport(char* domain, unsigned short port);
|
||||
#endif
|
||||
|
||||
#endif // TRANSPORT_H
|
||||
@@ -21,7 +21,7 @@ typedef struct {
|
||||
} SchannelHandle;
|
||||
|
||||
// Initialize SChannel and perform TLS handshake
|
||||
static BOOL init_schannel(SchannelHandle* handle, const char* domain, unsigned short port, const char* sni_hostname) {
|
||||
BOOL init_schannel(SchannelHandle* handle, char* domain, unsigned short port, char* sni_hostname) {
|
||||
// Initialize Winsock
|
||||
WSADATA wsaData;
|
||||
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) {
|
||||
@@ -130,7 +130,7 @@ static BOOL init_schannel(SchannelHandle* handle, const char* domain, unsigned s
|
||||
}
|
||||
|
||||
// Send encrypted data
|
||||
static int schannel_send(void* handle, const char* data, size_t len) {
|
||||
int schannel_send(void* handle, char* data, size_t len) {
|
||||
SchannelHandle* schannel = (SchannelHandle*)handle;
|
||||
if (!schannel->initialized) return -1;
|
||||
|
||||
@@ -161,7 +161,7 @@ static int schannel_send(void* handle, const char* data, size_t len) {
|
||||
}
|
||||
|
||||
// Receive and decrypt data
|
||||
static int schannel_recv(void* handle, char* buffer, size_t len) {
|
||||
int schannel_recv(void* handle, char* buffer, size_t len) {
|
||||
SchannelHandle* schannel = (SchannelHandle*)handle;
|
||||
if (!schannel->initialized) return -1;
|
||||
|
||||
@@ -193,7 +193,7 @@ static int schannel_recv(void* handle, char* buffer, size_t len) {
|
||||
}
|
||||
|
||||
// Cleanup SChannel resources
|
||||
static void schannel_cleanup(void* handle) {
|
||||
void schannel_cleanup(void* handle) {
|
||||
SchannelHandle* schannel = (SchannelHandle*)handle;
|
||||
if (schannel->initialized) {
|
||||
DeleteSecurityContext(&schannel->ctx);
|
||||
@@ -208,7 +208,7 @@ static void schannel_cleanup(void* handle) {
|
||||
}
|
||||
|
||||
// Initialize SChannel transport
|
||||
Transport* InitSchannelTransport(const char* domain, unsigned short port, const char* sni_hostname) {
|
||||
Transport* InitSchannelTransport(char* domain, unsigned short port, char* sni_hostname) {
|
||||
SchannelHandle* handle = (SchannelHandle*)calloc(1, sizeof(SchannelHandle));
|
||||
if (!handle) {
|
||||
fprintf(stderr, "Error: Failed to allocate memory for Schannel handle\n");
|
||||
|
||||
@@ -5,17 +5,17 @@
|
||||
|
||||
#include "transport.h"
|
||||
|
||||
static int tcp_send(void* handle, const char* data, size_t len) {
|
||||
int tcp_send(void* handle, char* data, size_t len) {
|
||||
SOCKET sock = *(SOCKET*)handle;
|
||||
return send(sock, data, len, 0);
|
||||
}
|
||||
|
||||
static int tcp_recv(void* handle, char* buffer, size_t len) {
|
||||
int tcp_recv(void* handle, char* buffer, size_t len) {
|
||||
SOCKET sock = *(SOCKET*)handle;
|
||||
return recv(sock, buffer, len, 0);
|
||||
}
|
||||
|
||||
static void tcp_cleanup(void* handle) {
|
||||
void tcp_cleanup(void* handle) {
|
||||
SOCKET* sock = (SOCKET*)handle;
|
||||
if (*sock != INVALID_SOCKET) {
|
||||
shutdown(*sock, SD_BOTH);
|
||||
@@ -25,7 +25,7 @@ static void tcp_cleanup(void* handle) {
|
||||
free(sock);
|
||||
}
|
||||
|
||||
Transport* InitTCPTransport(const char* domain, unsigned short port) {
|
||||
Transport* InitTCPTransport(char* domain, unsigned short port) {
|
||||
WSADATA wsaData;
|
||||
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) {
|
||||
fprintf(stderr, "Error: WSAStartup failed\n");
|
||||
|
||||
@@ -15,7 +15,7 @@ typedef struct {
|
||||
SOCKET sockfd;
|
||||
} WolfSSLConnection;
|
||||
|
||||
static int wolfssl_send(void* handle, const char* data, size_t len) {
|
||||
int wolfssl_send(void* handle, char* data, size_t len) {
|
||||
if (!handle) {
|
||||
fprintf(stderr, "Error: wolfssl_send called with null handle\n");
|
||||
return -1;
|
||||
@@ -35,7 +35,7 @@ static int wolfssl_send(void* handle, const char* data, size_t len) {
|
||||
return result;
|
||||
}
|
||||
|
||||
static int wolfssl_recv(void* handle, char* buffer, size_t len) {
|
||||
int wolfssl_recv(void* handle, char* buffer, size_t len) {
|
||||
if (!handle || !buffer) {
|
||||
fprintf(stderr, "Error: wolfssl_recv called with null handle or buffer\n");
|
||||
return -1;
|
||||
@@ -55,7 +55,7 @@ static int wolfssl_recv(void* handle, char* buffer, size_t len) {
|
||||
return result;
|
||||
}
|
||||
|
||||
static void wolfssl_cleanup(void* handle) {
|
||||
void wolfssl_cleanup(void* handle) {
|
||||
if (!handle) {
|
||||
fprintf(stderr, "Error: wolfssl_cleanup called with null handle\n");
|
||||
return;
|
||||
@@ -80,7 +80,7 @@ static void wolfssl_cleanup(void* handle) {
|
||||
free(conn);
|
||||
}
|
||||
|
||||
Transport* InitWolfSSLTransport(const char* domain, unsigned short port) {
|
||||
Transport* InitWolfSSLTransport(char* domain, unsigned short port) {
|
||||
// Testing
|
||||
// WSADATA wsaData;
|
||||
// if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) {
|
||||
|
||||
Reference in New Issue
Block a user