From 51a51b90d41417a4df2fcf85b84937b96028674d Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sat, 27 Jun 2015 09:36:35 +0200 Subject: [PATCH] Added function ZakCgiMain::redirect. --- .gitignore | 1 + src/main.c | 9 +++++++++ src/main.h | 2 ++ tests/Makefile.am | 3 ++- tests/redirect.c | 34 ++++++++++++++++++++++++++++++++++ 5 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 tests/redirect.c diff --git a/.gitignore b/.gitignore index 0eae689..4696acc 100644 --- a/.gitignore +++ b/.gitignore @@ -52,3 +52,4 @@ Rules-quot *.csv tests/env tests/querystring +tests/redirect diff --git a/src/main.c b/src/main.c index 1816586..c860ced 100644 --- a/src/main.c +++ b/src/main.c @@ -471,6 +471,15 @@ GHashTable return ht; } +void +zak_cgi_main_redirect (const gchar *url) +{ + g_printf ("%s%s%c%c\n", + "Location: ", + url, + 13, 10); +} + /* PRIVATE */ static void zak_cgi_main_set_property (GObject *object, diff --git a/src/main.h b/src/main.h index 63e4c88..2e42f39 100644 --- a/src/main.h +++ b/src/main.h @@ -64,6 +64,8 @@ GHashTable *zak_cgi_main_parse_stdin (const gchar *buf, const gchar *boundary); GHashTable *zak_cgi_main_parse_stdin_bin (const gchar *buf, const gchar *boundary); +void zak_cgi_main_redirect (const gchar *url); + G_END_DECLS diff --git a/tests/Makefile.am b/tests/Makefile.am index dbdd3e9..704f382 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -10,4 +10,5 @@ LDADD = $(top_builddir)/src/libzakcgi.la noinst_PROGRAMS = \ env \ - querystring + querystring \ + redirect diff --git a/tests/redirect.c b/tests/redirect.c new file mode 100644 index 0000000..ca02c77 --- /dev/null +++ b/tests/redirect.c @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2015 Andrea Zagli + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include + +int +main (int argc, char *argv[]) +{ + GHashTable *ht_env; + + ht_env = zak_cgi_main_get_parameters (); + + zak_cgi_main_redirect ((const gchar *)g_hash_table_lookup (ht_env, "redirectto")); + + g_hash_table_destroy (ht_env); + + return 0; +} + -- 2.49.0