annotate seobeo/s_web.c @ 73:ede391ac83c8

[MrJuneJune] My own websites.
author June Park <parkjune1995@gmail.com>
date Wed, 31 Dec 2025 09:07:29 -0800
parents 4532ce6d9eb8
children 35b1abc37969
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1 #include "seobeo/seobeo.h"
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 // Global folder path for serving files
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server 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 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
5
17
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
6 int Seobeo_Web_GenerateRequestHeader(void *buffer, const char *host,
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
7 const char *path)
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
8 {
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
9 return sprintf(
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
10 buffer,
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
11 "GET %s HTTP/1.1\r\n"
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
12 "Host: %s\r\n"
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
13 "Connection: close\r\n"
18
fa2b8af609d9 [Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents: 17
diff changeset
14 "accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7\r\n"
fa2b8af609d9 [Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents: 17
diff changeset
15 "accept-language: en-GB,en;q=0.9,en-US;q=0.8,ko;q=0.7\r\n"
fa2b8af609d9 [Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents: 17
diff changeset
16 "if-modified-since: Sat, 02 Aug 2025 22:51:58 GMT\r\n"
fa2b8af609d9 [Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents: 17
diff changeset
17 "if-none-match: W/\"688e968e-5700\"\r\n"
fa2b8af609d9 [Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents: 17
diff changeset
18 "priority: u=0, i\r\n"
fa2b8af609d9 [Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents: 17
diff changeset
19 "sec-ch-ua: \"Chromium\";v=\"140\", \"Not=A?Brand\";v=\"24\", \"Google Chrome\";v=\"140\"\r\n"
fa2b8af609d9 [Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents: 17
diff changeset
20 "sec-ch-ua-mobile: 0\r\n"
fa2b8af609d9 [Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents: 17
diff changeset
21 "sec-ch-ua-platform: \"macOS\"\r\n"
fa2b8af609d9 [Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents: 17
diff changeset
22 "sec-fetch-dest: document\r\n"
fa2b8af609d9 [Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents: 17
diff changeset
23 "sec-fetch-mode: navigate\r\n"
fa2b8af609d9 [Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents: 17
diff changeset
24 "sec-fetch-site: none\r\n"
fa2b8af609d9 [Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents: 17
diff changeset
25 "sec-fetch-user: 1\r\n"
fa2b8af609d9 [Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents: 17
diff changeset
26 "upgrade-insecure-requests: 1\r\n"
17
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
27 "\r\n",
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
28 path, host
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
29 );
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
30 }
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
31
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
32 // Load file from disk and cache it
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server 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 static char* Seobeo_Web_LoadFile(const char *file_path, size_t *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
34 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
35 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
36 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
37
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
38 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
39 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
40 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
41
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
42 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
43 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
44 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
45
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
46 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
47 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
48 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
49 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
50 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
51 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
52
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
53 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
54 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
55 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
56
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
57 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
58 *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
59
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
60 return 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
61 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
62
19
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 18
diff changeset
63 void Seobeo_Web_Header_Generate(void *buffer, int status,
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
64 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
65 {
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
66 const char *status_text;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
67 switch(status)
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
68 {
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
69 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
70 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
71 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
72 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
73 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
74 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
75 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
76 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
77 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
78 default: status_text = "Unknown"; break;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
79 }
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
80
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
81 sprintf(
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
82 buffer,
18
fa2b8af609d9 [Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents: 17
diff changeset
83 "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
84 "Content-Type: %s\r\n"
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
85 "Content-Length: %d\r\n"
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
86 "Connection: close\r\n"
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
87 "\r\n",
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
88 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
89 );
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
90 }
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
91
66
a0f0ad5e42eb [Misc] taking out capital P stuff.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
92 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
93 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
94 {
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
95 Dowa_Arena *p_request_arena = Dowa_Arena_Create(1*1024*1024); // 1MB for request parsing
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
96 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
97
72
4532ce6d9eb8 [Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents: 71
diff changeset
98 Dowa_Arena *p_response_arena = Dowa_Arena_Create(5*1024*1024); // 1MB 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
99 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
100
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
101 void *p_response_header = Dowa_Arena_Allocate(p_response_arena, (size_t)1024*5); // 5Kb
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
102 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
103
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
104 // Parse request headers into hashmap using 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
105 Seobeo_Request_Entry *p_req_map = 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
106 if (Seobeo_Web_Header_Parse(p_cli_handle, &p_req_map, p_request_arena) != 0)
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
107 {
19
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 18
diff changeset
108 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
109 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
110 "text/plain", 0);
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
111 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
112 (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
113 (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
114 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
115 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
116 }
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
117
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
118 // Extract method (GET, POST, etc.)
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
119 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
120 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
121
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can 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 {
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
124 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
125 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
126 "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
127 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
128 (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
129 (uint32)strlen(p_response_header));
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
130 Seobeo_Handle_Flush(p_cli_handle);
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
131 goto clean_up;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
132 }
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
133
72
4532ce6d9eb8 [Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents: 71
diff changeset
134 // Extract path
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
4532ce6d9eb8 [Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents: 71
diff changeset
138 // --- 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
139 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
140
4532ce6d9eb8 [Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents: 71
diff changeset
141 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
142 {
4532ce6d9eb8 [Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents: 71
diff changeset
143 // Call the API handler
4532ce6d9eb8 [Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents: 71
diff changeset
144 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
145
4532ce6d9eb8 [Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents: 71
diff changeset
146 // Send the response
4532ce6d9eb8 [Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents: 71
diff changeset
147 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
148 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
149 }
4532ce6d9eb8 [Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents: 71
diff changeset
150
4532ce6d9eb8 [Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents: 71
diff changeset
151 // --- Handle different HTTP methods (static files fallback) ---
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
152 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
153 {
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
154 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
155 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
156 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
157
22
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
158 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
159 {
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
160 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
161 }
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can 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 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
163 {
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
164 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
165 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
166 {
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
167 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
168 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
169 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
170 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
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 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
174 }
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can 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
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
176 // 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
177 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
178 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
179 size_t body_size = 0;
18
fa2b8af609d9 [Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents: 17
diff changeset
180
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
181 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
182 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
183 // File is cached
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
184 file_content = ((Seobeo_Cache_Entry*)p_file_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
185 body_size = strlen(file_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
186 }
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server 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 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
188 {
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server 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 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
190 if (file_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
191 Dowa_HashMap_Push(p_html_cache, file_path, 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
192 }
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
193
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
194 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
195 {
19
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 18
diff changeset
196 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
197 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
198 "text/html", 0);
18
fa2b8af609d9 [Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents: 17
diff changeset
199 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
200 (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
201 (uint32)strlen(p_response_header));
18
fa2b8af609d9 [Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents: 17
diff changeset
202 Seobeo_Handle_Flush(p_cli_handle);
fa2b8af609d9 [Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents: 17
diff changeset
203 goto clean_up;
fa2b8af609d9 [Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents: 17
diff changeset
204 }
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
205
72
4532ce6d9eb8 [Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents: 71
diff changeset
206 // 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
207 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
208 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
209 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
210 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
211 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
212 else if (strstr(file_path, ".jpg") || strstr(file_path, ".jpeg")) mime = "image/jpeg";
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can 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 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
214 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
215 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
216 else if (strstr(file_path, ".json")) mime = "application/json";
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
217
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
218 printf("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
219
19
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 18
diff changeset
220 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
221 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
222 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
223 body_size);
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
224
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
225 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
226 (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
227 (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
228 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
229 (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
230 (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
231 Seobeo_Handle_Flush(p_cli_handle);
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
232 printf("DONE\n\n\n");
22
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
233 }
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can 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
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
235 {
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
236 Seobeo_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
237 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
238 "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
239 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
240 (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
241 (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
242 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
243 }
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
244 goto clean_up;
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
245
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
246 clean_up:
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
247 printf("clean up\n\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
248 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
249 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
250 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
251 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
252 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
253 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
254 return;
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
255 }
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
256
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
257
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
258 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
259 {
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
260 // 1) Fill read_buffer until we see "\r\n\r\n"
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
261 while (1)
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
262 {
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
263 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
264 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
265 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
266 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
267 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
268
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
269 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
270 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
271 {
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
272 break;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
273 }
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
274 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
275 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
276 }
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
277
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
278 // 2) Parse request‐line "METHOD SP PATH SP VERSION CRLF"
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
279 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
280 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
281 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
282
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
283 // This seems kinda bad ?
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
284 char method[16], path[256], version[16];
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
285 if (sscanf(buf, "%15s %255s %15s", method, path, version) != 3)
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
286 {
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
287 return -1;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
288 }
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
289
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
290 // Copy strings to arena and store in hashmap
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
291 char *method_copy = Dowa_Arena_Allocate(p_arena, strlen(method) + 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
292 if (!method_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
293 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
294
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server 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 char *version_copy = Dowa_Arena_Allocate(p_arena, strlen(version) + 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
296 if (!version_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
297 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
298
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
299 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
300 Dowa_HashMap_Push_Arena(*pp_map, "Version", version_copy, p_arena);
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
301
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
302 // 1) Separate raw path and query string
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
303 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
304 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
305 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
306
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
307 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
308 {
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
309 *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
310 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
311 }
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can 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
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
313 // push only the clean path
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
314 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
315 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
316 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
317 Dowa_HashMap_Push_Arena(*pp_map, "Path", path_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
318
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
319 // 2) If there *is* a query, tokenize into the same map with "query_" prefix
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
320 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
321 {
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
322 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
323 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
324 {
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
325 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
326 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
327
22
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
328 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
329 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
330 {
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
331 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
332 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
333
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
334 char key_buf[256];
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server 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 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
336
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
337 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
338 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
339 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
340 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
341
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
342 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
343 }
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
344
22
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
345 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
346 }
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can 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
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can 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 // 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
350 // 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
351 // 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
352 // 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
353
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
354 // 3) Parse each header line until the blank line
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
355 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
356 while (line < hdr_end)
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
357 {
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
358 char *next = strstr(line, "\r\n");
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
359 if (!next) break;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
360
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
361 // split at colon
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
362 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
363 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
364 {
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
365 size_t key_len = colon - line;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
366 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
367
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
368 char *val_start = colon + 1;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
369 if (*val_start == ' ')
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
370 {
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
371 val_start++;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
372 value_len--;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
373 }
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
374
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
375 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
376 if (!key) return -1;
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
377 memcpy(key, line, key_len);
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
378 key[key_len] = '\0';
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
379
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
380 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
381 if (!val) return -1;
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
382 memcpy(val, val_start, value_len);
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
383 val[value_len] = '\0';
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
384
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 // 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
386 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
387 }
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
388
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
389 line = next + 2;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
390 }
71
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
391
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
392 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
393
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
394 // 4) If Content-Length was provided, read that much 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
395 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
396 if (p_cl_kv)
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
397 {
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
398 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
399 size_t body_len = atoi(content_length_str);
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
400 while (p_handle->read_buffer_len < body_len)
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
401 {
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
402 int r = Seobeo_Handle_Read(p_handle);
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
403 if (r < 0) return -1;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
404 if (r == 0) return 1; // wait for more data
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
405 }
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
406
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
407 char *body = Dowa_Arena_Allocate(p_arena, body_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
408 if (!body) return -1;
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
409 memcpy(body, p_handle->read_buffer, body_len);
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
410 body[body_len] = '\0';
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
411
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
412 // Body is arena-allocated
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
413 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
414
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
415 Seobeo_Handle_Consume(p_handle, (uint32)body_len);
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
416 }
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
417
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
418 return 0; // success; map now holds Method, Path, Version, headers, and optional Body
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
419 }
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 // TODO: Do epoll or kqueue depending on the OS.
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
422 void SigchildHandler(int s)
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 (void)s; // quiet unused variable warning
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
425
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
426 // 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
427 int saved_errno = errno;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
428
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
429 while(waitpid(-1, NULL, WNOHANG) > 0);
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
430
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
431 errno = saved_errno;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
432 }
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
433
19
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 18
diff changeset
434 int Seobeo_Web_Server_Start(
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
435 const char *folder_path,
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
436 const char *port,
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
437 Seobeo_ServerMode mode,
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
438 int thread_count)
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
439 {
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
440 // Store folder path globally
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server 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 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
442 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
443
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server side instead of file level caching. Deleted bunch of things I don't really use.
June Park <parkjune1995@gmail.com>
parents: 67
diff changeset
444 // Initialize empty cache - files will be loaded on-demand
75de5903355c Giagantic changes that update Dowa library to be more align with stb style array and hashmap. Updated Seobeo to be caching on server 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 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
446
66
a0f0ad5e42eb [Misc] taking out capital P stuff.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
447 Seobeo_Handle *p_server_handle =
18
fa2b8af609d9 [Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents: 17
diff changeset
448 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
449 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
450
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
451 printf("Listening on port %s\n", port);
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
452
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
453 // Fork‐based fallback
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
454 if (mode == SEOBEO_MODE_FORK)
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
455 {
18
fa2b8af609d9 [Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents: 17
diff changeset
456 printf("FORK MODE\n");
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
457 struct sigaction sa;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
458 sa.sa_handler = SigchildHandler;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
459 sigemptyset(&sa.sa_mask);
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
460 sa.sa_flags = SA_RESTART;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
461 sigaction(SIGCHLD, &sa, NULL);
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
462
34
6c322f9c2cb9 [Birthday] I didn't have nay time to buy birhtday present so w/e/
MrJuneJune <me@mrjunejune.com>
parents: 33
diff changeset
463 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
464 {
66
a0f0ad5e42eb [Misc] taking out capital P stuff.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
465 Seobeo_Handle *p_cli_handle =
19
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 18
diff changeset
466 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
467 if (!p_cli_handle) continue;
7
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
468
16
fb2cff495a60 [Seobeo] Fixed the problem with edge server.
June Park <parkjune1995@gmail.com>
parents: 7
diff changeset
469 if (fork() == 0)
fb2cff495a60 [Seobeo] Fixed the problem with edge server.
June Park <parkjune1995@gmail.com>
parents: 7
diff changeset
470 {
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
471 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
472 p_html_cache);
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
473 _exit(0);
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
474 }
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
475 }
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
476 }
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
477
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
478 if (mode == SEOBEO_MODE_EDGE)
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
479 {
18
fa2b8af609d9 [Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents: 17
diff changeset
480 printf("EDGE MODE\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
481 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
482 }
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
483
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
484 return -1;
114cad94008f [Seobeo] Updated to support thread and edge server calls.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
485 }
17
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
486
19
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 18
diff changeset
487 int Seobeo_Web_Client_Get(const char *host,
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 18
diff changeset
488 const char *port,
875bb6e10db7 [Seobeo] Chaning Function naming to be easily readable.
June Park <parkjune1995@gmail.com>
parents: 18
diff changeset
489 const char *path)
17
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
490 {
66
a0f0ad5e42eb [Misc] taking out capital P stuff.
June Park <parkjune1995@gmail.com>
parents: 65
diff changeset
491 Seobeo_Handle *h = Seobeo_Stream_Handle_Client_Create(host, port, TRUE);
17
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
492 if (!h || h->socket < 0)
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
493 {
18
fa2b8af609d9 [Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents: 17
diff changeset
494 if (h)
fa2b8af609d9 [Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents: 17
diff changeset
495 Seobeo_Handle_Destroy(h);
17
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
496 return -1;
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
497 }
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
498
65
ecb6ee6a22c3 [Misc] I will no longer drink cool aids of capital P.
June Park <parkjune1995@gmail.com>
parents: 62
diff changeset
499 Dowa_Arena *p_request_arena = Dowa_Arena_Create(1 * 1024 * 1024);
18
fa2b8af609d9 [Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents: 17
diff changeset
500 if (!p_request_arena) { perror("Dowa_Arena_Create"); return -1; }
fa2b8af609d9 [Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents: 17
diff changeset
501
17
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
502 void *p_request_header = Dowa_Arena_Allocate(p_request_arena, 4096);
18
fa2b8af609d9 [Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents: 17
diff changeset
503 if (!p_request_header) { perror("Dowa_Arena_Allocate"); return -1; }
17
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
504
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
505 int request_len = Seobeo_Web_GenerateRequestHeader(p_request_header, host, path);
18
fa2b8af609d9 [Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents: 17
diff changeset
506 // DEBUG
fa2b8af609d9 [Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents: 17
diff changeset
507 // printf("request: %s\n", (char *)p_request_header);
17
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
508 Seobeo_Handle_Queue(h, (uint8 *)p_request_header, (uint32)request_len);
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
509 if (Seobeo_Handle_Flush(h) < 0)
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
510 {
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
511 perror("Seobeo_Handle_Flush");
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
512 Seobeo_Handle_Destroy(h);
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
513 return -1;
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
514 }
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
515
18
fa2b8af609d9 [Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents: 17
diff changeset
516 // Response
17
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
517 size_t cap = 1024*8, used = 0;
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
518 char *p_request_body = Dowa_Arena_Allocate(p_request_arena, cap);
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
519 if (!p_request_body) { Seobeo_Handle_Destroy(h); return -1; }
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
520
18
fa2b8af609d9 [Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents: 17
diff changeset
521 while (1)
fa2b8af609d9 [Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents: 17
diff changeset
522 {
17
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
523 int n = Seobeo_Handle_Read(h);
18
fa2b8af609d9 [Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents: 17
diff changeset
524 printf("Size: %d\n", n);
17
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
525 if (n > 0)
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
526 {
18
fa2b8af609d9 [Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents: 17
diff changeset
527 // TODO: Maybe directly use arena inside of the struct? idk if that is useful or not...
17
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
528 memcpy(p_request_body + used, h->read_buffer, h->read_buffer_len);
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
529 used += h->read_buffer_len;
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
530 Seobeo_Handle_Consume(h, (uint32)h->read_buffer_len);
18
fa2b8af609d9 [Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents: 17
diff changeset
531 }else if (n == 0)
17
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
532 {
18
fa2b8af609d9 [Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents: 17
diff changeset
533 // Wait
17
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
534 continue;
18
fa2b8af609d9 [Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents: 17
diff changeset
535 }else if (n == -2)
17
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
536 {
18
fa2b8af609d9 [Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents: 17
diff changeset
537 // Debug
17
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
538 // peer closed; we’ve got everything
18
fa2b8af609d9 [Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents: 17
diff changeset
539 printf("\n\nCLOSED\n\n");
17
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
540 break;
18
fa2b8af609d9 [Seobeo] Fixed a bug with pathing. Support SSL.
June Park <parkjune1995@gmail.com>
parents: 17
diff changeset
541 }else
17
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
542 {
72
4532ce6d9eb8 [Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents: 71
diff changeset
543 Dowa_Arena_Free(p_request_arena);
17
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
544 Seobeo_Handle_Destroy(h);
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
545 return -1;
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
546 }
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
547 }
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
548
22
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
549 // Debug
947b81010aba [Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
June Park <parkjune1995@gmail.com>
parents: 21
diff changeset
550 printf("Request body %s", p_request_body);
72
4532ce6d9eb8 [Seobeo] Added router to the server logic. Few dowa string manipulation logics.
June Park <parkjune1995@gmail.com>
parents: 71
diff changeset
551 Dowa_Arena_Free(p_request_arena);
17
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
552 Seobeo_Handle_Destroy(h);
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
553 return 0;
d97ec3ded2ae [Seobeo] Few changes...
June Park <parkjune1995@gmail.com>
parents: 16
diff changeset
554 }