annotate seobeo/seobeo_internal.h @ 106:daf2d393741a

Debugging in server.
author June Park <parkjune1995@gmail.com>
date Sat, 03 Jan 2026 10:46:58 -0800
parents 70401cf61e97
children c39582f937e5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
1 #ifndef SEOBEO_SERVER_INTERNAL_H
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
2 #define SEOBEO_SERVER_INTERNAL_H
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
3
67
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents: 66
diff changeset
4 #ifndef SEOBEO_NO_SSL
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents: 66
diff changeset
5 #include <openssl/ssl.h>
19
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
6 #include <openssl/err.h>
67
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents: 66
diff changeset
7 #define SSL_CTX_TYPE SSL_CTX
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents: 66
diff changeset
8 #define SSL_TYPE SSL
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents: 66
diff changeset
9 #else
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents: 66
diff changeset
10 #define SSL_CTX_TYPE void
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents: 66
diff changeset
11 #define SSL_TYPE void
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents: 66
diff changeset
12 #endif
19
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
13
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
14 #include "dowa/dowa.h"
96
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 72
diff changeset
15 #include <stdatomic.h>
19
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
16
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
17 typedef enum {
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
18 SEOBEO_STREAM_TYPE_SERVER,
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
19 SEOBEO_STREAM_TYPE_CLIENT,
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
20 } Seobeo_SocketType;
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
21
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
22 typedef struct {
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
23 int32 socket;
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
24 Seobeo_SocketType type;
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
25 boolean connected;
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
26
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
27 char *host;
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
28 char *port;
67
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents: 66
diff changeset
29
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents: 66
diff changeset
30 SSL_CTX_TYPE *ssl_ctx;
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents: 66
diff changeset
31 SSL_TYPE *ssl;
19
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
32
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
33 uint8 *read_buffer;
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
34 uint32 read_buffer_capacity;
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
35 uint32 read_buffer_len; // current size
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
36 uint32 read_buffer_used; // TODO: Implement this for client
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
37
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
38 uint8 *write_buffer;
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
39 uint32 write_buffer_capacity;
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
40 uint32 write_buffer_len; // current size
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
41
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
42 void *file;
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
43 void *text_copy;
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
44 char *file_name;
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
45
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
46 atomic_bool destroyed;
66
a0f0ad5e42eb [Misc] taking out capital P stuff.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
47 } Seobeo_Handle;
19
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
48
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.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
49 // HTML cache type: maps file paths (char*) to file contents (char*)
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.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
50 typedef Dowa_KV(char*, char*) Seobeo_Cache_Entry;
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.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
51
19
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
52 typedef struct {
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.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
53 Seobeo_Handle *srv;
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.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
54 Seobeo_Cache_Entry *cache;
19
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
55 } WorkerArgs;
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
56
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
57 typedef enum {
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
58 SEOBEO_MODE_FORK,
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
59 SEOBEO_MODE_EDGE,
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
60 } Seobeo_ServerMode;
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
61
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
62
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.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
63 // HTTP request map type: maps header names to header values
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.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
64 typedef Dowa_KV(char*, char*) Seobeo_Request_Entry;
19
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
65
72
4532ce6d9eb8 [Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents: 71
diff changeset
66 // --- Router Types --- //
4532ce6d9eb8 [Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents: 71
diff changeset
67 // Forward declaration
4532ce6d9eb8 [Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents: 71
diff changeset
68 typedef struct Seobeo_Route_Struct Seobeo_Route;
4532ce6d9eb8 [Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents: 71
diff changeset
69
4532ce6d9eb8 [Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents: 71
diff changeset
70 // Route handler function type
4532ce6d9eb8 [Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents: 71
diff changeset
71 typedef Seobeo_Request_Entry* (*Seobeo_Route_Handler)(
4532ce6d9eb8 [Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents: 71
diff changeset
72 Seobeo_Request_Entry *p_request_map,
4532ce6d9eb8 [Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents: 71
diff changeset
73 Dowa_Arena *p_arena
4532ce6d9eb8 [Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents: 71
diff changeset
74 );
4532ce6d9eb8 [Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents: 71
diff changeset
75
19
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
76 // --- Parse Header into Dowa Map ---//
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.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
77 extern int Seobeo_Web_Header_Parse(Seobeo_Handle *p_handle, Seobeo_Request_Entry **pp_map, Dowa_Arena *p_arena);
19
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
78
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
79 // --- Handle Request --- //
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.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
80 extern void Seobeo_Web_HandleClientRequest(Seobeo_Handle *cli, Seobeo_Cache_Entry *p_html_cache);
19
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
81
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
82 // --- SSL --- //
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
83 extern void Seobeo_Web_SSL_Init();
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
84 extern void Seobeo_Web_SSL_Cleanup(); // Not used
67
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents: 66
diff changeset
85 extern int Seobeo_SSL_Setup_Client(Seobeo_Handle *p_handle, const char *host, int socket_fd);
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents: 66
diff changeset
86 extern void Seobeo_SSL_Cleanup(Seobeo_Handle *p_handle);
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents: 66
diff changeset
87 extern int32 Seobeo_SSL_Write(Seobeo_Handle *p_handle, const uint8 *data, uint32 length);
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents: 66
diff changeset
88 extern int32 Seobeo_SSL_Read(Seobeo_Handle *p_handle, uint8 *buffer, uint32 length);
19
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
89
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
90 // --- Serving using Edge --- //
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.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
91 extern void *Seobeo_Web_Edge_Worker(void *vargs);
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.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
92 extern void Seobeo_Web_Edge(Seobeo_Handle *p_server_handle, int thread_count, Seobeo_Cache_Entry *p_html_cache);
19
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
93
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
94 #endif