mirror of
https://github.com/freebsd/freebsd-src.git
synced 2024-11-29 21:52:45 +00:00
Add (and document) fetchMakeURL()
This commit is contained in:
parent
84861c13f9
commit
9a964d6a82
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=60927
@ -28,6 +28,7 @@
|
|||||||
.Dt FETCH 3
|
.Dt FETCH 3
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
|
.Nm fetchMakeURL ,
|
||||||
.Nm fetchParseURL ,
|
.Nm fetchParseURL ,
|
||||||
.Nm fetchFreeURL ,
|
.Nm fetchFreeURL ,
|
||||||
.Nm fetchGetURL ,
|
.Nm fetchGetURL ,
|
||||||
@ -58,6 +59,8 @@
|
|||||||
.Fd #include <stdio.h>
|
.Fd #include <stdio.h>
|
||||||
.Fd #include <fetch.h>
|
.Fd #include <fetch.h>
|
||||||
.Ft struct url *
|
.Ft struct url *
|
||||||
|
.Fn fetchMakeURL "char *scheme" "char *host" "int port" "char *doc" "char *user" "char *pwd"
|
||||||
|
.Ft struct url *
|
||||||
.Fn fetchParseURL "char *URL"
|
.Fn fetchParseURL "char *URL"
|
||||||
.Ft void
|
.Ft void
|
||||||
.Fn fetchFreeURL "struct url *URL"
|
.Fn fetchFreeURL "struct url *URL"
|
||||||
@ -120,8 +123,10 @@ all URL schemes.
|
|||||||
For instance, the file scheme only needs the <scheme>
|
For instance, the file scheme only needs the <scheme>
|
||||||
and <document> components.
|
and <document> components.
|
||||||
.Pp
|
.Pp
|
||||||
|
.Fn fetchMakeURL
|
||||||
|
and
|
||||||
.Fn fetchParseURL
|
.Fn fetchParseURL
|
||||||
returns a pointer to a
|
return a pointer to a
|
||||||
.Fa url
|
.Fa url
|
||||||
structure, which is defined as follows in
|
structure, which is defined as follows in
|
||||||
.Aq Pa fetch.h :
|
.Aq Pa fetch.h :
|
||||||
@ -143,6 +148,8 @@ struct url {
|
|||||||
.Ed
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
The pointer returned by
|
The pointer returned by
|
||||||
|
.Fn fetchMakeURL
|
||||||
|
or
|
||||||
.Fn fetchParseURL
|
.Fn fetchParseURL
|
||||||
should be freed using
|
should be freed using
|
||||||
.Fn fetchFreeURL .
|
.Fn fetchFreeURL .
|
||||||
|
@ -236,6 +236,48 @@ fetchListURL(char *URL, char *flags)
|
|||||||
return ue;
|
return ue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Make a URL
|
||||||
|
*/
|
||||||
|
struct url *
|
||||||
|
fetchMakeURL(char *scheme, char *host, int port, char *doc,
|
||||||
|
char *user, char *pwd)
|
||||||
|
{
|
||||||
|
struct url *u;
|
||||||
|
|
||||||
|
if (!scheme || (!host && !doc)) {
|
||||||
|
_url_seterr(URL_MALFORMED);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (port < 0 || port > 65535) {
|
||||||
|
_url_seterr(URL_BAD_PORT);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* allocate struct url */
|
||||||
|
if ((u = calloc(1, sizeof *u)) == NULL) {
|
||||||
|
_fetch_syserr();
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((u->doc = strdup(doc ? doc : "/")) == NULL) {
|
||||||
|
_fetch_syserr();
|
||||||
|
free(u);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define seturl(x) snprintf(u->x, sizeof u->x, "%s", x)
|
||||||
|
seturl(scheme);
|
||||||
|
seturl(host);
|
||||||
|
seturl(user);
|
||||||
|
seturl(pwd);
|
||||||
|
#undef seturl
|
||||||
|
u->port = port;
|
||||||
|
|
||||||
|
return u;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Split an URL into components. URL syntax is:
|
* Split an URL into components. URL syntax is:
|
||||||
* method:[//[user[:pwd]@]host[:port]]/[document]
|
* method:[//[user[:pwd]@]host[:port]]/[document]
|
||||||
@ -250,7 +292,6 @@ fetchParseURL(char *URL)
|
|||||||
|
|
||||||
/* allocate struct url */
|
/* allocate struct url */
|
||||||
if ((u = calloc(1, sizeof *u)) == NULL) {
|
if ((u = calloc(1, sizeof *u)) == NULL) {
|
||||||
errno = ENOMEM;
|
|
||||||
_fetch_syserr();
|
_fetch_syserr();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -320,7 +361,6 @@ nohost:
|
|||||||
p = "/";
|
p = "/";
|
||||||
|
|
||||||
if ((u->doc = strdup(p)) == NULL) {
|
if ((u->doc = strdup(p)) == NULL) {
|
||||||
errno = ENOMEM;
|
|
||||||
_fetch_syserr();
|
_fetch_syserr();
|
||||||
goto ouch;
|
goto ouch;
|
||||||
}
|
}
|
||||||
|
@ -110,6 +110,7 @@ int fetchStat(struct url *, struct url_stat *, char *);
|
|||||||
struct url_ent *fetchList(struct url *, char *);
|
struct url_ent *fetchList(struct url *, char *);
|
||||||
|
|
||||||
/* URL parsing */
|
/* URL parsing */
|
||||||
|
struct url *fetchMakeURL(char *, char *, int, char *, char *, char *);
|
||||||
struct url *fetchParseURL(char *);
|
struct url *fetchParseURL(char *);
|
||||||
void fetchFreeURL(struct url *);
|
void fetchFreeURL(struct url *);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user