Mercurial
comparison seobeo/s_web.c @ 244:b8aa08503378
[tools] Add sandboxed online LaTeX editor
Co-authored-by: Copilot <[email protected]>
| author | MrJuneJune <me@mrjunejune.com> |
|---|---|
| date | Mon, 03 Aug 2026 16:56:25 -0700 |
| parents | 543df0fe7168 |
| children | 117c4d53c9a4 |
comparison
equal
deleted
inserted
replaced
| 243:823f2a8b16c8 | 244:b8aa08503378 |
|---|---|
| 1 #include "seobeo/seobeo.h" | 1 #include "seobeo/seobeo.h" |
| 2 #include <strings.h> | 2 #include <strings.h> |
| 3 #include <time.h> | 3 #include <time.h> |
| 4 | 4 |
| 5 static char g_folder_path[512] = "."; | 5 static char g_folder_path[512] = "."; |
| 6 | |
| 7 static char *canonical_request_header(char *header) | |
| 8 { | |
| 9 if (strcasecmp(header, "content-length") == 0) return "Content-Length"; | |
| 10 if (strcasecmp(header, "content-type") == 0) return "Content-Type"; | |
| 11 if (strcasecmp(header, "connection") == 0) return "Connection"; | |
| 12 if (strcasecmp(header, "authorization") == 0) return "Authorization"; | |
| 13 if (strcasecmp(header, "host") == 0) return "Host"; | |
| 14 if (strcasecmp(header, "upgrade") == 0) return "Upgrade"; | |
| 15 if (strcasecmp(header, "x-real-ip") == 0) return "X-Real-IP"; | |
| 16 if (strcasecmp(header, "sec-websocket-key") == 0) return "Sec-WebSocket-Key"; | |
| 17 if (strcasecmp(header, "sec-websocket-version") == 0) return "Sec-WebSocket-Version"; | |
| 18 return header; | |
| 19 } | |
| 6 | 20 |
| 7 char* Seobeo_Web_LoadFile(const char *file_path, size_t *p_file_size) | 21 char* Seobeo_Web_LoadFile(const char *file_path, size_t *p_file_size) |
| 8 { | 22 { |
| 9 char full_path[1024]; | 23 char full_path[1024]; |
| 10 snprintf(full_path, sizeof(full_path), "%s/%s", g_folder_path, file_path); | 24 snprintf(full_path, sizeof(full_path), "%s/%s", g_folder_path, file_path); |
| 56 case HTTP_FOUND: status_text = "Found"; break; | 70 case HTTP_FOUND: status_text = "Found"; break; |
| 57 case HTTP_BAD_REQUEST: status_text = "Bad Request"; break; | 71 case HTTP_BAD_REQUEST: status_text = "Bad Request"; break; |
| 58 case HTTP_UNAUTHORIZED: status_text = "Unauthorized"; break; | 72 case HTTP_UNAUTHORIZED: status_text = "Unauthorized"; break; |
| 59 case HTTP_FORBIDDEN: status_text = "Forbidden"; break; | 73 case HTTP_FORBIDDEN: status_text = "Forbidden"; break; |
| 60 case HTTP_NOT_FOUND: status_text = "Not Found"; break; | 74 case HTTP_NOT_FOUND: status_text = "Not Found"; break; |
| 75 case HTTP_PAYLOAD_TOO_LARGE: status_text = "Content Too Large"; break; | |
| 76 case HTTP_UNPROCESSABLE_CONTENT: status_text = "Unprocessable Content"; break; | |
| 77 case HTTP_TOO_MANY_REQUESTS: status_text = "Too Many Requests"; break; | |
| 61 case HTTP_INTERNAL_ERROR: status_text = "Internal Server Error"; break; | 78 case HTTP_INTERNAL_ERROR: status_text = "Internal Server Error"; break; |
| 79 case HTTP_SERVICE_UNAVAILABLE: status_text = "Service Unavailable"; break; | |
| 62 case 502: status_text = "Bad Gateway"; break; | 80 case 502: status_text = "Bad Gateway"; break; |
| 63 case 504: status_text = "Gateway Timeout"; break; | 81 case 504: status_text = "Gateway Timeout"; break; |
| 64 default: status_text = "Unknown"; break; | 82 default: status_text = "Unknown"; break; |
| 65 } | 83 } |
| 66 | 84 |
| 492 char *val = Dowa_Arena_Allocate(p_arena, value_len + 1); | 510 char *val = Dowa_Arena_Allocate(p_arena, value_len + 1); |
| 493 if (!val) return -1; | 511 if (!val) return -1; |
| 494 memcpy(val, val_start, value_len); | 512 memcpy(val, val_start, value_len); |
| 495 val[value_len] = '\0'; | 513 val[value_len] = '\0'; |
| 496 | 514 |
| 497 Dowa_HashMap_Push_Arena(*pp_map, key, val, p_arena); | 515 Dowa_HashMap_Push_Arena( |
| 516 *pp_map, | |
| 517 canonical_request_header(key), | |
| 518 val, | |
| 519 p_arena); | |
| 498 } | 520 } |
| 499 | 521 |
| 500 line = next + 2; | 522 line = next + 2; |
| 501 } | 523 } |
| 502 | 524 |