urlsplit#
Functions
-
int isurl(const char *url)#
Returns non-zero if
url
is a valid URL.Note: If
url
starts 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
len
bytes ofurl
.If
len
is negative, all ofurl
is checked.
-
int urlsplit(const char *url, UrlComponents *components)#
Returns the length of the initial segment of
url
that correspond to a valid URL. Hence, zero is returned ifurl
is not a valid URL.If
components
is 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
len
is positive, thelen
first characters ofurl
must be a valid URL (in which caselen
is returned), otherwise zero is returned.A negative
len
means that the whole length ofurl
is parsed (equivalent tolen=strlen(url)
).
-
int urljoin(char *buf, long size, UrlComponents *components)#
Join URL components
components
and write them to bufferbuf
.At most
size
bytes are written tobuf
(incl. terminating NUL.If the ‘host’ field of
components
is not NULL, the authority will be derived from the ‘username’, ‘host’ and ‘port’ fields, otherwise theauthority
field will be used.Return number of bytes written to
buf
, or the number of bytes that would have been written tobuf
ifsize
would 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
src
tobuf
.At most
size
bytes 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 tobuf
if 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
len
bytes are read fromsrc
. Iflen
is negative, all ofsrc
is 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
len
bytes ofsrc
tobuf
.At most
size
bytes are written (including NUL-termination). Character in categories larger thanmaxcat
and 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 tobuf
if 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
encoded
tobuf
.At most
size
bytes 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 tobuf
if 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
len
bytes are read fromencoded
. Iflen
is negative, all ofencoded
is 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#