From: Andrea Zagli Date: Sat, 8 Aug 2015 15:33:17 +0000 (+0200) Subject: ZakCgiMain::get_env now returns GValue (closes #939). X-Git-Tag: v0.1.0~20 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=2f8a622928ced261d853cb4f51c5e50f5c1a96e0;p=libzakcgi ZakCgiMain::get_env now returns GValue (closes #939). --- diff --git a/src/main.c b/src/main.c index e3d7934..7d34c8c 100644 --- a/src/main.c +++ b/src/main.c @@ -131,7 +131,7 @@ zak_cgi_main_out (const gchar *header, const gchar *body) * zak_cgi_main_get_env: * @zakcgimain: * - * Returns: a #GHashTable with all the environment variables. + * Returns: a #GHashTable with all the environment variables as #GValue. */ GHashTable *zak_cgi_main_get_env (ZakCgiMain *zakcgimain) @@ -144,6 +144,8 @@ GHashTable guint i; gchar **envs; + GValue *gval; + if (zakcgimain != NULL) { priv = ZAK_CGI_MAIN_GET_PRIVATE (zakcgimain); @@ -164,7 +166,11 @@ GHashTable for (i = 0; i < l; i++) { envs = g_strsplit (environ[i], "=", 2); - g_hash_table_replace (ht, g_strdup (envs[0]), g_strdup (envs[1])); + + gval = (GValue *)g_new0 (GValue, 1); + g_value_init (gval, G_TYPE_STRING); + g_value_take_string (gval, g_strdup (envs[1])); + g_hash_table_replace (ht, g_strdup (envs[0]), gval); g_strfreev (envs); } @@ -201,7 +207,7 @@ gchar while (g_hash_table_iter_next (&iter, &key, &value)) { g_string_append_printf (str, "%s%s\n", - (gchar *)key, (gchar *)value); + (gchar *)key, g_value_get_string ((GValue *)value)); } g_string_append_printf (str, "\n"); diff --git a/tests/env.c b/tests/env.c index a604817..be407e4 100644 --- a/tests/env.c +++ b/tests/env.c @@ -73,12 +73,14 @@ gchar int main (int argc, char *argv[]) { + ZakCgiMain *zakcgimain; gchar *env; GString *str; GHashTable *ht; gchar *ret; - env = zak_cgi_main_dump_env (NULL); + zakcgimain = zak_cgi_main_new (); + env = zak_cgi_main_dump_env (zakcgimain); str = g_string_new ("\n" "Environment variables\n" @@ -87,7 +89,7 @@ main (int argc, char *argv[]) g_string_append_printf (str, "%s\n", env); g_free (env); - env = zak_cgi_main_get_stdin (NULL); + env = zak_cgi_main_get_stdin (zakcgimain); /*syslog (LOG_MAKEPRI(LOG_SYSLOG, LOG_DEBUG), "stdin: %s", env);*/ if (env != NULL) {