Mercurial
annotate seobeo/s_web.c @ 246:4f2b50bc78e7
[tools] Fix LaTeX editor visibility
Co-authored-by: Copilot <[email protected]>
| author | MrJuneJune <me@mrjunejune.com> |
|---|---|
| date | Mon, 03 Aug 2026 18:30:45 -0700 |
| parents | b8aa08503378 |
| children | 117c4d53c9a4 |
| 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] = "."; |
|
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
|
6 |
|
244
b8aa08503378
[tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents:
242
diff
changeset
|
7 static char *canonical_request_header(char *header) |
|
b8aa08503378
[tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents:
242
diff
changeset
|
8 { |
|
b8aa08503378
[tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents:
242
diff
changeset
|
9 if (strcasecmp(header, "content-length") == 0) return "Content-Length"; |
|
b8aa08503378
[tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents:
242
diff
changeset
|
10 if (strcasecmp(header, "content-type") == 0) return "Content-Type"; |
|
b8aa08503378
[tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents:
242
diff
changeset
|
11 if (strcasecmp(header, "connection") == 0) return "Connection"; |
|
b8aa08503378
[tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents:
242
diff
changeset
|
12 if (strcasecmp(header, "authorization") == 0) return "Authorization"; |
|
b8aa08503378
[tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents:
242
diff
changeset
|
13 if (strcasecmp(header, "host") == 0) return "Host"; |
|
b8aa08503378
[tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents:
242
diff
changeset
|
14 if (strcasecmp(header, "upgrade") == 0) return "Upgrade"; |
|
b8aa08503378
[tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents:
242
diff
changeset
|
15 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
|
16 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
|
17 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
|
18 return header; |
|
b8aa08503378
[tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents:
242
diff
changeset
|
19 } |
|
b8aa08503378
[tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents:
242
diff
changeset
|
20 |
|
77
c348ac875294
[Seobeo] Server side rendering.
June Park <parkjune1995@gmail.com>
parents:
76
diff
changeset
|
21 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
|
22 { |
|
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
|
23 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
|
24 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
|
25 |
|
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
|
26 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
|
27 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
|
28 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
|
29 |
|
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
|
30 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
|
31 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
|
32 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
|
33 |
|
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
|
34 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
|
35 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
|
36 { |
|
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
|
37 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
|
38 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
|
39 } |
|
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
|
40 |
|
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
|
41 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
|
42 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
|
43 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
|
44 |
|
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
|
45 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
|
46 *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
|
47 |
|
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
|
48 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
|
49 } |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
50 |
|
76
35b1abc37969
Updating my website to use seobeo library.
June Park <parkjune1995@gmail.com>
parents:
72
diff
changeset
|
51 void Seobeo_Web_Header_Generate( |
|
35b1abc37969
Updating my website to use seobeo library.
June Park <parkjune1995@gmail.com>
parents:
72
diff
changeset
|
52 void *buffer, int status, |
|
35b1abc37969
Updating my website to use seobeo library.
June Park <parkjune1995@gmail.com>
parents:
72
diff
changeset
|
53 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
|
54 { |
|
183
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
154
diff
changeset
|
55 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
|
56 } |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
154
diff
changeset
|
57 |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
154
diff
changeset
|
58 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
|
59 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
|
60 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
|
61 boolean keep_alive) |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
154
diff
changeset
|
62 { |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
63 const char *status_text; |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
64 switch(status) |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
65 { |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
66 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
|
67 case HTTP_CREATED: status_text = "Created"; break; |
|
223
0e7b9464248d
[hg-web] Add browser route regression coverage
MrJuneJune <me@mrjunejune.com>
parents:
221
diff
changeset
|
68 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
|
69 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
|
70 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
|
71 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
|
72 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
|
73 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
|
74 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
|
75 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
|
76 case HTTP_UNPROCESSABLE_CONTENT: status_text = "Unprocessable Content"; break; |
|
b8aa08503378
[tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents:
242
diff
changeset
|
77 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
|
78 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
|
79 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
|
80 case 502: status_text = "Bad Gateway"; break; |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
187
diff
changeset
|
81 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
|
82 default: status_text = "Unknown"; break; |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
83 } |
|
183
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
154
diff
changeset
|
84 |
|
221
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
187
diff
changeset
|
85 snprintf( |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
187
diff
changeset
|
86 (char*)buffer, 1024, |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
87 "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
|
88 "Content-Type: %s\r\n" |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
89 "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
|
90 "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
|
91 "\r\n", |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
154
diff
changeset
|
92 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
|
93 keep_alive ? "keep-alive" : "close" |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
94 ); |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
95 } |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
96 |
|
183
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
154
diff
changeset
|
97 // 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
|
98 #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
|
99 |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
154
diff
changeset
|
100 // 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
|
101 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
|
102 { |
|
183
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
154
diff
changeset
|
103 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
|
104 |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
154
diff
changeset
|
105 // 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
|
106 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
|
107 if (!copy) return FALSE; |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
108 |
|
183
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
154
diff
changeset
|
109 boolean found = FALSE; |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
154
diff
changeset
|
110 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
|
111 while (token) { |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
154
diff
changeset
|
112 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
|
113 found = TRUE; |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
154
diff
changeset
|
114 break; |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
154
diff
changeset
|
115 } |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
154
diff
changeset
|
116 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
|
117 } |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
154
diff
changeset
|
118 free(copy); |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
154
diff
changeset
|
119 return found; |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
154
diff
changeset
|
120 } |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
154
diff
changeset
|
121 |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
154
diff
changeset
|
122 // 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
|
123 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
|
124 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
|
125 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
|
126 { |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
154
diff
changeset
|
127 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
|
128 |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
154
diff
changeset
|
129 // 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
|
130 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
|
131 |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
154
diff
changeset
|
132 // 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
|
133 // 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
|
134 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
|
135 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
|
136 |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
154
diff
changeset
|
137 Dowa_Arena *p_response_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
|
138 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
|
139 |
|
124
dbf14f84d51c
Refactor Seobeo and mrjunejune build files so it works.
June Park <parkjune1995@gmail.com>
parents:
121
diff
changeset
|
140 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
|
141 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
|
142 |
|
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
|
143 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
|
144 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
|
145 |
|
183
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
154
diff
changeset
|
146 // Handle parse errors |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
154
diff
changeset
|
147 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
|
148 // 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
|
149 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
|
150 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
|
151 // 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
|
152 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
|
153 } |
|
19
875bb6e10db7
[Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents:
18
diff
changeset
|
154 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
|
155 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
|
156 "text/plain", 0); |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
157 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
|
158 (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
|
159 (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
|
160 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
|
161 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
|
162 } |
|
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
|
163 |
|
183
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
154
diff
changeset
|
164 // 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
|
165 // 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
|
166 // 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
|
167 |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
154
diff
changeset
|
168 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
|
169 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
|
170 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
|
171 |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
154
diff
changeset
|
172 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
|
173 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
|
174 |
|
3468e2fe8d88
[Seobeo] log ngnix proxy values (for myself). took out unneeded stuff fflush.
June Park <parkjune1995@gmail.com>
parents:
100
diff
changeset
|
175 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
|
176 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
|
177 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
|
178 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
|
179 |
|
184
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
183
diff
changeset
|
180 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
|
181 { |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
183
diff
changeset
|
182 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
|
183 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
|
184 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
|
185 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
|
186 else |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
183
diff
changeset
|
187 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
|
188 } |
|
8c74204fd362
[MD to HTML] Updated so it can be used through readme to html
MrJuneJune <me@mrjunejune.com>
parents:
183
diff
changeset
|
189 else |
|
183
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
154
diff
changeset
|
190 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
|
191 |
|
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
|
192 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
|
193 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
|
194 |
|
183
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
154
diff
changeset
|
195 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
|
196 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
|
197 |
|
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
|
198 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
|
199 { |
|
183
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
154
diff
changeset
|
200 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
|
201 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
|
202 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
|
203 "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
|
204 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
|
205 (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
|
206 (uint32)strlen(p_response_header)); |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
207 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
|
208 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
|
209 goto clean_up_arenas; |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
210 } |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
211 |
|
121
7b1719fa918c
[Seobeo] Added web socket server.
June Park <parkjune1995@gmail.com>
parents:
119
diff
changeset
|
212 // --- 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
|
213 #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
|
214 Seobeo_Log(SEOBEO_DEBUG, "Web socket path \n"); |
|
121
7b1719fa918c
[Seobeo] Added web socket server.
June Park <parkjune1995@gmail.com>
parents:
119
diff
changeset
|
215 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
|
216 { |
|
7b1719fa918c
[Seobeo] Added web socket server.
June Park <parkjune1995@gmail.com>
parents:
119
diff
changeset
|
217 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
|
218 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
|
219 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
|
220 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
|
221 } |
|
124
dbf14f84d51c
Refactor Seobeo and mrjunejune build files so it works.
June Park <parkjune1995@gmail.com>
parents:
121
diff
changeset
|
222 #endif |
|
121
7b1719fa918c
[Seobeo] Added web socket server.
June Park <parkjune1995@gmail.com>
parents:
119
diff
changeset
|
223 |
|
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
|
224 // --- Try to match streaming route first --- |
|
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
|
225 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
|
226 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
|
227 { |
|
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
|
228 stream_handler(p_cli_handle, p_req_map, p_response_arena); |
| 187 | 229 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
|
230 } |
|
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
|
231 |
|
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
|
232 // --- 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
|
233 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
|
234 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
|
235 { |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
236 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
|
237 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
|
238 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
|
239 } |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
240 |
|
183
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
154
diff
changeset
|
241 // --- 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
|
242 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
|
243 { |
|
183
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
154
diff
changeset
|
244 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
|
245 |
|
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
|
246 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
|
247 { |
|
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
|
248 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
|
249 } |
|
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
|
250 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
|
251 { |
|
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
|
252 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
|
253 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
|
254 { |
|
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
|
255 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
|
256 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
|
257 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
|
258 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
|
259 } |
|
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
|
260 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
|
261 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
|
262 } |
|
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
|
263 |
|
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
|
264 void *p_file_kv = Dowa_HashMap_Get_Ptr(p_html_cache, 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
|
265 const char *file_content = 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
|
266 size_t body_size = 0; |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
267 |
|
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
|
268 if (p_file_kv) |
|
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
|
269 { |
|
132
7a63e41a21fb
[Seobeo] Added debug targets.
June Park <parkjune1995@gmail.com>
parents:
124
diff
changeset
|
270 Seobeo_Cached_File *cached = ((Seobeo_Cache_Entry*)p_file_kv)->value; |
|
7a63e41a21fb
[Seobeo] Added debug targets.
June Park <parkjune1995@gmail.com>
parents:
124
diff
changeset
|
271 file_content = cached->content; |
|
7a63e41a21fb
[Seobeo] Added debug targets.
June Park <parkjune1995@gmail.com>
parents:
124
diff
changeset
|
272 body_size = cached->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
|
273 } |
|
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
|
274 else |
|
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
|
275 { |
|
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
|
276 file_content = Seobeo_Web_LoadFile(file_path, &body_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
|
277 if (file_content) |
|
132
7a63e41a21fb
[Seobeo] Added debug targets.
June Park <parkjune1995@gmail.com>
parents:
124
diff
changeset
|
278 { |
|
7a63e41a21fb
[Seobeo] Added debug targets.
June Park <parkjune1995@gmail.com>
parents:
124
diff
changeset
|
279 Seobeo_Cached_File *cached = malloc(sizeof(Seobeo_Cached_File)); |
|
7a63e41a21fb
[Seobeo] Added debug targets.
June Park <parkjune1995@gmail.com>
parents:
124
diff
changeset
|
280 cached->content = (char*)file_content; |
|
7a63e41a21fb
[Seobeo] Added debug targets.
June Park <parkjune1995@gmail.com>
parents:
124
diff
changeset
|
281 cached->size = body_size; |
|
7a63e41a21fb
[Seobeo] Added debug targets.
June Park <parkjune1995@gmail.com>
parents:
124
diff
changeset
|
282 Dowa_HashMap_Push(p_html_cache, file_path, cached); |
|
7a63e41a21fb
[Seobeo] Added debug targets.
June Park <parkjune1995@gmail.com>
parents:
124
diff
changeset
|
283 } |
|
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
|
284 } |
|
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
|
285 |
|
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
|
286 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
|
287 { |
|
183
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
154
diff
changeset
|
288 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
|
289 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
|
290 "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
|
291 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
|
292 (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
|
293 (uint32)strlen(p_response_header)); |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
294 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
|
295 goto clean_up_arenas; |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
296 } |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
297 |
|
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 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
|
299 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
|
300 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
|
301 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
|
302 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
|
303 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
|
304 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
|
305 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
|
306 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
|
307 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
|
308 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
|
309 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
|
310 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
|
311 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
|
312 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
|
313 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
|
314 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
|
315 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
|
316 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
|
317 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
|
318 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
|
319 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
|
320 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
|
321 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
|
322 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
|
323 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
|
324 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
|
325 |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
326 |
|
183
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
154
diff
changeset
|
327 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
|
328 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
|
329 mime, |
|
183
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
154
diff
changeset
|
330 body_size, should_keep_alive); |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
331 |
|
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
|
332 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
|
333 (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
|
334 (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
|
335 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
|
336 (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
|
337 (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
|
338 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
|
339 } |
|
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 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
|
341 { |
|
183
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
154
diff
changeset
|
342 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
|
343 HTTP_NOT_FOUND, |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
154
diff
changeset
|
344 "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
|
345 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
|
346 (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
|
347 (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
|
348 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
|
349 } |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
350 |
|
183
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
154
diff
changeset
|
351 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
|
352 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
|
353 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
|
354 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
|
355 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
|
356 return should_keep_alive; |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
357 } |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
358 |
|
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
|
359 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
|
360 { |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
361 while (1) |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
362 { |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
363 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
|
364 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
|
365 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
|
366 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
|
367 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
|
368 |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
369 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
|
370 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
|
371 break; |
|
110
99c4530e4629
[Seobeo] Small Syntax fixes.
June Park <parkjune1995@gmail.com>
parents:
101
diff
changeset
|
372 |
|
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
|
373 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
|
374 { |
|
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
|
375 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
|
376 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
|
377 } |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
378 } |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
379 |
|
110
99c4530e4629
[Seobeo] Small Syntax fixes.
June Park <parkjune1995@gmail.com>
parents:
101
diff
changeset
|
380 // "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
|
381 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
|
382 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
|
383 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
|
384 |
|
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
|
385 // 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
|
386 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
|
387 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
|
388 { |
|
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
|
389 size_t first_line_len = first_line_end - buf; |
| 96 | 390 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
|
391 } |
|
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
|
392 |
|
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
|
393 // This seems kinda bad ? |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
394 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
|
395 int scan_result = sscanf(buf, "%15s %255s %15s", method, path, version); |
| 96 | 396 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
|
397 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
|
398 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
|
399 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
|
400 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
|
401 |
|
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
|
402 if (scan_result != 3) |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
403 { |
| 96 | 404 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
|
405 return -1; |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
406 } |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
407 |
| 96 | 408 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
|
409 char *method_copy = Dowa_Arena_Allocate(p_arena, strlen(method) + 1); |
| 96 | 410 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
|
411 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
|
412 |
| 96 | 413 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
|
414 char *version_copy = Dowa_Arena_Allocate(p_arena, strlen(version) + 1); |
| 96 | 415 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
|
416 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
|
417 |
| 96 | 418 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
|
419 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
|
420 Dowa_HashMap_Push_Arena(*pp_map, "Version", version_copy, p_arena); |
| 96 | 421 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
|
422 |
|
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
|
423 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
|
424 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
|
425 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
|
426 |
|
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
|
427 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
|
428 { |
|
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
|
429 *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
|
430 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
|
431 } |
|
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
|
432 |
|
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
|
433 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
|
434 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
|
435 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
|
436 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
|
437 |
|
ffb764d2fcc5
[HgWeb] Updated hg web so it works
June Park <parkjune1995@gmail.com>
parents:
132
diff
changeset
|
438 // Store full query string for proxying |
|
ffb764d2fcc5
[HgWeb] Updated hg web so it works
June Park <parkjune1995@gmail.com>
parents:
132
diff
changeset
|
439 if (query_str && *query_str) |
|
ffb764d2fcc5
[HgWeb] Updated hg web so it works
June Park <parkjune1995@gmail.com>
parents:
132
diff
changeset
|
440 { |
|
ffb764d2fcc5
[HgWeb] Updated hg web so it works
June Park <parkjune1995@gmail.com>
parents:
132
diff
changeset
|
441 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
|
442 if (qs_copy) |
|
ffb764d2fcc5
[HgWeb] Updated hg web so it works
June Park <parkjune1995@gmail.com>
parents:
132
diff
changeset
|
443 { |
|
ffb764d2fcc5
[HgWeb] Updated hg web so it works
June Park <parkjune1995@gmail.com>
parents:
132
diff
changeset
|
444 strcpy(qs_copy, query_str); |
|
ffb764d2fcc5
[HgWeb] Updated hg web so it works
June Park <parkjune1995@gmail.com>
parents:
132
diff
changeset
|
445 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
|
446 } |
|
ffb764d2fcc5
[HgWeb] Updated hg web so it works
June Park <parkjune1995@gmail.com>
parents:
132
diff
changeset
|
447 } |
|
ffb764d2fcc5
[HgWeb] Updated hg web so it works
June Park <parkjune1995@gmail.com>
parents:
132
diff
changeset
|
448 |
|
110
99c4530e4629
[Seobeo] Small Syntax fixes.
June Park <parkjune1995@gmail.com>
parents:
101
diff
changeset
|
449 // 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
|
450 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
|
451 { |
|
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
|
452 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
|
453 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
|
454 { |
|
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
|
455 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
|
456 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
|
457 |
|
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
|
458 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
|
459 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
|
460 { |
|
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
|
461 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
|
462 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
|
463 |
|
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
|
464 char key_buf[256]; |
|
110
99c4530e4629
[Seobeo] Small Syntax fixes.
June Park <parkjune1995@gmail.com>
parents:
101
diff
changeset
|
465 // 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
|
466 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
|
467 |
|
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 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
|
469 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
|
470 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
|
471 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
|
472 |
|
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 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
|
474 } |
|
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 |
|
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
|
476 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
|
477 } |
|
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
|
478 } |
|
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 |
|
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 // 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
|
481 // 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
|
482 // 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
|
483 // 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
|
484 |
|
110
99c4530e4629
[Seobeo] Small Syntax fixes.
June Park <parkjune1995@gmail.com>
parents:
101
diff
changeset
|
485 // Parse headers |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
486 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
|
487 while (line < hdr_end) |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
488 { |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
489 char *next = strstr(line, "\r\n"); |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
490 if (!next) break; |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
491 |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
492 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
|
493 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
|
494 { |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
495 size_t key_len = colon - line; |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
496 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
|
497 |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
498 char *val_start = colon + 1; |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
499 if (*val_start == ' ') |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
500 { |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
501 val_start++; |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
502 value_len--; |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
503 } |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
504 |
|
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
|
505 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
|
506 if (!key) return -1; |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
507 memcpy(key, line, key_len); |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
508 key[key_len] = '\0'; |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
509 |
|
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
|
510 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
|
511 if (!val) return -1; |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
512 memcpy(val, val_start, value_len); |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
513 val[value_len] = '\0'; |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
514 |
|
244
b8aa08503378
[tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents:
242
diff
changeset
|
515 Dowa_HashMap_Push_Arena( |
|
b8aa08503378
[tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents:
242
diff
changeset
|
516 *pp_map, |
|
b8aa08503378
[tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents:
242
diff
changeset
|
517 canonical_request_header(key), |
|
b8aa08503378
[tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents:
242
diff
changeset
|
518 val, |
|
b8aa08503378
[tools] Add sandboxed online LaTeX editor
MrJuneJune <me@mrjunejune.com>
parents:
242
diff
changeset
|
519 p_arena); |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
520 } |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
521 |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
522 line = next + 2; |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
523 } |
|
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
|
524 |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
525 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
|
526 |
|
110
99c4530e4629
[Seobeo] Small Syntax fixes.
June Park <parkjune1995@gmail.com>
parents:
101
diff
changeset
|
527 // 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
|
528 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
|
529 if (p_cl_kv) |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
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 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
|
532 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
|
533 |
| 96 | 534 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
|
535 |
|
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
|
536 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
|
537 if (!body) |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
538 { |
| 96 | 539 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
|
540 return -1; |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
541 } |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
542 |
|
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
|
543 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
|
544 |
|
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
|
545 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
|
546 { |
|
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
|
547 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
|
548 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
|
549 |
|
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
|
550 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
|
551 { |
|
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
|
552 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
|
553 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
|
554 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
|
555 |
| 96 | 556 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
|
557 } |
|
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
|
558 |
|
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
|
559 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
|
560 { |
|
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
|
561 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
|
562 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
|
563 { |
| 96 | 564 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
|
565 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
|
566 } |
|
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
|
567 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
|
568 { |
|
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
|
569 // 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
|
570 // 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
|
571 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
|
572 } |
|
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
|
573 } |
|
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
|
574 } |
|
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
|
575 |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
576 body[body_len] = '\0'; |
| 96 | 577 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
|
578 |
|
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
|
579 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
|
580 } |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
581 |
|
110
99c4530e4629
[Seobeo] Small Syntax fixes.
June Park <parkjune1995@gmail.com>
parents:
101
diff
changeset
|
582 return 0; |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
583 } |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
584 |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
585 void SigchildHandler(int s) |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
586 { |
|
110
99c4530e4629
[Seobeo] Small Syntax fixes.
June Park <parkjune1995@gmail.com>
parents:
101
diff
changeset
|
587 (void)s; |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
588 |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
589 // 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
|
590 int saved_errno = errno; |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
591 |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
592 while(waitpid(-1, NULL, WNOHANG) > 0); |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
593 |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
594 errno = saved_errno; |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
595 } |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
596 |
|
19
875bb6e10db7
[Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents:
18
diff
changeset
|
597 int Seobeo_Web_Server_Start( |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
598 const char *folder_path, |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
599 const char *port, |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
600 Seobeo_ServerMode mode, |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
601 int thread_count) |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
602 { |
|
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
|
603 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
|
604 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
|
605 |
|
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
|
606 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
|
607 |
|
66
a0f0ad5e42eb
[Misc] taking out capital P stuff.
June Park <parkjune1995@gmail.com>
parents:
65
diff
changeset
|
608 Seobeo_Handle *p_server_handle = |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
609 Seobeo_Stream_Handle_Server_Create(NULL, port); |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
610 if (p_server_handle->socket < 0) return 1; |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
611 |
| 96 | 612 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
|
613 |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
614 if (mode == SEOBEO_MODE_FORK) |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
615 { |
| 96 | 616 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
|
617 struct sigaction sa; |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
618 sa.sa_handler = SigchildHandler; |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
619 sigemptyset(&sa.sa_mask); |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
620 sa.sa_flags = SA_RESTART; |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
621 sigaction(SIGCHLD, &sa, NULL); |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
622 |
|
34
6c322f9c2cb9
[Birthday] I didn't have nay time to buy birhtday present so w/e/
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
623 while (1) |
|
6c322f9c2cb9
[Birthday] I didn't have nay time to buy birhtday present so w/e/
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
624 { |
|
66
a0f0ad5e42eb
[Misc] taking out capital P stuff.
June Park <parkjune1995@gmail.com>
parents:
65
diff
changeset
|
625 Seobeo_Handle *p_cli_handle = |
|
19
875bb6e10db7
[Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents:
18
diff
changeset
|
626 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
|
627 if (!p_cli_handle) continue; |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
628 |
|
16
fb2cff495a60
[Seobeo] Fixed the problem with edge server.
June Park <parkjune1995@gmail.com>
parents:
7
diff
changeset
|
629 if (fork() == 0) |
|
fb2cff495a60
[Seobeo] Fixed the problem with edge server.
June Park <parkjune1995@gmail.com>
parents:
7
diff
changeset
|
630 { |
|
183
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
154
diff
changeset
|
631 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
|
632 _exit(0); |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
633 } |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
634 } |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
635 } |
|
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 if (mode == SEOBEO_MODE_EDGE) |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
638 { |
| 96 | 639 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
|
640 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
|
641 } |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
642 |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
643 return -1; |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
644 } |
| 17 | 645 |
| 96 | 646 /* Router logic */ |
| 647 struct Seobeo_Route_Struct { | |
| 648 char *method; // "GET", "POST", "PUT", "DELETE" | |
| 649 char *path_pattern; // "/v1/users/:id/posts/:post_id" | |
| 650 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
|
651 Seobeo_Stream_Handler stream_handler; // For streaming responses |
| 96 | 652 |
| 653 // Pre-parsed path segments for efficient matching | |
| 654 char **path_segments; // ["v1", "users", ":id", "posts", ":post_id"] | |
| 655 boolean *is_param; // [false, false, true, false, true] | |
| 656 size_t segment_count; | |
| 657 }; | |
| 658 | |
| 659 static Seobeo_Route *g_routes = NULL; | |
| 660 | |
| 661 void Seobeo_Router_Init() | |
| 662 { | |
| 663 Dowa_Array_Reserve(g_routes, 20); | |
| 664 } | |
| 665 | |
| 666 void Seobeo_Router_Register(const char *method, const char *path_pattern, Seobeo_Route_Handler handler) | |
| 667 { | |
| 668 Seobeo_Route route = {0}; | |
| 669 | |
| 670 route.method = strdup(method); | |
| 671 route.path_pattern = strdup(path_pattern); | |
| 672 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
|
673 route.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
|
674 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
|
675 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
|
676 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
|
677 |
|
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
|
678 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
|
679 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
|
680 |
|
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
|
681 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
|
682 } |
|
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
|
683 |
|
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
|
684 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
|
685 { |
|
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
|
686 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
|
687 |
|
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
|
688 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
|
689 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
|
690 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
|
691 route.stream_handler = handler; |
| 96 | 692 route.path_segments = Dowa_String_Split(path_pattern, "/", strlen(path_pattern), 1, NULL); |
| 693 route.segment_count = Dowa_Array_Length(route.path_segments); | |
| 694 route.is_param = (boolean*)malloc(sizeof(boolean) * route.segment_count); | |
| 695 | |
| 696 for (size_t i = 0; i < route.segment_count; i++) | |
| 697 route.is_param[i] = (route.path_segments[i][0] == ':'); | |
| 698 | |
| 699 Dowa_Array_Push(g_routes, route); | |
| 700 } | |
| 701 | |
| 702 static boolean match_route_and_extract( | |
| 703 Seobeo_Route *route, | |
| 704 const char *request_path, | |
| 705 Seobeo_Request_Entry **pp_request_map, | |
| 706 Dowa_Arena *p_arena) | |
| 707 { | |
| 708 Dowa_Arena *p_temp_arena = Dowa_Arena_Create(1024); | |
| 709 char **request_segments = Dowa_String_Split(request_path, "/", strlen(request_path), 1, p_temp_arena); | |
| 710 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
|
711 |
| 96 | 712 // Check segment count matches |
| 713 if (request_segment_count != route->segment_count) | |
| 714 { | |
| 715 Dowa_Arena_Free(p_temp_arena); | |
| 716 return FALSE; | |
| 717 } | |
| 718 | |
| 719 for (size_t i = 0; i < route->segment_count; i++) | |
| 720 { | |
| 721 // parameters | |
| 722 if (route->is_param[i]) | |
| 723 { | |
| 724 char *param_name = route->path_segments[i]; // e.g., ":id" | |
| 725 char *param_value = request_segments[i]; // e.g., "123" | |
| 726 | |
| 727 // Should Copy to arena | |
| 728 char *key = Dowa_String_Copy_Arena(param_name, p_arena); | |
| 729 char *value = Dowa_String_Copy_Arena(param_value, p_arena); | |
| 730 Dowa_HashMap_Push_Arena(*pp_request_map, key, value, p_arena); | |
| 731 } | |
| 732 else | |
| 733 { | |
| 734 // Does not match. | |
| 735 if (strcmp(route->path_segments[i], request_segments[i]) != 0) | |
| 736 { | |
| 737 Dowa_Arena_Free(p_temp_arena); | |
| 738 return FALSE; | |
| 739 } | |
| 740 } | |
| 741 } | |
| 742 | |
| 743 Dowa_Arena_Free(p_temp_arena); | |
| 744 return TRUE; | |
| 745 } | |
| 746 | |
| 747 Seobeo_Route_Handler Seobeo_Router_Find_Handler(const char *method, | |
| 748 const char *path, | |
| 749 Seobeo_Request_Entry **pp_request_map, | |
| 750 Dowa_Arena *p_arena) { | |
| 751 if (g_routes == NULL) | |
| 752 { | |
| 753 return NULL; | |
| 754 } | |
| 755 | |
| 756 size_t route_count = Dowa_Array_Length(g_routes); | |
| 757 for (size_t i = 0; i < route_count; i++) | |
| 758 { | |
| 759 Seobeo_Route *route = &g_routes[i]; | |
| 760 if (strcmp(route->method, method) != 0) | |
| 761 { | |
| 762 continue; | |
| 763 } | |
| 764 | |
| 765 if (match_route_and_extract(route, path, pp_request_map, p_arena)) | |
| 766 { | |
| 767 return route->handler; | |
| 768 } | |
| 769 } | |
| 770 | |
| 771 return NULL; | |
| 772 } | |
| 773 | |
|
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
|
774 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
|
775 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
|
776 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
|
777 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
|
778 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
|
779 { |
|
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
|
780 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
|
781 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
|
782 |
|
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
|
783 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
|
784 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
|
785 { |
|
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
|
786 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
|
787 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
|
788 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
|
789 |
|
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
|
790 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
|
791 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
|
792 } |
|
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
|
793 |
|
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
|
794 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
|
795 } |
|
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
|
796 |
| 96 | 797 void Seobeo_Router_Send_Response( |
| 798 Seobeo_Handle *p_handle, | |
| 799 Seobeo_Request_Entry *p_response_map, | |
| 800 Dowa_Arena *p_arena) | |
| 801 { | |
|
183
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
154
diff
changeset
|
802 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
|
803 } |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
154
diff
changeset
|
804 |
|
221
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
187
diff
changeset
|
805 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
|
806 { |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
187
diff
changeset
|
807 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
|
808 } |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
187
diff
changeset
|
809 |
|
183
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
154
diff
changeset
|
810 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
|
811 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
|
812 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
|
813 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
|
814 boolean keep_alive) |
|
a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
MrJuneJune <me@mrjunejune.com>
parents:
154
diff
changeset
|
815 { |
| 96 | 816 if (p_response_map == NULL) |
| 817 { | |
| 818 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
|
819 Seobeo_Web_Header_Generate_KeepAlive(header, HTTP_INTERNAL_ERROR, "text/plain", 21, keep_alive); |
| 96 | 820 Seobeo_Handle_Queue(p_handle, (uint8_t*)header, strlen(header)); |
| 821 Seobeo_Handle_Queue(p_handle, (uint8_t*)"Internal Server Error", 21); | |
| 822 Seobeo_Handle_Flush(p_handle); | |
| 823 return; | |
| 824 } | |
| 825 | |
| 826 int status = HTTP_OK; | |
| 827 void *p_status_kv = Dowa_HashMap_Get_Ptr(p_response_map, "status"); | |
| 828 if (p_status_kv) | |
| 829 { | |
| 830 const char *status_str = ((Seobeo_Request_Entry*)p_status_kv)->value; | |
| 831 status = atoi(status_str); | |
| 832 } | |
| 833 | |
| 834 const char *body = ""; | |
| 835 void *p_body_kv = Dowa_HashMap_Get_Ptr(p_response_map, "body"); | |
| 836 if (p_body_kv) | |
| 837 body = ((Seobeo_Request_Entry*)p_body_kv)->value; | |
| 838 | |
| 839 const char *content_type = "text/html"; | |
| 840 void *p_content_type_kv = Dowa_HashMap_Get_Ptr(p_response_map, "content-type"); | |
| 841 if (p_content_type_kv) | |
| 842 content_type = ((Seobeo_Request_Entry*)p_content_type_kv)->value; | |
| 843 | |
|
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
|
844 // 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
|
845 size_t body_length; |
| 96 | 846 void *p_content_length_kv = Dowa_HashMap_Get_Ptr(p_response_map, "content-length"); |
| 847 if (p_content_length_kv) | |
| 848 { | |
| 849 const char *content_length_str = ((Seobeo_Request_Entry*)p_content_length_kv)->value; | |
| 850 body_length = atoi(content_length_str); | |
| 851 } | |
|
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
|
852 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
|
853 body_length = strlen(body); |
| 96 | 854 |
|
221
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
187
diff
changeset
|
855 size_t header_capacity = 1024; |
| 96 | 856 for (int i = 0; i < Dowa_Array_Length(p_response_map); i++) |
| 857 { | |
|
221
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
187
diff
changeset
|
858 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
|
859 const char *value = p_response_map[i].value; |
| 96 | 860 if ( |
|
221
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
187
diff
changeset
|
861 strcasecmp(key, "status") == 0 || |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
187
diff
changeset
|
862 strcasecmp(key, "body") == 0 || |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
187
diff
changeset
|
863 strcasecmp(key, "content-type") == 0 || |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
187
diff
changeset
|
864 strcasecmp(key, "content-length") == 0 |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
187
diff
changeset
|
865 ) |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
187
diff
changeset
|
866 continue; |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
187
diff
changeset
|
867 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
|
868 Seobeo_Response_Header_Value_Is_Safe(value)) |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
187
diff
changeset
|
869 header_capacity += strlen(key) + strlen(value) + 4; |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
187
diff
changeset
|
870 } |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
187
diff
changeset
|
871 |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
187
diff
changeset
|
872 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
|
873 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
|
874 size_t header_length = strlen(header); |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
187
diff
changeset
|
875 if (header_length < 2) |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
187
diff
changeset
|
876 return; |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
187
diff
changeset
|
877 header_length -= 2; |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
187
diff
changeset
|
878 |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
187
diff
changeset
|
879 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
|
880 { |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
187
diff
changeset
|
881 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
|
882 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
|
883 if ( |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
187
diff
changeset
|
884 strcasecmp(key, "status") == 0 || |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
187
diff
changeset
|
885 strcasecmp(key, "body") == 0 || |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
187
diff
changeset
|
886 strcasecmp(key, "content-type") == 0 || |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
187
diff
changeset
|
887 strcasecmp(key, "content-length") == 0 |
| 96 | 888 ) |
| 889 continue; | |
| 890 | |
|
221
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
187
diff
changeset
|
891 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
|
892 !Seobeo_Response_Header_Value_Is_Safe(value)) |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
187
diff
changeset
|
893 { |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
187
diff
changeset
|
894 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
|
895 continue; |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
187
diff
changeset
|
896 } |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
187
diff
changeset
|
897 |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
187
diff
changeset
|
898 int written = snprintf( |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
187
diff
changeset
|
899 header + header_length, |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
187
diff
changeset
|
900 header_capacity - header_length, |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
187
diff
changeset
|
901 "%s: %s\r\n", |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
187
diff
changeset
|
902 key, |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
187
diff
changeset
|
903 value); |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
187
diff
changeset
|
904 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
|
905 { |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
187
diff
changeset
|
906 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
|
907 return; |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
187
diff
changeset
|
908 } |
|
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
187
diff
changeset
|
909 header_length += (size_t)written; |
| 96 | 910 } |
|
221
ce7f4400c2de
[hg-web] Harden forge and add changeset UI
MrJuneJune <me@mrjunejune.com>
parents:
187
diff
changeset
|
911 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
|
912 |
| 96 | 913 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
|
914 Seobeo_Handle_Queue(p_handle, (uint8_t*)body, body_length); |
| 96 | 915 Seobeo_Handle_Flush(p_handle); |
| 916 } | |
| 917 | |
| 918 void Seobeo_Router_Destroy() | |
| 919 { | |
| 920 if (g_routes == NULL) | |
| 921 return; | |
| 922 | |
| 923 size_t route_count = Dowa_Array_Length(g_routes); | |
| 924 for (size_t i = 0; i < route_count; i++) | |
| 925 { | |
| 926 Seobeo_Route *route = &g_routes[i]; | |
| 927 if (route->method) free(route->method); | |
| 928 if (route->path_pattern) free(route->path_pattern); | |
| 929 if (route->path_segments) Dowa_Array_Free(route->path_segments); | |
| 930 if (route->is_param) free(route->is_param); | |
| 931 } | |
| 932 Dowa_Array_Free(g_routes); | |
| 933 g_routes = NULL; | |
| 934 } | |
| 935 | |
|
147
6de849867459
[HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents:
141
diff
changeset
|
936 // 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
|
937 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
|
938 { |
|
6de849867459
[HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents:
141
diff
changeset
|
939 char a, b; |
|
6de849867459
[HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents:
141
diff
changeset
|
940 while (*src) { |
|
6de849867459
[HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents:
141
diff
changeset
|
941 /* 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
|
942 if (*src == '%' && src[1] && src[2]) { |
|
6de849867459
[HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents:
141
diff
changeset
|
943 a = src[1]; |
|
6de849867459
[HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents:
141
diff
changeset
|
944 b = src[2]; |
|
6de849867459
[HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents:
141
diff
changeset
|
945 |
|
6de849867459
[HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents:
141
diff
changeset
|
946 /* Manual isxdigit check and conversion for 'a' */ |
|
6de849867459
[HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents:
141
diff
changeset
|
947 int a_val = -1; |
|
6de849867459
[HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents:
141
diff
changeset
|
948 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
|
949 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
|
950 else if (a >= 'A' && a <= 'F') a_val = a - 'A' + 10; |
| 96 | 951 |
|
147
6de849867459
[HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents:
141
diff
changeset
|
952 /* Manual isxdigit check and conversion for 'b' */ |
|
6de849867459
[HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents:
141
diff
changeset
|
953 int b_val = -1; |
|
6de849867459
[HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents:
141
diff
changeset
|
954 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
|
955 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
|
956 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
|
957 |
|
6de849867459
[HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents:
141
diff
changeset
|
958 /* If both were valid hex, combine them */ |
|
6de849867459
[HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents:
141
diff
changeset
|
959 if (a_val != -1 && b_val != -1) { |
|
6de849867459
[HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents:
141
diff
changeset
|
960 *dst++ = (char)((a_val << 4) | b_val); |
|
6de849867459
[HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents:
141
diff
changeset
|
961 src += 3; |
|
6de849867459
[HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents:
141
diff
changeset
|
962 continue; |
|
6de849867459
[HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents:
141
diff
changeset
|
963 } |
|
6de849867459
[HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents:
141
diff
changeset
|
964 } |
|
6de849867459
[HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents:
141
diff
changeset
|
965 |
|
6de849867459
[HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents:
141
diff
changeset
|
966 /* Handle '+' as space, otherwise copy character literally */ |
|
6de849867459
[HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents:
141
diff
changeset
|
967 if (*src == '+') { |
|
6de849867459
[HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents:
141
diff
changeset
|
968 *dst++ = ' '; |
|
6de849867459
[HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents:
141
diff
changeset
|
969 } else { |
|
6de849867459
[HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents:
141
diff
changeset
|
970 *dst++ = *src; |
|
6de849867459
[HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents:
141
diff
changeset
|
971 } |
|
6de849867459
[HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents:
141
diff
changeset
|
972 src++; |
|
6de849867459
[HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents:
141
diff
changeset
|
973 } |
|
6de849867459
[HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents:
141
diff
changeset
|
974 *dst = '\0'; |
|
6de849867459
[HgWeb] Updated logic to use Seobeo Client.
June Park <parkjune1995@gmail.com>
parents:
141
diff
changeset
|
975 } |