]> git.itanic.dy.fi Git - rrdd/blob - parser.c
onewire_parser.c: Fix compiler warnings about string lengths
[rrdd] / parser.c
1 #include <string.h>
2
3 #include "parser.h"
4 #include "debug.h"
5 #include "plugin_manager.h"
6
7 static struct parser_info *parser_list;
8
9 int register_parser(struct parser_info *info)
10 {
11         struct parser_info *parser;
12
13         if (!info->name) {
14                 pr_err("Unable to register parser without a name\n");
15                 return -1;
16         }
17
18         pr_info("Registering parser %s\n", info->name);
19
20         if (!parser_list) {
21                 parser_list = info;
22                 return 0;
23         }
24
25         for (parser = parser_list; parser->next; parser = parser->next)
26                 ;
27
28         parser->next = info;
29         info->next = NULL;
30
31         return 0;
32 }
33
34 static struct parser_info *_str_to_parser(const char *str)
35 {
36         struct parser_info *parser;
37
38         for (parser = parser_list; parser; parser = parser->next) {
39                 if (!strcmp(str, parser->name))
40                         return parser;
41         }
42
43         return NULL;
44 }
45
46 struct parser_info *str_to_parser(const char *str)
47 {
48         struct parser_info *parser;
49         int ret;
50
51         parser = _str_to_parser(str);
52
53         if (parser)
54                 return parser;
55
56         /* No parser found? Try loading a plugin */
57         ret = load_parser_plugin(str);
58         if (ret)
59                 return NULL;
60
61         /* Try finding the parser again, maybe we got lucky and have it now */
62         return _str_to_parser(str);
63 }