urlsplit#
Functions
-
int isurl(const char *url)#
Returns non-zero if
urlis a valid URL.Note: If
urlstarts with an upper case letter followed by colon (e.g. “C:”), then it is interpreted as a Windows drive and not an URL.
-
int isurln(const char *url, int len)#
Like isurl(), but only considers the first
lenbytes ofurl.If
lenis negative, all ofurlis checked.
-
int urlsplit(const char *url, UrlComponents *components)#
Returns the length of the initial segment of
urlthat correspond to a valid URL. Hence, zero is returned ifurlis not a valid URL.If
componentsis not NULL, the memory it points to is filled in with start and length information of the different components ofurl.
-
int urlsplitn(const char *url, int len, UrlComponents *components)#
Like urlsplit(), but takes an extra argument
len.If
lenis positive, thelenfirst characters ofurlmust be a valid URL (in which caselenis returned), otherwise zero is returned.A negative
lenmeans that the whole length ofurlis parsed (equivalent tolen=strlen(url)).
-
int urljoin(char *buf, long size, UrlComponents *components)#
Join URL components
componentsand write them to bufferbuf.At most
sizebytes are written tobuf(incl. terminating NUL.If the ‘host’ field of
componentsis not NULL, the authority will be derived from the ‘username’, ‘host’ and ‘port’ fields, otherwise theauthorityfield will be used.Return number of bytes written to
buf, or the number of bytes that would have been written tobufifsizewould be big enough. On error, a negative value is returned.
-
int pct_encode(char *buf, long size, const char *src)#
Write percent-encoded copy of
srctobuf.At most
sizebytes are written (including NUL-termination).Return the number of bytes that would have been written to
buf(excluding NUL-terminator), or would have been written tobufif it would have been large enough. On error a negative number is returned.
-
int pct_nencode(char *buf, long size, const char *src, long len)#
Like pct_encode(), but at most
lenbytes are read fromsrc. Iflenis negative, all ofsrcis read.
-
int pct_xencode(char *buf, long size, const char *src, long len, StrCategory maxcat, const char *accepted)#
Write percent-encoded copy of the first
lenbytes ofsrctobuf.At most
sizebytes are written (including NUL-termination). Character in categories larger thanmaxcatand not inaccepted, will be percent-encoded.Return the number of bytes that would have been written to
buf(excluding NUL-terminator), or would have been written tobufif it would have been large enough. On error a negative number is returned.
-
int pct_decode(char *buf, long size, const char *encoded)#
Write percent-decoded copy of
encodedtobuf.At most
sizebytes are written (including NUL-termination).Return the number of bytes that would have been written to
buf(excluding NUL-terminator), or would have been written tobufif it would have been large enough. On error a negative number is returned.
-
int pct_ndecode(char *buf, long size, const char *encoded, long len)#
Like pct_decode(), but at most
lenbytes are read fromencoded. Iflenis negative, all ofencodedis read.
-
struct UrlComponents#
- #include <urlsplit.h>
Following RFC 3986, an URL has the general structure:
URL = scheme ":" ["//" authority] path ["?" query] ["#" fragment] authority = [userinfo "@"] host [":" port]
References
Struct filled in by urlsplit() with the start position and length of the different components of an url.
The scheme always start at position zero.
Public Members
-
const char *scheme#
-
int scheme_len#
-
const char *authority#
-
int authority_len#
-
const char *userinfo#
-
int userinfo_len#
-
const char *host#
-
int host_len#
-
const char *port#
-
int port_len#
-
const char *path#
-
int path_len#
-
const char *query#
-
int query_len#
-
const char *fragment#
-
int fragment_len#
-
const char *scheme#