xref: /third_party/libcoap/examples/coap_list.c (revision c87c5fba)
1/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 * -*- */
2
3/* coap_list.c -- CoAP list structures
4 *
5 * Copyright (C) 2010,2011,2015 Olaf Bergmann <bergmann@tzi.org>
6 *
7 * SPDX-License-Identifier: BSD-2-Clause
8 *
9 * This file is part of the CoAP library libcoap. Please see README for terms of
10 * use.
11 */
12
13/*
14 * examples/coap_list.[ch] are DEPRECATED.  You should be using
15 * struct coap_optlist_t instead with the following functions which are a part
16 * of libcoap.
17 *
18 * coap_new_optlist()
19 * coap_insert_optlist()
20 * coap_delete_optlist()
21 * coap_add_optlist_pdu()
22 *
23 * See 'man coap_pdu_setup' for further information.
24 *
25 * examples/coap_list.[ch] files will be removed in a future release
26 * They are left here to support building backward compatability of old versions
27 * of coap-client
28 */
29
30#include <stdio.h>
31#include <string.h>
32
33#include <coap3/coap.h>
34
35int
36coap_insert(coap_list_t **head, coap_list_t *node) {
37  if (!node) {
38    coap_log_warn("cannot create option Proxy-Uri\n");
39  } else {
40    /* must append at the list end to avoid re-ordering of
41     * options during sort */
42    LL_APPEND((*head), node);
43  }
44
45  return node != NULL;
46}
47
48int
49coap_delete(coap_list_t *node) {
50  if (node) {
51    coap_free(node);
52  }
53  return 1;
54}
55
56void
57coap_delete_list(coap_list_t *queue) {
58  coap_list_t *elt, *tmp;
59
60  if (!queue)
61    return;
62
63  LL_FOREACH_SAFE(queue, elt, tmp) {
64    coap_delete(elt);
65  }
66}
67