2000-08-28 02:34:02 +08:00
|
|
|
/** \ingroup rpmio
|
|
|
|
* \file rpmio/url.c
|
|
|
|
*/
|
|
|
|
|
1999-07-04 07:36:35 +08:00
|
|
|
#include "system.h"
|
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
|
2000-06-10 05:24:37 +08:00
|
|
|
#include <rpmmacro.h>
|
|
|
|
#include <rpmmessages.h>
|
2000-06-10 02:57:23 +08:00
|
|
|
#include <rpmio_internal.h>
|
1999-07-04 07:36:35 +08:00
|
|
|
|
2000-12-13 04:03:45 +08:00
|
|
|
#include "debug.h"
|
|
|
|
|
2000-02-24 13:41:47 +08:00
|
|
|
#ifndef IPPORT_FTP
|
|
|
|
#define IPPORT_FTP 21
|
|
|
|
#endif
|
1999-12-06 05:22:45 +08:00
|
|
|
#ifndef IPPORT_HTTP
|
|
|
|
#define IPPORT_HTTP 80
|
|
|
|
#endif
|
2004-11-04 21:29:11 +08:00
|
|
|
#ifndef IPPORT_HTTPS
|
|
|
|
#define IPPORT_HTTPS 443
|
|
|
|
#endif
|
2004-11-29 05:14:41 +08:00
|
|
|
#ifndef IPPORT_PGPKEYSERVER
|
|
|
|
#define IPPORT_PGPKEYSERVER 11371
|
|
|
|
#endif
|
1999-12-06 05:22:45 +08:00
|
|
|
|
2001-10-18 00:43:36 +08:00
|
|
|
/**
|
|
|
|
*/
|
|
|
|
int _url_iobuf_size = RPMURL_IOBUF_SIZE;
|
1999-11-02 22:33:14 +08:00
|
|
|
|
2001-10-18 00:43:36 +08:00
|
|
|
/**
|
|
|
|
*/
|
1999-11-10 04:57:38 +08:00
|
|
|
int _url_debug = 0;
|
2001-10-18 00:43:36 +08:00
|
|
|
|
2000-06-10 05:24:37 +08:00
|
|
|
#define URLDBG(_f, _m, _x) if ((_url_debug | (_f)) & (_m)) fprintf _x
|
1999-11-02 22:33:14 +08:00
|
|
|
|
2000-06-10 05:24:37 +08:00
|
|
|
#define URLDBGIO(_f, _x) URLDBG((_f), RPMURL_DEBUG_IO, _x)
|
|
|
|
#define URLDBGREFS(_f, _x) URLDBG((_f), RPMURL_DEBUG_REFS, _x)
|
1999-11-02 22:33:14 +08:00
|
|
|
|
2001-10-15 11:22:10 +08:00
|
|
|
/**
|
|
|
|
*/
|
2001-10-18 00:43:36 +08:00
|
|
|
urlinfo *_url_cache = NULL;
|
2001-10-15 11:22:10 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
2001-10-18 00:43:36 +08:00
|
|
|
int _url_count = 0;
|
1999-10-31 00:43:29 +08:00
|
|
|
|
2001-05-04 05:00:18 +08:00
|
|
|
/**
|
|
|
|
* Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
|
2001-06-04 21:55:58 +08:00
|
|
|
* @param p memory to free
|
2001-05-04 05:00:18 +08:00
|
|
|
* @retval NULL always
|
|
|
|
*/
|
2007-09-11 22:48:54 +08:00
|
|
|
static inline void *
|
|
|
|
_free(const void * p)
|
2001-06-04 21:55:58 +08:00
|
|
|
{
|
|
|
|
if (p != NULL) free((void *)p);
|
2001-05-04 05:00:18 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1999-11-02 22:33:14 +08:00
|
|
|
urlinfo XurlLink(urlinfo u, const char *msg, const char *file, unsigned line)
|
|
|
|
{
|
1999-11-10 04:57:38 +08:00
|
|
|
URLSANE(u);
|
1999-11-02 22:33:14 +08:00
|
|
|
u->nrefs++;
|
2000-06-10 05:24:37 +08:00
|
|
|
URLDBGREFS(0, (stderr, "--> url %p ++ %d %s at %s:%u\n", u, u->nrefs, msg, file, line));
|
2007-09-11 22:48:54 +08:00
|
|
|
return u;
|
1999-11-02 22:33:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
urlinfo XurlNew(const char *msg, const char *file, unsigned line)
|
1999-10-31 00:43:29 +08:00
|
|
|
{
|
1999-11-02 22:33:14 +08:00
|
|
|
urlinfo u;
|
1999-10-31 00:43:29 +08:00
|
|
|
if ((u = xmalloc(sizeof(*u))) == NULL)
|
|
|
|
return NULL;
|
|
|
|
memset(u, 0, sizeof(*u));
|
|
|
|
u->proxyp = -1;
|
|
|
|
u->port = -1;
|
1999-11-24 08:03:54 +08:00
|
|
|
u->urltype = URL_IS_UNKNOWN;
|
1999-11-02 22:33:14 +08:00
|
|
|
u->nrefs = 0;
|
1999-11-10 04:57:38 +08:00
|
|
|
u->magic = URLMAGIC;
|
1999-11-02 22:33:14 +08:00
|
|
|
return XurlLink(u, msg, file, line);
|
1999-10-31 00:43:29 +08:00
|
|
|
}
|
1999-09-18 05:51:23 +08:00
|
|
|
|
1999-11-10 04:57:38 +08:00
|
|
|
urlinfo XurlFree(urlinfo u, const char *msg, const char *file, unsigned line)
|
1999-07-04 07:36:35 +08:00
|
|
|
{
|
1999-11-10 04:57:38 +08:00
|
|
|
URLSANE(u);
|
2000-06-10 05:24:37 +08:00
|
|
|
URLDBGREFS(0, (stderr, "--> url %p -- %d %s at %s:%u\n", u, u->nrefs, msg, file, line));
|
1999-11-02 22:33:14 +08:00
|
|
|
if (--u->nrefs > 0)
|
2007-09-11 22:48:54 +08:00
|
|
|
return u;
|
2001-05-04 05:00:18 +08:00
|
|
|
u->url = _free(u->url);
|
2004-11-06 00:00:31 +08:00
|
|
|
u->scheme = _free((void *)u->scheme);
|
2001-05-04 05:00:18 +08:00
|
|
|
u->user = _free((void *)u->user);
|
|
|
|
u->password = _free((void *)u->password);
|
|
|
|
u->host = _free((void *)u->host);
|
|
|
|
u->portstr = _free((void *)u->portstr);
|
|
|
|
u->proxyu = _free((void *)u->proxyu);
|
|
|
|
u->proxyh = _free((void *)u->proxyh);
|
|
|
|
|
2007-09-11 22:48:54 +08:00
|
|
|
u = _free(u);
|
1999-11-10 04:57:38 +08:00
|
|
|
return NULL;
|
1999-07-04 07:36:35 +08:00
|
|
|
}
|
|
|
|
|
1999-11-02 22:33:14 +08:00
|
|
|
void urlFreeCache(void)
|
1999-07-04 07:36:35 +08:00
|
|
|
{
|
2001-10-18 00:43:36 +08:00
|
|
|
if (_url_cache) {
|
2001-05-04 05:00:18 +08:00
|
|
|
int i;
|
2001-10-18 00:43:36 +08:00
|
|
|
for (i = 0; i < _url_count; i++) {
|
|
|
|
if (_url_cache[i] == NULL) continue;
|
|
|
|
_url_cache[i] = urlFree(_url_cache[i], "_url_cache");
|
|
|
|
if (_url_cache[i])
|
2001-05-04 05:00:18 +08:00
|
|
|
fprintf(stderr,
|
2001-10-18 00:43:36 +08:00
|
|
|
_("warning: _url_cache[%d] %p nrefs(%d) != 1 (%s %s)\n"),
|
|
|
|
i, _url_cache[i], _url_cache[i]->nrefs,
|
|
|
|
(_url_cache[i]->host ? _url_cache[i]->host : ""),
|
2004-11-06 00:00:31 +08:00
|
|
|
(_url_cache[i]->scheme ? _url_cache[i]->scheme : ""));
|
2001-05-04 05:00:18 +08:00
|
|
|
}
|
1999-10-31 00:43:29 +08:00
|
|
|
}
|
2001-10-18 00:43:36 +08:00
|
|
|
_url_cache = _free(_url_cache);
|
|
|
|
_url_count = 0;
|
1999-07-04 07:36:35 +08:00
|
|
|
}
|
|
|
|
|
2007-09-11 22:48:54 +08:00
|
|
|
static int urlStrcmp(const char * str1, const char * str2)
|
1999-07-04 07:36:35 +08:00
|
|
|
{
|
2002-04-15 05:48:44 +08:00
|
|
|
if (str1)
|
|
|
|
if (str2)
|
|
|
|
return strcmp(str1, str2);
|
1999-10-31 00:43:29 +08:00
|
|
|
if (str1 != str2)
|
|
|
|
return -1;
|
1999-07-04 07:36:35 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-09-11 22:48:54 +08:00
|
|
|
static void urlFind(urlinfo * uret, int mustAsk)
|
1999-07-04 07:36:35 +08:00
|
|
|
{
|
1999-11-02 22:33:14 +08:00
|
|
|
urlinfo u;
|
|
|
|
int ucx;
|
2001-06-02 06:00:07 +08:00
|
|
|
int i = 0;
|
1999-07-04 07:36:35 +08:00
|
|
|
|
|
|
|
if (uret == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
u = *uret;
|
1999-11-10 04:57:38 +08:00
|
|
|
URLSANE(u);
|
1999-07-04 07:36:35 +08:00
|
|
|
|
1999-11-02 22:33:14 +08:00
|
|
|
ucx = -1;
|
2001-10-18 00:43:36 +08:00
|
|
|
for (i = 0; i < _url_count; i++) {
|
2001-06-02 06:00:07 +08:00
|
|
|
urlinfo ou = NULL;
|
2001-10-18 00:43:36 +08:00
|
|
|
if (_url_cache == NULL || (ou = _url_cache[i]) == NULL) {
|
1999-11-02 22:33:14 +08:00
|
|
|
if (ucx < 0)
|
|
|
|
ucx = i;
|
1999-07-04 07:36:35 +08:00
|
|
|
continue;
|
|
|
|
}
|
1999-10-31 00:43:29 +08:00
|
|
|
|
1999-07-04 07:36:35 +08:00
|
|
|
/* Check for cache-miss condition. A cache miss is
|
|
|
|
* a) both items are not NULL and don't compare.
|
|
|
|
* b) either of the items is not NULL.
|
|
|
|
*/
|
2004-11-06 00:00:31 +08:00
|
|
|
if (urlStrcmp(u->scheme, ou->scheme))
|
1999-07-04 07:36:35 +08:00
|
|
|
continue;
|
|
|
|
if (urlStrcmp(u->host, ou->host))
|
|
|
|
continue;
|
|
|
|
if (urlStrcmp(u->user, ou->user))
|
|
|
|
continue;
|
|
|
|
if (urlStrcmp(u->portstr, ou->portstr))
|
|
|
|
continue;
|
|
|
|
break; /* Found item in cache */
|
|
|
|
}
|
|
|
|
|
2001-10-18 00:43:36 +08:00
|
|
|
if (i == _url_count) {
|
1999-11-02 22:33:14 +08:00
|
|
|
if (ucx < 0) {
|
2001-10-18 00:43:36 +08:00
|
|
|
ucx = _url_count++;
|
|
|
|
_url_cache = xrealloc(_url_cache, sizeof(*_url_cache) * _url_count);
|
1999-07-04 07:36:35 +08:00
|
|
|
}
|
2001-10-18 00:43:36 +08:00
|
|
|
if (_url_cache) /* XXX always true */
|
|
|
|
_url_cache[ucx] = urlLink(u, "_url_cache (miss)");
|
1999-11-10 04:57:38 +08:00
|
|
|
u = urlFree(u, "urlSplit (urlFind miss)");
|
1999-07-04 07:36:35 +08:00
|
|
|
} else {
|
1999-12-13 01:46:22 +08:00
|
|
|
ucx = i;
|
1999-11-10 04:57:38 +08:00
|
|
|
u = urlFree(u, "urlSplit (urlFind hit)");
|
1999-07-04 07:36:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This URL is now cached. */
|
1999-11-02 22:33:14 +08:00
|
|
|
|
2001-10-18 00:43:36 +08:00
|
|
|
if (_url_cache) /* XXX always true */
|
|
|
|
u = urlLink(_url_cache[ucx], "_url_cache");
|
1999-11-02 22:33:14 +08:00
|
|
|
*uret = u;
|
2001-10-18 00:43:36 +08:00
|
|
|
u = urlFree(u, "_url_cache (urlFind)");
|
1999-07-04 07:36:35 +08:00
|
|
|
|
|
|
|
/* Zap proxy host and port in case they have been reset */
|
|
|
|
u->proxyp = -1;
|
2001-05-04 05:00:18 +08:00
|
|
|
u->proxyh = _free(u->proxyh);
|
1999-07-04 07:36:35 +08:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-10-15 11:22:10 +08:00
|
|
|
/**
|
|
|
|
*/
|
1999-10-31 00:43:29 +08:00
|
|
|
static struct urlstring {
|
2002-04-15 05:48:44 +08:00
|
|
|
const char * leadin;
|
1999-10-31 00:43:29 +08:00
|
|
|
urltype ret;
|
|
|
|
} urlstrings[] = {
|
|
|
|
{ "file://", URL_IS_PATH },
|
|
|
|
{ "ftp://", URL_IS_FTP },
|
2004-11-29 05:14:41 +08:00
|
|
|
{ "hkp://", URL_IS_HKP },
|
1999-10-31 00:43:29 +08:00
|
|
|
{ "http://", URL_IS_HTTP },
|
2004-11-04 21:29:11 +08:00
|
|
|
{ "https://", URL_IS_HTTPS },
|
1999-10-31 00:43:29 +08:00
|
|
|
{ "-", URL_IS_DASH },
|
|
|
|
{ NULL, URL_IS_UNKNOWN }
|
|
|
|
};
|
|
|
|
|
2001-06-06 03:26:22 +08:00
|
|
|
urltype urlIsURL(const char * url)
|
|
|
|
{
|
1999-10-31 00:43:29 +08:00
|
|
|
struct urlstring *us;
|
|
|
|
|
1999-11-13 01:20:49 +08:00
|
|
|
if (url && *url) {
|
|
|
|
for (us = urlstrings; us->leadin != NULL; us++) {
|
|
|
|
if (strncmp(url, us->leadin, strlen(us->leadin)))
|
|
|
|
continue;
|
|
|
|
return us->ret;
|
|
|
|
}
|
1999-10-31 00:43:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return URL_IS_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
1999-11-20 02:19:41 +08:00
|
|
|
/* Return path portion of url (or pointer to NUL if url == NULL) */
|
2000-08-28 02:34:02 +08:00
|
|
|
urltype urlPath(const char * url, const char ** pathp)
|
1999-11-13 01:20:49 +08:00
|
|
|
{
|
1999-11-19 02:07:46 +08:00
|
|
|
const char *path;
|
|
|
|
int urltype;
|
1999-11-13 01:20:49 +08:00
|
|
|
|
1999-11-19 02:07:46 +08:00
|
|
|
path = url;
|
|
|
|
urltype = urlIsURL(url);
|
1999-11-13 01:20:49 +08:00
|
|
|
switch (urltype) {
|
|
|
|
case URL_IS_FTP:
|
1999-11-24 08:03:54 +08:00
|
|
|
url += sizeof("ftp://") - 1;
|
|
|
|
path = strchr(url, '/');
|
|
|
|
if (path == NULL) path = url + strlen(url);
|
1999-11-13 01:20:49 +08:00
|
|
|
break;
|
|
|
|
case URL_IS_PATH:
|
1999-11-24 08:03:54 +08:00
|
|
|
url += sizeof("file://") - 1;
|
|
|
|
path = strchr(url, '/');
|
|
|
|
if (path == NULL) path = url + strlen(url);
|
1999-11-13 01:20:49 +08:00
|
|
|
break;
|
2004-11-29 05:14:41 +08:00
|
|
|
case URL_IS_HKP:
|
|
|
|
url += sizeof("hkp://") - 1;
|
|
|
|
path = strchr(url, '/');
|
|
|
|
if (path == NULL) path = url + strlen(url);
|
|
|
|
break;
|
2004-11-04 21:29:11 +08:00
|
|
|
case URL_IS_HTTP:
|
|
|
|
url += sizeof("http://") - 1;
|
|
|
|
path = strchr(url, '/');
|
|
|
|
if (path == NULL) path = url + strlen(url);
|
|
|
|
break;
|
|
|
|
case URL_IS_HTTPS:
|
|
|
|
url += sizeof("https://") - 1;
|
|
|
|
path = strchr(url, '/');
|
|
|
|
if (path == NULL) path = url + strlen(url);
|
|
|
|
break;
|
1999-11-13 01:20:49 +08:00
|
|
|
case URL_IS_UNKNOWN:
|
1999-11-24 08:03:54 +08:00
|
|
|
if (path == NULL) path = "";
|
1999-11-13 01:20:49 +08:00
|
|
|
break;
|
|
|
|
case URL_IS_DASH:
|
|
|
|
path = "";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (pathp)
|
|
|
|
*pathp = path;
|
|
|
|
return urltype;
|
|
|
|
}
|
|
|
|
|
1999-07-04 07:36:35 +08:00
|
|
|
/*
|
|
|
|
* Split URL into components. The URL can look like
|
2004-11-06 00:00:31 +08:00
|
|
|
* scheme://user:password@host:port/path
|
2007-06-25 15:40:14 +08:00
|
|
|
* or as in RFC2732 for IPv6 address
|
|
|
|
* service://user:password@[ip:v6:ad:dr:es:s]:port/path
|
1999-07-04 07:36:35 +08:00
|
|
|
*/
|
1999-11-02 22:33:14 +08:00
|
|
|
int urlSplit(const char * url, urlinfo *uret)
|
1999-07-04 07:36:35 +08:00
|
|
|
{
|
1999-11-02 22:33:14 +08:00
|
|
|
urlinfo u;
|
1999-07-04 07:36:35 +08:00
|
|
|
char *myurl;
|
|
|
|
char *s, *se, *f, *fe;
|
|
|
|
|
|
|
|
if (uret == NULL)
|
|
|
|
return -1;
|
1999-11-02 22:33:14 +08:00
|
|
|
if ((u = urlNew("urlSplit")) == NULL)
|
1999-07-04 07:36:35 +08:00
|
|
|
return -1;
|
|
|
|
|
1999-09-21 11:22:53 +08:00
|
|
|
if ((se = s = myurl = xstrdup(url)) == NULL) {
|
1999-11-10 04:57:38 +08:00
|
|
|
u = urlFree(u, "urlSplit (error #1)");
|
1999-07-04 07:36:35 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
1999-09-21 11:22:53 +08:00
|
|
|
u->url = xstrdup(url);
|
1999-11-24 08:03:54 +08:00
|
|
|
u->urltype = urlIsURL(url);
|
1999-07-04 07:36:35 +08:00
|
|
|
|
1999-10-21 05:40:10 +08:00
|
|
|
while (1) {
|
1999-07-04 07:36:35 +08:00
|
|
|
/* Point to end of next item */
|
|
|
|
while (*se && *se != '/') se++;
|
2004-11-06 00:00:31 +08:00
|
|
|
/* Item was scheme. Save scheme and go for the rest ...*/
|
1999-11-19 02:07:46 +08:00
|
|
|
if (*se && (se != s) && se[-1] == ':' && se[0] == '/' && se[1] == '/') {
|
1999-07-04 07:36:35 +08:00
|
|
|
se[-1] = '\0';
|
2004-11-06 00:00:31 +08:00
|
|
|
u->scheme = xstrdup(s);
|
1999-07-04 07:36:35 +08:00
|
|
|
se += 2; /* skip over "//" */
|
|
|
|
s = se++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
1999-12-13 05:14:05 +08:00
|
|
|
/* Item was everything-but-path. Continue parse on rest */
|
1999-07-04 07:36:35 +08:00
|
|
|
*se = '\0';
|
|
|
|
break;
|
1999-10-21 05:40:10 +08:00
|
|
|
}
|
1999-07-04 07:36:35 +08:00
|
|
|
|
|
|
|
/* Look for ...@host... */
|
|
|
|
fe = f = s;
|
|
|
|
while (*fe && *fe != '@') fe++;
|
|
|
|
if (*fe == '@') {
|
|
|
|
s = fe + 1;
|
|
|
|
*fe = '\0';
|
|
|
|
/* Look for user:password@host... */
|
|
|
|
while (fe > f && *fe != ':') fe--;
|
|
|
|
if (*fe == ':') {
|
|
|
|
*fe++ = '\0';
|
1999-09-21 11:22:53 +08:00
|
|
|
u->password = xstrdup(fe);
|
1999-07-04 07:36:35 +08:00
|
|
|
}
|
1999-09-21 11:22:53 +08:00
|
|
|
u->user = xstrdup(f);
|
1999-07-04 07:36:35 +08:00
|
|
|
}
|
|
|
|
|
2007-06-25 15:40:14 +08:00
|
|
|
/* Look for ...host:port or [v6addr]:port*/
|
1999-07-04 07:36:35 +08:00
|
|
|
fe = f = s;
|
2007-06-25 15:40:14 +08:00
|
|
|
if (strchr(fe, '[') && strchr(fe, ']'))
|
|
|
|
{
|
|
|
|
fe = strchr(f, ']');
|
|
|
|
*f++ = '\0';
|
|
|
|
*fe++ = '\0';
|
|
|
|
}
|
1999-07-04 07:36:35 +08:00
|
|
|
while (*fe && *fe != ':') fe++;
|
|
|
|
if (*fe == ':') {
|
|
|
|
*fe++ = '\0';
|
1999-09-21 11:22:53 +08:00
|
|
|
u->portstr = xstrdup(fe);
|
1999-07-04 07:36:35 +08:00
|
|
|
if (u->portstr != NULL && u->portstr[0] != '\0') {
|
|
|
|
char *end;
|
|
|
|
u->port = strtol(u->portstr, &end, 0);
|
|
|
|
if (!(end && *end == '\0')) {
|
|
|
|
rpmMessage(RPMMESS_ERROR, _("url port must be a number\n"));
|
2001-05-04 05:00:18 +08:00
|
|
|
myurl = _free(myurl);
|
1999-11-10 04:57:38 +08:00
|
|
|
u = urlFree(u, "urlSplit (error #3)");
|
1999-07-04 07:36:35 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-09-21 11:22:53 +08:00
|
|
|
u->host = xstrdup(f);
|
1999-07-04 07:36:35 +08:00
|
|
|
|
2004-11-06 00:00:31 +08:00
|
|
|
if (u->port < 0 && u->scheme != NULL) {
|
1999-09-18 05:51:23 +08:00
|
|
|
struct servent *serv;
|
2004-11-29 05:14:41 +08:00
|
|
|
/* HACK hkp:// might lookup "pgpkeyserver" */
|
2004-11-06 00:00:31 +08:00
|
|
|
serv = getservbyname(u->scheme, "tcp");
|
1999-09-23 02:17:41 +08:00
|
|
|
if (serv != NULL)
|
1999-09-18 05:51:23 +08:00
|
|
|
u->port = ntohs(serv->s_port);
|
1999-11-24 08:03:54 +08:00
|
|
|
else if (u->urltype == URL_IS_FTP)
|
1999-07-04 07:36:35 +08:00
|
|
|
u->port = IPPORT_FTP;
|
2004-11-29 05:14:41 +08:00
|
|
|
else if (u->urltype == URL_IS_HKP)
|
|
|
|
u->port = IPPORT_PGPKEYSERVER;
|
1999-11-24 08:03:54 +08:00
|
|
|
else if (u->urltype == URL_IS_HTTP)
|
1999-07-04 07:36:35 +08:00
|
|
|
u->port = IPPORT_HTTP;
|
2004-11-04 21:29:11 +08:00
|
|
|
else if (u->urltype == URL_IS_HTTPS)
|
|
|
|
u->port = IPPORT_HTTPS;
|
1999-07-04 07:36:35 +08:00
|
|
|
}
|
|
|
|
|
2001-05-04 05:00:18 +08:00
|
|
|
myurl = _free(myurl);
|
1999-07-04 07:36:35 +08:00
|
|
|
if (uret) {
|
|
|
|
*uret = u;
|
2007-09-11 22:48:54 +08:00
|
|
|
/* FIX: rpmGlobalMacroContext not in <rpmlib.h> */
|
1999-11-02 22:33:14 +08:00
|
|
|
urlFind(uret, 0);
|
1999-07-04 07:36:35 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-06-06 03:26:22 +08:00
|
|
|
int urlGetFile(const char * url, const char * dest)
|
|
|
|
{
|
1999-07-04 07:36:35 +08:00
|
|
|
int rc;
|
|
|
|
FD_t sfd = NULL;
|
|
|
|
FD_t tfd = NULL;
|
1999-12-13 01:46:22 +08:00
|
|
|
const char * sfuPath = NULL;
|
|
|
|
int urlType = urlPath(url, &sfuPath);
|
1999-07-04 07:36:35 +08:00
|
|
|
|
1999-12-13 01:46:22 +08:00
|
|
|
if (*sfuPath == '\0')
|
|
|
|
return FTPERR_UNKNOWN;
|
|
|
|
|
1999-11-05 05:26:08 +08:00
|
|
|
sfd = Fopen(url, "r.ufdio");
|
1999-10-31 00:43:29 +08:00
|
|
|
if (sfd == NULL || Ferror(sfd)) {
|
1999-11-11 06:09:49 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, _("failed to open %s: %s\n"), url, Fstrerror(sfd));
|
1999-12-13 01:46:22 +08:00
|
|
|
rc = FTPERR_UNKNOWN;
|
|
|
|
goto exit;
|
1999-07-04 07:36:35 +08:00
|
|
|
}
|
|
|
|
|
1999-12-13 01:46:22 +08:00
|
|
|
if (dest == NULL) {
|
|
|
|
if ((dest = strrchr(sfuPath, '/')) != NULL)
|
|
|
|
dest++;
|
|
|
|
else
|
|
|
|
dest = sfuPath;
|
|
|
|
}
|
1999-07-04 07:36:35 +08:00
|
|
|
|
2001-05-04 05:00:18 +08:00
|
|
|
if (dest == NULL)
|
|
|
|
return FTPERR_UNKNOWN;
|
|
|
|
|
1999-11-11 06:09:49 +08:00
|
|
|
tfd = Fopen(dest, "w.ufdio");
|
|
|
|
if (_url_debug)
|
2001-05-04 05:00:18 +08:00
|
|
|
fprintf(stderr, "*** urlGetFile sfd %p %s tfd %p %s\n", sfd, url, (tfd ? tfd : NULL), dest);
|
1999-12-12 09:46:13 +08:00
|
|
|
if (tfd == NULL || Ferror(tfd)) {
|
1999-10-31 00:43:29 +08:00
|
|
|
/* XXX Fstrerror */
|
1999-11-11 06:09:49 +08:00
|
|
|
rpmMessage(RPMMESS_DEBUG, _("failed to create %s: %s\n"), dest, Fstrerror(tfd));
|
1999-12-13 01:46:22 +08:00
|
|
|
rc = FTPERR_UNKNOWN;
|
|
|
|
goto exit;
|
1999-07-04 07:36:35 +08:00
|
|
|
}
|
|
|
|
|
1999-12-13 01:46:22 +08:00
|
|
|
switch (urlType) {
|
2004-11-04 21:29:11 +08:00
|
|
|
case URL_IS_HTTPS:
|
1999-07-04 07:36:35 +08:00
|
|
|
case URL_IS_HTTP:
|
2004-11-29 05:14:41 +08:00
|
|
|
case URL_IS_HKP:
|
2004-11-04 21:29:11 +08:00
|
|
|
case URL_IS_FTP:
|
1999-07-04 07:36:35 +08:00
|
|
|
case URL_IS_PATH:
|
|
|
|
case URL_IS_DASH:
|
1999-11-11 06:09:49 +08:00
|
|
|
case URL_IS_UNKNOWN:
|
1999-11-13 01:20:49 +08:00
|
|
|
if ((rc = ufdGetFile(sfd, tfd))) {
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) Unlink(dest);
|
1999-11-11 06:09:49 +08:00
|
|
|
/* XXX FIXME: sfd possibly closed by copyData */
|
2007-09-11 22:48:54 +08:00
|
|
|
(void) Fclose(sfd) ;
|
1999-07-04 07:36:35 +08:00
|
|
|
}
|
1999-12-13 01:46:22 +08:00
|
|
|
sfd = NULL; /* XXX Fclose(sfd) done by ufdGetFile */
|
1999-07-04 07:36:35 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
rc = FTPERR_UNKNOWN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1999-12-13 01:46:22 +08:00
|
|
|
exit:
|
|
|
|
if (tfd)
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) Fclose(tfd);
|
1999-12-13 01:46:22 +08:00
|
|
|
if (sfd)
|
2001-05-01 06:32:22 +08:00
|
|
|
(void) Fclose(sfd);
|
1999-07-04 07:36:35 +08:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|