priv = ZAK_CGI_MAIN_GET_PRIVATE (zakcgimain);
if (priv->stdin != NULL)
{
- return g_strdup (priv->stdin);
+ return priv->stdin;
}
}
G_DEFINE_BOXED_TYPE (ZakCgiFile, zak_cgi_file, zak_cgi_file_copy, zak_cgi_file_free)
-/**
- * zak_cgi_main_parse_stdin:
- *
- * Returns:
- */
-GHashTable
-*zak_cgi_main_parse_stdin (const gchar *buf, const gchar *boundary)
+static GHashTable
+*_zak_cgi_main_parse_stdin (const gchar *buf, const gchar *boundary)
{
GHashTable *ht;
return ht;
}
+/**
+ * zak_cgi_main_parse_stdin:
+ *
+ * Returns:
+ */
+GHashTable
+*zak_cgi_main_parse_stdin (const gchar *buf, const gchar *boundary)
+{
+ return _zak_cgi_main_parse_stdin (buf, boundary);
+}
+
+/**
+ * zak_cgi_main_get_stdin_field:
+ * @zakcgimain:
+ * @field:
+ *
+ * Returns:
+ */
+GValue
+*zak_cgi_main_get_stdin_field (ZakCgiMain *zakcgimain, const gchar *field)
+{
+ ZakCgiMainPrivate *priv;
+
+ GHashTable *ht;
+
+ GValue *ret;
+
+ g_return_val_if_fail (ZAK_CGI_IS_MAIN (zakcgimain), NULL);
+
+ ht = _zak_cgi_main_parse_stdin (zak_cgi_main_get_stdin (zakcgimain), NULL);
+
+ ret = g_hash_table_lookup (ht, field);
+
+ return ret;
+}
+
+/**
+ * zak_cgi_main_stdin_foreach:
+ * @zakcgimain:
+ * @func:
+ * @user_data:
+ *
+ */
+void
+zak_cgi_main_stdin_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_parse_stdin (zak_cgi_main_get_stdin (zakcgimain), NULL);
+
+ g_hash_table_foreach (ht, func, user_data);
+}
+
void
zak_cgi_main_redirect (ZakCgiMain *zakcgimain, const gchar *url)
{
g_string_free (_url, TRUE);
}
+/**
+ * zak_cgi_main_is_request_method:
+ * @zakcgimain:
+ * @method:
+ *
+ * Returns:
+ */
gboolean
zak_cgi_main_is_request_method (ZakCgiMain *zakcgimain, const gchar *method)
{
gboolean ret;
- GHashTable *ht;
-
- gchar *param;
+ GValue *gval;
+ const gchar *param;
ret = FALSE;
- ht = _zak_cgi_main_get_env (zakcgimain);
- param = (gchar *)g_hash_table_lookup (ht, "REQUEST_METHOD");
- if (param != NULL)
+ gval = zak_cgi_main_get_env_field (zakcgimain, "REQUEST_METHOD");
+ if (gval != NULL)
{
+ param = g_value_get_string (gval);
ret = (g_strcmp0 (param, method) == 0);
}
return ret;
}
+/**
+ * zak_cgi_main_is_get:
+ * @zakcgimain:
+ *
+ * Returns:
+ */
gboolean
zak_cgi_main_is_get (ZakCgiMain *zakcgimain)
{
- gboolean ret;
-
- ret = zak_cgi_main_is_request_method (zakcgimain, "GET");
-
- return ret;
+ return zak_cgi_main_is_request_method (zakcgimain, "GET");
}
+/**
+ * zak_cgi_main_is_post:
+ * @zakcgimain:
+ *
+ * Returns:
+ */
gboolean
zak_cgi_main_is_post (ZakCgiMain *zakcgimain)
{
- gboolean ret;
-
- ret = zak_cgi_main_is_request_method (zakcgimain, "POST");
-
- return ret;
+ return zak_cgi_main_is_request_method (zakcgimain, "POST");
}
/* PRIVATE */
(gchar *)key, g_value_get_string ((GValue *)value));
}
+void
+ht_foreach_stdin (gpointer key,
+ gpointer value,
+ gpointer user_data)
+{
+ gchar *ret;
+
+ GString *str = (GString *)user_data;
+
+ if (G_VALUE_HOLDS (value, G_TYPE_PTR_ARRAY))
+ {
+ guint i;
+ GPtrArray *ar = (GPtrArray *)g_value_get_boxed (value);
+ for (i = 0; i < ar->len; i++)
+ {
+ ret = get_value (g_ptr_array_index (ar, i));
+ g_string_append_printf (str,
+ "<tr><td>%s[%d]</td><td>%s</td></tr>\n",
+ (gchar *)key, i, ret);
+ g_free (ret);
+ }
+ }
+ else
+ {
+ ret = get_value ((GValue *)value);
+ g_string_append_printf (str,
+ "<tr><td>%s</td><td>%s</td></tr>\n",
+ (gchar *)key, ret);
+ g_free (ret);
+ }
+}
+
int
main (int argc, char *argv[])
{
/*syslog (LOG_MAKEPRI(LOG_SYSLOG, LOG_DEBUG), "stdin: %s", env);*/
if (env != NULL)
{
- GHashTableIter iter;
-
- gpointer key;
- gpointer value;
-
g_string_append_printf (str,
"<br/><hr/>\n"
"%s",
env);
- ht = zak_cgi_main_parse_stdin (env, NULL);
+ g_string_append_printf (str, "<br/><hr/>\n<table>\n");
- if (g_hash_table_size (ht) > 0)
- {
- g_string_append_printf (str, "<br/><hr/>\n<table>\n");
+ g_string_append_printf (str,
+ "<tr><td>IS GET?</td><td>%s</td></tr>\n",
+ zak_cgi_main_is_get (zakcgimain) ? "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 (zakcgimain) ? "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);
- while (g_hash_table_iter_next (&iter, &key, &value))
- {
- if (G_VALUE_HOLDS (value, G_TYPE_PTR_ARRAY))
- {
- guint i;
- GPtrArray *ar = (GPtrArray *)g_value_get_boxed (value);
- for (i = 0; i < ar->len; i++)
- {
- ret = get_value (g_ptr_array_index (ar, i));
- g_string_append_printf (str,
- "<tr><td>%s[%d]</td><td>%s</td></tr>\n",
- (gchar *)key, i, ret);
- g_free (ret);
- }
- }
- else
- {
- ret = get_value ((GValue *)value);
- g_string_append_printf (str,
- "<tr><td>%s</td><td>%s</td></tr>\n",
- (gchar *)key, ret);
- g_free (ret);
- }
- }
-
- g_string_append_printf (str, "</table>\n");
- }
+ zak_cgi_main_stdin_foreach (zakcgimain, ht_foreach_stdin, str);
- g_free (env);
+ g_string_append_printf (str, "</table>\n");
}
g_string_append (str, "\n</body>");