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"
23 coap_insert(coap_list_t **queue, coap_list_t *node,
24 int (*order)(void *, void *node) ) {
26 if ( !queue || !node )
29 /* set queue head if empty */
35 /* replace queue head if new node has to be added before the existing queue head */
37 if ( order( node->data, q->data ) < 0) {
43 /* search for right place to insert */
47 } while ( q && order( node->data, q->data ) >= 0);
56 coap_delete(coap_list_t *node) {
60 if ( node->delete_func )
61 node->delete_func( node->data );
62 coap_free( node->data );
69 coap_delete_list(coap_list_t *queue) {
73 coap_delete_list( queue->next );
78 coap_new_listnode(void *data, void (*delete_func)(void *) ) {
79 coap_list_t *node = (coap_list_t*)coap_malloc( sizeof(coap_list_t) );
82 coap_log(LOG_CRIT, "coap_new_listnode: malloc\n");
87 memset(node, 0, sizeof(coap_list_t));
89 node->delete_func = delete_func;