, ", ' and & with <, >, ",
* ' and & correspondingly.
*
* The returned string needs to be freed by the caller.
*
* @param html an unescaped HTML string
* @return an escaped HTML string or NULL on error
*/
char *evhttp_htmlescape(const char *html);
/**
* Return a new empty evhttp_uri with no fields set.
*/
struct evhttp_uri *evhttp_uri_new(void);
/**
* Changes the flags set on a given URI. See EVHTTP_URI_* for
* a list of flags.
**/
void evhttp_uri_set_flags(struct evhttp_uri *uri, unsigned flags);
/** Return the scheme of an evhttp_uri, or NULL if there is no scheme has
* been set and the evhttp_uri contains a Relative-Ref. */
const char *evhttp_uri_get_scheme(const struct evhttp_uri *uri);
/**
* Return the userinfo part of an evhttp_uri, or NULL if it has no userinfo
* set.
*/
const char *evhttp_uri_get_userinfo(const struct evhttp_uri *uri);
/**
* Return the host part of an evhttp_uri, or NULL if it has no host set.
* The host may either be a regular hostname (conforming to the RFC 3986
* "regname" production), or an IPv4 address, or the empty string, or a
* bracketed IPv6 address, or a bracketed 'IP-Future' address.
*
* Note that having a NULL host means that the URI has no authority
* section, but having an empty-string host means that the URI has an
* authority section with no host part. For example,
* "mailto:user@example.com" has a host of NULL, but "file:///etc/motd"
* has a host of "".
*/
const char *evhttp_uri_get_host(const struct evhttp_uri *uri);
/** Return the port part of an evhttp_uri, or -1 if there is no port set. */
int evhttp_uri_get_port(const struct evhttp_uri *uri);
/** Return the path part of an evhttp_uri, or NULL if it has no path set */
const char *evhttp_uri_get_path(const struct evhttp_uri *uri);
/** Return the query part of an evhttp_uri (excluding the leading "?"), or
* NULL if it has no query set */
const char *evhttp_uri_get_query(const struct evhttp_uri *uri);
/** Return the fragment part of an evhttp_uri (excluding the leading "#"),
* or NULL if it has no fragment set */
const char *evhttp_uri_get_fragment(const struct evhttp_uri *uri);
/** Set the scheme of an evhttp_uri, or clear the scheme if scheme==NULL.
* Returns 0 on success, -1 if scheme is not well-formed. */
int evhttp_uri_set_scheme(struct evhttp_uri *uri, const char *scheme);
/** Set the userinfo of an evhttp_uri, or clear the userinfo if userinfo==NULL.
* Returns 0 on success, -1 if userinfo is not well-formed. */
int evhttp_uri_set_userinfo(struct evhttp_uri *uri, const char *userinfo);
/** Set the host of an evhttp_uri, or clear the host if host==NULL.
* Returns 0 on success, -1 if host is not well-formed. */
int evhttp_uri_set_host(struct evhttp_uri *uri, const char *host);
/** Set the port of an evhttp_uri, or clear the port if port==-1.
* Returns 0 on success, -1 if port is not well-formed. */
int evhttp_uri_set_port(struct evhttp_uri *uri, int port);
/** Set the path of an evhttp_uri, or clear the path if path==NULL.
* Returns 0 on success, -1 if path is not well-formed. */
int evhttp_uri_set_path(struct evhttp_uri *uri, const char *path);
/** Set the query of an evhttp_uri, or clear the query if query==NULL.
* The query should not include a leading "?".
* Returns 0 on success, -1 if query is not well-formed. */
int evhttp_uri_set_query(struct evhttp_uri *uri, const char *query);
/** Set the fragment of an evhttp_uri, or clear the fragment if fragment==NULL.
* The fragment should not include a leading "#".
* Returns 0 on success, -1 if fragment is not well-formed. */
int evhttp_uri_set_fragment(struct evhttp_uri *uri, const char *fragment);
/**
* Helper function to parse a URI-Reference as specified by RFC3986.
*
* This function matches the URI-Reference production from RFC3986,
* which includes both URIs like
*
* scheme://[[userinfo]@]foo.com[:port]]/[path][?query][#fragment]
*
* and relative-refs like
*
* [path][?query][#fragment]
*
* Any optional elements portions not present in the original URI are
* left set to NULL in the resulting evhttp_uri. If no port is
* specified, the port is set to -1.
*
* Note that no decoding is performed on percent-escaped characters in
* the string; if you want to parse them, use evhttp_uridecode or
* evhttp_parse_query_str as appropriate.
*
* Note also that most URI schemes will have additional constraints that
* this function does not know about, and cannot check. For example,
* mailto://www.example.com/cgi-bin/fortune.pl is not a reasonable
* mailto url, http://www.example.com:99999/ is not a reasonable HTTP
* URL, and ftp:username@example.com is not a reasonable FTP URL.
* Nevertheless, all of these URLs conform to RFC3986, and this function
* accepts all of them as valid.
*
* @param source_uri the request URI
* @param flags Zero or more EVHTTP_URI_* flags to affect the behavior
* of the parser.
* @return uri container to hold parsed data, or NULL if there is error
* @see evhttp_uri_free()
*/
struct evhttp_uri *evhttp_uri_parse_with_flags(const char *source_uri,
unsigned flags);
/** Tolerate URIs that do not conform to RFC3986.
*
* Unfortunately, some HTTP clients generate URIs that, according to RFC3986,
* are not conformant URIs. If you need to support these URIs, you can
* do so by passing this flag to evhttp_uri_parse_with_flags.
*
* Currently, these changes are:
*
* - Nonconformant URIs are allowed to contain otherwise unreasonable
* characters in their path, query, and fragment components.
*
*/
#define EVHTTP_URI_NONCONFORMANT 0x01
/** Alias for evhttp_uri_parse_with_flags(source_uri, 0) */
struct evhttp_uri *evhttp_uri_parse(const char *source_uri);
/**
* Free all memory allocated for a parsed uri. Only use this for URIs
* generated by evhttp_uri_parse.
*
* @param uri container with parsed data
* @see evhttp_uri_parse()
*/
void evhttp_uri_free(struct evhttp_uri *uri);
/**
* Join together the uri parts from parsed data to form a URI-Reference.
*
* Note that no escaping of reserved characters is done on the members
* of the evhttp_uri, so the generated string might not be a valid URI
* unless the members of evhttp_uri are themselves valid.
*
* @param uri container with parsed data
* @param buf destination buffer
* @param limit destination buffer size
* @return an joined uri as string or NULL on error
* @see evhttp_uri_parse()
*/
char *evhttp_uri_join(struct evhttp_uri *uri, char *buf, size_t limit);
#ifdef __cplusplus
}
#endif
#endif /* _EVENT2_HTTP_H_ */