return ret;
}
-GHashTable
+static GHashTable
*_zak_cgi_main_get_cookies (ZakCgiMain *zakcgimain)
{
ZakCgiMainPrivate *priv;
}
/* end from libsoup */
-/**
- * zak_cgi_main_get_parameters:
- * @zakcgimain:
- * @query_string:
- *
- * Returns:
- */
-GHashTable
-*zak_cgi_main_get_parameters (ZakCgiMain *zakcgimain, const gchar *query_string)
+static GHashTable
+*_zak_cgi_main_get_parameters (ZakCgiMain *zakcgimain, const gchar *query_string)
{
ZakCgiMainPrivate *priv;
GHashTable *ht;
return ht;
}
+/**
+ * zak_cgi_main_get_parameters:
+ * @zakcgimain:
+ * @query_string:
+ *
+ * Returns:
+ */
+G_DEPRECATED_FOR (zak_cgi_main_get_parameter)
+GHashTable
+*zak_cgi_main_get_parameters (ZakCgiMain *zakcgimain, const gchar *query_string)
+{
+ return _zak_cgi_main_get_parameters (zakcgimain, query_string);
+}
+
+/**
+ * zak_cgi_main_get_param:
+ * @zakcgimain:
+ * @param:
+ *
+ * Returns:
+ */
+GValue
+*zak_cgi_main_get_param (ZakCgiMain *zakcgimain, const gchar *param)
+{
+ ZakCgiMainPrivate *priv;
+
+ GHashTable *ht;
+
+ GValue *ret;
+
+ g_return_val_if_fail (ZAK_CGI_IS_MAIN (zakcgimain), NULL);
+
+ ht = _zak_cgi_main_get_parameters (zakcgimain, NULL);
+
+ ret = g_hash_table_lookup (ht, param);
+
+ return ret;
+}
+
+/**
+ * zak_cgi_main_parameters_foreach:
+ * @zakcgimain:
+ * @func:
+ * @user_data:
+ *
+ */
+void
+zak_cgi_main_parameters_foreach (ZakCgiMain *zakcgimain, GHFunc func, gpointer user_data)
+{
+ ZakCgiMainPrivate *priv;
+
+ GHashTable *ht;
+
+ g_return_if_fail (ZAK_CGI_IS_MAIN (zakcgimain));
+ g_return_if_fail (func != NULL);
+
+ ht = _zak_cgi_main_get_parameters (zakcgimain, NULL);
+
+ g_hash_table_foreach (ht, func, user_data);
+}
+
/**
* zak_cgi_main_get_stdin:
* @zakcgimain:
if (g_strcmp0 (content_type, "") == 0
|| g_strcmp0 (splitted[0], "application/x-www-form-urlencoded") == 0)
{
- return zak_cgi_main_get_parameters (NULL, buf);
+ return _zak_cgi_main_get_parameters (NULL, buf);
}
else if (g_strcmp0 (splitted[0], "multipart/form-data") == 0)
{
#include <main.h>
+void
+ht_foreach (gpointer key,
+ gpointer value,
+ gpointer user_data)
+{
+ GString *str = (GString *)user_data;
+
+ if (G_VALUE_HOLDS ((GValue *)value, G_TYPE_BOXED))
+ {
+ guint i;
+ GPtrArray *ar = (GPtrArray *)g_value_get_boxed ((GValue *)value);
+ for (i = 0; i < ar->len; i++)
+ {
+ g_string_append_printf (str,
+ "<tr><td>%s[%d]</td><td>%s</td></tr>\n",
+ (gchar *)key,
+ i,
+ (gchar *)g_ptr_array_index (ar, i));
+ }
+ }
+ else
+ {
+ g_string_append_printf (str,
+ "<tr><td>%s</td><td>%s</td></tr>\n",
+ (gchar *)key,
+ (gchar *)g_value_get_string ((GValue *)value));
+ }
+}
+
int
main (int argc, char *argv[])
{
- GHashTable *ht_env;
GString *str;
- GHashTableIter iter;
- gpointer key;
- gpointer value;
-
ZakCgiMain *main;
main = zak_cgi_main_new ();
- ht_env = zak_cgi_main_get_parameters (main, NULL);
-
- /* test #960 */
- ht_env = zak_cgi_main_get_parameters (main, NULL);
-
str = g_string_new ("<html>\n"
"<head><title>Query string</title></head>\n"
"<body>\n");
- if (g_hash_table_size (ht_env) > 0)
- {
- g_string_append_printf (str, "<table>\n");
+ g_string_append_printf (str, "<table>\n");
- g_string_append_printf (str,
- "<tr><td>IS GET?</td><td>%s</td></tr>\n",
- zak_cgi_main_is_get (NULL) ? "TRUE" : "FALSE");
+ g_string_append_printf (str,
+ "<tr><td>IS GET?</td><td>%s</td></tr>\n",
+ zak_cgi_main_is_get (NULL) ? "TRUE" : "FALSE");
- g_string_append_printf (str,
- "<tr><td>IS POST?</td><td>%s</td></tr>\n",
- zak_cgi_main_is_post (NULL) ? "TRUE" : "FALSE");
+ g_string_append_printf (str,
+ "<tr><td>IS POST?</td><td>%s</td></tr>\n",
+ zak_cgi_main_is_post (NULL) ? "TRUE" : "FALSE");
- g_hash_table_iter_init (&iter, ht_env);
- while (g_hash_table_iter_next (&iter, &key, &value))
- {
- if (G_VALUE_HOLDS ((GValue *)value, G_TYPE_BOXED))
- {
- guint i;
- GPtrArray *ar = (GPtrArray *)g_value_get_boxed ((GValue *)value);
- for (i = 0; i < ar->len; i++)
- {
- g_string_append_printf (str,
- "<tr><td>%s[%d]</td><td>%s</td></tr>\n",
- (gchar *)key,
- i,
- (gchar *)g_ptr_array_index (ar, i));
- }
- }
- else
- {
- g_string_append_printf (str,
- "<tr><td>%s</td><td>%s</td></tr>\n",
- (gchar *)key,
- (gchar *)g_value_get_string ((GValue *)value));
- }
- }
+ zak_cgi_main_parameters_foreach (main, ht_foreach, str);
- g_string_append_printf (str, "</table>\n");
- }
+ g_string_append_printf (str, "</table>\n");
g_string_append_printf (str, "</body>\n");