libcoap  4.3.0
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 
12 #ifndef COAP_URI_H_
13 #define COAP_URI_H_
14 
15 #include <stdint.h>
16 
17 #include "str.h"
18 
23 typedef enum coap_uri_scheme_t {
28  COAP_URI_SCHEME_HTTP, /* 4 Proxy-Uri only */
29  COAP_URI_SCHEME_HTTPS /* 5 Proxy-Uri only */
31 
33 #define COAP_URI_SCHEME_SECURE_MASK 0x01
34 
40 typedef struct {
42  uint16_t port;
48  enum coap_uri_scheme_t scheme;
49 } coap_uri_t;
50 
51 static inline int
53  return uri && ((uri->scheme & COAP_URI_SCHEME_SECURE_MASK) != 0);
54 }
55 
66 coap_uri_t *coap_new_uri(const uint8_t *uri, unsigned int length);
67 
73 
96 int coap_split_uri(const uint8_t *str_var, size_t len, coap_uri_t *uri);
97 
114 int coap_split_proxy_uri(const uint8_t *str_var, size_t len, coap_uri_t *uri);
115 
129 int coap_split_path(const uint8_t *s,
130  size_t length,
131  unsigned char *buf,
132  size_t *buflen);
133 
149 int coap_split_query(const uint8_t *s,
150  size_t length,
151  unsigned char *buf,
152  size_t *buflen);
153 
162 coap_string_t *coap_get_query(const coap_pdu_t *request);
163 
173 
176 #endif /* COAP_URI_H_ */
coap_string_t * coap_get_uri_path(const coap_pdu_t *request)
Extract uri_path string from request PDU.
Definition: uri.c:606
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
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
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
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
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
structure for CoAP PDUs token, if any, follows the fixed size header, then options until payload mark...
CoAP string data definition with const data.
Definition: str.h:40
CoAP string data definition.
Definition: str.h:32
Representation of parsed URI.
Definition: uri.h:40
enum coap_uri_scheme_t scheme
The parsed scheme specifier.
Definition: uri.h:48
coap_str_const_t path
Beginning of the first path segment.
Definition: uri.h:43
uint16_t port
The port in host byte order.
Definition: uri.h:42
coap_str_const_t query
The query part if present.
Definition: uri.h:45
coap_str_const_t host
host part of the URI
Definition: uri.h:41
static int coap_uri_scheme_is_secure(const coap_uri_t *uri)
Definition: uri.h:52
coap_uri_scheme_t
The scheme specifiers.
Definition: uri.h:23
@ COAP_URI_SCHEME_COAPS_TCP
Definition: uri.h:27
@ COAP_URI_SCHEME_COAPS
Definition: uri.h:25
@ COAP_URI_SCHEME_COAP_TCP
Definition: uri.h:26
@ COAP_URI_SCHEME_HTTPS
Definition: uri.h:29
@ COAP_URI_SCHEME_COAP
Definition: uri.h:24
@ COAP_URI_SCHEME_HTTP
Definition: uri.h:28
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_uri_t * coap_clone_uri(const coap_uri_t *uri)
Clones the specified coap_uri_t object.
Definition: uri.c:501
#define COAP_URI_SCHEME_SECURE_MASK
This mask can be used to check if a parsed URI scheme is secure.
Definition: uri.h:33