Mercurial
diff seobeo/seobeo.h @ 18:fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Mon, 06 Oct 2025 08:21:34 -0700 |
| parents | d97ec3ded2ae |
| children | 875bb6e10db7 |
line wrap: on
line diff
--- a/seobeo/seobeo.h Sat Oct 04 07:53:12 2025 -0700 +++ b/seobeo/seobeo.h Mon Oct 06 08:21:34 2025 -0700 @@ -22,6 +22,10 @@ #include <stdatomic.h> #include <stdbool.h> +// SSL +#include <openssl/ssl.h> +#include <openssl/err.h> + #include "dowa/dowa.h" #define INITIAL_BUFFER_CAPACITY 4096 @@ -37,23 +41,39 @@ #define HTTP_NOT_FOUND 404 #define HTTP_INTERNAL_ERROR 500 +typedef enum { + SEOBEO_STREAM_TYPE_SERVER, + SEOBEO_STREAM_TYPE_CLIENT, +} Seobeo_SocketType; + typedef struct { - int socket; - char *host; - char *port; + uint32 ip; + uint16 port; +} Seobeo_Address, Seobeo_PAddress; + +typedef struct { + int32 socket; + Seobeo_SocketType type; + boolean connected; - uint8 *read_buffer; - uint32 read_buffer_capacity; - uint32 read_buffer_len; // current size - uint32 read_buffer_used; // TODO: Implement this for client + char *host; + char *port; + + SSL_CTX *ssl_ctx; + SSL *ssl; - uint8 *write_buffer; - uint32 write_buffer_capacity; - uint32 write_buffer_len; // current size + uint8 *read_buffer; + uint32 read_buffer_capacity; + uint32 read_buffer_len; // current size + uint32 read_buffer_used; // TODO: Implement this for client - void *file; - void *text_copy; - char *file_name; + uint8 *write_buffer; + uint32 write_buffer_capacity; + uint32 write_buffer_len; // current size + + void *file; + void *text_copy; + char *file_name; atomic_bool destroyed; } Sebeo_Handle, *Seobeo_PHandle; @@ -70,11 +90,12 @@ } Seobeo_ServerMode; // --- Socket, IP related --- // -extern int Seobeo_CreateSocket(int32 stream, const char *host, const char* port); +extern boolean Seobeo_DNS_LookUp(Seobeo_Address *address, char *dns_name); extern void *Seobeo_GetIP4OrIP6(struct sockaddr *sa); // --- TCP --- // -extern Seobeo_PHandle Seobeo_Stream_Handle_Create(const char *host, const char* port); +extern Seobeo_PHandle Seobeo_Stream_Handle_Server_Create(const char *host, const char* port); +extern Seobeo_PHandle Seobeo_Stream_Handle_Client_Create(const char *host, const char* port, boolean use_tls); extern Seobeo_PHandle Seobeo_Stream_Handle_Accept(Seobeo_PHandle p_server_handle); extern int Seobeo_Stream_Handle_Read(Seobeo_PHandle p_handle); @@ -95,5 +116,15 @@ extern int Seobeo_Handle_Read(Seobeo_PHandle p_handle); extern void Seobeo_Handle_Consume(Seobeo_PHandle p_handle, uint32 consumed); +static void init_openssl(void) +{ + SSL_load_error_strings(); + OpenSSL_add_ssl_algorithms(); +} + +static void cleanup_openssl(void) +{ + EVP_cleanup(); +} #endif