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

Function cbm_http_query_param

src/ui/httpd.c:820–871  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

818}
819
820bool cbm_http_query_param(const char *query, const char *name, char *buf, int bufsz) {
821 if (!query || !name || !buf || bufsz <= 0)
822 return false;
823 buf[0] = '\0';
824 size_t name_len = strlen(name);
825
826 const char *p = query;
827 while (*p) {
828 const char *pair_end = strchr(p, '&');
829 if (!pair_end)
830 pair_end = p + strlen(p);
831 const char *eq = memchr(p, '=', (size_t)(pair_end - p));
832 size_t klen = eq ? (size_t)(eq - p) : (size_t)(pair_end - p);
833
834 if (klen == name_len && memcmp(p, name, name_len) == 0) {
835 if (!eq)
836 return false; /* present but no value */
837 /* Percent-decode the value into buf. */
838 const char *v = eq + 1;
839 int out = 0;
840 while (v < pair_end) {
841 char ch = *v;
842 if (ch == '+') {
843 ch = ' ';
844 v++;
845 } else if (ch == '%') {
846 if (pair_end - v < 3) /* needs two hex digits */
847 return false;
848 int hi = hex_val(v[1]);
849 int lo = hex_val(v[2]);
850 if (hi < 0 || lo < 0)
851 return false;
852 ch = (char)((hi << 4) | lo);
853 if (ch == '\0')
854 return false; /* decoded NUL never allowed */
855 v += 3;
856 } else {
857 v++;
858 }
859 if (out >= bufsz - 1) {
860 buf[0] = '\0';
861 return false; /* oversize — reject, never truncate */
862 }
863 buf[out++] = ch;
864 }
865 buf[out] = '\0';
866 return out > 0;
867 }
868 p = (*pair_end == '&') ? pair_end + 1 : pair_end;
869 }
870 return false;
871}

Callers 15

handle_repo_infoFunction · 0.85
handle_logsFunction · 0.85
handle_agent_eventsFunction · 0.85
handle_ui_log_getFunction · 0.85
handle_browseFunction · 0.85
handle_adr_getFunction · 0.85
handle_delete_projectFunction · 0.85
handle_project_healthFunction · 0.85
handle_layoutFunction · 0.85
atlas_open_projectFunction · 0.85
handle_atlas_treeFunction · 0.85
handle_atlas_symbolFunction · 0.85

Calls 1

hex_valFunction · 0.70

Tested by

no test coverage detected