]> saetta.ns0.it Git - libzakcgi/commitdiff
Removed internal use of deprecated functions (closes #965).
authorAndrea Zagli <azagli@libero.it>
Sat, 19 Nov 2016 08:44:41 +0000 (09:44 +0100)
committerAndrea Zagli <azagli@libero.it>
Sat, 19 Nov 2016 08:44:41 +0000 (09:44 +0100)
src/session.c
src/url.c
tests/env.c
tests/redirect.c
tests/session.c
tests/url.c

index aa8d0bc3c89c31b0b61452d030552d4bb405423f..f2c62c4d953d20524ccdac296fcd16ae23ad269b 100644 (file)
@@ -221,8 +221,6 @@ gchar
 {
        gchar *ret;
 
-       GHashTable *ht_env;
-
        ZakCgiSessionPrivate *priv = ZAK_CGI_SESSION_GET_PRIVATE (session);
 
        if (priv->sid == NULL)
@@ -232,8 +230,6 @@ gchar
 
        if (priv->sid != NULL)
                {
-                       ht_env = zak_cgi_main_get_env (priv->zakcgimain);
-
                        ret = zak_cgi_main_set_cookie ("ZAKCGISID", priv->sid, NULL, NULL,
                                                                                   priv->base_uri != NULL ? priv->base_uri : (gchar *)g_value_get_string (zak_cgi_main_get_env_field (priv->zakcgimain, "CONTEXT_PREFIX")),
                                                                                   FALSE, FALSE);
index 2a181add7db879c8d033ffffd18e96acf8a7d32a..a7d9eb95eced83cfb1538f3de93b1dd82d3bcf0b 100644 (file)
--- a/src/url.c
+++ b/src/url.c
@@ -195,7 +195,6 @@ zak_cgi_url_dispatch (ZakCgiUrl *url)
 
        gint pos;
 
-       GHashTable *ht_env;
        GHashTableIter iter;
        gpointer key;
        gpointer value;
@@ -211,8 +210,7 @@ zak_cgi_url_dispatch (ZakCgiUrl *url)
 
        ZakCgiUrlPrivate *priv = ZAK_CGI_URL_GET_PRIVATE (url);
 
-       ht_env = zak_cgi_main_get_parameters (priv->zakcgimain, NULL);
-       _url = g_string_new (g_value_get_string (g_hash_table_lookup (ht_env, "_url")));
+       _url = g_string_new (g_value_get_string (zak_cgi_main_get_parameter (priv->zakcgimain, "_url")));
        if (_url != NULL
                && g_strcmp0 (_url->str, "") != 0)
                {
index c56c557a20f1f0fc252d4dcd5f5ad63ddd36308f..c2bf08f874450bc6b6de0f8fa3f27144aa61e0cc 100644 (file)
@@ -132,7 +132,6 @@ main (int argc, char *argv[])
        g_string_append_printf (str, "</table>\n");
 
        env = zak_cgi_main_get_stdin (zakcgimain);
-       zak_cgi_main_parse_stdin (env, NULL);
        /*g_message ("stdin: %s", env);*/
        if (env != NULL)
                {
index 2069d8b6f1fd6cee65707bfff5aad2ee734ab76b..3248602e238d6e68f69bc186ccf581a886e34518 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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
@@ -22,12 +22,10 @@ int
 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;
 }
index d2775832b217486c675d4b97e24aebe30b0b08fa..77f795aa8b25d4efdb11958304605280b0341abe 100644 (file)
@@ -33,7 +33,6 @@ ht_foreach (gpointer key,
 int
 main (int argc, char *argv[])
 {
-       gchar *env;
        gchar *username;
        GString *str;
        GString *header;
@@ -56,41 +55,29 @@ main (int argc, char *argv[])
        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");
index dbad74b47968d19d0174766a330b8cb4555c40ca..b8a57421defff5d3c5d94194036691579710427f 100644 (file)
 
 #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)
 {
@@ -63,16 +74,22 @@ hook_not_found (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);
 
@@ -84,10 +101,12 @@ main (int argc, char *argv[])
 
        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;
 }