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

Function dk_normalize

src/pipeline/pass_docker.c:292–332  ·  view source on GitHub ↗

The repository identity of image reference `ref` into out, the registry * its host names into reg. A reference without a host is the repository as * written, its registry unknown: docker.io is only Docker's default -- a * short-name search list (Podman, CRI-O) or a local-only build tag resolves * elsewhere or nowhere. */

Source from the content-addressed store, hash-verified

290 * short-name search list (Podman, CRI-O) or a local-only build tag resolves
291 * elsewhere or nowhere. */
292static bool dk_normalize(const char *ref, char *out, size_t sz, char *reg, size_t reg_sz) {
293 if (!dk_ref_chars(ref)) {
294 return false;
295 }
296 char r[CBM_SZ_512];
297 snprintf(r, sizeof(r), "%s", ref);
298 char *at = strchr(r, '@');
299 if (at) {
300 *at = '\0';
301 }
302 char *slash = strrchr(r, '/');
303 char *colon = strchr(slash ? slash : r, ':');
304 if (colon) {
305 *colon = '\0';
306 }
307 if (!r[0] || strchr(r, ' ') || strchr(r, '$')) {
308 return false;
309 }
310 char *first_end = strchr(r, '/');
311 size_t fl = first_end ? (size_t)(first_end - r) : 0;
312 bool host = first_end && (memchr(r, '.', fl) || memchr(r, ':', fl) ||
313 (fl == strlen("localhost") && strncmp(r, "localhost", fl) == 0));
314 if (!host) {
315 snprintf(out, sz, "%s", r);
316 snprintf(reg, reg_sz, "%s", DK_REGISTRY_UNKNOWN);
317 return true;
318 }
319 const char *rest = first_end + SKIP_ONE;
320 bool hub =
321 (fl == strlen("docker.io") && strncmp(r, "docker.io", fl) == 0) ||
322 (fl == strlen("index.docker.io") && strncmp(r, "index.docker.io", fl) == 0) ||
323 (fl == strlen("registry-1.docker.io") && strncmp(r, "registry-1.docker.io", fl) == 0);
324 if (hub) {
325 snprintf(out, sz, "docker.io/%s%s", strchr(rest, '/') ? "" : "library/", rest);
326 snprintf(reg, reg_sz, "docker.io");
327 } else {
328 snprintf(out, sz, "%.*s/%s", (int)fl, r, rest);
329 snprintf(reg, reg_sz, "%.*s", (int)fl, r);
330 }
331 return true;
332}
333
334/* An earlier stage of this file: its name, or a stage index. */
335static bool dk_is_stage(const dk_t *d, const char *ref) {

Callers 2

cbm_pipeline_image_nodeFunction · 0.85
dk_hub_imageFunction · 0.85

Calls 1

dk_ref_charsFunction · 0.85

Tested by

no test coverage detected