summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7004fc9)
raw | patch | inline | side by side (parent: 7004fc9)
author | Florian Forster <ff@octo.it> | |
Mon, 12 Jul 2010 07:55:17 +0000 (09:55 +0200) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Mon, 12 Jul 2010 07:55:17 +0000 (09:55 +0200) |
src/utils_search.c | patch | blob | history |
diff --git a/src/utils_search.c b/src/utils_search.c
index cb01a41268921f529d27494bf1453cdcaa79d1df..648c2ec4694dd75aca5c0544580488989255bd2b 100644 (file)
--- a/src/utils_search.c
+++ b/src/utils_search.c
#include <stdio.h>
#include <string.h>
#include <ctype.h>
+#include <errno.h>
#include "utils_search.h"
#include "utils_array.h"
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;
while ((token = next_token (&ptr)) != NULL)
{
- array_append (si->terms, token);
-
+ store_token (si, token);
free (token);
}