annotate seobeo/seobeo_internal.h @ 85:0618addd5438

Updated so CSS and JS works for non root path.
author June Park <parkjune1995@gmail.com>
date Thu, 01 Jan 2026 13:16:30 -0800
parents 4532ce6d9eb8
children 70401cf61e97
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
64
a30944e5719e Added vibe coded markdown to html script since it is useful for me. Updated Dowa so that it can be compiled without dirnet for windows.
June Park <parkjune1995@gmail.com>
parents: 62
diff changeset
14 #ifndef DIRECTORY
a30944e5719e Added vibe coded markdown to html script since it is useful for me. Updated Dowa so that it can be compiled without dirnet for windows.
June Park <parkjune1995@gmail.com>
parents: 62
diff changeset
15 #define DIRECTORY
a30944e5719e Added vibe coded markdown to html script since it is useful for me. Updated Dowa so that it can be compiled without dirnet for windows.
June Park <parkjune1995@gmail.com>
parents: 62
diff changeset
16 #endif
19
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
17 #include "dowa/dowa.h"
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
18
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
19 typedef enum {
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
20 SEOBEO_STREAM_TYPE_SERVER,
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
21 SEOBEO_STREAM_TYPE_CLIENT,
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
22 } Seobeo_SocketType;
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
23
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
24 typedef struct {
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
25 int32 socket;
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
26 Seobeo_SocketType type;
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
27 boolean connected;
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
28
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
29 char *host;
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
30 char *port;
67
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents: 66
diff changeset
31
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents: 66
diff changeset
32 SSL_CTX_TYPE *ssl_ctx;
6626ec933933 [Seobeo] Separated out Client Server logic. Created test tools.
June Park <parkjune1995@gmail.com>
parents: 66
diff changeset
33 SSL_TYPE *ssl;
19
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
34
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
35 uint8 *read_buffer;
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
36 uint32 read_buffer_capacity;
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
37 uint32 read_buffer_len; // current size
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
38 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
39
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
40 uint8 *write_buffer;
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
41 uint32 write_buffer_capacity;
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
42 uint32 write_buffer_len; // current size
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
43
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
44 void *file;
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
45 void *text_copy;
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
46 char *file_name;
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
47
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
48 atomic_bool destroyed;
66
a0f0ad5e42eb [Misc] taking out capital P stuff.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
49 } Seobeo_Handle;
19
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
50
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
51 // 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
52 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
53
19
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
54 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
55 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
56 Seobeo_Cache_Entry *cache;
19
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
57 } WorkerArgs;
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
58
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
59 typedef enum {
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
60 SEOBEO_MODE_FORK,
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
61 SEOBEO_MODE_EDGE,
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
62 } Seobeo_ServerMode;
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
63
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
64
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
65 // 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
66 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
67
72
4532ce6d9eb8 [Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents: 71
diff changeset
68 // --- Router Types --- //
4532ce6d9eb8 [Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents: 71
diff changeset
69 // Forward declaration
4532ce6d9eb8 [Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents: 71
diff changeset
70 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
71
4532ce6d9eb8 [Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents: 71
diff changeset
72 // 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
73 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
74 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
75 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
76 );
4532ce6d9eb8 [Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents: 71
diff changeset
77
19
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
78 // --- 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
79 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
80
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
81 // --- 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
82 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
83
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
84 // --- SSL --- //
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
85 extern void Seobeo_Web_SSL_Init();
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
86 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
87 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
88 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
89 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
90 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
91
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
92 // --- 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
93 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
94 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
95
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 1
diff changeset
96 #endif