summaryrefslogtreecommitdiffstats
path: root/common/collection/collection_ut.c
diff options
context:
space:
mode:
authorDmitri Pal <dpal@redhat.com>2009-09-10 10:42:43 -0400
committerSimo Sorce <ssorce@redhat.com>2009-09-10 17:17:07 -0400
commit7f1ff81b891bc463822d09093329554691d52270 (patch)
treeec3e188f3b17ff006dcc3e075b90fe4909f3168e /common/collection/collection_ut.c
parent5acd83d38319f3da83b1831f486a55d83b64867c (diff)
downloadsssd-7f1ff81b891bc463822d09093329554691d52270.tar.gz
sssd-7f1ff81b891bc463822d09093329554691d52270.tar.xz
sssd-7f1ff81b891bc463822d09093329554691d52270.zip
COLLECTION Improvements to copy functions
This patch adds better options for copying collections in flat mode. It allows caller of the interface to control prefixing of the fields when one collection is appended to another. It also avoids creating prefixes when the collection is simply copied in flat mode. Also for ELAPI I realized that the most efficient way to deal with the "resolved" event (event where all templeted values are actually replaced with the real values) is to add a callback capability to a copy collection function so that the callback can be used to modify the data (resolve it) while the copy operation is in progress. This approach eliminates the need for separate set of lookups after the event is already copied.
Diffstat (limited to 'common/collection/collection_ut.c')
-rw-r--r--common/collection/collection_ut.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/common/collection/collection_ut.c b/common/collection/collection_ut.c
index 3666179c9..f1ec905ae 100644
--- a/common/collection/collection_ut.c
+++ b/common/collection/collection_ut.c
@@ -222,16 +222,30 @@ int add_collection_test(void)
return error;
}
+int copy_cb(struct collection_item *item,
+ void *ext_data,
+ int *skip)
+{
+ printf("INSIDE Copy Callback\n");
+ col_debug_item(item);
+ printf("Passed in data: %s\n", (char *) ext_data);
+ if (strcmp(col_get_item_property(item, NULL), "id") == 0) *skip = 1;
+ return EOK;
+}
+
+
int mixed_collection_test(void)
{
struct collection_item *peer;
struct collection_item *socket1;
struct collection_item *socket2;
+ struct collection_item *socket3;
struct collection_item *event;
struct collection_item *host;
char binary_dump[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
int found = 0;
unsigned int class = 0;
+ char foo[] = "foo";
int error = EOK;
@@ -295,6 +309,20 @@ int mixed_collection_test(void)
col_debug_collection(socket2, COL_TRAVERSE_DEFAULT);
col_debug_collection(peer, COL_TRAVERSE_DEFAULT);
+ error = col_copy_collection_with_cb(&socket3, socket1, "socket3",
+ COL_COPY_FLATDOT, copy_cb, (void *)foo);
+ if (error) {
+ col_destroy_collection(peer);
+ col_destroy_collection(host);
+ col_destroy_collection(socket1);
+ col_destroy_collection(socket2);
+ printf("Failed to copy collection. Error %d\n", error);
+ return error;
+ }
+
+ col_debug_collection(socket3, COL_TRAVERSE_DEFAULT);
+ col_destroy_collection(socket3);
+
printf("Adding PEER collection to SOCKET2 collection as a reference named PEER2\n");
/* Embed peer host into the socket2 as reference */