From 174a14ebd396c8311f47bdf974db44f27e1b5880 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sat, 20 Jun 2015 12:39:19 +0200 Subject: [PATCH] Added function ZakMain::get_stdin. --- src/main.c | 32 ++++++++++++++++++++++++++++++++ src/main.h | 2 ++ tests/env.c | 10 ++++++++++ 3 files changed, 44 insertions(+) diff --git a/src/main.c b/src/main.c index dde008e..7732373 100644 --- a/src/main.c +++ b/src/main.c @@ -20,6 +20,8 @@ #include #endif +#include + #include "main.h" static void zak_cgi_main_class_init (ZakCgiMainClass *class); @@ -127,6 +129,11 @@ GHashTable return ht; } +/** + * zak_cgi_main_dump_env: + * + * Returns: an html table with each environment variables. + */ gchar *zak_cgi_main_dump_env () { @@ -195,6 +202,31 @@ GHashTable return ht; } +/** + * zak_cgi_main_get_stdin: + * + * Returns: the stdin. + */ +gchar +*zak_cgi_main_get_stdin (void) +{ + gchar *ret; + + guint l; + + ret = NULL; + + l = strtol (g_getenv ("CONTENT_LENGTH"), NULL, 10); + if (l > 0) + { + ret = g_malloc (l + 1); + fread (ret, l, 1, stdin); + ret[l] = '\0'; + } + + return ret; +} + /* PRIVATE */ static void zak_cgi_main_set_property (GObject *object, diff --git a/src/main.h b/src/main.h index 69a3c29..a672caa 100644 --- a/src/main.h +++ b/src/main.h @@ -58,6 +58,8 @@ gchar *zak_cgi_main_dump_env (); GHashTable *zak_cgi_main_get_parameters (void); +gchar *zak_cgi_main_get_stdin (void); + G_END_DECLS diff --git a/tests/env.c b/tests/env.c index 0a3e519..3706965 100644 --- a/tests/env.c +++ b/tests/env.c @@ -33,6 +33,16 @@ main (int argc, char *argv[]) g_string_append_printf (str, "%s\n", env); g_free (env); + env = zak_cgi_main_get_stdin (); + if (env != NULL) + { + g_string_append_printf (str, + "

\n" + "%s", + env); + g_free (env); + } + zak_cgi_main_out (str->str); g_string_free (str, TRUE); -- 2.49.0