From 72f42f3352e563ac49636cf64a0c985fe3ca8b67 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Mon, 12 Jul 2010 09:55:17 +0200 Subject: [PATCH] src/utils_search.c: Implement parsing of the tokens. --- src/utils_search.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/src/utils_search.c b/src/utils_search.c index cb01a41..648c2ec 100644 --- a/src/utils_search.c +++ b/src/utils_search.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "utils_search.h" #include "utils_array.h" @@ -150,6 +151,39 @@ static char *next_token (const char **buffer) /* {{{ */ return (ret); } /* }}} char *next_token */ +static int store_token_field (char **field, const char *token) +{ + char *copy; + + if ((field == NULL) || (token == NULL)) + return (EINVAL); + + copy = strdup (token); + if (copy == NULL) + return (ENOMEM); + + free (*field); + *field = copy; + + return (0); +} /* }}} int store_token_field */ + +static int store_token (search_info_t *si, const char *token) +{ + if (strncmp ("host:", token, strlen ("host:")) == 0) + return (store_token_field (&si->host, token + strlen ("host:"))); + else if (strncmp ("plugin:", token, strlen ("plugin:")) == 0) + return (store_token_field (&si->plugin, token + strlen ("plugin:"))); + else if (strncmp ("plugin_instance:", token, strlen ("plugin_instance:")) == 0) + return (store_token_field (&si->plugin_instance, token + strlen ("plugin_instance:"))); + else if (strncmp ("type:", token, strlen ("type:")) == 0) + return (store_token_field (&si->type, token + strlen ("type:"))); + else if (strncmp ("type_instance:", token, strlen ("type_instance:")) == 0) + return (store_token_field (&si->type_instance, token + strlen ("type_instance:"))); + + return (array_append (si->terms, token)); +} /* }}} int store_token */ + search_info_t *search_parse (const char *search) /* {{{ */ { const char *ptr; @@ -172,8 +206,7 @@ search_info_t *search_parse (const char *search) /* {{{ */ while ((token = next_token (&ptr)) != NULL) { - array_append (si->terms, token); - + store_token (si, token); free (token); } -- 2.30.2