]> saetta.ns0.it Git - libzakcgi/commitdiff
Added ZakCgiSession::close.
authorAndrea Zagli <azagli@libero.it>
Sat, 1 Aug 2015 13:20:31 +0000 (15:20 +0200)
committerAndrea Zagli <azagli@libero.it>
Sat, 1 Aug 2015 13:20:31 +0000 (15:20 +0200)
Saved REMOTE_ADDR and timestamp on session creation (refs #950).

src/session.c
src/session.h

index e06dd4debfd963a6255e873d69570d67a7015f14..0fed8778e0c15972c4254fe25624f3d897e6fc90 100644 (file)
@@ -99,6 +99,8 @@ ZakCgiSession
        ZakCgiSession *zak_cgi_session;
        ZakCgiSessionPrivate *priv;
 
+       gchar *val;
+
        zak_cgi_session = ZAK_CGI_SESSION (g_object_new (zak_cgi_session_get_type (), NULL));
 
        priv = ZAK_CGI_SESSION_GET_PRIVATE (zak_cgi_session);
@@ -122,7 +124,6 @@ ZakCgiSession
 
                        error = NULL;
 
-                       /* TODO */
                        /* check the content */
                        priv->kfile = g_key_file_new ();
                        if (!g_key_file_load_from_file (priv->kfile,
@@ -133,6 +134,9 @@ ZakCgiSession
                                {
                                        /* TODO */
                                }
+                       else
+                               {
+                               }
                }
 
        return zak_cgi_session;
@@ -184,10 +188,31 @@ gchar
                                }
                        else
                                {
-                                       /* TODO */
-                                       /* insert some data (ex IP) */
                                        g_io_stream_close (G_IO_STREAM (iostream), NULL, NULL);
                                        g_object_unref (iostream);
+
+                                       priv->kfile = g_key_file_new ();
+                                       if (!g_key_file_load_from_file (priv->kfile,
+                                                                                                       g_file_get_path (priv->gfile),
+                                                                                                       G_KEY_FILE_NONE,
+                                                                                                       &error)
+                                               || error != NULL)
+                                               {
+                                                       /* TODO */
+                                               }
+                                       else
+                                               {
+                                                       /* write REMOTE_ADDR and creation timestamp */
+                                                       GDateTime *gdt;
+
+                                                       gdt = g_date_time_new_now_local ();
+
+                                                       g_key_file_set_value (priv->kfile, "ZAKCGI", "REMOTE_ADDR", g_getenv ("REMOTE_ADDR"));
+                                                       g_key_file_set_value (priv->kfile, "ZAKCGI", "TIMESTAMP", g_date_time_format (gdt, "%F %T"));
+                                                       g_key_file_save_to_file (priv->kfile, g_file_get_path (priv->gfile), NULL);
+
+                                                       g_date_time_unref (gdt);
+                                               }
                                }
 
                        ht_env = zak_cgi_main_get_env (priv->zakcgimain);
@@ -246,6 +271,34 @@ gchar
        return ret;
 }
 
+/**
+ * zak_cgi_session_close:
+ * @session:
+ *
+ */
+void
+zak_cgi_session_close (ZakCgiSession *session)
+{
+       ZakCgiSessionPrivate *priv = ZAK_CGI_SESSION_GET_PRIVATE (session);
+
+       if (priv->kfile != NULL)
+               {
+                       g_key_file_free (priv->kfile);
+                       priv->kfile = NULL;
+               }
+       if (priv->gfile != NULL)
+               {
+                       g_file_delete (priv->gfile, NULL, NULL);
+                       g_object_unref (priv->gfile);
+                       priv->gfile = NULL;
+               }
+       if (priv->sid != NULL)
+               {
+                       g_free (priv->sid);
+                       priv->sid = NULL;
+               }
+}
+
 /* PRIVATE */
 static void
 zak_cgi_session_set_property (GObject *object,
index 44a992c4de0377cb36d7bb53ba403f3a0baa15e5..caa23c2b64fc206f1ebfe864381d3ad68e8ae4c3 100644 (file)
@@ -60,6 +60,8 @@ gchar *zak_cgi_session_get_header (ZakCgiSession *session);
 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_close (ZakCgiSession *session);
+
 
 G_END_DECLS