#include "graph_def.h"
#include "graph_ident.h"
#include "utils_cgi.h"
+#include "utils_search.h"
#include <fcgiapp.h>
#include <fcgi_stdio.h>
static int gl_compare_hosts (const void *v0, const void *v1) /* {{{ */
{
- return (strcmp (v0, v1));
+ return (strcmp (*(char * const *) v0, *(char * const *) v1));
} /* }}} int gl_compare_hosts */
static int gl_register_file (const graph_ident_t *file, /* {{{ */
graph_config_t *cfg = gl_active[i];
int status;
- if (!graph_matches_ident (cfg, file))
+ if (!graph_ident_matches (cfg, file))
continue;
status = graph_add_file (cfg, file);
} /* }}} int gl_instance_get_all */
/* }}} gl_instance_get_all, gl_graph_instance_get_all */
-int gl_search (const char *term, graph_inst_callback_t callback, /* {{{ */
- void *user_data)
+int gl_search (search_info_t *si, /* {{{ */
+ graph_inst_callback_t callback, void *user_data)
{
size_t i;
+ graph_ident_t *ident;
+
+ if ((si == NULL) || (callback == NULL))
+ return (EINVAL);
+
+ if (search_has_selector (si))
+ {
+ ident = search_to_ident (si);
+ if (ident == NULL)
+ {
+ fprintf (stderr, "gl_search: search_to_ident failed\n");
+ return (-1);
+ }
+ }
+ else
+ {
+ ident = NULL;
+ }
for (i = 0; i < gl_active_num; i++)
{
int status;
- status = graph_inst_search (gl_active[i], term,
+ if ((ident != NULL) && !graph_ident_intersect (gl_active[i], ident))
+ continue;
+
+ status = graph_search_inst (gl_active[i], si,
/* callback = */ callback,
/* user data = */ user_data);
if (status != 0)
{
int status;
- status = graph_inst_search (gl_dynamic[i], term,
+ if ((ident != NULL) && !graph_ident_intersect (gl_dynamic[i], ident))
+ continue;
+
+ status = graph_search_inst (gl_dynamic[i], si,
/* callback = */ callback,
/* user data = */ user_data);
if (status != 0)
return (0);
} /* }}} int gl_search */
+int gl_search_string (const char *term, graph_inst_callback_t callback, /* {{{ */
+ void *user_data)
+{
+ size_t i;
+
+ for (i = 0; i < gl_active_num; i++)
+ {
+ int status;
+
+ status = graph_search_inst_string (gl_active[i], term,
+ /* callback = */ callback,
+ /* user data = */ user_data);
+ if (status != 0)
+ return (status);
+ }
+
+ for (i = 0; i < gl_dynamic_num; i++)
+ {
+ int status;
+
+ status = graph_search_inst_string (gl_dynamic[i], term,
+ /* callback = */ callback,
+ /* user data = */ user_data);
+ if (status != 0)
+ return (status);
+ }
+
+ return (0);
+} /* }}} int gl_search_string */
+
int gl_search_field (graph_ident_field_t field, /* {{{ */
const char *field_value,
graph_inst_callback_t callback, void *user_data)
{
time_t now;
int status;
+ size_t i;
/*
printf ("Content-Type: text/plain\n\n");
gl_last_update = now;
+ for (i = 0; i < gl_active_num; i++)
+ graph_sort_instances (gl_active[i]);
+
return (status);
} /* }}} int gl_update */