aboutsummaryrefslogtreecommitdiff
path: root/src/include/gnunet_uri_lib.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/include/gnunet_uri_lib.h')
-rw-r--r--src/include/gnunet_uri_lib.h170
1 files changed, 98 insertions, 72 deletions
diff --git a/src/include/gnunet_uri_lib.h b/src/include/gnunet_uri_lib.h
index 48db0ac85..e5f144591 100644
--- a/src/include/gnunet_uri_lib.h
+++ b/src/include/gnunet_uri_lib.h
@@ -1,96 +1,122 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2020 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/** 1/**
21 * @file include/gnunet_uri_lib.h 2 * Copyright (C) 2016 Jack Engqvist Johansson
22 * @brief generic parser for URIs 3 *
23 * @author Jonathan Buchanan 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in all
12 * copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
24 */ 21 */
25
26#ifndef GNUNET_URI_LIB_H 22#ifndef GNUNET_URI_LIB_H
27#define GNUNET_URI_LIB_H 23#define GNUNET_URI_LIB_H
28 24
25
29/** 26/**
30 * A Universal Resource Identifier (URI). 27 * The struct where the parsed values will be stored:
28 *
29 * scheme ":" [ "//" ] [ username ":" password "@" ] host [ ":" port ] [ "/" ] [ path ] [ "?" query ]
30 *
31 * Note: to make sure that no strings are copied, the first slash "/" in the
32 * path will be used to null terminate the hostname if no port is supplied.
31 */ 33 */
32struct GNUNET_Uri 34struct GNUNET_uri {
33{ 35 char *scheme; /* scheme, without ":" and "//" */
34 /** 36 char *username; /* username, default: NULL */
35 * The scheme of the uri. 37 char *password; /* password, default: NULL */
36 */ 38 char *host; /* hostname or IP address */
37 char *scheme; 39 int port; /* port, default: 0 */
38 40 char *path; /* path, without leading "/", default: NULL */
39 41 char *query; /* query, default: NULL */
40 /** 42 char *fragment; /* fragment, default: NULL */
41 * The authority of the uri. If not present in the uri, NULL. 43};
42 */
43 char *authority;
44
45
46 /**
47 * The list of path segments in the URI. Note that if the path ends with a
48 * '/', then this array will end with an empty string to indicate the empty
49 * segment following the '/'.
50 */
51 char **path_segments;
52
53
54 /**
55 * The length of @e path_segments.
56 */
57 unsigned int path_segments_count;
58 44
59 45
60 /** 46/* A struct to hold the query string parameter values. */
61 * The query of the uri. If not present in the uri, NULL. 47struct GNUNET_uri_param {
62 */ 48 char *key;
63 char *query; 49 char *val;
50};
64 51
65 52
66 /** 53/**
67 * The fragment of the uri. If not present in the uri, NULL. 54 * Parse a URL to a struct.
68 */ 55 *
69 char *fragment; 56 * The URL string should be in one of the following formats:
70}; 57 *
58 * Absolute URL:
59 * scheme ":" [ "//" ] [ username ":" password "@" ] host [ ":" port ] [ "/" ] [ path ] [ "?" query ] [ "#" fragment ]
60 *
61 * Relative URL:
62 * path [ "?" query ] [ "#" fragment ]
63 *
64 * The following parts will be parsed to the corresponding struct member.
65 *
66 * *url: a pointer to the struct where to store the parsed values.
67 * *url_str: a pointer to the url to be parsed (null terminated). The string
68 * will be modified.
69 *
70 * Returns 0 on success, otherwise -1.
71 */
72int
73GNUNET_uri_parse (struct GNUNET_uri *url,
74 char *url_str);
71 75
72 76
73/** 77/**
74 * Parse a URI from a string into an internal representation. 78 * Split a path into several strings.
79 *
80 * No data is copied, the slashed are used as null terminators and then
81 * pointers to each path part will be stored in **parts. Double slashes will be
82 * treated as one.
83 *
84 * *path: the path to split. The string will be modified.
85 * **parts: a pointer to an array of (char *) where to store the result.
86 * max_parts: max number of parts to parse.
75 * 87 *
76 * @param uri string to parse 88 * Returns the number of parsed items. -1 on error.
77 * @param emsg where to store the parser error message (if any)
78 * @return handle to the internal representation of the URI, or NULL on error
79 */ 89 */
80struct GNUNET_Uri * 90int
81GNUNET_uri_parse (const char *uri, 91GNUNET_uri_split_path (char *path,
82 char **emsg); 92 char **parts,
93 int max_parts);
83 94
84 95
85/** 96/**
86 * Free URI. 97 * Parse a query string into a key/value struct.
87 * 98 *
88 * @param uri uri to free 99 * The query string should be a null terminated string of parameters separated by
100 * a delimiter. Each parameter are checked for the equal sign character. If it
101 * appears in the parameter, it will be used as a null terminator and the part
102 * that comes after it will be the value of the parameter.
103 *
104 * No data are copied, the equal sign and delimiters are used as null
105 * terminators and then pointers to each parameter key and value will be stored
106 * in the yuarel_param struct.
107 *
108 * *query: the query string to parse. The string will be modified.
109 * delimiter: the character that separates the key/value pairs from eachother.
110 * *params: an array of (struct yuarel_param) where to store the result.
111 * max_values: max number of parameters to parse.
112 *
113 * Returns the number of parsed items. -1 on error.
89 */ 114 */
90void 115int
91GNUNET_uri_destroy (struct GNUNET_Uri *uri); 116GNUNET_uri_parse_query (char *query,
117 char delimiter,
118 struct GNUNET_uri_param *params,
119 int max_params);
92 120
93 121
94#endif /* GNUNET_URI_LIB_H */ 122#endif /* GNUNET_URI_LIB_H */
95
96/* end of include/gnunet_uri_lib.h */