7 #include <netinet/in.h>
30 #define IPPORT_HTTP 80
33 #define IPPORT_HTTPS 443
35 #ifndef IPPORT_PGPKEYSERVER
36 #define IPPORT_PGPKEYSERVER 11371
39 #define IPPORT_MONGO 27017
47 #define URL_IS_POSTGRES
48 #define URL_IS_SQLSERVER
73 #define URLDBG(_f, _m, _x) if ((_url_debug | (_f)) & (_m)) fprintf _x
75 #define URLDBGIO(_f, _x) URLDBG((_f), RPMURL_DEBUG_IO, _x)
76 #define URLDBGREFS(_f, _x) URLDBG((_f), RPMURL_DEBUG_REFS, _x)
106 fprintf(stderr,
_(
"warning: u %p ctrl %p nrefs != 0 (%s %s)\n"),
126 fprintf(stderr,
_(
"warning: u %p data %p nrefs != 0 (%s %s)\n"),
166 if (_urlPool == NULL) {
167 _urlPool =
rpmioNewPool(
"u",
sizeof(*u), -1, _url_debug,
172 memset(((
char *)u)+
sizeof(u->
_item), 0,
sizeof(*u)-
sizeof(u->
_item));
207 if (_url_cache[i] == NULL)
continue;
208 _url_cache[i] =
urlFree(_url_cache[i],
"_url_cache");
209 if (_url_cache[i] == NULL)
211 yarnPossess(_url_cache[i]->_item.use);
213 _(
"warning: _url_cache[%d] %p nrefs(%ld) != 1 (%s %s)\n"),
214 i, _url_cache[i], yarnPeekLock(_url_cache[i]->_item.use),
215 (_url_cache[i]->
host ? _url_cache[i]->
host :
""),
217 yarnRelease(_url_cache[i]->_item.use);
220 _url_cache =
_free(_url_cache);
224 static int urlStrcmp(
const char * str1,
const char * str2)
229 return strcmp(str1, str2);
253 if (_url_cache == NULL || (ou = _url_cache[i]) == NULL) {
274 if (i == _url_count) {
280 _url_cache[ucx] =
urlLink(u,
"_url_cache (miss)");
281 u =
urlFree(u,
"urlSplit (urlFind miss)");
284 u =
urlFree(u,
"urlSplit (urlFind hit)");
290 u =
urlLink(_url_cache[ucx],
"_url_cache");
293 u =
urlFree(u,
"_url_cache (urlFind)");
304 if (mustAsk || (u->
user != NULL && u->
password == NULL)) {
305 const char * host = (u->
host ? u->
host :
"");
306 const char * user = (u->
user ? u->
user :
"");
308 prompt = (
char *)
alloca(strlen(host) + strlen(user) + 256);
309 sprintf(prompt,
_(
"Password for %s@%s: "), user, host);
319 const char *proxy =
rpmExpand(
"%{_ftpproxy}", NULL);
320 if (proxy && *proxy !=
'%') {
322 const char * host = (u->
host ? u->
host :
"");
323 const char *uu = (u->
user ? u->
user :
"anonymous");
324 char *nu = (
char *)
xmalloc(strlen(uu) +
sizeof(
"@") + strlen(host));
329 proxy =
_free(proxy);
333 const char *proxy =
rpmExpand(
"%{_ftpport}", NULL);
334 if (proxy && *proxy !=
'%') {
336 int port = strtol(proxy, &end, 0);
337 if (!(end && *end ==
'\0')) {
338 fprintf(stderr,
_(
"error: %sport must be a number\n"),
344 proxy =
_free(proxy);
352 const char *proxy =
rpmExpand(
"%{_httpproxy}", NULL);
353 if (proxy && *proxy !=
'%')
355 proxy =
_free(proxy);
359 const char *proxy =
rpmExpand(
"%{_httpport}", NULL);
360 if (proxy && *proxy !=
'%') {
362 int port = strtol(proxy, &end, 0);
363 if (!(end && *end ==
'\0')) {
364 fprintf(stderr,
_(
"error: %sport must be a number\n"),
370 proxy =
_free(proxy);
413 if (url && *url && *url !=
'/')
431 static const char empty[] =
"";
432 const char *path = (url ? url : empty);
435 if (*path !=
'\0' && *path !=
'/') {
440 if ((path = strchr(url+us->
len,
'/')) == NULL)
459 size_t nb = strlen(url);
460 char * t = (
char *)
xmalloc(nb + 1 + 1);
461 const char * nurl = t;
479 char *s, *se, *f, *fe;
483 if ((u =
urlNew(
"urlSplit")) == NULL)
487 if ((se = strrchr(myurl,
'#')) != NULL) {
491 if ((se = strrchr(myurl,
'?')) != NULL) {
502 while (*se && *se !=
'/') se++;
504 if (*se && (se != s) && se[-1] ==
':' && se[0] ==
'/' && se[1] ==
'/') {
519 while (*fe && *fe !=
'@') fe++;
524 while (fe > f && *fe !=
':') fe--;
534 if (strchr(fe,
'[') && strchr(fe,
']')) {
540 while (*fe && *fe !=
':') fe++;
547 if (!(end && *end ==
'\0')) {
549 myurl =
_free(myurl);
550 u =
urlFree(u,
"urlSplit (error #3)");
558 struct servent *serv;
561 serv = getservbyname(u->
scheme,
"tcp");
564 u->
port = (int) ntohs(serv->s_port);
579 #define URL_IS_SQLITE
581 #define URL_IS_POSTGRES
586 myurl =
_free(myurl);
602 const char * sfuPath = NULL;
606 if (*sfuPath ==
'\0')
610 if ((dest = strrchr(sfuPath,
'/')) != NULL)
620 result =
rpmExpand(
"%{__urlgetfile ", url,
" ", dest,
"}", NULL);
621 if (result != NULL && strcmp(result,
"OK") == 0)
627 result =
_free(result);
632 sfd =
Fopen(url,
"r.ufdio");
633 if (sfd == NULL ||
Ferror(sfd)) {
640 tfd =
Fopen(dest,
"w");
642 fprintf(stderr,
"*** urlGetFile sfd %p %s tfd %p %s\n", sfd, url, (tfd ? tfd : NULL), dest);
643 if (tfd == NULL ||
Ferror(tfd)) {