libcoap  4.3.0rc2
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  * This file is part of the CoAP library libcoap. Please see README for terms
7  * of use.
8  */
9 
10 #ifndef COAP_URI_H_
11 #define COAP_URI_H_
12 
13 #include <stdint.h>
14 
15 #include "str.h"
16 
21 typedef enum coap_uri_scheme_t {
26  COAP_URI_SCHEME_HTTP, /* 4 Proxy-Uri only */
27  COAP_URI_SCHEME_HTTPS /* 5 Proxy-Uri only */
29 
31 #define COAP_URI_SCHEME_SECURE_MASK 0x01
32 
38 typedef struct {
40  uint16_t port;
46  enum coap_uri_scheme_t scheme;
47 } coap_uri_t;
48 
49 static inline int
51  return uri && ((uri->scheme & COAP_URI_SCHEME_SECURE_MASK) != 0);
52 }
53 
64 coap_uri_t *coap_new_uri(const uint8_t *uri, unsigned int length);
65 
71 
94 int coap_split_uri(const uint8_t *str_var, size_t len, coap_uri_t *uri);
95 
112 int coap_split_proxy_uri(const uint8_t *str_var, size_t len, coap_uri_t *uri);
113 
127 int coap_split_path(const uint8_t *s,
128  size_t length,
129  unsigned char *buf,
130  size_t *buflen);
131 
147 int coap_split_query(const uint8_t *s,
148  size_t length,
149  unsigned char *buf,
150  size_t *buflen);
151 
160 coap_string_t *coap_get_query(const coap_pdu_t *request);
161 
171 
174 #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:604
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:554
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:442
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:454
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:234
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:239
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:38
CoAP string data definition.
Definition: str.h:30
Representation of parsed URI.
Definition: uri.h:38
enum coap_uri_scheme_t scheme
The parsed scheme specifier.
Definition: uri.h:46
coap_str_const_t path
Beginning of the first path segment.
Definition: uri.h:41
uint16_t port
The port in host byte order.
Definition: uri.h:40
coap_str_const_t query
The query part if present.
Definition: uri.h:43
coap_str_const_t host
host part of the URI
Definition: uri.h:39
static int coap_uri_scheme_is_secure(const coap_uri_t *uri)
Definition: uri.h:50
coap_uri_scheme_t
The scheme specifiers.
Definition: uri.h:21
@ COAP_URI_SCHEME_COAPS_TCP
Definition: uri.h:25
@ COAP_URI_SCHEME_COAPS
Definition: uri.h:23
@ COAP_URI_SCHEME_COAP_TCP
Definition: uri.h:24
@ COAP_URI_SCHEME_HTTPS
Definition: uri.h:27
@ COAP_URI_SCHEME_COAP
Definition: uri.h:22
@ COAP_URI_SCHEME_HTTP
Definition: uri.h:26
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:480
coap_uri_t * coap_clone_uri(const coap_uri_t *uri)
Clones the specified coap_uri_t object.
Definition: uri.c:499
#define COAP_URI_SCHEME_SECURE_MASK
This mask can be used to check if a parsed URI scheme is secure.
Definition: uri.h:31