]> saetta.ns0.it Git - libzakcgi/commitdiff
Added functions ZakCgiMain::isGet and ::isPost (closes #946).
authorAndrea Zagli <azagli@libero.it>
Sun, 26 Jul 2015 09:15:57 +0000 (11:15 +0200)
committerAndrea Zagli <azagli@libero.it>
Sun, 26 Jul 2015 09:15:57 +0000 (11:15 +0200)
src/main.c
src/main.h
tests/env.c
tests/querystring.c

index c92302c19dbdb5fc1f6d4340ae2f1bed4a6aff5e..89e21ac406a9f50a7722149ddcc42b926e51a263 100644 (file)
@@ -814,6 +814,48 @@ zak_cgi_main_redirect (const gchar *url)
                  13, 10);
 }
 
+gboolean
+zak_cgi_main_is_get (ZakCgiMain *zakcgimain)
+{
+       gboolean ret;
+
+       GHashTable *ht;
+
+       gchar *param;
+
+       ret = FALSE;
+
+       ht = zak_cgi_main_get_env (zakcgimain);
+       param = (gchar *)g_hash_table_lookup (ht, "REQUEST_METHOD");
+       if (param != NULL)
+               {
+                       ret = (g_strcmp0 (param, "GET") == 0);
+               }
+
+       return ret;
+}
+
+gboolean
+zak_cgi_main_is_post (ZakCgiMain *zakcgimain)
+{
+       gboolean ret;
+
+       GHashTable *ht;
+
+       gchar *param;
+
+       ret = FALSE;
+
+       ht = zak_cgi_main_get_env (zakcgimain);
+       param = (gchar *)g_hash_table_lookup (ht, "REQUEST_METHOD");
+       if (param != NULL)
+               {
+                       ret = (g_strcmp0 (param, "POST") == 0);
+               }
+
+       return ret;
+}
+
 /* PRIVATE */
 static void
 zak_cgi_main_set_property (GObject *object,
index c163009b545f51f5c8f162506833ec7386717bf5..05b2bc48c5150a53095d2af0475ce3827d2296cd 100644 (file)
@@ -93,6 +93,9 @@ GHashTable *zak_cgi_main_parse_stdin (const gchar *buf, const gchar *boundary);
 
 void zak_cgi_main_redirect (const gchar *url);
 
+gboolean zak_cgi_main_is_get (ZakCgiMain *zakcgimain);
+gboolean zak_cgi_main_is_post (ZakCgiMain *zakcgimain);
+
 
 G_END_DECLS
 
index be53b5bcfea17237b850f4a35908dd9454b17d99..a6048179d918da99623dcd018aa7bebcb760079e 100644 (file)
@@ -107,6 +107,14 @@ main (int argc, char *argv[])
                                {
                                        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 (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);
                                        while (g_hash_table_iter_next (&iter, &key, &value))
                                                {
index 8aa8f1f1ca8343f9a33b68e38b13b6a06662fb9d..e69873c0ad2a8a864c5d9563aa209ec7f5c5cf1d 100644 (file)
@@ -38,6 +38,14 @@ main (int argc, char *argv[])
                {
                        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 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))
                                {