libcoap 4.3.5-develop-783b531
Loading...
Searching...
No Matches
coap_uri.h
Go to the documentation of this file.
1/*
2 * coap_uri.h -- helper functions for URI treatment
3 *
4 * Copyright (C) 2010-2026 Olaf Bergmann <bergmann@tzi.org>
5 *
6 * SPDX-License-Identifier: BSD-2-Clause
7 *
8 * This file is part of the CoAP library libcoap. Please see README for terms
9 * of use.
10 */
11
17#ifndef COAP_URI_H_
18#define COAP_URI_H_
19
20#include "coap_str.h"
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
41
43#define COAP_URI_SCHEME_SECURE_MASK 0x01
44
45#define COAP_URI_SCHEME_COAP_BIT (1 << COAP_URI_SCHEME_COAP)
46#define COAP_URI_SCHEME_COAPS_BIT (1 << COAP_URI_SCHEME_COAPS)
47#define COAP_URI_SCHEME_COAP_TCP_BIT (1 << COAP_URI_SCHEME_COAP_TCP)
48#define COAP_URI_SCHEME_COAPS_TCP_BIT (1 << COAP_URI_SCHEME_COAPS_TCP)
49#define COAP_URI_SCHEME_HTTP_BIT (1 << COAP_URI_SCHEME_HTTP)
50#define COAP_URI_SCHEME_HTTPS_BIT (1 << COAP_URI_SCHEME_HTTPS)
51#define COAP_URI_SCHEME_COAP_WS_BIT (1 << COAP_URI_SCHEME_COAP_WS)
52#define COAP_URI_SCHEME_COAPS_WS_BIT (1 << COAP_URI_SCHEME_COAPS_WS)
53
54#define COAP_URI_SCHEME_ALL_COAP_BITS (COAP_URI_SCHEME_COAP_BIT | \
55 COAP_URI_SCHEME_COAPS_BIT | \
56 COAP_URI_SCHEME_COAP_TCP_BIT | \
57 COAP_URI_SCHEME_COAPS_TCP_BIT | \
58 COAP_URI_SCHEME_COAP_WS_BIT | \
59 COAP_URI_SCHEME_COAPS_WS_BIT)
60
84
85typedef struct {
86 uint32_t upa_value;
87 const char *upa_path;
90
91static inline int
93 return uri && ((uri->scheme & COAP_URI_SCHEME_SECURE_MASK) != 0);
94}
95
106
115int coap_host_is_llc(const coap_str_const_t *host);
116
127coap_uri_t *coap_new_uri(const uint8_t *uri, unsigned int length);
128
139
145void coap_delete_uri(coap_uri_t *uri);
146
170int coap_split_uri(const uint8_t *str_var, size_t len, coap_uri_t *uri);
171
188int coap_split_proxy_uri(const uint8_t *str_var, size_t len, coap_uri_t *uri);
189
214 coap_optlist_t **optlist_chain,
215 int create_port_host_opt,
216 uint8_t *buf, size_t buflen);
217
236int coap_uri_into_optlist(const coap_uri_t *uri, const coap_address_t *dst,
237 coap_optlist_t **optlist_chain,
238 int create_port_host_opt);
262 coap_optlist_t **optlist_chain,
263 int create_port_host_opt,
264 coap_upa_abbrev_t *mapping, uint32_t count);
265
281int coap_split_path(const uint8_t *path,
282 size_t length,
283 unsigned char *buf,
284 size_t *buflen);
285
301int coap_path_into_optlist(const uint8_t *path, size_t length,
302 coap_option_num_t optnum,
303 coap_optlist_t **optlist_chain);
322int coap_path_into_optlist_abbrev(const uint8_t *path, size_t length,
323 coap_option_num_t optnum,
324 coap_optlist_t **optlist_chain,
325 coap_upa_abbrev_t *mapping, uint32_t count);
326
342int coap_split_query(const uint8_t *query,
343 size_t length,
344 unsigned char *buf,
345 size_t *buflen);
346
360int coap_query_into_optlist(const uint8_t *query, size_t length,
361 coap_option_num_t optnum,
362 coap_optlist_t **optlist_chain);
363
373
383
393void coap_upa_client_fallback(coap_upa_abbrev_t *mapping, uint32_t count);
394
403void coap_upa_server_mapping(coap_upa_abbrev_t *mapping, uint32_t count);
404
407#ifdef __cplusplus
408}
409#endif
410
411#endif /* COAP_URI_H_ */
uint16_t coap_option_num_t
Definition coap_option.h:37
Strings to be used in the CoAP library.
static int coap_uri_scheme_is_secure(const coap_uri_t *uri)
Definition coap_uri.h:92
coap_uri_scheme_t
The scheme specifiers.
Definition coap_uri.h:30
@ COAP_URI_SCHEME_COAPS_WS
Definition coap_uri.h:38
@ COAP_URI_SCHEME_COAPS_TCP
Definition coap_uri.h:34
@ COAP_URI_SCHEME_COAPS
Definition coap_uri.h:32
@ COAP_URI_SCHEME_COAP_TCP
Definition coap_uri.h:33
@ COAP_URI_SCHEME_COAP_WS
Definition coap_uri.h:37
@ COAP_URI_SCHEME_HTTPS
Definition coap_uri.h:36
@ COAP_URI_SCHEME_COAP
Definition coap_uri.h:31
@ COAP_URI_SCHEME_LAST
Definition coap_uri.h:39
@ COAP_URI_SCHEME_HTTP
Definition coap_uri.h:35
void coap_delete_uri(coap_uri_t *uri)
Removes the specified coap_uri_t object.
Definition coap_uri.c:1084
int coap_host_is_llc(const coap_str_const_t *host)
Determines from the host whether this is an LLC socket request.
Definition coap_uri.c:478
#define COAP_URI_SCHEME_SECURE_MASK
This mask can be used to check if a parsed URI scheme is secure.
Definition coap_uri.h:43
coap_uri_t * coap_clone_uri(const coap_uri_t *uri)
Clones the specified coap_uri_t object.
Definition coap_uri.c:1042
coap_uri_t * coap_new_uri(const uint8_t *uri, unsigned int length)
Creates a new coap_uri_t object from the specified URI.
Definition coap_uri.c:1021
int coap_host_is_unix_domain(const coap_str_const_t *host)
Determines from the host whether this is a Unix Domain socket request.
Definition coap_uri.c:466
coap_string_t * coap_get_uri_path(const coap_pdu_t *request)
Extract uri_path string from request PDU.
Definition coap_uri.c:1182
int coap_split_path(const uint8_t *path, size_t length, unsigned char *buf, size_t *buflen)
Splits the given URI path into segments.
Definition coap_uri.c:813
void coap_upa_client_fallback(coap_upa_abbrev_t *mapping, uint32_t count)
Define a Path to use if an Uri-Path-Abbrev option fails and the client is to retry the request using ...
Definition coap_uri.c:1305
void coap_upa_server_mapping(coap_upa_abbrev_t *mapping, uint32_t count)
Define a Path to use on receipt of an Uri-Path-Abbrev option value.
Definition coap_uri.c:1313
int coap_query_into_optlist(const uint8_t *query, size_t length, coap_option_num_t optnum, coap_optlist_t **optlist_chain)
Splits the given URI query into '&' separate segments, and then adds the Uri-Query / Location-Query o...
Definition coap_uri.c:985
int coap_split_uri(const uint8_t *str_var, size_t len, coap_uri_t *uri)
Parses a given string into URI components.
Definition coap_uri.c:346
int coap_path_into_optlist(const uint8_t *path, size_t length, coap_option_num_t optnum, coap_optlist_t **optlist_chain)
Splits the given URI path into '/' separate segments, and then adds the Uri-Path / Location-Path opti...
Definition coap_uri.c:865
int coap_split_proxy_uri(const uint8_t *str_var, size_t len, coap_uri_t *uri)
Parses a given string into URI components.
Definition coap_uri.c:351
int coap_uri_into_options(const coap_uri_t *uri, const coap_address_t *dst, coap_optlist_t **optlist_chain, int create_port_host_opt, uint8_t *buf, size_t buflen)
Takes a coap_uri_t and then adds CoAP options into the optlist_chain.
int coap_uri_into_optlist_abbrev(const coap_uri_t *uri, const coap_address_t *dst, coap_optlist_t **optlist_chain, int create_port_host_opt, coap_upa_abbrev_t *mapping, uint32_t count)
Takes a coap_uri_t and then adds CoAP options into the optlist_chain.
Definition coap_uri.c:380
int coap_uri_into_optlist(const coap_uri_t *uri, const coap_address_t *dst, coap_optlist_t **optlist_chain, int create_port_host_opt)
Takes a coap_uri_t and then adds CoAP options into the optlist_chain.
Definition coap_uri.c:374
int coap_split_query(const uint8_t *query, size_t length, unsigned char *buf, size_t *buflen)
Splits the given URI query into segments.
Definition coap_uri.c:961
int coap_path_into_optlist_abbrev(const uint8_t *path, size_t length, coap_option_num_t optnum, coap_optlist_t **optlist_chain, coap_upa_abbrev_t *mapping, uint32_t count)
Splits the given URI path into '/' separate segments, and then adds the Uri-Path / Location-Path opti...
Definition coap_uri.c:871
coap_string_t * coap_get_query(const coap_pdu_t *request)
Extract query string from request PDU according to escape rules in 6.5.8.
Definition coap_uri.c:1103
Multi-purpose address abstraction.
Representation of chained list of CoAP options to install.
structure for CoAP PDUs
CoAP string data definition with const data.
Definition coap_str.h:47
CoAP string data definition.
Definition coap_str.h:39
uint32_t upa_value
The Uri-Path-Abbrev option value.
Definition coap_uri.h:86
const char * upa_path
The Uri-Path-Abbrev option path representation (withouot the leading '/')
Definition coap_uri.h:87
Representation of parsed URI.
Definition coap_uri.h:70
enum coap_uri_scheme_t scheme
The parsed scheme specifier.
Definition coap_uri.h:82
coap_str_const_t path
The complete path if present or {0, NULL}.
Definition coap_uri.h:73
uint16_t port
The port in host byte order.
Definition coap_uri.h:72
coap_str_const_t query
The complete query if present or {0, NULL}.
Definition coap_uri.h:77
coap_str_const_t host
The host part of the URI.
Definition coap_uri.h:71