| 2073 | } |
| 2074 | |
| 2075 | static void handle_layout(cbm_http_conn_t *c, const cbm_http_req_t *req) { |
| 2076 | char project[256] = {0}; |
| 2077 | char max_str[32] = {0}; |
| 2078 | char graph_str[32] = {0}; |
| 2079 | |
| 2080 | if (!cbm_http_query_param(req->query, "project", project, (int)sizeof(project)) || |
| 2081 | project[0] == '\0') { |
| 2082 | cbm_http_replyf(c, 400, g_cors_json, "{\"error\":\"missing project parameter\"}"); |
| 2083 | return; |
| 2084 | } |
| 2085 | |
| 2086 | int max_nodes = 0; /* 0 → layout default budget */ |
| 2087 | if (cbm_http_query_param(req->query, "max_nodes", max_str, (int)sizeof(max_str))) { |
| 2088 | int v = atoi(max_str); |
| 2089 | if (v > 0) |
| 2090 | max_nodes = v; |
| 2091 | } |
| 2092 | |
| 2093 | /* graph=missed (#963): lay out the derived miss graph (shadow project |
| 2094 | * "<name>::missed" inside the SAME db file) instead of the code graph — |
| 2095 | * only files the indexer could not fully cover, as their file structure. |
| 2096 | * The db file still resolves from the validated base project name. */ |
| 2097 | bool missed_graph = false; |
| 2098 | if (cbm_http_query_param(req->query, "graph", graph_str, (int)sizeof(graph_str))) { |
| 2099 | missed_graph = strcmp(graph_str, "missed") == 0; |
| 2100 | } |
| 2101 | char scoped_project[320]; |
| 2102 | if (missed_graph) { |
| 2103 | cbm_store_coverage_shadow_project(scoped_project, sizeof(scoped_project), project); |
| 2104 | } else { |
| 2105 | snprintf(scoped_project, sizeof(scoped_project), "%s", project); |
| 2106 | } |
| 2107 | |
| 2108 | char db_path[1024]; |
| 2109 | db_path_for_project(project, db_path, sizeof(db_path)); |
| 2110 | |
| 2111 | if (!cbm_file_exists(db_path)) { |
| 2112 | cbm_http_replyf(c, 404, g_cors_json, "{\"error\":\"project not found\"}"); |
| 2113 | return; |
| 2114 | } |
| 2115 | |
| 2116 | cbm_store_t *store = cbm_store_open_path_query(db_path); |
| 2117 | if (!store) { |
| 2118 | cbm_http_replyf(c, 500, g_cors_json, "{\"error\":\"cannot open store\"}"); |
| 2119 | return; |
| 2120 | } |
| 2121 | |
| 2122 | /* level=regions (CBM Atlas): the coarsest level of detail — one body per |
| 2123 | * region instead of one per node. Regions do not mix with the missed |
| 2124 | * skeleton or cross-repo satellites; the client asks for those at finer |
| 2125 | * levels. */ |
| 2126 | char level_str[32] = {0}; |
| 2127 | if (cbm_http_query_param(req->query, "level", level_str, (int)sizeof(level_str)) && |
| 2128 | strcmp(level_str, "regions") == 0 && !missed_graph) { |
| 2129 | char *regions_json = cbm_layout_regions_json(store, scoped_project); |
| 2130 | cbm_store_close(store); |
| 2131 | if (!regions_json) { |
| 2132 | cbm_http_replyf(c, 500, g_cors_json, "{\"error\":\"region computation failed\"}"); |
no test coverage detected