Mercurial
comparison seobeo/s_web.c @ 264:04fee26ecce0
add authenticated JRPG conversation platform
Add reusable auth/session storage, owned conversation recovery, guest quotas, admin workflows, URL-routed conversation UI, mobile frame support, and parallel browser acceptance.
Co-authored-by: Copilot <[email protected]>
| author | MrJuneJune <me@mrjunejune.com> |
|---|---|
| date | Fri, 07 Aug 2026 07:34:12 -0700 |
| parents | 1f9877b637e9 |
| children |
comparison
equal
deleted
inserted
replaced
| 263:ee04e4e69fed | 264:04fee26ecce0 |
|---|---|
| 40 { | 40 { |
| 41 if (strcasecmp(header, "content-length") == 0) return "Content-Length"; | 41 if (strcasecmp(header, "content-length") == 0) return "Content-Length"; |
| 42 if (strcasecmp(header, "content-type") == 0) return "Content-Type"; | 42 if (strcasecmp(header, "content-type") == 0) return "Content-Type"; |
| 43 if (strcasecmp(header, "connection") == 0) return "Connection"; | 43 if (strcasecmp(header, "connection") == 0) return "Connection"; |
| 44 if (strcasecmp(header, "authorization") == 0) return "Authorization"; | 44 if (strcasecmp(header, "authorization") == 0) return "Authorization"; |
| 45 if (strcasecmp(header, "cookie") == 0) return "Cookie"; | |
| 46 if (strcasecmp(header, "origin") == 0) return "Origin"; | |
| 47 if (strcasecmp(header, "x-csrf-token") == 0) return "X-CSRF-Token"; | |
| 45 if (strcasecmp(header, "host") == 0) return "Host"; | 48 if (strcasecmp(header, "host") == 0) return "Host"; |
| 46 if (strcasecmp(header, "upgrade") == 0) return "Upgrade"; | 49 if (strcasecmp(header, "upgrade") == 0) return "Upgrade"; |
| 47 if (strcasecmp(header, "x-real-ip") == 0) return "X-Real-IP"; | 50 if (strcasecmp(header, "x-real-ip") == 0) return "X-Real-IP"; |
| 48 if (strcasecmp(header, "sec-websocket-key") == 0) return "Sec-WebSocket-Key"; | 51 if (strcasecmp(header, "sec-websocket-key") == 0) return "Sec-WebSocket-Key"; |
| 49 if (strcasecmp(header, "sec-websocket-version") == 0) return "Sec-WebSocket-Version"; | 52 if (strcasecmp(header, "sec-websocket-version") == 0) return "Sec-WebSocket-Version"; |
| 201 const char *http_version = p_ver_kv ? ((Seobeo_Request_Entry*)p_ver_kv)->value : "HTTP/1.0"; | 204 const char *http_version = p_ver_kv ? ((Seobeo_Request_Entry*)p_ver_kv)->value : "HTTP/1.0"; |
| 202 boolean is_http11 = (strstr(http_version, "1.1") != NULL); | 205 boolean is_http11 = (strstr(http_version, "1.1") != NULL); |
| 203 | 206 |
| 204 void *p_conn_kv = Dowa_HashMap_Get_Ptr(p_req_map, "Connection"); | 207 void *p_conn_kv = Dowa_HashMap_Get_Ptr(p_req_map, "Connection"); |
| 205 const char *conn_header = p_conn_kv ? ((Seobeo_Request_Entry*)p_conn_kv)->value : NULL; | 208 const char *conn_header = p_conn_kv ? ((Seobeo_Request_Entry*)p_conn_kv)->value : NULL; |
| 206 | |
| 207 void *p_real_ip_kv = Dowa_HashMap_Get_Ptr(p_req_map, "X-Real-IP"); | |
| 208 const char *real_ip = p_real_ip_kv ? ((Seobeo_Request_Entry*)p_real_ip_kv)->value : NULL; | |
| 209 if (!real_ip) | |
| 210 real_ip = p_cli_handle->host; | |
| 211 | 209 |
| 212 if (conn_header) | 210 if (conn_header) |
| 213 { | 211 { |
| 214 if (connection_header_contains(conn_header, "close")) | 212 if (connection_header_contains(conn_header, "close")) |
| 215 should_keep_alive = FALSE; | 213 should_keep_alive = FALSE; |
| 447 } | 445 } |
| 448 | 446 |
| 449 // This seems kinda bad ? | 447 // This seems kinda bad ? |
| 450 char method[16], path[256], version[16]; | 448 char method[16], path[256], version[16]; |
| 451 int scan_result = sscanf(buf, "%15s %255s %15s", method, path, version); | 449 int scan_result = sscanf(buf, "%15s %255s %15s", method, path, version); |
| 452 Seobeo_Log(SEOBEO_DEBUG, "sscanf returned %d (method='%s', path='%s', version='%s')\n", | 450 Seobeo_Log(SEOBEO_DEBUG, "sscanf returned %d (method='%s', path_length=%zu)\n", |
| 453 scan_result, | 451 scan_result, |
| 454 scan_result >= 1 ? method : "N/A", | 452 scan_result >= 1 ? method : "N/A", |
| 455 scan_result >= 2 ? path : "N/A", | 453 scan_result >= 2 ? strlen(path) : (size_t)0); |
| 456 scan_result >= 3 ? version : "N/A"); | |
| 457 | 454 |
| 458 if (scan_result != 3) | 455 if (scan_result != 3) |
| 459 { | 456 { |
| 460 Seobeo_Log(SEOBEO_ERROR, "Failed to parse request line\n"); | 457 Seobeo_Log(SEOBEO_ERROR, "Failed to parse request line\n"); |
| 461 return -1; | 458 return -1; |
| 472 strcpy(version_copy, version); | 469 strcpy(version_copy, version); |
| 473 | 470 |
| 474 Seobeo_Log(SEOBEO_DEBUG, "Pushing HTTP_Method and Version to map\n"); | 471 Seobeo_Log(SEOBEO_DEBUG, "Pushing HTTP_Method and Version to map\n"); |
| 475 Dowa_HashMap_Push_Arena(*pp_map, "HTTP_Method", method_copy, p_arena); | 472 Dowa_HashMap_Push_Arena(*pp_map, "HTTP_Method", method_copy, p_arena); |
| 476 Dowa_HashMap_Push_Arena(*pp_map, "Version", version_copy, p_arena); | 473 Dowa_HashMap_Push_Arena(*pp_map, "Version", version_copy, p_arena); |
| 474 if (p_handle->host) | |
| 475 { | |
| 476 char *remote_addr = Dowa_Arena_Allocate(p_arena, strlen(p_handle->host) + 1); | |
| 477 if (!remote_addr) | |
| 478 return -1; | |
| 479 strcpy(remote_addr, p_handle->host); | |
| 480 Dowa_HashMap_Push_Arena(*pp_map, "Remote-Addr", remote_addr, p_arena); | |
| 481 } | |
| 477 Seobeo_Log(SEOBEO_DEBUG, "Map now has %zu entries\n", Dowa_Array_Length(*pp_map)); | 482 Seobeo_Log(SEOBEO_DEBUG, "Map now has %zu entries\n", Dowa_Array_Length(*pp_map)); |
| 478 | 483 |
| 479 char *raw_path = path; | 484 char *raw_path = path; |
| 480 char *query_start = strchr(raw_path, '?'); | 485 char *query_start = strchr(raw_path, '?'); |
| 481 char *query_str = NULL; | 486 char *query_str = NULL; |
| 560 | 565 |
| 561 char *key = Dowa_Arena_Allocate(p_arena, key_len + 1); | 566 char *key = Dowa_Arena_Allocate(p_arena, key_len + 1); |
| 562 if (!key) return -1; | 567 if (!key) return -1; |
| 563 memcpy(key, line, key_len); | 568 memcpy(key, line, key_len); |
| 564 key[key_len] = '\0'; | 569 key[key_len] = '\0'; |
| 570 | |
| 571 if (strcasecmp(key, "remote-addr") == 0) | |
| 572 { | |
| 573 line = next + 2; | |
| 574 continue; | |
| 575 } | |
| 565 | 576 |
| 566 char *val = Dowa_Arena_Allocate(p_arena, value_len + 1); | 577 char *val = Dowa_Arena_Allocate(p_arena, value_len + 1); |
| 567 if (!val) return -1; | 578 if (!val) return -1; |
| 568 memcpy(val, val_start, value_len); | 579 memcpy(val, val_start, value_len); |
| 569 val[value_len] = '\0'; | 580 val[value_len] = '\0'; |