diff options
author | Dmitri Pal <dpal@redhat.com> | 2009-07-15 15:17:53 -0400 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2009-07-16 16:29:52 -0400 |
commit | 08edf9d6445f3962bf31d5f3c9fa5c9cb363c30d (patch) | |
tree | 410a86adb5653204f0f8f476e377a8a89c803102 /common/collection/collection.c | |
parent | 699f1a55fd6358f04ce90d44380f1a7cb75614b6 (diff) | |
download | sssd-08edf9d6445f3962bf31d5f3c9fa5c9cb363c30d.tar.gz sssd-08edf9d6445f3962bf31d5f3c9fa5c9cb363c30d.tar.xz sssd-08edf9d6445f3962bf31d5f3c9fa5c9cb363c30d.zip |
COLLECTION Add remove item functions
The remove functions extract and remove
items, they act differently from the way
the delete_property function works.
The new functions allow deletion with
the disposition while the delete_property
only deletes specified property.
The delete_property function is left as is
since there are some use cases when it is
more efficient to use it rather than new
remove_item_xxx ones.
Diffstat (limited to 'common/collection/collection.c')
-rw-r--r-- | common/collection/collection.c | 62 |
1 files changed, 60 insertions, 2 deletions
diff --git a/common/collection/collection.c b/common/collection/collection.c index 69475b048..113d9f037 100644 --- a/common/collection/collection.c +++ b/common/collection/collection.c @@ -683,7 +683,7 @@ int col_extract_item_from_current(struct collection_item *collection, *ret_ref = current->next; current->next = (*ret_ref)->next; /* If we removed the last element adjust header */ - if(current->next == NULL) header->last = parent; + if(current->next == NULL) header->last = current; } else { TRACE_ERROR_STRING("Property is last in the list", refprop); @@ -817,7 +817,7 @@ int col_extract_item(struct collection_item *collection, type, ret_ref); if (error) { - TRACE_ERROR_NUMBER("Failed extract item into current collection", error); + TRACE_ERROR_NUMBER("Failed to extract item from the current collection", error); return error; } @@ -826,6 +826,64 @@ int col_extract_item(struct collection_item *collection, } +/* Remove item (property) from collection.*/ +int col_remove_item(struct collection_item *ci, + const char *subcollection, + int disposition, + const char *refprop, + int idx, + int type) +{ + int error = EOK; + struct collection_item *ret_ref = NULL; + + TRACE_FLOW_STRING("col_remove_item", "Exit"); + + /* Extract from the current collection */ + error = col_extract_item(ci, + subcollection, + disposition, + refprop, + idx, + type, + &ret_ref); + if (error) { + TRACE_ERROR_NUMBER("Failed to extract item from the collection", error); + return error; + } + + col_delete_item(ret_ref); + + TRACE_FLOW_STRING("col_remove_item", "Exit"); + return EOK; +} + +/* Remove item (property) from current collection. + * Just a simple wropper. + */ +int col_remove_item_from_current(struct collection_item *ci, + int disposition, + const char *refprop, + int idx, + int type) +{ + int error = EOK; + + TRACE_FLOW_STRING("col_remove_item_from_current", "Exit"); + + /* Remove item from current collection */ + error = col_remove_item(ci, + NULL, + disposition, + refprop, + idx, + type); + + TRACE_FLOW_NUMBER("col_remove_item_from_current. Exit. Returning", error); + return error; +} + + /* Insert the item into the collection or subcollection */ int col_insert_item(struct collection_item *collection, const char *subcollection, |