From: Jeffrey Altman Date: Mon, 22 May 2006 17:18:27 +0000 (+0000) Subject: Move generic list functions to common/generic_lists.c X-Git-Tag: krb5-1.6-alpha1~274^2~16 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=395cb4fe2007693553b37dc53981218e72b3b389;p=krb5.git Move generic list functions to common/generic_lists.c so they can be used by both the client dll and the server. Fix type utilization in serv_ops.c git-svn-id: svn://anonsvn.mit.edu/krb5/branches/ccapi@18029 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/ccapi/server/ccs_lists.c b/src/lib/ccapi/server/ccs_lists.c index 06f8ced87..95ca398fb 100644 --- a/src/lib/ccapi/server/ccs_lists.c +++ b/src/lib/ccapi/server/ccs_lists.c @@ -54,51 +54,6 @@ #include "CredentialsCache.h" #include "datastore.h" -/** - * cci_generic_iterate_has_next() - * - * Purpose: Determine if an iterator has a next element - * - * Return: 1 if another element exists - * 0 if no additional elements exist - * - * Errors: None - * - */ -cc_int32 -cci_generic_iterate_has_next(cc_generic_iterate_t *iterate) -{ - return ((iterate == NULL || iterate->next == NULL) ? 0 : 1); -} - -/** - * cci_generic_iterate_next() - * - * Purpose: Retrieve the next element from an iterator and advance - * the iterator - * - * Return: non-NULL, the next element in the iterator - * NULL, the iterator list is empty or iterator is invalid - * - * Errors: ccErrBadParam - * - */ -cc_int32 -cci_generic_iterate_next(cc_generic_iterate_t *iterator, cc_generic_list_node_t** nodepp) -{ - cc_generic_list_node_t* ret; - - if (iterator == NULL || nodepp == NULL) - return ccErrBadParam; - - ret = iterator->next; - if (iterator->next != NULL) - iterator->next = iterator->next->next; - - *nodepp = ret; - return ccNoError; -} - /** * ccs_context_iterate_has_next() * @@ -219,214 +174,6 @@ ccs_credentials_iterate_next(cc_credentials_iterate_t *iterate, cc_credentials_l return cci_generic_iterate_next((cc_generic_iterate_t*)iterate, (cc_credentials_list_node_t**)nodepp); } -/** - * cci_generic_list_new() - * - * Purpose: Allocate new generic list - * - * Return: non-NULL, an empty list - * NULL, failure - * - * Errors: ccErrNoMem - * - */ -cc_int32 -cci_generic_list_new(cc_generic_list_head_t ** listpp) -{ - cc_generic_list_head_t* ret = (cc_generic_list_head_t *)malloc(sizeof(cc_generic_list_head_t)); - if (ret == NULL) - return ccErrNoMem; - - ret->type = generic; - ret->head = ret->tail = NULL; - *listpp = ret; - - return ccNoError; -} - -/** - * cci_generic_list_append() - * - * Purpose: Appends a new node containing a copy of 'len' bytes of 'data' - * - * Return: non-NULL, a pointer to the newly allocated node - * NULL, failure - * - * Errors: ccErrNoMem,ccErrBadParam - * - */ -cc_int32 -cci_generic_list_append(cc_generic_list_head_t *head, void *data, cc_uint32 len, cc_generic_list_node_t** nodepp) -{ - cc_generic_list_node_t* new_node; - - if ( data == NULL || len == 0 ) - return ccErrBadParam; - - new_node = (cc_generic_list_node_t *)malloc(sizeof(cc_generic_list_node_t)); - if (new_node == NULL) - return ccErrNoMem; - - new_node->data = malloc(len); - if ( new_node->data == NULL ) { - free(new_node); - return ccErrNoMem; - } - - memcpy(new_node->data,data,len); - new_node->len = len; - - if (head->head == NULL) { /*empty list*/ - head->head = new_node; - head->tail = new_node; - new_node->next = new_node->prev = NULL; - } else { - new_node->prev = head->tail; - head->tail->next = new_node; - head->tail = new_node; - new_node->next = NULL; - } - if (nodepp != NULL) - *nodepp = new_node; - return ccNoError; -} - -/** - * cci_generic_list_prepend() - * - * Purpose: Prepends a new node containing a copy of 'len' bytes of 'data' - * - * Return: non-NULL, a pointer to the newly allocated node - * NULL, failure - * - * Errors: ccErrNoMem, ccErrBadParam - * - */ -cc_int32 -cci_generic_list_prepend(cc_generic_list_head_t *head, void *data, cc_uint32 len, cc_generic_list_node_t** nodepp) -{ - cc_generic_list_node_t* new_node; - - if ( data == NULL || len == 0 ) - return ccErrBadParam; - - new_node = (cc_generic_list_node_t *)malloc(sizeof(cc_generic_list_node_t)); - if (new_node == NULL) - return ccErrNoMem; - - new_node->data = malloc(len); - if ( new_node->data == NULL ) { - free(new_node); - return ccErrNoMem; - } - - memcpy(new_node->data,data,len); - new_node->len = len; - - if (head->head == NULL) { /*empty list*/ - head->head = new_node; - head->tail = new_node; - new_node->prev = new_node->next = NULL; - } else { - new_node->next = head->head; - head->head->prev = new_node; - new_node->prev = NULL; - head->head = new_node; - } - - if (nodepp != NULL) - *nodepp = new_node; - - return ccNoError; -} - -/** - * cci_generic_list_remove_element() - * - * Purpose: Remove a node from the list - * - * Return: 0, success - * -1, failure - * - * Errors: ccErrBadParam - * - */ -cc_int32 -cci_generic_list_remove_element(cc_generic_list_head_t* head, cc_generic_list_node_t* rem) -{ - if (head->head == NULL || rem == NULL) - return ccErrBadParam; - - if (head->head == rem && head->tail == rem) { /*removing only element of list*/ - head->head = head->tail = NULL; - } else if (head->head == rem) { /*removing head*/ - head->head = head->head->next; - } else if (head->tail == rem) { /*removing tail*/ - head->tail = head->tail->prev; - head->tail->next = NULL; - } else { - rem->prev->next = rem->next; - rem->next->prev = rem->prev; - } - free(rem); - return ccNoError; -} - -/** - * cci_generic_free_element() - * - * Purpose: Free the memory associated with a node - * - * Return: 0, success - * -1, failure - * - * Errors: ccErrBadParam - * - */ -cc_int32 -cci_generic_free_element(cc_generic_list_node_t* node) -{ - if ( node == NULL ) - return ccErrBadParam; - - if ( node->data ) { - free(node->data); - node->data = NULL; - } - node->len = 0; - node->next = node->prev = NULL; - free(node); - return ccNoError; -} - - -/** - * cci_generic_list_destroy() - * - * Purpose: Deallocate a list and all of its contents - * - * Return: 0, success - * -1, failure - * - * Errors: ccErrBadParam - */ -cc_int32 -cci_generic_list_destroy(cc_generic_list_head_t* head) -{ - cc_generic_list_node_t *cur, *next; - cc_int32 ret = ccNoError; - - if ( head == NULL ) - return ccErrBadParam; - - for (cur = head->head; ret == ccNoError && cur != NULL; cur = next) { - next = cur->next; - ret = cci_generic_free_element(cur); - } - free(head); - return(ret); -} - /** * ccs_context_list_destroy() * @@ -475,42 +222,6 @@ ccs_credentials_list_destroy(cc_credentials_list_head_t* head) return cci_generic_list_destroy((cc_generic_list_head_t*)head); } -/** - * cci_generic_list_copy() - * - * Purpose: Copy a list - * - * Return: non-NULL, a new list - * NULL, failure - * - * Errors: ccErrBadParam, ccErrNoMem - * - */ -cc_int32 -cci_generic_list_copy(cc_generic_list_head_t* head, cc_generic_list_head_t** headpp) -{ - cc_generic_list_head_t* copy; - cc_generic_list_node_t *src_node, *dst_node; - cc_int32 code; - - if (head == NULL || headpp == NULL) - return ccErrBadParam; - - code = cci_generic_list_new(©); - if (code != ccNoError) - return code; - - for (src_node = head->head; src_node != NULL; src_node = src_node->next) { - code = cci_generic_list_append(copy, src_node->data, src_node->len, &dst_node); - if (code != ccNoError) { - cci_generic_list_destroy(copy); - return code; - } - } - *headpp = copy; - return ccNoError; -} - /** * ccs_context_list_copy() * @@ -562,57 +273,6 @@ ccs_credentials_list_copy(cc_credentials_list_head_t* head, cc_credentials_list_ } -/** - * cci_generic_list_iterator() - * - * Purpose: Allocate an iterator for the specified list - * - * Return: non-NULL, an iterator - * NULL, failure - * - * Errors: ccErrNoMem - * - */ -cc_int32 -cci_generic_list_iterator(cc_generic_list_head_t *head, cc_generic_iterate_t** headpp) -{ - cc_generic_iterate_t* iterator; - - if ( head == NULL || headpp == NULL ) - return ccErrBadParam; - - iterator = (cc_generic_iterate_t*)malloc(sizeof(cc_generic_iterate_t)); - if (iterator == NULL) - return ccErrNoMem; - - iterator->next = head->head; - *headpp = iterator; - return ccNoError; -} - -/** - * cci_generic_free_iterator() - * - * Purpose: Deallocate memory associated with an iterator - * - * Return: 0, success - * -1, failure - * - * Errors: ccErrBadParam - * - */ -cc_int32 -cci_generic_free_iterator(cc_generic_iterate_t* iterator) -{ - if ( iterator == NULL ) - return ccErrBadParam; - - iterator->next = NULL; - free(iterator); - return ccNoError; -} - - /** * ccs_context_list_new() * diff --git a/src/lib/ccapi/server/serv_ops.c b/src/lib/ccapi/server/serv_ops.c index 01a9742cd..9c544fc58 100644 --- a/src/lib/ccapi/server/serv_ops.c +++ b/src/lib/ccapi/server/serv_ops.c @@ -549,7 +549,7 @@ ccop_CTX_COMPARE(cc_server_context_t* ctx, { cc_server_context_t *ctx2; ccmsg_ctx_compare_resp_t* resp_header; - ccmsg_ctx_compare_t* header = (ccmsg_ctx_compare_t *)(ntohll(msg->header)); + ccmsg_ctx_compare_t* header = (ccmsg_ctx_compare_t *)msg->header; cc_uint32 header_len = ntohl(msg->header_len); cc_int32 code;