]> saetta.ns0.it Git - zakaudit/libzakaudit/commitdiff
Added function Audit::audit_action_v.
authorAndrea Zagli <azagli@libero.it>
Sat, 5 Jun 2010 09:49:53 +0000 (11:49 +0200)
committerAndrea Zagli <azagli@libero.it>
Sat, 5 Jun 2010 09:49:53 +0000 (11:49 +0200)
src/audit.c
src/libaudit.h

index ca35600c2f5a81b2603e8ec84186411cfae37c62..f195a3af3b5383ad01698a4de71eb7ec808d407f 100644 (file)
@@ -452,8 +452,9 @@ Audit
  * @audit: l'oggetto #Audit su cui effettuare l'azione.
  * @action: il tipo di azione.
  * @dn: lo username che effettua l'azione.
- * @datasource:
- * @tabella:
+ * @datasource_name: the datasource's name.
+ * @table_name: the table's name.
+ * @...: a #NULL terminated list of couples field-value.
  *
  * Returns: #TRUE se l'azione viene effettuata con successo.
  */
@@ -464,6 +465,60 @@ audit_action (Audit *audit,
               const gchar *datasource_name,
               const gchar *table_name,
               ...)
+{
+       va_list vargs;
+       gchar *str;
+       gchar **fields_values;
+       gchar *field_name;
+       gchar *field_value;
+
+       gboolean ret;
+
+       ret = FALSE;
+       str = g_strdup ("");
+
+       va_start (vargs, table_name);
+
+       field_name = va_arg (vargs, gchar *);
+       while (field_name != NULL)
+               {
+                       field_value = va_arg (vargs, gchar *);
+                       if (field_value == NULL) break;
+
+                       str = g_strconcat (str, (g_strcmp0 (str, "") != 0 ? "|" : ""), field_name, "|", field_value, NULL);
+
+                       field_name = va_arg (vargs, gchar *);
+               }
+
+       va_end (vargs);
+
+       if (g_strcmp0 (str, "") != 0)
+               {
+                       ret = audit_action_v (audit, action, dn, datasource_name, table_name, (const gchar **)g_strsplit (str, "|", -1));
+               }
+
+       return ret;
+}
+
+/**
+ * audit_action_v:
+ * @audit: l'oggetto #Audit su cui effettuare l'azione.
+ * @action: the action's type.
+ * @dn: lo username che effettua l'azione.
+ * @datasource_name: the datasource's name.
+ * @table_name: the table's name.
+ * @fields_values: a #NULL-terminated array of strings in the form
+ *                 "<field_name><field_value><field_name><field_value>...#NULL"
+ *
+ * Returns: #TRUE se l'azione viene effettuata con successo.
+ */
+gboolean
+audit_action_v (Audit *audit,
+              enum AuditActions action,
+              const gchar *dn,
+              const gchar *datasource_name,
+              const gchar *table_name,
+              const gchar **fields_values)
 {
        GdaDataModel *dm;
        gchar *sql;
@@ -471,12 +526,13 @@ audit_action (Audit *audit,
        gchar *field_name;
        gchar *value;
        gchar *value_new;
+       gint l;
+       gint strpart;
        gint id = 0;
        gint cols;
        gint col;
        time_t t;
        struct tm *tm_ora;
-       va_list vargs;
        Datasource *datasource;
        Table *table;
 
@@ -533,9 +589,9 @@ audit_action (Audit *audit,
                        gdaex_execute (priv->gdaex, sql);
                }
 
-       /* fields */
-       va_start (vargs, table_name);
+       l = g_strv_length ((gchar **)fields_values);
 
+       /* fields */
        switch (action)
                {
                        case AUDIT_ACTION_INSERT:
@@ -544,15 +600,18 @@ audit_action (Audit *audit,
                                                       table_name);
 
                                sql_where = g_strdup (" WHERE TRUE");
-                               field_name = va_arg (vargs, gchar *);
-                               while (field_name != NULL)
+                               for (strpart = 0; strpart < l; strpart++)
                                        {
-                                               value = va_arg (vargs, gchar *);
+                                               field_name = (gchar *)fields_values[strpart];
+                                               if (field_name == NULL) break;
+
+                                               if (strpart + 1 >= l) break;
+
+                                               value = (gchar *)fields_values[++strpart];
                                                if (value == NULL) break;
 
                                                /* TODO the db field can be other type than string */
                                                sql_where = g_strconcat (sql_where, " AND ", field_name, " = ", value, "", NULL);
-                                               field_name = va_arg (vargs, gchar *);
                                        }
                                sql = g_strconcat (sql, sql_where, NULL);
                                dm = gdaex_query (datasource->gdaex, sql);
@@ -578,15 +637,18 @@ audit_action (Audit *audit,
                                                       table_name);
 
                                sql_where = g_strdup (" WHERE TRUE");
-                               field_name = va_arg (vargs, gchar *);
-                               while (field_name != NULL)
+                               for (strpart = 0; strpart < l; strpart++)
                                        {
-                                               value = va_arg (vargs, gchar *);
+                                               field_name = (gchar *)fields_values[strpart];
+                                               if (field_name == NULL) break;
+
+                                               if (strpart + 1 >= l) break;
+
+                                               value = (gchar *)fields_values[++strpart];
                                                if (value == NULL) break;
 
                                                /* TODO the db field can be other type than string */
                                                sql_where = g_strconcat (sql_where, " AND ", field_name, " = ", value, "", NULL);
-                                               field_name = va_arg (vargs, gchar *);
                                        }
                                sql = g_strconcat (sql, sql_where, NULL);
                                dm = gdaex_query (datasource->gdaex, sql);
@@ -612,15 +674,18 @@ audit_action (Audit *audit,
                                                       table_name);
 
                                sql_where = g_strdup (" WHERE TRUE");
-                               field_name = va_arg (vargs, gchar *);
-                               while (field_name != NULL)
+                               for (strpart = 0; strpart < l; strpart++)
                                        {
-                                               value = va_arg (vargs, gchar *);
+                                               field_name = (gchar *)fields_values[strpart];
+                                               if (field_name == NULL) break;
+
+                                               if (strpart + 1 >= l) break;
+
+                                               value = (gchar *)fields_values[++strpart];
                                                if (value == NULL) break;
 
                                                /* TODO the db field can be other type than string */
                                                sql_where = g_strconcat (sql_where, " AND ", field_name, " = ", value, "", NULL);
-                                               field_name = va_arg (vargs, gchar *);
                                        }
                                sql = g_strconcat (sql, sql_where, NULL);
                                dm = gdaex_query (datasource->gdaex, sql);
@@ -647,15 +712,17 @@ audit_action (Audit *audit,
 
                        case AUDIT_ACTION_DELETE:
                                /* salvo solo i fields della chiave */
-                               field_name = va_arg (vargs, gchar *);
-                               while (field_name != NULL)
+                               for (strpart = 0; strpart < l; strpart++)
                                        {
-                                               value = va_arg (vargs, gchar *);
+                                               field_name = (gchar *)fields_values[strpart];
+                                               if (field_name == NULL) break;
+
+                                               if (strpart + 1 >= l) break;
+
+                                               value = (gchar *)fields_values[++strpart];
                                                if (value == NULL) break;
 
                                                insert_value (audit, id, table, field_name, value);
-
-                                               field_name = va_arg (vargs, gchar *);
                                        }
                                break;
 
@@ -663,8 +730,6 @@ audit_action (Audit *audit,
                                return FALSE;
                };
 
-       va_end (vargs);
-
        return TRUE;
 }
 
index 9817b9c6690328bc80078d8f672c3a7aea0e4ee8..0b71bc17d0bdc2ed4c2ccf9797f8a6fc73dbe20c 100644 (file)
@@ -73,6 +73,13 @@ gboolean audit_action (Audit *audit,
                        const gchar *table_name,
                        ...);
 
+gboolean audit_action_v (Audit *audit,
+                       enum AuditActions action,
+                       const gchar *dn,
+                       const gchar *datasource_name,
+                       const gchar *table_name,
+                       const gchar **fields_values);
+
 void audit_destroy (Audit *audit);