Open the query store for ?project=... or reply with the right error. * Returns NULL after replying. */
| 2382 | /* Open the query store for ?project=... or reply with the right error. |
| 2383 | * Returns NULL after replying. */ |
| 2384 | static cbm_store_t *atlas_open_project(cbm_http_conn_t *c, const cbm_http_req_t *req, char *project, |
| 2385 | size_t project_cap) { |
| 2386 | if (!cbm_http_query_param(req->query, "project", project, (int)project_cap) || |
| 2387 | project[0] == '\0') { |
| 2388 | cbm_http_replyf(c, 400, g_cors_json, "{\"error\":\"missing project parameter\"}"); |
| 2389 | return NULL; |
| 2390 | } |
| 2391 | char db_path[1024]; |
| 2392 | db_path_for_project(project, db_path, sizeof(db_path)); |
| 2393 | if (!cbm_file_exists(db_path)) { |
| 2394 | cbm_http_replyf(c, 404, g_cors_json, "{\"error\":\"project not found\"}"); |
| 2395 | return NULL; |
| 2396 | } |
| 2397 | cbm_store_t *store = cbm_store_open_path_query(db_path); |
| 2398 | if (!store) |
| 2399 | cbm_http_replyf(c, 500, g_cors_json, "{\"error\":\"cannot open store\"}"); |
| 2400 | return store; |
| 2401 | } |
| 2402 | |
| 2403 | static void atlas_reply_json(cbm_http_conn_t *c, char *json, int missing_status, |
| 2404 | const char *missing_body) { |
no test coverage detected