| 1074 | } |
| 1075 | |
| 1076 | static char *agent_json_canonical(cbm_agent_client_id_t id, const char *binary_path) { |
| 1077 | char *escaped = agent_json_escape(binary_path); |
| 1078 | if (!escaped) { |
| 1079 | return NULL; |
| 1080 | } |
| 1081 | const char *extra = ""; |
| 1082 | if (id == CBM_AGENT_CLIENT_GITLAB_DUO || id == CBM_AGENT_CLIENT_VISUAL_STUDIO || |
| 1083 | id == CBM_AGENT_CLIENT_OMP) { |
| 1084 | extra = ", \"type\": \"stdio\""; |
| 1085 | } else if (id == CBM_AGENT_CLIENT_ROVO_DEV) { |
| 1086 | extra = ", \"transport\": \"stdio\""; |
| 1087 | } |
| 1088 | size_t needed = strlen(escaped) + strlen(extra) + 64U; |
| 1089 | char *canonical = (char *)malloc(needed); |
| 1090 | if (canonical) { |
| 1091 | int written = |
| 1092 | snprintf(canonical, needed, "{ \"command\": \"%s\", \"args\": []%s }", escaped, extra); |
| 1093 | if (written < 0 || (size_t)written >= needed) { |
| 1094 | free(canonical); |
| 1095 | canonical = NULL; |
| 1096 | } |
| 1097 | } |
| 1098 | free(escaped); |
| 1099 | return canonical; |
| 1100 | } |
| 1101 | |
| 1102 | static char *agent_json_compact(const char *data, size_t length) { |
| 1103 | char *output = (char *)malloc(length + 1U); |
no test coverage detected