GRU - Generic Reusable Utilities
gru_uri.h
Go to the documentation of this file.
1 /*
2  Copyright 2016 Otavio Rodolfo Piske
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15  */
16 #ifndef GRU_URI_H
17 #define GRU_URI_H
18 
19 #include <inttypes.h>
20 #include <stdbool.h>
21 
22 
23 #if !defined(_WIN32) && !defined(_WIN64)
24  #include <arpa/inet.h>
25 #else
26  #include <winsock2.h>
27  #include <ws2tcpip.h>
28 #endif
29 
30 #include <common/gru_portable.h>
31 #include <common/gru_status.h>
32 #include <string/gru_alt.h>
33 #include <common/gru_keypair.h>
34 #include <common/gru_variant.h>
35 
36 #include <uriparser/Uri.h>
37 #include <collection/gru_list.h>
38 
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42 
47 typedef enum gru_uri_parse_opt_t_ {
51 
52 typedef enum gru_uri_format_opt_t_ {
59 
60 typedef struct gru_uri_t_ {
61  char *scheme;
62  char *host;
63  char *path;
64  uint16_t port;
67 
75  gru_status_t *gru_restrict status);
76 
85  gru_uri_parse_opt_t parseopt,
86  gru_status_t *gru_restrict status);
87 
95  gru_status_t *gru_restrict status);
96 
106  gru_status_t *gru_restrict status);
107 
114 gru_export bool gru_uri_set_scheme(gru_uri_t *uri, const char *scheme);
115 
122 gru_export bool gru_uri_set_path(gru_uri_t *uri, const char *path);
123 
132 
138 
139 #ifdef __cplusplus
140 }
141 #endif
142 
143 #endif /* GRU_URI_H */
#define gru_restrict
Definition: gru_portable.h:20
#define gru_export
Definition: gru_portable.h:19
enum gru_uri_format_opt_t_ gru_uri_format_opt_t
gru_export bool gru_uri_set_scheme(gru_uri_t *uri, const char *scheme)
Sets the scheme in a URI object.
Definition: gru_uri.c:303
gru_uri_parse_opt_t_
Definition: gru_uri.h:47
@ GRU_URI_PARSE_STRIP
Definition: gru_uri.h:49
@ GRU_URI_PARSE_DEFAULT
Definition: gru_uri.h:48
struct gru_uri_t_ gru_uri_t
gru_export gru_uri_t gru_uri_parse(const char *gru_restrict uri, gru_status_t *gru_restrict status)
Default URI parser.
enum gru_uri_parse_opt_t_ gru_uri_parse_opt_t
gru_export bool gru_uri_set_path(gru_uri_t *uri, const char *path)
Sets the URI path.
Definition: gru_uri.c:313
gru_export gru_uri_t gru_uri_clone(gru_uri_t other, gru_status_t *status)
Clone a URI object.
Definition: gru_uri.c:327
gru_export void gru_uri_cleanup(gru_uri_t *uri)
Cleans up a URI object.
Definition: gru_uri.c:380
gru_export char * gru_uri_format(const gru_uri_t *gru_restrict uri, gru_uri_format_opt_t fopt, gru_status_t *gru_restrict status)
A more elaborate URI string converter that can filter parts of the URI.
gru_export gru_uri_t gru_uri_parse_ex(const char *gru_restrict url, gru_uri_parse_opt_t parseopt, gru_status_t *gru_restrict status)
URI parser with additional options.
Definition: gru_uri.c:183
gru_uri_format_opt_t_
Definition: gru_uri.h:52
@ GRU_URI_FORMAT_DEFAULT
Formats scheme, host, port and path if available.
Definition: gru_uri.h:56
@ GRU_URI_FORMAT_NONE
Definition: gru_uri.h:53
@ GRU_URI_FORMAT_PATH
Formats only scheme, host and port if available.
Definition: gru_uri.h:55
@ GRU_URI_FORMAT_PORT
Formats only scheme and host.
Definition: gru_uri.h:54
gru_export char * gru_uri_simple_format(const gru_uri_t *gru_restrict uri, gru_status_t *gru_restrict status)
Converts a URI object to a string.
Definition: gru_list.h:41
Status type.
Definition: gru_status.h:47
Definition: gru_uri.h:60
char * host
Definition: gru_uri.h:62
uint16_t port
Definition: gru_uri.h:64
char * path
Definition: gru_uri.h:63
gru_list_t * query
Definition: gru_uri.h:65
char * scheme
Definition: gru_uri.h:61