The MCP client could only start one program and talk to it on a pipe; a server behind an endpoint (junction at http://host:8090/mcp) had no way in. Now the config names the servers and the plugin speaks whichever transport each one offers: - new `mcp NAME { url | cmd | header | enabled }` block (and the flat `mcp = NAME | url=...` form), parsed into struct sp_mcpserver; an entry without a url and without a cmd is refused with its line number - streamable HTTP in plugins/mcp/mcp.c: one POST per JSON-RPC message, answered with one JSON object or an SSE stream of `data:` lines - both are read, Mcp-Session-Id is kept and echoed back, and the Authorization header travels through curl's stdin config so the token never appears in ps - several servers register side by side; tools are mcp_<tool> for one server and mcp_<server>_<tool> for more, so two servers that both offer `search` do not overwrite each other. A server that fails its handshake is reported and skipped, the rest still load. SPLINTER_MCP_CMD stays as the one stdio server - tests: the config and block parsers, and a socket server in test_mcpclient that refuses the tool list without the configured header and answers the call as an event stream - README and docs/CONFIG.md describe both transports and where the token lives
734 lines
15 KiB
C
734 lines
15 KiB
C
/* splinter -- config block syntax; see confblock.h. */
|
|
#include <ctype.h>
|
|
#include <stdarg.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include "confblock.h"
|
|
|
|
#define MAX_ITEMS 64
|
|
#define MAX_ENTRIES 64
|
|
|
|
struct val {
|
|
char *items[MAX_ITEMS];
|
|
size_t n;
|
|
int list;
|
|
};
|
|
|
|
struct ent {
|
|
char key[48];
|
|
struct val v;
|
|
unsigned line;
|
|
};
|
|
|
|
struct cb {
|
|
const char *p;
|
|
unsigned line;
|
|
const char *path;
|
|
struct sp_buf *err;
|
|
struct sp_buf *out;
|
|
unsigned *map;
|
|
size_t nmap, capmap;
|
|
int failed;
|
|
};
|
|
|
|
static void
|
|
fail(struct cb *c, unsigned line, const char *fmt, ...)
|
|
{
|
|
va_list ap;
|
|
char msg[400];
|
|
|
|
if (c->failed)
|
|
return;
|
|
c->failed = 1;
|
|
va_start(ap, fmt);
|
|
vsnprintf(msg, sizeof(msg), fmt, ap);
|
|
va_end(ap);
|
|
sp_buf_printf(c->err, "config: %s:%u: %s", c->path, line, msg);
|
|
}
|
|
|
|
static void
|
|
val_free(struct val *v)
|
|
{
|
|
size_t i;
|
|
|
|
for (i = 0; i < v->n; i++)
|
|
free(v->items[i]);
|
|
v->n = 0;
|
|
}
|
|
|
|
static void
|
|
ents_free(struct ent *e, size_t n)
|
|
{
|
|
size_t i;
|
|
|
|
for (i = 0; i < n; i++)
|
|
val_free(&e[i].v);
|
|
}
|
|
|
|
/* blanks and comments; newlines too when 'nl' */
|
|
static void
|
|
skip(struct cb *c, int nl)
|
|
{
|
|
for (;;) {
|
|
if (*c->p == ' ' || *c->p == '\t' || *c->p == '\r')
|
|
c->p++;
|
|
else if (*c->p == '\n' && nl) {
|
|
c->line++;
|
|
c->p++;
|
|
} else if (*c->p == '#') {
|
|
while (*c->p != '\0' && *c->p != '\n')
|
|
c->p++;
|
|
} else
|
|
break;
|
|
}
|
|
}
|
|
|
|
/* ${NAME} becomes the variable's value, empty when it is not set */
|
|
static char *
|
|
expand(const char *s)
|
|
{
|
|
struct sp_buf b;
|
|
char *r;
|
|
|
|
if (sp_buf_init(&b) != 0)
|
|
return NULL;
|
|
while (*s != '\0') {
|
|
if (s[0] == '$' && s[1] == '{') {
|
|
const char *e = strchr(s + 2, '}');
|
|
char name[96];
|
|
size_t n;
|
|
const char *v;
|
|
|
|
if (e != NULL && (size_t)(e - s - 2) < sizeof(name)) {
|
|
n = (size_t)(e - s - 2);
|
|
memcpy(name, s + 2, n);
|
|
name[n] = '\0';
|
|
v = getenv(name);
|
|
if (v != NULL)
|
|
sp_buf_puts(&b, v);
|
|
s = e + 1;
|
|
continue;
|
|
}
|
|
}
|
|
sp_buf_add(&b, s, 1);
|
|
s++;
|
|
}
|
|
r = b.p != NULL ? strdup(b.p) : strdup("");
|
|
sp_buf_free(&b);
|
|
return r;
|
|
}
|
|
|
|
/* one scalar: "quoted with \" \\ \n" or a bare word */
|
|
static char *
|
|
scalar(struct cb *c)
|
|
{
|
|
char tmp[2048];
|
|
size_t n = 0;
|
|
char *r;
|
|
|
|
if (*c->p == '"') {
|
|
unsigned start = c->line;
|
|
|
|
c->p++;
|
|
while (*c->p != '"') {
|
|
if (*c->p == '\0' || *c->p == '\n') {
|
|
fail(c, start, "string without a closing quote");
|
|
return NULL;
|
|
}
|
|
if (*c->p == '\\' && c->p[1] != '\0') {
|
|
c->p++;
|
|
tmp[n] = *c->p == 'n' ? '\n' : *c->p;
|
|
} else
|
|
tmp[n] = *c->p;
|
|
if (n + 1 < sizeof(tmp))
|
|
n++;
|
|
c->p++;
|
|
}
|
|
c->p++;
|
|
} else {
|
|
while (*c->p != '\0' && !isspace((unsigned char)*c->p) &&
|
|
*c->p != '#' && *c->p != ',' && *c->p != ']' &&
|
|
*c->p != '}' && *c->p != '[' && *c->p != '{') {
|
|
tmp[n] = *c->p++;
|
|
if (n + 1 < sizeof(tmp))
|
|
n++;
|
|
}
|
|
if (n == 0) {
|
|
fail(c, c->line, "a value is missing");
|
|
return NULL;
|
|
}
|
|
}
|
|
tmp[n] = '\0';
|
|
r = expand(tmp);
|
|
if (r == NULL)
|
|
fail(c, c->line, "out of memory");
|
|
return r;
|
|
}
|
|
|
|
static int
|
|
value(struct cb *c, struct val *v)
|
|
{
|
|
memset(v, 0, sizeof(*v));
|
|
skip(c, 0);
|
|
if (*c->p == '[') {
|
|
unsigned start = c->line;
|
|
|
|
v->list = 1;
|
|
c->p++;
|
|
for (;;) {
|
|
skip(c, 1);
|
|
if (*c->p == ',') {
|
|
c->p++;
|
|
continue;
|
|
}
|
|
if (*c->p == ']') {
|
|
c->p++;
|
|
break;
|
|
}
|
|
if (*c->p == '\0') {
|
|
fail(c, start, "list without a closing ]");
|
|
return -1;
|
|
}
|
|
if (v->n == MAX_ITEMS) {
|
|
fail(c, c->line, "more than %d items in a list",
|
|
MAX_ITEMS);
|
|
return -1;
|
|
}
|
|
v->items[v->n] = scalar(c);
|
|
if (v->items[v->n] == NULL)
|
|
return -1;
|
|
v->n++;
|
|
}
|
|
return 0;
|
|
}
|
|
v->items[0] = scalar(c);
|
|
if (v->items[0] == NULL)
|
|
return -1;
|
|
v->n = 1;
|
|
return 0;
|
|
}
|
|
|
|
static const char *
|
|
one(struct cb *c, const struct ent *e)
|
|
{
|
|
if (e->v.n != 1 || e->v.list) {
|
|
fail(c, e->line, "%s wants one value, not a list", e->key);
|
|
return NULL;
|
|
}
|
|
return e->v.items[0];
|
|
}
|
|
|
|
/* the items as "a,b,c" */
|
|
static void
|
|
joined(const struct val *v, char *buf, size_t cap)
|
|
{
|
|
size_t i, n = 0;
|
|
|
|
buf[0] = '\0';
|
|
for (i = 0; i < v->n && n + 1 < cap; i++)
|
|
n += (size_t)snprintf(buf + n, cap - n, "%s%s", i > 0 ? "," : "",
|
|
v->items[i]);
|
|
if (n >= cap)
|
|
buf[cap - 1] = '\0';
|
|
}
|
|
|
|
static int
|
|
boolean(const char *s)
|
|
{
|
|
return !strcmp(s, "true") || !strcmp(s, "yes") || !strcmp(s, "on") ||
|
|
!strcmp(s, "1");
|
|
}
|
|
|
|
static void
|
|
emit(struct cb *c, unsigned line, const char *fmt, ...)
|
|
{
|
|
va_list ap;
|
|
char l[4096];
|
|
|
|
va_start(ap, fmt);
|
|
vsnprintf(l, sizeof(l), fmt, ap);
|
|
va_end(ap);
|
|
sp_buf_puts(c->out, l);
|
|
sp_buf_puts(c->out, "\n");
|
|
if (c->nmap == c->capmap) {
|
|
size_t nc = c->capmap != 0 ? c->capmap * 2 : 64;
|
|
unsigned *nm = realloc(c->map, nc * sizeof(*nm));
|
|
|
|
if (nm == NULL) {
|
|
fail(c, line, "out of memory");
|
|
return;
|
|
}
|
|
c->map = nm;
|
|
c->capmap = nc;
|
|
}
|
|
c->map[c->nmap++] = line;
|
|
}
|
|
|
|
/* a field value goes into a '|' separated line: it must not hold one */
|
|
static int
|
|
clean(struct cb *c, const struct ent *e, const char *s)
|
|
{
|
|
if (strchr(s, '|') != NULL || strchr(s, '\n') != NULL) {
|
|
fail(c, e->line, "%s must not contain '|' or a newline", e->key);
|
|
return 0;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
static int
|
|
in_list(const char *const *list, const char *k)
|
|
{
|
|
for (; *list != NULL; list++)
|
|
if (!strcmp(*list, k))
|
|
return 1;
|
|
return 0;
|
|
}
|
|
|
|
static void
|
|
do_core(struct cb *c, struct ent *e, size_t n)
|
|
{
|
|
size_t i, j;
|
|
|
|
for (i = 0; i < n && !c->failed; i++) {
|
|
const char *k = e[i].key, *s;
|
|
char list[2048];
|
|
|
|
if (!strcmp(k, "plugins") || !strcmp(k, "skills")) {
|
|
for (j = 0; j < e[i].v.n; j++)
|
|
emit(c, e[i].line, "%s = %s",
|
|
k[0] == 'p' ? "plugin" : "skills_dir",
|
|
e[i].v.items[j]);
|
|
continue;
|
|
}
|
|
if (e[i].v.list) {
|
|
joined(&e[i].v, list, sizeof(list));
|
|
emit(c, e[i].line, "%s = %s", k, list);
|
|
continue;
|
|
}
|
|
s = one(c, &e[i]);
|
|
if (s == NULL)
|
|
return;
|
|
if (!strcmp(k, "autonomous") || !strcmp(k, "env_delegates"))
|
|
emit(c, e[i].line, "%s = %d", k, boolean(s));
|
|
else
|
|
emit(c, e[i].line, "%s = %s", k, s);
|
|
}
|
|
}
|
|
|
|
static void
|
|
do_provider(struct cb *c, const char *name, unsigned line, struct ent *e,
|
|
size_t n)
|
|
{
|
|
static const char *const plain[] = { "kind", "cmd", "host", "endpoint",
|
|
"model", "key_env", "prio", "max_parallel", "limit", "tokens", NULL };
|
|
struct sp_buf l;
|
|
const char *about = "";
|
|
size_t i, j;
|
|
int skip_it = 0;
|
|
|
|
if (sp_buf_init(&l) != 0) {
|
|
fail(c, line, "out of memory");
|
|
return;
|
|
}
|
|
for (i = 0; i < n; i++) {
|
|
if (!strcmp(e[i].key, "about") || !strcmp(e[i].key, "description")) {
|
|
about = one(c, &e[i]);
|
|
if (about == NULL || !clean(c, &e[i], about))
|
|
goto done;
|
|
} else if (!strcmp(e[i].key, "delegate")) {
|
|
const char *s = one(c, &e[i]);
|
|
|
|
if (s == NULL)
|
|
goto done;
|
|
skip_it = !boolean(s);
|
|
}
|
|
}
|
|
sp_buf_printf(&l, "delegate = %s", name);
|
|
if (about[0] != '\0')
|
|
sp_buf_printf(&l, " | %s", about);
|
|
for (i = 0; i < n; i++) {
|
|
const char *k = e[i].key, *s;
|
|
char list[1024];
|
|
|
|
if (!strcmp(k, "about") || !strcmp(k, "description") ||
|
|
!strcmp(k, "delegate"))
|
|
continue;
|
|
if (!strcmp(k, "tags")) {
|
|
joined(&e[i].v, list, sizeof(list));
|
|
if (!clean(c, &e[i], list))
|
|
goto done;
|
|
if (list[0] != '\0')
|
|
sp_buf_printf(&l, " | tags=%s", list);
|
|
} else if (!strcmp(k, "env")) {
|
|
for (j = 0; j < e[i].v.n; j++) {
|
|
const char *kv = e[i].v.items[j], *eq = strchr(kv, '=');
|
|
|
|
/* NAME= with nothing after it: the variable was not set */
|
|
if (eq == NULL || eq[1] == '\0')
|
|
continue;
|
|
if (!clean(c, &e[i], kv))
|
|
goto done;
|
|
sp_buf_printf(&l, " | env=%s", kv);
|
|
}
|
|
} else if (in_list(plain, k)) {
|
|
s = one(c, &e[i]);
|
|
if (s == NULL || !clean(c, &e[i], s))
|
|
goto done;
|
|
sp_buf_printf(&l, " | %s=%s", k, s);
|
|
} else {
|
|
fail(c, e[i].line, "unknown provider field '%s'", k);
|
|
goto done;
|
|
}
|
|
}
|
|
if (!skip_it && l.p != NULL)
|
|
emit(c, line, "%s", l.p);
|
|
done:
|
|
sp_buf_free(&l);
|
|
}
|
|
|
|
static void
|
|
do_pool(struct cb *c, const char *name, unsigned line, struct ent *e, size_t n)
|
|
{
|
|
char members[512] = "";
|
|
const char *strategy = "failover";
|
|
size_t i;
|
|
|
|
for (i = 0; i < n; i++) {
|
|
if (!strcmp(e[i].key, "members"))
|
|
joined(&e[i].v, members, sizeof(members));
|
|
else if (!strcmp(e[i].key, "strategy")) {
|
|
strategy = one(c, &e[i]);
|
|
if (strategy == NULL)
|
|
return;
|
|
} else {
|
|
fail(c, e[i].line, "unknown pool field '%s'", e[i].key);
|
|
return;
|
|
}
|
|
}
|
|
if (members[0] == '\0') {
|
|
fail(c, line, "pool %s has no members", name);
|
|
return;
|
|
}
|
|
emit(c, line, "pool = %s | strategy=%s | members=%s", name, strategy,
|
|
members);
|
|
}
|
|
|
|
static void
|
|
do_mcp(struct cb *c, const char *name, unsigned line, struct ent *e, size_t n)
|
|
{
|
|
struct sp_buf l;
|
|
size_t i;
|
|
|
|
if (sp_buf_init(&l) != 0)
|
|
return;
|
|
sp_buf_printf(&l, "mcp = %s", name);
|
|
for (i = 0; i < n; i++) {
|
|
const char *s = one(c, &e[i]);
|
|
|
|
if (s == NULL || !clean(c, &e[i], s))
|
|
goto done;
|
|
if (!strcmp(e[i].key, "url") || !strcmp(e[i].key, "cmd") ||
|
|
!strcmp(e[i].key, "header"))
|
|
sp_buf_printf(&l, " | %s=%s", e[i].key, s);
|
|
else if (!strcmp(e[i].key, "enabled"))
|
|
sp_buf_printf(&l, " | enabled=%d", boolean(s));
|
|
else {
|
|
fail(c, e[i].line, "unknown mcp field '%s'", e[i].key);
|
|
goto done;
|
|
}
|
|
}
|
|
emit(c, line, "%s", l.p);
|
|
done:
|
|
sp_buf_free(&l);
|
|
}
|
|
|
|
static void
|
|
do_exit(struct cb *c, const char *name, unsigned line, struct ent *e, size_t n)
|
|
{
|
|
struct sp_buf l;
|
|
size_t i;
|
|
|
|
if (sp_buf_init(&l) != 0)
|
|
return;
|
|
sp_buf_printf(&l, "exit = %s", name);
|
|
for (i = 0; i < n; i++) {
|
|
const char *s = one(c, &e[i]);
|
|
|
|
if (s == NULL || !clean(c, &e[i], s))
|
|
goto done;
|
|
if (!strcmp(e[i].key, "label") || !strcmp(e[i].key, "about"))
|
|
sp_buf_printf(&l, " | %s", s);
|
|
else if (!strcmp(e[i].key, "endpoint") ||
|
|
!strcmp(e[i].key, "model") || !strcmp(e[i].key, "key_env"))
|
|
sp_buf_printf(&l, " | %s=%s", e[i].key, s);
|
|
else {
|
|
fail(c, e[i].line, "unknown exit field '%s'", e[i].key);
|
|
goto done;
|
|
}
|
|
}
|
|
emit(c, line, "%s", l.p);
|
|
done:
|
|
sp_buf_free(&l);
|
|
}
|
|
|
|
/*
|
|
* The body of a block, after its '{': key = value entries, and for 'env' a
|
|
* nested block of NAME = value lines which becomes the list of NAME=value.
|
|
*/
|
|
static size_t
|
|
body(struct cb *c, struct ent *e, int *closed)
|
|
{
|
|
size_t n = 0;
|
|
|
|
*closed = 0;
|
|
for (;;) {
|
|
char key[48];
|
|
size_t k = 0;
|
|
unsigned line;
|
|
|
|
skip(c, 1);
|
|
if (*c->p == '}') {
|
|
c->p++;
|
|
*closed = 1;
|
|
return n;
|
|
}
|
|
if (*c->p == '\0') {
|
|
fail(c, c->line, "block without a closing }");
|
|
return n;
|
|
}
|
|
line = c->line;
|
|
while (isalnum((unsigned char)*c->p) || *c->p == '_' ||
|
|
*c->p == '-' || *c->p == '.') {
|
|
if (k + 1 < sizeof(key))
|
|
key[k++] = *c->p;
|
|
c->p++;
|
|
}
|
|
key[k] = '\0';
|
|
if (k == 0) {
|
|
fail(c, line, "expected a name, found '%c'", *c->p);
|
|
return n;
|
|
}
|
|
if (n == MAX_ENTRIES) {
|
|
fail(c, line, "more than %d entries in a block", MAX_ENTRIES);
|
|
return n;
|
|
}
|
|
memset(&e[n], 0, sizeof(e[n]));
|
|
snprintf(e[n].key, sizeof(e[n].key), "%s", key);
|
|
e[n].line = line;
|
|
skip(c, 0);
|
|
if (*c->p == '{') {
|
|
/* env { A = b } */
|
|
c->p++;
|
|
e[n].v.list = 1;
|
|
for (;;) {
|
|
char nm[96];
|
|
size_t m = 0;
|
|
char *v;
|
|
unsigned vl;
|
|
|
|
skip(c, 1);
|
|
if (*c->p == '}') {
|
|
c->p++;
|
|
break;
|
|
}
|
|
if (*c->p == '\0') {
|
|
fail(c, line, "block without a closing }");
|
|
n++;
|
|
return n;
|
|
}
|
|
vl = c->line;
|
|
while (isalnum((unsigned char)*c->p) || *c->p == '_') {
|
|
if (m + 1 < sizeof(nm))
|
|
nm[m++] = *c->p;
|
|
c->p++;
|
|
}
|
|
nm[m] = '\0';
|
|
skip(c, 0);
|
|
if (m == 0 || *c->p != '=') {
|
|
fail(c, vl, "expected NAME = value");
|
|
n++;
|
|
return n;
|
|
}
|
|
c->p++;
|
|
skip(c, 0);
|
|
v = scalar(c);
|
|
if (v == NULL) {
|
|
n++;
|
|
return n;
|
|
}
|
|
if (e[n].v.n < MAX_ITEMS) {
|
|
size_t len = strlen(nm) + strlen(v) + 2;
|
|
char *kv = malloc(len);
|
|
|
|
if (kv != NULL) {
|
|
snprintf(kv, len, "%s=%s", nm, v);
|
|
e[n].v.items[e[n].v.n++] = kv;
|
|
}
|
|
}
|
|
free(v);
|
|
}
|
|
n++;
|
|
continue;
|
|
}
|
|
if (*c->p != '=') {
|
|
fail(c, line, "expected '=' after %s", key);
|
|
return n;
|
|
}
|
|
c->p++;
|
|
if (value(c, &e[n].v) != 0) {
|
|
n++;
|
|
return n;
|
|
}
|
|
n++;
|
|
}
|
|
}
|
|
|
|
int
|
|
sp_confblock_is(const char *text)
|
|
{
|
|
const char *p = text;
|
|
|
|
while (*p != '\0') {
|
|
const char *eol = strchr(p, '\n'), *q;
|
|
|
|
if (eol == NULL)
|
|
eol = p + strlen(p);
|
|
for (q = p; q < eol && (*q == ' ' || *q == '\t'); q++)
|
|
;
|
|
if (q < eol && *q != '#') {
|
|
for (; q < eol; q++) {
|
|
if (*q == '=')
|
|
return 0;
|
|
if (*q == '{')
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
p = *eol == '\n' ? eol + 1 : eol;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int
|
|
sp_confblock_translate(const char *text, const char *path, struct sp_buf *out,
|
|
unsigned **map, size_t *nmap, struct sp_buf *err)
|
|
{
|
|
struct cb c;
|
|
struct ent *e;
|
|
|
|
memset(&c, 0, sizeof(c));
|
|
c.p = text;
|
|
c.line = 1;
|
|
c.path = path;
|
|
c.err = err;
|
|
c.out = out;
|
|
e = calloc(MAX_ENTRIES, sizeof(*e));
|
|
if (e == NULL) {
|
|
sp_buf_printf(err, "config: %s: out of memory", path);
|
|
return -1;
|
|
}
|
|
for (;;) {
|
|
char kind[48], name[96];
|
|
size_t k = 0, n;
|
|
unsigned line;
|
|
int closed;
|
|
|
|
skip(&c, 1);
|
|
if (*c.p == '\0' || c.failed)
|
|
break;
|
|
line = c.line;
|
|
while (isalnum((unsigned char)*c.p) || *c.p == '_' || *c.p == '-')
|
|
if (k + 1 < sizeof(kind))
|
|
kind[k++] = *c.p++;
|
|
else
|
|
c.p++;
|
|
kind[k] = '\0';
|
|
if (k == 0) {
|
|
fail(&c, line, "expected a block or a setting, found '%c'",
|
|
*c.p);
|
|
break;
|
|
}
|
|
skip(&c, 0);
|
|
if (*c.p == '=') {
|
|
/* a bare setting at the top level belongs to core */
|
|
c.p++;
|
|
snprintf(e[0].key, sizeof(e[0].key), "%s", kind);
|
|
e[0].line = line;
|
|
if (value(&c, &e[0].v) != 0)
|
|
break;
|
|
do_core(&c, e, 1);
|
|
ents_free(e, 1);
|
|
continue;
|
|
}
|
|
name[0] = '\0';
|
|
if (*c.p != '{') {
|
|
size_t m = 0;
|
|
|
|
while (*c.p != '\0' && !isspace((unsigned char)*c.p) &&
|
|
*c.p != '{' && *c.p != '#')
|
|
if (m + 1 < sizeof(name))
|
|
name[m++] = *c.p++;
|
|
else
|
|
c.p++;
|
|
name[m] = '\0';
|
|
skip(&c, 0);
|
|
}
|
|
if (*c.p != '{') {
|
|
fail(&c, line, "expected '{' after %s", kind);
|
|
break;
|
|
}
|
|
c.p++;
|
|
n = body(&c, e, &closed);
|
|
if (!c.failed && closed) {
|
|
int needs_name = !strcmp(kind, "provider") ||
|
|
!strcmp(kind, "pool") || !strcmp(kind, "exit") ||
|
|
!strcmp(kind, "mcp");
|
|
|
|
if (needs_name && name[0] == '\0')
|
|
fail(&c, line, "%s needs a name: %s NAME { ... }",
|
|
kind, kind);
|
|
else if (!needs_name && name[0] != '\0')
|
|
fail(&c, line, "%s takes no name", kind);
|
|
else if (!strcmp(kind, "core"))
|
|
do_core(&c, e, n);
|
|
else if (!strcmp(kind, "telegram")) {
|
|
size_t i;
|
|
|
|
for (i = 0; i < n && !c.failed; i++) {
|
|
if (!strcmp(e[i].key, "allow")) {
|
|
char list[256];
|
|
|
|
joined(&e[i].v, list, sizeof(list));
|
|
emit(&c, e[i].line, "telegram_allow = %s", list);
|
|
} else
|
|
fail(&c, e[i].line,
|
|
"unknown telegram field '%s'", e[i].key);
|
|
}
|
|
} else if (!strcmp(kind, "provider"))
|
|
do_provider(&c, name, line, e, n);
|
|
else if (!strcmp(kind, "pool"))
|
|
do_pool(&c, name, line, e, n);
|
|
else if (!strcmp(kind, "exit"))
|
|
do_exit(&c, name, line, e, n);
|
|
else if (!strcmp(kind, "mcp"))
|
|
do_mcp(&c, name, line, e, n);
|
|
else
|
|
fail(&c, line, "unknown block '%s' (core, telegram, "
|
|
"provider, pool, exit, mcp)", kind);
|
|
}
|
|
ents_free(e, n);
|
|
if (c.failed)
|
|
break;
|
|
}
|
|
free(e);
|
|
if (c.failed) {
|
|
free(c.map);
|
|
return -1;
|
|
}
|
|
*map = c.map;
|
|
*nmap = c.nmap;
|
|
return 0;
|
|
}
|