#include "platform.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "gnunet_uri_lib.h"
Go to the source code of this file.
Functions | |
static int | natoi (const char *str, size_t len) |
Copyright (C) 2016,2017 Jack Engqvist Johansson. More... | |
static int | is_relative (const char *url) |
Check if a URL is relative (no scheme and hostname). More... | |
static char * | parse_scheme (char *str) |
Parse the scheme of a URL by inserting a null terminator after the scheme. More... | |
static char * | find_and_terminate (char *str, char find) |
Find a character in a string, replace it with '\0' and return the next character in the string. More... | |
static char * | find_fragment (char *str) |
static char * | find_query (char *str) |
static char * | find_path (char *str) |
int | GNUNET_uri_parse (struct GNUNET_Uri *url, char *u) |
Parse a URL to a struct. More... | |
int | GNUNET_uri_split_path (char *path, char **parts, int max_parts) |
Split a path into several strings. More... | |
int | GNUNET_uri_parse_query (char *query, char delimiter, struct GNUNET_UriParam *params, int max_params) |
Parse a query string into a key/value struct. More... | |
|
inlinestatic |
Copyright (C) 2016,2017 Jack Engqvist Johansson.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Parse a non null terminated string into an integer.
str: the string containing the number. len: Number of characters to parse.
Definition at line 36 of file uri.c.
Referenced by GNUNET_uri_parse().
|
inlinestatic |
Check if a URL is relative (no scheme and hostname).
url: the string containing the URL to check.
Returns 1 if relative, otherwise 0.
Definition at line 57 of file uri.c.
Referenced by GNUNET_uri_parse().
|
inlinestatic |
Parse the scheme of a URL by inserting a null terminator after the scheme.
str: the string containing the URL to parse. Will be modified.
Returns a pointer to the hostname on success, otherwise NULL.
Definition at line 71 of file uri.c.
Referenced by GNUNET_uri_parse().
|
inlinestatic |
Find a character in a string, replace it with '\0' and return the next character in the string.
str: the string to search in. find: the character to search for.
Returns a pointer to the character after the one to search for. If not found, NULL is returned.
Definition at line 103 of file uri.c.
Referenced by find_fragment(), find_path(), and find_query().
|
inlinestatic |
Definition at line 120 of file uri.c.
References find_and_terminate().
Referenced by GNUNET_uri_parse().
|
inlinestatic |
Definition at line 127 of file uri.c.
References find_and_terminate().
Referenced by GNUNET_uri_parse().
|
inlinestatic |
Definition at line 134 of file uri.c.
References find_and_terminate().
Referenced by GNUNET_uri_parse().
int GNUNET_uri_parse | ( | struct GNUNET_Uri * | url, |
char * | u | ||
) |
Parse a URL to a struct.
The URL string should be in one of the following formats:
Absolute URL: scheme ":" [ "//" ] [ username ":" password "@" ] host [ ":" port ] [ "/" ] [ path ] [ "?" query ] [ "#" fragment ]
Relative URL: path [ "?" query ] [ "#" fragment ]
The following parts will be parsed to the corresponding struct member.
*url: a pointer to the struct where to store the parsed values. *url_str: a pointer to the url to be parsed (null terminated). The string will be modified.
Returns 0 on success, otherwise -1.
Definition at line 160 of file uri.c.
References find_fragment(), find_path(), find_query(), GNUNET_Uri::fragment, GNUNET_Uri::host, is_relative(), natoi(), parse_scheme(), GNUNET_Uri::password, GNUNET_Uri::path, GNUNET_Uri::port, GNUNET_Uri::query, GNUNET_Uri::scheme, u, and GNUNET_Uri::username.
int GNUNET_uri_split_path | ( | char * | path, |
char ** | parts, | ||
int | max_parts | ||
) |
Split a path into several strings.
No data is copied, the slashed are used as null terminators and then pointers to each path part will be stored in **parts. Double slashes will be treated as one.
*path: the path to split. The string will be modified. **parts: a pointer to an array of (char *) where to store the result. max_parts: max number of parts to parse.
Returns the number of parsed items. -1 on error.
Definition at line 261 of file uri.c.
int GNUNET_uri_parse_query | ( | char * | query, |
char | delimiter, | ||
struct GNUNET_UriParam * | params, | ||
int | max_params | ||
) |
Parse a query string into a key/value struct.
The query string should be a null terminated string of parameters separated by a delimiter. Each parameter are checked for the equal sign character. If it appears in the parameter, it will be used as a null terminator and the part that comes after it will be the value of the parameter.
No data are copied, the equal sign and delimiters are used as null terminators and then pointers to each parameter key and value will be stored in the yuarel_param struct.
*query: the query string to parse. The string will be modified. delimiter: the character that separates the key/value pairs from each other. *params: an array of (struct yuarel_param) where to store the result. max_values: max number of parameters to parse.
Returns the number of parsed items. -1 on error.
Definition at line 313 of file uri.c.
References key, GNUNET_UriParam::key, and GNUNET_UriParam::val.