Loading...
Searching...
No Matches
coap_uri.h
Go to the documentation of this file.
/*
* coap_uri.h -- helper functions for URI treatment
*
* Copyright (C) 2010-2023 Olaf Bergmann <bergmann@tzi.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*
* This file is part of the CoAP library libcoap. Please see README for terms
* of use.
*/
#ifndef COAP_URI_H_
#define COAP_URI_H_
#include <stdint.h>
#include "coap_str.h"
typedef enum coap_uri_scheme_t {
COAP_URI_SCHEME_COAP = 0,
COAP_URI_SCHEME_COAPS, /* 1 */
COAP_URI_SCHEME_COAP_TCP, /* 2 */
COAP_URI_SCHEME_COAPS_TCP, /* 3 */
COAP_URI_SCHEME_HTTP, /* 4 Proxy-Uri only */
COAP_URI_SCHEME_HTTPS, /* 5 Proxy-Uri only */
COAP_URI_SCHEME_COAP_WS, /* 6 */
COAP_URI_SCHEME_COAPS_WS, /* 7 */
COAP_URI_SCHEME_LAST /* 8 Size of scheme */
} coap_uri_scheme_t;
#define COAP_URI_SCHEME_SECURE_MASK 0x01
#define COAP_URI_SCHEME_COAP_BIT (1 << COAP_URI_SCHEME_COAP)
#define COAP_URI_SCHEME_COAPS_BIT (1 << COAP_URI_SCHEME_COAPS)
#define COAP_URI_SCHEME_COAP_TCP_BIT (1 << COAP_URI_SCHEME_COAP_TCP)
#define COAP_URI_SCHEME_COAPS_TCP_BIT (1 << COAP_URI_SCHEME_COAPS_TCP)
#define COAP_URI_SCHEME_HTTP_BIT (1 << COAP_URI_SCHEME_HTTP)
#define COAP_URI_SCHEME_HTTPS_BIT (1 << COAP_URI_SCHEME_HTTPS)
#define COAP_URI_SCHEME_COAP_WS_BIT (1 << COAP_URI_SCHEME_COAP_WS)
#define COAP_URI_SCHEME_COAPS_WS_BIT (1 << COAP_URI_SCHEME_COAPS_WS)
#define COAP_URI_SCHEME_ALL_COAP_BITS (COAP_URI_SCHEME_COAP_BIT | \
COAP_URI_SCHEME_COAPS_BIT | \
COAP_URI_SCHEME_COAP_TCP_BIT | \
COAP_URI_SCHEME_COAPS_TCP_BIT | \
COAP_URI_SCHEME_COAP_WS_BIT | \
COAP_URI_SCHEME_COAPS_WS_BIT)
typedef struct {
coap_str_const_t host;
uint16_t port;
coap_str_const_t path;
coap_str_const_t query;
enum coap_uri_scheme_t scheme;
} coap_uri_t;
static inline int
coap_uri_scheme_is_secure(const coap_uri_t *uri) {
return uri && ((uri->scheme & COAP_URI_SCHEME_SECURE_MASK) != 0);
}
int coap_host_is_unix_domain(const coap_str_const_t *host);
coap_uri_t *coap_new_uri(const uint8_t *uri, unsigned int length);
coap_uri_t *coap_clone_uri(const coap_uri_t *uri);
void coap_delete_uri(coap_uri_t *uri);
int coap_split_uri(const uint8_t *str_var, size_t len, coap_uri_t *uri);
int coap_split_proxy_uri(const uint8_t *str_var, size_t len, coap_uri_t *uri);
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);
int coap_split_path(const uint8_t *s,
size_t length,
unsigned char *buf,
size_t *buflen);
int coap_split_query(const uint8_t *s,
size_t length,
unsigned char *buf,
size_t *buflen);
coap_string_t *coap_get_query(const coap_pdu_t *request);
coap_string_t *coap_get_uri_path(const coap_pdu_t *request);
#endif /* COAP_URI_H_ */
coap_str.h
Strings to be used in the CoAP library.
coap_uri_scheme_is_secure
static int coap_uri_scheme_is_secure(const coap_uri_t *uri)
Definition coap_uri.h:79
coap_uri_scheme_t
coap_uri_scheme_t
The scheme specifiers.
Definition coap_uri.h:28
COAP_URI_SCHEME_COAPS_WS
@ COAP_URI_SCHEME_COAPS_WS
Definition coap_uri.h:36
COAP_URI_SCHEME_COAPS_TCP
@ COAP_URI_SCHEME_COAPS_TCP
Definition coap_uri.h:32
COAP_URI_SCHEME_COAPS
@ COAP_URI_SCHEME_COAPS
Definition coap_uri.h:30
COAP_URI_SCHEME_COAP_TCP
@ COAP_URI_SCHEME_COAP_TCP
Definition coap_uri.h:31
COAP_URI_SCHEME_COAP_WS
@ COAP_URI_SCHEME_COAP_WS
Definition coap_uri.h:35
COAP_URI_SCHEME_HTTPS
@ COAP_URI_SCHEME_HTTPS
Definition coap_uri.h:34
COAP_URI_SCHEME_COAP
@ COAP_URI_SCHEME_COAP
Definition coap_uri.h:29
COAP_URI_SCHEME_LAST
@ COAP_URI_SCHEME_LAST
Definition coap_uri.h:37
COAP_URI_SCHEME_HTTP
@ COAP_URI_SCHEME_HTTP
Definition coap_uri.h:33
coap_delete_uri
void coap_delete_uri(coap_uri_t *uri)
Removes the specified coap_uri_t object.
Definition coap_uri.c:699
COAP_URI_SCHEME_SECURE_MASK
#define COAP_URI_SCHEME_SECURE_MASK
This mask can be used to check if a parsed URI scheme is secure.
Definition coap_uri.h:41
coap_clone_uri
coap_uri_t * coap_clone_uri(const coap_uri_t *uri)
Clones the specified coap_uri_t object.
Definition coap_uri.c:657
coap_new_uri
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:638
coap_host_is_unix_domain
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:386
coap_get_uri_path
coap_string_t * coap_get_uri_path(const coap_pdu_t *request)
Extract uri_path string from request PDU.
Definition coap_uri.c:769
coap_split_path
int coap_split_path(const uint8_t *s, size_t length, unsigned char *buf, size_t *buflen)
Splits the given URI path into segments.
Definition coap_uri.c:600
coap_split_query
int coap_split_query(const uint8_t *s, size_t length, unsigned char *buf, size_t *buflen)
Splits the given URI query into segments.
Definition coap_uri.c:612
coap_split_uri
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:269
coap_split_proxy_uri
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:274
coap_uri_into_options
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.
Definition coap_uri.c:279
coap_get_query
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:718
coap_address_t
Multi-purpose address abstraction.
Definition coap_address.h:109
coap_optlist_t
Representation of chained list of CoAP options to install.
Definition coap_option.h:325
coap_pdu_t
structure for CoAP PDUs
Definition coap_pdu_internal.h:119
coap_str_const_t
CoAP string data definition with const data.
Definition coap_str.h:46
coap_string_t
CoAP string data definition.
Definition coap_str.h:38
coap_uri_t
Representation of parsed URI.
Definition coap_uri.h:65
coap_uri_t::scheme
enum coap_uri_scheme_t scheme
The parsed scheme specifier.
Definition coap_uri.h:75
coap_uri_t::path
coap_str_const_t path
The complete path if present or {0, NULL}.
Definition coap_uri.h:68
coap_uri_t::port
uint16_t port
The port in host byte order.
Definition coap_uri.h:67
coap_uri_t::query
coap_str_const_t query
The complete query if present or {0, NULL}.
Definition coap_uri.h:71
coap_uri_t::host
coap_str_const_t host
The host part of the URI.
Definition coap_uri.h:66