uri.h
Go to the documentation of this file.
/*
* uri.h -- helper functions for URI treatment
*
* Copyright (C) 2010-2020 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 "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_t;
#define COAP_URI_SCHEME_SECURE_MASK 0x01
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);
}
coap_uri_t *coap_new_uri(const uint8_t *uri, unsigned int length);
coap_uri_t *coap_clone_uri(const 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_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_get_uri_path
coap_string_t * coap_get_uri_path(const coap_pdu_t *request)
Extract uri_path string from request PDU.
Definition: uri.c:606
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: uri.c:556
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: uri.c:444
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: uri.c:456
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: uri.c:236
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: uri.c:241
str.h
coap_pdu_t
structure for CoAP PDUs token, if any, follows the fixed size header, then options until payload mark...
Definition: coap_pdu_internal.h:94
coap_str_const_t
CoAP string data definition with const data.
Definition: str.h:40
coap_string_t
CoAP string data definition.
Definition: str.h:32
coap_uri_t
Representation of parsed URI.
Definition: uri.h:40
coap_uri_t::scheme
enum coap_uri_scheme_t scheme
The parsed scheme specifier.
Definition: uri.h:48
coap_uri_t::path
coap_str_const_t path
Beginning of the first path segment.
Definition: uri.h:43
coap_uri_t::port
uint16_t port
The port in host byte order.
Definition: uri.h:42
coap_uri_t::query
coap_str_const_t query
The query part if present.
Definition: uri.h:45
coap_uri_t::host
coap_str_const_t host
host part of the URI
Definition: uri.h:41
coap_uri_scheme_is_secure
static int coap_uri_scheme_is_secure(const coap_uri_t *uri)
Definition: uri.h:52
coap_uri_scheme_t
coap_uri_scheme_t
The scheme specifiers.
Definition: uri.h:23
COAP_URI_SCHEME_COAPS_TCP
@ COAP_URI_SCHEME_COAPS_TCP
Definition: uri.h:27
COAP_URI_SCHEME_COAPS
@ COAP_URI_SCHEME_COAPS
Definition: uri.h:25
COAP_URI_SCHEME_COAP_TCP
@ COAP_URI_SCHEME_COAP_TCP
Definition: uri.h:26
COAP_URI_SCHEME_HTTPS
@ COAP_URI_SCHEME_HTTPS
Definition: uri.h:29
COAP_URI_SCHEME_COAP
@ COAP_URI_SCHEME_COAP
Definition: uri.h:24
COAP_URI_SCHEME_HTTP
@ COAP_URI_SCHEME_HTTP
Definition: uri.h:28
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: uri.c:482
coap_clone_uri
coap_uri_t * coap_clone_uri(const coap_uri_t *uri)
Clones the specified coap_uri_t object.
Definition: uri.c:501
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: uri.h:33