]> saetta.ns0.it Git - libzakcgi/commitdiff
Added functions ZakCgiSession::[gs]et_value_full_* (closes #992).
authorAndrea Zagli <azagli@libero.it>
Sat, 26 Mar 2016 14:06:40 +0000 (15:06 +0100)
committerAndrea Zagli <azagli@libero.it>
Sat, 26 Mar 2016 15:39:10 +0000 (16:39 +0100)
src/session.c
src/session.h
tests/session.c

index afba2fdb3cecc4cea9bcca56a4e9e05e2e394acc..61d0462b6386e6dc630bdf11fc381936d7e3049e 100644 (file)
@@ -20,6 +20,8 @@
        #include <config.h>
 #endif
 
+#include <stdlib.h>
+
 #include <gio/gio.h>
 
 #include <string.h>
@@ -404,6 +406,112 @@ gchar
        return zak_cgi_session_get_value_full (session, "SESSION", name);
 }
 
+/**
+ * zak_cgi_session_set_value_full_int:
+ * @session:
+ * @group:
+ * @name:
+ * @value:
+ *
+ */
+void
+zak_cgi_session_set_value_full_int (ZakCgiSession *session, const gchar *group, const gchar *name, gint value)
+{
+       gchar *str;
+
+       str = g_strdup_printf ("%d", value);
+       zak_cgi_session_set_value_full (session, group, name, str);
+       g_free (str);
+}
+
+/**
+ * zak_cgi_session_set_value_full_double:
+ * @session:
+ * @group:
+ * @name:
+ * @value:
+ *
+ */
+void
+zak_cgi_session_set_value_full_double (ZakCgiSession *session, const gchar *group, const gchar *name, gdouble value)
+{
+       gchar *str;
+
+       str = g_strdup_printf ("%f", value);
+       zak_cgi_session_set_value_full (session, group, name, str);
+       g_free (str);
+}
+
+/**
+ * zak_cgi_session_set_value_full_boolean:
+ * @session:
+ * @group:
+ * @name:
+ * @value:
+ *
+ */
+void
+zak_cgi_session_set_value_full_boolean (ZakCgiSession *session, const gchar *group, const gchar *name, gboolean value)
+{
+       zak_cgi_session_set_value_full_int (session, group, name, (gint)value);
+}
+
+/**
+ * zak_cgi_session_get_value_full_int:
+ * @session:
+ * @group:
+ * @name:
+ *
+ * Returns:
+ */
+gint
+zak_cgi_session_get_value_full_int (ZakCgiSession *session, const gchar *group, const gchar *name)
+{
+       gchar *str;
+       gint ret;
+
+       str = zak_cgi_session_get_value_full (session, group, name);
+       ret = strtol (str, NULL, 10);
+       g_free (str);
+
+       return ret;
+}
+
+/**
+ * zak_cgi_session_get_value_full_double:
+ * @session:
+ * @group:
+ * @name:
+ *
+ * Returns:
+ */
+gdouble
+zak_cgi_session_get_value_full_double (ZakCgiSession *session, const gchar *group, const gchar *name)
+{
+       gchar *str;
+       gdouble ret;
+
+       str = zak_cgi_session_get_value_full (session, group, name);
+       ret = g_strtod (str, NULL);
+       g_free (str);
+
+       return ret;
+}
+
+/**
+ * zak_cgi_session_get_value_full_boolean:
+ * @session:
+ * @group:
+ * @name:
+ *
+ * Returns:
+ */
+gboolean
+zak_cgi_session_get_value_full_boolean (ZakCgiSession *session, const gchar *group, const gchar *name)
+{
+       return (gboolean)zak_cgi_session_get_value_full_int (session, group, name);
+}
+
 /**
  * zak_cgi_session_close:
  * @session:
index 2f645484a40b463118347195ed3a89c7981bd284..ce238a649148242008429be10abf7ee6694876f0 100644 (file)
@@ -63,6 +63,14 @@ gchar *zak_cgi_session_get_value_full (ZakCgiSession *session, const gchar *grou
 void zak_cgi_session_set_value (ZakCgiSession *session, const gchar *name, const gchar *value);
 gchar *zak_cgi_session_get_value (ZakCgiSession *session, const gchar *name);
 
+void zak_cgi_session_set_value_full_int (ZakCgiSession *session, const gchar *group, const gchar *name, gint value);
+void zak_cgi_session_set_value_full_double (ZakCgiSession *session, const gchar *group, const gchar *name, gdouble value);
+void zak_cgi_session_set_value_full_boolean (ZakCgiSession *session, const gchar *group, const gchar *name, gboolean value);
+
+gint zak_cgi_session_get_value_full_int (ZakCgiSession *session, const gchar *group, const gchar *name);
+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_close (ZakCgiSession *session);
 
 
index 2289b3693419e3584e7b8345ba389060bbacb785..b26bf60b1a91f279061f083ad97277934f96a540 100644 (file)
@@ -75,7 +75,10 @@ main (int argc, char *argv[])
                                                        ht_stdin = zak_cgi_main_parse_stdin (env, boundary[1]);
                                                        if (g_hash_table_lookup (ht_stdin, "reset") != NULL)
                                                                {
-                                                                       g_warning ("Session: %s", zak_cgi_session_get_value_full (session, "NEW GROUP", "new key"));
+                                                                       g_warning ("new key: %s", zak_cgi_session_get_value_full (session, "NEW GROUP", "new key"));
+                                                                       g_warning ("new int: %d", zak_cgi_session_get_value_full_int (session, "NEW GROUP", "new int"));
+                                                                       g_warning ("new double: %f", zak_cgi_session_get_value_full_double (session, "NEW GROUP", "new double"));
+                                                                       g_warning ("new boolean: %d", zak_cgi_session_get_value_full_boolean (session, "NEW GROUP", "new boolean"));
 
                                                                        zak_cgi_session_set_value (session, "user_name", NULL);
                                                                        zak_cgi_session_set_value_full (session, "NEW GROUP", NULL, NULL);
@@ -118,6 +121,9 @@ main (int argc, char *argv[])
                        else
                                {
                                        zak_cgi_session_set_value_full (session, "NEW GROUP", "new key", "new value");
+                                       zak_cgi_session_set_value_full_int (session, "NEW GROUP", "new int", 55);
+                                       zak_cgi_session_set_value_full_double (session, "NEW GROUP", "new double", 123.66);
+                                       zak_cgi_session_set_value_full_boolean (session, "NEW GROUP", "new boolean", TRUE);
 
                                        g_string_append (str, ", on the second page.<br/><br/>");
                                        g_string_append (str,