Mercurial
view seobeo/seobeo.h @ 61:9df5587cf23b
[Color game] It can compile on windows now.
| author | June Park <me@mrjunejune.com> |
|---|---|
| date | Sat, 20 Dec 2025 21:07:34 -0500 |
| parents | 84672efec192 |
| children | a30944e5719e |
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. */ #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_PHandle Seobeo_Stream_Handle_Server_Create(const char *host, const char* port); // --- Generate a Client Handle. ---// extern Seobeo_PHandle Seobeo_Stream_Handle_Client_Create(const char *host, const char* port, boolean use_tls); // --- Generate a Client Handle from given Server Handle. ---// extern Seobeo_PHandle Seobeo_Stream_Handle_Server_Accept(Seobeo_PHandle 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_PHandle p_handle); /* Write to socket from write_buffer in the handle. */ extern int Seobeo_Handle_Flush(Seobeo_PHandle 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_PHandle 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_PHandle p_handle); /* Move to read_buffer to front and we already consumed the given amount in the handle. */ extern void Seobeo_Handle_Consume(Seobeo_PHandle 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