summaryrefslogtreecommitdiffstats
path: root/common/collection/collection.c
diff options
context:
space:
mode:
authorDmitri Pal <dpal@redhat.com>2010-07-23 14:33:56 -0400
committerDmitri Pal <dpal@redhat.com>2010-08-10 12:51:32 -0400
commita1935263ae19d2161b1e425135864c7edb9efe49 (patch)
tree1aa3effc6bc353bf7239fad55727487f6b35b2f1 /common/collection/collection.c
parent85acfe3f0e53db93a741040d12642083260664f6 (diff)
downloadsssd-a1935263ae19d2161b1e425135864c7edb9efe49.tar.gz
sssd-a1935263ae19d2161b1e425135864c7edb9efe49.tar.xz
sssd-a1935263ae19d2161b1e425135864c7edb9efe49.zip
[COLLECTION] Allow destroying collection with a callback
Addresses ticket #572 Bumps the library and interface version. Updates the docs. [COLLECTION] Changed callback signature
Diffstat (limited to 'common/collection/collection.c')
-rw-r--r--common/collection/collection.c57
1 files changed, 47 insertions, 10 deletions
diff --git a/common/collection/collection.c b/common/collection/collection.c
index 87ac321..f24102b 100644
--- a/common/collection/collection.c
+++ b/common/collection/collection.c
@@ -172,8 +172,11 @@ static int col_validate_property(const char *property)
return invalid;
}
-/* Function that cleans the item */
-void col_delete_item(struct collection_item *item)
+
+/* Function that cleans the item with callback */
+static void col_delete_item_with_cb(struct collection_item *item,
+ col_item_cleanup_fn cb,
+ void *custom_data)
{
struct collection_item *other_collection;
@@ -189,9 +192,17 @@ void col_delete_item(struct collection_item *item)
/* Our data is a pointer to a whole external collection so dereference
* it or delete */
other_collection = *((struct collection_item **)(item->data));
- col_destroy_collection(other_collection);
+ col_destroy_collection_with_cb(other_collection, cb, custom_data);
}
+ /* Call the callback */
+ if (cb) cb(item->property,
+ item->property_len,
+ item->type,
+ item->data,
+ item->length,
+ custom_data);
+
TRACE_INFO_STRING("Deleting property:", item->property);
TRACE_INFO_NUMBER("Type:", item->type);
@@ -203,6 +214,18 @@ void col_delete_item(struct collection_item *item)
TRACE_FLOW_STRING("col_delete_item","Exit.");
}
+/* Function that cleans the item */
+void col_delete_item(struct collection_item *item)
+{
+ TRACE_FLOW_STRING("col_delete_item","Entry point.");
+
+ col_delete_item_with_cb(item, NULL, NULL);
+
+ TRACE_FLOW_STRING("col_delete_item","Exit.");
+}
+
+
+
/* A generic function to allocate a property item */
int col_allocate_item(struct collection_item **ci, const char *property,
const void *item_data, int length, int type)
@@ -1164,7 +1187,9 @@ static int col_get_subcollection(const char *property,
/* Cleans the collection tree including current item. */
/* The passed in variable should not be used after the call
* as memory is freed!!! */
-static void col_delete_collection(struct collection_item *ci)
+static void col_delete_collection(struct collection_item *ci,
+ col_item_cleanup_fn cb,
+ void *custom_data)
{
TRACE_FLOW_STRING("col_delete_collection", "Entry.");
@@ -1177,10 +1202,10 @@ static void col_delete_collection(struct collection_item *ci)
TRACE_INFO_STRING("Property", ci->property);
TRACE_INFO_NUMBER("Next item", ci->next);
- col_delete_collection(ci->next);
+ col_delete_collection(ci->next, cb, custom_data);
/* Delete this item */
- col_delete_item(ci);
+ col_delete_item_with_cb(ci, cb, custom_data);
TRACE_FLOW_STRING("col_delete_collection", "Exit.");
}
@@ -2235,11 +2260,13 @@ int col_create_collection(struct collection_item **ci, const char *name,
/* DESTROY */
/* Function that destroys a collection */
-void col_destroy_collection(struct collection_item *ci)
+void col_destroy_collection_with_cb(struct collection_item *ci,
+ col_item_cleanup_fn cb,
+ void *custom_data)
{
struct collection_header *header;
- TRACE_FLOW_STRING("col_destroy_collection", "Entry.");
+ TRACE_FLOW_STRING("col_destroy_collection_with_cb", "Entry.");
/* Do not try to delete NULL */
if (ci == NULL) return;
@@ -2263,13 +2290,23 @@ void col_destroy_collection(struct collection_item *ci)
header->reference_count);
}
else {
- col_delete_collection(ci);
+ col_delete_collection(ci, cb, custom_data);
}
- TRACE_FLOW_STRING("col_destroy_collection", "Exit.");
+ TRACE_FLOW_STRING("col_destroy_collection_with_cb", "Exit.");
}
+/* Function that destroys a collection */
+void col_destroy_collection(struct collection_item *ci)
+{
+ TRACE_FLOW_STRING("col_destroy_collection", "Entry.");
+
+ col_destroy_collection_with_cb(ci, NULL, NULL);
+
+ TRACE_FLOW_STRING("col_destroy_collection", "Exit.");
+}
+
/* COPY */
/* Wrapper around a more advanced function */