diff options
author | Dmitri Pal <dpal@redhat.com> | 2009-10-25 13:21:24 -0400 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2009-12-10 17:20:26 -0500 |
commit | 18c06c0836306c194e5f89e37d2f3913b3bf01e4 (patch) | |
tree | c991c0a4fa484733c14822769f71f04d90492711 /common | |
parent | 7faf7764c8b99bd51e952f24350dcdb05f9ab78e (diff) | |
download | sssd-18c06c0836306c194e5f89e37d2f3913b3bf01e4.tar.gz sssd-18c06c0836306c194e5f89e37d2f3913b3bf01e4.tar.bz2 sssd-18c06c0836306c194e5f89e37d2f3913b3bf01e4.zip |
COLLECTION Create reference to the top level collection
This patch adds ability to create a reference to the top
level collection.
Previously one could get reference only to collection
inside other collection. With this change it becomes
possible to have two pointers to the same top level
collection from multiple places.
COLLECTION Adding comment.
COLLECTION: Some tracing
Diffstat (limited to 'common')
-rw-r--r-- | common/collection/collection.c | 49 | ||||
-rw-r--r-- | common/collection/collection.h | 6 | ||||
-rw-r--r-- | common/collection/collection_ut.c | 13 |
3 files changed, 47 insertions, 21 deletions
diff --git a/common/collection/collection.c b/common/collection/collection.c index 27dee836..c8a00779 100644 --- a/common/collection/collection.c +++ b/common/collection/collection.c @@ -1171,7 +1171,9 @@ static void col_delete_collection(struct collection_item *ci) return; } - TRACE_INFO_STRING("Real work to do",""); + TRACE_INFO_STRING("Real work to do", ""); + TRACE_INFO_STRING("Property", ci->property); + TRACE_INFO_NUMBER("Next item", ci->next); col_delete_collection(ci->next); @@ -2247,8 +2249,11 @@ void col_destroy_collection(struct collection_item *ci) return; } + TRACE_INFO_STRING("Name:", ci->property); + /* Collection can be referenced by other collection */ header = (struct collection_header *)(ci->data); + TRACE_INFO_NUMBER("Reference count:", header->reference_count); if (header->reference_count > 1) { TRACE_INFO_STRING("Dereferencing a referenced collection.", ""); header->reference_count--; @@ -2376,29 +2381,35 @@ int col_get_collection_reference(struct collection_item *ci, if ((ci == NULL) || (ci->type != COL_TYPE_COLLECTION) || - (acceptor == NULL) || - (collection_to_find == NULL)) { + (acceptor == NULL)) { TRACE_ERROR_NUMBER("Invalid parameter - returning error",EINVAL); return EINVAL; } - /* Find a sub collection */ - TRACE_INFO_STRING("We are given subcollection name - search it:", - collection_to_find); - error = col_find_item_and_do(ci, collection_to_find, - COL_TYPE_COLLECTIONREF, - COL_TRAVERSE_DEFAULT, - col_get_subcollection, - (void *)(&subcollection), - COLLECTION_ACTION_FIND); - if (error) { - TRACE_ERROR_NUMBER("Search failed returning error", error); - return error; - } + if (collection_to_find) { + /* Find a sub collection */ + TRACE_INFO_STRING("We are given subcollection name - search it:", + collection_to_find); + error = col_find_item_and_do(ci, collection_to_find, + COL_TYPE_COLLECTIONREF, + COL_TRAVERSE_DEFAULT, + col_get_subcollection, + (void *)(&subcollection), + COLLECTION_ACTION_FIND); + if (error) { + TRACE_ERROR_NUMBER("Search failed returning error", error); + return error; + } - if (subcollection == NULL) { - TRACE_ERROR_STRING("Search for subcollection returned NULL pointer", ""); - return ENOENT; + if (subcollection == NULL) { + TRACE_ERROR_STRING("Search for subcollection returned NULL pointer", ""); + return ENOENT; + } + } + else { + /* Create reference to the same collection */ + TRACE_INFO_STRING("Creating reference to the top level collection.", ""); + subcollection = ci; } header = (struct collection_header *)subcollection->data; diff --git a/common/collection/collection.h b/common/collection/collection.h index 2e2fe642..665d5f00 100644 --- a/common/collection/collection.h +++ b/common/collection/collection.h @@ -686,8 +686,10 @@ int col_is_item_in_collection(struct collection_item *ci, /* Collection to fin int *found); /* Boolean that turns to nonzero if the match is found */ -/* Get collection - get a pointer to a collection included into another collection */ -/* Delete extracted collection after use to decrease reference count. */ +/* Get collection - get a pointer to a collection included into another collection. + * If the collection_to_find is NULL function reterns a reference to the top level collection. + * Delete extracted collection after use to decrease reference count. + */ int col_get_collection_reference(struct collection_item *ci, /* High level collection */ struct collection_item **acceptor, /* The pointer that will accept extracted handle */ const char *collection_to_find); /* Name to of the collection */ diff --git a/common/collection/collection_ut.c b/common/collection/collection_ut.c index 1e91c232..86620550 100644 --- a/common/collection/collection_ut.c +++ b/common/collection/collection_ut.c @@ -33,6 +33,7 @@ int ref_collection_test(void) { struct collection_item *peer = NULL; struct collection_item *socket = NULL; + struct collection_item *socket2 = NULL; char binary_dump[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 }; int error = EOK; @@ -98,7 +99,19 @@ int ref_collection_test(void) col_destroy_collection(peer); col_debug_collection(socket, COL_TRAVERSE_DEFAULT); + + error = col_get_collection_reference(socket, &socket2, NULL); + if (error) { + col_destroy_collection(socket); + printf("Failed to extract collection. Error %d\n", error); + return error; + } + + col_debug_collection(socket2, COL_TRAVERSE_DEFAULT); col_destroy_collection(socket); + col_debug_collection(socket2, COL_TRAVERSE_DEFAULT); + col_destroy_collection(socket2); + TRACE_FLOW_NUMBER("ref_collection_test. Returning", error); printf("\n\nEND OF REF TEST!!!.\n\n\n"); |