uri_parser.h
1 /*
2  * SPDX-FileCopyrightText: 2020 HAW Hamburg
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
27 #include <string.h>
28 #include <stdint.h>
29 #include <stdbool.h>
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
38 typedef struct {
39  const char *scheme;
40  const char *userinfo;
49  const char *host;
50 
58  const char *ipv6addr;
59 
65  const char *zoneid;
66 
67  const char *port_str;
68  const char *path;
69  const char *query;
70  uint16_t port;
71  uint16_t scheme_len;
72  uint16_t userinfo_len;
73  uint16_t host_len;
74  uint16_t ipv6addr_len;
75  uint16_t zoneid_len;
76  uint16_t port_str_len;
77  uint16_t path_len;
78  uint16_t query_len;
80 
84 typedef struct {
85  const char *name;
86  const char *value;
87  uint16_t name_len;
88  uint16_t value_len;
90 
102 bool uri_parser_is_absolute(const char *uri, size_t uri_len);
103 
114 bool uri_parser_is_absolute_string(const char *uri);
115 
128 int uri_parser_process(uri_parser_result_t *result, const char *uri,
129  size_t uri_len);
130 
142 int uri_parser_process_string(uri_parser_result_t *result, const char *uri);
143 
171  uri_parser_query_param_t *params,
172  size_t params_len);
173 
174 #ifdef __cplusplus
175 }
176 #endif
177 
int uri_parser_process_string(uri_parser_result_t *result, const char *uri)
Parse a URI reference.
int uri_parser_process(uri_parser_result_t *result, const char *uri, size_t uri_len)
Parse a URI reference.
int uri_parser_split_query(const uri_parser_result_t *uri_parsed, uri_parser_query_param_t *params, size_t params_len)
Provides a list of URI query parameters from a given URI parser result.
bool uri_parser_is_absolute_string(const char *uri)
Checks whether uri is in absolute form.
bool uri_parser_is_absolute(const char *uri, size_t uri_len)
Checks whether uri is in absolute form.
Container to represent a query parameter.
Definition: uri_parser.h:84
const char * value
value of the query parameter
Definition: uri_parser.h:86
const char * name
name of the query parameter
Definition: uri_parser.h:85
uint16_t name_len
length of name
Definition: uri_parser.h:87
uint16_t value_len
length of value
Definition: uri_parser.h:88
container that holds all results
Definition: uri_parser.h:38
uint16_t scheme_len
length of scheme
Definition: uri_parser.h:71
const char * scheme
scheme
Definition: uri_parser.h:39
uint16_t zoneid_len
length of zoneid
Definition: uri_parser.h:75
uint16_t path_len
length of path
Definition: uri_parser.h:77
const char * host
host part
Definition: uri_parser.h:49
const char * userinfo
userinfo
Definition: uri_parser.h:40
uint16_t userinfo_len
length of userinfo
Definition: uri_parser.h:72
const char * query
query
Definition: uri_parser.h:69
uint16_t query_len
length of query
Definition: uri_parser.h:78
uint16_t port_str_len
length of port_str
Definition: uri_parser.h:76
uint16_t ipv6addr_len
length of ipv6addr
Definition: uri_parser.h:74
const char * port_str
port as str
Definition: uri_parser.h:67
uint16_t port
port as uint16_t
Definition: uri_parser.h:70
const char * path
path
Definition: uri_parser.h:68
const char * zoneid
zoneid if host is IPv6 address, NULL otherwise
Definition: uri_parser.h:65
uint16_t host_len
length of host
Definition: uri_parser.h:73
const char * ipv6addr
Pointer to the start of the address, if host is an IPv6 address and NULL otherwise.
Definition: uri_parser.h:58