1 /* coap_list.c -- CoAP list structures
3 * Copyright (C) 2010,2011 Olaf Bergmann <bergmann@tzi.org>
5 * This file is part of the CoAP library libcoap. Please see
6 * README for terms of use.
16 #include "coap_list.h"
19 coap_insert(coap_list_t **queue, coap_list_t *node,
20 int (*order)(void *, void *node) ) {
22 if ( !queue || !node )
25 /* set queue head if empty */
31 /* replace queue head if new node has to be added before the existing queue head */
33 if ( order( node->data, q->data ) < 0) {
39 /* search for right place to insert */
43 } while ( q && order( node->data, q->data ) >= 0);
52 coap_delete(coap_list_t *node) {
56 if ( node->delete_func )
57 node->delete_func( node->data );
58 coap_free( node->data );
65 coap_delete_list(coap_list_t *queue) {
69 coap_delete_list( queue->next );
74 coap_new_listnode(void *data, void (*delete_func)(void *) ) {
75 coap_list_t *node = (coap_list_t*)coap_malloc( sizeof(coap_list_t) );
78 coap_log(LOG_CRIT, "coap_new_listnode: malloc\n");
83 memset(node, 0, sizeof(coap_list_t));
85 node->delete_func = delete_func;