From: Andrea Zagli Date: Sat, 1 Aug 2015 13:20:31 +0000 (+0200) Subject: Added ZakCgiSession::close. X-Git-Tag: v0.0.1~2 X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=4134b3cbf42b8027d4fe2af6878ae18380ebd2e4;p=libzakcgi Added ZakCgiSession::close. Saved REMOTE_ADDR and timestamp on session creation (refs #950). --- diff --git a/src/session.c b/src/session.c index e06dd4d..0fed877 100644 --- a/src/session.c +++ b/src/session.c @@ -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, diff --git a/src/session.h b/src/session.h index 44a992c..caa23c2 100644 --- a/src/session.h +++ b/src/session.h @@ -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