summaryrefslogtreecommitdiffstats
path: root/cfg.c
diff options
context:
space:
mode:
authornicm <nicm>2019-12-12 12:49:36 +0000
committernicm <nicm>2019-12-12 12:49:36 +0000
commit5134666702ce972390f39e34bed9b60fe566263a (patch)
tree0e4e8ca37b0dad58d158881356eac998e3932e37 /cfg.c
parent268f2b047a6e9b932a0ff51aa526e1df61d54165 (diff)
Change source-file to use new file code which allows it to read from
stdin.
Diffstat (limited to 'cfg.c')
-rw-r--r--cfg.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/cfg.c b/cfg.c
index fd7ee897..8509ad1b 100644
--- a/cfg.c
+++ b/cfg.c
@@ -195,6 +195,52 @@ load_cfg(const char *path, struct client *c, struct cmdq_item *item, int flags,
return (0);
}
+int
+load_cfg_from_buffer(const void *buf, size_t len, const char *path,
+ struct client *c, struct cmdq_item *item, int flags,
+ struct cmdq_item **new_item)
+{
+ struct cmd_parse_input pi;
+ struct cmd_parse_result *pr;
+ struct cmdq_item *new_item0;
+
+ if (new_item != NULL)
+ *new_item = NULL;
+
+ log_debug("loading %s", path);
+
+ memset(&pi, 0, sizeof pi);
+ pi.flags = flags;
+ pi.file = path;
+ pi.line = 1;
+ pi.item = item;
+ pi.c = c;
+
+ pr = cmd_parse_from_buffer(buf, len, &pi);
+ if (pr->status == CMD_PARSE_EMPTY)
+ return (0);
+ if (pr->status == CMD_PARSE_ERROR) {
+ cfg_add_cause("%s", pr->error);
+ free(pr->error);
+ return (-1);
+ }
+ if (flags & CMD_PARSE_PARSEONLY) {
+ cmd_list_free(pr->cmdlist);
+ return (0);
+ }
+
+ new_item0 = cmdq_get_command(pr->cmdlist, NULL, NULL, 0);
+ if (item != NULL)
+ cmdq_insert_after(item, new_item0);
+ else
+ cmdq_append(NULL, new_item0);
+ cmd_list_free(pr->cmdlist);
+
+ if (new_item != NULL)
+ *new_item = new_item0;
+ return (0);
+}
+
void
cfg_add_cause(const char *fmt, ...)
{