From 5134666702ce972390f39e34bed9b60fe566263a Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 12 Dec 2019 12:49:36 +0000 Subject: Change source-file to use new file code which allows it to read from stdin. --- cfg.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'cfg.c') 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, ...) { -- cgit v1.2.3