summaryrefslogtreecommitdiffstats
path: root/cfg.c
diff options
context:
space:
mode:
authorThomas Adam <thomas@xteddy.org>2019-12-12 14:33:47 +0000
committerThomas Adam <thomas@xteddy.org>2019-12-12 14:33:47 +0000
commit7922f4ee7bd4c18509c6774971fd007a4c5a10e3 (patch)
treecccfdd336c64b1b652a4b2333fa2efef0ba5edb3 /cfg.c
parent0d99519c3d3522e9281f8e0726e3d71fcf3e57f3 (diff)
parent5134666702ce972390f39e34bed9b60fe566263a (diff)
Merge branch 'obsd-master'
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 8dbb6233..ddc112a2 100644
--- a/cfg.c
+++ b/cfg.c
@@ -194,6 +194,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, ...)
{