7 #include <netinet/in.h>
25 #define IPPORT_HTTP 80
28 #define IPPORT_HTTPS 443
30 #ifndef IPPORT_PGPKEYSERVER
31 #define IPPORT_PGPKEYSERVER 11371
56 #define URLDBG(_f, _m, _x) if ((_url_debug | (_f)) & (_m)) fprintf _x
58 #define URLDBGIO(_f, _x) URLDBG((_f), RPMURL_DEBUG_IO, _x)
59 #define URLDBGREFS(_f, _x) URLDBG((_f), RPMURL_DEBUG_REFS, _x)
89 fprintf(stderr,
_(
"warning: u %p ctrl %p nrefs != 0 (%s %s)\n"),
109 fprintf(stderr,
_(
"warning: u %p data %p nrefs != 0 (%s %s)\n"),
149 if (_urlPool == NULL) {
188 if (_url_cache[i] == NULL)
continue;
189 _url_cache[i] =
urlFree(_url_cache[i],
"_url_cache");
190 if (_url_cache[i] == NULL)
192 yarnPossess(_url_cache[i]->_item.use);
194 _(
"warning: _url_cache[%d] %p nrefs(%ld) != 1 (%s %s)\n"),
195 i, _url_cache[i], yarnPeekLock(_url_cache[i]->_item.use),
196 (_url_cache[i]->
host ? _url_cache[i]->
host :
""),
198 yarnRelease(_url_cache[i]->_item.use);
201 _url_cache =
_free(_url_cache);
205 static int urlStrcmp(
const char * str1,
const char * str2)
210 return strcmp(str1, str2);
234 if (_url_cache == NULL || (ou = _url_cache[i]) == NULL) {
255 if (i == _url_count) {
258 _url_cache =
xrealloc(_url_cache,
sizeof(*_url_cache) * _url_count);
261 _url_cache[ucx] =
urlLink(u,
"_url_cache (miss)");
262 u =
urlFree(u,
"urlSplit (urlFind miss)");
265 u =
urlFree(u,
"urlSplit (urlFind hit)");
271 u =
urlLink(_url_cache[ucx],
"_url_cache");
274 u =
urlFree(u,
"_url_cache (urlFind)");
285 if (mustAsk || (u->
user != NULL && u->
password == NULL)) {
286 const char * host = (u->
host ? u->
host :
"");
287 const char * user = (u->
user ? u->
user :
"");
289 prompt =
alloca(strlen(host) + strlen(user) + 256);
290 sprintf(prompt,
_(
"Password for %s@%s: "), user, host);
300 const char *proxy =
rpmExpand(
"%{_ftpproxy}", NULL);
301 if (proxy && *proxy !=
'%') {
303 const char * host = (u->
host ? u->
host :
"");
304 const char *uu = (u->
user ? u->
user :
"anonymous");
305 char *nu =
xmalloc(strlen(uu) +
sizeof(
"@") + strlen(host));
310 proxy =
_free(proxy);
314 const char *proxy =
rpmExpand(
"%{_ftpport}", NULL);
315 if (proxy && *proxy !=
'%') {
317 int port = strtol(proxy, &end, 0);
318 if (!(end && *end ==
'\0')) {
319 fprintf(stderr,
_(
"error: %sport must be a number\n"),
325 proxy =
_free(proxy);
333 const char *proxy =
rpmExpand(
"%{_httpproxy}", NULL);
334 if (proxy && *proxy !=
'%')
336 proxy =
_free(proxy);
340 const char *proxy =
rpmExpand(
"%{_httpport}", NULL);
341 if (proxy && *proxy !=
'%') {
343 int port = strtol(proxy, &end, 0);
344 if (!(end && *end ==
'\0')) {
345 fprintf(stderr,
_(
"error: %sport must be a number\n"),
351 proxy =
_free(proxy);
402 url +=
sizeof(
"ftp://") - 1;
403 path = strchr(url,
'/');
404 if (path == NULL) path = url + strlen(url);
407 url +=
sizeof(
"file://") - 1;
408 path = strchr(url,
'/');
409 if (path == NULL) path = url + strlen(url);
412 url +=
sizeof(
"hkp://") - 1;
413 path = strchr(url,
'/');
414 if (path == NULL) path = url + strlen(url);
417 url +=
sizeof(
"http://") - 1;
418 path = strchr(url,
'/');
419 if (path == NULL) path = url + strlen(url);
422 url +=
sizeof(
"https://") - 1;
423 path = strchr(url,
'/');
424 if (path == NULL) path = url + strlen(url);
427 if (path == NULL) path =
"";
446 size_t nb = strlen(url);
447 char * t =
xmalloc(nb + 1 + 1);
448 const char * nurl = t;
466 char *s, *se, *f, *fe;
470 if ((u =
urlNew(
"urlSplit")) == NULL)
474 if ((se = strrchr(myurl,
'#')) != NULL) {
478 if ((se = strrchr(myurl,
'?')) != NULL) {
489 while (*se && *se !=
'/') se++;
491 if (*se && (se != s) && se[-1] ==
':' && se[0] ==
'/' && se[1] ==
'/') {
506 while (*fe && *fe !=
'@') fe++;
511 while (fe > f && *fe !=
':') fe--;
521 if (strchr(fe,
'[') && strchr(fe,
']')) {
527 while (*fe && *fe !=
':') fe++;
534 if (!(end && *end ==
'\0')) {
536 myurl =
_free(myurl);
537 u =
urlFree(u,
"urlSplit (error #3)");
545 struct servent *serv;
548 serv = getservbyname(u->
scheme,
"tcp");
551 u->
port = (int) ntohs(serv->s_port);
562 myurl =
_free(myurl);
578 const char * sfuPath = NULL;
579 int urlType =
urlPath(url, &sfuPath);
582 if (*sfuPath ==
'\0')
586 if ((dest = strrchr(sfuPath,
'/')) != NULL)
596 result =
rpmExpand(
"%{__urlgetfile ", url,
" ", dest,
"}", NULL);
597 if (result != NULL && strcmp(result,
"OK") == 0)
603 result =
_free(result);
608 sfd =
Fopen(url,
"r.ufdio");
609 if (sfd == NULL ||
Ferror(sfd)) {
616 tfd =
Fopen(dest,
"w");
618 fprintf(stderr,
"*** urlGetFile sfd %p %s tfd %p %s\n", sfd, url, (tfd ? tfd : NULL), dest);
619 if (tfd == NULL ||
Ferror(tfd)) {