1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*
* 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.
*/
/**
* @file uri.h
* @brief Helper functions for URI treatment
*/
/**
* The scheme specifiers. Secure schemes have an odd numeric value,
* others are even.
*/
typedef enum coap_uri_scheme_t coap_uri_scheme_t;
/** This mask can be used to check if a parsed URI scheme is secure. */
/**
* Representation of parsed URI. Components may be filled from a string with
* coap_split_uri() or coap_split_proxy_uri() and can be used as input for
* option-creation functions.
*/
typedef struct coap_uri_t;
static inline int
/**
* Creates a new coap_uri_t object from the specified URI. Returns the new
* object or NULL on error. The memory allocated by the new coap_uri_t
* must be released using coap_free().
*
* @param uri The URI path to copy.
* @param length The length of uri.
*
* @return New URI object or NULL on error.
*/
coap_uri_t *;
/**
* Clones the specified coap_uri_t object. Thie function allocates sufficient
* memory to hold the coap_uri_t structure and its contents. The object must
* be released with coap_free(). */
coap_uri_t *;
/**
* @ingroup application_api
* @defgroup uri_parse URI Parsing Functions
* API for parsing URIs.
* CoAP PDUs contain normalized URIs with their path and query split into
* multiple segments. The functions in this module help splitting strings.
* @{
*/
/**
* Parses a given string into URI components. The identified syntactic
* components are stored in the result parameter @p uri. Optional URI
* components that are not specified will be set to { 0, 0 }, except for the
* port which is set to the default port for the protocol. This function
* returns @p 0 if parsing succeeded, a value less than zero otherwise.
*
* @param str_var The string to split up.
* @param len The actual length of @p str_var
* @param uri The coap_uri_t object to store the result.
*
* @return @c 0 on success, or < 0 on error.
*
*/
int ;
/**
* Parses a given string into URI components. The identified syntactic
* components are stored in the result parameter @p uri. Optional URI
* components that are not specified will be set to { 0, 0 }, except for the
* port which is set to default port for the protocol. This function returns
* @p 0 if parsing succeeded, a value less than zero otherwise.
* Note: This function enforces that the given string is in Proxy-Uri format
* as well as supports different schema such as http.
*
* @param str_var The string to split up.
* @param len The actual length of @p str_var
* @param uri The coap_uri_t object to store the result.
*
* @return @c 0 on success, or < 0 on error.
*
*/
int ;
/**
* Splits the given URI path into segments. Each segment is preceded
* by an option pseudo-header with delta-value 0 and the actual length
* of the respective segment after percent-decoding.
*
* @param s The path string to split.
* @param length The actual length of @p s.
* @param buf Result buffer for parsed segments.
* @param buflen Maximum length of @p buf. Will be set to the actual number
* of bytes written into buf on success.
*
* @return The number of segments created or @c -1 on error.
*/
int ;
/**
* Splits the given URI query into segments. Each segment is preceded
* by an option pseudo-header with delta-value 0 and the actual length
* of the respective query term.
*
* @param s The query string to split.
* @param length The actual length of @p s.
* @param buf Result buffer for parsed segments.
* @param buflen Maximum length of @p buf. Will be set to the actual number
* of bytes written into buf on success.
*
* @return The number of segments created or @c -1 on error.
*
* @bug This function does not reserve additional space for delta > 12.
*/
int ;
/**
* Extract query string from request PDU according to escape rules in 6.5.8.
* @param request Request PDU.
* @return Reconstructed and escaped query string part or @c NULL if
* no query was contained in @p request. The coap_string_t
* object returned by this function must be released with
* coap_delete_string.
*/
coap_string_t *;
/**
* Extract uri_path string from request PDU
* @param request Request PDU.
* @return Reconstructed and escaped uri path string part or @c NULL
* if no URI-Path was contained in @p request. The
* coap_string_t object returned by this function must be
* released with coap_delete_string.
*/
coap_string_t *;
/** @} */
/* COAP_URI_H_ */