Mercurial
diff seobeo/s_web.c @ 21:09def63429b9
[Dowa] Updated the naming scheme and tests.
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Mon, 06 Oct 2025 10:57:30 -0700 |
| parents | 875bb6e10db7 |
| children | 947b81010aba |
line wrap: on
line diff
--- a/seobeo/s_web.c Mon Oct 06 10:13:41 2025 -0700 +++ b/seobeo/s_web.c Mon Oct 06 10:57:30 2025 -0700 @@ -58,19 +58,17 @@ void Seobeo_Web_HandleClientRequest(Seobeo_PHandle p_cli_handle, Dowa_PHashMap p_html_cache) { - Dowa_PArena p_response_arena = Dowa_Arena_Create(8192); - Dowa_PHashMap p_req_map = NULL; - Dowa_PHashEntry entry = NULL; Dowa_PHashMap p_current = p_html_cache; char *slash; + Dowa_PArena p_response_arena = Dowa_Arena_Create(8192); if (!p_response_arena) { perror("Dowa_Arena_Initialize"); goto clean_up; } void *p_response_header = Dowa_Arena_Allocate(p_response_arena, (size_t)2048); if (!p_response_header) { perror("Dowa_Arena_Allocate"); goto clean_up; } - p_req_map = Dowa_HashMap_Create(32); + Dowa_PHashMap p_req_map = Dowa_HashMap_Create_With_Arena(32, p_response_arena); if (Seobeo_Web_Header_Parse(p_cli_handle, p_req_map) != 0) { // malformed request or closed — respond 400 @@ -137,7 +135,7 @@ } } - size_t pos = Dowa_HashMap_GetPosition(p_current, file_path); + size_t pos = Dowa_HashMap_Get_Position(p_current, file_path); entry = p_current->entries[pos]; // Missing so 404 @@ -188,9 +186,7 @@ if (p_cli_handle) Seobeo_Handle_Destroy(p_cli_handle); if (p_response_arena) - Dowa_Arena_Free(p_response_arena); - if (p_req_map) - Dowa_HashMap_Free(p_req_map); // TODO: Maybe initilized hashmap within the Arena? + Dowa_Arena_Destroy(p_response_arena); } int Seobeo_Web_Header_Parse(Seobeo_PHandle p_handle, Dowa_PHashMap map) @@ -221,9 +217,9 @@ return -1; } - Dowa_HashMap_PushValueWithType(map, "Method", method, strlen(method) + 1, DOWA_HASH_MAP_TYPE_STRING); - Dowa_HashMap_PushValueWithType(map, "Path", path, strlen(path) + 1, DOWA_HASH_MAP_TYPE_STRING); - Dowa_HashMap_PushValueWithType(map, "Version", version, strlen(version) + 1, DOWA_HASH_MAP_TYPE_STRING); + Dowa_HashMap_Push_Value_With_Type(map, "Method", method, strlen(method) + 1, DOWA_HASH_MAP_TYPE_STRING); + Dowa_HashMap_Push_Value_With_Type(map, "Path", path, strlen(path) + 1, DOWA_HASH_MAP_TYPE_STRING); + Dowa_HashMap_Push_Value_With_Type(map, "Version", version, strlen(version) + 1, DOWA_HASH_MAP_TYPE_STRING); // 3) Parse each header line until the blank line char *line = buf + strlen(method) + 1 + strlen(path) + 1 + strlen(version) + 2; @@ -253,7 +249,7 @@ memcpy(val, val_start, value_len); val[value_len] = '\0'; - Dowa_HashMap_PushValue(map, key, val, value_len + 1); + Dowa_HashMap_Push_Value(map, key, val, value_len + 1); free(key); free(val); @@ -264,7 +260,7 @@ Seobeo_Handle_Consume(p_handle, (uint32)hdr_len); // 4) If Content-Length was provided, read that much body - int content_length_pos = Dowa_HashMap_GetPosition(map, "Content-Length"); + int content_length_pos = Dowa_HashMap_Get_Position(map, "Content-Length"); Dowa_PHashEntry p_content_length_entry = map->entries[content_length_pos]; if (p_content_length_entry) { @@ -280,7 +276,7 @@ memcpy(body, p_handle->read_buffer, body_len); body[body_len] = '\0'; - Dowa_HashMap_PushValue(map, "Body", body, body_len + 1); + Dowa_HashMap_Push_Value(map, "Body", body, body_len + 1); free(body); Seobeo_Handle_Consume(p_handle, (uint32)body_len); @@ -308,7 +304,7 @@ Seobeo_ServerMode mode, int thread_count) { - Dowa_PHashMap p_html_cache = Dowa_HashMap_Create(1024); + Dowa_PHashMap p_html_cache = Dowa_HashMap_Create(200); if (Dowa_HashMap_Cache_Folder(p_html_cache, folder_path) != 0) { @@ -412,14 +408,14 @@ break; }else { - Dowa_Arena_Free(p_request_arena); + Dowa_Arena_Destroy(p_request_arena); Seobeo_Handle_Destroy(h); return -1; } } printf("%s", p_request_body); - Dowa_Arena_Free(p_request_arena); + Dowa_Arena_Destroy(p_request_arena); Seobeo_Handle_Destroy(h); return 0; }