]> saetta.ns0.it Git - zakaudit/libzakaudit/commitdiff
Adjustments, bugfixes and memory leaks.
authorAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Wed, 15 Jun 2011 10:56:21 +0000 (12:56 +0200)
committerAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Wed, 15 Jun 2011 10:56:21 +0000 (12:56 +0200)
configure.ac
src/Makefile.am
src/audit.c
src/libzakaudit.h

index ba5ead1bc4e4011630dbe8b8a24ebeca59b920ad..e4315e21adfefc13d987f37b8fc639bb1d703cc7 100644 (file)
@@ -2,11 +2,13 @@
 # Process this file with autoconf to produce a configure script.
 
 AC_PREREQ(2.59)
-AC_INIT([libzakaudit], [0.0.2], [azagli@libero.it])
+AC_INIT([libzakaudit], [0.3.0], [azagli@libero.it])
 AC_CONFIG_SRCDIR([src/audit.c])
 AC_CONFIG_HEADER([config.h])
 
-AM_INIT_AUTOMAKE
+AM_INIT_AUTOMAKE(-Wall)
+
+m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
 
 AM_MAINTAINER_MODE
 
@@ -28,7 +30,8 @@ if test "x$HAVE_PKGCONFIG" = "xno"; then
   AC_MSG_ERROR(you need to have pkgconfig installed !)
 fi
 
-PKG_CHECK_MODULES(LIBZAKAUDIT, libgdaex >= $GDAEX_REQUIRED)
+PKG_CHECK_MODULES(LIBZAKAUDIT, gtk+-2.0 >= 2.20
+                               libgdaex >= $GDAEX_REQUIRED)
 
 AC_SUBST(LIBZAKAUDIT_CFLAGS)
 AC_SUBST(LIBZAKAUDIT_LIBS)
index bd8e1d68cec9d69c4e4c97550ed8a54120c46bbd..a30bbc8466b6750fe130c330e893f21fb7435183 100644 (file)
@@ -1,5 +1,6 @@
-INCLUDES = $(WARN_CFLAGS) \
+AM_CPPFLAGS = $(WARN_CFLAGS) \
            $(DISABLE_DEPRECATED_CFLAGS) \
+           -DG_LOG_DOMAIN=\"ZakAudit\" \
            $(LIBZAKAUDIT_CFLAGS)
 
 LIBS = $(LIBZAKAUDIT_LIBS)
index 1c9f6e125cb358e0d3c0d2ae00bd8c11bbd2a79f..e485e3b48601cc8e51b7b632b3c57ca5b6e2e386 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * audit.c
  *
- * Copyright (C) 2005-2010 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2005-2011 Andrea Zagli <azagli@libero.it>
  *
  *  This file is part of libzak_audit.
  *  
@@ -144,13 +144,14 @@ load_fields (ZakAudit *zak_audit,
        gchar *sql;
        gint rows, row;
 
-       Field *cam;
+       Field *field;
 
        ZakAuditPrivate *priv = ZAK_AUDIT_GET_PRIVATE (zak_audit);
 
        /* check if table exists */
-       dm_table = gdaex_query (datasource->gdaex,
-                               g_strdup_printf ("SELECT * FROM %s", table->name));
+       sql = g_strdup_printf ("SELECT * FROM %s", table->name);
+       dm_table = gdaex_query (datasource->gdaex, sql);
+       g_free (sql);
        if (dm_table == NULL)
                {
                        g_warning ("The table «%s» doesn't exist on db.", table->name);
@@ -161,10 +162,10 @@ load_fields (ZakAudit *zak_audit,
                               " WHERE status <> 'D' AND id_tables = %d",
                               table->id);
        dm = gdaex_query (priv->gdaex, sql);
-
+       g_free (sql);
        if (dm == NULL)
                {
-                       g_warning ("For table \"%s\" fields have not been configured.",
+                       g_warning ("For table «%s» fields have not been configured.",
                                   table->name);
                        return FALSE;
                }
@@ -172,39 +173,44 @@ load_fields (ZakAudit *zak_audit,
        rows = gda_data_model_get_n_rows (dm);
        if (rows == 0)
                {
-                       g_warning ("For table \"%s\" fields have not been configured.",
+                       g_warning ("For table «%s» fields have not been configured.",
                                   table->name);
+                       g_object_unref (dm);
                        return FALSE;
                }
 
        for (row = 0; row < rows; row++)
                {
-                       cam = (Field *)g_malloc (sizeof (Field));
+                       field = g_new0 (Field, 1);
 
-                       cam->id = gdaex_data_model_get_field_value_integer_at (dm, row, "id");
-                       cam->name = gdaex_data_model_get_field_value_stringify_at (dm, row, "name");
-                       cam->is_key = gdaex_data_model_get_field_value_boolean_at (dm, row, "is_key");
+                       field->id = gdaex_data_model_get_field_value_integer_at (dm, row, "id");
+                       field->name = gdaex_data_model_get_field_value_stringify_at (dm, row, "name");
+                       field->is_key = gdaex_data_model_get_field_value_boolean_at (dm, row, "is_key");
 
-                       if (gda_data_model_get_column_index (dm_table, cam->name) < 0)
+                       if (gda_data_model_get_column_index (dm_table, field->name) < 0)
                                {
                                        g_warning ("The field «%s» doesn't exists on table «%s».",
-                                                  cam->name, table->name);
+                                                  field->name, table->name);
+                                       g_object_unref (dm);
                                        return FALSE;
                                }
 
-                       table->fields = g_list_append (table->fields, (gpointer)cam);
+                       table->fields = g_list_append (table->fields, (gpointer)field);
                        table->fields_sql = g_strconcat (table->fields_sql == NULL ? "" :
                                                         g_strconcat (table->fields_sql, ", ", NULL),
-                                                        cam->name, NULL);
-                       if (cam->is_key)
+                                                        field->name, NULL);
+                       if (field->is_key)
                                {
-                                       table->keys = g_list_append (table->fields, (gpointer)cam);
+                                       table->keys = g_list_append (table->fields, (gpointer)field);
                                        table->keys_sql = g_strconcat (table->keys_sql == NULL ? "" :
-                                                                                g_strconcat (table->keys_sql, ", ", NULL),
-                                                                                cam->name, NULL);
+                                                                      g_strconcat (table->keys_sql, ", ", NULL),
+                                                                      field->name, NULL);
                                }
                }
 
+       g_object_unref (dm_table);
+       g_object_unref (dm);
+
        if (table->keys == NULL)
                {
                        g_warning ("No key's fields defined for table «%s».",
@@ -230,25 +236,26 @@ load_tables (ZakAudit *zak_audit,
                               " WHERE status <> 'D' AND id_datasources = %d",
                               datasource->id);
        dm = gdaex_query (priv->gdaex, sql);
-
+       g_free (sql);
        if (dm == NULL)
                {
-                       g_warning ("For datasource \"%d\" tables have not been configured.",
+                       g_warning ("For datasource «%d» tables have not been configured.",
                                   datasource->id);
                        return FALSE;
                }
 
        rows = gda_data_model_get_n_rows (dm);
-       if (rows == 0)
+       if (rows < 1)
                {
-                       g_warning ("For datasource \"%d\" tables have not been configured.",
+                       g_warning ("For datasource «%d» tables have not been configured.",
                                   datasource->id);
+                       g_object_unref (dm);
                        return FALSE;
                }
 
        for (row = 0; row < rows; row++)
                {
-                       tab = (Table *)g_malloc (sizeof (Table));
+                       tab = g_new0 (Table, 1);
 
                        tab->id = gdaex_data_model_get_field_value_integer_at (dm, row, "id");
                        tab->name = gdaex_data_model_get_field_value_stringify_at (dm, row, "name");
@@ -260,11 +267,13 @@ load_tables (ZakAudit *zak_audit,
                        tab->keys_sql = NULL;
                        if (!load_fields (zak_audit, datasource, tab))
                                {
+                                       g_object_unref (dm);
                                        return FALSE;
                                }
 
                        datasource->tables = g_list_append (datasource->tables, (gpointer)tab);
                }
+       g_object_unref (dm);
 
   return TRUE;
 }
@@ -290,15 +299,16 @@ load_datasources (ZakAudit *zak_audit)
                }
 
        rows = gda_data_model_get_n_rows (dm);
-       if (rows == 0)
+       if (rows < 1)
                {
                        g_warning ("There are no datasources configured.");
+                       g_object_unref (dm);
                        return FALSE;
                }
 
        for (row = 0; row < rows; row++)
                {
-                       datas = (Datasource *)g_malloc (sizeof (Datasource));
+                       datas = g_new0 (Datasource, 1);
 
                        datas->id = gdaex_data_model_get_field_value_integer_at (dm, row, "id");
                        datas->name = gdaex_data_model_get_field_value_stringify_at (dm, row, "name");
@@ -315,9 +325,11 @@ load_datasources (ZakAudit *zak_audit)
                        datas->tables = NULL;
                        if (!load_tables (zak_audit, datas))
                                {
+                                       g_object_unref (dm);
                                        return FALSE;
                                }
                }
+       g_object_unref (dm);
 
        return TRUE;
 }
@@ -327,23 +339,27 @@ static Field
                       Table *table,
                       const char *field)
 {
+       Field *ret_field;
        GList *c = g_list_first (table->fields);
 
        gchar *real_field;
 
        real_field = string_unquote (field);
 
+       ret_field = NULL;
        while (c != NULL)
                {
                        if (g_strcmp0 (((Field *)c->data)->name, real_field) == 0)
                                {
-                                       return (Field *)c->data;
+                                       ret_field = (Field *)c->data;
+                                       break;
                                }
 
                        c = g_list_next (c);
                }
+       g_free (real_field);
 
-       return NULL;
+       return ret_field;
 }
 
 static Table
@@ -351,29 +367,35 @@ static Table
                         Datasource *datasource,
                         const char *table)
 {
+       Table *ret_table;
        GList *t = g_list_first (datasource->tables);
 
        gchar *real_table;
 
        real_table = string_unquote (table);
 
+       ret_table = NULL;
        while (t != NULL)
                {
                        if (g_strcmp0 (((Table *)t->data)->name, real_table) == 0)
                                {
-                                       return (Table *)t->data;
+                                       ret_table = (Table *)t->data;
+                                       break;
                                }
 
                        t = g_list_next (t);
                }
+       g_free (real_table);
 
-       return NULL;
+       return ret_table;
 }
 
 static Datasource
 *get_datasource_from_name (ZakAudit *zak_audit,
                            const char *datasource)
 {
+       Datasource *ret_datasource;
+
        ZakAuditPrivate *priv = ZAK_AUDIT_GET_PRIVATE (zak_audit);
 
        GList *f = g_list_first (priv->datasources);
@@ -382,17 +404,19 @@ static Datasource
 
        real_datasource = string_unquote (datasource);
 
+       ret_datasource = NULL;
        while (f != NULL)
                {
                        if (g_strcmp0 (((Datasource *)f->data)->name, real_datasource) == 0)
                                {
-                                       return (Datasource *)f->data;
+                                       ret_datasource = (Datasource *)f->data;
                                }
 
                        f = g_list_next (f);
                }
+       g_free (real_datasource);
 
-       return NULL;
+       return ret_datasource;
 }
 
 static gboolean
@@ -410,7 +434,7 @@ insert_value (ZakAudit *zak_audit,
        Field *field = get_field_from_name (zak_audit, table, field_name);
        if (field == NULL)
                {
-                       g_warning ("Unable to find the field \"%s\" on loaded fields.",
+                       g_warning ("Unable to find the field «%s» on loaded fields.",
                                   field_name);
                }
        else
@@ -433,6 +457,9 @@ insert_value (ZakAudit *zak_audit,
                                               id_actions, field->id,
                                               real_value);
                        gdaex_execute (priv->gdaex, sql);
+
+                       g_free (sql);
+                       g_free (real_value);
                }
 
        return TRUE;
@@ -447,10 +474,10 @@ parse_cond (GdaSqlExpr *cond, gchar **str)
                        GdaSqlExpr *op2 = (GdaSqlExpr *)cond->cond->operands->next->data;
 
                        *str = g_strconcat (*str, (g_strcmp0 (*str, "") != 0 ? "|" : ""),
-                                                           gda_value_stringify (op1->value),
-                                                           "|",
-                                                           gda_value_stringify (op2->value),
-                                                           NULL);
+                                           gda_value_stringify (op1->value),
+                                           "|",
+                                           gda_value_stringify (op2->value),
+                                           NULL);
                }
        else
                {
@@ -495,7 +522,6 @@ static void
 zak_audit_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
 {
        ZakAudit *zak_audit = ZAK_AUDIT (object);
-
        ZakAuditPrivate *priv = ZAK_AUDIT_GET_PRIVATE (zak_audit);
 
        switch (property_id)
@@ -510,7 +536,6 @@ static void
 zak_audit_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
 {
        ZakAudit *zak_audit = ZAK_AUDIT (object);
-
        ZakAuditPrivate *priv = ZAK_AUDIT_GET_PRIVATE (zak_audit);
 
        switch (property_id)
@@ -541,7 +566,7 @@ ZakAudit
        if (priv->gdaex == NULL)
                {
                        /* TODO */
-                       g_message ("Error creating GdaEx object.");
+                       g_warning ("Error creating GdaEx object.");
                        return NULL;
                }
 
@@ -549,7 +574,7 @@ ZakAudit
        if (!load_datasources (zak_audit))
                {
                        /* TODO */
-                       g_message ("Error loading datasources.");
+                       g_warning ("Error loading datasources.");
                        return NULL;
                }
 
@@ -574,7 +599,7 @@ ZakAudit
        if (priv->gdaex == NULL)
                {
                        /* TODO */
-                       g_message ("Error creating GdaEx object.");
+                       g_warning ("Error creating GdaEx object.");
                        return NULL;
                }
 
@@ -582,7 +607,7 @@ ZakAudit
        if (!load_datasources (zak_audit))
                {
                        /* TODO */
-                       g_message ("Error loading datasources.");
+                       g_warning ("Error loading datasources.");
                        return NULL;
                }
 
@@ -638,6 +663,7 @@ zak_audit_action (ZakAudit *zak_audit,
                {
                        ret = zak_audit_action_v (zak_audit, action, username, datasource_name, table_name, (const gchar **)g_strsplit (str, "|", -1));
                }
+       g_free (str);
 
        return ret;
 }
@@ -735,7 +761,7 @@ zak_audit_action_v (ZakAudit *zak_audit,
        datasource = get_datasource_from_name (zak_audit, datasource_name);
        if (datasource == NULL)
                {
-                       g_warning ("Unable to find the datasource \"%s\" on loaded datasources.",
+                       g_warning ("Unable to find the datasource «%s» on loaded datasources.",
                                   datasource_name);
                        return FALSE;
                }
@@ -744,7 +770,7 @@ zak_audit_action_v (ZakAudit *zak_audit,
        table = get_table_from_name (zak_audit, datasource, table_name);
        if (table == NULL)
                {
-                       g_warning ("Unable to find the table \"%s\" on loaded tables.",
+                       g_warning ("Unable to find the table «%s» on loaded tables.",
                                   table_name);
                        return FALSE;
                }
@@ -761,6 +787,7 @@ zak_audit_action_v (ZakAudit *zak_audit,
                                               tm_ora->tm_hour, tm_ora->tm_min, tm_ora->tm_sec,
                                               table->id);
                        gdaex_execute (priv->gdaex, sql);
+                       g_free (sql);
                }
 
        l = g_strv_length ((gchar **)fields_values);
@@ -790,11 +817,16 @@ zak_audit_action_v (ZakAudit *zak_audit,
 
                                sql = g_strconcat (sql, sql_where, NULL);
                                dm = gdaex_query (datasource->gdaex, sql);
+                               g_free (sql);
+                               g_free (sql_where);
 
                                if (dm == NULL) return FALSE;
 
                                if (gda_data_model_get_n_rows (dm) == 0 ||
-                                   gda_data_model_get_n_rows (dm) > 1) return FALSE;
+                                   gda_data_model_get_n_rows (dm) > 1)
+                                       {
+                                               return FALSE;
+                                       }
 
                                cols = gda_data_model_get_n_columns (dm);
                                for (col = 0; col < cols; col++)
@@ -833,11 +865,16 @@ zak_audit_action_v (ZakAudit *zak_audit,
                                        }
                                sql = g_strconcat (sql, sql_where, NULL);
                                dm = gdaex_query (datasource->gdaex, sql);
+                               g_free (sql);
+                               g_free (sql_where);
 
                                if (dm == NULL) return FALSE;
 
                                if (gda_data_model_get_n_rows (dm) == 0 ||
-                                   gda_data_model_get_n_rows (dm) > 1) return FALSE;
+                                   gda_data_model_get_n_rows (dm) > 1)
+                                       {
+                                               return FALSE;
+                                       }
 
                                priv->fields_updated = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
                                cols = gda_data_model_get_n_columns (dm);
@@ -877,11 +914,16 @@ zak_audit_action_v (ZakAudit *zak_audit,
                                        }
                                sql = g_strconcat (sql, sql_where, NULL);
                                dm = gdaex_query (datasource->gdaex, sql);
+                               g_free (sql);
+                               g_free (sql_where);
 
                                if (dm == NULL) return FALSE;
 
                                if (gda_data_model_get_n_rows (dm) == 0 ||
-                                   gda_data_model_get_n_rows (dm) > 1) return FALSE;
+                                   gda_data_model_get_n_rows (dm) > 1)
+                                       {
+                                               return FALSE;
+                                       }
 
                                cols = gda_data_model_get_n_columns (dm);
                                for (col = 0; col < cols; col++)
@@ -928,11 +970,16 @@ zak_audit_action_v (ZakAudit *zak_audit,
                                        }
                                sql = g_strconcat (sql, sql_where, NULL);
                                dm = gdaex_query (datasource->gdaex, sql);
+                               g_free (sql);
+                               g_free (sql_where);
 
                                if (dm == NULL) return FALSE;
 
                                if (gda_data_model_get_n_rows (dm) == 0 ||
-                                   gda_data_model_get_n_rows (dm) > 1) return FALSE;
+                                   gda_data_model_get_n_rows (dm) > 1)
+                                       {
+                                               return FALSE;
+                                       }
 
                                cols = gda_data_model_get_n_columns (dm);
                                for (col = 0; col < cols; col++)
@@ -1101,7 +1148,7 @@ zak_audit_get_record_at (ZakAudit *zak_audit,
        datasource = get_datasource_from_name (zak_audit, datasource_name);
        if (datasource == NULL)
                {
-                       g_warning ("Unable to find the datasource \"%s\" on loaded datasources.",
+                       g_warning ("Unable to find the datasource «%s» on loaded datasources.",
                                   datasource_name);
                        return FALSE;
                }
index f8b963da82b3b0d68d9cb4f59aaff489833fec8f..450d0b715a9d5b3ffc3b8c0402700a3531087ff5 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * libzakaudit.h
  *
- * Copyright (C) 2005-2010 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2005-2011 Andrea Zagli <azagli@libero.it>
  *
  *  This file is part of libzak_audit.
  *  
@@ -23,7 +23,7 @@
 #include <glib.h>
 #include <glib-object.h>
 
-#include <libgdaex.h>
+#include <libgdaex/libgdaex.h>
 
 #ifndef __ZAK_AUDIT_H__
 #define __ZAK_AUDIT_H__