From 6c9d9eb2496708975792d31d9f2e6a8ca63ba8be Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sat, 19 Nov 2016 09:44:41 +0100 Subject: [PATCH] Removed internal use of deprecated functions (closes #965). --- src/session.c | 4 ---- src/url.c | 4 +--- tests/env.c | 1 - tests/redirect.c | 6 ++---- tests/session.c | 49 ++++++++++++++++++------------------------------ tests/url.c | 25 +++++++++++++++++++++--- 6 files changed, 43 insertions(+), 46 deletions(-) diff --git a/src/session.c b/src/session.c index aa8d0bc..f2c62c4 100644 --- a/src/session.c +++ b/src/session.c @@ -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); diff --git a/src/url.c b/src/url.c index 2a181ad..a7d9eb9 100644 --- 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) { diff --git a/tests/env.c b/tests/env.c index c56c557..c2bf08f 100644 --- a/tests/env.c +++ b/tests/env.c @@ -132,7 +132,6 @@ main (int argc, char *argv[]) g_string_append_printf (str, "\n"); env = zak_cgi_main_get_stdin (zakcgimain); - zak_cgi_main_parse_stdin (env, NULL); /*g_message ("stdin: %s", env);*/ if (env != NULL) { diff --git a/tests/redirect.c b/tests/redirect.c index 2069d8b..3248602 100644 --- a/tests/redirect.c +++ b/tests/redirect.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 Andrea Zagli + * Copyright (C) 2015-2016 Andrea Zagli * * 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; } diff --git a/tests/session.c b/tests/session.c index d277583..77f795a 100644 --- a/tests/session.c +++ b/tests/session.c @@ -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, "\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"); diff --git a/tests/url.c b/tests/url.c index dbad74b..b8a5742 100644 --- a/tests/url.c +++ b/tests/url.c @@ -18,6 +18,17 @@ #include +void +ht_foreach (gpointer key, + gpointer value, + gpointer user_data) +{ + GString *str = (GString *)user_data; + + g_string_append_printf (str, "%s%s\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 ("\n" "Url\n" "\n" "FROM INIT

\n"); - env = zak_cgi_main_dump_env (NULL); + env = g_string_new (""); + g_string_append_printf (env, "\n"); + zak_cgi_main_env_foreach (zakcgimain, ht_foreach, env); + g_string_append_printf (env, "
\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, "
%s\n", env); + g_string_append_printf (str, "
%s\n", env->str); zak_cgi_main_out (NULL, str->str); + g_string_free (str, TRUE); + g_string_free (env, TRUE); return 0; } -- 2.49.0