lc.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 HAW Hamburg
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
49 #ifndef NET_CORD_LC_H
50 #define NET_CORD_LC_H
51 
52 #include "net/sock/udp.h"
53 #include "net/nanocoap.h"
54 #include "clif.h"
55 
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
59 
63 enum {
64  CORD_LC_OK = 0,
66  CORD_LC_ERR = -2,
69 };
70 
74 enum {
77 };
78 
82 typedef struct {
84  char *res_lookif;
85  char *ep_lookif;
86  unsigned res_last_page;
87  unsigned ep_last_page;
88 } cord_lc_rd_t;
89 
96  size_t max_attrs;
97 };
98 
99 typedef struct cord_lc_result cord_lc_res_t;
100 typedef struct cord_lc_result cord_lc_ep_t;
105 typedef struct cord_lc_filter {
107  size_t len;
110 
126 int cord_lc_rd_init(cord_lc_rd_t *rd, void *buf, size_t maxlen,
127  const sock_udp_ep_t *remote);
128 
154 ssize_t cord_lc_raw(const cord_lc_rd_t *rd, unsigned content_format,
155  unsigned lookup_type, cord_lc_filter_t *filters,
156  void *result, size_t maxlen);
157 
181 ssize_t _lookup_result(cord_lc_rd_t *rd, cord_lc_res_t *result,
182  cord_lc_filter_t *filters, void *buf, size_t maxlen,
183  unsigned type);
184 
206 static inline ssize_t cord_lc_res(cord_lc_rd_t *rd, cord_lc_res_t *resource,
207  cord_lc_filter_t *filters, void *buf,
208  size_t maxlen)
209 {
210  return _lookup_result(rd, resource, filters, buf, maxlen, CORD_LC_RES);
211 }
212 
234 static inline ssize_t cord_lc_ep(cord_lc_rd_t *rd, cord_lc_ep_t *endpoint,
235  cord_lc_filter_t *filters, void *buf,
236  size_t maxlen)
237 {
238  return _lookup_result(rd, endpoint, filters, buf, maxlen, CORD_LC_EP);
239 }
240 
241 #ifdef __cplusplus
242 }
243 #endif
244 
245 #endif /* NET_CORD_LC_H */
246 
cord_lc_rd_t::res_last_page
unsigned res_last_page
Page of last resource lookup.
Definition: lc.h:86
cord_lc_rd_t::remote
const sock_udp_ep_t * remote
Remote endpoint of RD server.
Definition: lc.h:83
CORD_LC_ERR
@ CORD_LC_ERR
internal error or invalid reply
Definition: lc.h:66
CORD_LC_OVERFLOW
@ CORD_LC_OVERFLOW
internal buffers can not handle input
Definition: lc.h:67
nanocoap.h
nanocoap API
udp.h
UDP sock definitions.
cord_lc_filter::next
struct cord_lc_filter * next
Next set of filters.
Definition: lc.h:108
cord_lc_ep
static ssize_t cord_lc_ep(cord_lc_rd_t *rd, cord_lc_ep_t *endpoint, cord_lc_filter_t *filters, void *buf, size_t maxlen)
Get one endpoint from RD server.
Definition: lc.h:234
clif.h
CoRE Link Format encoding and decoding library public definitions.
cord_lc_filter::len
size_t len
No.
Definition: lc.h:107
cord_lc_result::link
clif_t link
Resource link.
Definition: lc.h:94
CORD_LC_RES
@ CORD_LC_RES
Resource lookup type.
Definition: lc.h:75
clif_attr_t
Link format attribute descriptor.
Definition: clif.h:137
CORD_LC_TIMEOUT
@ CORD_LC_TIMEOUT
no response from the network
Definition: lc.h:65
cord_lc_rd_init
int cord_lc_rd_init(cord_lc_rd_t *rd, void *buf, size_t maxlen, const sock_udp_ep_t *remote)
Discover the lookup interfaces of a RD server.
cord_lc_filter
Filters to use for a lookup.
Definition: lc.h:105
_lookup_result
ssize_t _lookup_result(cord_lc_rd_t *rd, cord_lc_res_t *result, cord_lc_filter_t *filters, void *buf, size_t maxlen, unsigned type)
Get one resource from RD server.
cord_lc_result::attrs
clif_attr_t * attrs
Array of Link Format parameters.
Definition: lc.h:95
CORD_LC_NORSC
@ CORD_LC_NORSC
lookup interface not found
Definition: lc.h:68
cord_lc_result::max_attrs
size_t max_attrs
Max parameters at params.
Definition: lc.h:96
cord_lc_rd_t
Information about RD server and its lookup interface resources.
Definition: lc.h:82
_sock_tl_ep
Common IP-based transport layer end point.
Definition: sock.h:213
cord_lc_rd_t::ep_last_page
unsigned ep_last_page
Page of last endpoint lookup.
Definition: lc.h:87
cord_lc_res
static ssize_t cord_lc_res(cord_lc_rd_t *rd, cord_lc_res_t *resource, cord_lc_filter_t *filters, void *buf, size_t maxlen)
Get one resource from RD server.
Definition: lc.h:206
clif_t
Link format descriptor.
Definition: clif.h:147
cord_lc_rd_t::res_lookif
char * res_lookif
Resource lookup interface.
Definition: lc.h:84
CORD_LC_OK
@ CORD_LC_OK
everything went as expected
Definition: lc.h:64
cord_lc_rd_t::ep_lookif
char * ep_lookif
Endpoint lookup interface.
Definition: lc.h:85
cord_lc_result
Result of lookup.
Definition: lc.h:93
cord_lc_filter_t
struct cord_lc_filter cord_lc_filter_t
Filters to use for a lookup.
CORD_LC_EP
@ CORD_LC_EP
Endpoint lookup type.
Definition: lc.h:76
cord_lc_raw
ssize_t cord_lc_raw(const cord_lc_rd_t *rd, unsigned content_format, unsigned lookup_type, cord_lc_filter_t *filters, void *result, size_t maxlen)
Raw lookup for registered resources/endpoints at a RD server.
cord_lc_filter::array
clif_attr_t * array
Array of filter(s)
Definition: lc.h:106