Name: @PACKAGE_NAME@
Description: Class for CGI.
Version: @PACKAGE_VERSION@
-Requires: glib-2.0 >= 2.36
+Requires: glib-2.0 >= 2.36 gobject gio gio-unix
Libs: -L${libdir} -lzakcgi
Cflags: -I${includedir}
typedef struct _ZakCgiMainPrivate ZakCgiMainPrivate;
struct _ZakCgiMainPrivate
{
+ GHashTable *ht_env;
+ GHashTable *ht_cookies;
+ GHashTable *ht_parameters;
+ gchar *stdin;
};
G_DEFINE_TYPE (ZakCgiMain, zak_cgi_main, G_TYPE_OBJECT)
{
ZakCgiMainPrivate *priv = ZAK_CGI_MAIN_GET_PRIVATE (zak_cgi_main);
+ priv->ht_env = NULL;
+ priv->ht_cookies = NULL;
+ priv->ht_parameters = NULL;
+ priv->stdin = NULL;
}
/**
priv = ZAK_CGI_MAIN_GET_PRIVATE (zak_cgi_main);
-
return zak_cgi_main;
}
/**
* zak_cgi_main_get_env:
+ * @zakcgimain:
*
* Returns: a #GHashTable with all the environment variables.
*/
GHashTable
-*zak_cgi_main_get_env (void)
+*zak_cgi_main_get_env (ZakCgiMain *zakcgimain)
{
+ ZakCgiMainPrivate *priv;
GHashTable *ht;
gchar **environ;
guint i;
gchar **envs;
+ if (zakcgimain != NULL)
+ {
+ priv = ZAK_CGI_MAIN_GET_PRIVATE (zakcgimain);
+ if (priv->ht_env != NULL)
+ {
+ return g_hash_table_ref (priv->ht_env);
+ }
+ }
+
ht = g_hash_table_new (g_str_hash, g_str_equal);
+ if (zakcgimain != NULL)
+ {
+ priv->ht_env = g_hash_table_ref (ht);
+ }
environ = g_get_environ ();
l = g_strv_length (environ);
/**
* zak_cgi_main_dump_env:
+ * @zakcgimain:
*
* Returns: an html table with each environment variables.
*/
gchar
-*zak_cgi_main_dump_env (void)
+*zak_cgi_main_dump_env (ZakCgiMain *zakcgimain)
{
GHashTable *ht_env;
GHashTableIter iter;
gpointer key;
gpointer value;
- ht_env = zak_cgi_main_get_env ();
+ ht_env = zak_cgi_main_get_env (zakcgimain);
str = g_string_new ("");
/**
* zak_cgi_main_get_cookies:
+ * @zakcgimain:
*
* Returns: a #GHashTable with all the cookies.
*/
GHashTable
-*zak_cgi_main_get_cookies (void)
+*zak_cgi_main_get_cookies (ZakCgiMain *zakcgimain)
{
+ ZakCgiMainPrivate *priv;
GHashTable *ht;
GHashTable *ht_env;
gchar **strv_cookies;
gchar **parts;
+ if (zakcgimain != NULL)
+ {
+ priv = ZAK_CGI_MAIN_GET_PRIVATE (zakcgimain);
+ if (priv->ht_cookies != NULL)
+ {
+ return g_hash_table_ref (priv->ht_cookies);
+ }
+ }
ht = g_hash_table_new (g_str_hash, g_str_equal);
+ if (zakcgimain != NULL)
+ {
+ priv->ht_cookies = g_hash_table_ref (ht);
+ }
- ht_env = zak_cgi_main_get_env ();
+ ht_env = zak_cgi_main_get_env (zakcgimain);
cookies = g_hash_table_lookup (ht_env, "HTTP_COOKIE");
if (cookies != NULL)
/**
* zak_cgi_main_dump_cookies:
+ * @zakcgimain:
*
* Returns: an html table with each cookies.
*/
gchar
-*zak_cgi_main_dump_cookies (void)
+*zak_cgi_main_dump_cookies (ZakCgiMain *zakcgimain)
{
GHashTable *ht_env;
GHashTableIter iter;
gpointer key;
gpointer value;
- ht_env = zak_cgi_main_get_cookies ();
+ ht_env = zak_cgi_main_get_cookies (zakcgimain);
str = g_string_new ("");
/**
* zak_cgi_main_get_parameters:
+ * @zakcgimain:
* @query_string:
*
* Returns:
*/
GHashTable
-*zak_cgi_main_get_parameters (const gchar *query_string)
+*zak_cgi_main_get_parameters (ZakCgiMain *zakcgimain, const gchar *query_string)
{
+ ZakCgiMainPrivate *priv;
GHashTable *ht;
const gchar *qstring;
GValue *gval;
- ht = g_hash_table_new (g_str_hash, g_str_equal);
+ ht = NULL;
+
+ if (zakcgimain != NULL)
+ {
+ priv = ZAK_CGI_MAIN_GET_PRIVATE (zakcgimain);
+ if (priv->ht_parameters != NULL)
+ {
+ ht = g_hash_table_ref (priv->ht_parameters);
+ }
+ }
+
+ if (ht == NULL)
+ {
+ ht = g_hash_table_new (g_str_hash, g_str_equal);
+ if (zakcgimain != NULL)
+ {
+ priv->ht_parameters = g_hash_table_ref (ht);
+ }
+ }
if (query_string == NULL)
{
/**
* zak_cgi_main_get_stdin:
+ * @zakcgimain:
*
* Returns: the stdin.
*/
gchar
-*zak_cgi_main_get_stdin (void)
+*zak_cgi_main_get_stdin (ZakCgiMain *zakcgimain)
{
gchar *ret;
+ ZakCgiMainPrivate *priv;
+
const gchar *env;
guint l;
gsize bytesread;
GInputStream *istream;
ret = NULL;
+ if (zakcgimain != NULL)
+ {
+ priv = ZAK_CGI_MAIN_GET_PRIVATE (zakcgimain);
+ if (priv->stdin != NULL)
+ {
+ return g_strdup (priv->stdin);
+ }
+ }
env = g_getenv ("CONTENT_LENGTH");
if (env != NULL)
}
}
+ if (zakcgimain != NULL)
+ {
+ priv->stdin = g_strdup (ret);
+ }
+
return ret;
}
if (g_strcmp0 (content_type, "") == 0
|| g_strcmp0 (splitted[0], "application/x-www-form-urlencoded") == 0)
{
- return zak_cgi_main_get_parameters (buf);
+ return zak_cgi_main_get_parameters (NULL, buf);
}
else if (g_strcmp0 (splitted[0], "multipart/form-data") == 0)
{
ZakCgiMain *zak_cgi_main = (ZakCgiMain *)gobject;
ZakCgiMainPrivate *priv = ZAK_CGI_MAIN_GET_PRIVATE (zak_cgi_main);
+ if (priv->ht_env != NULL)
+ {
+ g_hash_table_destroy (priv->ht_env);
+ }
+ if (priv->ht_cookies != NULL)
+ {
+ g_hash_table_destroy (priv->ht_cookies);
+ }
+ if (priv->ht_parameters != NULL)
+ {
+ g_hash_table_destroy (priv->ht_parameters);
+ }
+ if (priv->stdin != NULL)
+ {
+ g_free (priv->stdin);
+ }
GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject));
parent_class->finalize (gobject);
void zak_cgi_main_out (const gchar *header, const gchar *body);
-GHashTable *zak_cgi_main_get_env (void);
-gchar *zak_cgi_main_dump_env (void);
+GHashTable *zak_cgi_main_get_env (ZakCgiMain *zakcgimain);
+gchar *zak_cgi_main_dump_env (ZakCgiMain *zakcgimain);
-GHashTable *zak_cgi_main_get_cookies (void);
-gchar *zak_cgi_main_dump_cookies (void);
+GHashTable *zak_cgi_main_get_cookies (ZakCgiMain *zakcgimain);
+gchar *zak_cgi_main_dump_cookies (ZakCgiMain *zakcgimain);
gchar *zak_cgi_main_set_cookie (const gchar *name,
const gchar *value,
gboolean secure,
gboolean http_only);
-GHashTable *zak_cgi_main_get_parameters (const gchar *query_string);
+GHashTable *zak_cgi_main_get_parameters (ZakCgiMain *zakcgimain, const gchar *query_string);
-gchar *zak_cgi_main_get_stdin (void);
+gchar *zak_cgi_main_get_stdin (ZakCgiMain *zakcgimain);
GHashTable *zak_cgi_main_parse_stdin (const gchar *buf, const gchar *boundary);
#include <string.h>
-#include "main.h"
#include "session.h"
static void zak_cgi_session_class_init (ZakCgiSessionClass *class);
typedef struct _ZakCgiSessionPrivate ZakCgiSessionPrivate;
struct _ZakCgiSessionPrivate
{
+ ZakCgiMain *zakcgimain;
gchar *sid;
GFile *gfile;
GKeyFile *kfile;
{
ZakCgiSessionPrivate *priv = ZAK_CGI_SESSION_GET_PRIVATE (zak_cgi_session);
+ priv->zakcgimain;
}
/**
* zak_cgi_session_new:
+ * @zakcgimain:
*
* Returns: the newly created #ZakCgiSession object.
*/
ZakCgiSession
-*zak_cgi_session_new (void)
+*zak_cgi_session_new (ZakCgiMain *zakcgimain)
{
GHashTable *ht_cookies;
zak_cgi_session = ZAK_CGI_SESSION (g_object_new (zak_cgi_session_get_type (), NULL));
priv = ZAK_CGI_SESSION_GET_PRIVATE (zak_cgi_session);
+ priv->zakcgimain = zakcgimain;
- ht_cookies = zak_cgi_main_get_cookies ();
+ ht_cookies = zak_cgi_main_get_cookies (priv->zakcgimain);
priv->sid = g_hash_table_lookup (ht_cookies, "ZAKCGISID");
if (priv->sid != NULL)
#include <glib-object.h>
+#include "main.h"
+
G_BEGIN_DECLS
GType zak_cgi_session_get_type (void);
-ZakCgiSession *zak_cgi_session_new (void);
+ZakCgiSession *zak_cgi_session_new (ZakCgiMain *zakcgimain);
gchar *zak_cgi_session_get_header (ZakCgiSession *session);
#include <syslog.h>
-#include "main.h"
#include "url.h"
static void zak_cgi_url_class_init (ZakCgiUrlClass *class);
typedef struct _ZakCgiUrlPrivate ZakCgiUrlPrivate;
struct _ZakCgiUrlPrivate
{
+ ZakCgiMain *zakcgimain;
+
gchar *controller;
gchar *action;
{
ZakCgiUrlPrivate *priv = ZAK_CGI_URL_GET_PRIVATE (zak_cgi_url);
+ priv->zakcgimain = NULL;
+
priv->controller = NULL;
priv->action = NULL;
/**
* zak_cgi_url_new:
+ * @zakcgimain:
*
* Returns: the newly created #ZakCgiUrl object.
*/
ZakCgiUrl
-*zak_cgi_url_new (void)
+*zak_cgi_url_new (ZakCgiMain *zakcgimain)
{
ZakCgiUrl *zak_cgi_url;
ZakCgiUrlPrivate *priv;
zak_cgi_url = ZAK_CGI_URL (g_object_new (zak_cgi_url_get_type (), NULL));
priv = ZAK_CGI_URL_GET_PRIVATE (zak_cgi_url);
+ priv->zakcgimain = zakcgimain;
/* parsing */
- ht_env = zak_cgi_main_get_parameters (NULL);
+ ht_env = zak_cgi_main_get_parameters (priv->zakcgimain, NULL);
url = g_hash_table_lookup (ht_env, "_url");
if (url != NULL)
{
#include <glib-object.h>
+#include "main.h"
+
G_BEGIN_DECLS
GType zak_cgi_url_get_type (void);
-ZakCgiUrl *zak_cgi_url_new (void);
+ZakCgiUrl *zak_cgi_url_new (ZakCgiMain *zakcgimain);
typedef void (*ZakCgiUrlConnectedFunction) (GString *buf);
GString *header;
GHashTable *ht;
- env = zak_cgi_main_dump_cookies ();
+ env = zak_cgi_main_dump_cookies (NULL);
str = g_string_new ("<html>\n"
"<head><title>Cookies</title></head>\n"
GString *str;
GHashTable *ht;
- env = zak_cgi_main_dump_env ();
+ env = zak_cgi_main_dump_env (NULL);
str = g_string_new ("<html>\n"
"<head><title>Environment variables</title></head>\n"
g_string_append_printf (str, "%s\n</body>", env);
g_free (env);
- env = zak_cgi_main_get_stdin ();
+ env = zak_cgi_main_get_stdin (NULL);
/*syslog (LOG_MAKEPRI(LOG_SYSLOG, LOG_DEBUG), "stdin: %s", env);*/
if (env != NULL)
{
gpointer key;
gpointer value;
- ht_env = zak_cgi_main_get_parameters (NULL);
+ ht_env = zak_cgi_main_get_parameters (NULL, NULL);
str = g_string_new ("<html>\n"
"<head><title>Query string</title></head>\n"
{
GHashTable *ht_env;
- ht_env = zak_cgi_main_get_parameters (NULL);
+ ht_env = zak_cgi_main_get_parameters (NULL, NULL);
zak_cgi_main_redirect ((gchar *)g_value_get_string ((GValue *)(const gchar *)g_hash_table_lookup (ht_env, "redirectto")));
gchar *method;
- session = zak_cgi_session_new ();
+ session = zak_cgi_session_new (NULL);
str = g_string_new ("<html>\n"
"<head><title>Session Cookie</title></head>\n"
"<body>\n");
- ht = zak_cgi_main_get_env ();
+ ht = zak_cgi_main_get_env (NULL);
if (ht != NULL)
{
method = g_hash_table_lookup (ht, "REQUEST_METHOD");
{
gchar **boundary = g_strsplit (splitted[1], "=", 2);
- env = zak_cgi_main_get_stdin ();
+ env = zak_cgi_main_get_stdin (NULL);
ht_stdin = zak_cgi_main_parse_stdin (env, boundary[1]);
"<head><title>Url</title></head>\n"
"<body>\n");
- url = zak_cgi_url_new ();
+ url = zak_cgi_url_new (NULL);
zak_cgi_url_connect (url, "thecontroller", "theaction", (ZakCgiUrlConnectedFunction)hook, str);