From 67aacbda991bdbc1d8a2b0cc18ea9831883c115c Mon Sep 17 00:00:00 2001
From: Andrea Zagli <azagli@libero.it>
Date: Fri, 12 Feb 2010 12:55:14 +0100
Subject: [PATCH] Inizio migrazione senza la dipendenza di libconfi.

---
 .gitignore      |  25 ++++++
 autogen.sh      | 101 +++-------------------
 configure.ac    |  13 ++-
 src/Makefile.am |   4 +-
 src/aute.c      | 221 +++++++++++++++++++++++++++++++++++++++---------
 src/libaute.h   |  32 +++++--
 6 files changed, 259 insertions(+), 137 deletions(-)
 create mode 100644 .gitignore

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..08f49ef
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,25 @@
+COPYING
+INSTALL
+Makefile
+Makefile.in
+aclocal.m4
+autom4te.cache/
+config.guess
+config.log
+config.status
+config.sub
+configure
+depcomp
+version.xml
+gtk-doc.make
+install-sh
+libaute.pc
+libtool
+ltmain.sh
+missing
+.deps
+.libs
+*.lo
+*.o
+*.la
+*~
diff --git a/autogen.sh b/autogen.sh
index 36cce34..13b33e7 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -1,98 +1,23 @@
-#!/bin/sh
+#!/bin/bash
 # Run this to generate all the initial makefiles, etc.
 
 srcdir=`dirname $0`
 test -z "$srcdir" && srcdir=.
 
-ORIGDIR=`pwd`
-cd $srcdir
-PROJECT=libaute
-TEST_TYPE=-f
-FILE=configure.ac
+PKG_NAME="libaute"
 
-DIE=0
-
-have_libtool=false
-if libtoolize --version < /dev/null > /dev/null 2>&1 ; then
-	libtool_version=`libtoolize --version | sed 's/^[^0-9]*\([0-9.][0-9.]*\).*/\1/'`
-	case $libtool_version in
-	    1.4*|1.5*)
-		have_libtool=true
-		;;
-	esac
-fi
-if $have_libtool ; then : ; else
-	echo
-	echo "You must have libtool 1.4 installed to compile $PROJECT."
-	echo "Install the appropriate package for your distribution,"
-	echo "or get the source tarball at http://ftp.gnu.org/gnu/libtool/"
-	DIE=1
-fi
-
-(gtkdocize --version) < /dev/null > /dev/null 2>&1 || {
-	echo
-	echo "You must have gtk-doc installed to compile $PROJECT."
-	echo "Install the appropriate package for your distribution,"
-	echo "or get the source tarball at http://ftp.gnome.org/pub/GNOME/sources/gtk-doc/"
-	DIE=1
+(test -f $srcdir/configure.ac \
+  && test -d $srcdir/src \
+  && test -f $srcdir/src/libaute.h) || {
+    echo -n "**Error**: Directory "\`$srcdir\'" does not look like the"
+    echo " top-level libaute directory"
+    exit 1
 }
 
-(autoconf --version) < /dev/null > /dev/null 2>&1 || {
-	echo
-	echo "You must have autoconf installed to compile $PROJECT."
-	echo "Install the appropriate package for your distribution,"
-	echo "or get the source tarball at http://ftp.gnu.org/gnu/autoconf/"
-	DIE=1
+which gnome-autogen.sh || {
+    echo "You need to install gnome-common from GNOME and make"
+    echo "sure the gnome-autogen.sh script is in your \$PATH."
+    exit 1
 }
 
-if automake --version < /dev/null > /dev/null 2>&1 ; then
-    AUTOMAKE=automake
-    ACLOCAL=aclocal
-else
-	echo
-	echo "You must have automake 1.7.x installed to compile $PROJECT."
-	echo "Install the appropriate package for your distribution,"
-	echo "or get the source tarball at http://ftp.gnu.org/gnu/automake/"
-	DIE=1
-fi
-
-if test "$DIE" -eq 1; then
-	exit 1
-fi
-
-test $TEST_TYPE $FILE || {
-	echo "You must run this script in the top-level $PROJECT directory"
-	exit 1
-}
-
-if test -z "$AUTOGEN_SUBDIR_MODE"; then
-        if test -z "$*"; then
-                echo "I am going to run ./configure with no arguments - if you wish "
-                echo "to pass any to it, please specify them on the $0 command line."
-        fi
-fi
-
-rm -rf autom4te.cache
-
-# README and INSTALL are required by automake, but may be deleted by clean
-# up rules. to get automake to work, simply touch these here, they will be
-# regenerated from their corresponding *.in files by ./configure anyway.
-touch README INSTALL
-
-$ACLOCAL || exit $?
-
-libtoolize --force || exit $?
-gtkdocize || exit $?
-
-autoheader || exit $?
-
-$AUTOMAKE --add-missing || exit $?
-autoconf || exit $?
-cd $ORIGDIR || exit $?
-
-if test -z "$AUTOGEN_SUBDIR_MODE"; then
-        $srcdir/configure --enable-maintainer-mode $AUTOGEN_CONFIGURE_ARGS "$@" || exit $?
-
-        echo 
-        echo "Now type 'make' to compile $PROJECT."
-fi
+USE_GNOME2_MACROS=1 . gnome-autogen.sh
diff --git a/configure.ac b/configure.ac
index 07d06b1..f6c6aa8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2,7 +2,7 @@
 # Process this file with autoconf to produce a configure script.
 
 AC_PREREQ(2.59)
-AC_INIT([libaute], [0.0.1], [azagli@libero.it])
+AC_INIT([libaute], [0.0.2], [azagli@libero.it])
 AC_CONFIG_SRCDIR([src/aute.c])
 
 AM_INIT_AUTOMAKE
@@ -19,13 +19,20 @@ AC_PROG_LIBTOOL
 GTK_DOC_CHECK
 
 # Checks for libraries.
+have_libconfi=no
+
 PKG_CHECK_MODULES(LIBAUTE, [glib-2.0 >= 2.10.0
-                            gmodule-2.0 >= 2.10.0
-                            libconfi >= 0.0.2])
+                            gmodule-2.0 >= 2.10.0])
 
 AC_SUBST(LIBAUTE_CFLAGS)
 AC_SUBST(LIBAUTE_LIBS)
 
+PKG_CHECK_MODULES(LIBCONFI, [libconfi >= 0.0.2], AC_DEFINE(HAVE_LIBCONFI, [1], [libconfi is present]), have_libconfi=yes)
+
+AM_CONDITIONAL(HAVE_LIBCONFI, test x"$have_libconfi" = "xyes")
+AC_SUBST(LIBCONFI_CFLAGS)
+AC_SUBST(LIBCONFI_LIBS)
+
 # Checks for header files.
 
 # Checks for typedefs, structures, and compiler characteristics.
diff --git a/src/Makefile.am b/src/Makefile.am
index a7b7431..da5a343 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,7 +1,9 @@
 AM_CPPFLAGS = $(LIBAUTE_CFLAGS) \
+              $(LIBCONFI_CFLAGS) \
               -DLIBAUTE_PLUGINS_DIR=\""$(libdir)/libaute/plugins"\"
 
-LIBS = $(LIBAUTE_LIBS)
+LIBS = $(LIBAUTE_LIBS) \
+       $(LIBCONFI_LIBS)
 
 lib_LTLIBRARIES = libaute.la
 
diff --git a/src/aute.c b/src/aute.c
index 1fd4774..d921044 100644
--- a/src/aute.c
+++ b/src/aute.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005-2006 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2005-2010 Andrea Zagli <azagli@libero.it>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -20,6 +20,125 @@
 
 #include "libaute.h"
 
+static void aute_class_init (AuteClass *class);
+static void aute_init (Aute *form);
+
+static void aute_set_property (GObject *object,
+                               guint property_id,
+                               const GValue *value,
+                               GParamSpec *pspec);
+static void aute_get_property (GObject *object,
+                               guint property_id,
+                               GValue *value,
+                               GParamSpec *pspec);
+
+GModule *aute_get_module_from_confi (Aute *aute);
+
+#define AUTE_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_AUTE, AutePrivate))
+
+typedef struct _AutePrivate AutePrivate;
+struct _AutePrivate
+	{
+		GModule *module;
+
+		GSList *parameters;
+
+#ifdef HAVE_LIBCONFI
+		Confi *confi;
+#endif
+	};
+
+G_DEFINE_TYPE (Aute, aute, G_TYPE_OBJECT)
+
+static void
+aute_class_init (AuteClass *class)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+	object_class->set_property = aute_set_property;
+	object_class->get_property = aute_get_property;
+
+	g_type_class_add_private (object_class, sizeof (AutePrivate));
+}
+
+static void
+aute_init (Aute *form)
+{
+	AutePrivate *priv = AUTE_GET_PRIVATE (form);
+
+	priv->module = NULL;
+	priv->parameters = NULL;
+
+#ifdef HAVE_LIBCONFI
+	priv->confi = NULL;
+#endif
+}
+
+/**
+ * aute_new:
+ *
+ * Returns: the newly created #Aute object.
+ */
+Aute
+*aute_new ()
+{
+	return AUTE (g_object_new (aute_get_type (), NULL));
+}
+
+/*
+ * aute_set_config:
+ * @aute: an #Aute object.
+ * @parameters: a #GSList of config parameters.
+ *
+ */
+gboolean
+aute_set_config (Aute *aute, GSList *parameters)
+{
+	gchar *module_name;
+
+	AutePrivate *priv = AUTE_GET_PRIVATE (aute);
+
+	g_return_val_if_fail (parameters != NULL && parameters->data != NULL, FALSE);
+
+	priv->parameters = parameters;
+
+	module_name = NULL;
+
+#ifdef HAVE_LIBCONFI
+	/* the first and only parameters must be a Confi object */
+	Confi *confi;
+
+	if (IS_CONFI (priv->parameters->data))
+		{
+			priv->confi = CONFI (priv->parameters->data);
+			module_name = aute_get_module_from_confi (aute);
+		}
+#endif
+
+	if (module_name == NULL)
+		{
+			/* the first parameter must be the module's name with the full path */
+			module_name = g_strdup ((gchar *)priv->parameters->data);
+		}
+
+	if (module_name == NULL)
+		{
+			/* didn't find valid parameters */
+			return FALSE;
+		}
+
+	/* loading library */
+	priv->module = g_module_open (module_name, G_MODULE_BIND_LAZY);
+	if (!priv->module)
+		{
+			/* TO DO */
+			g_warning ("Error g_module_open.");
+			return FALSE;
+		}
+
+	return TRUE;
+}
+
 /**
  * aute_autentica:
  * @confi: un oggetto #Confi; se viene passato NULL verrà utilizzata la 
@@ -30,41 +149,30 @@
  * stringa vuota ("") se viene premuto "Annulla"; NULL in caso di errore.
  */
 gchar
-*aute_autentica (Confi *confi)
+*aute_autentica (Aute *aute)
 {
-	GModule *module;
-
-	gchar *(*autentica) (Confi *confi);
+	gchar *(*autentica) (GSList *parameters);
 	gchar *ret;
 
-	if (confi == NULL)
-		{
-			/* TO DO */
-			/* leggere il provider_id e cnc_string da GConf dell'utente */
-			confi = confi_new (NULL, "PostgreSQL", "HOSTADDR=127.0.0.1;PORT=5432;DATABASE=confi;HOST=localhost;USER=postgres", "Default", NULL, FALSE);
-			if (confi == NULL)
-				{
-					/* TO DO */
-					return NULL;
-				}
-		}
+	AutePrivate *priv = AUTE_GET_PRIVATE (aute);
+
+	g_return_val_if_fail (priv->module != NULL, NULL);
 
-	/* caricamento del plugin in base alla configurazione */
-	module = aute_plugin_get_module (confi);
+	ret = NULL;
 
-	/* carico la funzione */
-	if (!g_module_symbol (module, "autentica", (gpointer *)&autentica))
+	/* loading the function */
+	if (!g_module_symbol (priv->module, "autentica", (gpointer *)&autentica))
 		{
 			/* TO DO */
 			g_fprintf (stderr, "Error g_module_symbol\n");
 			return NULL;
 		}
 
-	/* chiamo la funzione del plugin */
-	ret = (*autentica) (confi);
+	/* calling plugin's function */
+	ret = (*autentica) (priv->parameters);
 
-	/* chiudo la libreria */
-	if (!g_module_close (module))
+	/* closing the library */
+	if (!g_module_close (priv->module))
 		{
 			g_fprintf (stderr, "Error g_module_close\n");
 		}
@@ -72,19 +180,60 @@ gchar
 	return ret;
 }
 
+/* PRIVATE */
+static void
+aute_set_property (GObject *object,
+                   guint property_id,
+                   const GValue *value,
+                   GParamSpec *pspec)
+{
+	Aute *aute = (Aute *)object;
+
+	AutePrivate *priv = AUTE_GET_PRIVATE (aute);
+
+	switch (property_id)
+		{
+			default:
+				G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+				break;
+	  }
+}
+
+static void
+aute_get_property (GObject *object,
+                   guint property_id,
+                   GValue *value,
+                   GParamSpec *pspec)
+{
+	Aute *aute = (Aute *)object;
+
+	AutePrivate *priv = AUTE_GET_PRIVATE (aute);
+
+	switch (property_id)
+		{
+			default:
+				G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+				break;
+	  }
+}
+
+#ifdef HAVE_LIBCONFI
 /**
  * aute_get_plugin_module:
- * @confi: un oggetto #Confi.
+ * @aute: un oggetto #Aute.
  *
- * Returns: l'oggetto #GModule corrispondente al plugin.
+ * Returns: il nome, con il percorso, del plugin.
  */
-GModule
-*aute_plugin_get_module (Confi *confi)
+gchar
+*aute_get_module_from_confi (Aute *aute)
 {
 	gchar *libname;
-	GModule *module = NULL;
 
-	libname = confi_path_get_value (confi, "aute/plugin");
+	AutePrivate *priv = AUTE_GET_PRIVATE (aute);
+
+	g_return_val_if_fail (IS_CONFI (priv->confi), NULL);
+
+	libname = confi_path_get_value (priv->confi, "aute/plugin");
 	if (libname == NULL)
 		{
 			/* TO DO */
@@ -93,14 +242,6 @@ GModule
 		}
 	libname = g_strconcat (LIBAUTE_PLUGINS_DIR "/", libname, NULL);
 
-	/* carico la libreria */
-	module = g_module_open (libname, G_MODULE_BIND_LAZY);
-	if (!module)
-		{
-			/* TO DO */
-			g_warning ("Error g_module_open.");
-			return NULL;
-		}
-
-	return module;
+	return libname;
 }
+#endif
diff --git a/src/libaute.h b/src/libaute.h
index 2bb25a7..82a0f2a 100644
--- a/src/libaute.h
+++ b/src/libaute.h
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2006 Andrea Zagli <azagli@libero.it>
+ * Copyright 2005-2010 Andrea Zagli <azagli@libero.it>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -20,17 +20,39 @@
 #define __AUTE_H__
 
 #include <glib.h>
+#include <glib-object.h>
 #include <gmodule.h>
 
-#include <libconfi.h>
+G_BEGIN_DECLS
 
+#define TYPE_AUTE                 (aute_get_type ())
+#define AUTE(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_AUTE, Aute))
+#define AUTE_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_AUTE, AuteClass))
+#define IS_AUTE(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_AUTE))
+#define IS_AUTE_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_AUTE))
+#define AUTE_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_AUTE, AuteClass))
 
-G_BEGIN_DECLS
 
+typedef struct _Aute Aute;
+typedef struct _AuteClass AuteClass;
+
+struct _Aute
+	{
+		GObject parent;
+	};
+
+struct _AuteClass
+	{
+		GObjectClass parent_class;
+	};
+
+GType aute_get_type (void) G_GNUC_CONST;
+
+Aute *aute_new (void);
 
-gchar *aute_autentica (Confi *confi);
+gboolean aute_set_config (Aute *aute, GSList *parameters);
 
-GModule *aute_plugin_get_module (Confi *confi);
+gchar *aute_autentica (Aute *aute);
 
 
 G_END_DECLS
-- 
2.49.0