| 1810 | } |
| 1811 | |
| 1812 | static void dispatch_request(cbm_http_server_t *srv, cbm_http_conn_t *c, |
| 1813 | const cbm_http_req_t *req) { |
| 1814 | if (!request_passes_http_security(srv, c, req)) |
| 1815 | return; |
| 1816 | |
| 1817 | bool is_get = strcmp(req->method, "GET") == 0; |
| 1818 | bool is_post = strcmp(req->method, "POST") == 0; |
| 1819 | bool is_delete = strcmp(req->method, "DELETE") == 0; |
| 1820 | |
| 1821 | /* OPTIONS preflight for CORS */ |
| 1822 | if (strcmp(req->method, "OPTIONS") == 0) { |
| 1823 | cbm_http_replyf(c, 204, g_cors, "%s", ""); |
| 1824 | return; |
| 1825 | } |
| 1826 | |
| 1827 | /* Private-generation proof used only by `daemon start --open`. The |
| 1828 | * challenge is public; the HMAC key exists only in this daemon's |
| 1829 | * authenticated application and HTTP server instances. */ |
| 1830 | if (is_get && strcmp(req->path, "/__cbm/ui-readiness") == 0) { |
| 1831 | handle_ui_readiness(srv, c, req); |
| 1832 | return; |
| 1833 | } |
| 1834 | |
| 1835 | /* POST /rpc → JSON-RPC dispatch (reuses existing MCP tools) */ |
| 1836 | if (is_post && cbm_http_path_match(req->path, "/rpc")) { |
| 1837 | handle_rpc(c, req, srv->mcp); |
| 1838 | return; |
| 1839 | } |
| 1840 | |
| 1841 | /* GET /api/layout → 3D graph layout */ |
| 1842 | if (is_get && cbm_http_path_match(req->path, "/api/layout*")) { |
| 1843 | handle_layout(c, req); |
| 1844 | return; |
| 1845 | } |
| 1846 | |
| 1847 | /* GET /api/repo-info → git remote / branch for GitHub deep-links */ |
| 1848 | if (is_get && cbm_http_path_match(req->path, "/api/repo-info*")) { |
| 1849 | handle_repo_info(c, req); |
| 1850 | return; |
| 1851 | } |
| 1852 | |
| 1853 | /* POST /api/index → start background indexing */ |
| 1854 | if (is_post && cbm_http_path_match(req->path, "/api/index")) { |
| 1855 | handle_index_start(srv, c, req); |
| 1856 | return; |
| 1857 | } |
| 1858 | |
| 1859 | /* GET /api/index-status → check indexing progress */ |
| 1860 | if (is_get && cbm_http_path_match(req->path, "/api/index-status")) { |
| 1861 | handle_index_status(srv, c); |
| 1862 | return; |
| 1863 | } |
| 1864 | |
| 1865 | /* GET /api/ui-config → language and local UI preferences */ |
| 1866 | if (is_get && cbm_http_path_match(req->path, "/api/ui-config")) { |
| 1867 | handle_ui_config(c, req); |
| 1868 | return; |
| 1869 | } |
no test coverage detected