comparison seobeo/seobeo.h @ 96:70401cf61e97

[Seobeo] Added logging.
author June Park <parkjune1995@gmail.com>
date Fri, 02 Jan 2026 19:16:17 -0800
parents 5710108c949e
children c39582f937e5
comparison
equal deleted inserted replaced
95:b51f8cce9170 96:70401cf61e97
6 * ------ 6 * ------
7 * 7 *
8 * Library for starting TCP, UDP server and serving static file or path. 8 * Library for starting TCP, UDP server and serving static file or path.
9 */ 9 */
10 10
11 // Define DIRECTORY before any includes to enable directory operations in dowa.h 11 #include "seobeo/seobeo_internal.h"
12 #ifndef DIRECTORY
13 #define DIRECTORY
14 #endif
15 12
16 #include <stdio.h> 13 /* Included in dowa
17 #include <stdlib.h> 14 #include <stdio.h>
15 #include <stdlib.h>
16 */
17 #include <stdarg.h>
18 #include <unistd.h> 18 #include <unistd.h>
19 #include <errno.h> 19 #include <errno.h>
20 #include <string.h> 20 #include <string.h>
21 #include <sys/types.h> 21 #include <sys/types.h>
22 #include <sys/socket.h> 22 #include <sys/socket.h>
25 #include <arpa/inet.h> 25 #include <arpa/inet.h>
26 #include <sys/wait.h> 26 #include <sys/wait.h>
27 #include <signal.h> 27 #include <signal.h>
28 #include <fcntl.h> 28 #include <fcntl.h>
29 #include <pthread.h> 29 #include <pthread.h>
30 #include <stdatomic.h>
31 #include <stdbool.h>
32 30
33 #include "seobeo/seobeo_internal.h"
34 31
35 #define INITIAL_BUFFER_CAPACITY 4096 32 #define INITIAL_BUFFER_CAPACITY 4096
36 33
37 // HTTP STATUS CODE 34 // HTTP STATUS CODE
38 #define HTTP_OK 200 35 #define HTTP_OK 200
71 extern void Seobeo_Web_Header_Generate(void *buffer, int status, const char *content_type, const int content_length); 68 extern void Seobeo_Web_Header_Generate(void *buffer, int status, const char *content_type, const int content_length);
72 /* Start a Generic HTTP static file server with given folder. It will store folder into memory. */ 69 /* Start a Generic HTTP static file server with given folder. It will store folder into memory. */
73 extern int Seobeo_Web_Server_Start(const char *folder_path, const char *port, Seobeo_ServerMode mode, int thread_count); 70 extern int Seobeo_Web_Server_Start(const char *folder_path, const char *port, Seobeo_ServerMode mode, int thread_count);
74 /* Generic HTTP GET Rquest to given host and port with path. It will mimic chrome. */ 71 /* Generic HTTP GET Rquest to given host and port with path. It will mimic chrome. */
75 extern int Seobeo_Web_Client_Get(const char *host, const char *port, const char *path); 72 extern int Seobeo_Web_Client_Get(const char *host, const char *port, const char *path);
76
77 // --- Router --- //
78 /* Initialize the router system (called automatically by Seobeo_Web_Server_Start) */ 73 /* Initialize the router system (called automatically by Seobeo_Web_Server_Start) */
79 extern void Seobeo_Router_Init(); 74 extern void Seobeo_Router_Init();
80 /* Register an API route handler. Call before starting server. */ 75 /* Register an API route handler. Call before starting server. */
81 extern void Seobeo_Router_Register(const char *method, const char *path_pattern, Seobeo_Route_Handler handler); 76 extern void Seobeo_Router_Register(const char *method, const char *path_pattern, Seobeo_Route_Handler handler);
82 /* Clean up router resources */ 77 /* Clean up router resources */
97 /* Read to socket from read_buffer in the handle. */ 92 /* Read to socket from read_buffer in the handle. */
98 extern int Seobeo_Handle_Read(Seobeo_Handle *p_handle); 93 extern int Seobeo_Handle_Read(Seobeo_Handle *p_handle);
99 /* Move to read_buffer to front and we already consumed the given amount in the handle. */ 94 /* Move to read_buffer to front and we already consumed the given amount in the handle. */
100 extern void Seobeo_Handle_Consume(Seobeo_Handle *p_handle, uint32 consumed); 95 extern void Seobeo_Handle_Consume(Seobeo_Handle *p_handle, uint32 consumed);
101 /* Assign IP4 or IP6 to sockaddr. TODO: Maybe create my own struct for this? */ 96 /* Assign IP4 or IP6 to sockaddr. TODO: Maybe create my own struct for this? */
102 extern void *Seobeo_Get_IP4_Or_IP6(struct sockaddr *sa); 97 extern void *Seobeo_Get_IP4_Or_IP6(struct sockaddr *sa);
98 /* Logging */
99 typedef enum {
100 SEOBEO_INFO = 0,
101 SEOBEO_WARNING,
102 SEOBEO_ERROR,
103 SEOBEO_DEBUG,
104 } Seobeo_Log_Level;
105 extern int Seobeo_Log(Seobeo_Log_Level level, const char *format, ...);
103 #endif 106 #endif