#include "CredentialsCache.h"\r
#include "datastore.h"\r
\r
-/**\r
- * cci_generic_iterate_has_next()\r
- *\r
- * Purpose: Determine if an iterator has a next element\r
- *\r
- * Return: 1 if another element exists\r
- * 0 if no additional elements exist\r
- *\r
- * Errors: None\r
- *\r
- */\r
-cc_int32 \r
-cci_generic_iterate_has_next(cc_generic_iterate_t *iterate) \r
-{\r
- return ((iterate == NULL || iterate->next == NULL) ? 0 : 1);\r
-}\r
-\r
-/**\r
- * cci_generic_iterate_next()\r
- *\r
- * Purpose: Retrieve the next element from an iterator and advance\r
- * the iterator\r
- *\r
- * Return: non-NULL, the next element in the iterator\r
- * NULL, the iterator list is empty or iterator is invalid\r
- *\r
- * Errors: ccErrBadParam\r
- *\r
- */\r
-cc_int32\r
-cci_generic_iterate_next(cc_generic_iterate_t *iterator, cc_generic_list_node_t** nodepp) \r
-{\r
- cc_generic_list_node_t* ret;\r
- \r
- if (iterator == NULL || nodepp == NULL)\r
- return ccErrBadParam;\r
-\r
- ret = iterator->next;\r
- if (iterator->next != NULL)\r
- iterator->next = iterator->next->next;\r
-\r
- *nodepp = ret;\r
- return ccNoError;\r
-}\r
-\r
/**\r
* ccs_context_iterate_has_next()\r
*\r
return cci_generic_iterate_next((cc_generic_iterate_t*)iterate, (cc_credentials_list_node_t**)nodepp);\r
}\r
\r
-/**\r
- * cci_generic_list_new()\r
- *\r
- * Purpose: Allocate new generic list\r
- *\r
- * Return: non-NULL, an empty list\r
- * NULL, failure\r
- *\r
- * Errors: ccErrNoMem\r
- *\r
- */\r
-cc_int32\r
-cci_generic_list_new(cc_generic_list_head_t ** listpp) \r
-{\r
- cc_generic_list_head_t* ret = (cc_generic_list_head_t *)malloc(sizeof(cc_generic_list_head_t));\r
- if (ret == NULL)\r
- return ccErrNoMem;\r
- \r
- ret->type = generic;\r
- ret->head = ret->tail = NULL;\r
- *listpp = ret;\r
-\r
- return ccNoError;\r
-}\r
-\r
-/**\r
- * cci_generic_list_append()\r
- *\r
- * Purpose: Appends a new node containing a copy of 'len' bytes of 'data' \r
- *\r
- * Return: non-NULL, a pointer to the newly allocated node\r
- * NULL, failure\r
- *\r
- * Errors: ccErrNoMem,ccErrBadParam\r
- *\r
- */\r
-cc_int32\r
-cci_generic_list_append(cc_generic_list_head_t *head, void *data, cc_uint32 len, cc_generic_list_node_t** nodepp) \r
-{\r
- cc_generic_list_node_t* new_node;\r
-\r
- if ( data == NULL || len == 0 )\r
- return ccErrBadParam;\r
-\r
- new_node = (cc_generic_list_node_t *)malloc(sizeof(cc_generic_list_node_t));\r
- if (new_node == NULL)\r
- return ccErrNoMem;\r
-\r
- new_node->data = malloc(len);\r
- if ( new_node->data == NULL ) {\r
- free(new_node);\r
- return ccErrNoMem; \r
- }\r
- \r
- memcpy(new_node->data,data,len);\r
- new_node->len = len;\r
-\r
- if (head->head == NULL) { /*empty list*/\r
- head->head = new_node;\r
- head->tail = new_node;\r
- new_node->next = new_node->prev = NULL;\r
- } else {\r
- new_node->prev = head->tail;\r
- head->tail->next = new_node;\r
- head->tail = new_node;\r
- new_node->next = NULL;\r
- }\r
- if (nodepp != NULL)\r
- *nodepp = new_node;\r
- return ccNoError;\r
-}\r
-\r
-/**\r
- * cci_generic_list_prepend()\r
- *\r
- * Purpose: Prepends a new node containing a copy of 'len' bytes of 'data'\r
- *\r
- * Return: non-NULL, a pointer to the newly allocated node\r
- * NULL, failure\r
- *\r
- * Errors: ccErrNoMem, ccErrBadParam\r
- *\r
- */\r
-cc_int32 \r
-cci_generic_list_prepend(cc_generic_list_head_t *head, void *data, cc_uint32 len, cc_generic_list_node_t** nodepp) \r
-{\r
- cc_generic_list_node_t* new_node;\r
-\r
- if ( data == NULL || len == 0 )\r
- return ccErrBadParam;\r
-\r
- new_node = (cc_generic_list_node_t *)malloc(sizeof(cc_generic_list_node_t));\r
- if (new_node == NULL)\r
- return ccErrNoMem;\r
-\r
- new_node->data = malloc(len);\r
- if ( new_node->data == NULL ) {\r
- free(new_node);\r
- return ccErrNoMem;\r
- }\r
- \r
- memcpy(new_node->data,data,len);\r
- new_node->len = len;\r
- \r
- if (head->head == NULL) { /*empty list*/\r
- head->head = new_node;\r
- head->tail = new_node;\r
- new_node->prev = new_node->next = NULL;\r
- } else {\r
- new_node->next = head->head;\r
- head->head->prev = new_node;\r
- new_node->prev = NULL;\r
- head->head = new_node;\r
- }\r
-\r
- if (nodepp != NULL)\r
- *nodepp = new_node;\r
-\r
- return ccNoError;\r
-}\r
-\r
-/**\r
- * cci_generic_list_remove_element()\r
- *\r
- * Purpose: Remove a node from the list\r
- *\r
- * Return: 0, success\r
- * -1, failure\r
- *\r
- * Errors: ccErrBadParam\r
- *\r
- */\r
-cc_int32 \r
-cci_generic_list_remove_element(cc_generic_list_head_t* head, cc_generic_list_node_t* rem) \r
-{\r
- if (head->head == NULL || rem == NULL)\r
- return ccErrBadParam;\r
-\r
- if (head->head == rem && head->tail == rem) { /*removing only element of list*/\r
- head->head = head->tail = NULL;\r
- } else if (head->head == rem) { /*removing head*/\r
- head->head = head->head->next;\r
- } else if (head->tail == rem) { /*removing tail*/\r
- head->tail = head->tail->prev;\r
- head->tail->next = NULL;\r
- } else {\r
- rem->prev->next = rem->next;\r
- rem->next->prev = rem->prev;\r
- }\r
- free(rem);\r
- return ccNoError;\r
-}\r
-\r
-/**\r
- * cci_generic_free_element()\r
- *\r
- * Purpose: Free the memory associated with a node\r
- *\r
- * Return: 0, success\r
- * -1, failure\r
- *\r
- * Errors: ccErrBadParam\r
- *\r
- */\r
-cc_int32\r
-cci_generic_free_element(cc_generic_list_node_t* node)\r
-{\r
- if ( node == NULL )\r
- return ccErrBadParam;\r
-\r
- if ( node->data ) {\r
- free(node->data);\r
- node->data = NULL;\r
- }\r
- node->len = 0;\r
- node->next = node->prev = NULL;\r
- free(node);\r
- return ccNoError;\r
-}\r
-\r
-\r
-/**\r
- * cci_generic_list_destroy()\r
- *\r
- * Purpose: Deallocate a list and all of its contents\r
- *\r
- * Return: 0, success\r
- * -1, failure\r
- *\r
- * Errors: ccErrBadParam\r
- */\r
-cc_int32\r
-cci_generic_list_destroy(cc_generic_list_head_t* head) \r
-{\r
- cc_generic_list_node_t *cur, *next;\r
- cc_int32 ret = ccNoError;\r
-\r
- if ( head == NULL )\r
- return ccErrBadParam;\r
- \r
- for (cur = head->head; ret == ccNoError && cur != NULL; cur = next) {\r
- next = cur->next;\r
- ret = cci_generic_free_element(cur);\r
- } \r
- free(head);\r
- return(ret);\r
-}\r
-\r
/**\r
* ccs_context_list_destroy()\r
*\r
return cci_generic_list_destroy((cc_generic_list_head_t*)head);\r
}\r
\r
-/**\r
- * cci_generic_list_copy()\r
- *\r
- * Purpose: Copy a list\r
- *\r
- * Return: non-NULL, a new list\r
- * NULL, failure\r
- *\r
- * Errors: ccErrBadParam, ccErrNoMem\r
- *\r
- */\r
-cc_int32\r
-cci_generic_list_copy(cc_generic_list_head_t* head, cc_generic_list_head_t** headpp) \r
-{\r
- cc_generic_list_head_t* copy;\r
- cc_generic_list_node_t *src_node, *dst_node;\r
- cc_int32 code;\r
-\r
- if (head == NULL || headpp == NULL)\r
- return ccErrBadParam;\r
-\r
- code = cci_generic_list_new(©);\r
- if (code != ccNoError)\r
- return code;\r
-\r
- for (src_node = head->head; src_node != NULL; src_node = src_node->next) {\r
- code = cci_generic_list_append(copy, src_node->data, src_node->len, &dst_node);\r
- if (code != ccNoError) {\r
- cci_generic_list_destroy(copy);\r
- return code;\r
- }\r
- }\r
- *headpp = copy;\r
- return ccNoError;\r
-}\r
-\r
/**\r
* ccs_context_list_copy()\r
*\r
}\r
\r
\r
-/**\r
- * cci_generic_list_iterator()\r
- *\r
- * Purpose: Allocate an iterator for the specified list\r
- *\r
- * Return: non-NULL, an iterator\r
- * NULL, failure\r
- *\r
- * Errors: ccErrNoMem\r
- *\r
- */\r
-cc_int32\r
-cci_generic_list_iterator(cc_generic_list_head_t *head, cc_generic_iterate_t** headpp) \r
-{\r
- cc_generic_iterate_t* iterator;\r
-\r
- if ( head == NULL || headpp == NULL )\r
- return ccErrBadParam;\r
-\r
- iterator = (cc_generic_iterate_t*)malloc(sizeof(cc_generic_iterate_t));\r
- if (iterator == NULL)\r
- return ccErrNoMem;\r
- \r
- iterator->next = head->head;\r
- *headpp = iterator;\r
- return ccNoError;\r
-}\r
-\r
-/**\r
- * cci_generic_free_iterator()\r
- *\r
- * Purpose: Deallocate memory associated with an iterator\r
- *\r
- * Return: 0, success\r
- * -1, failure\r
- *\r
- * Errors: ccErrBadParam\r
- *\r
- */\r
-cc_int32\r
-cci_generic_free_iterator(cc_generic_iterate_t* iterator)\r
-{\r
- if ( iterator == NULL )\r
- return ccErrBadParam;\r
-\r
- iterator->next = NULL;\r
- free(iterator);\r
- return ccNoError;\r
-}\r
-\r
-\r
/**\r
* ccs_context_list_new()\r
*\r