summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 4c1798b)
raw | patch | inline | side by side (parent: 4c1798b)
author | Florian Forster <ff@octo.it> | |
Sat, 19 Jun 2010 08:34:44 +0000 (10:34 +0200) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Sat, 19 Jun 2010 08:34:44 +0000 (10:34 +0200) |
src/Makefile.am | patch | blob | history | |
src/action_graph.c | patch | blob | history | |
src/action_list_graphs.c | patch | blob | history | |
src/graph.c | patch | blob | history | |
src/graph_instance.c | patch | blob | history | |
src/graph_list.c | patch | blob | history | |
src/main.c | patch | blob | history | |
src/utils_cgi.c | [new file with mode: 0644] | patch | blob |
src/utils_cgi.h | [new file with mode: 0644] | patch | blob |
src/utils_params.c | [deleted file] | patch | blob | history |
src/utils_params.h | [deleted file] | patch | blob | history |
diff --git a/src/Makefile.am b/src/Makefile.am
index 9b91a91578a88a836afff618e521b1c936443f18..ac11e9fe4eabed33ad46debbfa862edc02a3e8ee 100644 (file)
--- a/src/Makefile.am
+++ b/src/Makefile.am
graph_instance.c graph_instance.h \
graph_list.c graph_list.h \
utils_array.c utils_array.h \
- utils_params.c utils_params.h
+ utils_cgi.c utils_cgi.h
diff --git a/src/action_graph.c b/src/action_graph.c
index 0bb58563e0a9094d6acd2315527217319edd4ba3..45a9c94a5af05827f3e93e6efb42351bd292667a 100644 (file)
--- a/src/action_graph.c
+++ b/src/action_graph.c
#include "common.h"
#include "action_graph.h"
#include "graph_list.h"
-#include "utils_params.h"
+#include "utils_cgi.h"
#include "utils_array.h"
#include <fcgiapp.h>
index b6fc0394fe439d5e1bd0f9dcfcdf793869f41fc3..92d82d7e2e779092fa80c546cfceea20ba883634 100644 (file)
--- a/src/action_list_graphs.c
+++ b/src/action_list_graphs.c
#include "graph.h"
#include "graph_ident.h"
#include "graph_list.h"
-#include "utils_params.h"
+#include "utils_cgi.h"
#include <fcgiapp.h>
#include <fcgi_stdio.h>
diff --git a/src/graph.c b/src/graph.c
index 2809ebbe0b65f8a386e4dce4c8dfeffe40949a21..da4b5ea2a47733fa691d6ba2898cdfc086b22fb2 100644 (file)
--- a/src/graph.c
+++ b/src/graph.c
#include "graph_config.h"
#include "common.h"
#include "filesystem.h"
-#include "utils_params.h"
+#include "utils_cgi.h"
#include <fcgiapp.h>
#include <fcgi_stdio.h>
diff --git a/src/graph_instance.c b/src/graph_instance.c
index 90d175334b74ced9e79a5ff7f98f91e2b24fa9fb..45dcefb2519158b2e9bc1ca488d07617eb104817 100644 (file)
--- a/src/graph_instance.c
+++ b/src/graph_instance.c
#include "graph_ident.h"
#include "graph_list.h"
#include "common.h"
-#include "utils_params.h"
+#include "utils_cgi.h"
#include <fcgiapp.h>
#include <fcgi_stdio.h>
diff --git a/src/graph_list.c b/src/graph_list.c
index 3c8d375d1573eaa88ab7bc836ac06f0fd1ed20a9..f3e97385a4464850c2e2891f38084698a4c3900f 100644 (file)
--- a/src/graph_list.c
+++ b/src/graph_list.c
#include "graph_config.h"
#include "common.h"
#include "filesystem.h"
-#include "utils_params.h"
+#include "utils_cgi.h"
#include <fcgiapp.h>
#include <fcgi_stdio.h>
diff --git a/src/main.c b/src/main.c
index 097c55cfee70700ea48e6622686f2bacc445c36f..5c2b146f9245b9da1903bf29fcbee458b588b37b 100644 (file)
--- a/src/main.c
+++ b/src/main.c
#include "common.h"
#include "graph_list.h"
-#include "utils_params.h"
+#include "utils_cgi.h"
#include "action_graph.h"
#include "action_list_graphs.h"
diff --git a/src/utils_cgi.c b/src/utils_cgi.c
--- /dev/null
+++ b/src/utils_cgi.c
@@ -0,0 +1,291 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+#include <errno.h>
+#include <time.h>
+
+#include "utils_cgi.h"
+
+struct parameter_s
+{
+ char *key;
+ char *value;
+};
+typedef struct parameter_s parameter_t;
+
+static parameter_t *parameters = NULL;
+static size_t parameters_num = 0;
+static _Bool parameters_init = 0;
+
+static int parameter_add (const char *key, const char *value) /* {{{ */
+{
+ parameter_t *ptr;
+
+ if (value == NULL)
+ return (EINVAL);
+
+ ptr = realloc (parameters, sizeof (*parameters) * (parameters_num + 1));
+ if (ptr == NULL)
+ return (ENOMEM);
+ parameters = ptr;
+
+ ptr = parameters + parameters_num;
+ if (key == NULL)
+ {
+ ptr->key = NULL;
+ }
+ else
+ {
+ ptr->key = strdup (key);
+ if (ptr->key == NULL)
+ return (ENOMEM);
+ }
+
+ ptr->value = strdup (value);
+ if (ptr->value == NULL)
+ {
+ free (ptr->key);
+ return (ENOMEM);
+ }
+
+ parameters_num++;
+ return (0);
+} /* }}} int parameter_add */
+
+static char *parameter_lookup (const char *key) /* {{{ */
+{
+ size_t i;
+
+ for (i = 0; i < parameters_num; i++)
+ {
+ if ((key == NULL) && (parameters[i].key == NULL))
+ return (parameters[i].value);
+ else if ((key != NULL) && (parameters[i].key != NULL)
+ && (strcmp (key, parameters[i].key) == 0))
+ return (parameters[i].value);
+ }
+
+ return (NULL);
+} /* }}} char *parameter_lookup */
+
+static char *uri_unescape (char *string) /* {{{ */
+{
+ char *in;
+ char *out;
+
+ if (string == NULL)
+ return (NULL);
+
+ in = string;
+ out = string;
+
+ while (*in != 0)
+ {
+ if (*in == '+')
+ {
+ *out = ' ';
+ }
+ else if ((in[0] == '%')
+ && isxdigit ((int) in[1]) && isxdigit ((int) in[2]))
+ {
+ char tmpstr[3];
+ char *endptr;
+ long value;
+
+ tmpstr[0] = in[1];
+ tmpstr[1] = in[2];
+ tmpstr[2] = 0;
+
+ errno = 0;
+ endptr = NULL;
+ value = strtol (tmpstr, &endptr, /* base = */ 16);
+ if ((endptr == tmpstr) || (errno != 0))
+ {
+ *out = '?';
+ }
+ else
+ {
+ *out = (char) value;
+ }
+
+ in += 2;
+ }
+ else
+ {
+ *out = *in;
+ }
+
+ in++;
+ out++;
+ } /* while (*in != 0) */
+
+ *out = 0;
+ return (string);
+} /* }}} char *uri_unescape */
+
+static int parse_keyval (char *keyval) /* {{{ */
+{
+ char *key;
+ char *val;
+
+ val = strchr (keyval, '=');
+ if (val == NULL)
+ {
+ key = NULL;
+ val = keyval;
+ }
+ else
+ {
+ key = keyval;
+ *val = 0;
+ val++;
+ }
+
+ parameter_add (uri_unescape (key), uri_unescape (val));
+
+ return (0);
+} /* }}} int parse_keyval */
+
+static int parse_query_string (char *query_string) /* {{{ */
+{
+ char *dummy;
+ char *keyval;
+
+ if (query_string == NULL)
+ return (EINVAL);
+
+ dummy = query_string;
+ while ((keyval = strtok (dummy, ";&")) != NULL)
+ {
+ dummy = NULL;
+ parse_keyval (keyval);
+ }
+
+ return (0);
+} /* }}} int parse_query_string */
+
+int param_init (void) /* {{{ */
+{
+ const char *query_string;
+ char *copy;
+ int status;
+
+ if (parameters_init)
+ return (0);
+
+ query_string = getenv ("QUERY_STRING");
+ if (query_string == NULL)
+ return (ENOENT);
+
+ copy = strdup (query_string);
+ if (copy == NULL)
+ return (ENOMEM);
+
+ status = parse_query_string (copy);
+ free (copy);
+
+ parameters_init = 1;
+
+ return (status);
+} /* }}} int param_init */
+
+void param_finish (void) /* {{{ */
+{
+ size_t i;
+
+ if (!parameters_init)
+ return;
+
+ for (i = 0; i < parameters_num; i++)
+ {
+ free (parameters[i].key);
+ free (parameters[i].value);
+ }
+ free (parameters);
+
+ parameters = NULL;
+ parameters_num = 0;
+ parameters_init = 0;
+} /* }}} void param_finish */
+
+const char *param (const char *key) /* {{{ */
+{
+ param_init ();
+
+ return (parameter_lookup (key));
+} /* }}} const char *param */
+
+int uri_escape (char *dst, const char *src, size_t size) /* {{{ */
+{
+ size_t in;
+ size_t out;
+
+ in = 0;
+ out = 0;
+ while (42)
+ {
+ if (src[in] == 0)
+ {
+ dst[out] = 0;
+ return (0);
+ }
+ else if ((src[in] < 32)
+ || (src[in] == '&')
+ || (src[in] == ';')
+ || (((unsigned char) src[in]) >= 128))
+ {
+ char esc[4];
+
+ if ((size - out) < 4)
+ break;
+
+ snprintf (esc, sizeof (esc), "%%%02x", (unsigned int) src[in]);
+ dst[out] = esc[0];
+ dst[out+1] = esc[1];
+ dst[out+2] = esc[2];
+
+ out += 3;
+ in++;
+ }
+ else
+ {
+ dst[out] = src[in];
+ out++;
+ in++;
+ }
+ } /* while (42) */
+
+ return (0);
+} /* }}} int uri_escape */
+
+const char *script_name (void) /* {{{ */
+{
+ char *ret;
+
+ ret = getenv ("SCRIPT_NAME");
+ if (ret == NULL)
+ ret = "collection4.fcgi";
+
+ return (ret);
+} /* }}} char *script_name */
+
+int time_to_rfc1123 (time_t t, char *buffer, size_t buffer_size) /* {{{ */
+{
+ struct tm tm_tmp;
+ size_t status;
+
+ /* RFC 1123 *requires* the time to be GMT and the "GMT" timezone string.
+ * Apache will ignore the timezone if "localtime_r" and "%z" is used,
+ * resulting in weird behavior. */
+ if (gmtime_r (&t, &tm_tmp) == NULL)
+ return (errno);
+
+ status = strftime (buffer, buffer_size, "%a, %d %b %Y %T GMT", &tm_tmp);
+ if (status == 0)
+ return (errno);
+
+ return (0);
+} /* }}} int time_to_rfc1123 */
+
+/* vim: set sw=2 sts=2 et fdm=marker : */
diff --git a/src/utils_cgi.h b/src/utils_cgi.h
--- /dev/null
+++ b/src/utils_cgi.h
@@ -0,0 +1,17 @@
+#ifndef UTILS_CGI_H
+#define UTILS_CGI_H 1
+
+#include <time.h>
+
+int param_init (void);
+void param_finish (void);
+
+const char *param (const char *key);
+
+int uri_escape (char *dst, const char *src, size_t size);
+
+const char *script_name (void);
+
+int time_to_rfc1123 (time_t t, char *buffer, size_t buffer_size);
+
+#endif /* UTILS_CGI_H */
diff --git a/src/utils_params.c b/src/utils_params.c
--- a/src/utils_params.c
+++ /dev/null
@@ -1,291 +0,0 @@
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <ctype.h>
-#include <errno.h>
-#include <time.h>
-
-#include "utils_params.h"
-
-struct parameter_s
-{
- char *key;
- char *value;
-};
-typedef struct parameter_s parameter_t;
-
-static parameter_t *parameters = NULL;
-static size_t parameters_num = 0;
-static _Bool parameters_init = 0;
-
-static int parameter_add (const char *key, const char *value) /* {{{ */
-{
- parameter_t *ptr;
-
- if (value == NULL)
- return (EINVAL);
-
- ptr = realloc (parameters, sizeof (*parameters) * (parameters_num + 1));
- if (ptr == NULL)
- return (ENOMEM);
- parameters = ptr;
-
- ptr = parameters + parameters_num;
- if (key == NULL)
- {
- ptr->key = NULL;
- }
- else
- {
- ptr->key = strdup (key);
- if (ptr->key == NULL)
- return (ENOMEM);
- }
-
- ptr->value = strdup (value);
- if (ptr->value == NULL)
- {
- free (ptr->key);
- return (ENOMEM);
- }
-
- parameters_num++;
- return (0);
-} /* }}} int parameter_add */
-
-static char *parameter_lookup (const char *key) /* {{{ */
-{
- size_t i;
-
- for (i = 0; i < parameters_num; i++)
- {
- if ((key == NULL) && (parameters[i].key == NULL))
- return (parameters[i].value);
- else if ((key != NULL) && (parameters[i].key != NULL)
- && (strcmp (key, parameters[i].key) == 0))
- return (parameters[i].value);
- }
-
- return (NULL);
-} /* }}} char *parameter_lookup */
-
-static char *uri_unescape (char *string) /* {{{ */
-{
- char *in;
- char *out;
-
- if (string == NULL)
- return (NULL);
-
- in = string;
- out = string;
-
- while (*in != 0)
- {
- if (*in == '+')
- {
- *out = ' ';
- }
- else if ((in[0] == '%')
- && isxdigit ((int) in[1]) && isxdigit ((int) in[2]))
- {
- char tmpstr[3];
- char *endptr;
- long value;
-
- tmpstr[0] = in[1];
- tmpstr[1] = in[2];
- tmpstr[2] = 0;
-
- errno = 0;
- endptr = NULL;
- value = strtol (tmpstr, &endptr, /* base = */ 16);
- if ((endptr == tmpstr) || (errno != 0))
- {
- *out = '?';
- }
- else
- {
- *out = (char) value;
- }
-
- in += 2;
- }
- else
- {
- *out = *in;
- }
-
- in++;
- out++;
- } /* while (*in != 0) */
-
- *out = 0;
- return (string);
-} /* }}} char *uri_unescape */
-
-static int parse_keyval (char *keyval) /* {{{ */
-{
- char *key;
- char *val;
-
- val = strchr (keyval, '=');
- if (val == NULL)
- {
- key = NULL;
- val = keyval;
- }
- else
- {
- key = keyval;
- *val = 0;
- val++;
- }
-
- parameter_add (uri_unescape (key), uri_unescape (val));
-
- return (0);
-} /* }}} int parse_keyval */
-
-static int parse_query_string (char *query_string) /* {{{ */
-{
- char *dummy;
- char *keyval;
-
- if (query_string == NULL)
- return (EINVAL);
-
- dummy = query_string;
- while ((keyval = strtok (dummy, ";&")) != NULL)
- {
- dummy = NULL;
- parse_keyval (keyval);
- }
-
- return (0);
-} /* }}} int parse_query_string */
-
-int param_init (void) /* {{{ */
-{
- const char *query_string;
- char *copy;
- int status;
-
- if (parameters_init)
- return (0);
-
- query_string = getenv ("QUERY_STRING");
- if (query_string == NULL)
- return (ENOENT);
-
- copy = strdup (query_string);
- if (copy == NULL)
- return (ENOMEM);
-
- status = parse_query_string (copy);
- free (copy);
-
- parameters_init = 1;
-
- return (status);
-} /* }}} int param_init */
-
-void param_finish (void) /* {{{ */
-{
- size_t i;
-
- if (!parameters_init)
- return;
-
- for (i = 0; i < parameters_num; i++)
- {
- free (parameters[i].key);
- free (parameters[i].value);
- }
- free (parameters);
-
- parameters = NULL;
- parameters_num = 0;
- parameters_init = 0;
-} /* }}} void param_finish */
-
-const char *param (const char *key) /* {{{ */
-{
- param_init ();
-
- return (parameter_lookup (key));
-} /* }}} const char *param */
-
-int uri_escape (char *dst, const char *src, size_t size) /* {{{ */
-{
- size_t in;
- size_t out;
-
- in = 0;
- out = 0;
- while (42)
- {
- if (src[in] == 0)
- {
- dst[out] = 0;
- return (0);
- }
- else if ((src[in] < 32)
- || (src[in] == '&')
- || (src[in] == ';')
- || (((unsigned char) src[in]) >= 128))
- {
- char esc[4];
-
- if ((size - out) < 4)
- break;
-
- snprintf (esc, sizeof (esc), "%%%02x", (unsigned int) src[in]);
- dst[out] = esc[0];
- dst[out+1] = esc[1];
- dst[out+2] = esc[2];
-
- out += 3;
- in++;
- }
- else
- {
- dst[out] = src[in];
- out++;
- in++;
- }
- } /* while (42) */
-
- return (0);
-} /* }}} int uri_escape */
-
-const char *script_name (void) /* {{{ */
-{
- char *ret;
-
- ret = getenv ("SCRIPT_NAME");
- if (ret == NULL)
- ret = "collection4.fcgi";
-
- return (ret);
-} /* }}} char *script_name */
-
-int time_to_rfc1123 (time_t t, char *buffer, size_t buffer_size) /* {{{ */
-{
- struct tm tm_tmp;
- size_t status;
-
- /* RFC 1123 *requires* the time to be GMT and the "GMT" timezone string.
- * Apache will ignore the timezone if "localtime_r" and "%z" is used,
- * resulting in weird behavior. */
- if (gmtime_r (&t, &tm_tmp) == NULL)
- return (errno);
-
- status = strftime (buffer, buffer_size, "%a, %d %b %Y %T GMT", &tm_tmp);
- if (status == 0)
- return (errno);
-
- return (0);
-} /* }}} int time_to_rfc1123 */
-
-/* vim: set sw=2 sts=2 et fdm=marker : */
diff --git a/src/utils_params.h b/src/utils_params.h
--- a/src/utils_params.h
+++ /dev/null
@@ -1,17 +0,0 @@
-#ifndef UTILS_PARAMS_H
-#define UTILS_PARAMS_H 1
-
-#include <time.h>
-
-int param_init (void);
-void param_finish (void);
-
-const char *param (const char *key);
-
-int uri_escape (char *dst, const char *src, size_t size);
-
-const char *script_name (void);
-
-int time_to_rfc1123 (time_t t, char *buffer, size_t buffer_size);
-
-#endif /* UTILS_PARAMS_H */