libcoap 4.3.1
uri.h
Go to the documentation of this file.
1/*
2 * uri.h -- helper functions for URI treatment
3 *
4 * Copyright (C) 2010-2020 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 <stdint.h>
21
22#include "coap_str.h"
23
28typedef enum coap_uri_scheme_t {
33 COAP_URI_SCHEME_HTTP, /* 4 Proxy-Uri only */
34 COAP_URI_SCHEME_HTTPS /* 5 Proxy-Uri only */
36
38#define COAP_URI_SCHEME_SECURE_MASK 0x01
39
46typedef struct {
48 uint16_t port;
58
59static inline int
61 return uri && ((uri->scheme & COAP_URI_SCHEME_SECURE_MASK) != 0);
62}
63
74coap_uri_t *coap_new_uri(const uint8_t *uri, unsigned int length);
75
86
93
117int coap_split_uri(const uint8_t *str_var, size_t len, coap_uri_t *uri);
118
135int coap_split_proxy_uri(const uint8_t *str_var, size_t len, coap_uri_t *uri);
136
154int coap_uri_into_options(coap_uri_t *uri, coap_optlist_t **optlist_chain,
155 int create_port_opt, uint8_t *buf, size_t buflen);
156
170int coap_split_path(const uint8_t *s,
171 size_t length,
172 unsigned char *buf,
173 size_t *buflen);
174
190int coap_split_query(const uint8_t *s,
191 size_t length,
192 unsigned char *buf,
193 size_t *buflen);
194
204
214
217#endif /* COAP_URI_H_ */
Strings to be used in the CoAP library.
coap_string_t * coap_get_uri_path(const coap_pdu_t *request)
Extract uri_path string from request PDU.
Definition: uri.c:673
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: uri.c:506
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: uri.c:518
int coap_uri_into_options(coap_uri_t *uri, coap_optlist_t **optlist_chain, int create_port_opt, uint8_t *buf, size_t buflen)
Takes a coap_uri_t and then adds CoAP options into the optlist_chain.
Definition: uri.c:251
int coap_split_uri(const uint8_t *str_var, size_t len, coap_uri_t *uri)
Parses a given string into URI components.
Definition: uri.c:241
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: uri.c:246
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: uri.c:623
Representation of chained list of CoAP options to install.
Definition: coap_option.h:326
structure for CoAP PDUs
CoAP string data definition with const data.
Definition: coap_str.h:46
CoAP string data definition.
Definition: coap_str.h:38
Representation of parsed URI.
Definition: uri.h:46
enum coap_uri_scheme_t scheme
The parsed scheme specifier.
Definition: uri.h:56
coap_str_const_t path
The complete path if present or {0, NULL}.
Definition: uri.h:49
uint16_t port
The port in host byte order.
Definition: uri.h:48
coap_str_const_t query
The complete query if present or {0, NULL}.
Definition: uri.h:52
coap_str_const_t host
The host part of the URI.
Definition: uri.h:47
static int coap_uri_scheme_is_secure(const coap_uri_t *uri)
Definition: uri.h:60
coap_uri_scheme_t
The scheme specifiers.
Definition: uri.h:28
@ COAP_URI_SCHEME_COAPS_TCP
Definition: uri.h:32
@ COAP_URI_SCHEME_COAPS
Definition: uri.h:30
@ COAP_URI_SCHEME_COAP_TCP
Definition: uri.h:31
@ COAP_URI_SCHEME_HTTPS
Definition: uri.h:34
@ COAP_URI_SCHEME_COAP
Definition: uri.h:29
@ COAP_URI_SCHEME_HTTP
Definition: uri.h:33
void coap_delete_uri(coap_uri_t *uri)
Removes the specified coap_uri_t object.
Definition: uri.c:605
#define COAP_URI_SCHEME_SECURE_MASK
This mask can be used to check if a parsed URI scheme is secure.
Definition: uri.h:38
coap_uri_t * coap_clone_uri(const coap_uri_t *uri)
Clones the specified coap_uri_t object.
Definition: uri.c:563
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: uri.c:544