# HG changeset patch # User June Park # Date 1759773450 25200 # Node ID 09def63429b97169d316ccc963649bfd5c83b1d2 # Parent 0a9e67c7039a0df7f5d5bf3145d3f17f3d938617 [Dowa] Updated the naming scheme and tests. diff -r 0a9e67c7039a -r 09def63429b9 README.md --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.md Mon Oct 06 10:57:30 2025 -0700 @@ -0,0 +1,15 @@ +# Zenbu + +This is a mono repo where I will share all my codes and utilize them using bazel. +I decied to do this since I re-use codes often and I don't want to deal with making make +and cmake every time and this eliminates the problem that exists within C or C++ where using +library is harder as we need to add gzillian stuff into it lmao. + +# Debugging Command + +```bash +bazel build target -c dbg +i.e) bazel build //mrjunejune:mrjunejune_server -c dbg +``` + +And run whatever your favoriate debugging tools diff -r 0a9e67c7039a -r 09def63429b9 dowa/d_memory.c --- a/dowa/d_memory.c Mon Oct 06 10:13:41 2025 -0700 +++ b/dowa/d_memory.c Mon Oct 06 10:57:30 2025 -0700 @@ -26,7 +26,7 @@ return currnet_ptr; } -void Dowa_Arena_Destory(Dowa_PArena p_arena) +void Dowa_Arena_Destroy(Dowa_PArena p_arena) { if (p_arena) { @@ -56,10 +56,10 @@ return p_hash_map; } -Dowa_PHashMap Dowa_HashMap_Create(size_t capacity, Dowa_PArena p_arena) +Dowa_PHashMap Dowa_HashMap_Create_With_Arena(size_t capacity, Dowa_PArena p_arena) { if (p_arena == NULL) - printf("Arena is NULL"); + printf("Arena is NULL\n"); return Dowa_HashMap_Create(capacity); Dowa_PHashMap p_hash_map; @@ -80,12 +80,12 @@ return p_hash_map; } -void Dowa_HashMap_Destory(Dowa_PHashMap p_hash_map) +void Dowa_HashMap_Destroy(Dowa_PHashMap p_hash_map) { if (!p_hash_map) return; if (p_hash_map->p_arena) - Dowa_Arena_Destory(p_hash_map->p_arena); + Dowa_Arena_Destroy(p_hash_map->p_arena); else { Dowa_PHashEntry entry; @@ -107,7 +107,7 @@ free(p_hash_map); } -int32 Dowa_HashMap_Get_Position(Dowa_PHashMap p_hash_map, char *key) +int32 Dowa_HashMap_Get_Position(Dowa_PHashMap p_hash_map, const char *key) { int32 hash_val = HASH_KEY_NUMBER; int32 c; @@ -118,7 +118,7 @@ return hash_val % p_hash_map->capacity; } -void *Dowa_HashMap_Get(Dowa_PHashMap p_hash_map, char *key) +void *Dowa_HashMap_Get(Dowa_PHashMap p_hash_map, const char *key) { int idx_foo = Dowa_HashMap_Get_Position(p_hash_map, key); void *value = p_hash_map->entries[idx_foo]; @@ -129,9 +129,11 @@ return ((Dowa_PHashEntry) value)->buffer; } -int32 Dowa_HashMap_Push_Value_With_Type_NoCopy(Dowa_PHashMap p_hash_map, char *key, void *value, size_t value_size, Dowa_HashMap_ValueType type) +int32 Dowa_HashMap_Push_Value_With_Type_NoCopy(Dowa_PHashMap p_hash_map, const char *key, + void *value, size_t value_size, + Dowa_HashMap_ValueType type) { - int idx = Dowa_HashMap_GetPosition(p_hash_map, key); + int idx = Dowa_HashMap_Get_Position(p_hash_map, key); Dowa_PHashEntry entry = p_hash_map->entries[idx]; if (entry) free(entry->buffer); @@ -152,9 +154,11 @@ return 0; } -int32 Dowa_HashMap_Push_Value_With_Type(Dowa_PHashMap p_hash_map, char *key, void *value, size_t value_size, Dowa_HashMap_ValueType type) +int32 Dowa_HashMap_Push_Value_With_Type(Dowa_PHashMap p_hash_map, const char *key, + void *value, size_t value_size, + Dowa_HashMap_ValueType type) { - int idx = Dowa_HashMap_GetPosition(p_hash_map, key); + int idx = Dowa_HashMap_Get_Position(p_hash_map, key); Dowa_PHashEntry entry = p_hash_map->entries[idx]; if (entry) free(entry->buffer); @@ -180,14 +184,14 @@ return 0; } -void Dowa_HashMap_Push_Value(Dowa_PHashMap p_hash_map, char *key, void *value, size_t value_size) +void Dowa_HashMap_Push_Value(Dowa_PHashMap p_hash_map, const char *key, void *value, size_t value_size) { Dowa_HashMap_Push_Value_With_Type(p_hash_map, key, value, value_size, DOWA_HASH_MAP_TYPE_BUFFER); } -void Dowa_HashMap_Pop_Key(Dowa_PHashMap p_hash_map, char *key) +void Dowa_HashMap_Pop_Key(Dowa_PHashMap p_hash_map, const char *key) { - int idx = Dowa_HashMap_GetPosition(p_hash_map, key); + int idx = Dowa_HashMap_Get_Position(p_hash_map, key); Dowa_PHashEntry entry = p_hash_map->entries[idx]; if (entry) { @@ -273,8 +277,8 @@ if (!f) { perror("fopen"); continue; } void *buf = p_hash_map->p_arena ? - Dowa_Arena_Allocate(p_hash_map->p_arena, value_size) : - malloc(value_size); + Dowa_Arena_Allocate(p_hash_map->p_arena, size) : + malloc(size); if (!buf) { perror("malloc"); fclose(f); closedir(dir); return -1; } if (fread(buf, 1, size, f) != size) @@ -286,12 +290,12 @@ } fclose(f); - Dowa_HashMap_PushValueWithType(p_hash_map, entry->d_name, buf, size, DOWA_HASH_MAP_TYPE_STRING); + Dowa_HashMap_Push_Value_With_Type(p_hash_map, entry->d_name, buf, size, DOWA_HASH_MAP_TYPE_STRING); free(buf); // Dowa_HashMap_PushValue made its own copy } else if (S_ISDIR(st.st_mode)) { - Dowa_PHashMap p_child_map = Dowa_HashMap_Create(100, p_hash_map->p_arena); + Dowa_PHashMap p_child_map = Dowa_HashMap_Create_With_Arena(100, p_hash_map->p_arena); if (!p_child_map) { perror("Dowa_HashMap_Create"); @@ -307,7 +311,7 @@ if (Dowa_HashMap_Push_Value_With_Type_NoCopy(p_hash_map, entry->d_name, p_child_map, sizeof(p_child_map), DOWA_HASH_MAP_TYPE_HASHMAP) == -1) { - Dowa_HashMap_Destory(p_child_map); + Dowa_HashMap_Destroy(p_child_map); return -1; } } diff -r 0a9e67c7039a -r 09def63429b9 dowa/dowa.h --- a/dowa/dowa.h Mon Oct 06 10:13:41 2025 -0700 +++ b/dowa/dowa.h Mon Oct 06 10:57:30 2025 -0700 @@ -4,8 +4,8 @@ #include #include // stdup #include // only for malloc, free, stuff -#include -#include +#include // mostly for TODO +#include // some functions loop through files #include #include @@ -17,64 +17,82 @@ #define TRUE 1 #define FALSE 0 -typedef unsigned int uint32; -typedef int int32; -typedef unsigned short uint16; -typedef short int16; -typedef unsigned char uint8; -typedef char int8; -typedef char boolean; +// Fixed-width integer types +typedef unsigned int uint32; // 32-bit unsigned integer +typedef int int32; // 32-bit signed integer +typedef unsigned short uint16; // 16-bit unsigned integer +typedef short int16; // 16-bit signed integer +typedef unsigned char uint8; // 8-bit unsigned integer +typedef char int8; // 8-bit signed integer +typedef char boolean; // Boolean type (0 = false, nonzero = true) + -// --- Misc --- // -char *Dowa_Int32ToString(uint32 int32, char *buffer); +// --- Miscellaneous --- // +/* Just use atoid lmao*/ +char *Dowa_Int32ToString(uint32 value, char *buffer); + -// --- Arena --- // +// --- Arena Allocator --- // typedef struct { - char *buffer; - size_t offset; - size_t capacity; + char *buffer; + size_t offset; + size_t capacity; } Dowa_Arena, *Dowa_PArena; -extern Dowa_PArena Dowa_Arena_Create(size_t capacity); -extern void *Dowa_Arena_Allocate(Dowa_PArena p_arena, size_t size); -extern void Dowa_Arena_Destory(Dowa_PArena p_arena); +/* Creates a new arena with the specified capacity (in bytes). Returns a pointer to the arena, or NULL on failure. */ +extern Dowa_PArena Dowa_Arena_Create(size_t capacity); +/* Allocates a block of memory of the given size from the arena. Returns pointer to the allocated memory, or NULL if there is insufficient space. */ +extern void *Dowa_Arena_Allocate(Dowa_PArena arena, size_t size); +/* Destroys the arena and frees its underlying memory block.*/ +extern void Dowa_Arena_Destroy(Dowa_PArena arena); + // --- HashMap --- // typedef enum { - DOWA_HASH_MAP_TYPE_BUFFER, - DOWA_HASH_MAP_TYPE_STRING, - DOWA_HASH_MAP_TYPE_HASHMAP, - DOWA_HASH_MAP_TYPE_INT, + DOWA_HASH_MAP_TYPE_BUFFER, // Raw byte buffer + DOWA_HASH_MAP_TYPE_STRING, // Null-terminated string + DOWA_HASH_MAP_TYPE_HASHMAP, // Nested hashmap + DOWA_HASH_MAP_TYPE_INT // Integer value } Dowa_HashMap_ValueType; typedef struct { - char *key; - void *buffer; - size_t capacity; - Dowa_HashMap_ValueType type; + char *key; + void *buffer; + size_t capacity; + Dowa_HashMap_ValueType type; } Dowa_HashEntry, *Dowa_PHashEntry; typedef struct { - Dowa_PHashEntry *entries; - size_t capacity; - uint32 current_capacity; - Dowa_PArena p_arena; + Dowa_PHashEntry *entries; + size_t capacity; + uint32 current_capacity; + Dowa_PArena p_arena; } Dowa_HashMap, *Dowa_PHashMap; -extern Dowa_PHashMap Dowa_HashMap_Create(size_t capacity); -extern Dowa_PHashMap Dowa_HashMap_Create(size_t capacity, Dowa_PArena p_arena); -extern void Dowa_HashMap_Destory(Dowa_PHashMap p_hash_map); -extern int32 Dowa_HashMap_Get_Position(Dowa_PHashMap p_hash_map, char *key); -extern void *Dowa_HashMap_Get(Dowa_PHashMap p_hash_map, char *key); -extern void Dowa_HashMap_Push_Value(Dowa_PHashMap p_hash_map, char *key, void *value, size_t value_size); -extern int32 Dowa_HashMap_Push_Value_With_Type_NoCopy(Dowa_PHashMap p_hash_map, char *key, void *value, size_t value_size, Dowa_HashMap_ValueType type); -extern int32 Dowa_HashMap_Push_Value_With_Type(Dowa_PHashMap p_hash_map, char *key, void *value, size_t value_size, Dowa_HashMap_ValueType type); -extern void Dowa_HashMap_Pop_Key(Dowa_PHashMap p_hash_map, char *key); +/* Creates a new hashmap with the given initial capacity. Returns pointer to the hashmap, or NULL on failure. */ +extern Dowa_PHashMap Dowa_HashMap_Create(size_t capacity); +/* Creates a new hashmap with the given initial capacity, using the provided arena for all internal allocations. Returns pointer to the hashmap, or NULL on failure. */ +extern Dowa_PHashMap Dowa_HashMap_Create_With_Arena(size_t capacity, Dowa_PArena arena); +/* Destroys the hashmap and frees all associated memory */ +extern void Dowa_HashMap_Destroy(Dowa_PHashMap p_hash_map); +/* Returns the index of the entry for the specified key, or -1 if the key is not found. */ +extern int32 Dowa_HashMap_Get_Position(Dowa_PHashMap p_hash_map, const char *key); +/* Retrieves the value buffer for the specified key, or NULL if the key does not exist. */ +extern void *Dowa_HashMap_Get(Dowa_PHashMap p_hash_map, const char *key); +/* Inserts a copy of the given value into the hashmap under the specified key. Uses DOWA_HASH_MAP_TYPE_BUFFER as the entry type. */ +extern void Dowa_HashMap_Push_Value(Dowa_PHashMap p_hash_map, const char *key, void *value, size_t value_size); +/* Inserts a copy of the given value with the specified type into the hashmap under the key. Returns the index of the new entry, or -1 on failure. */ +extern int32 Dowa_HashMap_Push_Value_With_Type(Dowa_PHashMap p_hash_map, const char *key, void *value, size_t value_size, Dowa_HashMap_ValueType type); +/* Inserts a value pointer into the hashmap under the specified key without copying data. The caller retains ownership of the pointer. Returns the entry index, or -1 on failure. */ +extern int32 Dowa_HashMap_Push_Value_With_Type_NoCopy(Dowa_PHashMap p_hash_map, const char *key, void *value, size_t value_size, Dowa_HashMap_ValueType type); +/* Removes the entry with the specified key from the hashmap and frees its data if owned. */ +extern void Dowa_HashMap_Pop_Key(Dowa_PHashMap p_hash_map, const char *key); -// --- Maybe Useful --- // -extern void Dowa_HashMap_Print(Dowa_PHashMap map); -// 0 for success, -1 for failure. Get all files in the folder into key and vlaues. -extern int Dowa_HashMap_Cache_Folder(Dowa_PHashMap map, const char *folder_path); +// --- Utility Functions --- // +/* Prints all entries in the hashmap to stdout for debugging purposes. */ +extern void Dowa_HashMap_Print(Dowa_PHashMap map); +/* Loads all files from the specified folder into the hashmap. Uses file names as keys and file contents as values. Returns 0 on success, or -1 on failure. */ +extern int Dowa_HashMap_Cache_Folder(Dowa_PHashMap map, const char *folder_path); #endif diff -r 0a9e67c7039a -r 09def63429b9 dowa/dowa_test.c --- a/dowa/dowa_test.c Mon Oct 06 10:13:41 2025 -0700 +++ b/dowa/dowa_test.c Mon Oct 06 10:57:30 2025 -0700 @@ -1,116 +1,118 @@ +#include +#include +#include +#include #include "dowa.h" -static void TestArena() +int main(void) { - const size_t capacity = 64; - Dowa_PArena arena = Dowa_Arena_Create(capacity); - assert(arena != NULL); - assert(arena->offset == 0); - assert(arena->capacity == capacity); - - // Allocate within capacity - void *p1 = Dowa_Arena_Allocate(arena, 16); - assert(p1 != NULL); - assert(arena->offset == 16); - sprintf((char *)p1, "%i", 10); - assert(strcmp(p1, "10") == 0); - - // Allocate more - void *p2 = Dowa_Arena_Allocate(arena, 32); - assert(p2 != NULL); - assert(arena->offset == 48); + // --- Test Arena Allocator --- + Dowa_PArena arena = Dowa_Arena_Create(64); + assert(arena && "Arena creation failed"); - // Overflow allocation should return NULL and not advance offset - void *p3 = Dowa_Arena_Allocate(arena, 20); - assert(p3 == NULL); - assert(arena->offset == 48); - - Dowa_Arena_Free(arena); -} + char *arena_mem1 = (char *)Dowa_Arena_Allocate(arena, 16); + assert(arena_mem1 && "Arena allocation #1 failed"); + strcpy(arena_mem1, "hello arena"); + printf("[Arena Allocate] mem1 = \"%s\"\n", arena_mem1); -static void TestHashMap() -{ - const size_t capacity = 10; - Dowa_PHashMap map = Dowa_HashMap_Create(capacity); - assert(map != NULL); - assert(map->capacity == capacity); - assert(map->current_capacity == 0); + char *arena_mem2 = (char *)Dowa_Arena_Allocate(arena, 8); + assert(arena_mem2 && "Arena allocation #2 failed"); + strcpy(arena_mem2, "data"); + printf("[Arena Allocate] mem2 = \"%s\"\n", arena_mem2); - // Insert "foo" -> 42 - int val1 = 42; - Dowa_HashMap_PushValue(map, "foo", &val1, sizeof(val1)); - assert(map->current_capacity == 1); - - int idx_foo = Dowa_HashMap_GetPosition(map, "foo"); - Dowa_PHashEntry e_foo = map->entries[idx_foo]; - assert(e_foo != NULL); - assert(strcmp(e_foo->key, "foo") == 0); - assert(*(int*)e_foo->buffer == 42); + Dowa_Arena_Destroy(arena); + printf("[Arena] destroyed\n\n"); - // Overwrite "foo" -> 100 (capacity should not change) - int val2 = 100; - Dowa_HashMap_PushValue(map, "foo", &val2, sizeof(val2)); - assert(map->current_capacity == 1); - - e_foo = map->entries[idx_foo]; - assert(e_foo != NULL); - assert(strcmp(e_foo->key, "foo") == 0); - assert(*(int*)e_foo->buffer == 100); + // --- Test HashMap Basic Operations --- + Dowa_PHashMap map = Dowa_HashMap_Create(8); + assert(map && "HashMap_Create failed"); - // Insert "bar" -> -7 - int val3 = -7; - Dowa_HashMap_PushValue(map, "bar", &val3, sizeof(val3)); - assert(map->current_capacity == 2); + // Push raw buffer (default type: BUFFER) + const char raw_buf[] = {0x01, 0x02, 0x03, 0x04}; + Dowa_HashMap_Push_Value(map, "raw", raw_buf, sizeof(raw_buf)); - int idx_bar = Dowa_HashMap_GetPosition(map, "bar"); - Dowa_PHashEntry e_bar = map->entries[idx_bar]; - assert(e_bar != NULL); - assert(strcmp(e_bar->key, "bar") == 0); - assert(*(int*)e_bar->buffer == -7); + // Push string with explicit STRING type + const char *hello = "hello, world"; + Dowa_HashMap_Push_Value_With_Type(map, "greeting", hello, strlen(hello) + 1, DOWA_HASH_MAP_TYPE_STRING); - // Pop "foo" - Dowa_HashMap_PopKey(map, "foo"); - assert(map->entries[idx_foo] == NULL); - assert(map->current_capacity == 1); - - // Pop "bar" - Dowa_HashMap_PopKey(map, "bar"); - assert(map->entries[idx_bar] == NULL); - assert(map->current_capacity == 0); + // Push nested hashmap (no copy) + Dowa_PHashMap inner = Dowa_HashMap_Create(4); + Dowa_HashMap_Push_Value(inner, "inner_key", "inner_val", strlen("inner_val") + 1); + Dowa_HashMap_Push_Value_With_Type_NoCopy(map, "nested", inner, sizeof(inner), DOWA_HASH_MAP_TYPE_HASHMAP); - // Clean up map - Dowa_HashMap_Free(map); -} - -void Test_Dowa_HashMap_Cache_Folder() -{ - Dowa_PHashMap map = Dowa_HashMap_Create(100); + // Push integer with INT type + int32 number = 42; + Dowa_HashMap_Push_Value_With_Type(map, "answer", &number, sizeof(number), DOWA_HASH_MAP_TYPE_INT); - int res = Dowa_HashMap_Cache_Folder(map, "dowa/test_folder"); - assert(res == 0 && "Folder caching should succeed"); - - const char *foo_val = (const char *)Dowa_HashMap_Get(map, "foo.txt"); - assert(foo_val != NULL); - assert(strcmp("this is foo\n", foo_val)==0); - + // Print full map + printf("=== Map After Inserts ===\n"); Dowa_HashMap_Print(map); - Dowa_PHashMap p_bar_map = (Dowa_PHashMap)Dowa_HashMap_Get(map, "bar"); - assert(p_bar_map != NULL); - assert(strcmp("this is bar\n", (const char *)Dowa_HashMap_Get(p_bar_map, "bar.txt"))==0); + // Retrieve and validate values + { + // raw buffer + uint8 *r = Dowa_HashMap_Get(map, "raw"); + printf("[Get raw] bytes:"); + for (size_t i = 0; i < sizeof(raw_buf); ++i) { + printf(" %02X", r[i]); + } + printf("\n"); + + // greeting + char *g = Dowa_HashMap_Get(map, "greeting"); + printf("[Get greeting] \"%s\"\n", g); - Dowa_HashMap_Free(map); -} + // nested hashmap + Dowa_PHashMap ni = Dowa_HashMap_Get(map, "nested"); + printf("[Get nested] Inner map contents:\n"); + Dowa_HashMap_Print(ni); + + // answer + int32 *ans = Dowa_HashMap_Get(map, "answer"); + printf("[Get answer] %d\n", *ans); + } + + // Test Get_Position + printf("[Get_Position] 'greeting' at index %d\n", + Dowa_HashMap_Get_Position(map, "greeting")); + printf("[Get_Position] 'missing' at index %d\n", + Dowa_HashMap_Get_Position(map, "missing")); -int main(void) { - TestArena(); - printf("Arena tests passed.\n"); + // Pop a key + Dowa_HashMap_Pop_Key(map, "raw"); + printf("=== Map After Pop 'raw' ===\n"); + Dowa_HashMap_Print(map); + + // --- Test HashMap with Arena --- + Dowa_PArena mapArena = Dowa_Arena_Create(256); + Dowa_PHashMap map2 = Dowa_HashMap_Create_With_Arena(8, mapArena); + assert(map2 && "HashMap_Create_With_Arena failed"); + char *test = "bar"; + + Dowa_HashMap_Push_Value_With_Type(map2, "foo", test, 4, DOWA_HASH_MAP_TYPE_STRING); + Dowa_HashMap_Push_Value_With_Type(map2, "num", &number, sizeof(number), DOWA_HASH_MAP_TYPE_INT); + + printf("=== Map2 (with arena) ===\n"); + Dowa_HashMap_Print(map2); - TestHashMap(); - printf("HashMap tests passed.\n"); + Dowa_HashMap_Destroy(map2); + Dowa_Arena_Destroy(mapArena); + printf("[Map2 & Arena] destroyed\n\n"); - Test_Dowa_HashMap_Cache_Folder(); - printf("Test_Dowa_HashMap_Cache_Folder passed\n"); + // --- Test Cache_Folder --- + // Ensure there is a directory "./dowa/test_folder" with some files for this test to succeed. + int cache_result = Dowa_HashMap_Cache_Folder(map, "dowa/test_folder"); + printf("[Cache_Folder] returned %d\n", cache_result); + if (cache_result == 0) { + printf("=== Map After Caching 'dowa/test_folder' ===\n"); + Dowa_HashMap_Print(map); + } else { + printf("Cache_Folder failed (ensure 'dowa/test_folder' exists with files)\n"); + } + + // Cleanup + Dowa_HashMap_Destroy(map); + printf("[Map] destroyed\n"); + return 0; } - diff -r 0a9e67c7039a -r 09def63429b9 seobeo/s_web.c --- 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; }