From bdc737707e5fc362288d36d0251c3e9ee46340b1 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sun, 25 Jun 2017 13:05:49 +0200 Subject: [PATCH] Added test to load cgi from ini. --- src/cgi_ini.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/cgi_ini.c b/src/cgi_ini.c index 9d0465d..bbe5d4d 100644 --- a/src/cgi_ini.c +++ b/src/cgi_ini.c @@ -37,6 +37,7 @@ main (int argc, char *argv[]) GValue *val; gchar *filename; + gint id; ZakFormCgiForm *form; @@ -61,7 +62,24 @@ main (int argc, char *argv[]) "
\n"); val = zak_cgi_main_get_parameter (zakcgimain, "filename"); - filename = (gchar *)g_value_get_string (val); + if (val != NULL) + { + filename = (gchar *)g_value_get_string (val); + } + else + { + filename = g_strdup (""); + } + + val = zak_cgi_main_get_parameter (zakcgimain, "id"); + if (val != NULL) + { + id = strtol (g_value_get_string (val), NULL, 10); + } + else + { + id = 0; + } form = zak_form_cgi_form_new (zakcgimain, "method", "post", @@ -72,7 +90,6 @@ main (int argc, char *argv[]) { if (zak_cgi_main_is_post (zakcgimain)) { - sleep(10); /* validating the form */ zak_form_cgi_form_bind (form); if (zak_form_form_is_valid (ZAK_FORM_FORM (form))) @@ -112,6 +129,17 @@ main (int argc, char *argv[]) else { zak_form_form_clear (ZAK_FORM_FORM (form)); + if (id > 0) + { + zak_form_element_set_value (zak_form_form_get_element_by_id (ZAK_FORM_FORM (form), "id"), g_strdup_printf ("%d", id)); + + provider = zak_form_ini_provider_new_from_file (filename); + if (provider != NULL) + { + zak_form_form_load (ZAK_FORM_FORM (form), ZAK_FORM_IPROVIDER (provider)); + g_object_unref (provider); + } + } g_string_append (str, zak_form_cgi_form_render (form)); } } -- 2.49.0