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

Function sh_link_http

src/pipeline/pass_shell.c:3697–3752  ·  view source on GitHub ↗

An HTTP request a script makes: HTTP_CALLS {via: curl | wget, method, * url_path, host} to its Route (sh_http_service). */

Source from the content-addressed store, hash-verified

3695/* An HTTP request a script makes: HTTP_CALLS {via: curl | wget, method,
3696 * url_path, host} to its Route (sh_http_service). */
3697static int sh_link_http(cbm_pipeline_ctx_t *ctx, int64_t src, const sh_hit_t *x) {
3698 const char *auth = strstr(x->ext, "://");
3699 if (!auth || src <= 0) {
3700 return 0;
3701 }
3702 auth += strlen("://");
3703 size_t al = strcspn(auth, "/");
3704 char host[CBM_SZ_256];
3705 size_t hl = auth[0] == '[' ? strcspn(auth, "]") + SKIP_ONE : strcspn(auth, ":/");
3706 if (hl == 0 || hl > al || hl >= sizeof(host)) {
3707 return 0;
3708 }
3709 for (size_t i = 0; i < hl; i++) {
3710 host[i] = (char)tolower((unsigned char)auth[i]);
3711 }
3712 host[hl] = '\0';
3713 const char *path = auth + al;
3714 char cpath[CBM_SZ_2K];
3715 cbm_route_canon_path(path, cpath, sizeof(cpath));
3716 bool local = sh_http_service(ctx, host);
3717 char qn[CBM_ROUTE_QN_SIZE];
3718 snprintf(qn, sizeof(qn), "__route__%s__%.*s%s", x->path, local ? 0 : (int)(auth + al - x->ext),
3719 x->ext, cpath);
3720 char authority[CBM_SZ_256]; /* the host with its port */
3721 if (al >= sizeof(authority)) {
3722 return 0;
3723 }
3724 for (size_t i = 0; i < al; i++) {
3725 authority[i] = (char)tolower((unsigned char)auth[i]);
3726 }
3727 authority[al] = '\0';
3728 char ehost[CBM_SZ_512];
3729 char epath[CBM_SZ_4K];
3730 cbm_json_escape(ehost, (int)sizeof(ehost), authority);
3731 cbm_json_escape(epath, (int)sizeof(epath), path);
3732 char rprops[CBM_SZ_1K];
3733 if (local) {
3734 snprintf(rprops, sizeof(rprops), "{\"method\":\"%s\"}", x->path);
3735 } else {
3736 snprintf(rprops, sizeof(rprops), "{\"method\":\"%s\",\"host\":\"%s\",\"external\":true}",
3737 x->path, ehost);
3738 }
3739 int64_t route =
3740 cbm_gbuf_upsert_node(ctx->gbuf, "Route", local ? path : x->ext, qn, "", 0, 0, rprops);
3741 if (route <= 0 || route == src) {
3742 return 0;
3743 }
3744 char ci[CBM_SZ_1K];
3745 sh_ci_props(x, ci, sizeof(ci));
3746 char props[CBM_SZ_4K + CBM_SZ_1K];
3747 snprintf(props, sizeof(props),
3748 "{\"via\":\"%s\",\"method\":\"%s\",\"url_path\":\"%s\",\"host\":\"%s\"%s,\"line\":%d}",
3749 x->via, x->path, epath, ehost, ci, x->line);
3750 cbm_gbuf_insert_edge(ctx->gbuf, src, route, "HTTP_CALLS", props);
3751 return SKIP_ONE;
3752}
3753
3754static int sh_link_hit(cbm_pipeline_ctx_t *ctx, const sh_hit_t *x, int64_t src,

Callers 1

sh_link_hitFunction · 0.85

Calls 6

cbm_route_canon_pathFunction · 0.85
sh_http_serviceFunction · 0.85
cbm_json_escapeFunction · 0.85
cbm_gbuf_upsert_nodeFunction · 0.85
sh_ci_propsFunction · 0.85
cbm_gbuf_insert_edgeFunction · 0.85

Tested by

no test coverage detected