tests/cookies
tests/env
tests/form
+tests/form_xml
tests/querystring
tests/redirect
tests/session
+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) \
url.h
libzakcgi_includedir = $(includedir)/libzakcgi
+
+install-exec-hook:
+ cd $(libzakformmodulesdir) && \
+ ln -s -f $(libmodulesdir)/libzakcgi$(libmodulesext) .
+
+uninstall-hook:
+ rm -f $(libzakformmodulesdir)/libzakcgi$(libmodulesext)
/**
* 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 (const gchar *id,
- ...)
+*zak_cgi_form_element_check_new_attrs (const gchar *id,
+ ...)
{
va_list ap;
GHashTable *ht_attrs;
- ZakCgiFormElementCheck *zak_cgi_form_element_check;
+ ZakCgiFormElement *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));
+ 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 (zak_cgi_form_element_check),
- id,
- ht_attrs);
+ 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 (zak_cgi_form_element_check);
+ 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;
+
+ 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
#include <glib-object.h>
+#include <libxml/tree.h>
+
#include "formelement.h"
GType zak_cgi_form_element_check_get_type (void);
-ZakCgiFormElement *zak_cgi_form_element_check_new (const gchar *id, ...);
+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
/**
* 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 (const gchar *id,
- ...)
+*zak_cgi_form_element_hidden_new_attrs (const gchar *id,
+ ...)
{
va_list ap;
GHashTable *ht_attrs;
- ZakCgiFormElementHidden *zak_cgi_form_element_hidden;
+ ZakCgiFormElement *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));
+ 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 (zak_cgi_form_element_hidden),
- id,
- ht_attrs);
+ 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 (zak_cgi_form_element_hidden);
+ 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;
+
+ 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
#include <glib-object.h>
+#include <libxml/tree.h>
+
#include "formelement.h"
GType zak_cgi_form_element_hidden_get_type (void);
-ZakCgiFormElement *zak_cgi_form_element_hidden_new (const gchar *id, ...);
+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
/**
* 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 (const gchar *id,
- ...)
+*zak_cgi_form_element_password_new_attrs (const gchar *id,
+ ...)
{
va_list ap;
GHashTable *ht_attrs;
- ZakCgiFormElementPassword *zak_cgi_form_element_password;
+ ZakCgiFormElement *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));
+ 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 (zak_cgi_form_element_password),
- id,
- ht_attrs);
+ 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 (zak_cgi_form_element_password);
+ 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;
+
+ 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
#include <glib-object.h>
+#include <libxml/tree.h>
+
#include "formelement.h"
GType zak_cgi_form_element_password_get_type (void);
-ZakCgiFormElement *zak_cgi_form_element_password_new (const gchar *id, ...);
+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
/**
* 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 (const gchar *id,
- ...)
+*zak_cgi_form_element_select_new_attrs (const gchar *id,
+ ...)
{
va_list ap;
- ZakCgiFormElementSelect *zak_cgi_form_element_select;
+ ZakCgiFormElement *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));
+ 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 (zak_cgi_form_element_select),
- id,
- zak_cgi_commons_valist_to_ghashtable (ap));
+ 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 (zak_cgi_form_element_select);
+ return zak_cgi_form_element_select;
}
/**
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;
+
+ 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)
{
#include <glib-object.h>
+#include <libxml/tree.h>
+
#include "formelement.h"
GType zak_cgi_form_element_select_get_type (void);
-ZakCgiFormElement *zak_cgi_form_element_select_new (const gchar *id, ...);
+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
/**
* zak_cgi_form_element_string_new:
- * @str:
*
* Returns: the newly created #ZakCgiFormElementString object.
*/
ZakCgiFormElement
-*zak_cgi_form_element_string_new (const gchar *str)
+*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 (zak_cgi_form_element_string);
+ 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;
+
+ 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
#include <glib-object.h>
+#include <libxml/tree.h>
+
#include "formelement.h"
GType zak_cgi_form_element_string_get_type (void);
-ZakCgiFormElement *zak_cgi_form_element_string_new (const gchar *str);
+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
/**
* 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 (const gchar *id,
- ...)
+*zak_cgi_form_element_submit_new_attrs (const gchar *id,
+ ...)
{
va_list ap;
- ZakCgiFormElementSubmit *zak_cgi_form_element_submit;
+ ZakCgiFormElement *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));
+ 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 (zak_cgi_form_element_submit),
+ 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 (zak_cgi_form_element_submit);
+ 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;
+
+ 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
#include <glib-object.h>
+#include <libxml/tree.h>
+
#include "formelement.h"
GType zak_cgi_form_element_submit_get_type (void);
-ZakCgiFormElement *zak_cgi_form_element_submit_new (const gchar *id, ...);
+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
/**
* 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 (const gchar *id,
- ...)
+*zak_cgi_form_element_text_new_attrs (const gchar *id,
+ ...)
{
va_list ap;
- ZakCgiFormElementText *zak_cgi_form_element_text;
+ ZakCgiFormElement *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));
+ 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 (zak_cgi_form_element_text),
+ 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 (zak_cgi_form_element_text);
+ 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;
+
+ 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
#include <glib-object.h>
+#include <libxml/tree.h>
+
#include "formelement.h"
GType zak_cgi_form_element_text_get_type (void);
-ZakCgiFormElement *zak_cgi_form_element_text_new (const gchar *id, ...);
+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
/**
* 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 (const gchar *id,
- ...)
+*zak_cgi_form_element_text_area_new_attrs (const gchar *id,
+ ...)
{
va_list ap;
- ZakCgiFormElementTextArea *zak_cgi_form_element_text_area;
+ ZakCgiFormElement *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));
+ 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 (zak_cgi_form_element_text_area),
+ 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 (zak_cgi_form_element_text_area);
+ 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;
+
+ 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
#include <glib-object.h>
+#include <libxml/tree.h>
+
#include "formelement.h"
GType zak_cgi_form_element_text_area_get_type (void);
-ZakCgiFormElement *zak_cgi_form_element_text_area_new (const gchar *id, ...);
+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
}
/**
- * zak_cgi_main_get_param:
+ * zak_cgi_main_get_parameter:
* @zakcgimain:
* @param:
*
* Returns:
*/
GValue
-*zak_cgi_main_get_param (ZakCgiMain *zakcgimain, const gchar *param)
+*zak_cgi_main_get_parameter (ZakCgiMain *zakcgimain, const gchar *param)
{
ZakCgiMainPrivate *priv;
G_DEPRECATED_FOR (zak_cgi_main_get_parameter)
GHashTable *zak_cgi_main_get_parameters (ZakCgiMain *zakcgimain, const gchar *query_string);
-gchar *zak_cgi_main_get_parameter (ZakCgiMain *zakcgimain, const gchar *param);
+GValue *zak_cgi_main_get_parameter (ZakCgiMain *zakcgimain, const gchar *param);
void zak_cgi_main_parameters_foreach (ZakCgiMain *zakcgimain, GHFunc func, gpointer user_data);
cookies \
env \
form \
+ form_xml \
querystring \
redirect \
session \
tag \
url
+
+EXTRA_DIST = \
+ form_xml.xml
"action", "form",
NULL);
- element = zak_cgi_form_element_text_new ("first", 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 ()));
ZAK_FORM_ELEMENT_VALIDATOR (zak_form_element_validator_regex_new ("^aaa$")));
zak_form_form_add_element (ZAK_FORM_FORM (form), ZAK_FORM_ELEMENT (element));
- element = zak_cgi_form_element_check_new ("chk", NULL);
+ 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 ("<h1>big big big</h1>");
+ element = zak_cgi_form_element_string_new_attrs ("<h1>big big big</h1>");
zak_form_form_add_element (ZAK_FORM_FORM (form), ZAK_FORM_ELEMENT (element));
- element = zak_cgi_form_element_password_new ("pws", NULL);
+ 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 ("txtarea", NULL);
+ 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 ("slc", NULL);
+ 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 ("hdn", NULL);
+ 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 ("submit", "zak-cgi-content", "Submit", NULL);
+ 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))
--- /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 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 <unistd.h>
+
+#include <libzakform/libzakform.h>
+
+#include <form.h>
+#include <formelement.h>
+#include <formelementcheck.h>
+#include <formelementhidden.h>
+#include <formelementpassword.h>
+#include <formelementselect.h>
+#include <formelementstring.h>
+#include <formelementtext.h>
+#include <formelementtextarea.h>
+#include <formelementsubmit.h>
+
+int
+main (int argc, char *argv[])
+{
+ ZakCgiMain *zakcgimain;
+
+ GString *str;
+
+ ZakCgiForm *form;
+ ZakCgiFormElement *element;
+
+ zakcgimain = zak_cgi_main_new ();
+
+ str = g_string_new ("<!DOCTYPE html>\n"
+ "<html lang=\"it\">\n"
+ "<head>\n"
+ "<meta charset=\"utf-8\">\n"
+ "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n"
+ "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n"
+ "<title>Form test</title>\n"
+ "<!-- Bootstrap -->\n"
+ "<!-- Latest compiled and minified CSS -->\n"
+ "<link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css\">\n"
+ "</head>\n"
+ "<body>\n"
+ "<div class=\"container\">\n");
+
+ form = zak_cgi_form_new (zakcgimain,
+ "method", "post",
+ "action", "form",
+ NULL);
+
+ GValue *val = zak_cgi_main_get_parameter (zakcgimain, "filename");
+ if (zak_form_form_load_from_file (ZAK_FORM_FORM (form), g_value_get_string (val)))
+ {
+ 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</div>\n"
+ "<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->\n"
+ "<script src=\"http://code.jquery.com/jquery-1.11.3.min.js\"></script>\n"
+ "<!-- Include all compiled plugins (below), or include individual files as needed -->\n"
+ "<!-- Latest compiled and minified JavaScript -->\n"
+ "<script src=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js\"></script>\n"
+ "</body>\n"
+ "</html>");
+
+ zak_cgi_main_out (NULL, str->str);
+
+ return 0;
+}
--- /dev/null
+<?xml version="1.0"?>
+<zakform>
+
+ <element type="zak_cgi_form_element_text">
+ <id>first</id>
+ <label>The Label for first</label>
+ </element>
+
+ <element type="zak_cgi_form_element_check">
+ <id>chk</id>
+ <label>The checkbox</label>
+ </element>
+
+ <element type="zak_cgi_form_element_string">
+ <string><h1>big big big</h1></string>
+ </element>
+
+ <element type="zak_cgi_form_element_password">
+ <id>pws</id>
+ <label>The password</label>
+ </element>
+
+ <element type="zak_cgi_form_element_text_area">
+ <id>txtarea</id>
+ <label>The Text Area</label>
+ </element>
+
+ <element type="zak_cgi_form_element_select">
+ <id>slc</id>
+ <option id="1">first</option>
+ <option id="2">second</option>
+ <option id="3">third</option>
+ </element>
+
+ <element type="zak_cgi_form_element_hidden">
+ <id>hdn</id>
+ </element>
+
+ <element type="zak_cgi_form_element_submit">
+ <id>submit</id>
+ <zak-cgi-content>Submit</zak-cgi-content>
+ </element>
+
+</zakform>
g_string_append_printf (str,
"<tr><td>IS GET?</td><td>%s</td></tr>\n",
- zak_cgi_main_is_get (NULL) ? "TRUE" : "FALSE");
+ zak_cgi_main_is_get (main) ? "TRUE" : "FALSE");
g_string_append_printf (str,
"<tr><td>IS POST?</td><td>%s</td></tr>\n",
- zak_cgi_main_is_post (NULL) ? "TRUE" : "FALSE");
+ zak_cgi_main_is_post (main) ? "TRUE" : "FALSE");
zak_cgi_main_parameters_foreach (main, ht_foreach, str);