annotate seobeo/s_web.c @ 262:0f45474c1b1a

Add cyberpunk JRPG blog browser Show the latest posts in the JRPG preview and render the full blog archive and sanitized post details in the Inspect modal. Co-authored-by: Copilot <[email protected]>
author MrJuneJune <mrjunejune@users.noreply.github.com>
date Thu, 06 Aug 2026 04:08:45 -0700
parents 1f9877b637e9
children 04fee26ecce0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1 #include "seobeo/seobeo.h"
184
8c74204fd362 [MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
2 #include <strings.h>
8c74204fd362 [MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
3 #include <time.h>
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
4
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
5 static char g_folder_path[512] = ".";
260
1f9877b637e9 Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents: 257
diff changeset
6 static volatile sig_atomic_t g_server_stopping = 0;
1f9877b637e9 Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents: 257
diff changeset
7
1f9877b637e9 Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents: 257
diff changeset
8 void Seobeo_Web_Server_Stop(void)
1f9877b637e9 Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents: 257
diff changeset
9 {
1f9877b637e9 Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents: 257
diff changeset
10 g_server_stopping = 1;
1f9877b637e9 Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents: 257
diff changeset
11 }
1f9877b637e9 Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents: 257
diff changeset
12
1f9877b637e9 Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents: 257
diff changeset
13 boolean Seobeo_Web_Server_Is_Stopping(void)
1f9877b637e9 Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents: 257
diff changeset
14 {
1f9877b637e9 Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents: 257
diff changeset
15 return g_server_stopping ? TRUE : FALSE;
1f9877b637e9 Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents: 257
diff changeset
16 }
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
17
251
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
18 static boolean Seobeo_Static_Path_Is_Safe(const char *path)
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
19 {
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
20 if (!path || strchr(path, '\\'))
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
21 return FALSE;
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
22 const char *segment = path;
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
23 while (*segment)
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
24 {
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
25 while (*segment == '/')
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
26 segment++;
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
27 const char *end = segment;
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
28 while (*end && *end != '/')
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
29 end++;
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
30 if ((size_t)(end - segment) == 2 &&
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
31 segment[0] == '.' &&
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
32 segment[1] == '.')
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
33 return FALSE;
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
34 segment = end;
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
35 }
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
36 return TRUE;
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
37 }
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
38
244
b8aa08503378 [tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents: 242
diff changeset
39 static char *canonical_request_header(char *header)
b8aa08503378 [tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents: 242
diff changeset
40 {
b8aa08503378 [tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents: 242
diff changeset
41 if (strcasecmp(header, "content-length") == 0) return "Content-Length";
b8aa08503378 [tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents: 242
diff changeset
42 if (strcasecmp(header, "content-type") == 0) return "Content-Type";
b8aa08503378 [tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents: 242
diff changeset
43 if (strcasecmp(header, "connection") == 0) return "Connection";
b8aa08503378 [tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents: 242
diff changeset
44 if (strcasecmp(header, "authorization") == 0) return "Authorization";
b8aa08503378 [tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents: 242
diff changeset
45 if (strcasecmp(header, "host") == 0) return "Host";
b8aa08503378 [tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents: 242
diff changeset
46 if (strcasecmp(header, "upgrade") == 0) return "Upgrade";
b8aa08503378 [tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents: 242
diff changeset
47 if (strcasecmp(header, "x-real-ip") == 0) return "X-Real-IP";
b8aa08503378 [tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents: 242
diff changeset
48 if (strcasecmp(header, "sec-websocket-key") == 0) return "Sec-WebSocket-Key";
b8aa08503378 [tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents: 242
diff changeset
49 if (strcasecmp(header, "sec-websocket-version") == 0) return "Sec-WebSocket-Version";
b8aa08503378 [tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents: 242
diff changeset
50 return header;
b8aa08503378 [tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents: 242
diff changeset
51 }
b8aa08503378 [tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents: 242
diff changeset
52
77
c348ac875294 [Seobeo] Server side rendering.
June Park <parkjune1995@gmail.com>
parents: 76
diff changeset
53 char* Seobeo_Web_LoadFile(const char *file_path, size_t *p_file_size)
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
54 {
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 char full_path[1024];
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 snprintf(full_path, sizeof(full_path), "%s/%s", g_folder_path, file_path);
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
57
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
58 FILE *p_file = fopen(full_path, "rb");
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
59 if (!p_file)
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
60 return NULL;
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
61
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
62 fseek(p_file, 0, SEEK_END);
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 size_t file_size = ftell(p_file);
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 fseek(p_file, 0, SEEK_SET);
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
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 char *p_content = (char*)malloc(file_size + 1);
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
67 if (!p_content)
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
68 {
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
69 fclose(p_file);
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
70 return NULL;
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
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
72
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
73 fread(p_content, 1, file_size, p_file);
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
74 p_content[file_size] = '\0';
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
75 fclose(p_file);
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
76
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 if (p_file_size)
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
78 *p_file_size = file_size;
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
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 return p_content;
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
81 }
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
76
35b1abc37969 Updating my website to use seobeo library.
June Park <parkjune1995@gmail.com>
parents: 72
diff changeset
83 void Seobeo_Web_Header_Generate(
35b1abc37969 Updating my website to use seobeo library.
June Park <parkjune1995@gmail.com>
parents: 72
diff changeset
84 void *buffer, int status,
35b1abc37969 Updating my website to use seobeo library.
June Park <parkjune1995@gmail.com>
parents: 72
diff changeset
85 const char *content_type, const int content_length)
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
86 {
183
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
87 Seobeo_Web_Header_Generate_KeepAlive(buffer, status, content_type, content_length, FALSE);
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
88 }
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
89
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
90 void Seobeo_Web_Header_Generate_KeepAlive(
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
91 void *buffer, int status,
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
92 const char *content_type, const int content_length,
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
93 boolean keep_alive)
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
94 {
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
95 const char *status_text;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
96 switch(status)
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
97 {
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
98 case HTTP_OK: status_text = "OK"; break;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
99 case HTTP_CREATED: status_text = "Created"; break;
223
0e7b9464248d [hg-web] Add browser route regression coverage
MrJuneJune <me@mrjunejune.com>
parents: 221
diff changeset
100 case HTTP_NO_CONTENT: status_text = "No Content"; break;
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
101 case HTTP_MOVED_PERMANENTLY: status_text = "Moved Permanently"; break;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
102 case HTTP_FOUND: status_text = "Found"; break;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
103 case HTTP_BAD_REQUEST: status_text = "Bad Request"; break;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
104 case HTTP_UNAUTHORIZED: status_text = "Unauthorized"; break;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
105 case HTTP_FORBIDDEN: status_text = "Forbidden"; break;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
106 case HTTP_NOT_FOUND: status_text = "Not Found"; break;
244
b8aa08503378 [tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents: 242
diff changeset
107 case HTTP_PAYLOAD_TOO_LARGE: status_text = "Content Too Large"; break;
b8aa08503378 [tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents: 242
diff changeset
108 case HTTP_UNPROCESSABLE_CONTENT: status_text = "Unprocessable Content"; break;
b8aa08503378 [tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents: 242
diff changeset
109 case HTTP_TOO_MANY_REQUESTS: status_text = "Too Many Requests"; break;
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
110 case HTTP_INTERNAL_ERROR: status_text = "Internal Server Error"; break;
244
b8aa08503378 [tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents: 242
diff changeset
111 case HTTP_SERVICE_UNAVAILABLE: status_text = "Service Unavailable"; break;
221
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
112 case 502: status_text = "Bad Gateway"; break;
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
113 case 504: status_text = "Gateway Timeout"; break;
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
114 default: status_text = "Unknown"; break;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
115 }
183
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
116
221
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
117 snprintf(
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
118 (char*)buffer, 1024,
18
fa2b8af609d9 [Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents: 17
diff changeset
119 "HTTP/1.1 %d %s\r\n"
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
120 "Content-Type: %s\r\n"
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
121 "Content-Length: %d\r\n"
183
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
122 "Connection: %s\r\n"
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
123 "\r\n",
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
124 status, status_text, content_type, content_length,
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
125 keep_alive ? "keep-alive" : "close"
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
126 );
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
127 }
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
128
183
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
129 // Default arena size (5MB) - will allocate more if Content-Length requires it
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
130 #define DEFAULT_ARENA_SIZE (5 * 1024 * 1024)
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
131
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
132 // Helper to check if Connection header contains a specific value (case-insensitive)
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
133 static boolean connection_header_contains(const char *header_value, const char *target)
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
134 {
183
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
135 if (!header_value || !target) return FALSE;
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
136
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
137 // Make a copy to tokenize
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
138 char *copy = strdup(header_value);
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
139 if (!copy) return FALSE;
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
140
183
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
141 boolean found = FALSE;
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
142 char *token = strtok(copy, ", \t");
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
143 while (token) {
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
144 if (strcasecmp(token, target) == 0) {
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
145 found = TRUE;
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
146 break;
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
147 }
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
148 token = strtok(NULL, ", \t");
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
149 }
257
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
150 Dowa_Free(copy);
183
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
151 return found;
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
152 }
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
153
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
154 // Returns TRUE if connection should be kept alive, FALSE if it should be closed
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
155 boolean Seobeo_Web_ClientHandle_Request(Seobeo_Handle *p_cli_handle,
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
156 Seobeo_Cache_Entry *p_html_cache,
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
157 boolean use_keep_alive)
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
158 {
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
159 boolean should_keep_alive = FALSE;
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
160
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
161 // Start with default arena size (5MB)
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
162 size_t arena_size = DEFAULT_ARENA_SIZE;
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
163
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
164 // We'll peek at Content-Length to potentially allocate larger arena
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
165 // For now, start with default and handle body reading separately
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
166 Dowa_Arena *p_request_arena = Dowa_Arena_Create(arena_size);
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
167 if (!p_request_arena) { perror("Dowa_Arena_Create request"); return FALSE; }
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
168
260
1f9877b637e9 Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents: 257
diff changeset
169 Dowa_Arena *p_response_arena = Dowa_Arena_Create(1024 * 1024 * 16);
183
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
170 if (!p_response_arena) { perror("Dowa_Arena_Create response"); Dowa_Arena_Free(p_request_arena); return FALSE; }
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
171
124
dbf14f84d51c Refactor Seobeo and mrjunejune build files so it works.
June Park <parkjune1995@gmail.com>
parents: 121
diff changeset
172 void *p_response_header = Dowa_Arena_Allocate(p_response_arena, 1024*5); // 5Kb
183
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
173 if (!p_response_header) { perror("Dowa_Arena_Allocate"); goto clean_up_arenas; }
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
174
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
175 Seobeo_Request_Entry *p_req_map = NULL;
92
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
176 int parse_result = Seobeo_Web_Header_Parse(p_cli_handle, &p_req_map, p_request_arena);
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
177
183
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
178 // Handle parse errors
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
179 if (parse_result < 0) {
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
180 // Fatal error or connection closed
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
181 Seobeo_Log(SEOBEO_DEBUG, "Seobeo_Web_Header_Parse failed with code %d\n", parse_result);
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
182 if (parse_result == -2) {
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
183 // Connection closed by client - don't send error response
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
184 goto clean_up_arenas;
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
185 }
19
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 18
diff changeset
186 Seobeo_Web_Header_Generate(p_response_header,
22
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
187 HTTP_BAD_REQUEST,
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
188 "text/plain", 0);
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
189 Seobeo_Handle_Queue(p_cli_handle,
22
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
190 (const uint8*)p_response_header,
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
191 (uint32)strlen(p_response_header));
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
192 Seobeo_Handle_Flush(p_cli_handle);
183
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
193 goto clean_up_arenas;
22
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
194 }
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
195
183
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
196 // Determine keep-alive based on HTTP version and Connection header
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
197 // HTTP/1.1: keep-alive by default unless "Connection: close"
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
198 // HTTP/1.0: close by default unless "Connection: keep-alive"
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
199
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
200 void *p_ver_kv = Dowa_HashMap_Get_Ptr(p_req_map, "Version");
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
201 const char *http_version = p_ver_kv ? ((Seobeo_Request_Entry*)p_ver_kv)->value : "HTTP/1.0";
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
202 boolean is_http11 = (strstr(http_version, "1.1") != NULL);
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
203
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
204 void *p_conn_kv = Dowa_HashMap_Get_Ptr(p_req_map, "Connection");
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
205 const char *conn_header = p_conn_kv ? ((Seobeo_Request_Entry*)p_conn_kv)->value : NULL;
101
3468e2fe8d88 [Seobeo] log ngnix proxy values (for myself). took out unneeded stuff fflush.
June Park <parkjune1995@gmail.com>
parents: 100
diff changeset
206
3468e2fe8d88 [Seobeo] log ngnix proxy values (for myself). took out unneeded stuff fflush.
June Park <parkjune1995@gmail.com>
parents: 100
diff changeset
207 void *p_real_ip_kv = Dowa_HashMap_Get_Ptr(p_req_map, "X-Real-IP");
3468e2fe8d88 [Seobeo] log ngnix proxy values (for myself). took out unneeded stuff fflush.
June Park <parkjune1995@gmail.com>
parents: 100
diff changeset
208 const char *real_ip = p_real_ip_kv ? ((Seobeo_Request_Entry*)p_real_ip_kv)->value : NULL;
3468e2fe8d88 [Seobeo] log ngnix proxy values (for myself). took out unneeded stuff fflush.
June Park <parkjune1995@gmail.com>
parents: 100
diff changeset
209 if (!real_ip)
3468e2fe8d88 [Seobeo] log ngnix proxy values (for myself). took out unneeded stuff fflush.
June Park <parkjune1995@gmail.com>
parents: 100
diff changeset
210 real_ip = p_cli_handle->host;
92
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
211
184
8c74204fd362 [MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
212 if (conn_header)
8c74204fd362 [MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
213 {
8c74204fd362 [MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
214 if (connection_header_contains(conn_header, "close"))
183
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
215 should_keep_alive = FALSE;
184
8c74204fd362 [MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
216 else if (connection_header_contains(conn_header, "keep-alive"))
183
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
217 should_keep_alive = use_keep_alive;
184
8c74204fd362 [MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
218 else
8c74204fd362 [MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
219 should_keep_alive = is_http11 && use_keep_alive; // Unknown value, use version default
8c74204fd362 [MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
220 }
8c74204fd362 [MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
221 else
183
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
222 should_keep_alive = is_http11 && use_keep_alive;
92
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
223
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
224 void *p_method_kv = Dowa_HashMap_Get_Ptr(p_req_map, "HTTP_Method");
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
225 const char *method = p_method_kv ? ((Seobeo_Request_Entry*)p_method_kv)->value : NULL;
22
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
226
183
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
227 void *p_path_kv = Dowa_HashMap_Get_Ptr(p_req_map, "Path");
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
228 const char *path = p_path_kv ? ((Seobeo_Request_Entry*)p_path_kv)->value : "/";
92
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
229
22
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
230 if (!method)
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
231 {
183
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
232 Seobeo_Log(SEOBEO_DEBUG, "No HTTP method found in request\n");
22
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
233 Seobeo_Web_Header_Generate(p_response_header,
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
234 HTTP_BAD_REQUEST,
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
235 "text/plain", 0);
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
236 Seobeo_Handle_Queue(p_cli_handle,
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
237 (const uint8*)p_response_header,
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
238 (uint32)strlen(p_response_header));
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
239 Seobeo_Handle_Flush(p_cli_handle);
183
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
240 should_keep_alive = FALSE;
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
241 goto clean_up_arenas;
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
242 }
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
243
121
7b1719fa918c [Seobeo] Added web socket server.
June Park <parkjune1995@gmail.com>
parents: 119
diff changeset
244 // --- Check for WebSocket upgrade request ---
124
dbf14f84d51c Refactor Seobeo and mrjunejune build files so it works.
June Park <parkjune1995@gmail.com>
parents: 121
diff changeset
245 #ifdef SEOBEO_WEBSOCKET_SERVER
175
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
246 Seobeo_Log(SEOBEO_DEBUG, "Web socket path \n");
121
7b1719fa918c [Seobeo] Added web socket server.
June Park <parkjune1995@gmail.com>
parents: 119
diff changeset
247 if (Seobeo_WebSocket_Server_Handle_Upgrade(p_cli_handle, p_req_map, path))
7b1719fa918c [Seobeo] Added web socket server.
June Park <parkjune1995@gmail.com>
parents: 119
diff changeset
248 {
7b1719fa918c [Seobeo] Added web socket server.
June Park <parkjune1995@gmail.com>
parents: 119
diff changeset
249 Seobeo_Log(SEOBEO_INFO, "WebSocket connection established\n");
183
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
250 Dowa_Arena_Free(p_request_arena);
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
251 Dowa_Arena_Free(p_response_arena);
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
252 return FALSE; // WebSocket takes over, don't keep-alive in HTTP sense
121
7b1719fa918c [Seobeo] Added web socket server.
June Park <parkjune1995@gmail.com>
parents: 119
diff changeset
253 }
124
dbf14f84d51c Refactor Seobeo and mrjunejune build files so it works.
June Park <parkjune1995@gmail.com>
parents: 121
diff changeset
254 #endif
121
7b1719fa918c [Seobeo] Added web socket server.
June Park <parkjune1995@gmail.com>
parents: 119
diff changeset
255
175
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
256 // --- Try to match streaming route first ---
257
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
257 Seobeo_SSE_Handler sse_handler = Seobeo_Router_Find_SSE_Handler(
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
258 method,
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
259 path,
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
260 &p_req_map,
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
261 p_request_arena);
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
262 if (sse_handler != NULL)
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
263 {
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
264 Seobeo_SSE_Stream *p_stream = Seobeo_SSE_Server_Attach(
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
265 p_cli_handle,
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
266 path);
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
267 if (p_stream)
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
268 {
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
269 sse_handler(p_stream, p_req_map, p_response_arena);
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
270 should_keep_alive = Seobeo_SSE_Is_Open(p_stream);
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
271 }
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
272 else
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
273 {
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
274 should_keep_alive = FALSE;
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
275 }
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
276 goto clean_up_arenas;
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
277 }
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
278
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
279 // --- Try to match generic streaming route ---
175
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
280 Seobeo_Stream_Handler stream_handler = Seobeo_Router_Find_Stream_Handler(method, path, &p_req_map, p_request_arena);
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
281 if (stream_handler != NULL)
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
282 {
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
283 stream_handler(p_cli_handle, p_req_map, p_response_arena);
260
1f9877b637e9 Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents: 257
diff changeset
284 should_keep_alive = p_cli_handle->is_sse;
187
a69485d9f2e1 Fixed a small bug.
MrJuneJune <me@mrjunejune.com>
parents: 186
diff changeset
285 goto clean_up_arenas;
175
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
286 }
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
287
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
288 // --- Try to match API route ---
72
4532ce6d9eb8 [Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents: 71
diff changeset
289 Seobeo_Route_Handler handler = Seobeo_Router_Find_Handler(method, path, &p_req_map, p_request_arena);
4532ce6d9eb8 [Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents: 71
diff changeset
290 if (handler != NULL)
4532ce6d9eb8 [Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents: 71
diff changeset
291 {
4532ce6d9eb8 [Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents: 71
diff changeset
292 Seobeo_Request_Entry *p_response_map = handler(p_req_map, p_response_arena);
183
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
293 Seobeo_Router_Send_Response_KeepAlive(p_cli_handle, p_response_map, p_response_arena, should_keep_alive);
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
294 goto clean_up_arenas;
72
4532ce6d9eb8 [Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents: 71
diff changeset
295 }
4532ce6d9eb8 [Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents: 71
diff changeset
296
183
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
297 // --- Static files fallback for GET (use original large arena logic) ---
22
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
298 if (strcmp(method, "GET") == 0)
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
299 {
251
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
300 if (!Seobeo_Static_Path_Is_Safe(path))
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
301 {
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
302 Seobeo_Web_Header_Generate_KeepAlive(
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
303 p_response_header,
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
304 HTTP_BAD_REQUEST,
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
305 "text/plain",
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
306 0,
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
307 should_keep_alive);
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
308 Seobeo_Handle_Queue(
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
309 p_cli_handle,
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
310 (const uint8 *)p_response_header,
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
311 (uint32)strlen(p_response_header));
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
312 Seobeo_Handle_Flush(p_cli_handle);
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
313 goto clean_up_arenas;
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
314 }
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
315
183
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
316 char *file_path = Dowa_Arena_Allocate(p_response_arena, (size_t)5 * 1024);
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
317
22
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
318 if (!path || strcmp(path, "/") == 0)
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
319 {
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
320 strcpy(file_path, "index.html");
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
321 }
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
322 else
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
323 {
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
324 size_t L = strlen(path);
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
325 if (path[0] == '/')
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
326 {
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
327 if (strchr(path, '.') == NULL)
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
328 snprintf(file_path, 512, "%.*s/index.html", (int)(L-1), path+1);
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
329 else
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
330 snprintf(file_path, 512, "%.*s", (int)(L-1), path+1);
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
331 }
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
332 else
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
333 strcpy(file_path, path);
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
334 }
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
335
251
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
336 char *file_content = NULL;
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
337 size_t body_size = 0;
251
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
338 (void)p_html_cache;
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
339 file_content = Seobeo_Web_LoadFile(file_path, &body_size);
22
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
340
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
341 if (!file_content)
22
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
342 {
183
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
343 Seobeo_Web_Header_Generate_KeepAlive(p_response_header,
22
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
344 HTTP_NOT_FOUND,
183
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
345 "text/html", 0, should_keep_alive);
18
fa2b8af609d9 [Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents: 17
diff changeset
346 Seobeo_Handle_Queue(p_cli_handle,
22
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
347 (const uint8*)p_response_header,
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
348 (uint32)strlen(p_response_header));
18
fa2b8af609d9 [Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents: 17
diff changeset
349 Seobeo_Handle_Flush(p_cli_handle);
183
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
350 goto clean_up_arenas;
18
fa2b8af609d9 [Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents: 17
diff changeset
351 }
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
352
22
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
353 const char *mime = "application/octet-stream";
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
354 if (strstr(file_path, ".html")) mime = "text/html; charset=utf-8";
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
355 else if (strstr(file_path, ".css")) mime = "text/css";
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
356 else if (strstr(file_path, ".js")) mime = "application/javascript";
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
357 else if (strstr(file_path, ".png")) mime = "image/png";
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
358 else if (strstr(file_path, ".jpg") || strstr(file_path, ".jpeg")) mime = "image/jpeg";
184
8c74204fd362 [MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
359 else if (strstr(file_path, ".gif")) mime = "image/gif";
8c74204fd362 [MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
360 else if (strstr(file_path, ".svg")) mime = "image/svg+xml";
8c74204fd362 [MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
361 else if (strstr(file_path, ".ico")) mime = "image/x-icon";
8c74204fd362 [MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
362 else if (strstr(file_path, ".webp")) mime = "image/webp";
22
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
363 else if (strstr(file_path, ".json")) mime = "application/json";
184
8c74204fd362 [MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
364 else if (strstr(file_path, ".wasm")) mime = "application/wasm";
8c74204fd362 [MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
365 else if (strstr(file_path, ".xml")) mime = "application/xml";
8c74204fd362 [MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
366 else if (strstr(file_path, ".pdf")) mime = "application/pdf";
8c74204fd362 [MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
367 else if (strstr(file_path, ".txt")) mime = "text/plain";
242
543df0fe7168 [tools] Add full HLS player support
MrJuneJune <me@mrjunejune.com>
parents: 223
diff changeset
368 else if (strstr(file_path, ".m3u8")) mime = "application/vnd.apple.mpegurl";
543df0fe7168 [tools] Add full HLS player support
MrJuneJune <me@mrjunejune.com>
parents: 223
diff changeset
369 else if (strstr(file_path, ".m4s")) mime = "video/iso.segment";
543df0fe7168 [tools] Add full HLS player support
MrJuneJune <me@mrjunejune.com>
parents: 223
diff changeset
370 else if (strstr(file_path, ".ts")) mime = "video/mp2t";
184
8c74204fd362 [MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
371 else if (strstr(file_path, ".mp4")) mime = "video/mp4";
8c74204fd362 [MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
372 else if (strstr(file_path, ".webm")) mime = "video/webm";
8c74204fd362 [MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
373 else if (strstr(file_path, ".mp3")) mime = "audio/mpeg";
8c74204fd362 [MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
374 else if (strstr(file_path, ".woff2")) mime = "font/woff2";
8c74204fd362 [MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
375 else if (strstr(file_path, ".woff")) mime = "font/woff";
8c74204fd362 [MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
376 else if (strstr(file_path, ".ttf")) mime = "font/ttf";
8c74204fd362 [MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
377 else if (strstr(file_path, ".webp")) mime = "image/webp";
8c74204fd362 [MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
378 else if (strstr(file_path, ".glb")) mime = "model/gltf-binary";
8c74204fd362 [MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
379 else if (strstr(file_path, ".gltf")) mime = "model/gltf+json";
8c74204fd362 [MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents: 183
diff changeset
380
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
381
183
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
382 Seobeo_Web_Header_Generate_KeepAlive(p_response_header,
22
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
383 HTTP_OK,
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
384 mime,
183
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
385 body_size, should_keep_alive);
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
386
22
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
387 Seobeo_Handle_Queue(p_cli_handle,
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
388 (const uint8*)p_response_header,
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
389 (uint32)strlen(p_response_header));
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
390 Seobeo_Handle_Queue(p_cli_handle,
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
391 (const uint8*)file_content,
22
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
392 (uint32)body_size);
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
393 Seobeo_Handle_Flush(p_cli_handle);
257
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
394 Dowa_Free(file_content);
22
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
395 }
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
396 else
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
397 {
183
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
398 Seobeo_Web_Header_Generate_KeepAlive(p_response_header,
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
399 HTTP_NOT_FOUND,
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
400 "text/plain", 0, should_keep_alive);
22
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
401 Seobeo_Handle_Queue(p_cli_handle,
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
402 (const uint8*)p_response_header,
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
403 (uint32)strlen(p_response_header));
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
404 Seobeo_Handle_Flush(p_cli_handle);
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
405 }
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
406
183
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
407 clean_up_arenas:
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
408 if (p_request_arena)
72
4532ce6d9eb8 [Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents: 71
diff changeset
409 Dowa_Arena_Free(p_request_arena);
62
ea9ef388ab97 [Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
410 if (p_response_arena)
72
4532ce6d9eb8 [Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents: 71
diff changeset
411 Dowa_Arena_Free(p_response_arena);
183
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
412 return should_keep_alive;
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
413 }
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
414
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
415 int Seobeo_Web_Header_Parse(Seobeo_Handle *p_handle, Seobeo_Request_Entry **pp_map, Dowa_Arena *p_arena)
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
416 {
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
417 while (1)
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
418 {
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
419 int r = Seobeo_Handle_Read(p_handle);
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
420 if (r < 0)
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
421 return -1; // fatal error
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
422 if (r == -2)
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
423 return -2; // connection closed TODO: Add this as part of Handle struct.
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
424
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
425 if (p_handle->read_buffer_len >= 4 &&
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
426 strstr((char*)p_handle->read_buffer, "\r\n\r\n") != NULL)
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
427 break;
110
99c4530e4629 [Seobeo] Small Syntax fixes.
June Park <parkjune1995@gmail.com>
parents: 101
diff changeset
428
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
429 if (r == 0)
175
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
430 {
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
431 Seobeo_Log(SEOBEO_INFO, "Waiting?\n");
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
432 continue; // EAGAIN, try again later TODO: Add this as part of Handle struct.
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
433 }
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
434 }
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
435
110
99c4530e4629 [Seobeo] Small Syntax fixes.
June Park <parkjune1995@gmail.com>
parents: 101
diff changeset
436 // "METHOD SP PATH SP VERSION CRLF"
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
437 char *buf = (char*)p_handle->read_buffer;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
438 char *hdr_end = strstr(buf, "\r\n\r\n");
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
439 size_t hdr_len = hdr_end - buf + 4;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
440
92
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
441 // Debug: Print the first line of the request
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
442 char *first_line_end = strstr(buf, "\r\n");
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
443 if (first_line_end)
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
444 {
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
445 size_t first_line_len = first_line_end - buf;
96
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
446 Seobeo_Log(SEOBEO_DEBUG, "Request line (first %zu bytes)\n", first_line_len > 200 ? 200 : first_line_len);
92
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
447 }
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
448
22
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
449 // This seems kinda bad ?
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
450 char method[16], path[256], version[16];
92
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
451 int scan_result = sscanf(buf, "%15s %255s %15s", method, path, version);
96
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
452 Seobeo_Log(SEOBEO_DEBUG, "sscanf returned %d (method='%s', path='%s', version='%s')\n",
92
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
453 scan_result,
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
454 scan_result >= 1 ? method : "N/A",
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
455 scan_result >= 2 ? path : "N/A",
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
456 scan_result >= 3 ? version : "N/A");
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
457
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
458 if (scan_result != 3)
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
459 {
96
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
460 Seobeo_Log(SEOBEO_ERROR, "Failed to parse request line\n");
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
461 return -1;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
462 }
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
463
96
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
464 Seobeo_Log(SEOBEO_DEBUG, "Allocating method_copy\n");
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
465 char *method_copy = Dowa_Arena_Allocate(p_arena, strlen(method) + 1);
96
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
466 if (!method_copy) { Seobeo_Log(SEOBEO_ERROR, "Failed to allocate method_copy\n"); return -1; }
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
467 strcpy(method_copy, method);
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
468
96
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
469 Seobeo_Log(SEOBEO_DEBUG, "Allocating version_copy\n");
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
470 char *version_copy = Dowa_Arena_Allocate(p_arena, strlen(version) + 1);
96
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
471 if (!version_copy) { Seobeo_Log(SEOBEO_ERROR, "Failed to allocate version_copy\n"); return -1; }
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
472 strcpy(version_copy, version);
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
473
96
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
474 Seobeo_Log(SEOBEO_DEBUG, "Pushing HTTP_Method and Version to map\n");
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
475 Dowa_HashMap_Push_Arena(*pp_map, "HTTP_Method", method_copy, p_arena);
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
476 Dowa_HashMap_Push_Arena(*pp_map, "Version", version_copy, p_arena);
96
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
477 Seobeo_Log(SEOBEO_DEBUG, "Map now has %zu entries\n", Dowa_Array_Length(*pp_map));
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
478
22
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
479 char *raw_path = path;
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
480 char *query_start = strchr(raw_path, '?');
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
481 char *query_str = NULL;
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
482
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
483 if (query_start)
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
484 {
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
485 *query_start = '\0'; // now raw_path ends before '?'
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
486 query_str = query_start + 1;
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
487 }
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
488
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
489 char *path_copy = Dowa_Arena_Allocate(p_arena, strlen(raw_path) + 1);
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
490 if (!path_copy) return -1;
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
491 strcpy(path_copy, raw_path);
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
492 Dowa_HashMap_Push_Arena(*pp_map, "Path", path_copy, p_arena);
135
ffb764d2fcc5 [HgWeb] Updated hg web so it works
June Park <parkjune1995@gmail.com>
parents: 132
diff changeset
493
ffb764d2fcc5 [HgWeb] Updated hg web so it works
June Park <parkjune1995@gmail.com>
parents: 132
diff changeset
494 // Store full query string for proxying
ffb764d2fcc5 [HgWeb] Updated hg web so it works
June Park <parkjune1995@gmail.com>
parents: 132
diff changeset
495 if (query_str && *query_str)
ffb764d2fcc5 [HgWeb] Updated hg web so it works
June Park <parkjune1995@gmail.com>
parents: 132
diff changeset
496 {
ffb764d2fcc5 [HgWeb] Updated hg web so it works
June Park <parkjune1995@gmail.com>
parents: 132
diff changeset
497 char *qs_copy = Dowa_Arena_Allocate(p_arena, strlen(query_str) + 1);
ffb764d2fcc5 [HgWeb] Updated hg web so it works
June Park <parkjune1995@gmail.com>
parents: 132
diff changeset
498 if (qs_copy)
ffb764d2fcc5 [HgWeb] Updated hg web so it works
June Park <parkjune1995@gmail.com>
parents: 132
diff changeset
499 {
ffb764d2fcc5 [HgWeb] Updated hg web so it works
June Park <parkjune1995@gmail.com>
parents: 132
diff changeset
500 strcpy(qs_copy, query_str);
ffb764d2fcc5 [HgWeb] Updated hg web so it works
June Park <parkjune1995@gmail.com>
parents: 132
diff changeset
501 Dowa_HashMap_Push_Arena(*pp_map, "QueryString", qs_copy, p_arena);
ffb764d2fcc5 [HgWeb] Updated hg web so it works
June Park <parkjune1995@gmail.com>
parents: 132
diff changeset
502 }
ffb764d2fcc5 [HgWeb] Updated hg web so it works
June Park <parkjune1995@gmail.com>
parents: 132
diff changeset
503 }
ffb764d2fcc5 [HgWeb] Updated hg web so it works
June Park <parkjune1995@gmail.com>
parents: 132
diff changeset
504
110
99c4530e4629 [Seobeo] Small Syntax fixes.
June Park <parkjune1995@gmail.com>
parents: 101
diff changeset
505 // GET Params
22
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
506 if (query_str && *query_str)
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
507 {
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
508 char *cur = query_str;
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
509 while (cur && *cur)
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
510 {
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
511 char *next_amp = strchr(cur, '&');
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
512 char *pair_end = next_amp ? next_amp : cur + strlen(cur);
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
513
22
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
514 char *eq = memchr(cur, '=', pair_end - cur);
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
515 if (eq)
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
516 {
22
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
517 size_t key_len = eq - cur;
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
518 size_t val_len = pair_end - (eq + 1);
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
519
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
520 char key_buf[256];
110
99c4530e4629 [Seobeo] Small Syntax fixes.
June Park <parkjune1995@gmail.com>
parents: 101
diff changeset
521 // Adding query_ in front to separate GET params
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
522 snprintf(key_buf, sizeof(key_buf), "query_%.*s", (int)key_len, cur);
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
523
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
524 char *val_copy = Dowa_Arena_Allocate(p_arena, val_len + 1);
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
525 if (!val_copy) return -1;
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
526 memcpy(val_copy, eq + 1, val_len);
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
527 val_copy[val_len] = '\0';
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
528
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
529 Dowa_HashMap_Push_Arena(*pp_map, key_buf, val_copy, p_arena);
22
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
530 }
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
531
22
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
532 cur = next_amp ? next_amp + 1 : NULL;
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
533 }
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
534 }
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
535
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
536 // int qp = Dowa_HashMap_Get_Position(map, "QueryParams");
65
ecb6ee6a22c3 [Misc] I will no longer drink cool aids of capital P.
June Park <parkjune1995@gmail.com>
parents: 62
diff changeset
537 // Dowa_HashEntry *p_qp_entry = map->entries[qp];
22
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
538 // printf("query param key: %s\n", p_qp_entry->key);
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
539 // printf("query param value: %s\n",(char *)Dowa_HashMap_Get(p_qp_entry->buffer, "hello"));
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
540
110
99c4530e4629 [Seobeo] Small Syntax fixes.
June Park <parkjune1995@gmail.com>
parents: 101
diff changeset
541 // Parse headers
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
542 char *line = buf + strlen(method) + 1 + strlen(path) + 1 + strlen(version) + 2;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
543 while (line < hdr_end)
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
544 {
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
545 char *next = strstr(line, "\r\n");
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
546 if (!next) break;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
547
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
548 char *colon = memchr(line, ':', next - line);
22
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
549 if (colon)
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
550 {
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
551 size_t key_len = colon - line;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
552 size_t value_len = next - colon - 1;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
553
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
554 char *val_start = colon + 1;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
555 if (*val_start == ' ')
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
556 {
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
557 val_start++;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
558 value_len--;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
559 }
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
560
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
561 char *key = Dowa_Arena_Allocate(p_arena, key_len + 1);
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
562 if (!key) return -1;
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
563 memcpy(key, line, key_len);
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
564 key[key_len] = '\0';
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
565
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
566 char *val = Dowa_Arena_Allocate(p_arena, value_len + 1);
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
567 if (!val) return -1;
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
568 memcpy(val, val_start, value_len);
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
569 val[value_len] = '\0';
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
570
244
b8aa08503378 [tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents: 242
diff changeset
571 Dowa_HashMap_Push_Arena(
b8aa08503378 [tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents: 242
diff changeset
572 *pp_map,
b8aa08503378 [tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents: 242
diff changeset
573 canonical_request_header(key),
b8aa08503378 [tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents: 242
diff changeset
574 val,
b8aa08503378 [tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents: 242
diff changeset
575 p_arena);
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
576 }
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
577
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
578 line = next + 2;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
579 }
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
580
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
581 Seobeo_Handle_Consume(p_handle, (uint32)hdr_len);
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
582
110
99c4530e4629 [Seobeo] Small Syntax fixes.
June Park <parkjune1995@gmail.com>
parents: 101
diff changeset
583 // Reading Body
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
584 void *p_cl_kv = Dowa_HashMap_Get_Ptr(*pp_map, "Content-Length");
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
585 if (p_cl_kv)
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
586 {
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
587 const char *content_length_str = ((Seobeo_Request_Entry*)p_cl_kv)->value;
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
588 size_t body_len = atoi(content_length_str);
92
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
589
96
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
590 Seobeo_Log(SEOBEO_DEBUG, "Content-Length=%zu, reading body in chunks...\n", body_len);
92
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
591
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
592 char *body = Dowa_Arena_Allocate(p_arena, body_len + 1);
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
593 if (!body)
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
594 {
96
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
595 Seobeo_Log(SEOBEO_ERROR, "Failed to allocate %zu bytes for body\n", body_len);
92
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
596 return -1;
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
597 }
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
598
92
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
599 size_t total_read = 0;
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
600
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
601 while (total_read < body_len)
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
602 {
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
603 size_t available = p_handle->read_buffer_len;
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
604 size_t to_copy = (body_len - total_read) < available ? (body_len - total_read) : available;
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
605
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
606 if (to_copy > 0)
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
607 {
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
608 memcpy(body + total_read, p_handle->read_buffer, to_copy);
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
609 total_read += to_copy;
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
610 Seobeo_Handle_Consume(p_handle, (uint32)to_copy);
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
611
96
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
612 Seobeo_Log(SEOBEO_DEBUG, "Copied %zu bytes, total %zu/%zu\n", to_copy, total_read, body_len);
92
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
613 }
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
614
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
615 if (total_read < body_len)
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
616 {
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
617 int r = Seobeo_Handle_Read(p_handle);
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
618 if (r < 0)
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
619 {
96
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
620 Seobeo_Log(SEOBEO_ERROR, "Read failed with %d\n", r);
92
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
621 return -1;
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
622 }
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
623 if (r == 0)
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
624 {
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
625 // No data available yet, continue waiting
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
626 // printf("DEBUG: Waiting for more data... (have %zu/%zu bytes)\n", total_read, body_len);
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
627 continue;
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
628 }
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
629 }
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
630 }
655ea0b661fd [Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents: 91
diff changeset
631
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
632 body[body_len] = '\0';
96
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
633 Seobeo_Log(SEOBEO_DEBUG, "Body fully received (%zu bytes)\n", body_len);
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
634
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
635 Dowa_HashMap_Push_Arena(*pp_map, "Body", body, p_arena);
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
636 }
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
637
110
99c4530e4629 [Seobeo] Small Syntax fixes.
June Park <parkjune1995@gmail.com>
parents: 101
diff changeset
638 return 0;
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
639 }
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
640
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
641 void SigchildHandler(int s)
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
642 {
110
99c4530e4629 [Seobeo] Small Syntax fixes.
June Park <parkjune1995@gmail.com>
parents: 101
diff changeset
643 (void)s;
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
644
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
645 // waitpid() might overwrite errno, so we save and restore it:
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
646 int saved_errno = errno;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
647
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
648 while(waitpid(-1, NULL, WNOHANG) > 0);
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
649
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
650 errno = saved_errno;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
651 }
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
652
19
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 18
diff changeset
653 int Seobeo_Web_Server_Start(
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
654 const char *folder_path,
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
655 const char *port,
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
656 Seobeo_ServerMode mode,
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
657 int thread_count)
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
658 {
251
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
659 return Seobeo_Web_Server_Start_On(
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
660 NULL,
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
661 folder_path,
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
662 port,
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
663 mode,
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
664 thread_count);
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
665 }
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
666
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
667 int Seobeo_Web_Server_Start_On(
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
668 const char *host,
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
669 const char *folder_path,
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
670 const char *port,
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
671 Seobeo_ServerMode mode,
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
672 int thread_count)
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
673 {
260
1f9877b637e9 Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents: 257
diff changeset
674 g_server_stopping = 0;
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
675 if (folder_path)
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
676 strncpy(g_folder_path, folder_path, sizeof(g_folder_path) - 1);
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
677
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
678 Seobeo_Cache_Entry *p_html_cache = NULL;
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
679
66
a0f0ad5e42eb [Misc] taking out capital P stuff.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
680 Seobeo_Handle *p_server_handle =
251
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
681 Seobeo_Stream_Handle_Server_Create(host, port);
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
682 if (!p_server_handle || p_server_handle->socket < 0)
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
683 {
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
684 if (p_server_handle)
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
685 Seobeo_Handle_Destroy(p_server_handle);
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
686 return 1;
117c4d53c9a4 [ui] Add HTML-first Web Component system
MrJuneJune <me@mrjunejune.com>
parents: 244
diff changeset
687 }
18
fa2b8af609d9 [Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents: 17
diff changeset
688
96
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
689 Seobeo_Log(SEOBEO_INFO, "Listening on port %s\n", port);
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
690
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
691 if (mode == SEOBEO_MODE_FORK)
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
692 {
96
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
693 Seobeo_Log(SEOBEO_INFO, "Server mode: FORK\n");
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
694 struct sigaction sa;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
695 sa.sa_handler = SigchildHandler;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
696 sigemptyset(&sa.sa_mask);
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
697 sa.sa_flags = SA_RESTART;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
698 sigaction(SIGCHLD, &sa, NULL);
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
699
260
1f9877b637e9 Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents: 257
diff changeset
700 while (!Seobeo_Web_Server_Is_Stopping())
34
6c322f9c2cb9 [Birthday] I didn't have nay time to buy birhtday present so w/e/
MrJuneJune <me@mrjunejune.com>
parents: 33
diff changeset
701 {
66
a0f0ad5e42eb [Misc] taking out capital P stuff.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
702 Seobeo_Handle *p_cli_handle =
19
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 18
diff changeset
703 Seobeo_Stream_Handle_Server_Accept(p_server_handle);
36
84672efec192 [Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
MrJuneJune <me@mrjunejune.com>
parents: 34
diff changeset
704 if (!p_cli_handle) continue;
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
705
16
fb2cff495a60 [Seobeo] Fixed the problem with edge server.
June Park <parkjune1995@gmail.com>
parents: 7
diff changeset
706 if (fork() == 0)
fb2cff495a60 [Seobeo] Fixed the problem with edge server.
June Park <parkjune1995@gmail.com>
parents: 7
diff changeset
707 {
183
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
708 Seobeo_Web_ClientHandle_Request(p_cli_handle, p_html_cache, FALSE);
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
709 _exit(0);
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
710 }
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
711 }
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
712 }
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
713
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
714 if (mode == SEOBEO_MODE_EDGE)
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
715 {
96
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
716 Seobeo_Log(SEOBEO_INFO, "Server mode: EDGE\n");
62
ea9ef388ab97 [Seobeo] Fixed issues with epoll or kqeue in different threads. Initizlied the event looop inside of the thread itself.
June Park <parkjune1995@gmail.com>
parents: 36
diff changeset
717 Seobeo_Web_Edge(p_server_handle, thread_count, p_html_cache);
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
718 }
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
719
260
1f9877b637e9 Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents: 257
diff changeset
720 Seobeo_Handle_Destroy(p_server_handle);
1f9877b637e9 Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents: 257
diff changeset
721 return 0;
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
722 }
17
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
723
96
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
724 /* Router logic */
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
725 struct Seobeo_Route_Struct {
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
726 char *method; // "GET", "POST", "PUT", "DELETE"
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
727 char *path_pattern; // "/v1/users/:id/posts/:post_id"
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
728 Seobeo_Route_Handler handler;
175
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
729 Seobeo_Stream_Handler stream_handler; // For streaming responses
257
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
730 Seobeo_SSE_Handler sse_handler;
96
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
731
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
732 // Pre-parsed path segments for efficient matching
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
733 char **path_segments; // ["v1", "users", ":id", "posts", ":post_id"]
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
734 boolean *is_param; // [false, false, true, false, true]
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
735 size_t segment_count;
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
736 };
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
737
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
738 static Seobeo_Route *g_routes = NULL;
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
739
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
740 void Seobeo_Router_Init()
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
741 {
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
742 Dowa_Array_Reserve(g_routes, 20);
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
743 }
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
744
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
745 void Seobeo_Router_Register(const char *method, const char *path_pattern, Seobeo_Route_Handler handler)
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
746 {
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
747 Seobeo_Route route = {0};
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
748
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
749 route.method = strdup(method);
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
750 route.path_pattern = strdup(path_pattern);
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
751 route.handler = handler;
175
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
752 route.stream_handler = NULL;
257
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
753 route.sse_handler = NULL;
175
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
754 route.path_segments = Dowa_String_Split(path_pattern, "/", strlen(path_pattern), 1, NULL);
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
755 route.segment_count = Dowa_Array_Length(route.path_segments);
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
756 route.is_param = (boolean*)malloc(sizeof(boolean) * route.segment_count);
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
757
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
758 for (size_t i = 0; i < route.segment_count; i++)
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
759 route.is_param[i] = (route.path_segments[i][0] == ':');
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
760
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
761 Dowa_Array_Push(g_routes, route);
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
762 }
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
763
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
764 void Seobeo_Router_Register_Stream(const char *method, const char *path_pattern, Seobeo_Stream_Handler handler)
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
765 {
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
766 Seobeo_Route route = {0};
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
767
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
768 route.method = strdup(method);
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
769 route.path_pattern = strdup(path_pattern);
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
770 route.handler = NULL;
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
771 route.stream_handler = handler;
257
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
772 route.sse_handler = NULL;
96
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
773 route.path_segments = Dowa_String_Split(path_pattern, "/", strlen(path_pattern), 1, NULL);
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
774 route.segment_count = Dowa_Array_Length(route.path_segments);
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
775 route.is_param = (boolean*)malloc(sizeof(boolean) * route.segment_count);
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
776
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
777 for (size_t i = 0; i < route.segment_count; i++)
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
778 route.is_param[i] = (route.path_segments[i][0] == ':');
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
779
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
780 Dowa_Array_Push(g_routes, route);
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
781 }
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
782
260
1f9877b637e9 Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents: 257
diff changeset
783 void Seobeo_Router_Register_SSE_Method(
1f9877b637e9 Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents: 257
diff changeset
784 const char *method,
257
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
785 const char *path_pattern,
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
786 Seobeo_SSE_Handler handler)
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
787 {
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
788 Seobeo_Route route = {0};
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
789
260
1f9877b637e9 Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents: 257
diff changeset
790 route.method = strdup(method);
257
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
791 route.path_pattern = strdup(path_pattern);
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
792 route.handler = NULL;
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
793 route.stream_handler = NULL;
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
794 route.sse_handler = handler;
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
795 route.path_segments = Dowa_String_Split(
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
796 path_pattern,
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
797 "/",
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
798 strlen(path_pattern),
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
799 1,
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
800 NULL);
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
801 route.segment_count = Dowa_Array_Length(route.path_segments);
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
802 route.is_param = (boolean*)malloc(
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
803 sizeof(boolean) * route.segment_count);
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
804
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
805 for (size_t i = 0; i < route.segment_count; i++)
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
806 route.is_param[i] = (route.path_segments[i][0] == ':');
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
807
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
808 Dowa_Array_Push(g_routes, route);
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
809 }
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
810
260
1f9877b637e9 Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents: 257
diff changeset
811 void Seobeo_Router_Register_SSE(
1f9877b637e9 Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents: 257
diff changeset
812 const char *path_pattern,
1f9877b637e9 Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents: 257
diff changeset
813 Seobeo_SSE_Handler handler)
1f9877b637e9 Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents: 257
diff changeset
814 {
1f9877b637e9 Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents: 257
diff changeset
815 Seobeo_Router_Register_SSE_Method("GET", path_pattern, handler);
1f9877b637e9 Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents: 257
diff changeset
816 }
1f9877b637e9 Add Copilot-powered cyberpunk JRPG chat
MrJuneJune <mrjunejune@users.noreply.github.com>
parents: 257
diff changeset
817
96
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
818 static boolean match_route_and_extract(
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
819 Seobeo_Route *route,
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
820 const char *request_path,
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
821 Seobeo_Request_Entry **pp_request_map,
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
822 Dowa_Arena *p_arena)
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
823 {
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
824 Dowa_Arena *p_temp_arena = Dowa_Arena_Create(1024);
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
825 char **request_segments = Dowa_String_Split(request_path, "/", strlen(request_path), 1, p_temp_arena);
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
826 size_t request_segment_count = Dowa_Array_Length(request_segments);
110
99c4530e4629 [Seobeo] Small Syntax fixes.
June Park <parkjune1995@gmail.com>
parents: 101
diff changeset
827
96
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
828 // Check segment count matches
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
829 if (request_segment_count != route->segment_count)
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
830 {
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
831 Dowa_Arena_Free(p_temp_arena);
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
832 return FALSE;
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
833 }
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
834
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
835 for (size_t i = 0; i < route->segment_count; i++)
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
836 {
257
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
837 if (!route->is_param[i])
96
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
838 {
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
839 if (strcmp(route->path_segments[i], request_segments[i]) != 0)
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
840 {
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
841 Dowa_Arena_Free(p_temp_arena);
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
842 return FALSE;
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
843 }
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
844 }
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
845 }
257
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
846
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
847 for (size_t i = 0; i < route->segment_count; i++)
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
848 {
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
849 if (!route->is_param[i])
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
850 continue;
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
851 char *key = Dowa_String_Copy_Arena(route->path_segments[i], p_arena);
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
852 char *value = Dowa_String_Copy_Arena(request_segments[i], p_arena);
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
853 Dowa_HashMap_Push_Arena(*pp_request_map, key, value, p_arena);
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
854 }
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
855
96
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
856 Dowa_Arena_Free(p_temp_arena);
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
857 return TRUE;
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
858 }
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
859
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
860 Seobeo_Route_Handler Seobeo_Router_Find_Handler(const char *method,
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
861 const char *path,
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
862 Seobeo_Request_Entry **pp_request_map,
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
863 Dowa_Arena *p_arena) {
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
864 if (g_routes == NULL)
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
865 {
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
866 return NULL;
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
867 }
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
868
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
869 size_t route_count = Dowa_Array_Length(g_routes);
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
870 for (size_t i = 0; i < route_count; i++)
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
871 {
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
872 Seobeo_Route *route = &g_routes[i];
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
873 if (strcmp(route->method, method) != 0)
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
874 {
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
875 continue;
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
876 }
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
877
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
878 if (match_route_and_extract(route, path, pp_request_map, p_arena))
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
879 {
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
880 return route->handler;
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
881 }
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
882 }
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
883
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
884 return NULL;
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
885 }
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
886
175
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
887 Seobeo_Stream_Handler Seobeo_Router_Find_Stream_Handler(
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
888 const char *method,
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
889 const char *path,
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
890 Seobeo_Request_Entry **pp_request_map,
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
891 Dowa_Arena *p_arena)
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
892 {
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
893 if (g_routes == NULL || method == NULL || path == NULL)
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
894 return NULL;
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
895
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
896 size_t route_count = Dowa_Array_Length(g_routes);
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
897 for (size_t i = 0; i < route_count; i++)
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
898 {
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
899 Seobeo_Route *route = &g_routes[i];
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
900 if (strcmp(route->method, method) != 0)
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
901 continue;
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
902
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
903 if (route->stream_handler && match_route_and_extract(route, path, pp_request_map, p_arena))
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
904 return route->stream_handler;
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
905 }
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
906
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
907 return NULL;
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
908 }
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
909
257
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
910 Seobeo_SSE_Handler Seobeo_Router_Find_SSE_Handler(
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
911 const char *method,
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
912 const char *path,
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
913 Seobeo_Request_Entry **pp_request_map,
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
914 Dowa_Arena *p_arena)
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
915 {
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
916 if (g_routes == NULL || method == NULL || path == NULL)
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
917 return NULL;
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
918
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
919 size_t route_count = Dowa_Array_Length(g_routes);
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
920 for (size_t i = 0; i < route_count; i++)
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
921 {
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
922 Seobeo_Route *route = &g_routes[i];
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
923 if (strcmp(route->method, method) != 0)
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
924 continue;
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
925 if (route->sse_handler &&
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
926 match_route_and_extract(
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
927 route,
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
928 path,
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
929 pp_request_map,
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
930 p_arena))
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
931 {
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
932 return route->sse_handler;
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
933 }
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
934 }
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
935 return NULL;
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
936 }
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
937
96
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
938 void Seobeo_Router_Send_Response(
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
939 Seobeo_Handle *p_handle,
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
940 Seobeo_Request_Entry *p_response_map,
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
941 Dowa_Arena *p_arena)
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
942 {
183
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
943 Seobeo_Router_Send_Response_KeepAlive(p_handle, p_response_map, p_arena, FALSE);
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
944 }
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
945
221
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
946 static boolean Seobeo_Response_Header_Value_Is_Safe(const char *value)
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
947 {
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
948 return value && strchr(value, '\r') == NULL && strchr(value, '\n') == NULL;
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
949 }
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
950
183
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
951 void Seobeo_Router_Send_Response_KeepAlive(
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
952 Seobeo_Handle *p_handle,
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
953 Seobeo_Request_Entry *p_response_map,
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
954 Dowa_Arena *p_arena,
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
955 boolean keep_alive)
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
956 {
96
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
957 if (p_response_map == NULL)
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
958 {
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
959 char *header = Dowa_Arena_Allocate(p_arena, 1024);
183
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
960 Seobeo_Web_Header_Generate_KeepAlive(header, HTTP_INTERNAL_ERROR, "text/plain", 21, keep_alive);
96
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
961 Seobeo_Handle_Queue(p_handle, (uint8_t*)header, strlen(header));
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
962 Seobeo_Handle_Queue(p_handle, (uint8_t*)"Internal Server Error", 21);
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
963 Seobeo_Handle_Flush(p_handle);
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
964 return;
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
965 }
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
966
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
967 int status = HTTP_OK;
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
968 void *p_status_kv = Dowa_HashMap_Get_Ptr(p_response_map, "status");
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
969 if (p_status_kv)
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
970 {
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
971 const char *status_str = ((Seobeo_Request_Entry*)p_status_kv)->value;
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
972 status = atoi(status_str);
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
973 }
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
974
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
975 const char *body = "";
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
976 void *p_body_kv = Dowa_HashMap_Get_Ptr(p_response_map, "body");
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
977 if (p_body_kv)
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
978 body = ((Seobeo_Request_Entry*)p_body_kv)->value;
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
979
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
980 const char *content_type = "text/html";
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
981 void *p_content_type_kv = Dowa_HashMap_Get_Ptr(p_response_map, "content-type");
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
982 if (p_content_type_kv)
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
983 content_type = ((Seobeo_Request_Entry*)p_content_type_kv)->value;
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
984
175
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
985 // TODO: Update this to be integer
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
986 size_t body_length;
96
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
987 void *p_content_length_kv = Dowa_HashMap_Get_Ptr(p_response_map, "content-length");
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
988 if (p_content_length_kv)
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
989 {
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
990 const char *content_length_str = ((Seobeo_Request_Entry*)p_content_length_kv)->value;
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
991 body_length = atoi(content_length_str);
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
992 }
175
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
993 else
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
994 body_length = strlen(body);
96
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
995
221
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
996 size_t header_capacity = 1024;
96
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
997 for (int i = 0; i < Dowa_Array_Length(p_response_map); i++)
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
998 {
221
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
999 const char *key = p_response_map[i].key;
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1000 const char *value = p_response_map[i].value;
96
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
1001 if (
221
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1002 strcasecmp(key, "status") == 0 ||
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1003 strcasecmp(key, "body") == 0 ||
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1004 strcasecmp(key, "content-type") == 0 ||
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1005 strcasecmp(key, "content-length") == 0
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1006 )
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1007 continue;
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1008 if (Seobeo_Response_Header_Value_Is_Safe(key) &&
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1009 Seobeo_Response_Header_Value_Is_Safe(value))
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1010 header_capacity += strlen(key) + strlen(value) + 4;
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1011 }
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1012
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1013 char *header = Dowa_Arena_Allocate(p_arena, header_capacity);
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1014 Seobeo_Web_Header_Generate_KeepAlive(header, status, content_type, body_length, keep_alive);
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1015 size_t header_length = strlen(header);
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1016 if (header_length < 2)
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1017 return;
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1018 header_length -= 2;
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1019
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1020 for (int i = 0; i < Dowa_Array_Length(p_response_map); i++)
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1021 {
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1022 const char *key = p_response_map[i].key;
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1023 const char *value = p_response_map[i].value;
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1024 if (
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1025 strcasecmp(key, "status") == 0 ||
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1026 strcasecmp(key, "body") == 0 ||
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1027 strcasecmp(key, "content-type") == 0 ||
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1028 strcasecmp(key, "content-length") == 0
96
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
1029 )
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
1030 continue;
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
1031
221
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1032 if (!Seobeo_Response_Header_Value_Is_Safe(key) ||
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1033 !Seobeo_Response_Header_Value_Is_Safe(value))
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1034 {
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1035 Seobeo_Log(SEOBEO_WARNING, "Skipping unsafe response header\n");
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1036 continue;
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1037 }
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1038
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1039 int written = snprintf(
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1040 header + header_length,
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1041 header_capacity - header_length,
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1042 "%s: %s\r\n",
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1043 key,
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1044 value);
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1045 if (written < 0 || (size_t)written >= header_capacity - header_length)
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1046 {
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1047 Seobeo_Log(SEOBEO_ERROR, "Response header exceeded allocated capacity\n");
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1048 return;
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1049 }
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1050 header_length += (size_t)written;
96
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
1051 }
221
ce7f4400c2de [hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents: 187
diff changeset
1052 memcpy(header + header_length, "\r\n", 3);
175
71ad34a8bc9a [HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents: 173
diff changeset
1053
96
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
1054 Seobeo_Handle_Queue(p_handle, (uint8_t*)header, strlen(header));
183
a8976a008a9d [BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents: 154
diff changeset
1055 Seobeo_Handle_Queue(p_handle, (uint8_t*)body, body_length);
96
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
1056 Seobeo_Handle_Flush(p_handle);
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
1057 }
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
1058
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
1059 void Seobeo_Router_Destroy()
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
1060 {
257
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
1061 Seobeo_SSE_Server_Destroy();
96
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
1062 if (g_routes == NULL)
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
1063 return;
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
1064
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
1065 size_t route_count = Dowa_Array_Length(g_routes);
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
1066 for (size_t i = 0; i < route_count; i++)
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
1067 {
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
1068 Seobeo_Route *route = &g_routes[i];
257
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
1069 if (route->method) Dowa_Free(route->method);
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
1070 if (route->path_pattern) Dowa_Free(route->path_pattern);
96
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
1071 if (route->path_segments) Dowa_Array_Free(route->path_segments);
257
609d3c6aff4e [seobeo] Add persistent SSE streams
MrJuneJune <me@mrjunejune.com>
parents: 251
diff changeset
1072 if (route->is_param) Dowa_Free(route->is_param);
96
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
1073 }
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
1074 Dowa_Array_Free(g_routes);
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
1075 g_routes = NULL;
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
1076 }
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
1077
147
6de849867459 [HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents: 141
diff changeset
1078 // Written by AI. I don't know what it does.
6de849867459 [HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents: 141
diff changeset
1079 void Seobeo_Url_Decode(char *dst, const char *src)
6de849867459 [HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents: 141
diff changeset
1080 {
6de849867459 [HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents: 141
diff changeset
1081 char a, b;
6de849867459 [HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents: 141
diff changeset
1082 while (*src) {
6de849867459 [HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents: 141
diff changeset
1083 /* Check if we have a % followed by two valid hex characters */
6de849867459 [HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents: 141
diff changeset
1084 if (*src == '%' && src[1] && src[2]) {
6de849867459 [HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents: 141
diff changeset
1085 a = src[1];
6de849867459 [HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents: 141
diff changeset
1086 b = src[2];
6de849867459 [HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents: 141
diff changeset
1087
6de849867459 [HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents: 141
diff changeset
1088 /* Manual isxdigit check and conversion for 'a' */
6de849867459 [HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents: 141
diff changeset
1089 int a_val = -1;
6de849867459 [HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents: 141
diff changeset
1090 if (a >= '0' && a <= '9') a_val = a - '0';
6de849867459 [HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents: 141
diff changeset
1091 else if (a >= 'a' && a <= 'f') a_val = a - 'a' + 10;
6de849867459 [HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents: 141
diff changeset
1092 else if (a >= 'A' && a <= 'F') a_val = a - 'A' + 10;
96
70401cf61e97 [Seobeo] Added logging.
June Park <parkjune1995@gmail.com>
parents: 92
diff changeset
1093
147
6de849867459 [HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents: 141
diff changeset
1094 /* Manual isxdigit check and conversion for 'b' */
6de849867459 [HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents: 141
diff changeset
1095 int b_val = -1;
6de849867459 [HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents: 141
diff changeset
1096 if (b >= '0' && b <= '9') b_val = b - '0';
6de849867459 [HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents: 141
diff changeset
1097 else if (b >= 'a' && b <= 'f') b_val = b - 'a' + 10;
6de849867459 [HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents: 141
diff changeset
1098 else if (b >= 'A' && b <= 'F') b_val = b - 'A' + 10;
6de849867459 [HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents: 141
diff changeset
1099
6de849867459 [HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents: 141
diff changeset
1100 /* If both were valid hex, combine them */
6de849867459 [HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents: 141
diff changeset
1101 if (a_val != -1 && b_val != -1) {
6de849867459 [HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents: 141
diff changeset
1102 *dst++ = (char)((a_val << 4) | b_val);
6de849867459 [HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents: 141
diff changeset
1103 src += 3;
6de849867459 [HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents: 141
diff changeset
1104 continue;
6de849867459 [HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents: 141
diff changeset
1105 }
6de849867459 [HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents: 141
diff changeset
1106 }
6de849867459 [HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents: 141
diff changeset
1107
6de849867459 [HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents: 141
diff changeset
1108 /* Handle '+' as space, otherwise copy character literally */
6de849867459 [HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents: 141
diff changeset
1109 if (*src == '+') {
6de849867459 [HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents: 141
diff changeset
1110 *dst++ = ' ';
6de849867459 [HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents: 141
diff changeset
1111 } else {
6de849867459 [HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents: 141
diff changeset
1112 *dst++ = *src;
6de849867459 [HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents: 141
diff changeset
1113 }
6de849867459 [HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents: 141
diff changeset
1114 src++;
6de849867459 [HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents: 141
diff changeset
1115 }
6de849867459 [HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents: 141
diff changeset
1116 *dst = '\0';
6de849867459 [HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents: 141
diff changeset
1117 }