Adaptive Framework  0.9.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
afw_uri.h
Go to the documentation of this file.
1 // See the 'COPYING' file in the project root for licensing information.
2 /*
3  * Adaptive Framework Uniform Resource Identifier (URI) helpers
4  *
5  * Copyright (c) 2010-2023 Clemson University
6  *
7  */
8 
9 #ifndef __AFW_URI_H__
10 #define __AFW_URI_H__
11 
12 #include "afw_interface.h"
13 
29 
32 
33 
34 
35 #define AFW_URI_OCTET_INVALID (afw_uri_octet_type_t)0x00000000
36 
37 #define AFW_URI_OCTET_GEN_DELIM (afw_uri_octet_type_t)0x00000001
38 #define AFW_URI_OCTET_SUB_DELIM (afw_uri_octet_type_t)0x00000002
39 #define AFW_URI_OCTET_UNRESERVED (afw_uri_octet_type_t)0x00000004
40 #define AFW_URI_OCTET_PCT_ENCODED (afw_uri_octet_type_t)0x00000008
41 
42 #define AFW_URI_OCTET_ALPHA_UPPER (afw_uri_octet_type_t)0x00000010
43 #define AFW_URI_OCTET_ALPHA_LOWER (afw_uri_octet_type_t)0x00000020
44 #define AFW_URI_OCTET_DIGIT (afw_uri_octet_type_t)0x00000040
45 #define AFW_URI_OCTET_HEXDIGIT (afw_uri_octet_type_t)0x00000080
46 
48 #define AFW_URI_OCTET_ENCODE_URI (afw_uri_octet_type_t)0x00000100
49 
51 #define AFW_URI_OCTET_ENCODE_COMPONENT (afw_uri_octet_type_t)0x00000200
52 
54 #define AFW_URI_OCTET_ENCODE_COMPONENT_VALUE (afw_uri_octet_type_t)0x00000400
55 
56 #define AFW_URI_OCTET_AT (afw_uri_octet_type_t)0x00010000
57 #define AFW_URI_OCTET_COLON (afw_uri_octet_type_t)0x00020000
58 #define AFW_URI_OCTET_MINUS (afw_uri_octet_type_t)0x00040000
59 #define AFW_URI_OCTET_PERCENT (afw_uri_octet_type_t)0x00080000
60 #define AFW_URI_OCTET_PERIOD (afw_uri_octet_type_t)0x00100000
61 #define AFW_URI_OCTET_PLUS (afw_uri_octet_type_t)0x00200000
62 #define AFW_URI_OCTET_QUESTION (afw_uri_octet_type_t)0x00400000
63 #define AFW_URI_OCTET_SLASH (afw_uri_octet_type_t)0x00800000
64 
65 #define AFW_URI_OCTET_MASK_IS_BITWISE_NOT (afw_uri_octet_type_t)0x80000000
66 
68 #define AFW_URI_OCTET_ALPHA \
69  ( AFW_URI_OCTET_ALPHA_UPPER | \
70  AFW_URI_OCTET_ALPHA_LOWER )
71 
73 #define AFW_URI_OCTET_PCHAR \
74  ( AFW_URI_OCTET_UNRESERVED | \
75  AFW_URI_OCTET_PCT_ENCODED | \
76  AFW_URI_OCTET_SUB_DELIM | \
77  AFW_URI_OCTET_COLON | \
78  AFW_URI_OCTET_AT )
79 
81 #define AFW_URI_OCTET_SCHEME_START \
82  ( AFW_URI_OCTET_ALPHA )
83 
85 #define AFW_URI_OCTET_SCHEME_CONTINUE \
86  ( AFW_URI_OCTET_ALPHA | \
87  AFW_URI_OCTET_DIGIT | \
88  AFW_URI_OCTET_PLUS | \
89  AFW_URI_OCTET_MINUS | \
90  AFW_URI_OCTET_PERIOD )
91 
93 #define AFW_URI_OCTET_USERINFO \
94  ( AFW_URI_OCTET_UNRESERVED | \
95  AFW_URI_OCTET_PCT_ENCODED | \
96  AFW_URI_OCTET_SUB_DELIM | \
97  AFW_URI_OCTET_COLON )
98 
100 #define AFW_URI_OCTET_QUERY \
101  ( AFW_URI_OCTET_PCHAR | \
102  AFW_URI_OCTET_SLASH | \
103  AFW_URI_OCTET_QUESTION )
104 
106 #define AFW_URI_OCTET_FRAGMENT \
107  ( AFW_URI_OCTET_PCHAR | \
108  AFW_URI_OCTET_SLASH | \
109  AFW_URI_OCTET_QUESTION )
110 
112 #define AFW_URI_OCTET_RESERVED \
113  ( AFW_URI_OCTET_GEN_DELIM | \
114  AFW_URI_OCTET_SUB_DELIM )
115 
116 
123 #define AFW_URI_OCTET_IS(type, mask) \
124 ((type) & (AFW_URI_OCTET_ ## mask))
125 
126 
130 
131 
133 typedef struct afw_uri_parsed_s {
134 
135  /* @brief Unparsed uri from call to afw_uri_parse(). */
136  const afw_utf8_t *original_uri;
137 
138  /* @brief Current path or NULL passed to afw_uri_parse(). */
139  const afw_utf8_t *current_path;
140 
141  /*
142  * @brief Parsed value path
143  *
144  * If path part of URI is an adaptive value path, this is the parsed
145  * path; otherwise, NULL.
146  */
147  const afw_object_path_parsed_t *path_parsed;
148 
149  /*
150  * @brief The form of the URI that AFW considers normalized.
151  *
152  * This will begin with a single slash if the URI is a local path;
153  * otherwise, this is a full URI.
154  */
155  afw_utf8_t normalized_uri;
156 
157  /* @brief Scheme. Can not be percent encoded. */
158  afw_utf8_t scheme;
159 
160  /* @brief Original hier-part */
161  afw_utf8_t original_hier_part;
162 
163  /* @brief Original authority */
164  afw_utf8_t original_authority;
165 
166  /* @brief Decoded authority */
167  const afw_utf8_t *authority;
168 
169  /* @brief Original userinfo */
170  afw_utf8_t original_userinfo;
171 
172  /* @brief Decoded userinfo */
173  const afw_utf8_t *userinfo;
174 
175  /* @brief Original host */
176  afw_utf8_t original_host;
177 
178  /* @brief Decoded host */
179  const afw_utf8_t *host;
180 
181  /* @brief Port. Can not be percent encoded. */
182  afw_utf8_t port;
183 
184  /* @brief Original path */
185  afw_utf8_t original_path;
186 
187  /* @brief Original query */
188  afw_utf8_t original_query;
189 
190  /* @brief Original fragment */
191  afw_utf8_t original_fragment;
192 
194 
195 
197 typedef struct afw_uri_parser_s {
198 
199  /* @brief Decoded string representing token. */
200  afw_utf8_t token;
201 
202  /* @brief Indicates that token is AFW_URI_OCTET_RESERVED. */
203  afw_boolean_t is_reserved;
204 
205  /* Private members. */
206  const afw_pool_t *p;
207  const afw_utf8_t *uri;
208  const afw_octet_t *c;
209  const afw_octet_t *end;
211  afw_boolean_t reuse;
212  afw_boolean_t consider_period_a_token;
214 
215 
227 AFW_DECLARE(void)
229  const afw_utf8_t *uri,
230  const afw_pool_t *p, afw_xctx_t *xctx);
231 
232 
246  const afw_pool_t *p, afw_xctx_t *xctx);
247 
248 
257 AFW_DECLARE(void)
259  afw_xctx_t *xctx);
260 
261 
262 
269 AFW_DECLARE(void)
271  afw_xctx_t *xctx);
272 
273 
284 AFW_DECLARE(void)
286  const afw_uri_parser_t *parser,
287  afw_boolean_t consider_period_a_token,
288  afw_xctx_t *xctx);
289 
290 
300  const afw_utf8_t *string,
302  afw_xctx_t *xctx);
303 
304 
317  const afw_memory_t *raw,
319  afw_xctx_t *xctx);
320 
321 
333 AFW_DECLARE(const afw_utf8_t *)
335  const afw_utf8_t *string,
337  const afw_pool_t *p,
338  afw_xctx_t *xctx);
339 
340 
353 AFW_DECLARE(const afw_utf8_t *)
355  const afw_utf8_octet_t *s,
356  afw_size_t len,
358  const afw_pool_t *p,
359  afw_xctx_t *xctx);
360 
361 
370 AFW_DECLARE(const afw_utf8_t *)
372  const afw_memory_t *raw,
374  const afw_pool_t *p,
375  afw_xctx_t *xctx);
376 
391  afw_utf8_octet_t *s,
392  afw_size_t s_len,
393  const afw_utf8_t *string,
395  const afw_pool_t *p,
396  afw_xctx_t *xctx);
397 
398 
413  afw_utf8_octet_t *s,
414  afw_size_t s_len,
415  const afw_memory_t *raw,
417  const afw_pool_t *p,
418  afw_xctx_t *xctx);
419 
420 
430 AFW_DECLARE(const afw_utf8_t *)
432  const afw_utf8_t *encoded,
433  const afw_pool_t *p,
434  afw_xctx_t *xctx);
435 
436 
447 AFW_DECLARE(const afw_utf8_t *)
449  const afw_utf8_octet_t *s,
450  afw_size_t len,
451  const afw_pool_t *p,
452  afw_xctx_t *xctx);
453 
454 
466 AFW_DECLARE(const afw_memory_t *)
468  const afw_utf8_octet_t *s,
469  afw_size_t len,
470  const afw_pool_t *p,
471  afw_xctx_t *xctx);
472 
473 
484 AFW_DECLARE(const afw_memory_t *)
486  const afw_utf8_t *encoded,
487  const afw_pool_t *p,
488  afw_xctx_t *xctx);
489 
490 
505  const afw_utf8_t *uri,
506  afw_boolean_t is_value_path,
507  const afw_utf8_t *current_path,
508  const afw_pool_t *p,
509  afw_xctx_t *xctx);
510 
511 
519 AFW_DECLARE(const afw_object_t *)
521  const afw_uri_parsed_t * parsed,
522  const afw_pool_t *p,
523  afw_xctx_t *xctx);
524 
525 
538 AFW_DECLARE(const afw_object_t *)
540  const afw_utf8_t *uri,
541  afw_boolean_t is_value_path,
542  const afw_utf8_t *current_path,
543  const afw_pool_t *p,
544  afw_xctx_t *xctx);
545 
546 
547 
574  afw_octet_t octet,
575  afw_uri_octet_type_t mask);
576 
577 
587  const afw_uri_parsed_t *parsed1,
588  const afw_uri_parsed_t *parsed2,
589  afw_xctx_t *xctx);
590 
591 
604  const afw_utf8_t *uri1,
605  const afw_utf8_t *uri2,
606  afw_boolean_t is_value_path,
607  const afw_utf8_t *current_path2,
608  const afw_pool_t *p,
609  afw_xctx_t *xctx);
610 
611 
612 AFW_END_DECLARES
613 
616 #endif /* __AFW_URI_H__ */
#define AFW_BEGIN_DECLARES
#define AFW_DECLARE(type)
Declare a public afw function.
Interfaceafw_interface header.
AFW_DECLARE_CONST_DATA(afw_utf8_t) afw_s_200
afw_utf8_t for string 200
_Bool afw_boolean_t
Definition: afw_common.h:373
apr_uint32_t afw_uint32_t
32-bit unsigned integer.
Definition: afw_common.h:184
char afw_utf8_octet_t
8 bits of utf-8 codepoint.
Definition: afw_common.h:236
apr_size_t afw_size_t
size_t.
Definition: afw_common.h:151
unsigned char afw_octet_t
8 bits (unsigned).
Definition: afw_common.h:211
const afw_object_t * afw_uri_to_object(const afw_utf8_t *uri, afw_boolean_t is_value_path, const afw_utf8_t *current_path, const afw_pool_t *p, afw_xctx_t *xctx)
Turn a URI into an object representation.
Definition: afw_uri.c:2039
afw_boolean_t afw_uri_are_equivalent(const afw_utf8_t *uri1, const afw_utf8_t *uri2, afw_boolean_t is_value_path, const afw_utf8_t *current_path2, const afw_pool_t *p, afw_xctx_t *xctx)
Determine if two URIs are equivalent.
Definition: afw_uri.c:2143
void afw_uri_parse_next_token(const afw_uri_parser_t *parser, afw_xctx_t *xctx)
Parse next token.
Definition: afw_uri.c:1175
const afw_utf8_t * afw_uri_decode_create(const afw_utf8_octet_t *s, afw_size_t len, const afw_pool_t *p, afw_xctx_t *xctx)
Create a URI decoded string.
Definition: afw_uri.c:1023
void afw_uri_parser_initialize(afw_uri_parser_t *parser, const afw_utf8_t *uri, const afw_pool_t *p, afw_xctx_t *xctx)
Initialize a parser in specific pool.
Definition: afw_uri.c:1146
void afw_uri_parse_reuse_token(const afw_uri_parser_t *parser, afw_xctx_t *xctx)
Cause next call afw_uri_parse_get_next_token() to return current token.
Definition: afw_uri.c:1265
const afw_memory_t * afw_uri_decode_to_raw_create(const afw_utf8_octet_t *s, afw_size_t len, const afw_pool_t *p, afw_xctx_t *xctx)
Decode URI encoded string to raw.
Definition: afw_uri.c:1047
struct afw_uri_parsed_s afw_uri_parsed_t
Typedef for parsed URI returned from afw_uri_parse().
const afw_uri_parsed_t * afw_uri_parse(const afw_utf8_t *uri, afw_boolean_t is_value_path, const afw_utf8_t *current_path, const afw_pool_t *p, afw_xctx_t *xctx)
Parse a URI in specific pool.
Definition: afw_uri.c:1470
afw_size_t afw_uri_encode_len(const afw_utf8_t *string, afw_uri_octet_type_t mask, afw_xctx_t *xctx)
The length needed to URI encode a string.
Definition: afw_uri.c:762
const afw_utf8_t * afw_uri_encode_create(const afw_utf8_octet_t *s, afw_size_t len, afw_uri_octet_type_t mask, const afw_pool_t *p, afw_xctx_t *xctx)
Create a URI encode a string.
Definition: afw_uri.c:866
const afw_utf8_t * afw_uri_encode_raw(const afw_memory_t *raw, afw_uri_octet_type_t mask, const afw_pool_t *p, afw_xctx_t *xctx)
URI encode raw.
Definition: afw_uri.c:884
const afw_object_t * afw_uri_parsed_to_object(const afw_uri_parsed_t *parsed, const afw_pool_t *p, afw_xctx_t *xctx)
Turn a parsed URI into an object representation.
Definition: afw_uri.c:1894
const afw_memory_t * afw_uri_decode_to_raw(const afw_utf8_t *encoded, const afw_pool_t *p, afw_xctx_t *xctx)
Decode a URI encoded string to raw.
Definition: afw_uri.c:1099
const afw_utf8_t * afw_uri_encode(const afw_utf8_t *string, afw_uri_octet_type_t mask, const afw_pool_t *p, afw_xctx_t *xctx)
URI encode a string.
Definition: afw_uri.c:814
struct afw_uri_parser_s afw_uri_parser_t
URI parser typedef.
const afw_uri_parser_t * afw_uri_parser_create(const afw_utf8_t *uri, const afw_pool_t *p, afw_xctx_t *xctx)
Create and initialize a parser in specific pool.
Definition: afw_uri.c:1160
afw_size_t afw_uri_encode_raw_to_preallocated(afw_utf8_octet_t *s, afw_size_t s_len, const afw_memory_t *raw, afw_uri_octet_type_t mask, const afw_pool_t *p, afw_xctx_t *xctx)
URI encode from raw using supplied afw_utf8_t.
Definition: afw_uri.c:963
afw_boolean_t afw_uri_octet_test(afw_octet_t octet, afw_uri_octet_type_t mask)
Test uri octet type mask.
Definition: afw_uri.c:2161
const afw_utf8_t * afw_uri_decode(const afw_utf8_t *encoded, const afw_pool_t *p, afw_xctx_t *xctx)
Decode a URI encoded string.
Definition: afw_uri.c:1000
afw_uint32_t afw_uri_octet_type_t
Token type typedef.
Definition: afw_uri.h:31
void afw_uri_parse_set_consider_period_a_token(const afw_uri_parser_t *parser, afw_boolean_t consider_period_a_token, afw_xctx_t *xctx)
Set consider_period_a_token flag.
Definition: afw_uri.c:2057
afw_size_t afw_uri_encode_raw_len(const afw_memory_t *raw, afw_uri_octet_type_t mask, afw_xctx_t *xctx)
The length needed to URI encode raw.
Definition: afw_uri.c:788
afw_boolean_t afw_uri_parsed_are_equivalent(const afw_uri_parsed_t *parsed1, const afw_uri_parsed_t *parsed2, afw_xctx_t *xctx)
Determine if two parsed URIs are equivalent.
Definition: afw_uri.c:2070
afw_size_t afw_uri_encode_to_preallocated(afw_utf8_octet_t *s, afw_size_t s_len, const afw_utf8_t *string, afw_uri_octet_type_t mask, const afw_pool_t *p, afw_xctx_t *xctx)
URI encode a string using supplied afw_utf8_t.
Definition: afw_uri.c:925
afw_uri_octet_type[256]
Token type table indexed by afw_octet_t ( 0 - 255 ).
Definition: afw_uri.h:129
Struct for memory pointer and size.
Definition: afw_common.h:505
Typedef for parsed object path.
Interface afw_object public struct.
Interface afw_pool public struct.
Typedef for parsed URI returned from afw_uri_parse().
Definition: afw_uri.h:133
URI parser typedef.
Definition: afw_uri.h:197
NFC normalized UTF-8 string.
Definition: afw_common.h:545
Interface afw_xctx public struct.