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

Function parse_extra_extensions

src/discover/userconfig.c:214–273  ·  view source on GitHub ↗

* Parse extra_extensions from a yyjson object root. * Appends valid entries to *entries / *count (growing via realloc). * Project-level entries (from_project=true) are appended after global * entries so that a later dedup pass can prefer project values. * * Returns 0 on success, -1 on alloc failure. */

Source from the content-addressed store, hash-verified

212 * Returns 0 on success, -1 on alloc failure.
213 */
214static int parse_extra_extensions(yyjson_val *root, cbm_userext_t **entries, int *count,
215 const char *source_label) {
216 if (!yyjson_is_obj(root)) {
217 cbm_log_warn("userconfig.bad_root", "file", source_label);
218 return 0;
219 }
220
221 yyjson_val *extra = yyjson_obj_get(root, "extra_extensions");
222 if (!extra) {
223 return 0; /* key absent — fine */
224 }
225 if (!yyjson_is_obj(extra)) {
226 cbm_log_warn("userconfig.bad_extra_extensions", "file", source_label);
227 return 0;
228 }
229
230 yyjson_obj_iter iter;
231 yyjson_obj_iter_init(extra, &iter);
232 yyjson_val *key;
233 while ((key = yyjson_obj_iter_next(&iter)) != NULL) {
234 yyjson_val *val = yyjson_obj_iter_get_val(key);
235
236 const char *ext_str = yyjson_get_str(key);
237 const char *lang_str = yyjson_get_str(val);
238
239 if (!ext_str || !lang_str) {
240 cbm_log_warn("userconfig.skip_non_string", "file", source_label);
241 continue;
242 }
243
244 /* Extension must start with '.' */
245 if (ext_str[0] != '.') {
246 cbm_log_warn("userconfig.skip_bad_ext", "file", source_label, "ext", ext_str);
247 continue;
248 }
249
250 CBMLanguage lang = lang_from_string(lang_str);
251 if (lang == CBM_LANG_COUNT) {
252 cbm_log_warn("userconfig.unknown_lang", "file", source_label, "lang", lang_str);
253 continue; /* fail-open: skip unknown languages */
254 }
255
256 /* Grow the array */
257 cbm_userext_t *tmp = realloc(*entries, (size_t)(*count + SKIP_ONE) * sizeof(cbm_userext_t));
258 if (!tmp) {
259 return CBM_NOT_FOUND;
260 }
261 *entries = tmp;
262
263 char *ext_copy = strdup(ext_str);
264 if (!ext_copy) {
265 return CBM_NOT_FOUND;
266 }
267
268 (*entries)[*count].ext = ext_copy;
269 (*entries)[*count].lang = lang;
270 (*count)++;
271 }

Callers 2

load_config_fileFunction · 0.85
load_project_sourceFunction · 0.85

Calls 1

lang_from_stringFunction · 0.85

Tested by

no test coverage detected