comparison seobeo/s_web.c @ 124:dbf14f84d51c

Refactor Seobeo and mrjunejune build files so it works.
author June Park <parkjune1995@gmail.com>
date Thu, 08 Jan 2026 07:31:32 -0800
parents 7b1719fa918c
children 7a63e41a21fb
comparison
equal deleted inserted replaced
123:3f4ec30e42e0 124:dbf14f84d51c
63 } 63 }
64 64
65 void Seobeo_Web_HandleClientRequest(Seobeo_Handle *p_cli_handle, 65 void Seobeo_Web_HandleClientRequest(Seobeo_Handle *p_cli_handle,
66 Seobeo_Cache_Entry *p_html_cache) 66 Seobeo_Cache_Entry *p_html_cache)
67 { 67 {
68 Dowa_Arena *p_request_arena = Dowa_Arena_Create(1*1024*1024); // 1MB for request parsing 68 // TODO: This should be splitted up instead of handling up to 50 MB as it will fail more often...
69 Dowa_Arena *p_request_arena = Dowa_Arena_Create(50*1024*1024); // 50 MB because of files...
69 if (!p_request_arena) { perror("Dowa_Arena_Create request"); goto clean_up; } 70 if (!p_request_arena) { perror("Dowa_Arena_Create request"); goto clean_up; }
70 71
71 Dowa_Arena *p_response_arena = Dowa_Arena_Create(5*1024*1024); // 5MB for response 72 Dowa_Arena *p_response_arena = Dowa_Arena_Create(50*1024*1024); // 50 MB for response
72 if (!p_response_arena) { perror("Dowa_Arena_Create response"); goto clean_up; } 73 if (!p_response_arena) { perror("Dowa_Arena_Create response"); goto clean_up; }
73 74
74 void *p_response_header = Dowa_Arena_Allocate(p_response_arena, (size_t)1024*5); // 5Kb 75 void *p_response_header = Dowa_Arena_Allocate(p_response_arena, 1024*5); // 5Kb
75 if (!p_response_header) { perror("Dowa_Arena_Allocate"); goto clean_up; } 76 if (!p_response_header) { perror("Dowa_Arena_Allocate"); goto clean_up; }
76 77
77 Seobeo_Request_Entry *p_req_map = NULL; 78 Seobeo_Request_Entry *p_req_map = NULL;
78 int parse_result = Seobeo_Web_Header_Parse(p_cli_handle, &p_req_map, p_request_arena); 79 int parse_result = Seobeo_Web_Header_Parse(p_cli_handle, &p_req_map, p_request_arena);
79 80
133 134
134 void *p_path_kv = Dowa_HashMap_Get_Ptr(p_req_map, "Path"); 135 void *p_path_kv = Dowa_HashMap_Get_Ptr(p_req_map, "Path");
135 const char *path = p_path_kv ? ((Seobeo_Request_Entry*)p_path_kv)->value : "/"; 136 const char *path = p_path_kv ? ((Seobeo_Request_Entry*)p_path_kv)->value : "/";
136 137
137 // --- Check for WebSocket upgrade request --- 138 // --- Check for WebSocket upgrade request ---
139 #ifdef SEOBEO_WEBSOCKET_SERVER
138 if (Seobeo_WebSocket_Server_Handle_Upgrade(p_cli_handle, p_req_map, path)) 140 if (Seobeo_WebSocket_Server_Handle_Upgrade(p_cli_handle, p_req_map, path))
139 { 141 {
140 Seobeo_Log(SEOBEO_INFO, "WebSocket connection established\n"); 142 Seobeo_Log(SEOBEO_INFO, "WebSocket connection established\n");
141 if (p_request_arena) 143 if (p_request_arena)
142 Dowa_Arena_Free(p_request_arena); 144 Dowa_Arena_Free(p_request_arena);
143 if (p_response_arena) 145 if (p_response_arena)
144 Dowa_Arena_Free(p_response_arena); 146 Dowa_Arena_Free(p_response_arena);
145 return; 147 return;
146 } 148 }
149 #endif
147 150
148 // --- Try to match API route first --- 151 // --- Try to match API route first ---
149 Seobeo_Route_Handler handler = Seobeo_Router_Find_Handler(method, path, &p_req_map, p_request_arena); 152 Seobeo_Route_Handler handler = Seobeo_Router_Find_Handler(method, path, &p_req_map, p_request_arena);
150 if (handler != NULL) 153 if (handler != NULL)
151 { 154 {
728 } 731 }
729 Dowa_Array_Free(g_routes); 732 Dowa_Array_Free(g_routes);
730 g_routes = NULL; 733 g_routes = NULL;
731 } 734 }
732 735
733 static char *Seobeo_Log_Level_String(Seobeo_Log_Level level) 736 // Logging functions moved to s_logging.c
734 { 737
735 switch(level) {
736 case SEOBEO_DEBUG: return "DEBUG";
737 case SEOBEO_INFO: return "INFO";
738 case SEOBEO_WARNING: return "WARNING";
739 case SEOBEO_ERROR: return "ERROR";
740 default: return "INFO";
741 }
742 }
743
744 int Seobeo_Log(Seobeo_Log_Level level, const char * restrict format, ...)
745 {
746 #ifndef SEOBEO_ENABLE_DEBUG
747 if (level == SEOBEO_DEBUG)
748 return 0;
749 #endif
750
751 int result;
752 va_list args;
753 printf("[%s] ", Seobeo_Log_Level_String(level));
754 va_start(args, format);
755 result = vprintf(format, args);
756 va_end(args);
757
758 return result;
759 }
760