Mercurial
annotate seobeo/s_web.c @ 160:948de3f54cea
[ThirdParty] Added libuv
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Wed, 14 Jan 2026 19:39:52 -0800 |
| parents | bdcc610eeed8 |
| children | 827c6ac504cd a8976a008a9d |
| 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" |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
2 |
|
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
|
3 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
|
4 |
|
77
c348ac875294
[Seobeo] Server side rendering.
June Park <parkjune1995@gmail.com>
parents:
76
diff
changeset
|
5 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
|
6 { |
|
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
|
7 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
|
8 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
|
9 |
|
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
|
10 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
|
11 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
|
12 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
|
13 |
|
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
|
14 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
|
15 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
|
16 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
|
17 |
|
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
|
18 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
|
19 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
|
20 { |
|
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
|
21 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
|
22 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
|
23 } |
|
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 |
|
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 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
|
26 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
|
27 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
|
28 |
|
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 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
|
30 *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
|
31 |
|
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 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
|
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 |
|
76
35b1abc37969
Updating my website to use seobeo library.
June Park <parkjune1995@gmail.com>
parents:
72
diff
changeset
|
35 void Seobeo_Web_Header_Generate( |
|
35b1abc37969
Updating my website to use seobeo library.
June Park <parkjune1995@gmail.com>
parents:
72
diff
changeset
|
36 void *buffer, int status, |
|
35b1abc37969
Updating my website to use seobeo library.
June Park <parkjune1995@gmail.com>
parents:
72
diff
changeset
|
37 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
|
38 { |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
39 const char *status_text; |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
40 switch(status) |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
41 { |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
42 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
|
43 case HTTP_CREATED: status_text = "Created"; break; |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
44 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
|
45 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
|
46 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
|
47 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
|
48 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
|
49 case HTTP_NOT_FOUND: status_text = "Not Found"; break; |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
50 case HTTP_INTERNAL_ERROR: status_text = "Internal Server Error"; break; |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
51 default: status_text = "Unknown"; break; |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
52 } |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
53 |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
54 sprintf( |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
55 buffer, |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
56 "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
|
57 "Content-Type: %s\r\n" |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
58 "Content-Length: %d\r\n" |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
59 "Connection: close\r\n" |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
60 "\r\n", |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
61 status, status_text, content_type, content_length |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
62 ); |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
63 } |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
64 |
|
66
a0f0ad5e42eb
[Misc] taking out capital P stuff.
June Park <parkjune1995@gmail.com>
parents:
65
diff
changeset
|
65 void Seobeo_Web_HandleClientRequest(Seobeo_Handle *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
|
66 Seobeo_Cache_Entry *p_html_cache) |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
67 { |
|
124
dbf14f84d51c
Refactor Seobeo and mrjunejune build files so it works.
June Park <parkjune1995@gmail.com>
parents:
121
diff
changeset
|
68 // TODO: This should be splitted up instead of handling up to 50 MB as it will fail more often... |
|
dbf14f84d51c
Refactor Seobeo and mrjunejune build files so it works.
June Park <parkjune1995@gmail.com>
parents:
121
diff
changeset
|
69 Dowa_Arena *p_request_arena = Dowa_Arena_Create(50*1024*1024); // 50 MB because of files... |
|
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
|
70 if (!p_request_arena) { perror("Dowa_Arena_Create request"); goto clean_up; } |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
71 |
|
124
dbf14f84d51c
Refactor Seobeo and mrjunejune build files so it works.
June Park <parkjune1995@gmail.com>
parents:
121
diff
changeset
|
72 Dowa_Arena *p_response_arena = Dowa_Arena_Create(50*1024*1024); // 50 MB for response |
|
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
|
73 if (!p_response_arena) { perror("Dowa_Arena_Create response"); goto clean_up; } |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
74 |
|
124
dbf14f84d51c
Refactor Seobeo and mrjunejune build files so it works.
June Park <parkjune1995@gmail.com>
parents:
121
diff
changeset
|
75 void *p_response_header = Dowa_Arena_Allocate(p_response_arena, 1024*5); // 5Kb |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
76 if (!p_response_header) { perror("Dowa_Arena_Allocate"); goto clean_up; } |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
77 |
|
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
|
78 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
|
79 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
|
80 |
|
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
|
81 if (parse_result != 0 && parse_result != 1) |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
82 { |
| 96 | 83 Seobeo_Log(SEOBEO_ERROR, "Seobeo_Web_Header_Parse failed with code %d\n", parse_result); |
|
19
875bb6e10db7
[Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents:
18
diff
changeset
|
84 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
|
85 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
|
86 "text/plain", 0); |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
87 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
|
88 (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
|
89 (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
|
90 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
|
91 goto clean_up; |
|
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
|
92 } |
|
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
|
93 |
| 96 | 94 Seobeo_Log(SEOBEO_DEBUG, "Parse completed with code %d\n", parse_result); |
|
101
3468e2fe8d88
[Seobeo] log ngnix proxy values (for myself). took out unneeded stuff fflush.
June Park <parkjune1995@gmail.com>
parents:
100
diff
changeset
|
95 |
|
3468e2fe8d88
[Seobeo] log ngnix proxy values (for myself). took out unneeded stuff fflush.
June Park <parkjune1995@gmail.com>
parents:
100
diff
changeset
|
96 // Recording IP to see who is ddosing or any web scrappers... |
|
3468e2fe8d88
[Seobeo] log ngnix proxy values (for myself). took out unneeded stuff fflush.
June Park <parkjune1995@gmail.com>
parents:
100
diff
changeset
|
97 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
|
98 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
|
99 // Fallback |
|
3468e2fe8d88
[Seobeo] log ngnix proxy values (for myself). took out unneeded stuff fflush.
June Park <parkjune1995@gmail.com>
parents:
100
diff
changeset
|
100 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
|
101 { |
|
3468e2fe8d88
[Seobeo] log ngnix proxy values (for myself). took out unneeded stuff fflush.
June Park <parkjune1995@gmail.com>
parents:
100
diff
changeset
|
102 void *p_forwarded_kv = Dowa_HashMap_Get_Ptr(p_req_map, "X-Forwarded-For"); |
|
3468e2fe8d88
[Seobeo] log ngnix proxy values (for myself). took out unneeded stuff fflush.
June Park <parkjune1995@gmail.com>
parents:
100
diff
changeset
|
103 real_ip = p_forwarded_kv ? ((Seobeo_Request_Entry*)p_forwarded_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
|
104 } |
|
3468e2fe8d88
[Seobeo] log ngnix proxy values (for myself). took out unneeded stuff fflush.
June Park <parkjune1995@gmail.com>
parents:
100
diff
changeset
|
105 // Fallback |
|
3468e2fe8d88
[Seobeo] log ngnix proxy values (for myself). took out unneeded stuff fflush.
June Park <parkjune1995@gmail.com>
parents:
100
diff
changeset
|
106 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
|
107 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
|
108 |
|
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
|
109 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
|
110 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
|
111 |
|
101
3468e2fe8d88
[Seobeo] log ngnix proxy values (for myself). took out unneeded stuff fflush.
June Park <parkjune1995@gmail.com>
parents:
100
diff
changeset
|
112 void *p_path_kv_log = Dowa_HashMap_Get_Ptr(p_req_map, "Path"); |
|
3468e2fe8d88
[Seobeo] log ngnix proxy values (for myself). took out unneeded stuff fflush.
June Park <parkjune1995@gmail.com>
parents:
100
diff
changeset
|
113 const char *path_log = p_path_kv_log ? ((Seobeo_Request_Entry*)p_path_kv_log)->value : "/"; |
|
3468e2fe8d88
[Seobeo] log ngnix proxy values (for myself). took out unneeded stuff fflush.
June Park <parkjune1995@gmail.com>
parents:
100
diff
changeset
|
114 |
|
3468e2fe8d88
[Seobeo] log ngnix proxy values (for myself). took out unneeded stuff fflush.
June Park <parkjune1995@gmail.com>
parents:
100
diff
changeset
|
115 Seobeo_Log(SEOBEO_INFO, "%s - %s %s\n", |
|
3468e2fe8d88
[Seobeo] log ngnix proxy values (for myself). took out unneeded stuff fflush.
June Park <parkjune1995@gmail.com>
parents:
100
diff
changeset
|
116 real_ip ? real_ip : "unknown", |
|
3468e2fe8d88
[Seobeo] log ngnix proxy values (for myself). took out unneeded stuff fflush.
June Park <parkjune1995@gmail.com>
parents:
100
diff
changeset
|
117 method ? method : "UNKNOWN", |
|
3468e2fe8d88
[Seobeo] log ngnix proxy values (for myself). took out unneeded stuff fflush.
June Park <parkjune1995@gmail.com>
parents:
100
diff
changeset
|
118 path_log); |
|
3468e2fe8d88
[Seobeo] log ngnix proxy values (for myself). took out unneeded stuff fflush.
June Park <parkjune1995@gmail.com>
parents:
100
diff
changeset
|
119 |
| 96 | 120 Seobeo_Log(SEOBEO_DEBUG, "Parsed request, method=%s\n", method ? method : "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
|
121 |
|
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
|
122 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
|
123 { |
| 96 | 124 Seobeo_Log(SEOBEO_ERROR, "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
|
125 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
|
126 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
|
127 "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
|
128 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
|
129 (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
|
130 (uint32)strlen(p_response_header)); |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
131 Seobeo_Handle_Flush(p_cli_handle); |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
132 goto clean_up; |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
133 } |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
134 |
|
72
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
135 void *p_path_kv = Dowa_HashMap_Get_Ptr(p_req_map, "Path"); |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
136 const char *path = p_path_kv ? ((Seobeo_Request_Entry*)p_path_kv)->value : "/"; |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
137 |
|
121
7b1719fa918c
[Seobeo] Added web socket server.
June Park <parkjune1995@gmail.com>
parents:
119
diff
changeset
|
138 // --- 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
|
139 #ifdef SEOBEO_WEBSOCKET_SERVER |
| 141 | 140 Seobeo_Log(SEOBEO_DEBUG, "Web soceket path \n"); |
|
121
7b1719fa918c
[Seobeo] Added web socket server.
June Park <parkjune1995@gmail.com>
parents:
119
diff
changeset
|
141 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
|
142 { |
|
7b1719fa918c
[Seobeo] Added web socket server.
June Park <parkjune1995@gmail.com>
parents:
119
diff
changeset
|
143 Seobeo_Log(SEOBEO_INFO, "WebSocket connection established\n"); |
|
7b1719fa918c
[Seobeo] Added web socket server.
June Park <parkjune1995@gmail.com>
parents:
119
diff
changeset
|
144 if (p_request_arena) |
|
7b1719fa918c
[Seobeo] Added web socket server.
June Park <parkjune1995@gmail.com>
parents:
119
diff
changeset
|
145 Dowa_Arena_Free(p_request_arena); |
|
7b1719fa918c
[Seobeo] Added web socket server.
June Park <parkjune1995@gmail.com>
parents:
119
diff
changeset
|
146 if (p_response_arena) |
|
7b1719fa918c
[Seobeo] Added web socket server.
June Park <parkjune1995@gmail.com>
parents:
119
diff
changeset
|
147 Dowa_Arena_Free(p_response_arena); |
|
7b1719fa918c
[Seobeo] Added web socket server.
June Park <parkjune1995@gmail.com>
parents:
119
diff
changeset
|
148 return; |
|
7b1719fa918c
[Seobeo] Added web socket server.
June Park <parkjune1995@gmail.com>
parents:
119
diff
changeset
|
149 } |
|
124
dbf14f84d51c
Refactor Seobeo and mrjunejune build files so it works.
June Park <parkjune1995@gmail.com>
parents:
121
diff
changeset
|
150 #endif |
|
121
7b1719fa918c
[Seobeo] Added web socket server.
June Park <parkjune1995@gmail.com>
parents:
119
diff
changeset
|
151 |
|
72
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
152 // --- Try to match API route first --- |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
153 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
|
154 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
|
155 { |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
156 Seobeo_Request_Entry *p_response_map = handler(p_req_map, p_response_arena); |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
157 Seobeo_Router_Send_Response(p_cli_handle, p_response_map, p_response_arena); |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
158 goto clean_up; |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
159 } |
|
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
160 |
|
110
99c4530e4629
[Seobeo] Small Syntax fixes.
June Park <parkjune1995@gmail.com>
parents:
101
diff
changeset
|
161 // --- Static files fallback for GET --- |
|
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 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
|
163 { |
|
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
|
164 void *p_kv = Dowa_HashMap_Get_Ptr(p_req_map, "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
|
165 const char *path = p_kv ? ((Seobeo_Request_Entry*)p_kv)->value : 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
|
166 char *file_path = Dowa_Arena_Allocate(p_response_arena, (size_t)5 * 1024); // 5Kb only for path |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
167 |
|
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
|
168 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
|
169 { |
|
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
|
170 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
|
171 } |
|
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
|
172 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
|
173 { |
|
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
|
174 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
|
175 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
|
176 { |
|
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
|
177 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
|
178 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
|
179 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
|
180 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
|
181 } |
|
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
|
182 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
|
183 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
|
184 } |
|
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
|
185 |
|
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
|
186 // Check if file is in cache, load if not |
|
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
|
187 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
|
188 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
|
189 size_t body_size = 0; |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
190 |
|
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
|
191 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
|
192 { |
|
132
7a63e41a21fb
[Seobeo] Added debug targets.
June Park <parkjune1995@gmail.com>
parents:
124
diff
changeset
|
193 // File is cached - use stored size for binary file support |
|
7a63e41a21fb
[Seobeo] Added debug targets.
June Park <parkjune1995@gmail.com>
parents:
124
diff
changeset
|
194 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
|
195 file_content = cached->content; |
|
7a63e41a21fb
[Seobeo] Added debug targets.
June Park <parkjune1995@gmail.com>
parents:
124
diff
changeset
|
196 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
|
197 } |
|
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
|
198 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
|
199 { |
|
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
|
200 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
|
201 if (file_content) |
|
132
7a63e41a21fb
[Seobeo] Added debug targets.
June Park <parkjune1995@gmail.com>
parents:
124
diff
changeset
|
202 { |
|
7a63e41a21fb
[Seobeo] Added debug targets.
June Park <parkjune1995@gmail.com>
parents:
124
diff
changeset
|
203 Seobeo_Cached_File *cached = malloc(sizeof(Seobeo_Cached_File)); |
|
7a63e41a21fb
[Seobeo] Added debug targets.
June Park <parkjune1995@gmail.com>
parents:
124
diff
changeset
|
204 cached->content = (char*)file_content; |
|
7a63e41a21fb
[Seobeo] Added debug targets.
June Park <parkjune1995@gmail.com>
parents:
124
diff
changeset
|
205 cached->size = body_size; |
|
7a63e41a21fb
[Seobeo] Added debug targets.
June Park <parkjune1995@gmail.com>
parents:
124
diff
changeset
|
206 Dowa_HashMap_Push(p_html_cache, file_path, cached); |
|
7a63e41a21fb
[Seobeo] Added debug targets.
June Park <parkjune1995@gmail.com>
parents:
124
diff
changeset
|
207 } |
|
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
|
208 } |
|
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
|
209 |
|
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
|
210 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
|
211 { |
|
19
875bb6e10db7
[Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents:
18
diff
changeset
|
212 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
|
213 HTTP_NOT_FOUND, |
|
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
|
214 "text/html", 0); |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
215 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
|
216 (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
|
217 (uint32)strlen(p_response_header)); |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
218 Seobeo_Handle_Flush(p_cli_handle); |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
219 goto clean_up; |
|
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
220 } |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
221 |
|
154
bdcc610eeed8
[Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents:
141
diff
changeset
|
222 Seobeo_Log(SEOBEO_DEBUG, "Serving Static Files\n"); |
|
72
4532ce6d9eb8
[Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents:
71
diff
changeset
|
223 // Serve static file |
|
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
|
224 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
|
225 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
|
226 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
|
227 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
|
228 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
|
229 else if (strstr(file_path, ".jpg") || strstr(file_path, ".jpeg")) mime = "image/jpeg"; |
|
132
7a63e41a21fb
[Seobeo] Added debug targets.
June Park <parkjune1995@gmail.com>
parents:
124
diff
changeset
|
230 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
|
231 else if (strstr(file_path, ".gif")) mime = "image/gif"; |
|
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
|
232 else if (strstr(file_path, ".svg")) mime = "image/svg+xml"; |
|
947b81010aba
[Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents:
21
diff
changeset
|
233 else if (strstr(file_path, ".ico")) mime = "image/x-icon"; |
|
947b81010aba
[Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents:
21
diff
changeset
|
234 else if (strstr(file_path, ".json")) mime = "application/json"; |
|
100
65e5a5b89a4e
[Seobeo] Migrated everything to this page.
June Park <parkjune1995@gmail.com>
parents:
96
diff
changeset
|
235 else if (strstr(file_path, ".wasm")) mime = "application/wasm"; |
|
132
7a63e41a21fb
[Seobeo] Added debug targets.
June Park <parkjune1995@gmail.com>
parents:
124
diff
changeset
|
236 else if (strstr(file_path, ".mp4")) mime = "video/mp4"; |
|
7a63e41a21fb
[Seobeo] Added debug targets.
June Park <parkjune1995@gmail.com>
parents:
124
diff
changeset
|
237 else if (strstr(file_path, ".webm")) mime = "video/webm"; |
|
7a63e41a21fb
[Seobeo] Added debug targets.
June Park <parkjune1995@gmail.com>
parents:
124
diff
changeset
|
238 else if (strstr(file_path, ".glb")) mime = "model/gltf-binary"; |
|
7a63e41a21fb
[Seobeo] Added debug targets.
June Park <parkjune1995@gmail.com>
parents:
124
diff
changeset
|
239 else if (strstr(file_path, ".gltf")) mime = "model/gltf+json"; |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
240 |
| 96 | 241 Seobeo_Log(SEOBEO_DEBUG, "File path: %s\nBody Size: %zu\n", file_path, body_size); |
|
22
947b81010aba
[Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents:
21
diff
changeset
|
242 |
|
19
875bb6e10db7
[Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents:
18
diff
changeset
|
243 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
|
244 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
|
245 mime, |
|
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 body_size); |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
247 |
|
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
|
248 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
|
249 (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
|
250 (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
|
251 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
|
252 (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
|
253 (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
|
254 Seobeo_Handle_Flush(p_cli_handle); |
| 96 | 255 Seobeo_Log(SEOBEO_DEBUG, "Request handled successfully\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
|
256 } |
|
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 { |
|
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 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
|
260 HTTP_FORBIDDEN, |
|
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 "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
|
262 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
|
263 (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
|
264 (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
|
265 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
|
266 } |
|
33
c0f6c8c7829f
[Seobeo] Linux epoll. Set the client socket to be nonblocking so that it doesn't stop loading when two different threads handle different client calls. I might have problem with socket not being cleaned up properly so need to check that.
MrJuneJune <me@mrjunejune.com>
parents:
22
diff
changeset
|
267 goto clean_up; |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
268 |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
269 clean_up: |
| 96 | 270 Seobeo_Log(SEOBEO_INFO, "Clean up all Arenas\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
|
271 if (p_cli_handle) |
|
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
|
272 Seobeo_Handle_Destroy(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
|
273 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
|
274 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
|
275 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
|
276 Dowa_Arena_Free(p_response_arena); |
|
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
|
277 return; |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
278 } |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
279 |
|
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
|
280 |
|
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
|
281 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
|
282 { |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
283 while (1) |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
284 { |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
285 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
|
286 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
|
287 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
|
288 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
|
289 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
|
290 |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
291 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
|
292 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
|
293 break; |
|
110
99c4530e4629
[Seobeo] Small Syntax fixes.
June Park <parkjune1995@gmail.com>
parents:
101
diff
changeset
|
294 |
|
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
|
295 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
|
296 return 1; // EAGAIN, try again later 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
|
297 } |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
298 |
|
110
99c4530e4629
[Seobeo] Small Syntax fixes.
June Park <parkjune1995@gmail.com>
parents:
101
diff
changeset
|
299 // "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
|
300 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
|
301 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
|
302 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
|
303 |
|
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
|
304 // 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
|
305 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
|
306 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
|
307 { |
|
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
|
308 size_t first_line_len = first_line_end - buf; |
| 96 | 309 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
|
310 } |
|
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
|
311 |
|
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
|
312 // This seems kinda bad ? |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
313 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
|
314 int scan_result = sscanf(buf, "%15s %255s %15s", method, path, version); |
| 96 | 315 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
|
316 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
|
317 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
|
318 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
|
319 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
|
320 |
|
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
|
321 if (scan_result != 3) |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
322 { |
| 96 | 323 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
|
324 return -1; |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
325 } |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
326 |
| 96 | 327 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
|
328 char *method_copy = Dowa_Arena_Allocate(p_arena, strlen(method) + 1); |
| 96 | 329 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
|
330 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
|
331 |
| 96 | 332 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
|
333 char *version_copy = Dowa_Arena_Allocate(p_arena, strlen(version) + 1); |
| 96 | 334 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
|
335 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
|
336 |
| 96 | 337 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
|
338 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
|
339 Dowa_HashMap_Push_Arena(*pp_map, "Version", version_copy, p_arena); |
| 96 | 340 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
|
341 |
|
22
947b81010aba
[Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents:
21
diff
changeset
|
342 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
|
343 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
|
344 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
|
345 |
|
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 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
|
347 { |
|
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 *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
|
349 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
|
350 } |
|
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
|
351 |
|
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 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
|
353 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
|
354 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
|
355 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
|
356 |
|
ffb764d2fcc5
[HgWeb] Updated hg web so it works
June Park <parkjune1995@gmail.com>
parents:
132
diff
changeset
|
357 // Store full query string for proxying |
|
ffb764d2fcc5
[HgWeb] Updated hg web so it works
June Park <parkjune1995@gmail.com>
parents:
132
diff
changeset
|
358 if (query_str && *query_str) |
|
ffb764d2fcc5
[HgWeb] Updated hg web so it works
June Park <parkjune1995@gmail.com>
parents:
132
diff
changeset
|
359 { |
|
ffb764d2fcc5
[HgWeb] Updated hg web so it works
June Park <parkjune1995@gmail.com>
parents:
132
diff
changeset
|
360 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
|
361 if (qs_copy) |
|
ffb764d2fcc5
[HgWeb] Updated hg web so it works
June Park <parkjune1995@gmail.com>
parents:
132
diff
changeset
|
362 { |
|
ffb764d2fcc5
[HgWeb] Updated hg web so it works
June Park <parkjune1995@gmail.com>
parents:
132
diff
changeset
|
363 strcpy(qs_copy, query_str); |
|
ffb764d2fcc5
[HgWeb] Updated hg web so it works
June Park <parkjune1995@gmail.com>
parents:
132
diff
changeset
|
364 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
|
365 } |
|
ffb764d2fcc5
[HgWeb] Updated hg web so it works
June Park <parkjune1995@gmail.com>
parents:
132
diff
changeset
|
366 } |
|
ffb764d2fcc5
[HgWeb] Updated hg web so it works
June Park <parkjune1995@gmail.com>
parents:
132
diff
changeset
|
367 |
|
110
99c4530e4629
[Seobeo] Small Syntax fixes.
June Park <parkjune1995@gmail.com>
parents:
101
diff
changeset
|
368 // 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
|
369 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
|
370 { |
|
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
|
371 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
|
372 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
|
373 { |
|
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
|
374 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
|
375 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
|
376 |
|
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
|
377 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
|
378 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
|
379 { |
|
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
|
380 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
|
381 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
|
382 |
|
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
|
383 char key_buf[256]; |
|
110
99c4530e4629
[Seobeo] Small Syntax fixes.
June Park <parkjune1995@gmail.com>
parents:
101
diff
changeset
|
384 // 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
|
385 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
|
386 |
|
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
|
387 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
|
388 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
|
389 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
|
390 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
|
391 |
|
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
|
392 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
|
393 } |
|
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
|
394 |
|
22
947b81010aba
[Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents:
21
diff
changeset
|
395 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
|
396 } |
|
947b81010aba
[Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents:
21
diff
changeset
|
397 } |
|
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
|
398 |
|
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
|
399 // 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
|
400 // 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
|
401 // 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
|
402 // 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
|
403 |
|
110
99c4530e4629
[Seobeo] Small Syntax fixes.
June Park <parkjune1995@gmail.com>
parents:
101
diff
changeset
|
404 // Parse headers |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
405 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
|
406 while (line < hdr_end) |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
407 { |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
408 char *next = strstr(line, "\r\n"); |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
409 if (!next) break; |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
410 |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
411 // split at colon |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
412 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
|
413 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
|
414 { |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
415 size_t key_len = colon - line; |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
416 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
|
417 |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
418 char *val_start = colon + 1; |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
419 if (*val_start == ' ') |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
420 { |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
421 val_start++; |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
422 value_len--; |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
423 } |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
424 |
|
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
|
425 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
|
426 if (!key) return -1; |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
427 memcpy(key, line, key_len); |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
428 key[key_len] = '\0'; |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
429 |
|
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
|
430 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
|
431 if (!val) return -1; |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
432 memcpy(val, val_start, value_len); |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
433 val[value_len] = '\0'; |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
434 |
|
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
|
435 // Both key and value are arena-allocated, hashmap will use them |
|
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, key, val, p_arena); |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
437 } |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
438 |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
439 line = next + 2; |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
440 } |
|
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
|
441 |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
442 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
|
443 |
|
110
99c4530e4629
[Seobeo] Small Syntax fixes.
June Park <parkjune1995@gmail.com>
parents:
101
diff
changeset
|
444 // 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
|
445 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
|
446 if (p_cl_kv) |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
447 { |
|
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
|
448 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
|
449 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
|
450 |
| 96 | 451 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
|
452 |
|
655ea0b661fd
[Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents:
91
diff
changeset
|
453 // Allocate buffer for entire body |
|
655ea0b661fd
[Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
June Park <parkjune1995@gmail.com>
parents:
91
diff
changeset
|
454 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
|
455 if (!body) |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
456 { |
| 96 | 457 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
|
458 return -1; |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
459 } |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
460 |
|
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
|
461 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
|
462 |
|
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
|
463 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
|
464 { |
|
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
|
465 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
|
466 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
|
467 |
|
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
|
468 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
|
469 { |
|
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
|
470 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
|
471 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
|
472 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
|
473 |
| 96 | 474 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
|
475 } |
|
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
|
476 |
|
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
|
477 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
|
478 { |
|
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
|
479 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
|
480 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
|
481 { |
| 96 | 482 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
|
483 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
|
484 } |
|
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
|
485 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
|
486 { |
|
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
|
487 // 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
|
488 // 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
|
489 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
|
490 } |
|
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
|
491 } |
|
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
|
492 } |
|
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
|
493 |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
494 body[body_len] = '\0'; |
| 96 | 495 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
|
496 |
|
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
|
497 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
|
498 } |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
499 |
|
110
99c4530e4629
[Seobeo] Small Syntax fixes.
June Park <parkjune1995@gmail.com>
parents:
101
diff
changeset
|
500 return 0; |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
501 } |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
502 |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
503 void SigchildHandler(int s) |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
504 { |
|
110
99c4530e4629
[Seobeo] Small Syntax fixes.
June Park <parkjune1995@gmail.com>
parents:
101
diff
changeset
|
505 (void)s; |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
506 |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
507 // 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
|
508 int saved_errno = errno; |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
509 |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
510 while(waitpid(-1, NULL, WNOHANG) > 0); |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
511 |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
512 errno = saved_errno; |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
513 } |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
514 |
|
19
875bb6e10db7
[Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents:
18
diff
changeset
|
515 int Seobeo_Web_Server_Start( |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
516 const char *folder_path, |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
517 const char *port, |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
518 Seobeo_ServerMode mode, |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
519 int thread_count) |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
520 { |
|
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
|
521 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
|
522 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
|
523 |
|
75de5903355c
Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents:
67
diff
changeset
|
524 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
|
525 |
|
66
a0f0ad5e42eb
[Misc] taking out capital P stuff.
June Park <parkjune1995@gmail.com>
parents:
65
diff
changeset
|
526 Seobeo_Handle *p_server_handle = |
|
18
fa2b8af609d9
[Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents:
17
diff
changeset
|
527 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
|
528 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
|
529 |
| 96 | 530 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
|
531 |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
532 if (mode == SEOBEO_MODE_FORK) |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
533 { |
| 96 | 534 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
|
535 struct sigaction sa; |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
536 sa.sa_handler = SigchildHandler; |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
537 sigemptyset(&sa.sa_mask); |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
538 sa.sa_flags = SA_RESTART; |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
539 sigaction(SIGCHLD, &sa, NULL); |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
540 |
|
34
6c322f9c2cb9
[Birthday] I didn't have nay time to buy birhtday present so w/e/
MrJuneJune <me@mrjunejune.com>
parents:
33
diff
changeset
|
541 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
|
542 { |
|
66
a0f0ad5e42eb
[Misc] taking out capital P stuff.
June Park <parkjune1995@gmail.com>
parents:
65
diff
changeset
|
543 Seobeo_Handle *p_cli_handle = |
|
19
875bb6e10db7
[Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents:
18
diff
changeset
|
544 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
|
545 if (!p_cli_handle) continue; |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
546 |
|
16
fb2cff495a60
[Seobeo] Fixed the problem with edge server.
June Park <parkjune1995@gmail.com>
parents:
7
diff
changeset
|
547 if (fork() == 0) |
|
fb2cff495a60
[Seobeo] Fixed the problem with edge server.
June Park <parkjune1995@gmail.com>
parents:
7
diff
changeset
|
548 { |
|
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
|
549 Seobeo_Web_HandleClientRequest(p_cli_handle, |
|
7
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
550 p_html_cache); |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
551 _exit(0); |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
552 } |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
553 } |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
554 } |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
555 |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
556 if (mode == SEOBEO_MODE_EDGE) |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
557 { |
| 96 | 558 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
|
559 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
|
560 } |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
561 |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
562 return -1; |
|
114cad94008f
[Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
563 } |
| 17 | 564 |
| 96 | 565 /* Router logic */ |
| 566 struct Seobeo_Route_Struct { | |
| 567 char *method; // "GET", "POST", "PUT", "DELETE" | |
| 568 char *path_pattern; // "/v1/users/:id/posts/:post_id" | |
| 569 Seobeo_Route_Handler handler; | |
| 570 | |
| 571 // Pre-parsed path segments for efficient matching | |
| 572 char **path_segments; // ["v1", "users", ":id", "posts", ":post_id"] | |
| 573 boolean *is_param; // [false, false, true, false, true] | |
| 574 size_t segment_count; | |
| 575 }; | |
| 576 | |
| 577 static Seobeo_Route *g_routes = NULL; | |
| 578 | |
| 579 void Seobeo_Router_Init() | |
| 580 { | |
| 581 Dowa_Array_Reserve(g_routes, 20); | |
| 582 } | |
| 583 | |
| 584 void Seobeo_Router_Register(const char *method, const char *path_pattern, Seobeo_Route_Handler handler) | |
| 585 { | |
| 586 Seobeo_Route route = {0}; | |
| 587 | |
| 588 route.method = strdup(method); | |
| 589 route.path_pattern = strdup(path_pattern); | |
| 590 route.handler = handler; | |
| 591 route.path_segments = Dowa_String_Split(path_pattern, "/", strlen(path_pattern), 1, NULL); | |
| 592 route.segment_count = Dowa_Array_Length(route.path_segments); | |
| 593 route.is_param = (boolean*)malloc(sizeof(boolean) * route.segment_count); | |
| 594 | |
| 595 for (size_t i = 0; i < route.segment_count; i++) | |
| 596 route.is_param[i] = (route.path_segments[i][0] == ':'); | |
| 597 | |
| 598 Dowa_Array_Push(g_routes, route); | |
| 599 } | |
| 600 | |
| 601 static boolean match_route_and_extract( | |
| 602 Seobeo_Route *route, | |
| 603 const char *request_path, | |
| 604 Seobeo_Request_Entry **pp_request_map, | |
| 605 Dowa_Arena *p_arena) | |
| 606 { | |
| 607 Dowa_Arena *p_temp_arena = Dowa_Arena_Create(1024); | |
| 608 char **request_segments = Dowa_String_Split(request_path, "/", strlen(request_path), 1, p_temp_arena); | |
| 609 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
|
610 |
| 96 | 611 // Check segment count matches |
| 612 if (request_segment_count != route->segment_count) | |
| 613 { | |
| 614 Dowa_Arena_Free(p_temp_arena); | |
| 615 return FALSE; | |
| 616 } | |
| 617 | |
| 618 for (size_t i = 0; i < route->segment_count; i++) | |
| 619 { | |
| 620 // parameters | |
| 621 if (route->is_param[i]) | |
| 622 { | |
| 623 char *param_name = route->path_segments[i]; // e.g., ":id" | |
| 624 char *param_value = request_segments[i]; // e.g., "123" | |
| 625 | |
| 626 // Should Copy to arena | |
| 627 char *key = Dowa_String_Copy_Arena(param_name, p_arena); | |
| 628 char *value = Dowa_String_Copy_Arena(param_value, p_arena); | |
| 629 Dowa_HashMap_Push_Arena(*pp_request_map, key, value, p_arena); | |
| 630 } | |
| 631 else | |
| 632 { | |
| 633 // Does not match. | |
| 634 if (strcmp(route->path_segments[i], request_segments[i]) != 0) | |
| 635 { | |
| 636 Dowa_Arena_Free(p_temp_arena); | |
| 637 return FALSE; | |
| 638 } | |
| 639 } | |
| 640 } | |
| 641 | |
| 642 Dowa_Arena_Free(p_temp_arena); | |
| 643 return TRUE; | |
| 644 } | |
| 645 | |
| 646 Seobeo_Route_Handler Seobeo_Router_Find_Handler(const char *method, | |
| 647 const char *path, | |
| 648 Seobeo_Request_Entry **pp_request_map, | |
| 649 Dowa_Arena *p_arena) { | |
| 650 if (g_routes == NULL) | |
| 651 { | |
| 652 return NULL; | |
| 653 } | |
| 654 | |
| 655 size_t route_count = Dowa_Array_Length(g_routes); | |
| 656 for (size_t i = 0; i < route_count; i++) | |
| 657 { | |
| 658 Seobeo_Route *route = &g_routes[i]; | |
| 659 if (strcmp(route->method, method) != 0) | |
| 660 { | |
| 661 continue; | |
| 662 } | |
| 663 | |
| 664 if (match_route_and_extract(route, path, pp_request_map, p_arena)) | |
| 665 { | |
| 666 return route->handler; | |
| 667 } | |
| 668 } | |
| 669 | |
| 670 return NULL; | |
| 671 } | |
| 672 | |
| 673 void Seobeo_Router_Send_Response( | |
| 674 Seobeo_Handle *p_handle, | |
| 675 Seobeo_Request_Entry *p_response_map, | |
| 676 Dowa_Arena *p_arena) | |
| 677 { | |
| 678 if (p_response_map == NULL) | |
| 679 { | |
| 680 char *header = Dowa_Arena_Allocate(p_arena, 1024); | |
| 681 Seobeo_Web_Header_Generate(header, HTTP_INTERNAL_ERROR, "text/plain", 21); | |
| 682 Seobeo_Handle_Queue(p_handle, (uint8_t*)header, strlen(header)); | |
| 683 Seobeo_Handle_Queue(p_handle, (uint8_t*)"Internal Server Error", 21); | |
| 684 Seobeo_Handle_Flush(p_handle); | |
| 685 return; | |
| 686 } | |
| 687 | |
| 688 int status = HTTP_OK; | |
| 689 void *p_status_kv = Dowa_HashMap_Get_Ptr(p_response_map, "status"); | |
| 690 if (p_status_kv) | |
| 691 { | |
| 692 const char *status_str = ((Seobeo_Request_Entry*)p_status_kv)->value; | |
| 693 status = atoi(status_str); | |
| 694 } | |
| 695 | |
| 696 const char *body = ""; | |
| 697 void *p_body_kv = Dowa_HashMap_Get_Ptr(p_response_map, "body"); | |
| 698 if (p_body_kv) | |
| 699 { | |
| 700 body = ((Seobeo_Request_Entry*)p_body_kv)->value; | |
| 701 } | |
| 702 | |
| 703 const char *content_type = "text/html"; | |
| 704 void *p_content_type_kv = Dowa_HashMap_Get_Ptr(p_response_map, "content-type"); | |
| 705 if (p_content_type_kv) | |
| 706 { | |
| 707 content_type = ((Seobeo_Request_Entry*)p_content_type_kv)->value; | |
| 708 } | |
| 709 | |
| 710 size_t body_length = strlen(body); | |
| 711 void *p_content_length_kv = Dowa_HashMap_Get_Ptr(p_response_map, "content-length"); | |
| 712 if (p_content_length_kv) | |
| 713 { | |
| 714 const char *content_length_str = ((Seobeo_Request_Entry*)p_content_length_kv)->value; | |
| 715 body_length = atoi(content_length_str); | |
| 716 } | |
| 717 | |
| 718 char *header = Dowa_Arena_Allocate(p_arena, 4096); | |
| 719 Seobeo_Web_Header_Generate(header, status, content_type, body_length); | |
| 720 for (int i = 0; i < Dowa_Array_Length(p_response_map); i++) | |
| 721 { | |
| 722 if ( | |
| 723 strstr(p_response_map[i].key, "status") || | |
| 724 strstr(p_response_map[i].key, "body") || | |
| 725 strstr(p_response_map[i].key, "content-type") || | |
|
110
99c4530e4629
[Seobeo] Small Syntax fixes.
June Park <parkjune1995@gmail.com>
parents:
101
diff
changeset
|
726 strstr(p_response_map[i].key, "content-length") |
| 96 | 727 ) |
| 728 continue; | |
| 729 | |
| 730 int32 current_header_len = strlen(header); | |
| 731 char *temp = malloc(sizeof(char) * 1024); | |
| 732 sprintf(temp, "%s: %s\r\n\r\n", p_response_map[i].key, p_response_map[i].value); | |
| 733 memcpy(&header[current_header_len - 2 /* \r\n */], temp, strlen(temp)); | |
| 734 free(temp); | |
| 735 } | |
| 736 | |
| 737 Seobeo_Handle_Queue(p_handle, (uint8_t*)header, strlen(header)); | |
|
110
99c4530e4629
[Seobeo] Small Syntax fixes.
June Park <parkjune1995@gmail.com>
parents:
101
diff
changeset
|
738 Seobeo_Handle_Queue(p_handle, (uint8_t*)body, body_length); |
| 96 | 739 Seobeo_Handle_Flush(p_handle); |
| 740 } | |
| 741 | |
| 742 void Seobeo_Router_Destroy() | |
| 743 { | |
| 744 if (g_routes == NULL) | |
| 745 return; | |
| 746 | |
| 747 size_t route_count = Dowa_Array_Length(g_routes); | |
| 748 for (size_t i = 0; i < route_count; i++) | |
| 749 { | |
| 750 Seobeo_Route *route = &g_routes[i]; | |
| 751 if (route->method) free(route->method); | |
| 752 if (route->path_pattern) free(route->path_pattern); | |
| 753 if (route->path_segments) Dowa_Array_Free(route->path_segments); | |
| 754 if (route->is_param) free(route->is_param); | |
| 755 } | |
| 756 Dowa_Array_Free(g_routes); | |
| 757 g_routes = NULL; | |
| 758 } | |
| 759 | |
|
124
dbf14f84d51c
Refactor Seobeo and mrjunejune build files so it works.
June Park <parkjune1995@gmail.com>
parents:
121
diff
changeset
|
760 // Logging functions moved to s_logging.c |
| 96 | 761 |