MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / dispatch_request

Function dispatch_request

src/ui/http_server.c:3201–3449  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3199}
3200
3201static void dispatch_request(cbm_http_server_t *srv, cbm_http_conn_t *c,
3202 const cbm_http_req_t *req) {
3203 if (!request_passes_http_security(srv, c, req))
3204 return;
3205
3206 bool is_get = strcmp(req->method, "GET") == 0;
3207 bool is_post = strcmp(req->method, "POST") == 0;
3208 bool is_delete = strcmp(req->method, "DELETE") == 0;
3209
3210 if (strcmp(req->path, "/api/config") == 0 && (is_get || is_post)) {
3211 cbm_runtime_settings_note_http_port(srv->port);
3212 const char *cache = cbm_resolve_cache_dir();
3213 int status = 200;
3214 char *json = is_post
3215 ? cbm_runtime_settings_apply_json(cache, req->body, req->body_len, &status)
3216 : cbm_runtime_settings_get_json(cache);
3217 if (!json) {
3218 status = 500;
3219 }
3220 cbm_http_replyf(c, status, "Content-Type: application/json\r\nCache-Control: no-store\r\n",
3221 "%s", json ? json : "{\"error\":\"Configuration storage unavailable.\"}");
3222 cbm_free(CBM_MEM_CLASS_OTHER, json);
3223 return;
3224 }
3225
3226 /* OPTIONS preflight for CORS */
3227 if (strcmp(req->method, "OPTIONS") == 0) {
3228 cbm_http_replyf(c, 204, g_cors, "%s", "");
3229 return;
3230 }
3231
3232 /* Private-generation proof used only by `daemon start --open`. The
3233 * challenge is public; the HMAC key exists only in this daemon's
3234 * authenticated application and HTTP server instances. */
3235 if (is_get && strcmp(req->path, "/__cbm/ui-readiness") == 0) {
3236 handle_ui_readiness(srv, c, req);
3237 return;
3238 }
3239
3240 /* POST /rpc → JSON-RPC dispatch (reuses existing MCP tools) */
3241 if (is_post && cbm_http_path_match(req->path, "/rpc")) {
3242 handle_rpc(c, req, srv->mcp);
3243 return;
3244 }
3245
3246 /* GET /api/layout → 3D graph layout */
3247 if (is_get && cbm_http_path_match(req->path, "/api/layout*")) {
3248 handle_layout(c, req);
3249 return;
3250 }
3251
3252 /* GET /api/tree → CBM Atlas folder aggregates */
3253 if (is_get && cbm_http_path_match(req->path, "/api/tree*")) {
3254 handle_atlas_tree(c, req);
3255 return;
3256 }
3257
3258 /* GET /api/symbol-history → per-symbol git log -L evidence.

Callers 1

cbm_http_server_runFunction · 0.85

Calls 15

cbm_resolve_cache_dirFunction · 0.85
cbm_http_replyfFunction · 0.85
cbm_freeFunction · 0.85
handle_ui_readinessFunction · 0.85
cbm_http_path_matchFunction · 0.85
handle_rpcFunction · 0.85
handle_layoutFunction · 0.85
handle_atlas_treeFunction · 0.85

Tested by

no test coverage detected