Mercurial
view seobeo/seobeo_internal.h @ 119:c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Wed, 07 Jan 2026 16:05:57 -0800 |
| parents | 70401cf61e97 |
| children | cbbf78b17cfa |
line wrap: on
line source
#ifndef SEOBEO_SERVER_INTERNAL_H #define SEOBEO_SERVER_INTERNAL_H #ifndef SEOBEO_NO_SSL #include <openssl/ssl.h> #include <openssl/err.h> #define SSL_CTX_TYPE SSL_CTX #define SSL_TYPE SSL #else #define SSL_CTX_TYPE void #define SSL_TYPE void #endif #include "dowa/dowa.h" #include <stdatomic.h> typedef enum { SEOBEO_STREAM_TYPE_SERVER, SEOBEO_STREAM_TYPE_CLIENT, } Seobeo_SocketType; typedef struct { int32 socket; Seobeo_SocketType type; boolean connected; char *host; char *port; SSL_CTX_TYPE *ssl_ctx; SSL_TYPE *ssl; uint8 *read_buffer; uint32 read_buffer_capacity; uint32 read_buffer_len; // current size uint32 read_buffer_used; // TODO: Implement this for client uint8 *write_buffer; uint32 write_buffer_capacity; uint32 write_buffer_len; // current size void *file; void *text_copy; char *file_name; atomic_bool destroyed; } Seobeo_Handle; // HTML cache type: maps file paths (char*) to file contents (char*) typedef Dowa_KV(char*, char*) Seobeo_Cache_Entry; typedef struct { Seobeo_Handle *srv; Seobeo_Cache_Entry *cache; } WorkerArgs; typedef enum { SEOBEO_MODE_FORK, SEOBEO_MODE_EDGE, } Seobeo_ServerMode; // HTTP request map type: maps header names to header values typedef Dowa_KV(char*, char*) Seobeo_Request_Entry; // --- Router Types --- // // Forward declaration typedef struct Seobeo_Route_Struct Seobeo_Route; // Route handler function type typedef Seobeo_Request_Entry* (*Seobeo_Route_Handler)( Seobeo_Request_Entry *p_request_map, Dowa_Arena *p_arena ); // --- Parse Header into Dowa Map ---// extern int Seobeo_Web_Header_Parse(Seobeo_Handle *p_handle, Seobeo_Request_Entry **pp_map, Dowa_Arena *p_arena); // --- Handle Request --- // extern void Seobeo_Web_HandleClientRequest(Seobeo_Handle *cli, Seobeo_Cache_Entry *p_html_cache); // --- SSL --- // extern void Seobeo_Web_SSL_Init(); extern void Seobeo_Web_SSL_Cleanup(); // Not used extern int Seobeo_SSL_Setup_Client(Seobeo_Handle *p_handle, const char *host, int socket_fd); extern void Seobeo_SSL_Cleanup(Seobeo_Handle *p_handle); extern int32 Seobeo_SSL_Write(Seobeo_Handle *p_handle, const uint8 *data, uint32 length); extern int32 Seobeo_SSL_Read(Seobeo_Handle *p_handle, uint8 *buffer, uint32 length); // --- Serving using Edge --- // extern void *Seobeo_Web_Edge_Worker(void *vargs); extern void Seobeo_Web_Edge(Seobeo_Handle *p_server_handle, int thread_count, Seobeo_Cache_Entry *p_html_cache); // --- HTTP Client Types --- // typedef struct { char *method; char *url; char *host; char *port; char *path; boolean use_tls; // Headers can be either HashMap or Array Seobeo_Request_Entry *headers_map; char **headers_array; char *body; size_t body_length; boolean follow_redirects; int32 max_redirects; char *download_path; Dowa_Arena *p_arena; } Seobeo_Client_Request; typedef struct { int32 status_code; char *status_text; Seobeo_Request_Entry *headers; char *body; size_t body_length; char *redirect_url; Dowa_Arena *p_arena; } Seobeo_Client_Response; // --- HTTP Client Functions --- // extern Seobeo_Client_Request *Seobeo_Client_Request_Create(const char *url); extern void Seobeo_Client_Request_Set_Method(Seobeo_Client_Request *p_req, const char *method); extern void Seobeo_Client_Request_Add_Header_Map(Seobeo_Client_Request *p_req, const char *key, const char *value); extern void Seobeo_Client_Request_Add_Header_Array(Seobeo_Client_Request *p_req, const char *header); extern void Seobeo_Client_Request_Set_Body(Seobeo_Client_Request *p_req, const char *body, size_t length); extern void Seobeo_Client_Request_Set_Follow_Redirects(Seobeo_Client_Request *p_req, boolean follow, int32 max_redirects); extern void Seobeo_Client_Request_Set_Download_Path(Seobeo_Client_Request *p_req, const char *path); extern Seobeo_Client_Response *Seobeo_Client_Request_Execute(Seobeo_Client_Request *p_req); extern void Seobeo_Client_Request_Destroy(Seobeo_Client_Request *p_req); extern void Seobeo_Client_Response_Destroy(Seobeo_Client_Response *p_resp); #endif