summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 42951ae)
raw | patch | inline | side by side (parent: 42951ae)
author | Florian Forster <ff@octo.it> | |
Sun, 2 May 2010 06:57:22 +0000 (08:57 +0200) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sun, 2 May 2010 06:57:22 +0000 (08:57 +0200) |
test.fcgi.c | patch | blob | history |
diff --git a/test.fcgi.c b/test.fcgi.c
index a6ca107217399ca4bc7009de77dfe1dc72bf5246..d8edea73aa3007b9ff85bd7d872a33df71b2968c 100644 (file)
--- a/test.fcgi.c
+++ b/test.fcgi.c
#include "action_list_graphs.h"
+struct action_s
+{
+ const char *name;
+ int (*callback) (void);
+};
+typedef struct action_s action_t;
+
+#if 0
struct str_array_s
{
char **ptr;
size_t size;
};
typedef struct str_array_s str_array_t;
+#endif
+static int action_usage (void);
+
+static const action_t actions[] =
+{
+ { "list_graphs", action_list_graphs },
+ { "usage", action_usage }
+};
+static const size_t actions_num = sizeof (actions) / sizeof (actions[0]);
+
+#if 0
static str_array_t *array_alloc (void) /* {{{ */
{
str_array_t *a;
a->size++;
return (0);
} /* }}} int array_add */
-
-static int print_graph (const graph_list_t *gl, void *user_data) /* {{{ */
-{
- if (gl == NULL)
- return (EINVAL);
-
- printf ("host = %s; plugin = %s;", gl->host, gl->plugin);
- if (gl->plugin_instance != NULL)
- printf (" plugin_instance = %s;", gl->plugin_instance);
- printf (" type = %s;", gl->type);
- if (gl->type_instance != NULL)
- printf (" type_instance = %s;", gl->type_instance);
- printf ("\n");
-
- return (0);
-} /* }}} int print_graph */
-
-static int get_graphs_list (char ***ret_graphs, /* {{{ */
- size_t *ret_graphs_num)
-{
- gl_update ();
- gl_foreach (print_graph, /* user_data = */ NULL);
-
- return (0);
-} /* }}} int get_graphs_list */
-
-static int action_hello (void) /* {{{ */
-{
- printf ("Content-Type: text/plain\n\n");
-
- get_graphs_list (NULL, NULL);
-
- return (0);
-} /* }}} int action_hello */
+#endif
static int action_usage (void) /* {{{ */
{
+ size_t i;
+
printf ("Content-Type: text/plain\n\n");
- fputs ("Usage:\n"
+ printf ("Usage:\n"
"\n"
" Available actions:\n"
- "\n"
- " * hello\n"
- "\n", stdout);
+ "\n");
+
+ for (i = 0; i < actions_num; i++)
+ printf (" * %s\n", actions[i].name);
+
+ printf ("\n");
return (0);
} /* }}} int action_usage */
{
return (action_usage ());
}
- else if (strcmp ("list_graphs", action) == 0)
- {
- return (action_list_graphs ());
- }
- else if (strcmp ("hello", action) == 0)
- {
- return (action_hello ());
- }
else
{
+ size_t i;
+
+ for (i = 0; i < actions_num; i++)
+ {
+ if (strcmp (action, actions[i].name) == 0)
+ return ((*actions[i].callback) ());
+ }
+
return (action_usage ());
}
} /* }}} int handle_request */