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

Function compare_parse_arguments

src/mcp/mcp.c:3395–3456  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3393}
3394
3395static bool compare_parse_arguments(const char *args, char **base_project, char **target_project,
3396 uint64_t *limit, uint64_t *scan_limit,
3397 const char **error_message) {
3398 *base_project = NULL;
3399 *target_project = NULL;
3400 yyjson_doc *doc = yyjson_read(args ? args : "{}", args ? strlen(args) : SLEN("{}"), 0);
3401 if (!doc) {
3402 *error_message = "arguments must be valid JSON";
3403 return false;
3404 }
3405 yyjson_val *root = yyjson_doc_get_root(doc);
3406 if (!yyjson_is_obj(root)) {
3407 *error_message = "arguments must be an object";
3408 yyjson_doc_free(doc);
3409 return false;
3410 }
3411
3412 yyjson_obj_iter iterator = yyjson_obj_iter_with(root);
3413 yyjson_val *key = NULL;
3414 while ((key = yyjson_obj_iter_next(&iterator)) != NULL) {
3415 const char *name = yyjson_get_str(key);
3416 if (!name || !compare_arg_name_allowed(name)) {
3417 *error_message = "unknown argument";
3418 yyjson_doc_free(doc);
3419 return false;
3420 }
3421 }
3422
3423 yyjson_val *base = yyjson_obj_get(root, "base_project");
3424 yyjson_val *target = yyjson_obj_get(root, "target_project");
3425 if (!base || !yyjson_is_str(base) || yyjson_get_len(base) == 0 || !target ||
3426 !yyjson_is_str(target) || yyjson_get_len(target) == 0) {
3427 *error_message = "base_project and target_project are required non-empty strings";
3428 yyjson_doc_free(doc);
3429 return false;
3430 }
3431 if (strcmp(yyjson_get_str(base), yyjson_get_str(target)) == 0) {
3432 *error_message = "base_project and target_project must be distinct";
3433 yyjson_doc_free(doc);
3434 return false;
3435 }
3436 if (!compare_parse_bounded_integer(root, "limit", MCP_COMPARE_DEFAULT_LIMIT,
3437 MCP_COMPARE_MAX_LIMIT, limit, error_message) ||
3438 !compare_parse_bounded_integer(root, "scan_limit", MCP_COMPARE_DEFAULT_SCAN_LIMIT,
3439 MCP_COMPARE_MAX_SCAN_LIMIT, scan_limit, error_message)) {
3440 yyjson_doc_free(doc);
3441 return false;
3442 }
3443
3444 *base_project = heap_strdup(yyjson_get_str(base));
3445 *target_project = heap_strdup(yyjson_get_str(target));
3446 yyjson_doc_free(doc);
3447 if (!*base_project || !*target_project) {
3448 free(*base_project);
3449 free(*target_project);
3450 *base_project = NULL;
3451 *target_project = NULL;
3452 *error_message = "out of memory while validating arguments";

Callers 1

handle_compare_graphsFunction · 0.85

Calls 3

compare_arg_name_allowedFunction · 0.85
heap_strdupFunction · 0.70

Tested by

no test coverage detected