diff options
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 69475b04..113d9f03 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, |