gnunet_uri_lib.h (4382B)
1 /** 2 * Copyright (C) 2016 Jack Engqvist Johansson 3 * 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. 21 */ 22 #ifndef GNUNET_URI_LIB_H 23 #define GNUNET_URI_LIB_H 24 25 26 /** 27 * The struct where the parsed values will be stored: 28 * 29 * scheme ":" [ "//" ] [ username ":" password "@" ] host [ ":" port ] [ "/" ] [ path ] [ "?" query ] [ "#" fragment ] 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. 33 */ 34 struct GNUNET_Uri 35 { 36 char *scheme; /* scheme, without ":" and "//" */ 37 char *username; /* username, default: NULL */ 38 char *password; /* password, default: NULL */ 39 char *host; /* hostname or IP address */ 40 int port; /* port, default: 0 */ 41 char *path; /* path, without leading "/", default: NULL */ 42 char *query; /* query, default: NULL */ 43 char *fragment; /* fragment, default: NULL */ 44 }; 45 46 47 /* A struct to hold the query string parameter values. */ 48 struct GNUNET_UriParam 49 { 50 char *key; 51 char *val; 52 }; 53 54 55 /** 56 * Parse a URL to a struct. 57 * 58 * The URL string should be in one of the following formats: 59 * 60 * Absolute URL: 61 * scheme ":" [ "//" ] [ username ":" password "@" ] host [ ":" port ] [ "/" ] [ path ] [ "?" query ] [ "#" fragment ] 62 * 63 * Relative URL: 64 * path [ "?" query ] [ "#" fragment ] 65 * 66 * The following parts will be parsed to the corresponding struct member. 67 * 68 * *url: a pointer to the struct where to store the parsed values. 69 * *url_str: a pointer to the url to be parsed (null terminated). The string 70 * will be modified. 71 * 72 * Returns 0 on success, otherwise -1. 73 */ 74 int 75 GNUNET_uri_parse (struct GNUNET_Uri *url, 76 char *url_str); 77 78 79 /** 80 * Split a path into several strings. 81 * 82 * No data is copied, the slashed are used as null terminators and then 83 * pointers to each path part will be stored in **parts. Double slashes will be 84 * treated as one. 85 * 86 * *path: the path to split. The string will be modified. 87 * **parts: a pointer to an array of (char *) where to store the result. 88 * max_parts: max number of parts to parse. 89 * 90 * Returns the number of parsed items. -1 on error. 91 */ 92 int 93 GNUNET_uri_split_path (char *path, 94 char **parts, 95 int max_parts); 96 97 98 /** 99 * Parse a query string into a key/value struct. 100 * 101 * The query string should be a null terminated string of parameters separated by 102 * a delimiter. Each parameter are checked for the equal sign character. If it 103 * appears in the parameter, it will be used as a null terminator and the part 104 * that comes after it will be the value of the parameter. 105 * 106 * No data are copied, the equal sign and delimiters are used as null 107 * terminators and then pointers to each parameter key and value will be stored 108 * in the yuarel_param struct. 109 * 110 * *query: the query string to parse. The string will be modified. 111 * delimiter: the character that separates the key/value pairs from each other. 112 * *params: an array of (struct yuarel_param) where to store the result. 113 * max_values: max number of parameters to parse. 114 * 115 * Returns the number of parsed items. -1 on error. 116 */ 117 int 118 GNUNET_uri_parse_query (char *query, 119 char delimiter, 120 struct GNUNET_UriParam *params, 121 int max_params); 122 123 124 #endif /* GNUNET_URI_LIB_H */