From: Andrea Zagli <azagli@libero.it>
Date: Sat, 20 Jun 2015 10:39:19 +0000 (+0200)
Subject: Added function ZakMain::get_stdin.
X-Git-Tag: v0.0.1~33
X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=174a14ebd396c8311f47bdf974db44f27e1b5880;p=libzakcgi

Added function ZakMain::get_stdin.
---

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 <config.h>
 #endif
 
+#include <stdio.h>
+
 #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</body>", env);
 	g_free (env);
 
+	env = zak_cgi_main_get_stdin ();
+	if (env != NULL)
+		{
+			g_string_append_printf (str,
+			                        "<br/><hr/>\n"
+			                        "%s",
+			                        env);
+			g_free (env);
+		}
+
 	zak_cgi_main_out (str->str);
 	g_string_free (str, TRUE);