comparison seobeo/seobeo.h @ 6:1e61008b9980

[Seobeo] Updated seobeo so that API is more opinionated. Added my webpage./build.sh
author June Park <parkjune1995@gmail.com>
date Mon, 29 Sep 2025 16:00:44 -0700
parents 3e12bf044589
children 114cad94008f
comparison
equal deleted inserted replaced
5:3e12bf044589 6:1e61008b9980
21 21
22 #include "dowa/dowa.h" 22 #include "dowa/dowa.h"
23 23
24 #define INITIAL_BUFFER_CAPACITY 4096 24 #define INITIAL_BUFFER_CAPACITY 4096
25 25
26 // HTTP STATUS CODE
27 #define HTTP_OK 200
28 #define HTTP_CREATED 201
29 #define HTTP_MOVED_PERMANENTLY 301
30 #define HTTP_FOUND 302
31 #define HTTP_BAD_REQUEST 400
32 #define HTTP_UNAUTHORIZED 401
33 #define HTTP_FORBIDDEN 403
34 #define HTTP_NOT_FOUND 404
35 #define HTTP_INTERNAL_ERROR 500
36
26 typedef struct { 37 typedef struct {
27 int socket; 38 int socket;
28 char *host; 39 char *host;
29 char *port; 40 char *port;
30 41
31 uint8 *read_buffer; 42 uint8 *read_buffer;
32 uint32 read_buffer_capacity; 43 uint32 read_buffer_capacity;
33 uint32 read_buffer_len; // current size 44 uint32 read_buffer_len; // current size
34 uint32 read_buffer_pos; // TODO: Implement this for client 45 uint32 read_buffer_used; // TODO: Implement this for client
35 46
36 uint8 *write_buffer; 47 uint8 *write_buffer;
37 uint32 write_buffer_capacity; 48 uint32 write_buffer_capacity;
38 uint32 write_buffer_len; // current size 49 uint32 write_buffer_len; // current size
39 50
47 extern int Seobeo_CreateSocket(int32 stream, const char *host, const char* port, int32 backlog); 58 extern int Seobeo_CreateSocket(int32 stream, const char *host, const char* port, int32 backlog);
48 extern void *Seobeo_GetIP4OrIP6(struct sockaddr *sa); 59 extern void *Seobeo_GetIP4OrIP6(struct sockaddr *sa);
49 60
50 // --- TCP --- // 61 // --- TCP --- //
51 extern Seobeo_PHandle Seobeo_Stream_Handle_Create(const char *host, const char* port); 62 extern Seobeo_PHandle Seobeo_Stream_Handle_Create(const char *host, const char* port);
52 extern Seobeo_PHandle Seobeo_Stream_Handle_Accept(Seobeo_PHandle server_h); 63 extern Seobeo_PHandle Seobeo_Stream_Handle_Accept(Seobeo_PHandle p_server_handle);
64 extern int Seobeo_Stream_Handle_Read(Seobeo_PHandle p_handle);
65
66 // --- Web --- //
67 extern void Seobeo_Web_GenerateResponseHeader(void *buffer, int status, const char *content_type, const int content_length);
68 extern void Seobeo_Web_HandleClientRequest(Seobeo_PHandle cli, Dowa_PHashMap p_html_cache);
69 extern int Seobeo_Web_ParseClientHeader(Seobeo_PHandle p_handle, Dowa_PHashMap map);
70 extern int Seobeo_Web_StartBasicHTTPServer(const char *folder_path, const char *port);
53 71
54 // --- Helper functions --- // 72 // --- Helper functions --- //
55 extern void Seobeo_Handle_Destroy(Seobeo_PHandle h); 73 extern void Seobeo_Handle_Destroy(Seobeo_PHandle p_handle);
56 extern int Seobeo_Handle_Flush(Seobeo_PHandle h); 74 extern int Seobeo_Handle_Flush(Seobeo_PHandle p_handle);
57 extern int Seobeo_Handle_QueueData(Seobeo_PHandle h, const uint8_t *data, uint32_t data_size); 75 extern int Seobeo_Handle_Queue(Seobeo_PHandle p_handle, const uint8_t *data, uint32_t data_size);
76 extern int Seobeo_Handle_Read(Seobeo_PHandle p_handle);
77 extern void Seobeo_Handle_Consume(Seobeo_PHandle p_handle, uint32 consumed);
78
58 79
59 #endif 80 #endif