libzakcgi_la_SOURCES = \
form.c \
formelement.c \
+ formelementtext.c \
main.c \
session.c \
tag.c \
libzakcgi.h \
form.h \
formelement.h \
+ formelementtext.h \
main.h \
session.h \
tag.h \
#include "formelement.h"
+enum
+{
+ PROP_0,
+ PROP_VALIDATION_REGEX
+};
+
static void zak_cgi_form_element_class_init (ZakCgiFormElementClass *class);
static void zak_cgi_form_element_init (ZakCgiFormElement *zak_cgi_form_element);
typedef struct _ZakCgiFormElementPrivate ZakCgiFormElementPrivate;
struct _ZakCgiFormElementPrivate
{
+ gchar *validation_regex;
};
G_DEFINE_TYPE (ZakCgiFormElement, zak_cgi_form_element, G_TYPE_OBJECT)
object_class->finalize = zak_cgi_form_element_finalize;
g_type_class_add_private (object_class, sizeof (ZakCgiFormElementPrivate));
+
+ g_object_class_install_property (object_class, PROP_VALIDATION_REGEX,
+ g_param_spec_string ("validation-regex",
+ "Validation regex",
+ "Validation regex",
+ "",
+ G_PARAM_READWRITE));
}
static void
{
ZakCgiFormElementPrivate *priv = ZAK_CGI_FORM_ELEMENT_GET_PRIVATE (zak_cgi_form_element);
-
+ priv->validation_regex = NULL;
}
/**
* zak_cgi_form_element_new:
+ * @validation_regex:
*
* Returns: the newly created #ZakCgiFormElement object.
*/
ZakCgiFormElement
-*zak_cgi_form_element_new (void)
+*zak_cgi_form_element_new (const gchar *validation_regex)
{
ZakCgiFormElement *zak_cgi_form_element;
ZakCgiFormElementPrivate *priv;
priv = ZAK_CGI_FORM_ELEMENT_GET_PRIVATE (zak_cgi_form_element);
+ zak_cgi_form_element_set_validation_regex (zak_cgi_form_element, validation_regex);
+
return zak_cgi_form_element;
}
+void
+zak_cgi_form_element_set_validation_regex (ZakCgiFormElement *element, const gchar *validation_regex)
+{
+ ZakCgiFormElementPrivate *priv;
+
+ priv = ZAK_CGI_FORM_ELEMENT_GET_PRIVATE (element);
+
+ if (validation_regex == NULL)
+ {
+ if (priv->validation_regex != NULL)
+ {
+ g_free (priv->validation_regex);
+ }
+ priv->validation_regex = NULL;
+ }
+ else
+ {
+ priv->validation_regex = g_strdup (validation_regex);
+ }
+}
+
+gchar
+*zak_cgi_form_element_get_validation_regex (ZakCgiFormElement *element)
+{
+ gchar *ret;
+
+ ZakCgiFormElementPrivate *priv;
+
+ priv = ZAK_CGI_FORM_ELEMENT_GET_PRIVATE (element);
+
+ if (priv->validation_regex != NULL)
+ {
+ ret = g_strdup (priv->validation_regex);
+ }
+ else
+ {
+ ret = NULL;
+ }
+
+ return ret;
+}
+
+/**
+ * zak_cgi_form_element_render:
+ * @element:
+ *
+ */
+gchar
+*zak_cgi_form_element_render (ZakCgiFormElement *element)
+{
+ gchar *ret;
+
+ ret = g_strdup ("");
+
+ if (ZAK_CGI_IS_FORM_ELEMENT (element) && ZAK_CGI_FORM_ELEMENT_GET_CLASS (element)->render != NULL)
+ {
+ ret = ZAK_CGI_FORM_ELEMENT_CLASS (element)->render (element);
+ }
+
+ return ret;
+}
+
+/**
+ * zak_cgi_form_element_is_valid:
+ * @element:
+ *
+ */
+gboolean
+zak_cgi_form_element_is_valid (ZakCgiFormElement *element)
+{
+ gboolean ret;
+
+ ret = FALSE;
+
+ if (ZAK_CGI_IS_FORM_ELEMENT (element) && ZAK_CGI_FORM_ELEMENT_GET_CLASS (element)->is_valid != NULL)
+ {
+ ret = ZAK_CGI_FORM_ELEMENT_CLASS (element)->is_valid (element);
+ }
+
+ return ret;
+}
+
/* PRIVATE */
static void
zak_cgi_form_element_set_property (GObject *object,
switch (property_id)
{
+ case PROP_VALIDATION_REGEX:
+ zak_cgi_form_element_set_validation_regex (zak_cgi_form_element, g_value_get_string (value));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
switch (property_id)
{
+ case PROP_VALIDATION_REGEX:
+ g_value_set_string (value, zak_cgi_form_element_get_validation_regex (zak_cgi_form_element));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
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);
}
struct _ZakCgiFormElementClass
{
GObjectClass parent_class;
+
+ gchar *(*render) (ZakCgiFormElement *element);
+ gboolean (*is_valid) (ZakCgiFormElement *element);
};
GType zak_cgi_form_element_get_type (void);
-ZakCgiFormElement *zak_cgi_form_element_new (void);
+ZakCgiFormElement *zak_cgi_form_element_new (const gchar *validation_regex);
+
+void zak_cgi_form_element_set_validation_regex (ZakCgiFormElement *element, const gchar *validation_regex);
+gchar *zak_cgi_form_element_get_validation_regex (ZakCgiFormElement *element);
+
+gchar *zak_cgi_form_element_render (ZakCgiFormElement *element);
+
+gboolean zak_cgi_form_element_is_valid (ZakCgiFormElement *element);
G_END_DECLS
--- /dev/null
+/*
+ * Copyright (C) 2015 Andrea Zagli <azagli@libero.it>
+ *
+ * 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 <config.h>
+#endif
+
+#include <syslog.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 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
+ {
+ };
+
+G_DEFINE_TYPE (ZakCgiFormElementText, zak_cgi_form_element_text, G_TYPE_OBJECT)
+
+static void
+zak_cgi_form_element_text_class_init (ZakCgiFormElementTextClass *class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+ 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;
+
+ 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:
+ * @validation_regex:
+ *
+ * Returns: the newly created #ZakCgiFormElementText object.
+ */
+ZakCgiFormElementText
+*zak_cgi_form_element_text_new (const gchar *validation_regex)
+{
+ ZakCgiFormElementText *zak_cgi_form_element_text;
+ ZakCgiFormElementTextPrivate *priv;
+
+ zak_cgi_form_element_text = ZAK_CGI_FORM_ELEMENT_TEXT (g_object_new (zak_cgi_form_element_text_get_type (), NULL));
+
+ priv = ZAK_CGI_FORM_ELEMENT_TEXT_GET_PRIVATE (zak_cgi_form_element_text);
+
+ if (validation_regex != NULL)
+ {
+ }
+
+ return zak_cgi_form_element_text;
+}
+
+/**
+ * zak_cgi_form_element_text_render:
+ * @element_text:
+ *
+ */
+gchar
+*zak_cgi_form_element_text_render (ZakCgiFormElementText *element_text)
+{
+ gchar *ret;
+
+
+ return ret;
+}
+
+/**
+ * zak_cgi_form_element_text_is_valid:
+ * @element_text:
+ *
+ */
+gboolean
+zak_cgi_form_element_text_is_valid (ZakCgiFormElementText *element_text)
+{
+ gboolean ret;
+
+
+ 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);
+}
--- /dev/null
+/*
+ * Copyright (C) 2015 Andrea Zagli <azagli@libero.it>
+ *
+ * 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 <glib-object.h>
+
+#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);
+
+ZakCgiFormElementText *zak_cgi_form_element_text_new (const gchar *validation_regex);
+
+gchar *zak_cgi_form_element_text_render (ZakCgiFormElementText *element_text);
+
+gboolean zak_cgi_form_element_text_is_valid (ZakCgiFormElementText *element_text);
+
+
+G_END_DECLS
+
+
+#endif /* __ZAK_CGI_FORM_ELEMENT_TEXT_H__ */