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"
18 int coap_insert(coap_list_t **queue, coap_list_t *node, int (*order)(void *, void *node))
24 /* 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)
40 /* search for right place to insert */
45 } while (q && order(node->data, q->data) >= 0);
53 int coap_delete(coap_list_t *node)
58 if (node->delete_func)
59 node->delete_func(node->data);
60 coap_free( node->data);
66 void coap_delete_list(coap_list_t *queue)
71 coap_delete_list(queue->next);
76 coap_new_listnode(void *data, void (*delete_func)(void *))
78 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;