From b51e07a7ad62099fa578cbfb738b1e308fb3a7ce Mon Sep 17 00:00:00 2001 From: Timo Kokkonen Date: Mon, 19 Nov 2012 21:59:00 +0200 Subject: [PATCH] parser: Try loading a parser from a plugin in case no parser is found When a parser is queried and one is not found within the ones that we have already registered, try loading a plugin with that name. If parser plugins are available, the parser might be available after the plugin has been loaded. The project is now fully compatible with having parsers as plugins. Signed-off-by: Timo Kokkonen --- Makefile | 4 ++-- parser.c | 22 +++++++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 3a89e91..677e88e 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ CC=gcc LD=ld -CFLAGS=-Wall -O2 -g +CFLAGS=-Wall -O2 -g -fPIC RRDD_OBJS= main.o process.o rrdtool.o parser.o built_in_parsers.o string.o \ debug.o config.o onewire_parser.o plugin_manager.o @@ -24,7 +24,7 @@ rrdd: $(RRDD_OBJS) $(QUIET_LINK)$(CC) -o rrdd $(RRDD_OBJS) -lconfig -lownet -ldl -rdynamic clean: - rm -vf rrdd *~ *.o .*.d + rm -vf rrdd *~ *.o .*.d *.so .c.o: $(QUIET_CC)$(CC) -MMD -MF .$@.d $(CFLAGS) -c $< -o $@ diff --git a/parser.c b/parser.c index 4a5e535..0437096 100644 --- a/parser.c +++ b/parser.c @@ -2,6 +2,7 @@ #include "parser.h" #include "debug.h" +#include "plugin_manager.h" static struct parser_info *parser_list; @@ -30,7 +31,7 @@ int register_parser(struct parser_info *info) return 0; } -struct parser_info *str_to_parser(const char *str) +static struct parser_info *_str_to_parser(const char *str) { struct parser_info *parser; @@ -41,3 +42,22 @@ struct parser_info *str_to_parser(const char *str) return NULL; } + +struct parser_info *str_to_parser(const char *str) +{ + struct parser_info *parser; + int ret; + + parser = _str_to_parser(str); + + if (parser) + return parser; + + /* No parser found? Try loading a plugin */ + ret = load_parser_plugin(str); + if (ret) + return NULL; + + /* Try finding the parser again, maybe we got lucky and have it now */ + return _str_to_parser(str); +} -- 2.45.0