#ifndef URI_UTIL_H
#define URI_UTIL_H
#include "net.h"
/*
* Generic URI parsing.
*/
enum uri_parse_flags {
/* Scheme part 'scheme:' is already parsed externally. */
/* Allow '#fragment' part in URI */
};
struct uri_host {
const char *name;
};
struct uri_authority {
/* encoded userinfo part; e.g. "user:pass" */
const char *enc_userinfo;
};
struct uri_parser {
const char *error;
};
/* parse one instance of percent encoding. Returns 1 for success,
0 if none is preset at the current parser position, and -1 in
case of error. The decoded character is returned in ch_r upon
success */
unsigned char *ch_r);
/* parse characters as long as these comply with the the 'unreserved'
syntax. Returns 1 if characters were found, 0 if none were found,
and -1 if there was an error */
/* the same as uri_parse_unreserved(), but the allowed characters are
extended to 'unreserved / pct-encoded', meaning that percent encoding
is allowed */
/* decode percent-encoded data from the 'data' parameter, up until the
'until' parameter. If the latter is NULL, data is decoded up until the
'\0' character. The decoded data is allocated on the parser pool and
returned in decoded_r. Any errors are written to the parser object. */
/* cut the 'scheme ":"' part from the URI. The uri_p pointer is updated to
point just past the ":". Returns 0 on success and -1 on error. The
result is returned in the scheme_r parameter. This can be NULL to use
this function for merely checking the presence of a valid scheme. */
ATTR_NULL(2);
/* parse the URI 'scheme ":"' part. Returns 1 if successful, 0 if the first
character is not valid for a scheme, and -1 in case of error. The
result parameter scheme_r can be NULL to use this function for merely
checking the presence of a valid scheme. */
ATTR_NULL(2);
/* parse the URI 'reg-name' syntax. Returns 1 if successful, 0 if the first
character is not valid for a host name, and -1 in case of error. The
result parameter reg_name_r can be NULL to use this function for merely
checking the presence of a valid host name. The result is allocated from
the data stack.
*/
/* parse the URI 'reg-name' part as an Internet host name, which is a
sequence of domain name labels separated by '.', as defined in
Section 3.5 of RFC 1034 and Section 2.1 of RFC 1123. Returns 1 if
successful, 0 if the first character is not valid for a host name,
and -1 in case of error. The result parameter host_name_r can be NULL
to use this function for merely checking the presence of a valid host
name. The result is allocated from the data stack.
*/
/* parse the URI 'host' syntax, which is either an IP address literal or
a an Internet host name, as defined in Section 3.5 of RFC 1034 and
Section 2.1 of RFC 1123. An IP address literal is always allowed.
Returns 1 if successful, 0 if the first character is not valid for a
host name, and -1 in case of error. The provided host struct is filled
in with the parsed data, all allocated from the parser pool. The host
parameter can be NULL to use this function for merely checking for
valid 'host' syntax.
*/
/* parse the URI 'authority' syntax. Returns 1 if successful, 0 if the
first character is not valid for the 'authority' syntax and -1 in case
of error. The provided uri_authority struct is filled in with the parsed
data, all allocated from the parser pool. The auth parameter can be
NULL to use this function for merely checking for valid 'authority'
syntax.
*/
/* identical to uri_parse_authority(), except that this function parses
'"//" authority', rather than 'authority'.
*/
/* identical to uri_parse_authority(), except that this function parses
the registered name ('reg-name' syntax) as an Internet host name, as
defined in Section 3.5 of RFC 1034 and Section 2.1 of RFC 1123.
*/
/* identical to uri_parse_slashslash_authority(), except that this
function parses the registered name ('reg-name' syntax) as an Internet
host name, as defined in Section 3.5 of RFC 1034 and Section 2.1 of
RFC 1123.
*/
/* parse the URI 'segment' syntax. Returns 1 if successful, 0 if the first
character is not valid for the 'segment' syntax and -1 in case of
error. The result is allocated from the parser pool. Percent encoding is
not decoded in the result. The result parameter can be NULL to use this
function for merely checking for valid 'segment' syntax.
*/
/* parse the URI 'path' syntax. This also resolves '..' and '.' segments in
the path. If the path is relative, the relative_r parameter indicates
how many segments the base path must be moved towards root (as caused by
leading '..' segments). Returns 1 if successful, 0 if the first character
is not valid for the 'segment' syntax and -1 in case of error. The result
is a NULL-terminated string list allocated from the parser pool. Percent
encoding is not decoded in the result. The result parameter can be NULL
to use this function for merely checking for valid 'path' syntax.
*/
/* parse the URI 'query' syntax. Returns 1 if successful, 0 if the first
character is not valid for the 'query' syntax and -1 in case of
error. The result is allocated from the parser pool. Percent encoding is
not decoded in the result. The result parameter can be NULL to use this
function for merely checking for valid 'query' syntax.
*/
/* parse the URI 'fragment' syntax. Returns 1 if successful, 0 if the first
character is not valid for the 'fragment' syntax and -1 in case of
error. The result is allocated from the parser pool. Percent encoding is
not decoded in the result. The result parameter can be NULL to use this
function for merely checking for valid 'fragment' syntax.
*/
/* initialize the URI parser with the provided data */
/* initialize the URI parser with the provided '\0'-terminated string */
/* returns the temporary buffer associated with this parser. Can be used
for higher-level parsing activities. */
/* Parse a generic (RFC3986) absolute URI for validity.
Returns 0 if valid and -1 otherwise. Note that some URI formats like
"sip", "aix" and "aaa" violate RFC3986 and will currently fail with
this function.
*/
enum uri_parse_flags flags);
/*
* Generic URI manipulation
*/
/* copy uri_host struct from src to dest and allocate it on pool */
/*
* Generic URI validation
*/
/* Check whether the provided data is a valid absolute RFC3986 URI.
Returns 0 if valid and -1 otherwise. */
/* Check whether the provided string is a valid absolute RFC3986 URI.
Returns 0 if valid and -1 otherwise. */
const char **error_r);
/*
* Generic URI construction
*/
/* encodes the '\0'-terminated data using the percent encoding. The
esc_table is a 256 byte lookup table. If none of the esc_mask bits are
set at the character's position in the esc_table, a character needs
to be encoded. Also, when esc_extra contains a character, it needs to
be encoded. All other characters are copied verbatim to the out buffer.
*/
const unsigned char esc_table[256],
/* append the provided scheme to the out buffer */
/* append partial user data (i.e. some part of what comes before '@') to
the out buffer. No '@' is produced. Characters are percent-encoded when
necessary. Characters in esc are always percent-encoded, even when these
are valid 'userinfo' characters. */
/* append userinfo and '@' to the out buffer. Characters in userinfo are
percent-encoded when necessary.*/
/* append the host name to the out buffer. Characters are percent-encoded
when necessary.*/
/* append the host IP address to the out buffer. */
/* encode the URI host struct to the out buffer. */
/* append the port to the out buffer. */
/* append partial path segment data to the out buffer. No '/' is produced.
Characters are percent-encoded when necessary. Characters in esc are
always percent-encoded, even when these are valid 'segment' characters.
*/
/* append a full path segment to the out buffer. A leading '/' is
produced. Characters are percent-encoded when necessary. */
/* append partial path data to the out buffer. The data may include '/',
which is not encoded. Characters are percent-encoded when necessary.
Characters in esc are always percent-encoded, even when these are
valid 'path' characters.*/
/* append a full path to the out buffer. A leading '/' is produced. The
data may include more '/', which is not encoded. Characters are
percent-encoded when necessary.
*/
/* append partial query data to the out buffer. No leading '?' is
produced. Characters are percent-encoded when necessary. Characters
in esc are always percent-encoded, even when these are valid 'query'
characters.*/
/* append a full URI query part to the out buffer. A leading '?' is
produced. Characters are percent-encoded when necessary. */
/* append partial fragment data to the out buffer. No leading '#' is
produced. Characters are percent-encoded when necessary. Characters
in esc are always percent-encoded, even when these are valid
'fragment' characters.*/
/* append a full URI fragment part to the out buffer. A leading '#' is
produced. Characters are percent-encoded when necessary. */
#endif