comparison 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
comparison
equal deleted inserted replaced
17:d97ec3ded2ae 18:fa2b8af609d9
20 #include <fcntl.h> 20 #include <fcntl.h>
21 #include <pthread.h> 21 #include <pthread.h>
22 #include <stdatomic.h> 22 #include <stdatomic.h>
23 #include <stdbool.h> 23 #include <stdbool.h>
24 24
25 // SSL
26 #include <openssl/ssl.h>
27 #include <openssl/err.h>
28
25 #include "dowa/dowa.h" 29 #include "dowa/dowa.h"
26 30
27 #define INITIAL_BUFFER_CAPACITY 4096 31 #define INITIAL_BUFFER_CAPACITY 4096
28 32
29 // HTTP STATUS CODE 33 // HTTP STATUS CODE
35 #define HTTP_UNAUTHORIZED 401 39 #define HTTP_UNAUTHORIZED 401
36 #define HTTP_FORBIDDEN 403 40 #define HTTP_FORBIDDEN 403
37 #define HTTP_NOT_FOUND 404 41 #define HTTP_NOT_FOUND 404
38 #define HTTP_INTERNAL_ERROR 500 42 #define HTTP_INTERNAL_ERROR 500
39 43
44 typedef enum {
45 SEOBEO_STREAM_TYPE_SERVER,
46 SEOBEO_STREAM_TYPE_CLIENT,
47 } Seobeo_SocketType;
48
40 typedef struct { 49 typedef struct {
41 int socket; 50 uint32 ip;
42 char *host; 51 uint16 port;
43 char *port; 52 } Seobeo_Address, Seobeo_PAddress;
44 53
45 uint8 *read_buffer; 54 typedef struct {
46 uint32 read_buffer_capacity; 55 int32 socket;
47 uint32 read_buffer_len; // current size 56 Seobeo_SocketType type;
48 uint32 read_buffer_used; // TODO: Implement this for client 57 boolean connected;
49 58
50 uint8 *write_buffer; 59 char *host;
51 uint32 write_buffer_capacity; 60 char *port;
52 uint32 write_buffer_len; // current size 61
62 SSL_CTX *ssl_ctx;
63 SSL *ssl;
53 64
54 void *file; 65 uint8 *read_buffer;
55 void *text_copy; 66 uint32 read_buffer_capacity;
56 char *file_name; 67 uint32 read_buffer_len; // current size
68 uint32 read_buffer_used; // TODO: Implement this for client
69
70 uint8 *write_buffer;
71 uint32 write_buffer_capacity;
72 uint32 write_buffer_len; // current size
73
74 void *file;
75 void *text_copy;
76 char *file_name;
57 77
58 atomic_bool destroyed; 78 atomic_bool destroyed;
59 } Sebeo_Handle, *Seobeo_PHandle; 79 } Sebeo_Handle, *Seobeo_PHandle;
60 80
61 typedef struct { 81 typedef struct {
68 SEOBEO_MODE_FORK, 88 SEOBEO_MODE_FORK,
69 SEOBEO_MODE_EDGE, 89 SEOBEO_MODE_EDGE,
70 } Seobeo_ServerMode; 90 } Seobeo_ServerMode;
71 91
72 // --- Socket, IP related --- // 92 // --- Socket, IP related --- //
73 extern int Seobeo_CreateSocket(int32 stream, const char *host, const char* port); 93 extern boolean Seobeo_DNS_LookUp(Seobeo_Address *address, char *dns_name);
74 extern void *Seobeo_GetIP4OrIP6(struct sockaddr *sa); 94 extern void *Seobeo_GetIP4OrIP6(struct sockaddr *sa);
75 95
76 // --- TCP --- // 96 // --- TCP --- //
77 extern Seobeo_PHandle Seobeo_Stream_Handle_Create(const char *host, const char* port); 97 extern Seobeo_PHandle Seobeo_Stream_Handle_Server_Create(const char *host, const char* port);
98 extern Seobeo_PHandle Seobeo_Stream_Handle_Client_Create(const char *host, const char* port, boolean use_tls);
78 extern Seobeo_PHandle Seobeo_Stream_Handle_Accept(Seobeo_PHandle p_server_handle); 99 extern Seobeo_PHandle Seobeo_Stream_Handle_Accept(Seobeo_PHandle p_server_handle);
79 extern int Seobeo_Stream_Handle_Read(Seobeo_PHandle p_handle); 100 extern int Seobeo_Stream_Handle_Read(Seobeo_PHandle p_handle);
80 101
81 // --- Web --- // 102 // --- Web --- //
82 extern void Seobeo_Web_GenerateResponseHeader(void *buffer, int status, const char *content_type, const int content_length); 103 extern void Seobeo_Web_GenerateResponseHeader(void *buffer, int status, const char *content_type, const int content_length);
93 extern int Seobeo_Handle_Flush(Seobeo_PHandle p_handle); 114 extern int Seobeo_Handle_Flush(Seobeo_PHandle p_handle);
94 extern int Seobeo_Handle_Queue(Seobeo_PHandle p_handle, const uint8_t *data, uint32_t data_size); 115 extern int Seobeo_Handle_Queue(Seobeo_PHandle p_handle, const uint8_t *data, uint32_t data_size);
95 extern int Seobeo_Handle_Read(Seobeo_PHandle p_handle); 116 extern int Seobeo_Handle_Read(Seobeo_PHandle p_handle);
96 extern void Seobeo_Handle_Consume(Seobeo_PHandle p_handle, uint32 consumed); 117 extern void Seobeo_Handle_Consume(Seobeo_PHandle p_handle, uint32 consumed);
97 118
119 static void init_openssl(void)
120 {
121 SSL_load_error_strings();
122 OpenSSL_add_ssl_algorithms();
123 }
124
125 static void cleanup_openssl(void)
126 {
127 EVP_cleanup();
128 }
98 129
99 #endif 130 #endif