/*
- * Copyright (C) 2015 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2015-2016 Andrea Zagli <azagli@libero.it>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
main (int argc, char *argv[])
{
ZakCgiMain *zakcgi_main;
- GHashTable *ht_env;
zakcgi_main = zak_cgi_main_new ();
- ht_env = zak_cgi_main_get_parameters (zakcgi_main, NULL);
- zak_cgi_main_redirect (zakcgi_main, (gchar *)g_value_get_string ((GValue *)(const gchar *)g_hash_table_lookup (ht_env, "redirectto")));
+ zak_cgi_main_redirect (zakcgi_main, (gchar *)g_value_get_string (zak_cgi_main_get_parameter (zakcgi_main, "redirectto")));
return 0;
}
int
main (int argc, char *argv[])
{
- gchar *env;
gchar *username;
GString *str;
GString *header;
zak_cgi_main_cookies_foreach (zakcgimain, ht_foreach, str);
g_string_append_printf (str, "</table>\n");
- ht = zak_cgi_main_get_env (zakcgimain);
- if (ht != NULL)
+ method = (gchar *)g_value_get_string (zak_cgi_main_get_env_field (zakcgimain, "REQUEST_METHOD"));
+ if (g_strcmp0 (method, "POST") == 0)
{
- method = g_value_get_string (g_hash_table_lookup (ht, "REQUEST_METHOD"));
- if (g_strcmp0 (method, "POST") == 0)
+ const gchar *content_type = g_getenv ("CONTENT_TYPE");
+ gchar **splitted = g_strsplit (content_type, ";", -1);
+ if (g_strv_length (splitted) == 2)
{
- const gchar *content_type = g_getenv ("CONTENT_TYPE");
- gchar **splitted = g_strsplit (content_type, ";", -1);
- if (g_strv_length (splitted) == 2)
+ if (zak_cgi_main_get_stdin_field (zakcgimain, "reset") != NULL)
+ {
+ g_warning ("new key: %s", zak_cgi_session_get_value_full (session, "NEW GROUP", "new key"));
+ g_warning ("new int: %d", zak_cgi_session_get_value_full_int (session, "NEW GROUP", "new int"));
+ g_warning ("new double: %f", zak_cgi_session_get_value_full_double (session, "NEW GROUP", "new double"));
+ g_warning ("new boolean: %d", zak_cgi_session_get_value_full_boolean (session, "NEW GROUP", "new boolean"));
+
+ zak_cgi_session_set_value (session, "user_name", NULL);
+ zak_cgi_session_set_value_full (session, "NEW GROUP", NULL, NULL);
+ }
+ else
{
- gchar **boundary = g_strsplit (splitted[1], "=", 2);
-
- env = zak_cgi_main_get_stdin (zakcgimain);
-
- ht_stdin = zak_cgi_main_parse_stdin (env, boundary[1]);
- if (g_hash_table_lookup (ht_stdin, "reset") != NULL)
- {
- g_warning ("new key: %s", zak_cgi_session_get_value_full (session, "NEW GROUP", "new key"));
- g_warning ("new int: %d", zak_cgi_session_get_value_full_int (session, "NEW GROUP", "new int"));
- g_warning ("new double: %f", zak_cgi_session_get_value_full_double (session, "NEW GROUP", "new double"));
- g_warning ("new boolean: %d", zak_cgi_session_get_value_full_boolean (session, "NEW GROUP", "new boolean"));
-
- zak_cgi_session_set_value (session, "user_name", NULL);
- zak_cgi_session_set_value_full (session, "NEW GROUP", NULL, NULL);
- }
- else
- {
- zak_cgi_session_set_value (session, "user_name", (gchar *)g_value_get_string ((GValue *)g_hash_table_lookup (ht_stdin, "user")));
- }
-
- g_free (env);
- g_strfreev (boundary);
+ zak_cgi_session_set_value (session, "user_name", (gchar *)g_value_get_string (zak_cgi_main_get_stdin_field (zakcgimain, "user")));
}
- g_strfreev (splitted);
}
+ g_strfreev (splitted);
}
username = zak_cgi_session_get_value (session, "user_name");
#include <url.h>
+void
+ht_foreach (gpointer key,
+ gpointer value,
+ gpointer user_data)
+{
+ GString *str = (GString *)user_data;
+
+ g_string_append_printf (str, "<tr><td>%s</td><td>%s</td></tr>\n",
+ (gchar *)key, g_value_get_string ((GValue *)value));
+}
+
void
hook (GMatchInfo *minfo, gpointer user_data)
{
int
main (int argc, char *argv[])
{
- gchar *env;
+ ZakCgiMain *zakcgimain;
+ GString *env;
ZakCgiUrl *url;
GString *str;
+ zakcgimain = zak_cgi_main_new ();
+
str = g_string_new ("<html>\n"
"<head><title>Url</title></head>\n"
"<body>\n"
"FROM INIT<br/><br/>\n");
- env = zak_cgi_main_dump_env (NULL);
+ env = g_string_new ("");
+ g_string_append_printf (env, "<table>\n");
+ zak_cgi_main_env_foreach (zakcgimain, ht_foreach, env);
+ g_string_append_printf (env, "</table>\n");
url = zak_cgi_url_new (NULL);
zak_cgi_url_dispatch (url);
- g_string_append_printf (str, "<hr/>%s</body>\n", env);
+ g_string_append_printf (str, "<hr/>%s</body>\n", env->str);
zak_cgi_main_out (NULL, str->str);
+
g_string_free (str, TRUE);
+ g_string_free (env, TRUE);
return 0;
}