libcoap  4.0.3
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
option.h
Go to the documentation of this file.
1 /*
2  * option.h -- helpers for handling options in CoAP PDUs
3  *
4  * Copyright (C) 2010-2013 Olaf Bergmann <bergmann@tzi.org>
5  *
6  * This file is part of the CoAP library libcoap. Please see
7  * README for terms of use.
8  */
9 
15 #ifndef _OPTION_H_
16 #define _OPTION_H_
17 
18 #include "bits.h"
19 #include "pdu.h"
20 
26 typedef unsigned char coap_opt_t;
27 #define PCHAR(p) ((coap_opt_t *)(p))
28 
30 typedef struct {
31  unsigned short delta;
32  size_t length;
33  unsigned char *value;
35 
49 size_t coap_opt_parse(const coap_opt_t *opt, size_t length,
50  coap_option_t *result);
51 
62 size_t coap_opt_size(const coap_opt_t *opt);
63 
65 #define COAP_OPT_SIZE(opt) coap_opt_size(opt)
66 
74 
80 #define options_next(opt) \
81  ((coap_opt_t *)((unsigned char *)(opt) + COAP_OPT_SIZE(opt)))
82 
93 typedef unsigned char coap_opt_filter_t[(COAP_MAX_OPT >> 3) + 1];
94 
96 #define COAP_OPT_ALL NULL
97 
103 static inline void
105  memset(f, 0, sizeof(coap_opt_filter_t));
106 }
107 
118 inline static int
119 coap_option_setb(coap_opt_filter_t filter, unsigned short type) {
120  return bits_setb((uint8_t *)filter, sizeof(coap_opt_filter_t), type);
121 }
122 
133 inline static int
134 coap_option_clrb(coap_opt_filter_t filter, unsigned short type) {
135  return bits_clrb((uint8_t *)filter, sizeof(coap_opt_filter_t), type);
136 }
137 
148 inline static int
149 coap_option_getb(const coap_opt_filter_t filter, unsigned short type) {
150  return bits_getb((uint8_t *)filter, sizeof(coap_opt_filter_t), type);
151 }
152 
169 typedef struct {
170  size_t length;
171  unsigned short type;
172  unsigned int bad:1;
173  unsigned int filtered:1;
177 
196  coap_opt_iterator_t *oi, const coap_opt_filter_t filter);
197 
218 
234  unsigned char type,
235  coap_opt_iterator_t *oi);
236 
251 size_t coap_opt_setheader(coap_opt_t *opt, size_t maxlen,
252  unsigned short delta, size_t length);
253 
268 size_t coap_opt_encode(coap_opt_t *opt, size_t n, unsigned short delta,
269  const unsigned char *val, size_t length);
270 
280 unsigned short coap_opt_delta(const coap_opt_t *opt);
281 
283 #define COAP_OPT_DELTA(opt) coap_opt_delta(opt)
284 
286 #define COAP_OPT_SETDELTA(opt,val) \
287  coap_opt_encode((opt), COAP_MAX_PDU_SIZE, (val), NULL, 0)
288 
302 unsigned short coap_opt_length(const coap_opt_t *opt);
303 
305 #define COAP_OPT_LENGTH(opt) coap_opt_length(opt)
306 
315 unsigned char *coap_opt_value(coap_opt_t *opt);
316 
318 #define COAP_OPT_VALUE(opt) coap_opt_value((coap_opt_t *)opt)
319 
322 #endif /* _OPTION_H_ */