Mercurial
view seobeo/seobeo.h @ 71:75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Sun, 28 Dec 2025 20:34:22 -0800 |
| parents | a0f0ad5e42eb |
| children | 4532ce6d9eb8 |
line wrap: on
line source
#ifndef SEOBEO_SERVER_H #define SEOBEO_SERVER_H /** * Seobeo * ------ * * Library for starting TCP, UDP server and serving static file or path. */ // Define DIRECTORY before any includes to enable directory operations in dowa.h #ifndef DIRECTORY #define DIRECTORY #endif #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <errno.h> #include <string.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <netdb.h> #include <arpa/inet.h> #include <sys/wait.h> #include <signal.h> #include <fcntl.h> #include <pthread.h> #include <stdatomic.h> #include <stdbool.h> #include "seobeo/seobeo_internal.h" #define INITIAL_BUFFER_CAPACITY 4096 // HTTP STATUS CODE #define HTTP_OK 200 #define HTTP_CREATED 201 #define HTTP_MOVED_PERMANENTLY 301 #define HTTP_FOUND 302 #define HTTP_BAD_REQUEST 400 #define HTTP_UNAUTHORIZED 401 #define HTTP_FORBIDDEN 403 #define HTTP_NOT_FOUND 404 #define HTTP_INTERNAL_ERROR 500 extern volatile sig_atomic_t stop_server; // --- TCP --- // // --- Generate a Server Handle. ---// extern Seobeo_Handle *Seobeo_Stream_Handle_Server_Create(const char *host, const char* port); // --- Generate a Client Handle. ---// extern Seobeo_Handle *Seobeo_Stream_Handle_Client_Create(const char *host, const char* port, boolean use_tls); // --- Generate a Client Handle from given Server Handle. ---// extern Seobeo_Handle *Seobeo_Stream_Handle_Server_Accept(Seobeo_Handle *p_server_handle); // --- Web --- // /* Generate HTTP 1.1 Header value with given content_types and length. */ extern void Seobeo_Web_Header_Generate(void *buffer, int status, const char *content_type, const int content_length); /* Start a Generic HTTP static file server with given folder. It will store folder into memory. */ extern int Seobeo_Web_Server_Start(const char *folder_path, const char *port, Seobeo_ServerMode mode, int thread_count); /* Generic HTTP GET Rquest to given host and port with path. It will mimic chrome. */ extern int Seobeo_Web_Client_Get(const char *host, const char *port, const char *path); // --- Helper functions --- // /* Destroy handle. It will handle all NULL poointers. */ extern void Seobeo_Handle_Destroy(Seobeo_Handle *p_handle); /* Write to socket from write_buffer in the handle. */ extern int Seobeo_Handle_Flush(Seobeo_Handle *p_handle); /* Write to socket with given data source, if the data source is bigger than the write buffer for handle then we just directly write from the data source. */ extern int Seobeo_Handle_Queue(Seobeo_Handle *p_handle, const uint8_t *data, uint32_t data_size); /* Read to socket from read_buffer in the handle. */ extern int Seobeo_Handle_Read(Seobeo_Handle *p_handle); /* Move to read_buffer to front and we already consumed the given amount in the handle. */ extern void Seobeo_Handle_Consume(Seobeo_Handle *p_handle, uint32 consumed); /* Assign IP4 or IP6 to sockaddr. TODO: Maybe create my own struct for this? */ extern void *Seobeo_Get_IP4_Or_IP6(struct sockaddr *sa); #endif