]> saetta.ns0.it Git - zakaudit/libzakaudit/commitdiff
Boxed Table struct.
authorAndrea Zagli <azagli@libero.it>
Sat, 28 Dec 2019 10:26:47 +0000 (11:26 +0100)
committerAndrea Zagli <azagli@libero.it>
Sat, 28 Dec 2019 10:26:47 +0000 (11:26 +0100)
src/audit.c
src/libzakaudit.h

index f319bad941651a080b97bfbd9849c7f33f97fd4e..da610b01cecd1704b31c51f64bb47ba6f83e0ed3 100644 (file)
@@ -70,16 +70,6 @@ typedef struct
        gboolean is_key;
 } Field;
 
-typedef struct
-{
-       gint id;
-       gchar *name;
-       GList *fields;
-       gchar *fields_sql;
-       GList *keys;
-       gchar *keys_sql;
-} Table;
-
 typedef struct
 {
        gchar **values;
@@ -92,21 +82,21 @@ static void zak_audit_init (ZakAudit *zak_audit);
 static ZakAudit *zak_audit_new_ (void);
 static gboolean load_fields (ZakAudit *zak_audit,
                              ZakAuditDatasource *datasource,
-                             Table *table);
+                             ZakAuditTable *table);
 static gboolean load_tables (ZakAudit *zak_audit,
                              ZakAuditDatasource *datasource);
 static gboolean load_datasources (ZakAudit *zak_audit, va_list ap);
 static Field *get_field_from_name (ZakAudit *zak_audit,
-                                   Table *table,
+                                   ZakAuditTable *table,
                                    const char *field);
-static Table *get_table_from_name (ZakAudit *zak_audit,
+static ZakAuditTable *get_table_from_name (ZakAudit *zak_audit,
                                    ZakAuditDatasource *datasource,
                                    const char *table);
 static ZakAuditDatasource *get_datasource_from_name (ZakAudit *zak_audit,
                                              const char *datasource);
 static gboolean insert_value (ZakAudit *zak_audit,
                               gint id_actions,
-                              Table *table,
+                              ZakAuditTable *table,
                               gchar *field_name,
                               gchar *value);
 static gchar *string_unquote (const gchar *value);
@@ -243,24 +233,10 @@ free_field (gpointer data)
        g_free (f->name);
 }
 
-static void
-free_table (gpointer data)
-{
-       Table *t;
-
-       t = (Table *)data;
-
-       g_free (t->name);
-       g_list_free_full (t->fields, free_field);
-       g_free (t->fields_sql);
-       g_list_free_full (t->keys, free_field);
-       g_free (t->keys_sql);
-}
-
 static gboolean
 load_fields (ZakAudit *zak_audit,
              ZakAuditDatasource *datasource,
-             Table *table)
+             ZakAuditTable *table)
 {
        GdaDataModel *dm;
        GdaDataModel *dm_table;
@@ -352,7 +328,7 @@ load_tables (ZakAudit *zak_audit,
        GdaDataModel *dm;
        gchar *sql;
        gint rows, row;
-       Table *tab;
+       ZakAuditTable *tab;
 
        ZakAuditPrivate *priv = ZAK_AUDIT_GET_PRIVATE (zak_audit);
 
@@ -379,7 +355,7 @@ load_tables (ZakAudit *zak_audit,
 
        for (row = 0; row < rows; row++)
                {
-                       tab = g_new0 (Table, 1);
+                       tab = g_new0 (ZakAuditTable, 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");
@@ -498,7 +474,7 @@ load_datasources (ZakAudit *zak_audit, va_list ap)
 
 static Field
 *get_field_from_name (ZakAudit *zak_audit,
-                      Table *table,
+                      ZakAuditTable *table,
                       const char *field)
 {
        Field *ret_field;
@@ -524,12 +500,12 @@ static Field
        return ret_field;
 }
 
-static Table
+static ZakAuditTable
 *get_table_from_name (ZakAudit *zak_audit,
                         ZakAuditDatasource *datasource,
                         const char *table)
 {
-       Table *ret_table;
+       ZakAuditTable *ret_table;
        GList *t = g_list_first (datasource->tables);
 
        gchar *real_table;
@@ -539,9 +515,9 @@ static Table
        ret_table = NULL;
        while (t != NULL)
                {
-                       if (g_strcmp0 (((Table *)t->data)->name, real_table) == 0)
+                       if (g_strcmp0 (((ZakAuditTable *)t->data)->name, real_table) == 0)
                                {
-                                       ret_table = (Table *)t->data;
+                                       ret_table = (ZakAuditTable *)t->data;
                                        break;
                                }
 
@@ -584,7 +560,7 @@ static ZakAuditDatasource
 static gboolean
 insert_value (ZakAudit *zak_audit,
               gint id_actions,
-              Table *table,
+              ZakAuditTable *table,
               gchar *field_name,
               gchar *value)
 {
@@ -993,7 +969,7 @@ zak_audit_action_v (ZakAudit *zak_audit,
        gint col;
        GDateTime *gdt;
        ZakAuditDatasource *datasource;
-       Table *table;
+       ZakAuditTable *table;
 
        ZakAuditPrivate *priv = ZAK_AUDIT_GET_PRIVATE (zak_audit);
 
@@ -1373,7 +1349,7 @@ zak_audit_action_from_where (ZakAudit *zak_audit,
        gboolean ret;
 
        ZakAuditDatasource *datasource;
-       Table *table;
+       ZakAuditTable *table;
 
        GdaConnection *conn;
        GdaSqlParser *parser;
@@ -1751,7 +1727,7 @@ GtkWidget
        GtkWidget *ret;
 
        ZakAuditDatasource *datasource;
-       Table *table;
+       ZakAuditTable *table;
        Field *field;
 
        guint l;
@@ -2145,7 +2121,7 @@ const gchar
                                const gchar **key_values)
 {
        ZakAuditDatasource *datasource;
-       Table *table;
+       ZakAuditTable *table;
        Field *field;
 
        guint l;
@@ -2361,19 +2337,46 @@ GOptionGroup
        return ret;
 }
 
+ZakAuditTable
+*zak_audit_table_copy (ZakAuditTable *table)
+{
+       ZakAuditTable *t;
+
+       t = g_slice_new (ZakAuditTable);
+       t->id = table->id;
+       t->name = g_strdup (table->name);
+       t->fields = g_list_copy (table->fields);
+       t->fields_sql = g_strdup (table->fields_sql);
+       t->keys = g_list_copy (table->keys);
+       t->keys_sql = g_strdup (table->keys_sql);
+
+       return t;
+}
+
+void
+zak_audit_table_free (ZakAuditTable *table)
+{
+       g_free (table->name);
+       g_list_free_full (table->fields, free_field);
+       g_free (table->fields_sql);
+       g_list_free_full (table->keys, free_field);
+       g_free (table->keys_sql);
+       g_slice_free (ZakAuditTable, table);
+}
+
 ZakAuditDatasource
 *zak_audit_datasource_copy (ZakAuditDatasource *datasource)
 {
-       ZakAuditDatasource *b;
+       ZakAuditDatasource *d;
 
-       b = g_slice_new (ZakAuditDatasource);
-       b->id = datasource->id;
-       b->name = g_strdup (datasource->name);
-       b->cnc_string = g_strdup (datasource->cnc_string);
-       b->gdaex = g_object_ref (datasource->gdaex);
-       b->tables = g_list_copy (datasource->tables);
+       d = g_slice_new (ZakAuditDatasource);
+       d->id = datasource->id;
+       d->name = g_strdup (datasource->name);
+       d->cnc_string = g_strdup (datasource->cnc_string);
+       d->gdaex = g_object_ref (datasource->gdaex);
+       d->tables = g_list_copy (datasource->tables);
 
-       return b;
+       return d;
 }
 
 void
@@ -2382,6 +2385,6 @@ zak_audit_datasource_free (ZakAuditDatasource *datasource)
        g_free (datasource->name);
        g_free (datasource->cnc_string);
        g_object_unref (datasource->gdaex);
-       g_list_free_full (datasource->tables, free_table);
+       g_list_free_full (datasource->tables, g_free);
        g_slice_free (ZakAuditDatasource, datasource);
 }
index e4ceb547971763ad608af852d38051a02b482c4b..3b549a3428083ea30fde3d468ab189c60b07be40 100644 (file)
@@ -115,6 +115,19 @@ void zak_audit_destroy (ZakAudit *zak_audit);
 
 GOptionGroup *zak_audit_get_option_group (ZakAudit *zak_audit);
 
+typedef struct
+{
+       gint id;
+       gchar *name;
+       GList *fields;
+       gchar *fields_sql;
+       GList *keys;
+       gchar *keys_sql;
+} ZakAuditTable;
+
+ZakAuditTable *zak_audit_table_copy (ZakAuditTable *table);
+void zak_audit_table_free (ZakAuditTable *table);
+
 typedef struct
 {
        gint id;