From ed34839a279fbb0bcc799875b3fe81a3264631d8 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sat, 19 Nov 2016 11:22:17 +0100 Subject: [PATCH] Splitted ZakForm bind to a stand alone library (refs #1047). --- configure.ac | 4 +- libzakcgi.pc.in | 4 +- src/Makefile.am | 44 +---- src/form.c | 285 ----------------------------- src/form.h | 54 ------ src/formelement.c | 364 -------------------------------------- src/formelement.h | 61 ------- src/formelementcheck.c | 264 --------------------------- src/formelementcheck.h | 65 ------- src/formelementemail.c | 261 --------------------------- src/formelementemail.h | 65 ------- src/formelementhidden.c | 258 --------------------------- src/formelementhidden.h | 65 ------- src/formelementpassword.c | 261 --------------------------- src/formelementpassword.h | 65 ------- src/formelementselect.c | 318 --------------------------------- src/formelementselect.h | 67 ------- src/formelementstring.c | 227 ------------------------ src/formelementstring.h | 65 ------- src/formelementsubmit.c | 274 ---------------------------- src/formelementsubmit.h | 65 ------- src/formelementtext.c | 255 -------------------------- src/formelementtext.h | 65 ------- src/formelementtextarea.c | 255 -------------------------- src/formelementtextarea.h | 65 ------- src/libzakcgi.h | 1 + src/session.c | 72 +++----- src/session.h | 9 +- tests/Makefile.am | 5 +- tests/form.c | 135 -------------- tests/form_xml.c | 106 ----------- tests/form_xml.xml | 46 ----- 32 files changed, 39 insertions(+), 4111 deletions(-) delete mode 100644 src/form.c delete mode 100644 src/form.h delete mode 100644 src/formelement.c delete mode 100644 src/formelement.h delete mode 100644 src/formelementcheck.c delete mode 100644 src/formelementcheck.h delete mode 100644 src/formelementemail.c delete mode 100644 src/formelementemail.h delete mode 100644 src/formelementhidden.c delete mode 100644 src/formelementhidden.h delete mode 100644 src/formelementpassword.c delete mode 100644 src/formelementpassword.h delete mode 100644 src/formelementselect.c delete mode 100644 src/formelementselect.h delete mode 100644 src/formelementstring.c delete mode 100644 src/formelementstring.h delete mode 100644 src/formelementsubmit.c delete mode 100644 src/formelementsubmit.h delete mode 100644 src/formelementtext.c delete mode 100644 src/formelementtext.h delete mode 100644 src/formelementtextarea.c delete mode 100644 src/formelementtextarea.h delete mode 100644 tests/form.c delete mode 100644 tests/form_xml.c delete mode 100644 tests/form_xml.xml diff --git a/configure.ac b/configure.ac index a02bbbf..e8bb6e5 100644 --- a/configure.ac +++ b/configure.ac @@ -33,9 +33,7 @@ AC_PROG_RANLIB PKG_CHECK_MODULES(ZAKCGI, [glib-2.0 >= 2.36 gobject-2.0 >= 2.36 gio-2.0 >= 2.36 - gio-unix-2.0 >= 2.36 - libzakform >= 0.0.1 - libzakformini]) + gio-unix-2.0 >= 2.36]) AC_SUBST(ZAKCGI_CFLAGS) AC_SUBST(ZAKCGI_LIBS) diff --git a/libzakcgi.pc.in b/libzakcgi.pc.in index 5b736f5..8711cfb 100644 --- a/libzakcgi.pc.in +++ b/libzakcgi.pc.in @@ -4,8 +4,8 @@ libdir=@libdir@ includedir=@includedir@ Name: @PACKAGE_NAME@ -Description: Class for CGI. +Description: GObject class to implement CGI softwares. Version: @PACKAGE_VERSION@ -Requires: glib-2.0 >= 2.36 gobject-2.0 gio-2.0 gio-unix-2.0 libzakform libzakformini +Requires: glib-2.0 >= 2.36 gobject-2.0 gio-2.0 gio-unix-2.0 Libs: -L${libdir} -lzakcgi Cflags: -I${includedir} diff --git a/src/Makefile.am b/src/Makefile.am index 51b4a6a..6ce8ee2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,13 +1,3 @@ -if PLATFORM_WIN32 -libmodulesext = -0.dll -libmodulesdir = $(bindir) -else -libmodulesext = .so -libmodulesdir = $(libdir) -endif - -libzakformmodulesdir = `pkg-config --variable=modulesdir libzakform` - LIBS = $(ZAKCGI_LIBS) AM_CPPFLAGS = $(ZAKCGI_CFLAGS) \ @@ -16,18 +6,6 @@ AM_CPPFLAGS = $(ZAKCGI_CFLAGS) \ lib_LTLIBRARIES = libzakcgi.la libzakcgi_la_SOURCES = commons.c \ - commons.h \ - form.c \ - formelement.c \ - formelementcheck.c \ - formelementemail.c \ - formelementhidden.c \ - formelementpassword.c \ - formelementselect.c \ - formelementstring.c \ - formelementtext.c \ - formelementtextarea.c \ - formelementsubmit.c \ main.c \ session.c \ tag.c \ @@ -35,29 +13,11 @@ libzakcgi_la_SOURCES = commons.c \ libzakcgi_la_LDFLAGS = -no-undefined -libzakcgi_include_HEADERS = \ - libzakcgi.h \ - form.h \ - formelement.h \ - formelementcheck.h \ - formelementemail.h \ - formelementhidden.h \ - formelementpassword.h \ - formelementselect.h \ - formelementstring.h \ - formelementtext.h \ - formelementtextarea.h \ - formelementsubmit.h \ +libzakcgi_include_HEADERS = libzakcgi.h \ + commons.h \ main.h \ session.h \ tag.h \ url.h libzakcgi_includedir = $(includedir)/libzakcgi - -install-exec-hook: - cd $(libzakformmodulesdir) && \ - ln -s -f $(libmodulesdir)/libzakcgi$(libmodulesext) . - -uninstall-hook: - rm -f $(libzakformmodulesdir)/libzakcgi$(libmodulesext) diff --git a/src/form.c b/src/form.c deleted file mode 100644 index 03c584a..0000000 --- a/src/form.c +++ /dev/null @@ -1,285 +0,0 @@ -/* - * Copyright (C) 2015-2016 Andrea Zagli - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser 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 Lesser 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 - */ - -#ifdef HAVE_CONFIG_H - #include -#endif - -#include "commons.h" -#include "form.h" -#include "formelementstring.h" - -static void zak_cgi_form_class_init (ZakCgiFormClass *class); -static void zak_cgi_form_init (ZakCgiForm *zak_cgi_form); - -static void zak_cgi_form_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec); -static void zak_cgi_form_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec); - -static void zak_cgi_form_dispose (GObject *gobject); -static void zak_cgi_form_finalize (GObject *gobject); - -#define ZAK_CGI_FORM_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZAK_CGI_TYPE_FORM, ZakCgiFormPrivate)) - -typedef struct _ZakCgiFormPrivate ZakCgiFormPrivate; -struct _ZakCgiFormPrivate - { - ZakCgiMain *zakcgimain; - GHashTable *ht_attrs; - GPtrArray *ar_elems; - }; - -G_DEFINE_TYPE (ZakCgiForm, zak_cgi_form, ZAK_FORM_TYPE_FORM) - -static void -zak_cgi_form_class_init (ZakCgiFormClass *class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (class); - - object_class->set_property = zak_cgi_form_set_property; - object_class->get_property = zak_cgi_form_get_property; - object_class->dispose = zak_cgi_form_dispose; - object_class->finalize = zak_cgi_form_finalize; - - g_type_class_add_private (object_class, sizeof (ZakCgiFormPrivate)); -} - -static void -zak_cgi_form_init (ZakCgiForm *zak_cgi_form) -{ - ZakCgiFormPrivate *priv = ZAK_CGI_FORM_GET_PRIVATE (zak_cgi_form); - - priv->zakcgimain = NULL; - priv->ht_attrs = NULL; - priv->ar_elems = ZAK_FORM_FORM_CLASS (zak_cgi_form_parent_class)->get_elements (ZAK_FORM_FORM (zak_cgi_form)); -} - -/** - * zak_cgi_form_new: - * @zakcgimain: - * @...: - * - * Returns: the newly created #ZakCgiForm object. - */ -ZakCgiForm -*zak_cgi_form_new (ZakCgiMain *zakcgimain, ...) -{ - ZakCgiForm *zak_cgi_form; - ZakCgiFormPrivate *priv; - - va_list ap; - - zak_cgi_form = ZAK_CGI_FORM (g_object_new (zak_cgi_form_get_type (), NULL)); - - priv = ZAK_CGI_FORM_GET_PRIVATE (zak_cgi_form); - priv->zakcgimain = zakcgimain; - - va_start (ap, zakcgimain); - priv->ht_attrs = zak_cgi_commons_valist_to_ghashtable (ap); - - return zak_cgi_form; -} - -static guint -get_idx (ZakCgiForm *zakcgiform, const gchar *id) -{ - guint idx; - gchar *element_id; - - ZakCgiFormPrivate *priv; - - priv = ZAK_CGI_FORM_GET_PRIVATE (zakcgiform); - - for (idx = 0; idx < priv->ar_elems->len; idx++) - { - element_id = zak_cgi_form_element_get_id ((ZakCgiFormElement *)g_ptr_array_index (priv->ar_elems, idx)); - if (g_strcmp0 (element_id, id) == 0) - { - break; - } - g_free (element_id); - } - if (idx == priv->ar_elems->len) - { - idx = -1; - } - - return idx; -} - -/** - * zak_cgi_form_bind: - * @zakcgiform: - * - */ -void -zak_cgi_form_bind (ZakCgiForm *zakcgiform) -{ - guint i; - - GValue *gval; - - ZakCgiFormPrivate *priv; - - g_return_if_fail (ZAK_CGI_IS_FORM (zakcgiform)); - - priv = ZAK_CGI_FORM_GET_PRIVATE (zakcgiform); - - for (i = 0; i < priv->ar_elems->len; i++) - { - ZakCgiFormElement *element = (ZakCgiFormElement *)g_ptr_array_index (priv->ar_elems, i); - if (!ZAK_CGI_IS_FORM_ELEMENT_STRING (element)) - { - gval = zak_cgi_main_get_stdin_field (priv->zakcgimain, zak_cgi_form_element_get_id (element)); - if (gval != NULL) - { - zak_cgi_form_element_bind (element, g_value_get_string (gval)); - } - } - } -} - -/** - * zak_cgi_form_render_start: - * @zakcgiform: - * - * Returns: - */ -gchar -*zak_cgi_form_render_start (ZakCgiForm *zakcgiform) -{ - gchar *ret; - - GString *str; - - ZakCgiFormPrivate *priv; - - g_return_val_if_fail (ZAK_CGI_IS_FORM (zakcgiform), g_strdup ("")); - - priv = ZAK_CGI_FORM_GET_PRIVATE (zakcgiform); - - str = g_string_new ("ht_attrs); - g_string_append_printf (str, "%s>", ret); - g_free (ret); - - ret = g_strdup (str->str); - - return ret; -} - -/** - * zak_cgi_form_render: - * @zakcgiform: - * - * Returns: - */ -gchar -*zak_cgi_form_render (ZakCgiForm *zakcgiform) -{ - GString *str; - - guint i; - - gchar *tmp; - - ZakCgiFormPrivate *priv; - - priv = ZAK_CGI_FORM_GET_PRIVATE (zakcgiform); - - str = g_string_new (""); - - tmp = zak_cgi_form_render_start (zakcgiform); - g_string_append (str, tmp); - g_free (tmp); - - for (i = 0; i < priv->ar_elems->len; i++) - { - ZakCgiFormElement *element = (ZakCgiFormElement *)g_ptr_array_index (priv->ar_elems, i); - tmp = zak_cgi_form_element_render (element); - g_string_append_printf (str, "\n%s", tmp); - g_free (tmp); - } - - g_string_append (str, "\n"); - - return g_strdup (str->str); -} - -/* PRIVATE */ -static void -zak_cgi_form_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - ZakCgiForm *zak_cgi_form = (ZakCgiForm *)object; - ZakCgiFormPrivate *priv = ZAK_CGI_FORM_GET_PRIVATE (zak_cgi_form); - - switch (property_id) - { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -zak_cgi_form_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - ZakCgiForm *zak_cgi_form = (ZakCgiForm *)object; - ZakCgiFormPrivate *priv = ZAK_CGI_FORM_GET_PRIVATE (zak_cgi_form); - - switch (property_id) - { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -zak_cgi_form_dispose (GObject *gobject) -{ - ZakCgiForm *zak_cgi_form = (ZakCgiForm *)gobject; - ZakCgiFormPrivate *priv = ZAK_CGI_FORM_GET_PRIVATE (zak_cgi_form); - - - GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject)); - parent_class->dispose (gobject); -} - -static void -zak_cgi_form_finalize (GObject *gobject) -{ - ZakCgiForm *zak_cgi_form = (ZakCgiForm *)gobject; - ZakCgiFormPrivate *priv = ZAK_CGI_FORM_GET_PRIVATE (zak_cgi_form); - - - GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject)); - parent_class->finalize (gobject); -} diff --git a/src/form.h b/src/form.h deleted file mode 100644 index 01fb475..0000000 --- a/src/form.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2015 Andrea Zagli - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser 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 Lesser 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 - */ - -#ifndef __ZAK_CGI_FORM_H__ -#define __ZAK_CGI_FORM_H__ - - -#include - -#include - -#include "main.h" -#include "formelement.h" - - -G_BEGIN_DECLS - - -#define ZAK_CGI_TYPE_FORM zak_cgi_form_get_type () -G_DECLARE_DERIVABLE_TYPE (ZakCgiForm, zak_cgi_form, ZAK_CGI, FORM, ZakFormForm) - -struct _ZakCgiFormClass -{ - ZakFormFormClass parent_class; -}; - - -ZakCgiForm *zak_cgi_form_new (ZakCgiMain *zakcgimain, ...); - -void zak_cgi_form_bind (ZakCgiForm *zakcgiform); - -gchar *zak_cgi_form_render_start (ZakCgiForm *zakcgiform); -gchar *zak_cgi_form_render (ZakCgiForm *zakcgiform); - - -G_END_DECLS - - -#endif /* __ZAK_CGI_FORM_H__ */ diff --git a/src/formelement.c b/src/formelement.c deleted file mode 100644 index 6e079be..0000000 --- a/src/formelement.c +++ /dev/null @@ -1,364 +0,0 @@ -/* - * Copyright (C) 2015-2016 Andrea Zagli - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser 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 Lesser 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 - */ - -#ifdef HAVE_CONFIG_H - #include -#endif - -#include "commons.h" -#include "formelement.h" -#include "tag.h" - -enum -{ - PROP_0 -}; - -static void zak_cgi_form_element_class_init (ZakCgiFormElementClass *class); -static void zak_cgi_form_element_init (ZakCgiFormElement *zak_cgi_form_element); - -static void zak_cgi_form_element_construct (ZakCgiFormElement *element, - const gchar *id, - GHashTable *ht_attrs); - -static GHashTable *zak_cgi_form_element_get_ht_attrs (ZakCgiFormElement *element); - -static void zak_cgi_form_element_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec); -static void zak_cgi_form_element_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec); - -static void zak_cgi_form_element_dispose (GObject *gobject); -static void zak_cgi_form_element_finalize (GObject *gobject); - -static gchar *zak_cgi_form_element_get_value (ZakCgiFormElement *element); -static gboolean zak_cgi_form_element_set_value (ZakCgiFormElement *element, const gchar *value); -static void zak_cgi_form_element_xml_parsing (ZakFormElement *element, xmlNode *xmlnode); - -#define ZAK_CGI_FORM_ELEMENT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZAK_CGI_TYPE_FORM_ELEMENT, ZakCgiFormElementPrivate)) - -typedef struct _ZakCgiFormElementPrivate ZakCgiFormElementPrivate; -struct _ZakCgiFormElementPrivate - { - gchar *id; - GHashTable *ht_attrs; - GHashTable *ht_label_attrs; - gchar *value; - }; - -G_DEFINE_TYPE (ZakCgiFormElement, zak_cgi_form_element, ZAK_FORM_TYPE_ELEMENT) - -static void -zak_cgi_form_element_class_init (ZakCgiFormElementClass *class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (class); - ZakFormElementClass *elem_class = ZAK_FORM_ELEMENT_CLASS (class); - - object_class->set_property = zak_cgi_form_element_set_property; - object_class->get_property = zak_cgi_form_element_get_property; - object_class->dispose = zak_cgi_form_element_dispose; - object_class->finalize = zak_cgi_form_element_finalize; - - class->xml_parsing = zak_cgi_form_element_xml_parsing; - - elem_class->get_value = zak_cgi_form_element_get_value; - elem_class->set_value = zak_cgi_form_element_set_value; - - g_type_class_add_private (object_class, sizeof (ZakCgiFormElementPrivate)); - - class->construct = zak_cgi_form_element_construct; - class->get_ht_attrs = zak_cgi_form_element_get_ht_attrs; -} - -static void -zak_cgi_form_element_init (ZakCgiFormElement *zak_cgi_form_element) -{ - ZakCgiFormElementPrivate *priv = ZAK_CGI_FORM_ELEMENT_GET_PRIVATE (zak_cgi_form_element); - - priv->ht_attrs = NULL; - priv->ht_label_attrs = NULL; -} - -gchar -*zak_cgi_form_element_get_id (ZakCgiFormElement *element) -{ - ZakCgiFormElementPrivate *priv; - - priv = ZAK_CGI_FORM_ELEMENT_GET_PRIVATE (element); - - return g_strdup (priv->id); -} - -/** - * zak_cgi_form_element_set_label: - * @element: - * @label: - * @...: - * - */ -void -zak_cgi_form_element_set_label (ZakCgiFormElement *element, const gchar *label, ...) -{ - va_list ap; - - ZakCgiFormElementPrivate *priv; - - priv = ZAK_CGI_FORM_ELEMENT_GET_PRIVATE (element); - - if (priv->ht_label_attrs != NULL) - { - g_hash_table_destroy (priv->ht_label_attrs); - } - - va_start (ap, label); - priv->ht_label_attrs = zak_cgi_commons_valist_to_ghashtable (ap); - - g_hash_table_replace (priv->ht_label_attrs, "zak-cgi-content", g_strdup (label)); - g_hash_table_replace (priv->ht_label_attrs, "for", priv->id != NULL ? g_strdup (priv->id) : g_strdup ("")); - g_hash_table_replace (priv->ht_label_attrs, "class", "control-label"); - - zak_form_element_set_long_name (ZAK_FORM_ELEMENT (element), label); -} - -/** - * zak_cgi_form_element_bind: - * @element: - * @value: - * - */ -void -zak_cgi_form_element_bind (ZakCgiFormElement *element, const gchar *value) -{ - ZakCgiFormElementPrivate *priv; - - priv = ZAK_CGI_FORM_ELEMENT_GET_PRIVATE (element); - - priv->value = g_strdup (value); -} - -/** - * zak_cgi_form_element_render: - * @element: - * - */ -gchar -*zak_cgi_form_element_render (ZakCgiFormElement *element) -{ - GString *str; - gchar *ret; - GPtrArray *messages; - - ZakCgiFormElementPrivate *priv; - - priv = ZAK_CGI_FORM_ELEMENT_GET_PRIVATE (element); - - str = g_string_new ("
\n"); - - if (priv->ht_label_attrs != NULL) - { - gchar *lbl_id; - - if (g_strcmp0 (g_hash_table_lookup (priv->ht_label_attrs, "for"), "") == 0) - { - g_hash_table_replace (priv->ht_label_attrs, "for", g_strdup (priv->id)); - } - - lbl_id = g_strdup_printf ("lbl_%s", priv->id); - g_string_append (str, zak_cgi_tag_tag_ht ("label", lbl_id, priv->ht_label_attrs)); - g_free (lbl_id); - } - - if (ZAK_CGI_IS_FORM_ELEMENT (element) && ZAK_CGI_FORM_ELEMENT_GET_CLASS (element)->render != NULL) - { - gchar *attr_class; - - attr_class = g_hash_table_lookup (priv->ht_attrs, "class"); - if (attr_class != NULL) - { - if (g_strstr_len (attr_class, -1, "form-control") == NULL) - { - g_hash_table_insert (priv->ht_attrs, "class", g_strdup_printf ("%s form-control", attr_class)); - } - g_free (attr_class); - } - else - { - g_hash_table_replace (priv->ht_attrs, g_strdup ("class"), g_strdup ("form-control")); - } - - g_string_append (str, ZAK_CGI_FORM_ELEMENT_GET_CLASS (element)->render (element)); - } - - if (messages != NULL) - { - guint i; - - for (i = 0; i < messages->len; i++) - { - g_string_append_printf (str, - "\n%s", - priv->id, - i + 1, - (gchar *)g_ptr_array_index (messages, i)); - } - } - - g_string_append (str, "\n
\n"); - - ret = g_strdup (str->str); - g_string_free (str, TRUE); - - return ret; -} - -/* PRIVATE */ -static void -zak_cgi_form_element_construct (ZakCgiFormElement *element, - const gchar *id, - GHashTable *ht_attrs) -{ - ZakCgiFormElementPrivate *priv; - - g_return_if_fail (id != NULL); - - priv = ZAK_CGI_FORM_ELEMENT_GET_PRIVATE (element); - - priv->id = g_strdup (id); - - priv->ht_attrs = ht_attrs; - - if (g_hash_table_lookup (priv->ht_attrs, "name") == NULL) - { - g_hash_table_insert (priv->ht_attrs, "name", g_strdup (id)); - } - zak_form_element_set_name (ZAK_FORM_ELEMENT (element), g_hash_table_lookup (priv->ht_attrs, "name")); - - return; -} - -static GHashTable -*zak_cgi_form_element_get_ht_attrs (ZakCgiFormElement *element) -{ - ZakCgiFormElementPrivate *priv; - - priv = ZAK_CGI_FORM_ELEMENT_GET_PRIVATE (element); - - return priv->ht_attrs; -} - -static gchar -*zak_cgi_form_element_get_value (ZakCgiFormElement *element) -{ - gchar *ret; - - ZakCgiFormElementPrivate *priv; - - priv = ZAK_CGI_FORM_ELEMENT_GET_PRIVATE (element); - - ret = g_strdup (priv->value); - - return ret; -} - -static gboolean -zak_cgi_form_element_set_value (ZakCgiFormElement *element, const gchar *value) -{ - ZakCgiFormElementPrivate *priv; - - priv = ZAK_CGI_FORM_ELEMENT_GET_PRIVATE (element); - - priv->value = g_strdup (value); - - return TRUE; -} - -static void -zak_cgi_form_element_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - ZakCgiFormElement *zak_cgi_form_element = (ZakCgiFormElement *)object; - ZakCgiFormElementPrivate *priv = ZAK_CGI_FORM_ELEMENT_GET_PRIVATE (zak_cgi_form_element); - - switch (property_id) - { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -zak_cgi_form_element_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - ZakCgiFormElement *zak_cgi_form_element = (ZakCgiFormElement *)object; - ZakCgiFormElementPrivate *priv = ZAK_CGI_FORM_ELEMENT_GET_PRIVATE (zak_cgi_form_element); - - switch (property_id) - { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -zak_cgi_form_element_dispose (GObject *gobject) -{ - ZakCgiFormElement *zak_cgi_form_element = (ZakCgiFormElement *)gobject; - ZakCgiFormElementPrivate *priv = ZAK_CGI_FORM_ELEMENT_GET_PRIVATE (zak_cgi_form_element); - - - - GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject)); - parent_class->dispose (gobject); -} - -static void -zak_cgi_form_element_finalize (GObject *gobject) -{ - ZakCgiFormElement *zak_cgi_form_element = (ZakCgiFormElement *)gobject; - ZakCgiFormElementPrivate *priv = ZAK_CGI_FORM_ELEMENT_GET_PRIVATE (zak_cgi_form_element); - - - - GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject)); - parent_class->finalize (gobject); -} - -static void -zak_cgi_form_element_xml_parsing (ZakFormElement *element, xmlNode *xmlnode) -{ - ZAK_FORM_ELEMENT_GET_CLASS (element)->xml_parsing (element, xmlnode); -} diff --git a/src/formelement.h b/src/formelement.h deleted file mode 100644 index 50d5822..0000000 --- a/src/formelement.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (C) 2015-2016 Andrea Zagli - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser 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 Lesser 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 - */ - -#ifndef __ZAK_CGI_FORM_ELEMENT_H__ -#define __ZAK_CGI_FORM_ELEMENT_H__ - - -#include - -#include - -#include "main.h" - - -G_BEGIN_DECLS - - -#define ZAK_CGI_TYPE_FORM_ELEMENT zak_cgi_form_element_get_type () -G_DECLARE_DERIVABLE_TYPE (ZakCgiFormElement, zak_cgi_form_element, ZAK_CGI, FORM_ELEMENT, ZakFormElement) - -struct _ZakCgiFormElementClass - { - ZakFormElementClass parent_class; - - void (*construct) (ZakCgiFormElement *element, const gchar *id, GHashTable *ht_attrs); - GHashTable *(*get_ht_attrs) (ZakCgiFormElement *element); - - void (*xml_parsing) (ZakFormElement *element, xmlNode *xmlnode); - - gchar *(*render) (ZakCgiFormElement *element); - }; - - -gchar *zak_cgi_form_element_get_id (ZakCgiFormElement *element); - -void zak_cgi_form_element_set_label (ZakCgiFormElement *element, const gchar *label, ...); - -void zak_cgi_form_element_bind (ZakCgiFormElement *element, const gchar *value); - -gchar *zak_cgi_form_element_render (ZakCgiFormElement *element); - - -G_END_DECLS - - -#endif /* __ZAK_CGI_FORM_ELEMENT_H__ */ diff --git a/src/formelementcheck.c b/src/formelementcheck.c deleted file mode 100644 index d3b62fc..0000000 --- a/src/formelementcheck.c +++ /dev/null @@ -1,264 +0,0 @@ -/* - * Copyright (C) 2015-2016 Andrea Zagli - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser 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 Lesser 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 - */ - -#ifdef HAVE_CONFIG_H - #include -#endif - -#include - -#include "commons.h" -#include "tag.h" -#include "formelementcheck.h" - -static void zak_cgi_form_element_check_class_init (ZakCgiFormElementCheckClass *class); -static void zak_cgi_form_element_check_init (ZakCgiFormElementCheck *zak_cgi_form_element_check); - -static gchar *zak_cgi_form_element_check_render (ZakCgiFormElement *element); - -static void zak_cgi_form_element_check_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec); -static void zak_cgi_form_element_check_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec); - -static void zak_cgi_form_element_check_dispose (GObject *gobject); -static void zak_cgi_form_element_check_finalize (GObject *gobject); - -#define ZAK_CGI_FORM_ELEMENT_CHECK_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZAK_CGI_TYPE_FORM_ELEMENT_CHECK, ZakCgiFormElementCheckPrivate)) - -typedef struct _ZakCgiFormElementCheckPrivate ZakCgiFormElementCheckPrivate; -struct _ZakCgiFormElementCheckPrivate - { - gpointer empty; - }; - -G_DEFINE_TYPE (ZakCgiFormElementCheck, zak_cgi_form_element_check, ZAK_CGI_TYPE_FORM_ELEMENT) - -static void -zak_cgi_form_element_check_class_init (ZakCgiFormElementCheckClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - ZakCgiFormElementClass *elem_class = ZAK_CGI_FORM_ELEMENT_CLASS (klass); - - object_class->set_property = zak_cgi_form_element_check_set_property; - object_class->get_property = zak_cgi_form_element_check_get_property; - object_class->dispose = zak_cgi_form_element_check_dispose; - object_class->finalize = zak_cgi_form_element_check_finalize; - - elem_class->render = zak_cgi_form_element_check_render; - - g_type_class_add_private (object_class, sizeof (ZakCgiFormElementCheckPrivate)); -} - -static void -zak_cgi_form_element_check_init (ZakCgiFormElementCheck *zak_cgi_form_element_check) -{ - ZakCgiFormElementCheckPrivate *priv = ZAK_CGI_FORM_ELEMENT_CHECK_GET_PRIVATE (zak_cgi_form_element_check); - -} - -/** - * zak_cgi_form_element_check_new: - * - * Returns: the newly created #ZakCgiFormElementCheck object. - */ -ZakCgiFormElement -*zak_cgi_form_element_check_new () -{ - ZakCgiFormElementCheck *zak_cgi_form_element_check; - - zak_cgi_form_element_check = ZAK_CGI_FORM_ELEMENT_CHECK (g_object_new (zak_cgi_form_element_check_get_type (), NULL)); - - return ZAK_CGI_FORM_ELEMENT (zak_cgi_form_element_check); -} - -/** - * zak_cgi_form_element_check_new_attrs: - * @id: - * @...: - * - * Returns: the newly created #ZakCgiFormElementCheck object. - */ -ZakCgiFormElement -*zak_cgi_form_element_check_new_attrs (const gchar *id, - ...) -{ - va_list ap; - - GHashTable *ht_attrs; - - ZakCgiFormElement *zak_cgi_form_element_check; - - zak_cgi_form_element_check = zak_cgi_form_element_check_new (); - - va_start (ap, id); - - ht_attrs = zak_cgi_commons_valist_to_ghashtable (ap); - g_hash_table_replace (ht_attrs, "type", "checkbox"); - - ZAK_CGI_FORM_ELEMENT_CLASS (zak_cgi_form_element_check_parent_class)->construct (zak_cgi_form_element_check, - id, - ht_attrs); - - return zak_cgi_form_element_check; -} - -gboolean -zak_cgi_form_element_check_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode) -{ - gboolean ret; - - gchar *id; - - GHashTable *ht_attrs; - - xmlNode *cur; - - id = NULL; - - ZAK_CGI_FORM_ELEMENT_CLASS (zak_cgi_form_element_check_parent_class)->xml_parsing (element, xmlnode); - - ht_attrs = g_hash_table_new (g_str_hash, g_str_equal); - g_hash_table_replace (ht_attrs, "type", "checkbox"); - - cur = xmlnode->children; - while (cur != NULL) - { - if (xmlStrcmp (cur->name, (const xmlChar *)"id") == 0) - { - id = (gchar *)xmlNodeGetContent (cur); - } - else if (xmlStrcmp (cur->name, (const xmlChar *)"label") == 0) - { - zak_cgi_form_element_set_label (ZAK_CGI_FORM_ELEMENT (element), (gchar *)xmlNodeGetContent (cur), NULL); - } - else if (xmlStrcmp (cur->name, (const xmlChar *)"text") == 0) - { - } - else - { - g_hash_table_replace (ht_attrs, g_strdup (cur->name), (gchar *)xmlNodeGetContent (cur)); - } - - cur = cur->next; - } - - if (id != NULL) - { - ZAK_CGI_FORM_ELEMENT_CLASS (zak_cgi_form_element_check_parent_class)->construct (ZAK_CGI_FORM_ELEMENT (element), - id, - ht_attrs); - ret = TRUE; - } - else - { - ret = FALSE; - } - - return ret; -} - -static gchar -*zak_cgi_form_element_check_render (ZakCgiFormElement *element) -{ - gchar *ret; - - GHashTable *ht_attrs; - - gchar *value; - - ZakCgiFormElementClass *klass; - - klass = (ZakCgiFormElementClass *)g_type_class_peek_parent (ZAK_CGI_FORM_ELEMENT_CHECK_GET_CLASS (ZAK_CGI_FORM_ELEMENT_CHECK (element))); - - ht_attrs = klass->get_ht_attrs (element); - - value = zak_form_element_get_value (ZAK_FORM_ELEMENT (element)); - if (value != NULL - && zak_utils_string_to_boolean (value)) - { - g_hash_table_insert (ht_attrs, (gpointer)"checked", (gpointer)"checked"); - } - - ret = zak_cgi_tag_tag_ht ("input", zak_cgi_form_element_get_id (element), ht_attrs); - - return ret; -} - -/* PRIVATE */ -static void -zak_cgi_form_element_check_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - ZakCgiFormElementCheck *zak_cgi_form_element_check = (ZakCgiFormElementCheck *)object; - ZakCgiFormElementCheckPrivate *priv = ZAK_CGI_FORM_ELEMENT_CHECK_GET_PRIVATE (zak_cgi_form_element_check); - - switch (property_id) - { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -zak_cgi_form_element_check_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - ZakCgiFormElementCheck *zak_cgi_form_element_check = (ZakCgiFormElementCheck *)object; - ZakCgiFormElementCheckPrivate *priv = ZAK_CGI_FORM_ELEMENT_CHECK_GET_PRIVATE (zak_cgi_form_element_check); - - switch (property_id) - { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -zak_cgi_form_element_check_dispose (GObject *gobject) -{ - ZakCgiFormElementCheck *zak_cgi_form_element_check = (ZakCgiFormElementCheck *)gobject; - ZakCgiFormElementCheckPrivate *priv = ZAK_CGI_FORM_ELEMENT_CHECK_GET_PRIVATE (zak_cgi_form_element_check); - - - - GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject)); - parent_class->dispose (gobject); -} - -static void -zak_cgi_form_element_check_finalize (GObject *gobject) -{ - ZakCgiFormElementCheck *zak_cgi_form_element_check = (ZakCgiFormElementCheck *)gobject; - ZakCgiFormElementCheckPrivate *priv = ZAK_CGI_FORM_ELEMENT_CHECK_GET_PRIVATE (zak_cgi_form_element_check); - - - - GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject)); - parent_class->finalize (gobject); -} diff --git a/src/formelementcheck.h b/src/formelementcheck.h deleted file mode 100644 index 6fb9ede..0000000 --- a/src/formelementcheck.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) 2015 Andrea Zagli - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser 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 Lesser 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 - */ - -#ifndef __ZAK_CGI_FORM_ELEMENT_CHECK_H__ -#define __ZAK_CGI_FORM_ELEMENT_CHECK_H__ - - -#include - -#include - -#include "formelement.h" - - -G_BEGIN_DECLS - - -#define ZAK_CGI_TYPE_FORM_ELEMENT_CHECK (zak_cgi_form_element_check_get_type ()) -#define ZAK_CGI_FORM_ELEMENT_CHECK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ZAK_CGI_TYPE_FORM_ELEMENT_CHECK, ZakCgiFormElementCheck)) -#define ZAK_CGI_FORM_ELEMENT_CHECK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ZAK_CGI_TYPE_FORM_ELEMENT_CHECK, ZakCgiFormElementCheckClass)) -#define ZAK_CGI_IS_FORM_ELEMENT_CHECK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ZAK_CGI_TYPE_FORM_ELEMENT_CHECK)) -#define ZAK_CGI_IS_FORM_ELEMENT_CHECK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ZAK_CGI_TYPE_FORM_ELEMENT_CHECK)) -#define ZAK_CGI_FORM_ELEMENT_CHECK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ZAK_CGI_TYPE_FORM_ELEMENT_CHECK, ZakCgiFormElementCheckClass)) - -typedef struct _ZakCgiFormElementCheck ZakCgiFormElementCheck; -typedef struct _ZakCgiFormElementCheckClass ZakCgiFormElementCheckClass; - -struct _ZakCgiFormElementCheck - { - ZakCgiFormElement parent_instance; - }; - -struct _ZakCgiFormElementCheckClass - { - ZakCgiFormElementClass parent_class; - }; - - -GType zak_cgi_form_element_check_get_type (void); - -ZakCgiFormElement *zak_cgi_form_element_check_new (void); -ZakCgiFormElement *zak_cgi_form_element_check_new_attrs (const gchar *id, ...); - -gboolean zak_cgi_form_element_check_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode); - - -G_END_DECLS - - -#endif /* __ZAK_CGI_FORM_ELEMENT_CHECK_H__ */ diff --git a/src/formelementemail.c b/src/formelementemail.c deleted file mode 100644 index 7916e11..0000000 --- a/src/formelementemail.c +++ /dev/null @@ -1,261 +0,0 @@ -/* - * Copyright (C) 2016 Andrea Zagli - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser 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 Lesser 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 - */ - -#ifdef HAVE_CONFIG_H - #include -#endif - -#include "commons.h" -#include "tag.h" -#include "formelementemail.h" - -static void zak_cgi_form_element_email_class_init (ZakCgiFormElementEmailClass *class); -static void zak_cgi_form_element_email_init (ZakCgiFormElementEmail *zak_cgi_form_element_email); - -static gchar *zak_cgi_form_element_email_render (ZakCgiFormElement *element); - -static void zak_cgi_form_element_email_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec); -static void zak_cgi_form_element_email_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec); - -static void zak_cgi_form_element_email_dispose (GObject *gobject); -static void zak_cgi_form_element_email_finalize (GObject *gobject); - -#define ZAK_CGI_FORM_ELEMENT_EMAIL_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZAK_CGI_TYPE_FORM_ELEMENT_EMAIL, ZakCgiFormElementEmailPrivate)) - -typedef struct _ZakCgiFormElementEmailPrivate ZakCgiFormElementEmailPrivate; -struct _ZakCgiFormElementEmailPrivate - { - gpointer empty; - }; - -G_DEFINE_TYPE (ZakCgiFormElementEmail, zak_cgi_form_element_email, ZAK_CGI_TYPE_FORM_ELEMENT) - -static void -zak_cgi_form_element_email_class_init (ZakCgiFormElementEmailClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - ZakCgiFormElementClass *elem_class = ZAK_CGI_FORM_ELEMENT_CLASS (klass); - - object_class->set_property = zak_cgi_form_element_email_set_property; - object_class->get_property = zak_cgi_form_element_email_get_property; - object_class->dispose = zak_cgi_form_element_email_dispose; - object_class->finalize = zak_cgi_form_element_email_finalize; - - elem_class->render = zak_cgi_form_element_email_render; - - g_type_class_add_private (object_class, sizeof (ZakCgiFormElementEmailPrivate)); -} - -static void -zak_cgi_form_element_email_init (ZakCgiFormElementEmail *zak_cgi_form_element_email) -{ - ZakCgiFormElementEmailPrivate *priv = ZAK_CGI_FORM_ELEMENT_EMAIL_GET_PRIVATE (zak_cgi_form_element_email); - -} - -/** - * zak_cgi_form_element_email_new: - * - * Returns: the newly created #ZakCgiFormElementEmail object. - */ -ZakCgiFormElement -*zak_cgi_form_element_email_new () -{ - ZakCgiFormElementEmail *zak_cgi_form_element_email; - - zak_cgi_form_element_email = ZAK_CGI_FORM_ELEMENT_EMAIL (g_object_new (zak_cgi_form_element_email_get_type (), NULL)); - - return ZAK_CGI_FORM_ELEMENT (zak_cgi_form_element_email); -} - -/** - * zak_cgi_form_element_email_new_attrs: - * @id: - * @...: - * - * Returns: the newly created #ZakCgiFormElementEmail object. - */ -ZakCgiFormElement -*zak_cgi_form_element_email_new_attrs (const gchar *id, - ...) -{ - va_list ap; - - GHashTable *ht_attrs; - - ZakCgiFormElement *zak_cgi_form_element_email; - - zak_cgi_form_element_email = zak_cgi_form_element_email_new (); - - va_start (ap, id); - - ht_attrs = zak_cgi_commons_valist_to_ghashtable (ap); - g_hash_table_replace (ht_attrs, "type", "email"); - - ZAK_CGI_FORM_ELEMENT_CLASS (zak_cgi_form_element_email_parent_class)->construct (zak_cgi_form_element_email, - id, - ht_attrs); - - return zak_cgi_form_element_email; -} - -gboolean -zak_cgi_form_element_email_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode) -{ - gboolean ret; - - gchar *id; - - GHashTable *ht_attrs; - - xmlNode *cur; - - id = NULL; - - ZAK_CGI_FORM_ELEMENT_CLASS (zak_cgi_form_element_email_parent_class)->xml_parsing (element, xmlnode); - - ht_attrs = g_hash_table_new (g_str_hash, g_str_equal); - g_hash_table_replace (ht_attrs, "type", "email"); - - cur = xmlnode->children; - while (cur != NULL) - { - if (xmlStrcmp (cur->name, (const xmlChar *)"id") == 0) - { - id = (gchar *)xmlNodeGetContent (cur); - } - else if (xmlStrcmp (cur->name, (const xmlChar *)"label") == 0) - { - zak_cgi_form_element_set_label (ZAK_CGI_FORM_ELEMENT (element), (gchar *)xmlNodeGetContent (cur), NULL); - } - else if (xmlStrcmp (cur->name, (const xmlChar *)"text") == 0) - { - } - else - { - g_hash_table_replace (ht_attrs, g_strdup (cur->name), (gchar *)xmlNodeGetContent (cur)); - } - - cur = cur->next; - } - - if (id != NULL) - { - ZAK_CGI_FORM_ELEMENT_CLASS (zak_cgi_form_element_email_parent_class)->construct (ZAK_CGI_FORM_ELEMENT (element), - id, - ht_attrs); - ret = TRUE; - } - else - { - ret = FALSE; - } - - return ret; -} - -static gchar -*zak_cgi_form_element_email_render (ZakCgiFormElement *element) -{ - gchar *ret; - - GHashTable *ht_attrs; - - gchar *value; - - ZakCgiFormElementClass *klass; - - klass = (ZakCgiFormElementClass *)g_type_class_peek_parent (ZAK_CGI_FORM_ELEMENT_EMAIL_GET_CLASS (ZAK_CGI_FORM_ELEMENT_EMAIL (element))); - - ht_attrs = klass->get_ht_attrs (element); - - value = zak_form_element_get_value (ZAK_FORM_ELEMENT (element)); - if (value != NULL) - { - g_hash_table_insert (ht_attrs, (gpointer)"value", (gpointer)g_strdup (value)); - } - - ret = zak_cgi_tag_tag_ht ("input", zak_cgi_form_element_get_id (element), ht_attrs); - - return ret; -} - -/* PRIVATE */ -static void -zak_cgi_form_element_email_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - ZakCgiFormElementEmail *zak_cgi_form_element_email = (ZakCgiFormElementEmail *)object; - ZakCgiFormElementEmailPrivate *priv = ZAK_CGI_FORM_ELEMENT_EMAIL_GET_PRIVATE (zak_cgi_form_element_email); - - switch (property_id) - { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -zak_cgi_form_element_email_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - ZakCgiFormElementEmail *zak_cgi_form_element_email = (ZakCgiFormElementEmail *)object; - ZakCgiFormElementEmailPrivate *priv = ZAK_CGI_FORM_ELEMENT_EMAIL_GET_PRIVATE (zak_cgi_form_element_email); - - switch (property_id) - { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -zak_cgi_form_element_email_dispose (GObject *gobject) -{ - ZakCgiFormElementEmail *zak_cgi_form_element_email = (ZakCgiFormElementEmail *)gobject; - ZakCgiFormElementEmailPrivate *priv = ZAK_CGI_FORM_ELEMENT_EMAIL_GET_PRIVATE (zak_cgi_form_element_email); - - - - GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject)); - parent_class->dispose (gobject); -} - -static void -zak_cgi_form_element_email_finalize (GObject *gobject) -{ - ZakCgiFormElementEmail *zak_cgi_form_element_email = (ZakCgiFormElementEmail *)gobject; - ZakCgiFormElementEmailPrivate *priv = ZAK_CGI_FORM_ELEMENT_EMAIL_GET_PRIVATE (zak_cgi_form_element_email); - - - - GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject)); - parent_class->finalize (gobject); -} diff --git a/src/formelementemail.h b/src/formelementemail.h deleted file mode 100644 index 147511b..0000000 --- a/src/formelementemail.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) 2016 Andrea Zagli - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser 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 Lesser 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 - */ - -#ifndef __ZAK_CGI_FORM_ELEMENT_EMAIL_H__ -#define __ZAK_CGI_FORM_ELEMENT_EMAIL_H__ - - -#include - -#include - -#include "formelement.h" - - -G_BEGIN_DECLS - - -#define ZAK_CGI_TYPE_FORM_ELEMENT_EMAIL (zak_cgi_form_element_email_get_type ()) -#define ZAK_CGI_FORM_ELEMENT_EMAIL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ZAK_CGI_TYPE_FORM_ELEMENT_EMAIL, ZakCgiFormElementEmail)) -#define ZAK_CGI_FORM_ELEMENT_EMAIL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ZAK_CGI_TYPE_FORM_ELEMENT_EMAIL, ZakCgiFormElementEmailClass)) -#define ZAK_CGI_IS_FORM_ELEMENT_EMAIL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ZAK_CGI_TYPE_FORM_ELEMENT_EMAIL)) -#define ZAK_CGI_IS_FORM_ELEMENT_EMAIL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ZAK_CGI_TYPE_FORM_ELEMENT_EMAIL)) -#define ZAK_CGI_FORM_ELEMENT_EMAIL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ZAK_CGI_TYPE_FORM_ELEMENT_EMAIL, ZakCgiFormElementEmailClass)) - -typedef struct _ZakCgiFormElementEmail ZakCgiFormElementEmail; -typedef struct _ZakCgiFormElementEmailClass ZakCgiFormElementEmailClass; - -struct _ZakCgiFormElementEmail - { - ZakCgiFormElement parent_instance; - }; - -struct _ZakCgiFormElementEmailClass - { - ZakCgiFormElementClass parent_class; - }; - - -GType zak_cgi_form_element_email_get_type (void); - -ZakCgiFormElement *zak_cgi_form_element_email_new (); -ZakCgiFormElement *zak_cgi_form_element_email_new_attrs (const gchar *id, ...); - -gboolean zak_cgi_form_element_email_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode); - - -G_END_DECLS - - -#endif /* __ZAK_CGI_FORM_ELEMENT_EMAIL_H__ */ diff --git a/src/formelementhidden.c b/src/formelementhidden.c deleted file mode 100644 index ab7a11d..0000000 --- a/src/formelementhidden.c +++ /dev/null @@ -1,258 +0,0 @@ -/* - * Copyright (C) 2015-2016 Andrea Zagli - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser 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 Lesser 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 - */ - -#ifdef HAVE_CONFIG_H - #include -#endif - -#include "commons.h" -#include "tag.h" -#include "formelementhidden.h" - -static void zak_cgi_form_element_hidden_class_init (ZakCgiFormElementHiddenClass *class); -static void zak_cgi_form_element_hidden_init (ZakCgiFormElementHidden *zak_cgi_form_element_hidden); - -static gchar *zak_cgi_form_element_hidden_render (ZakCgiFormElement *element); - -static void zak_cgi_form_element_hidden_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec); -static void zak_cgi_form_element_hidden_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec); - -static void zak_cgi_form_element_hidden_dispose (GObject *gobject); -static void zak_cgi_form_element_hidden_finalize (GObject *gobject); - -#define ZAK_CGI_FORM_ELEMENT_HIDDEN_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZAK_CGI_TYPE_FORM_ELEMENT_HIDDEN, ZakCgiFormElementHiddenPrivate)) - -typedef struct _ZakCgiFormElementHiddenPrivate ZakCgiFormElementHiddenPrivate; -struct _ZakCgiFormElementHiddenPrivate - { - gpointer empty; - }; - -G_DEFINE_TYPE (ZakCgiFormElementHidden, zak_cgi_form_element_hidden, ZAK_CGI_TYPE_FORM_ELEMENT) - -static void -zak_cgi_form_element_hidden_class_init (ZakCgiFormElementHiddenClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - ZakCgiFormElementClass *elem_class = ZAK_CGI_FORM_ELEMENT_CLASS (klass); - - object_class->set_property = zak_cgi_form_element_hidden_set_property; - object_class->get_property = zak_cgi_form_element_hidden_get_property; - object_class->dispose = zak_cgi_form_element_hidden_dispose; - object_class->finalize = zak_cgi_form_element_hidden_finalize; - - elem_class->render = zak_cgi_form_element_hidden_render; - - g_type_class_add_private (object_class, sizeof (ZakCgiFormElementHiddenPrivate)); -} - -static void -zak_cgi_form_element_hidden_init (ZakCgiFormElementHidden *zak_cgi_form_element_hidden) -{ - ZakCgiFormElementHiddenPrivate *priv = ZAK_CGI_FORM_ELEMENT_HIDDEN_GET_PRIVATE (zak_cgi_form_element_hidden); - -} - -/** - * zak_cgi_form_element_hidden_new: - * - * Returns: the newly created #ZakCgiFormElementHidden object. - */ -ZakCgiFormElement -*zak_cgi_form_element_hidden_new () -{ - ZakCgiFormElementHidden *zak_cgi_form_element_hidden; - - zak_cgi_form_element_hidden = ZAK_CGI_FORM_ELEMENT_HIDDEN (g_object_new (zak_cgi_form_element_hidden_get_type (), NULL)); - - return ZAK_CGI_FORM_ELEMENT (zak_cgi_form_element_hidden); -} - -/** - * zak_cgi_form_element_hidden_new_attrs: - * @id: - * @...: - * - * Returns: the newly created #ZakCgiFormElementHidden object. - */ -ZakCgiFormElement -*zak_cgi_form_element_hidden_new_attrs (const gchar *id, - ...) -{ - va_list ap; - - GHashTable *ht_attrs; - - ZakCgiFormElement *zak_cgi_form_element_hidden; - - zak_cgi_form_element_hidden = zak_cgi_form_element_hidden_new (); - - va_start (ap, id); - - ht_attrs = zak_cgi_commons_valist_to_ghashtable (ap); - g_hash_table_replace (ht_attrs, "type", "hidden"); - - ZAK_CGI_FORM_ELEMENT_CLASS (zak_cgi_form_element_hidden_parent_class)->construct (zak_cgi_form_element_hidden, - id, - ht_attrs); - - return zak_cgi_form_element_hidden; -} - - -gboolean -zak_cgi_form_element_hidden_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode) -{ - gboolean ret; - - gchar *id; - - GHashTable *ht_attrs; - - xmlNode *cur; - - id = NULL; - - ZAK_CGI_FORM_ELEMENT_CLASS (zak_cgi_form_element_hidden_parent_class)->xml_parsing (element, xmlnode); - - ht_attrs = g_hash_table_new (g_str_hash, g_str_equal); - g_hash_table_replace (ht_attrs, "type", "hidden"); - - cur = xmlnode->children; - while (cur != NULL) - { - if (xmlStrcmp (cur->name, (const xmlChar *)"id") == 0) - { - id = (gchar *)xmlNodeGetContent (cur); - } - else if (xmlStrcmp (cur->name, (const xmlChar *)"text") == 0) - { - } - else - { - g_hash_table_replace (ht_attrs, g_strdup (cur->name), (gchar *)xmlNodeGetContent (cur)); - } - - cur = cur->next; - } - - if (id != NULL) - { - ZAK_CGI_FORM_ELEMENT_CLASS (zak_cgi_form_element_hidden_parent_class)->construct (ZAK_CGI_FORM_ELEMENT (element), - id, - ht_attrs); - ret = TRUE; - } - else - { - ret = FALSE; - } - - return ret; -} - -static gchar -*zak_cgi_form_element_hidden_render (ZakCgiFormElement *element) -{ - gchar *ret; - - GHashTable *ht_attrs; - - gchar *value; - - ZakCgiFormElementClass *klass; - - klass = (ZakCgiFormElementClass *)g_type_class_peek_parent (ZAK_CGI_FORM_ELEMENT_HIDDEN_GET_CLASS (ZAK_CGI_FORM_ELEMENT_HIDDEN (element))); - - ht_attrs = klass->get_ht_attrs (element); - - value = zak_form_element_get_value (ZAK_FORM_ELEMENT (element)); - if (value != NULL) - { - g_hash_table_insert (ht_attrs, (gpointer)"value", (gpointer)g_strdup (value)); - } - - ret = zak_cgi_tag_tag_ht ("input", zak_cgi_form_element_get_id (element), ht_attrs); - - return ret; -} - -/* PRIVATE */ -static void -zak_cgi_form_element_hidden_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - ZakCgiFormElementHidden *zak_cgi_form_element_hidden = (ZakCgiFormElementHidden *)object; - ZakCgiFormElementHiddenPrivate *priv = ZAK_CGI_FORM_ELEMENT_HIDDEN_GET_PRIVATE (zak_cgi_form_element_hidden); - - switch (property_id) - { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -zak_cgi_form_element_hidden_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - ZakCgiFormElementHidden *zak_cgi_form_element_hidden = (ZakCgiFormElementHidden *)object; - ZakCgiFormElementHiddenPrivate *priv = ZAK_CGI_FORM_ELEMENT_HIDDEN_GET_PRIVATE (zak_cgi_form_element_hidden); - - switch (property_id) - { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -zak_cgi_form_element_hidden_dispose (GObject *gobject) -{ - ZakCgiFormElementHidden *zak_cgi_form_element_hidden = (ZakCgiFormElementHidden *)gobject; - ZakCgiFormElementHiddenPrivate *priv = ZAK_CGI_FORM_ELEMENT_HIDDEN_GET_PRIVATE (zak_cgi_form_element_hidden); - - - - GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject)); - parent_class->dispose (gobject); -} - -static void -zak_cgi_form_element_hidden_finalize (GObject *gobject) -{ - ZakCgiFormElementHidden *zak_cgi_form_element_hidden = (ZakCgiFormElementHidden *)gobject; - ZakCgiFormElementHiddenPrivate *priv = ZAK_CGI_FORM_ELEMENT_HIDDEN_GET_PRIVATE (zak_cgi_form_element_hidden); - - - - GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject)); - parent_class->finalize (gobject); -} diff --git a/src/formelementhidden.h b/src/formelementhidden.h deleted file mode 100644 index 0ead29e..0000000 --- a/src/formelementhidden.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) 2015 Andrea Zagli - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser 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 Lesser 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 - */ - -#ifndef __ZAK_CGI_FORM_ELEMENT_HIDDEN_H__ -#define __ZAK_CGI_FORM_ELEMENT_HIDDEN_H__ - - -#include - -#include - -#include "formelement.h" - - -G_BEGIN_DECLS - - -#define ZAK_CGI_TYPE_FORM_ELEMENT_HIDDEN (zak_cgi_form_element_hidden_get_type ()) -#define ZAK_CGI_FORM_ELEMENT_HIDDEN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ZAK_CGI_TYPE_FORM_ELEMENT_HIDDEN, ZakCgiFormElementHidden)) -#define ZAK_CGI_FORM_ELEMENT_HIDDEN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ZAK_CGI_TYPE_FORM_ELEMENT_HIDDEN, ZakCgiFormElementHiddenClass)) -#define ZAK_CGI_IS_FORM_ELEMENT_HIDDEN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ZAK_CGI_TYPE_FORM_ELEMENT_HIDDEN)) -#define ZAK_CGI_IS_FORM_ELEMENT_HIDDEN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ZAK_CGI_TYPE_FORM_ELEMENT_HIDDEN)) -#define ZAK_CGI_FORM_ELEMENT_HIDDEN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ZAK_CGI_TYPE_FORM_ELEMENT_HIDDEN, ZakCgiFormElementHiddenClass)) - -typedef struct _ZakCgiFormElementHidden ZakCgiFormElementHidden; -typedef struct _ZakCgiFormElementHiddenClass ZakCgiFormElementHiddenClass; - -struct _ZakCgiFormElementHidden - { - ZakCgiFormElement parent_instance; - }; - -struct _ZakCgiFormElementHiddenClass - { - ZakCgiFormElementClass parent_class; - }; - - -GType zak_cgi_form_element_hidden_get_type (void); - -ZakCgiFormElement *zak_cgi_form_element_hidden_new (void); -ZakCgiFormElement *zak_cgi_form_element_hidden_new_attrs (const gchar *id, ...); - -gboolean zak_cgi_form_element_hidden_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode); - - -G_END_DECLS - - -#endif /* __ZAK_CGI_FORM_ELEMENT_HIDDEN_H__ */ diff --git a/src/formelementpassword.c b/src/formelementpassword.c deleted file mode 100644 index 989676f..0000000 --- a/src/formelementpassword.c +++ /dev/null @@ -1,261 +0,0 @@ -/* - * Copyright (C) 2015-2016 Andrea Zagli - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser 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 Lesser 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 - */ - -#ifdef HAVE_CONFIG_H - #include -#endif - -#include "commons.h" -#include "tag.h" -#include "formelementpassword.h" - -static void zak_cgi_form_element_password_class_init (ZakCgiFormElementPasswordClass *class); -static void zak_cgi_form_element_password_init (ZakCgiFormElementPassword *zak_cgi_form_element_password); - -static gchar *zak_cgi_form_element_password_render (ZakCgiFormElement *element); - -static void zak_cgi_form_element_password_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec); -static void zak_cgi_form_element_password_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec); - -static void zak_cgi_form_element_password_dispose (GObject *gobject); -static void zak_cgi_form_element_password_finalize (GObject *gobject); - -#define ZAK_CGI_FORM_ELEMENT_PASSWORD_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZAK_CGI_TYPE_FORM_ELEMENT_PASSWORD, ZakCgiFormElementPasswordPrivate)) - -typedef struct _ZakCgiFormElementPasswordPrivate ZakCgiFormElementPasswordPrivate; -struct _ZakCgiFormElementPasswordPrivate - { - gpointer empty; - }; - -G_DEFINE_TYPE (ZakCgiFormElementPassword, zak_cgi_form_element_password, ZAK_CGI_TYPE_FORM_ELEMENT) - -static void -zak_cgi_form_element_password_class_init (ZakCgiFormElementPasswordClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - ZakCgiFormElementClass *elem_class = ZAK_CGI_FORM_ELEMENT_CLASS (klass); - - object_class->set_property = zak_cgi_form_element_password_set_property; - object_class->get_property = zak_cgi_form_element_password_get_property; - object_class->dispose = zak_cgi_form_element_password_dispose; - object_class->finalize = zak_cgi_form_element_password_finalize; - - elem_class->render = zak_cgi_form_element_password_render; - - g_type_class_add_private (object_class, sizeof (ZakCgiFormElementPasswordPrivate)); -} - -static void -zak_cgi_form_element_password_init (ZakCgiFormElementPassword *zak_cgi_form_element_password) -{ - ZakCgiFormElementPasswordPrivate *priv = ZAK_CGI_FORM_ELEMENT_PASSWORD_GET_PRIVATE (zak_cgi_form_element_password); - -} - -/** - * zak_cgi_form_element_password_new: - * - * Returns: the newly created #ZakCgiFormElementPassword object. - */ -ZakCgiFormElement -*zak_cgi_form_element_password_new () -{ - ZakCgiFormElementPassword *zak_cgi_form_element_password; - - zak_cgi_form_element_password = ZAK_CGI_FORM_ELEMENT_PASSWORD (g_object_new (zak_cgi_form_element_password_get_type (), NULL)); - - return ZAK_CGI_FORM_ELEMENT (zak_cgi_form_element_password); -} - -/** - * zak_cgi_form_element_password_new_attrs: - * @id: - * @...: - * - * Returns: the newly created #ZakCgiFormElementPassword object. - */ -ZakCgiFormElement -*zak_cgi_form_element_password_new_attrs (const gchar *id, - ...) -{ - va_list ap; - - GHashTable *ht_attrs; - - ZakCgiFormElement *zak_cgi_form_element_password; - - zak_cgi_form_element_password = zak_cgi_form_element_password_new (); - - va_start (ap, id); - - ht_attrs = zak_cgi_commons_valist_to_ghashtable (ap); - g_hash_table_replace (ht_attrs, "type", "password"); - - ZAK_CGI_FORM_ELEMENT_CLASS (zak_cgi_form_element_password_parent_class)->construct (zak_cgi_form_element_password, - id, - ht_attrs); - - return zak_cgi_form_element_password; -} - -gboolean -zak_cgi_form_element_password_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode) -{ - gboolean ret; - - gchar *id; - - GHashTable *ht_attrs; - - xmlNode *cur; - - id = NULL; - - ZAK_CGI_FORM_ELEMENT_CLASS (zak_cgi_form_element_password_parent_class)->xml_parsing (element, xmlnode); - - ht_attrs = g_hash_table_new (g_str_hash, g_str_equal); - g_hash_table_replace (ht_attrs, "type", "password"); - - cur = xmlnode->children; - while (cur != NULL) - { - if (xmlStrcmp (cur->name, (const xmlChar *)"id") == 0) - { - id = (gchar *)xmlNodeGetContent (cur); - } - else if (xmlStrcmp (cur->name, (const xmlChar *)"label") == 0) - { - zak_cgi_form_element_set_label (ZAK_CGI_FORM_ELEMENT (element), (gchar *)xmlNodeGetContent (cur), NULL); - } - else if (xmlStrcmp (cur->name, (const xmlChar *)"text") == 0) - { - } - else - { - g_hash_table_replace (ht_attrs, g_strdup (cur->name), (gchar *)xmlNodeGetContent (cur)); - } - - cur = cur->next; - } - - if (id != NULL) - { - ZAK_CGI_FORM_ELEMENT_CLASS (zak_cgi_form_element_password_parent_class)->construct (ZAK_CGI_FORM_ELEMENT (element), - id, - ht_attrs); - ret = TRUE; - } - else - { - ret = FALSE; - } - - return ret; -} - -static gchar -*zak_cgi_form_element_password_render (ZakCgiFormElement *element) -{ - gchar *ret; - - GHashTable *ht_attrs; - - gchar *value; - - ZakCgiFormElementClass *klass; - - klass = (ZakCgiFormElementClass *)g_type_class_peek_parent (ZAK_CGI_FORM_ELEMENT_PASSWORD_GET_CLASS (ZAK_CGI_FORM_ELEMENT_PASSWORD (element))); - - ht_attrs = klass->get_ht_attrs (element); - - value = zak_form_element_get_value (ZAK_FORM_ELEMENT (element)); - if (value != NULL) - { - g_hash_table_insert (ht_attrs, (gpointer)"value", (gpointer)g_strdup (value)); - } - - ret = zak_cgi_tag_tag_ht ("input", zak_cgi_form_element_get_id (element), ht_attrs); - - return ret; -} - -/* PRIVATE */ -static void -zak_cgi_form_element_password_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - ZakCgiFormElementPassword *zak_cgi_form_element_password = (ZakCgiFormElementPassword *)object; - ZakCgiFormElementPasswordPrivate *priv = ZAK_CGI_FORM_ELEMENT_PASSWORD_GET_PRIVATE (zak_cgi_form_element_password); - - switch (property_id) - { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -zak_cgi_form_element_password_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - ZakCgiFormElementPassword *zak_cgi_form_element_password = (ZakCgiFormElementPassword *)object; - ZakCgiFormElementPasswordPrivate *priv = ZAK_CGI_FORM_ELEMENT_PASSWORD_GET_PRIVATE (zak_cgi_form_element_password); - - switch (property_id) - { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -zak_cgi_form_element_password_dispose (GObject *gobject) -{ - ZakCgiFormElementPassword *zak_cgi_form_element_password = (ZakCgiFormElementPassword *)gobject; - ZakCgiFormElementPasswordPrivate *priv = ZAK_CGI_FORM_ELEMENT_PASSWORD_GET_PRIVATE (zak_cgi_form_element_password); - - - - GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject)); - parent_class->dispose (gobject); -} - -static void -zak_cgi_form_element_password_finalize (GObject *gobject) -{ - ZakCgiFormElementPassword *zak_cgi_form_element_password = (ZakCgiFormElementPassword *)gobject; - ZakCgiFormElementPasswordPrivate *priv = ZAK_CGI_FORM_ELEMENT_PASSWORD_GET_PRIVATE (zak_cgi_form_element_password); - - - - GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject)); - parent_class->finalize (gobject); -} diff --git a/src/formelementpassword.h b/src/formelementpassword.h deleted file mode 100644 index 4b38eff..0000000 --- a/src/formelementpassword.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) 2015 Andrea Zagli - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser 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 Lesser 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 - */ - -#ifndef __ZAK_CGI_FORM_ELEMENT_PASSWORD_H__ -#define __ZAK_CGI_FORM_ELEMENT_PASSWORD_H__ - - -#include - -#include - -#include "formelement.h" - - -G_BEGIN_DECLS - - -#define ZAK_CGI_TYPE_FORM_ELEMENT_PASSWORD (zak_cgi_form_element_password_get_type ()) -#define ZAK_CGI_FORM_ELEMENT_PASSWORD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ZAK_CGI_TYPE_FORM_ELEMENT_PASSWORD, ZakCgiFormElementPassword)) -#define ZAK_CGI_FORM_ELEMENT_PASSWORD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ZAK_CGI_TYPE_FORM_ELEMENT_PASSWORD, ZakCgiFormElementPasswordClass)) -#define ZAK_CGI_IS_FORM_ELEMENT_PASSWORD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ZAK_CGI_TYPE_FORM_ELEMENT_PASSWORD)) -#define ZAK_CGI_IS_FORM_ELEMENT_PASSWORD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ZAK_CGI_TYPE_FORM_ELEMENT_PASSWORD)) -#define ZAK_CGI_FORM_ELEMENT_PASSWORD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ZAK_CGI_TYPE_FORM_ELEMENT_PASSWORD, ZakCgiFormElementPasswordClass)) - -typedef struct _ZakCgiFormElementPassword ZakCgiFormElementPassword; -typedef struct _ZakCgiFormElementPasswordClass ZakCgiFormElementPasswordClass; - -struct _ZakCgiFormElementPassword - { - ZakCgiFormElement parent_instance; - }; - -struct _ZakCgiFormElementPasswordClass - { - ZakCgiFormElementClass parent_class; - }; - - -GType zak_cgi_form_element_password_get_type (void); - -ZakCgiFormElement *zak_cgi_form_element_password_new (); -ZakCgiFormElement *zak_cgi_form_element_password_new_attrs (const gchar *id, ...); - -gboolean zak_cgi_form_element_password_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode); - - -G_END_DECLS - - -#endif /* __ZAK_CGI_FORM_ELEMENT_PASSWORD_H__ */ diff --git a/src/formelementselect.c b/src/formelementselect.c deleted file mode 100644 index aeda57d..0000000 --- a/src/formelementselect.c +++ /dev/null @@ -1,318 +0,0 @@ -/* - * Copyright (C) 2015-2016 Andrea Zagli - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser 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 Lesser 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 - */ - -#ifdef HAVE_CONFIG_H - #include -#endif - -#include "commons.h" -#include "tag.h" -#include "formelementselect.h" - -static void zak_cgi_form_element_select_class_init (ZakCgiFormElementSelectClass *class); -static void zak_cgi_form_element_select_init (ZakCgiFormElementSelect *zak_cgi_form_element_select); - -static gchar *zak_cgi_form_element_select_render (ZakCgiFormElement *element); - -static void zak_cgi_form_element_select_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec); -static void zak_cgi_form_element_select_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec); - -static void zak_cgi_form_element_select_dispose (GObject *gobject); -static void zak_cgi_form_element_select_finalize (GObject *gobject); - -#define ZAK_CGI_FORM_ELEMENT_SELECT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZAK_CGI_TYPE_FORM_ELEMENT_SELECT, ZakCgiFormElementSelectPrivate)) - -typedef struct _ZakCgiFormElementSelectPrivate ZakCgiFormElementSelectPrivate; -struct _ZakCgiFormElementSelectPrivate - { - GHashTable *ht_options; - }; - -G_DEFINE_TYPE (ZakCgiFormElementSelect, zak_cgi_form_element_select, ZAK_CGI_TYPE_FORM_ELEMENT) - -static void -zak_cgi_form_element_select_class_init (ZakCgiFormElementSelectClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - ZakCgiFormElementClass *elem_class = ZAK_CGI_FORM_ELEMENT_CLASS (klass); - - object_class->set_property = zak_cgi_form_element_select_set_property; - object_class->get_property = zak_cgi_form_element_select_get_property; - object_class->dispose = zak_cgi_form_element_select_dispose; - object_class->finalize = zak_cgi_form_element_select_finalize; - - elem_class->render = zak_cgi_form_element_select_render; - - g_type_class_add_private (object_class, sizeof (ZakCgiFormElementSelectPrivate)); -} - -static void -zak_cgi_form_element_select_init (ZakCgiFormElementSelect *zak_cgi_form_element_select) -{ - ZakCgiFormElementSelectPrivate *priv = ZAK_CGI_FORM_ELEMENT_SELECT_GET_PRIVATE (zak_cgi_form_element_select); - - priv->ht_options = g_hash_table_new (g_str_hash, g_str_equal); -} - -/** - * zak_cgi_form_element_select_new: - * - * Returns: the newly created #ZakCgiFormElementSelect object. - */ -ZakCgiFormElement -*zak_cgi_form_element_select_new () -{ - ZakCgiFormElementSelect *zak_cgi_form_element_select; - - zak_cgi_form_element_select = ZAK_CGI_FORM_ELEMENT_SELECT (g_object_new (zak_cgi_form_element_select_get_type (), NULL)); - - return ZAK_CGI_FORM_ELEMENT (zak_cgi_form_element_select); -} - -/** - * zak_cgi_form_element_select_new_attrs: - * @id: - * @...: - * - * Returns: the newly created #ZakCgiFormElementSelect object. - */ -ZakCgiFormElement -*zak_cgi_form_element_select_new_attrs (const gchar *id, - ...) -{ - va_list ap; - - ZakCgiFormElement *zak_cgi_form_element_select; - - zak_cgi_form_element_select = zak_cgi_form_element_select_new (); - - va_start (ap, id); - - ZAK_CGI_FORM_ELEMENT_CLASS (zak_cgi_form_element_select_parent_class)->construct (zak_cgi_form_element_select, - id, - zak_cgi_commons_valist_to_ghashtable (ap)); - - return zak_cgi_form_element_select; -} - -/** - * zak_cgi_form_element_select_add_option: - * @element: - * @value: - * @content: - * @...: - * - */ -void -zak_cgi_form_element_select_add_option (ZakCgiFormElementSelect *element, - const gchar *value, - const gchar *content, - ...) -{ - va_list ap; - GHashTable *ht_attrs; - - ZakCgiFormElementSelectPrivate *priv = ZAK_CGI_FORM_ELEMENT_SELECT_GET_PRIVATE (element); - - va_start (ap, content); - ht_attrs = zak_cgi_commons_valist_to_ghashtable (ap); - if (ht_attrs == NULL) - { - g_hash_table_new (g_str_hash, g_str_equal); - } - g_hash_table_replace (ht_attrs, "zak-cgi-content", g_strdup (content)); - - g_hash_table_replace (priv->ht_options, g_strdup (value), ht_attrs); -} - -gboolean -zak_cgi_form_element_select_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode) -{ - gboolean ret; - - gchar *id; - - GHashTable *ht_attrs; - - xmlNode *cur; - - id = NULL; - - ZAK_CGI_FORM_ELEMENT_CLASS (zak_cgi_form_element_select_parent_class)->xml_parsing (element, xmlnode); - - ht_attrs = g_hash_table_new (g_str_hash, g_str_equal); - - cur = xmlnode->children; - while (cur != NULL) - { - if (xmlStrcmp (cur->name, (const xmlChar *)"id") == 0) - { - id = (gchar *)xmlNodeGetContent (cur); - } - else if (xmlStrcmp (cur->name, (const xmlChar *)"label") == 0) - { - zak_cgi_form_element_set_label (ZAK_CGI_FORM_ELEMENT (element), (gchar *)xmlNodeGetContent (cur), NULL); - } - else if (xmlStrcmp (cur->name, (const xmlChar *)"option") == 0) - { - zak_cgi_form_element_select_add_option (ZAK_CGI_FORM_ELEMENT_SELECT (element), (gchar *)xmlGetProp (cur, (xmlChar *)"id"), (gchar *)xmlNodeGetContent (cur), NULL); - } - else if (xmlStrcmp (cur->name, (const xmlChar *)"text") == 0) - { - } - else - { - g_hash_table_replace (ht_attrs, g_strdup (cur->name), (gchar *)xmlNodeGetContent (cur)); - } - - cur = cur->next; - } - - if (id != NULL) - { - ZAK_CGI_FORM_ELEMENT_CLASS (zak_cgi_form_element_select_parent_class)->construct (ZAK_CGI_FORM_ELEMENT (element), - id, - ht_attrs); - ret = TRUE; - } - else - { - ret = FALSE; - } - - return ret; -} - -static gchar -*zak_cgi_form_element_select_render (ZakCgiFormElement *element) -{ - gchar *ret; - - GHashTableIter iter; - gpointer key; - gpointer value; - GString *options; - GHashTable *ht_options_attrs; - - GHashTable *ht_attrs; - - gchar *gval; - - ZakCgiFormElementClass *klass; - - ZakCgiFormElementSelectPrivate *priv = ZAK_CGI_FORM_ELEMENT_SELECT_GET_PRIVATE (element); - - klass = (ZakCgiFormElementClass *)g_type_class_peek_parent (ZAK_CGI_FORM_ELEMENT_SELECT_GET_CLASS (ZAK_CGI_FORM_ELEMENT_SELECT (element))); - - gval = zak_form_element_get_value (ZAK_FORM_ELEMENT (element)); - - /* list options */ - options = g_string_new ("\n"); - g_hash_table_iter_init (&iter, priv->ht_options); - while (g_hash_table_iter_next (&iter, &key, &value)) - { - ht_options_attrs = (GHashTable *)value; - g_hash_table_replace (ht_options_attrs, "value", g_strdup ((gchar *)key)); - - if (gval != NULL) - { - if (g_strcmp0 (gval, (gchar *)key) == 0) - { - g_hash_table_replace (ht_options_attrs, "selected", g_strdup ("selected")); - } - } - - g_string_append (options, - zak_cgi_tag_tag_ht ("option", NULL, ht_options_attrs)); - g_string_append (options, "\n"); - } - - ht_attrs = klass->get_ht_attrs (element); - - g_hash_table_replace (ht_attrs, "zak-cgi-content", g_strdup (options->str)); - ret = zak_cgi_tag_tag_ht ("select", zak_cgi_form_element_get_id (element), ht_attrs); - - g_string_free (options, TRUE); - - return ret; -} - -/* PRIVATE */ -static void -zak_cgi_form_element_select_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - ZakCgiFormElementSelect *zak_cgi_form_element_select = (ZakCgiFormElementSelect *)object; - ZakCgiFormElementSelectPrivate *priv = ZAK_CGI_FORM_ELEMENT_SELECT_GET_PRIVATE (zak_cgi_form_element_select); - - switch (property_id) - { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -zak_cgi_form_element_select_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - ZakCgiFormElementSelect *zak_cgi_form_element_select = (ZakCgiFormElementSelect *)object; - ZakCgiFormElementSelectPrivate *priv = ZAK_CGI_FORM_ELEMENT_SELECT_GET_PRIVATE (zak_cgi_form_element_select); - - switch (property_id) - { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -zak_cgi_form_element_select_dispose (GObject *gobject) -{ - ZakCgiFormElementSelect *zak_cgi_form_element_select = (ZakCgiFormElementSelect *)gobject; - ZakCgiFormElementSelectPrivate *priv = ZAK_CGI_FORM_ELEMENT_SELECT_GET_PRIVATE (zak_cgi_form_element_select); - - - - GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject)); - parent_class->dispose (gobject); -} - -static void -zak_cgi_form_element_select_finalize (GObject *gobject) -{ - ZakCgiFormElementSelect *zak_cgi_form_element_select = (ZakCgiFormElementSelect *)gobject; - ZakCgiFormElementSelectPrivate *priv = ZAK_CGI_FORM_ELEMENT_SELECT_GET_PRIVATE (zak_cgi_form_element_select); - - - - GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject)); - parent_class->finalize (gobject); -} diff --git a/src/formelementselect.h b/src/formelementselect.h deleted file mode 100644 index 23882ef..0000000 --- a/src/formelementselect.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2015 Andrea Zagli - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser 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 Lesser 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 - */ - -#ifndef __ZAK_CGI_FORM_ELEMENT_SELECT_H__ -#define __ZAK_CGI_FORM_ELEMENT_SELECT_H__ - - -#include - -#include - -#include "formelement.h" - - -G_BEGIN_DECLS - - -#define ZAK_CGI_TYPE_FORM_ELEMENT_SELECT (zak_cgi_form_element_select_get_type ()) -#define ZAK_CGI_FORM_ELEMENT_SELECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ZAK_CGI_TYPE_FORM_ELEMENT_SELECT, ZakCgiFormElementSelect)) -#define ZAK_CGI_FORM_ELEMENT_SELECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ZAK_CGI_TYPE_FORM_ELEMENT_SELECT, ZakCgiFormElementSelectClass)) -#define ZAK_CGI_IS_FORM_ELEMENT_SELECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ZAK_CGI_TYPE_FORM_ELEMENT_SELECT)) -#define ZAK_CGI_IS_FORM_ELEMENT_SELECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ZAK_CGI_TYPE_FORM_ELEMENT_SELECT)) -#define ZAK_CGI_FORM_ELEMENT_SELECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ZAK_CGI_TYPE_FORM_ELEMENT_SELECT, ZakCgiFormElementSelectClass)) - -typedef struct _ZakCgiFormElementSelect ZakCgiFormElementSelect; -typedef struct _ZakCgiFormElementSelectClass ZakCgiFormElementSelectClass; - -struct _ZakCgiFormElementSelect - { - ZakCgiFormElement parent_instance; - }; - -struct _ZakCgiFormElementSelectClass - { - ZakCgiFormElementClass parent_class; - }; - - -GType zak_cgi_form_element_select_get_type (void); - -ZakCgiFormElement *zak_cgi_form_element_select_new (void); -ZakCgiFormElement *zak_cgi_form_element_select_new_attrs (const gchar *id, ...); - -void zak_cgi_form_element_select_add_option (ZakCgiFormElementSelect *element, const gchar *value, const gchar *content, ...); - -gboolean zak_cgi_form_element_select_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode); - - -G_END_DECLS - - -#endif /* __ZAK_CGI_FORM_ELEMENT_SELECT_H__ */ diff --git a/src/formelementstring.c b/src/formelementstring.c deleted file mode 100644 index 632a5ff..0000000 --- a/src/formelementstring.c +++ /dev/null @@ -1,227 +0,0 @@ -/* - * Copyright (C) 2015-2016 Andrea Zagli - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser 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 Lesser 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 - */ - -#ifdef HAVE_CONFIG_H - #include -#endif - -#include "commons.h" -#include "tag.h" -#include "formelementstring.h" - -static void zak_cgi_form_element_string_class_init (ZakCgiFormElementStringClass *class); -static void zak_cgi_form_element_string_init (ZakCgiFormElementString *zak_cgi_form_element_string); - -static gchar *zak_cgi_form_element_string_render (ZakCgiFormElement *element); - -static gboolean zak_cgi_form_element_string_is_valid (ZakCgiFormElement *element); - -static void zak_cgi_form_element_string_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec); -static void zak_cgi_form_element_string_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec); - -static void zak_cgi_form_element_string_dispose (GObject *gobject); -static void zak_cgi_form_element_string_finalize (GObject *gobject); - -#define ZAK_CGI_FORM_ELEMENT_STRING_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZAK_CGI_TYPE_FORM_ELEMENT_STRING, ZakCgiFormElementStringPrivate)) - -typedef struct _ZakCgiFormElementStringPrivate ZakCgiFormElementStringPrivate; -struct _ZakCgiFormElementStringPrivate - { - gchar *str; - }; - -G_DEFINE_TYPE (ZakCgiFormElementString, zak_cgi_form_element_string, ZAK_CGI_TYPE_FORM_ELEMENT) - -static void -zak_cgi_form_element_string_class_init (ZakCgiFormElementStringClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - ZakCgiFormElementClass *elem_class = ZAK_CGI_FORM_ELEMENT_CLASS (klass); - - object_class->set_property = zak_cgi_form_element_string_set_property; - object_class->get_property = zak_cgi_form_element_string_get_property; - object_class->dispose = zak_cgi_form_element_string_dispose; - object_class->finalize = zak_cgi_form_element_string_finalize; - - elem_class->render = zak_cgi_form_element_string_render; - //elem_class->is_valid = zak_cgi_form_element_string_is_valid; - - g_type_class_add_private (object_class, sizeof (ZakCgiFormElementStringPrivate)); -} - -static void -zak_cgi_form_element_string_init (ZakCgiFormElementString *zak_cgi_form_element_string) -{ - ZakCgiFormElementStringPrivate *priv = ZAK_CGI_FORM_ELEMENT_STRING_GET_PRIVATE (zak_cgi_form_element_string); - - priv->str = NULL; -} - -/** - * zak_cgi_form_element_string_new: - * - * Returns: the newly created #ZakCgiFormElementString object. - */ -ZakCgiFormElement -*zak_cgi_form_element_string_new () -{ - ZakCgiFormElementString *zak_cgi_form_element_string; - - zak_cgi_form_element_string = ZAK_CGI_FORM_ELEMENT_STRING (g_object_new (zak_cgi_form_element_string_get_type (), NULL)); - - return ZAK_CGI_FORM_ELEMENT (zak_cgi_form_element_string); -} - -/** - * zak_cgi_form_element_string_new_attrs: - * @str: - * - * Returns: the newly created #ZakCgiFormElementString object. - */ -ZakCgiFormElement -*zak_cgi_form_element_string_new_attrs (const gchar *str) -{ - ZakCgiFormElement *zak_cgi_form_element_string; - - zak_cgi_form_element_string = zak_cgi_form_element_string_new (); - - ZakCgiFormElementStringPrivate *priv = ZAK_CGI_FORM_ELEMENT_STRING_GET_PRIVATE (zak_cgi_form_element_string); - - priv->str = g_strdup (str); - - return zak_cgi_form_element_string; -} - -gboolean -zak_cgi_form_element_string_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode) -{ - gboolean ret; - - xmlNode *cur; - - ZakCgiFormElementStringPrivate *priv; - - ret = FALSE; - - ZAK_CGI_FORM_ELEMENT_CLASS (zak_cgi_form_element_string_parent_class)->xml_parsing (element, xmlnode); - - cur = xmlnode->children; - while (cur != NULL) - { - if (xmlStrcmp (cur->name, (const xmlChar *)"string") == 0) - { - priv = ZAK_CGI_FORM_ELEMENT_STRING_GET_PRIVATE (ZAK_CGI_FORM_ELEMENT_STRING (element)); - priv->str = g_strdup ((gchar *)xmlNodeGetContent (cur)); - ret = TRUE; - break; - } - - cur = cur->next; - } - - return ret; -} - -static gchar -*zak_cgi_form_element_string_render (ZakCgiFormElement *element) -{ - gchar *ret; - - ZakCgiFormElementStringPrivate *priv = ZAK_CGI_FORM_ELEMENT_STRING_GET_PRIVATE (element); - - ret = g_strdup (priv->str); - - return ret; -} - -static gboolean -zak_cgi_form_element_string_check_value (const gchar *validation_regex, GValue *value) -{ - return TRUE; -} - -static gboolean -zak_cgi_form_element_string_is_valid (ZakCgiFormElement *element) -{ - return TRUE; -} - -/* PRIVATE */ -static void -zak_cgi_form_element_string_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - ZakCgiFormElementString *zak_cgi_form_element_string = (ZakCgiFormElementString *)object; - ZakCgiFormElementStringPrivate *priv = ZAK_CGI_FORM_ELEMENT_STRING_GET_PRIVATE (zak_cgi_form_element_string); - - switch (property_id) - { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -zak_cgi_form_element_string_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - ZakCgiFormElementString *zak_cgi_form_element_string = (ZakCgiFormElementString *)object; - ZakCgiFormElementStringPrivate *priv = ZAK_CGI_FORM_ELEMENT_STRING_GET_PRIVATE (zak_cgi_form_element_string); - - switch (property_id) - { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -zak_cgi_form_element_string_dispose (GObject *gobject) -{ - ZakCgiFormElementString *zak_cgi_form_element_string = (ZakCgiFormElementString *)gobject; - ZakCgiFormElementStringPrivate *priv = ZAK_CGI_FORM_ELEMENT_STRING_GET_PRIVATE (zak_cgi_form_element_string); - - - - GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject)); - parent_class->dispose (gobject); -} - -static void -zak_cgi_form_element_string_finalize (GObject *gobject) -{ - ZakCgiFormElementString *zak_cgi_form_element_string = (ZakCgiFormElementString *)gobject; - ZakCgiFormElementStringPrivate *priv = ZAK_CGI_FORM_ELEMENT_STRING_GET_PRIVATE (zak_cgi_form_element_string); - - - - GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject)); - parent_class->finalize (gobject); -} diff --git a/src/formelementstring.h b/src/formelementstring.h deleted file mode 100644 index 884b52b..0000000 --- a/src/formelementstring.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) 2015 Andrea Zagli - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser 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 Lesser 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 - */ - -#ifndef __ZAK_CGI_FORM_ELEMENT_STRING_H__ -#define __ZAK_CGI_FORM_ELEMENT_STRING_H__ - - -#include - -#include - -#include "formelement.h" - - -G_BEGIN_DECLS - - -#define ZAK_CGI_TYPE_FORM_ELEMENT_STRING (zak_cgi_form_element_string_get_type ()) -#define ZAK_CGI_FORM_ELEMENT_STRING(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ZAK_CGI_TYPE_FORM_ELEMENT_STRING, ZakCgiFormElementString)) -#define ZAK_CGI_FORM_ELEMENT_STRING_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ZAK_CGI_TYPE_FORM_ELEMENT_STRING, ZakCgiFormElementStringClass)) -#define ZAK_CGI_IS_FORM_ELEMENT_STRING(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ZAK_CGI_TYPE_FORM_ELEMENT_STRING)) -#define ZAK_CGI_IS_FORM_ELEMENT_STRING_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ZAK_CGI_TYPE_FORM_ELEMENT_STRING)) -#define ZAK_CGI_FORM_ELEMENT_STRING_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ZAK_CGI_TYPE_FORM_ELEMENT_STRING, ZakCgiFormElementStringClass)) - -typedef struct _ZakCgiFormElementString ZakCgiFormElementString; -typedef struct _ZakCgiFormElementStringClass ZakCgiFormElementStringClass; - -struct _ZakCgiFormElementString - { - ZakCgiFormElement parent_instance; - }; - -struct _ZakCgiFormElementStringClass - { - ZakCgiFormElementClass parent_class; - }; - - -GType zak_cgi_form_element_string_get_type (void); - -ZakCgiFormElement *zak_cgi_form_element_string_new (void); -ZakCgiFormElement *zak_cgi_form_element_string_new_attrs (const gchar *str); - -gboolean zak_cgi_form_element_string_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode); - - -G_END_DECLS - - -#endif /* __ZAK_CGI_FORM_ELEMENT_STRING_H__ */ diff --git a/src/formelementsubmit.c b/src/formelementsubmit.c deleted file mode 100644 index 61c0815..0000000 --- a/src/formelementsubmit.c +++ /dev/null @@ -1,274 +0,0 @@ -/* - * Copyright (C) 2015-2016 Andrea Zagli - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser 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 Lesser 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 - */ - -#ifdef HAVE_CONFIG_H - #include -#endif - -#include "commons.h" -#include "tag.h" -#include "formelementsubmit.h" - -static void zak_cgi_form_element_submit_class_init (ZakCgiFormElementSubmitClass *class); -static void zak_cgi_form_element_submit_init (ZakCgiFormElementSubmit *zak_cgi_form_element_submit); - -static gchar *zak_cgi_form_element_submit_render (ZakCgiFormElement *element); - -static void zak_cgi_form_element_submit_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec); -static void zak_cgi_form_element_submit_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec); - -static void zak_cgi_form_element_submit_dispose (GObject *gobject); -static void zak_cgi_form_element_submit_finalize (GObject *gobject); - -#define ZAK_CGI_FORM_ELEMENT_SUBMIT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZAK_CGI_TYPE_FORM_ELEMENT_SUBMIT, ZakCgiFormElementSubmitPrivate)) - -typedef struct _ZakCgiFormElementSubmitPrivate ZakCgiFormElementSubmitPrivate; -struct _ZakCgiFormElementSubmitPrivate - { - gpointer empty; - }; - -G_DEFINE_TYPE (ZakCgiFormElementSubmit, zak_cgi_form_element_submit, ZAK_CGI_TYPE_FORM_ELEMENT) - -static void -zak_cgi_form_element_submit_class_init (ZakCgiFormElementSubmitClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - ZakCgiFormElementClass *elem_class = ZAK_CGI_FORM_ELEMENT_CLASS (klass); - - object_class->set_property = zak_cgi_form_element_submit_set_property; - object_class->get_property = zak_cgi_form_element_submit_get_property; - object_class->dispose = zak_cgi_form_element_submit_dispose; - object_class->finalize = zak_cgi_form_element_submit_finalize; - - elem_class->render = zak_cgi_form_element_submit_render; - - g_type_class_add_private (object_class, sizeof (ZakCgiFormElementSubmitPrivate)); -} - -static void -zak_cgi_form_element_submit_init (ZakCgiFormElementSubmit *zak_cgi_form_element_submit) -{ - ZakCgiFormElementSubmitPrivate *priv = ZAK_CGI_FORM_ELEMENT_SUBMIT_GET_PRIVATE (zak_cgi_form_element_submit); - -} - -/** - * zak_cgi_form_element_submit_new: - * - * Returns: the newly created #ZakCgiFormElementSubmit object. - */ -ZakCgiFormElement -*zak_cgi_form_element_submit_new () -{ - ZakCgiFormElementSubmit *zak_cgi_form_element_submit; - - zak_cgi_form_element_submit = ZAK_CGI_FORM_ELEMENT_SUBMIT (g_object_new (zak_cgi_form_element_submit_get_type (), NULL)); - - return ZAK_CGI_FORM_ELEMENT (zak_cgi_form_element_submit); -} - -/** - * zak_cgi_form_element_submit_new_attrs: - * @id: - * @...: - * - * Returns: the newly created #ZakCgiFormElementSubmit object. - */ -ZakCgiFormElement -*zak_cgi_form_element_submit_new_attrs (const gchar *id, - ...) -{ - va_list ap; - - ZakCgiFormElement *zak_cgi_form_element_submit; - - zak_cgi_form_element_submit = zak_cgi_form_element_submit_new (); - - va_start (ap, id); - - ZAK_CGI_FORM_ELEMENT_CLASS (zak_cgi_form_element_submit_parent_class)->construct (zak_cgi_form_element_submit, - id, - zak_cgi_commons_valist_to_ghashtable (ap)); - - return zak_cgi_form_element_submit; -} - -gboolean -zak_cgi_form_element_submit_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode) -{ - gboolean ret; - - gchar *id; - - GHashTable *ht_attrs; - - xmlNode *cur; - - id = NULL; - - ZAK_CGI_FORM_ELEMENT_CLASS (zak_cgi_form_element_submit_parent_class)->xml_parsing (element, xmlnode); - - ht_attrs = g_hash_table_new (g_str_hash, g_str_equal); - - cur = xmlnode->children; - while (cur != NULL) - { - if (xmlStrcmp (cur->name, (const xmlChar *)"id") == 0) - { - id = (gchar *)xmlNodeGetContent (cur); - } - else if (xmlStrcmp (cur->name, (const xmlChar *)"label") == 0) - { - zak_cgi_form_element_set_label (ZAK_CGI_FORM_ELEMENT (element), (gchar *)xmlNodeGetContent (cur), NULL); - } - else if (xmlStrcmp (cur->name, (const xmlChar *)"text") == 0) - { - } - else - { - g_hash_table_replace (ht_attrs, g_strdup (cur->name), (gchar *)xmlNodeGetContent (cur)); - } - - cur = cur->next; - } - - if (id != NULL) - { - ZAK_CGI_FORM_ELEMENT_CLASS (zak_cgi_form_element_submit_parent_class)->construct (ZAK_CGI_FORM_ELEMENT (element), - id, - ht_attrs); - ret = TRUE; - } - else - { - ret = FALSE; - } - - return ret; -} - -static gchar -*zak_cgi_form_element_submit_render (ZakCgiFormElement *element) -{ - gchar *ret; - - GHashTable *ht_attrs; - gchar *attr_class; - GString *str_attr_class; - gchar *form_control; - - ZakCgiFormElementClass *klass; - - klass = (ZakCgiFormElementClass *)g_type_class_peek_parent (ZAK_CGI_FORM_ELEMENT_SUBMIT_GET_CLASS (ZAK_CGI_FORM_ELEMENT_SUBMIT (element))); - - ht_attrs = klass->get_ht_attrs (element); - - attr_class = g_hash_table_lookup (ht_attrs, "class"); - if (attr_class != NULL) - { - str_attr_class = g_string_new (attr_class); - form_control = g_strstr_len (str_attr_class->str, -1, "form-control"); - if (form_control != NULL) - { - /* no form-control for submit button */ - g_string_erase (str_attr_class, form_control - str_attr_class->str, 12); - } - - if (g_strstr_len (attr_class, -1, "btn btn-default") == NULL) - { - g_hash_table_insert (ht_attrs, "class", g_strdup_printf ("%s btn btn-default", str_attr_class->str)); - } - - g_free (attr_class); - g_string_free (str_attr_class, TRUE); - } - else - { - g_hash_table_replace (ht_attrs, g_strdup ("class"), g_strdup ("btn btn-default")); - } - - ret = zak_cgi_tag_submit_ht (zak_cgi_form_element_get_id (element), ht_attrs); - - return ret; -} - -/* PRIVATE */ -static void -zak_cgi_form_element_submit_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - ZakCgiFormElementSubmit *zak_cgi_form_element_submit = (ZakCgiFormElementSubmit *)object; - ZakCgiFormElementSubmitPrivate *priv = ZAK_CGI_FORM_ELEMENT_SUBMIT_GET_PRIVATE (zak_cgi_form_element_submit); - - switch (property_id) - { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -zak_cgi_form_element_submit_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - ZakCgiFormElementSubmit *zak_cgi_form_element_submit = (ZakCgiFormElementSubmit *)object; - ZakCgiFormElementSubmitPrivate *priv = ZAK_CGI_FORM_ELEMENT_SUBMIT_GET_PRIVATE (zak_cgi_form_element_submit); - - switch (property_id) - { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -zak_cgi_form_element_submit_dispose (GObject *gobject) -{ - ZakCgiFormElementSubmit *zak_cgi_form_element_submit = (ZakCgiFormElementSubmit *)gobject; - ZakCgiFormElementSubmitPrivate *priv = ZAK_CGI_FORM_ELEMENT_SUBMIT_GET_PRIVATE (zak_cgi_form_element_submit); - - - - GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject)); - parent_class->dispose (gobject); -} - -static void -zak_cgi_form_element_submit_finalize (GObject *gobject) -{ - ZakCgiFormElementSubmit *zak_cgi_form_element_submit = (ZakCgiFormElementSubmit *)gobject; - ZakCgiFormElementSubmitPrivate *priv = ZAK_CGI_FORM_ELEMENT_SUBMIT_GET_PRIVATE (zak_cgi_form_element_submit); - - - - GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject)); - parent_class->finalize (gobject); -} diff --git a/src/formelementsubmit.h b/src/formelementsubmit.h deleted file mode 100644 index 73be758..0000000 --- a/src/formelementsubmit.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) 2015 Andrea Zagli - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser 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 Lesser 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 - */ - -#ifndef __ZAK_CGI_FORM_ELEMENT_SUBMIT_H__ -#define __ZAK_CGI_FORM_ELEMENT_SUBMIT_H__ - - -#include - -#include - -#include "formelement.h" - - -G_BEGIN_DECLS - - -#define ZAK_CGI_TYPE_FORM_ELEMENT_SUBMIT (zak_cgi_form_element_submit_get_type ()) -#define ZAK_CGI_FORM_ELEMENT_SUBMIT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ZAK_CGI_TYPE_FORM_ELEMENT_SUBMIT, ZakCgiFormElementSubmit)) -#define ZAK_CGI_FORM_ELEMENT_SUBMIT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ZAK_CGI_TYPE_FORM_ELEMENT_SUBMIT, ZakCgiFormElementSubmitClass)) -#define ZAK_CGI_IS_FORM_ELEMENT_SUBMIT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ZAK_CGI_TYPE_FORM_ELEMENT_SUBMIT)) -#define ZAK_CGI_IS_FORM_ELEMENT_SUBMIT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ZAK_CGI_TYPE_FORM_ELEMENT_SUBMIT)) -#define ZAK_CGI_FORM_ELEMENT_SUBMIT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ZAK_CGI_TYPE_FORM_ELEMENT_SUBMIT, ZakCgiFormElementSubmitClass)) - -typedef struct _ZakCgiFormElementSubmit ZakCgiFormElementSubmit; -typedef struct _ZakCgiFormElementSubmitClass ZakCgiFormElementSubmitClass; - -struct _ZakCgiFormElementSubmit - { - ZakCgiFormElement parent_instance; - }; - -struct _ZakCgiFormElementSubmitClass - { - ZakCgiFormElementClass parent_class; - }; - - -GType zak_cgi_form_element_submit_get_type (void); - -ZakCgiFormElement *zak_cgi_form_element_submit_new (void); -ZakCgiFormElement *zak_cgi_form_element_submit_new_attrs (const gchar *id, ...); - -gboolean zak_cgi_form_element_submit_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode); - - -G_END_DECLS - - -#endif /* __ZAK_CGI_FORM_ELEMENT_SUBMIT_H__ */ diff --git a/src/formelementtext.c b/src/formelementtext.c deleted file mode 100644 index aa7b003..0000000 --- a/src/formelementtext.c +++ /dev/null @@ -1,255 +0,0 @@ -/* - * Copyright (C) 2015-2016 Andrea Zagli - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser 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 Lesser 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 - */ - -#ifdef HAVE_CONFIG_H - #include -#endif - -#include "commons.h" -#include "tag.h" -#include "formelementtext.h" - -static void zak_cgi_form_element_text_class_init (ZakCgiFormElementTextClass *class); -static void zak_cgi_form_element_text_init (ZakCgiFormElementText *zak_cgi_form_element_text); - -static gchar *zak_cgi_form_element_text_render (ZakCgiFormElement *element); - -static void zak_cgi_form_element_text_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec); -static void zak_cgi_form_element_text_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec); - -static void zak_cgi_form_element_text_dispose (GObject *gobject); -static void zak_cgi_form_element_text_finalize (GObject *gobject); - -#define ZAK_CGI_FORM_ELEMENT_TEXT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZAK_CGI_TYPE_FORM_ELEMENT_TEXT, ZakCgiFormElementTextPrivate)) - -typedef struct _ZakCgiFormElementTextPrivate ZakCgiFormElementTextPrivate; -struct _ZakCgiFormElementTextPrivate - { - gpointer empty; - }; - -G_DEFINE_TYPE (ZakCgiFormElementText, zak_cgi_form_element_text, ZAK_CGI_TYPE_FORM_ELEMENT) - -static void -zak_cgi_form_element_text_class_init (ZakCgiFormElementTextClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - ZakCgiFormElementClass *elem_class = ZAK_CGI_FORM_ELEMENT_CLASS (klass); - - object_class->set_property = zak_cgi_form_element_text_set_property; - object_class->get_property = zak_cgi_form_element_text_get_property; - object_class->dispose = zak_cgi_form_element_text_dispose; - object_class->finalize = zak_cgi_form_element_text_finalize; - - elem_class->render = zak_cgi_form_element_text_render; - - g_type_class_add_private (object_class, sizeof (ZakCgiFormElementTextPrivate)); -} - -static void -zak_cgi_form_element_text_init (ZakCgiFormElementText *zak_cgi_form_element_text) -{ - ZakCgiFormElementTextPrivate *priv = ZAK_CGI_FORM_ELEMENT_TEXT_GET_PRIVATE (zak_cgi_form_element_text); - -} - -/** - * zak_cgi_form_element_text_new: - * - * Returns: the newly created #ZakCgiFormElementText object. - */ -ZakCgiFormElement -*zak_cgi_form_element_text_new () -{ - ZakCgiFormElementText *zak_cgi_form_element_text; - - zak_cgi_form_element_text = ZAK_CGI_FORM_ELEMENT_TEXT (g_object_new (zak_cgi_form_element_text_get_type (), NULL)); - - return ZAK_CGI_FORM_ELEMENT (zak_cgi_form_element_text); -} - -/** - * zak_cgi_form_element_text_new_attrs: - * @id: - * @...: - * - * Returns: the newly created #ZakCgiFormElementText object. - */ -ZakCgiFormElement -*zak_cgi_form_element_text_new_attrs (const gchar *id, - ...) -{ - va_list ap; - - ZakCgiFormElement *zak_cgi_form_element_text; - - zak_cgi_form_element_text = zak_cgi_form_element_text_new (); - - va_start (ap, id); - - ZAK_CGI_FORM_ELEMENT_CLASS (zak_cgi_form_element_text_parent_class)->construct (zak_cgi_form_element_text, - id, - zak_cgi_commons_valist_to_ghashtable (ap)); - - return zak_cgi_form_element_text; -} - -gboolean -zak_cgi_form_element_text_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode) -{ - gboolean ret; - - gchar *id; - - GHashTable *ht_attrs; - - xmlNode *cur; - - id = NULL; - - ZAK_CGI_FORM_ELEMENT_CLASS (zak_cgi_form_element_text_parent_class)->xml_parsing (element, xmlnode); - - ht_attrs = g_hash_table_new (g_str_hash, g_str_equal); - - cur = xmlnode->children; - while (cur != NULL) - { - if (xmlStrcmp (cur->name, (const xmlChar *)"id") == 0) - { - id = (gchar *)xmlNodeGetContent (cur); - } - else if (xmlStrcmp (cur->name, (const xmlChar *)"label") == 0) - { - zak_cgi_form_element_set_label (ZAK_CGI_FORM_ELEMENT (element), (gchar *)xmlNodeGetContent (cur), NULL); - } - else if (xmlStrcmp (cur->name, (const xmlChar *)"text") == 0) - { - } - else - { - g_hash_table_replace (ht_attrs, g_strdup (cur->name), (gchar *)xmlNodeGetContent (cur)); - } - - cur = cur->next; - } - - if (id != NULL) - { - ZAK_CGI_FORM_ELEMENT_CLASS (zak_cgi_form_element_text_parent_class)->construct (ZAK_CGI_FORM_ELEMENT (element), - id, - ht_attrs); - ret = TRUE; - } - else - { - ret = FALSE; - } - - return ret; -} - -static gchar -*zak_cgi_form_element_text_render (ZakCgiFormElement *element) -{ - gchar *ret; - - GHashTable *ht_attrs; - - gchar *value; - - ZakCgiFormElementClass *klass; - - klass = (ZakCgiFormElementClass *)g_type_class_peek_parent (ZAK_CGI_FORM_ELEMENT_TEXT_GET_CLASS (ZAK_CGI_FORM_ELEMENT_TEXT (element))); - - ht_attrs = klass->get_ht_attrs (element); - - value = zak_form_element_get_value (ZAK_FORM_ELEMENT (element)); - if (value != NULL) - { - g_hash_table_insert (ht_attrs, (gpointer)"value", (gpointer)g_strdup (value)); - } - - ret = zak_cgi_tag_text_ht (zak_cgi_form_element_get_id (element), ht_attrs); - - return ret; -} - -/* PRIVATE */ -static void -zak_cgi_form_element_text_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - ZakCgiFormElementText *zak_cgi_form_element_text = (ZakCgiFormElementText *)object; - ZakCgiFormElementTextPrivate *priv = ZAK_CGI_FORM_ELEMENT_TEXT_GET_PRIVATE (zak_cgi_form_element_text); - - switch (property_id) - { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -zak_cgi_form_element_text_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - ZakCgiFormElementText *zak_cgi_form_element_text = (ZakCgiFormElementText *)object; - ZakCgiFormElementTextPrivate *priv = ZAK_CGI_FORM_ELEMENT_TEXT_GET_PRIVATE (zak_cgi_form_element_text); - - switch (property_id) - { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -zak_cgi_form_element_text_dispose (GObject *gobject) -{ - ZakCgiFormElementText *zak_cgi_form_element_text = (ZakCgiFormElementText *)gobject; - ZakCgiFormElementTextPrivate *priv = ZAK_CGI_FORM_ELEMENT_TEXT_GET_PRIVATE (zak_cgi_form_element_text); - - - - GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject)); - parent_class->dispose (gobject); -} - -static void -zak_cgi_form_element_text_finalize (GObject *gobject) -{ - ZakCgiFormElementText *zak_cgi_form_element_text = (ZakCgiFormElementText *)gobject; - ZakCgiFormElementTextPrivate *priv = ZAK_CGI_FORM_ELEMENT_TEXT_GET_PRIVATE (zak_cgi_form_element_text); - - - - GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject)); - parent_class->finalize (gobject); -} diff --git a/src/formelementtext.h b/src/formelementtext.h deleted file mode 100644 index 157e4de..0000000 --- a/src/formelementtext.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) 2015 Andrea Zagli - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser 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 Lesser 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 - */ - -#ifndef __ZAK_CGI_FORM_ELEMENT_TEXT_H__ -#define __ZAK_CGI_FORM_ELEMENT_TEXT_H__ - - -#include - -#include - -#include "formelement.h" - - -G_BEGIN_DECLS - - -#define ZAK_CGI_TYPE_FORM_ELEMENT_TEXT (zak_cgi_form_element_text_get_type ()) -#define ZAK_CGI_FORM_ELEMENT_TEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ZAK_CGI_TYPE_FORM_ELEMENT_TEXT, ZakCgiFormElementText)) -#define ZAK_CGI_FORM_ELEMENT_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ZAK_CGI_TYPE_FORM_ELEMENT_TEXT, ZakCgiFormElementTextClass)) -#define ZAK_CGI_IS_FORM_ELEMENT_TEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ZAK_CGI_TYPE_FORM_ELEMENT_TEXT)) -#define ZAK_CGI_IS_FORM_ELEMENT_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ZAK_CGI_TYPE_FORM_ELEMENT_TEXT)) -#define ZAK_CGI_FORM_ELEMENT_TEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ZAK_CGI_TYPE_FORM_ELEMENT_TEXT, ZakCgiFormElementTextClass)) - -typedef struct _ZakCgiFormElementText ZakCgiFormElementText; -typedef struct _ZakCgiFormElementTextClass ZakCgiFormElementTextClass; - -struct _ZakCgiFormElementText - { - ZakCgiFormElement parent_instance; - }; - -struct _ZakCgiFormElementTextClass - { - ZakCgiFormElementClass parent_class; - }; - - -GType zak_cgi_form_element_text_get_type (void); - -ZakCgiFormElement *zak_cgi_form_element_text_new (void); -ZakCgiFormElement *zak_cgi_form_element_text_new_attrs (const gchar *id, ...); - -gboolean zak_cgi_form_element_text_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode); - - -G_END_DECLS - - -#endif /* __ZAK_CGI_FORM_ELEMENT_TEXT_H__ */ diff --git a/src/formelementtextarea.c b/src/formelementtextarea.c deleted file mode 100644 index 05bb645..0000000 --- a/src/formelementtextarea.c +++ /dev/null @@ -1,255 +0,0 @@ -/* - * Copyright (C) 2015-2016 Andrea Zagli - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser 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 Lesser 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 - */ - -#ifdef HAVE_CONFIG_H - #include -#endif - -#include "commons.h" -#include "tag.h" -#include "formelementtextarea.h" - -static void zak_cgi_form_element_text_area_class_init (ZakCgiFormElementTextAreaClass *class); -static void zak_cgi_form_element_text_area_init (ZakCgiFormElementTextArea *zak_cgi_form_element_text_area); - -static gchar *zak_cgi_form_element_text_area_render (ZakCgiFormElement *element); - -static void zak_cgi_form_element_text_area_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec); -static void zak_cgi_form_element_text_area_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec); - -static void zak_cgi_form_element_text_area_dispose (GObject *gobject); -static void zak_cgi_form_element_text_area_finalize (GObject *gobject); - -#define ZAK_CGI_FORM_ELEMENT_TEXT_AREA_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZAK_CGI_TYPE_FORM_ELEMENT_TEXT_AREA, ZakCgiFormElementTextAreaPrivate)) - -typedef struct _ZakCgiFormElementTextAreaPrivate ZakCgiFormElementTextAreaPrivate; -struct _ZakCgiFormElementTextAreaPrivate - { - gpointer empty; - }; - -G_DEFINE_TYPE (ZakCgiFormElementTextArea, zak_cgi_form_element_text_area, ZAK_CGI_TYPE_FORM_ELEMENT) - -static void -zak_cgi_form_element_text_area_class_init (ZakCgiFormElementTextAreaClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - ZakCgiFormElementClass *elem_class = ZAK_CGI_FORM_ELEMENT_CLASS (klass); - - object_class->set_property = zak_cgi_form_element_text_area_set_property; - object_class->get_property = zak_cgi_form_element_text_area_get_property; - object_class->dispose = zak_cgi_form_element_text_area_dispose; - object_class->finalize = zak_cgi_form_element_text_area_finalize; - - elem_class->render = zak_cgi_form_element_text_area_render; - - g_type_class_add_private (object_class, sizeof (ZakCgiFormElementTextAreaPrivate)); -} - -static void -zak_cgi_form_element_text_area_init (ZakCgiFormElementTextArea *zak_cgi_form_element_text_area) -{ - ZakCgiFormElementTextAreaPrivate *priv = ZAK_CGI_FORM_ELEMENT_TEXT_AREA_GET_PRIVATE (zak_cgi_form_element_text_area); - -} - -/** - * zak_cgi_form_element_text_area_new: - * - * Returns: the newly created #ZakCgiFormElementTextArea object. - */ -ZakCgiFormElement -*zak_cgi_form_element_text_area_new () -{ - ZakCgiFormElementTextArea *zak_cgi_form_element_text_area; - - zak_cgi_form_element_text_area = ZAK_CGI_FORM_ELEMENT_TEXT_AREA (g_object_new (zak_cgi_form_element_text_area_get_type (), NULL)); - - return ZAK_CGI_FORM_ELEMENT (zak_cgi_form_element_text_area); -} - -/** - * zak_cgi_form_element_text_area_new_attrs: - * @id: - * @...: - * - * Returns: the newly created #ZakCgiFormElementTextArea object. - */ -ZakCgiFormElement -*zak_cgi_form_element_text_area_new_attrs (const gchar *id, - ...) -{ - va_list ap; - - ZakCgiFormElement *zak_cgi_form_element_text_area; - - zak_cgi_form_element_text_area = zak_cgi_form_element_text_area_new (); - - va_start (ap, id); - - ZAK_CGI_FORM_ELEMENT_CLASS (zak_cgi_form_element_text_area_parent_class)->construct (zak_cgi_form_element_text_area, - id, - zak_cgi_commons_valist_to_ghashtable (ap)); - - return zak_cgi_form_element_text_area; -} - -gboolean -zak_cgi_form_element_text_area_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode) -{ - gboolean ret; - - gchar *id; - - GHashTable *ht_attrs; - - xmlNode *cur; - - id = NULL; - - ZAK_CGI_FORM_ELEMENT_CLASS (zak_cgi_form_element_text_area_parent_class)->xml_parsing (element, xmlnode); - - ht_attrs = g_hash_table_new (g_str_hash, g_str_equal); - - cur = xmlnode->children; - while (cur != NULL) - { - if (xmlStrcmp (cur->name, (const xmlChar *)"id") == 0) - { - id = (gchar *)xmlNodeGetContent (cur); - } - else if (xmlStrcmp (cur->name, (const xmlChar *)"label") == 0) - { - zak_cgi_form_element_set_label (ZAK_CGI_FORM_ELEMENT (element), (gchar *)xmlNodeGetContent (cur), NULL); - } - else if (xmlStrcmp (cur->name, (const xmlChar *)"text") == 0) - { - } - else - { - g_hash_table_replace (ht_attrs, g_strdup (cur->name), (gchar *)xmlNodeGetContent (cur)); - } - - cur = cur->next; - } - - if (id != NULL) - { - ZAK_CGI_FORM_ELEMENT_CLASS (zak_cgi_form_element_text_area_parent_class)->construct (ZAK_CGI_FORM_ELEMENT (element), - id, - ht_attrs); - ret = TRUE; - } - else - { - ret = FALSE; - } - - return ret; -} - -static gchar -*zak_cgi_form_element_text_area_render (ZakCgiFormElement *element) -{ - gchar *ret; - - GHashTable *ht_attrs; - - gchar *value; - - ZakCgiFormElementClass *klass; - - klass = (ZakCgiFormElementClass *)g_type_class_peek_parent (ZAK_CGI_FORM_ELEMENT_TEXT_AREA_GET_CLASS (ZAK_CGI_FORM_ELEMENT_TEXT_AREA (element))); - - ht_attrs = klass->get_ht_attrs (element); - - value = zak_form_element_get_value (ZAK_FORM_ELEMENT (element)); - if (value != NULL) - { - g_hash_table_insert (ht_attrs, (gpointer)"zak-cgi-content", (gpointer)g_strdup (value)); - } - - ret = zak_cgi_tag_tag_ht ("textarea", zak_cgi_form_element_get_id (element), ht_attrs); - - return ret; -} - -/* PRIVATE */ -static void -zak_cgi_form_element_text_area_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - ZakCgiFormElementTextArea *zak_cgi_form_element_text_area = (ZakCgiFormElementTextArea *)object; - ZakCgiFormElementTextAreaPrivate *priv = ZAK_CGI_FORM_ELEMENT_TEXT_AREA_GET_PRIVATE (zak_cgi_form_element_text_area); - - switch (property_id) - { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -zak_cgi_form_element_text_area_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - ZakCgiFormElementTextArea *zak_cgi_form_element_text_area = (ZakCgiFormElementTextArea *)object; - ZakCgiFormElementTextAreaPrivate *priv = ZAK_CGI_FORM_ELEMENT_TEXT_AREA_GET_PRIVATE (zak_cgi_form_element_text_area); - - switch (property_id) - { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -zak_cgi_form_element_text_area_dispose (GObject *gobject) -{ - ZakCgiFormElementTextArea *zak_cgi_form_element_text_area = (ZakCgiFormElementTextArea *)gobject; - ZakCgiFormElementTextAreaPrivate *priv = ZAK_CGI_FORM_ELEMENT_TEXT_AREA_GET_PRIVATE (zak_cgi_form_element_text_area); - - - - GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject)); - parent_class->dispose (gobject); -} - -static void -zak_cgi_form_element_text_area_finalize (GObject *gobject) -{ - ZakCgiFormElementTextArea *zak_cgi_form_element_text_area = (ZakCgiFormElementTextArea *)gobject; - ZakCgiFormElementTextAreaPrivate *priv = ZAK_CGI_FORM_ELEMENT_TEXT_AREA_GET_PRIVATE (zak_cgi_form_element_text_area); - - - - GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject)); - parent_class->finalize (gobject); -} diff --git a/src/formelementtextarea.h b/src/formelementtextarea.h deleted file mode 100644 index 308fcd6..0000000 --- a/src/formelementtextarea.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) 2015 Andrea Zagli - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser 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 Lesser 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 - */ - -#ifndef __ZAK_CGI_FORM_ELEMENT_TEXT_AREA_H__ -#define __ZAK_CGI_FORM_ELEMENT_TEXT_AREA_H__ - - -#include - -#include - -#include "formelement.h" - - -G_BEGIN_DECLS - - -#define ZAK_CGI_TYPE_FORM_ELEMENT_TEXT_AREA (zak_cgi_form_element_text_area_get_type ()) -#define ZAK_CGI_FORM_ELEMENT_TEXT_AREA(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), ZAK_CGI_TYPE_FORM_ELEMENT_TEXT_AREA, ZakCgiFormElementTextArea)) -#define ZAK_CGI_FORM_ELEMENT_TEXT_AREA_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), ZAK_CGI_TYPE_FORM_ELEMENT_TEXT_AREA, ZakCgiFormElementTextAreaClass)) -#define ZAK_CGI_IS_FORM_ELEMENT_TEXT_AREA(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), ZAK_CGI_TYPE_FORM_ELEMENT_TEXT_AREA)) -#define ZAK_CGI_IS_FORM_ELEMENT_TEXT_AREA_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), ZAK_CGI_TYPE_FORM_ELEMENT_TEXT_AREA)) -#define ZAK_CGI_FORM_ELEMENT_TEXT_AREA_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), ZAK_CGI_TYPE_FORM_ELEMENT_TEXT_AREA, ZakCgiFormElementTextAreaClass)) - -typedef struct _ZakCgiFormElementTextArea ZakCgiFormElementTextArea; -typedef struct _ZakCgiFormElementTextAreaClass ZakCgiFormElementTextAreaClass; - -struct _ZakCgiFormElementTextArea - { - ZakCgiFormElement parent_instance; - }; - -struct _ZakCgiFormElementTextAreaClass - { - ZakCgiFormElementClass parent_class; - }; - - -GType zak_cgi_form_element_text_area_get_type (void); - -ZakCgiFormElement *zak_cgi_form_element_text_area_new (void); -ZakCgiFormElement *zak_cgi_form_element_text_area_new_attrs (const gchar *id, ...); - -gboolean zak_cgi_form_element_text_area_xml_parsing (ZakFormElement *element, xmlNodePtr xmlnode); - - -G_END_DECLS - - -#endif /* __ZAK_CGI_FORM_ELEMENT_TEXT_AREA_H__ */ diff --git a/src/libzakcgi.h b/src/libzakcgi.h index ac36e95..b943b41 100644 --- a/src/libzakcgi.h +++ b/src/libzakcgi.h @@ -19,6 +19,7 @@ #ifndef __LIBZAKCGI_H__ #define __LIBZAKCGI_H__ +#include #include #include #include diff --git a/src/session.c b/src/session.c index f2c62c4..2c064f0 100644 --- a/src/session.c +++ b/src/session.c @@ -31,8 +31,6 @@ #include -#include - #include "session.h" enum @@ -72,7 +70,6 @@ struct _ZakCgiSessionPrivate gchar *sid; GFile *gfile; GKeyFile *kfile; - ZakFormIniProvider *zakformini; gint minutes; }; @@ -111,7 +108,6 @@ zak_cgi_session_init (ZakCgiSession *zak_cgi_session) priv->path = NULL; priv->gfile = NULL; priv->kfile = NULL; - priv->zakformini = NULL; priv->minutes = MINUTES_DEFAULT; } @@ -468,46 +464,6 @@ zak_cgi_session_get_value_full_boolean (ZakCgiSession *session, const gchar *gro return (gboolean)zak_cgi_session_get_value_full_int (session, group, name); } -static ZakFormIniProvider -*zak_cgi_session_get_form_ini_provider (ZakCgiSession *session) -{ - ZakCgiSessionPrivate *priv = ZAK_CGI_SESSION_GET_PRIVATE (session); - - if (priv->zakformini == NULL) - { - priv->zakformini = zak_form_ini_provider_new_from_gkeyfile (priv->kfile, g_file_get_path (priv->gfile)); - } - - return priv->zakformini; -} - -/** - * zak_cgi_session_set_from_form: - * @session: - * @form: - * - */ -void -zak_cgi_session_set_from_form (ZakCgiSession *session, ZakFormForm *form) -{ - zak_form_form_insert (ZAK_FORM_FORM (form), ZAK_FORM_IPROVIDER (zak_cgi_session_get_form_ini_provider (session))); -} - -/** - * zak_cgi_session_fill_form: - * @session: - * @form: - * - */ -void -zak_cgi_session_fill_form (ZakCgiSession *session, ZakFormForm *form) -{ - ZakCgiSessionPrivate *priv = ZAK_CGI_SESSION_GET_PRIVATE (session); - - zak_cgi_session_get_form_ini_provider (session); - zak_form_form_load (ZAK_FORM_FORM (form), ZAK_FORM_IPROVIDER (priv->zakformini)); -} - /** * zak_cgi_session_is_valid: * @session: @@ -613,6 +569,34 @@ zak_cgi_session_is_valid (ZakCgiSession *session) return ret; } +/** + * zak_cgi_session_get_gkeyfile: + * @session: + * + * Returns: + */ +GKeyFile +*zak_cgi_session_get_gkeyfile (ZakCgiSession *session) +{ + ZakCgiSessionPrivate *priv = ZAK_CGI_SESSION_GET_PRIVATE (session); + + return priv->kfile; +} + +/** + * zak_cgi_session_get_gfile: + * @session: + * + * Returns: + */ +GFile +*zak_cgi_session_get_gfile (ZakCgiSession *session) +{ + ZakCgiSessionPrivate *priv = ZAK_CGI_SESSION_GET_PRIVATE (session); + + return priv->gfile; +} + /** * zak_cgi_session_close: * @session: diff --git a/src/session.h b/src/session.h index c56d46b..85dca75 100644 --- a/src/session.h +++ b/src/session.h @@ -21,8 +21,7 @@ #include - -#include +#include #include "main.h" @@ -80,11 +79,11 @@ gint zak_cgi_session_get_value_full_int (ZakCgiSession *session, const gchar *gr gdouble zak_cgi_session_get_value_full_double (ZakCgiSession *session, const gchar *group, const gchar *name); gboolean zak_cgi_session_get_value_full_boolean (ZakCgiSession *session, const gchar *group, const gchar *name); -void zak_cgi_session_set_from_form (ZakCgiSession *session, ZakFormForm *form); -void zak_cgi_session_fill_form (ZakCgiSession *session, ZakFormForm *form); - gboolean zak_cgi_session_is_valid (ZakCgiSession *session); +GKeyFile *zak_cgi_session_get_gkeyfile (ZakCgiSession *session); +GFile *zak_cgi_session_get_gfile (ZakCgiSession *session); + void zak_cgi_session_close (ZakCgiSession *session); diff --git a/tests/Makefile.am b/tests/Makefile.am index c888c63..8b1b046 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -11,13 +11,10 @@ LDADD = $(top_builddir)/src/libzakcgi.la noinst_PROGRAMS = \ cookies \ env \ - form \ - form_xml \ querystring \ redirect \ session \ tag \ url -EXTRA_DIST = \ - form_xml.xml +EXTRA_DIST = diff --git a/tests/form.c b/tests/form.c deleted file mode 100644 index 33e2c09..0000000 --- a/tests/form.c +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright (C) 2015-2016 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 - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -int -main (int argc, char *argv[]) -{ - ZakCgiMain *zakcgimain; - - GString *str; - - ZakCgiForm *form; - ZakCgiFormElement *element; - - ZakFormElementValidatorRegex *validator; - - zakcgimain = zak_cgi_main_new (); - - str = g_string_new ("\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "Form test\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "
\n"); - - form = zak_cgi_form_new (zakcgimain, - "method", "post", - "action", "form", - NULL); - - element = zak_cgi_form_element_text_new_attrs ("first", NULL); - zak_cgi_form_element_set_label (element, "The Label for first", NULL); - zak_form_element_add_filter (ZAK_FORM_ELEMENT (element), - ZAK_FORM_ELEMENT_FILTER (zak_form_element_filter_trim_new ())); - validator = zak_form_element_validator_regex_new (); - zak_form_element_validator_regex_set_regex (validator, "^aaa$"); - zak_form_element_add_validator (ZAK_FORM_ELEMENT (element), ZAK_FORM_ELEMENT_VALIDATOR (validator)); - zak_form_form_add_element (ZAK_FORM_FORM (form), ZAK_FORM_ELEMENT (element)); - - element = zak_cgi_form_element_check_new_attrs ("chk", NULL); - zak_cgi_form_element_set_label (element, "The checkbox", NULL); - zak_form_form_add_element (ZAK_FORM_FORM (form), ZAK_FORM_ELEMENT (element)); - - element = zak_cgi_form_element_string_new_attrs ("

big big big

"); - zak_form_form_add_element (ZAK_FORM_FORM (form), ZAK_FORM_ELEMENT (element)); - - element = zak_cgi_form_element_password_new_attrs ("pws", NULL); - zak_cgi_form_element_set_label (element, "The password", NULL); - zak_form_form_add_element (ZAK_FORM_FORM (form), ZAK_FORM_ELEMENT (element)); - - element = zak_cgi_form_element_text_area_new_attrs ("txtarea", NULL); - zak_cgi_form_element_set_label (element, "The text area", NULL); - zak_form_form_add_element (ZAK_FORM_FORM (form), ZAK_FORM_ELEMENT (element)); - - element = zak_cgi_form_element_select_new_attrs ("slc", NULL); - zak_cgi_form_element_select_add_option (ZAK_CGI_FORM_ELEMENT_SELECT (element), "1", "first", NULL); - zak_cgi_form_element_select_add_option (ZAK_CGI_FORM_ELEMENT_SELECT (element), "2", "second", NULL); - zak_cgi_form_element_select_add_option (ZAK_CGI_FORM_ELEMENT_SELECT (element), "3", "third", NULL); - zak_form_form_add_element (ZAK_FORM_FORM (form), ZAK_FORM_ELEMENT (element)); - - element = zak_cgi_form_element_hidden_new_attrs ("hdn", NULL); - zak_form_form_add_element (ZAK_FORM_FORM (form), ZAK_FORM_ELEMENT (element)); - - element = zak_cgi_form_element_submit_new_attrs ("submit", "zak-cgi-content", "Submit", NULL); - zak_form_form_add_element (ZAK_FORM_FORM (form), ZAK_FORM_ELEMENT (element)); - - if (zak_cgi_main_is_post (zakcgimain)) - { - /* validating the form */ - zak_cgi_form_bind (form); - if (zak_form_form_is_valid (ZAK_FORM_FORM (form))) - { - g_string_append (str, "Form is valid!!!"); - } - else - { - g_string_append (str, zak_cgi_form_render (form)); - g_string_append (str, "Form is not valid!!!"); - } - } - else - { - g_string_append (str, zak_cgi_form_render (form)); - } - - g_string_append (str, - "\n
\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "\n" - ""); - - zak_cgi_main_out (NULL, str->str); - - return 0; -} diff --git a/tests/form_xml.c b/tests/form_xml.c deleted file mode 100644 index 970b5da..0000000 --- a/tests/form_xml.c +++ /dev/null @@ -1,106 +0,0 @@ -/* - * 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 - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -int -main (int argc, char *argv[]) -{ - ZakCgiMain *zakcgimain; - - GString *str; - - GValue *val; - gchar *filename; - - ZakCgiForm *form; - ZakCgiFormElement *element; - - zakcgimain = zak_cgi_main_new (); - - str = g_string_new ("\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "Form test\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "
\n"); - - val = zak_cgi_main_get_parameter (zakcgimain, "filename"); - filename = (gchar *)g_value_get_string (val); - - form = zak_cgi_form_new (zakcgimain, - "method", "post", - "action", g_strdup_printf ("form_xml?filename=%s", filename), - NULL); - - if (zak_form_form_load_from_file (ZAK_FORM_FORM (form), filename)) - { - if (zak_cgi_main_is_post (zakcgimain)) - { - /* validating the form */ - zak_cgi_form_bind (form); - if (zak_form_form_is_valid (ZAK_FORM_FORM (form))) - { - g_string_append (str, "Form is valid!!!"); - } - else - { - g_string_append (str, zak_cgi_form_render (form)); - g_string_append (str, "Form is not valid!!!"); - } - } - else - { - g_string_append (str, zak_cgi_form_render (form)); - } - } - - g_string_append (str, - "\n
\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "\n" - ""); - - zak_cgi_main_out (NULL, str->str); - - return 0; -} diff --git a/tests/form_xml.xml b/tests/form_xml.xml deleted file mode 100644 index 5146bd1..0000000 --- a/tests/form_xml.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - - - first - - - ^blahblahblah$ - - - - chk - - - - - <h1>big big big</h1> - - - - pws - - - - - txtarea - - - - - slc - - - - - - - hdn - - - - submit - Submit - - - -- 2.49.0