summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 5cc6274)
raw | patch | inline | side by side (parent: 5cc6274)
author | Florian Forster <ff@octo.it> | |
Fri, 30 Apr 2010 15:42:18 +0000 (17:42 +0200) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Fri, 30 Apr 2010 15:42:18 +0000 (17:42 +0200) |
Makefile | patch | blob | history | |
fcgi_test.c | [deleted file] | patch | blob | history |
test.fcgi.c | [new file with mode: 0644] | patch | blob |
diff --git a/Makefile b/Makefile
index 7360c5ad9a5b5eee0001ac80fbee682e1d6a62ef..beef56c1a4911f0ce43f9c61b2a95b76bb850cf3 100644 (file)
--- a/Makefile
+++ b/Makefile
LDFLAGS =
LDLIBS =
-all: test fcgi_test
+all: test.fcgi
clean:
rm -f test.cgi
test: test.c utils_params.o
-fcgi_test: LDLIBS = -lfcgi
-fcgi_test: fcgi_test.c common.o graph_list.o utils_params.o action_list_graphs.o
+test.fcgi: LDLIBS = -lfcgi
+test.fcgi: test.fcgi.c common.o graph_list.o utils_params.o action_list_graphs.o
.PHONY: clean
diff --git a/fcgi_test.c b/fcgi_test.c
--- a/fcgi_test.c
+++ /dev/null
@@ -1,176 +0,0 @@
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <strings.h>
-#include <errno.h>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <dirent.h>
-
-#include <fcgiapp.h>
-#include <fcgi_stdio.h>
-
-#include "common.h"
-#include "graph_list.h"
-#include "utils_params.h"
-
-#include "action_list_graphs.h"
-
-struct str_array_s
-{
- char **ptr;
- size_t size;
-};
-typedef struct str_array_s str_array_t;
-
-static str_array_t *array_alloc (void) /* {{{ */
-{
- str_array_t *a;
-
- a = malloc (sizeof (*a));
- if (a == NULL)
- return (NULL);
-
- memset (a, 0, sizeof (*a));
- a->ptr = NULL;
- a->size = 0;
-
- return (a);
-} /* }}} str_array_t *array_alloc */
-
-static void array_free (str_array_t *a) /* {{{ */
-{
- if (a == NULL)
- return;
-
- free (a->ptr);
- a->ptr = NULL;
- a->size = 0;
-
- free (a);
-} /* }}} void array_free */
-
-static int array_add (const char *entry, void *user_data) /* {{{ */
-{
- str_array_t *a = user_data;
- char **ptr;
-
- if ((entry == NULL) || (a == NULL))
- return (EINVAL);
-
- ptr = realloc (a->ptr, sizeof (*a->ptr) * (a->size + 1));
- if (ptr == NULL)
- return (ENOMEM);
- a->ptr = ptr;
- ptr = a->ptr + a->size;
-
- *ptr = strdup (entry);
- if (*ptr == NULL)
- return (ENOMEM);
-
- 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 */
-
-static int action_usage (void) /* {{{ */
-{
- printf ("Content-Type: text/plain\n\n");
-
- fputs ("Usage:\n"
- "\n"
- " Available actions:\n"
- "\n"
- " * hello\n"
- "\n", stdout);
-
- return (0);
-} /* }}} int action_usage */
-
-static int handle_request (void) /* {{{ */
-{
- const char *action;
-
- param_init ();
-
- action = param ("action");
- if (action == NULL)
- {
- return (action_usage ());
- }
- else if (strcmp ("list_graphs", action) == 0)
- {
- return (action_list_graphs ());
- }
- else if (strcmp ("hello", action) == 0)
- {
- return (action_hello ());
- }
- else
- {
- return (action_usage ());
- }
-} /* }}} int handle_request */
-
-static int run (void) /* {{{ */
-{
- while (FCGI_Accept() >= 0)
- {
- handle_request ();
- param_finish ();
- }
-
- return (0);
-} /* }}} int run */
-
-int main (int argc, char **argv) /* {{{ */
-{
- int status;
-
- argc = 0;
- argv = NULL;
-
- if (FCGX_IsCGI ())
- status = handle_request ();
- else
- status = run ();
-
- exit ((status == 0) ? EXIT_SUCCESS : EXIT_FAILURE);
-} /* }}} int main */
-
-/* vim: set sw=2 sts=2 et fdm=marker : */
diff --git a/test.fcgi.c b/test.fcgi.c
--- /dev/null
+++ b/test.fcgi.c
@@ -0,0 +1,176 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <errno.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <dirent.h>
+
+#include <fcgiapp.h>
+#include <fcgi_stdio.h>
+
+#include "common.h"
+#include "graph_list.h"
+#include "utils_params.h"
+
+#include "action_list_graphs.h"
+
+struct str_array_s
+{
+ char **ptr;
+ size_t size;
+};
+typedef struct str_array_s str_array_t;
+
+static str_array_t *array_alloc (void) /* {{{ */
+{
+ str_array_t *a;
+
+ a = malloc (sizeof (*a));
+ if (a == NULL)
+ return (NULL);
+
+ memset (a, 0, sizeof (*a));
+ a->ptr = NULL;
+ a->size = 0;
+
+ return (a);
+} /* }}} str_array_t *array_alloc */
+
+static void array_free (str_array_t *a) /* {{{ */
+{
+ if (a == NULL)
+ return;
+
+ free (a->ptr);
+ a->ptr = NULL;
+ a->size = 0;
+
+ free (a);
+} /* }}} void array_free */
+
+static int array_add (const char *entry, void *user_data) /* {{{ */
+{
+ str_array_t *a = user_data;
+ char **ptr;
+
+ if ((entry == NULL) || (a == NULL))
+ return (EINVAL);
+
+ ptr = realloc (a->ptr, sizeof (*a->ptr) * (a->size + 1));
+ if (ptr == NULL)
+ return (ENOMEM);
+ a->ptr = ptr;
+ ptr = a->ptr + a->size;
+
+ *ptr = strdup (entry);
+ if (*ptr == NULL)
+ return (ENOMEM);
+
+ 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 */
+
+static int action_usage (void) /* {{{ */
+{
+ printf ("Content-Type: text/plain\n\n");
+
+ fputs ("Usage:\n"
+ "\n"
+ " Available actions:\n"
+ "\n"
+ " * hello\n"
+ "\n", stdout);
+
+ return (0);
+} /* }}} int action_usage */
+
+static int handle_request (void) /* {{{ */
+{
+ const char *action;
+
+ param_init ();
+
+ action = param ("action");
+ if (action == NULL)
+ {
+ return (action_usage ());
+ }
+ else if (strcmp ("list_graphs", action) == 0)
+ {
+ return (action_list_graphs ());
+ }
+ else if (strcmp ("hello", action) == 0)
+ {
+ return (action_hello ());
+ }
+ else
+ {
+ return (action_usage ());
+ }
+} /* }}} int handle_request */
+
+static int run (void) /* {{{ */
+{
+ while (FCGI_Accept() >= 0)
+ {
+ handle_request ();
+ param_finish ();
+ }
+
+ return (0);
+} /* }}} int run */
+
+int main (int argc, char **argv) /* {{{ */
+{
+ int status;
+
+ argc = 0;
+ argv = NULL;
+
+ if (FCGX_IsCGI ())
+ status = handle_request ();
+ else
+ status = run ();
+
+ exit ((status == 0) ? EXIT_SUCCESS : EXIT_FAILURE);
+} /* }}} int main */
+
+/* vim: set sw=2 sts=2 et fdm=marker : */