diff options
author | Dag-Erling Smørgrav <des@FreeBSD.org> | 2000-06-27 11:00:07 +0000 |
---|---|---|
committer | Dag-Erling Smørgrav <des@FreeBSD.org> | 2000-06-27 11:00:07 +0000 |
commit | c66a7bdea919f282d3aa1f3e4fc1f4c098c49eff (patch) | |
tree | f2aa74bfedc6d4b5ab59c120c73491e4a36bf995 | |
parent | 5cda06b8b76298b576f22487667976d5093d0d7c (diff) | |
download | src-c66a7bdea919f282d3aa1f3e4fc1f4c098c49eff.tar.gz src-c66a7bdea919f282d3aa1f3e4fc1f4c098c49eff.zip |
Use libfetch instead of libftpio. This adds support for http and IPv6.
Notes
Notes:
svn path=/head/; revision=62154
-rw-r--r-- | usr.sbin/pkg_install/add/Makefile | 4 | ||||
-rw-r--r-- | usr.sbin/pkg_install/create/Makefile | 4 | ||||
-rw-r--r-- | usr.sbin/pkg_install/delete/Makefile | 4 | ||||
-rw-r--r-- | usr.sbin/pkg_install/info/Makefile | 4 | ||||
-rw-r--r-- | usr.sbin/pkg_install/lib/file.c | 134 | ||||
-rw-r--r-- | usr.sbin/pkg_install/lib/lib.h | 14 |
6 files changed, 41 insertions, 123 deletions
diff --git a/usr.sbin/pkg_install/add/Makefile b/usr.sbin/pkg_install/add/Makefile index 0f541267161a..248f21e6c953 100644 --- a/usr.sbin/pkg_install/add/Makefile +++ b/usr.sbin/pkg_install/add/Makefile @@ -4,8 +4,8 @@ PROG= pkg_add CFLAGS+= ${DEBUG} -I${.CURDIR}/../lib -DPADD= ${LIBINSTALL} ${LIBFTPIO} ${LIBMD} -LDADD= ${LIBINSTALL} -lftpio -lmd +DPADD= ${LIBINSTALL} ${LIBFETCH} ${LIBMD} +LDADD= ${LIBINSTALL} -lfetch -lmd SRCS= main.c perform.c futil.c extract.c diff --git a/usr.sbin/pkg_install/create/Makefile b/usr.sbin/pkg_install/create/Makefile index 18e8ca7de3b6..d39f93a1ee7f 100644 --- a/usr.sbin/pkg_install/create/Makefile +++ b/usr.sbin/pkg_install/create/Makefile @@ -4,8 +4,8 @@ PROG= pkg_create CFLAGS+= ${DEBUG} -I${.CURDIR}/../lib -DPADD= ${LIBINSTALL} ${LIBFTPIO} ${LIBMD} -LDADD= ${LIBINSTALL} -lftpio -lmd +DPADD= ${LIBINSTALL} ${LIBFETCH} ${LIBMD} +LDADD= ${LIBINSTALL} -lfetch -lmd SRCS= main.c perform.c pl.c diff --git a/usr.sbin/pkg_install/delete/Makefile b/usr.sbin/pkg_install/delete/Makefile index 488eceffd0aa..36b83ba2fafe 100644 --- a/usr.sbin/pkg_install/delete/Makefile +++ b/usr.sbin/pkg_install/delete/Makefile @@ -3,8 +3,8 @@ PROG= pkg_delete CFLAGS+= ${DEBUG} -I${.CURDIR}/../lib -DPADD= ${LIBINSTALL} ${LIBFTPIO} ${LIBMD} -LDADD= ${LIBINSTALL} -lftpio -lmd +DPADD= ${LIBINSTALL} ${LIBFETCH} ${LIBMD} +LDADD= ${LIBINSTALL} -lfetch -lmd SRCS= main.c perform.c diff --git a/usr.sbin/pkg_install/info/Makefile b/usr.sbin/pkg_install/info/Makefile index 50e1ef02cd59..5ca61a5ca91c 100644 --- a/usr.sbin/pkg_install/info/Makefile +++ b/usr.sbin/pkg_install/info/Makefile @@ -3,8 +3,8 @@ PROG= pkg_info CFLAGS+= ${DEBUG} -I${.CURDIR}/../lib -DPADD= ${LIBINSTALL} ${LIBFTPIO} ${LIBMD} -LDADD= ${LIBINSTALL} -lftpio -lmd +DPADD= ${LIBINSTALL} ${LIBFETCH} ${LIBMD} +LDADD= ${LIBINSTALL} -lfetch -lmd SRCS= main.c perform.c show.c diff --git a/usr.sbin/pkg_install/lib/file.c b/usr.sbin/pkg_install/lib/file.c index a2c2f3b831ea..49db19874c3a 100644 --- a/usr.sbin/pkg_install/lib/file.c +++ b/usr.sbin/pkg_install/lib/file.c @@ -25,8 +25,7 @@ static const char rcsid[] = #include "lib.h" #include <err.h> -#include <ftpio.h> -#include <netdb.h> +#include <fetch.h> #include <pwd.h> #include <time.h> #include <sys/wait.h> @@ -107,69 +106,17 @@ isURL(char *fname) /* * I'm sure there are other types of URL specifications that I could * also be looking for here, but for now I'll just be happy to get ftp - * working. + * and http working. */ if (!fname) return FALSE; while (isspace(*fname)) ++fname; - if (!strncmp(fname, "ftp://", 6)) + if (!strncmp(fname, "ftp://", 6) || !strncmp(fname, "http://", 7)) return TRUE; return FALSE; } -/* Returns the host part of a URL */ -char * -fileURLHost(char *fname, char *where, int max) -{ - char *ret; - - while (isspace(*fname)) - ++fname; - /* Don't ever call this on a bad URL! */ - fname += strlen("ftp://"); - /* Do we have a place to stick our work? */ - if ((ret = where) != NULL) { - while (*fname && *fname != '/' && max--) - *where++ = *fname++; - *where = '\0'; - return ret; - } - /* If not, they must really want us to stomp the original string */ - ret = fname; - while (*fname && *fname != '/') - ++fname; - *fname = '\0'; - return ret; -} - -/* Returns the filename part of a URL */ -char * -fileURLFilename(char *fname, char *where, int max) -{ - char *ret; - - while (isspace(*fname)) - ++fname; - /* Don't ever call this on a bad URL! */ - fname += strlen("ftp://"); - /* Do we have a place to stick our work? */ - if ((ret = where) != NULL) { - while (*fname && *fname != '/') - ++fname; - if (*fname == '/') { - while (*fname && max--) - *where++ = *fname++; - } - *where = '\0'; - return ret; - } - /* If not, they must really want us to stomp the original string */ - while (*fname && *fname != '/') - ++fname; - return fname; -} - #define HOSTNAME_MAX 64 /* * Try and fetch a file by URL, returning the directory name for where @@ -223,64 +170,37 @@ fileGetURL(char *base, char *spec) } else strcpy(fname, spec); - cp = fileURLHost(fname, host, HOSTNAME_MAX); - if (!*cp) { - warnx("URL `%s' has bad host part!", fname); - return NULL; - } - cp = fileURLFilename(fname, file, FILENAME_MAX); - if (!*cp) { - warnx("URL `%s' has bad filename part!", fname); + if ((ftp = fetchGetURL(fname, NULL)) == NULL) { + printf("Error: FTP Unable to get %s: %s\n", + fname, fetchLastErrString); return NULL; } + + if (isatty(0) || Verbose) + printf("Fetching %s...", fname), fflush(stdout); + pen[0] = '\0'; + if ((rp = make_playpen(pen, 0)) != NULL) { + tpid = fork(); + if (!tpid) { + dup2(fileno(ftp), 0); + i = execl("/usr/bin/tar", "tar", Verbose ? "-xzvf" : "-xzf", "-", 0); + exit(i); + } + else { + int pstat; - /* Maybe change to ftp if this doesn't work */ - uname = "anonymous"; - - /* Make up a convincing "password" */ - pw = getpwuid(getuid()); - if (!pw) { - warnx("can't get user name for ID %d", getuid()); - strcpy(pword, "joe@"); - } - else { - char me[HOSTNAME_MAX]; - - gethostname(me, HOSTNAME_MAX); - snprintf(pword, HOSTNAME_MAX + 40, "%s@%s", pw->pw_name, me); - } - ftp = ftpGetURL(fname, uname, pword, &status); - if (ftp) { - if (isatty(0) || Verbose) - printf("Fetching %s...", fname), fflush(stdout); - pen[0] = '\0'; - if ((rp = make_playpen(pen, 0)) != NULL) { - tpid = fork(); - if (!tpid) { - dup2(fileno(ftp), 0); - i = execl("/usr/bin/tar", "tar", Verbose ? "-xzvf" : "-xzf", "-", 0); - exit(i); - } - else { - int pstat; - - fclose(ftp); - tpid = waitpid(tpid, &pstat, 0); - if (Verbose) - printf("tar command returns %d status\n", WEXITSTATUS(pstat)); - } + fclose(ftp); + tpid = waitpid(tpid, &pstat, 0); + if (Verbose) + printf("tar command returns %d status\n", WEXITSTATUS(pstat)); } - else - printf("Error: Unable to construct a new playpen for FTP!\n"); - fclose(ftp); - if (rp && (isatty(0) || Verbose)) - printf(" Done.\n"); } else - printf("Error: FTP Unable to get %s: %s\n", - fname, - status ? ftpErrString(status) : hstrerror(h_errno)); + printf("Error: Unable to construct a new playpen for FTP!\n"); + fclose(ftp); + if (rp && (isatty(0) || Verbose)) + printf(" Done.\n"); return rp; } diff --git a/usr.sbin/pkg_install/lib/lib.h b/usr.sbin/pkg_install/lib/lib.h index 00b9b6f2913f..3d5f0ec58648 100644 --- a/usr.sbin/pkg_install/lib/lib.h +++ b/usr.sbin/pkg_install/lib/lib.h @@ -24,16 +24,16 @@ #define _INST_LIB_LIB_H_ /* Includes */ +#include <sys/param.h> +#include <sys/file.h> +#include <sys/stat.h> +#include <ctype.h> +#include <dirent.h> +#include <stdarg.h> #include <stdio.h> #include <stdlib.h> -#include <stdarg.h> #include <string.h> #include <unistd.h> -#include <ctype.h> -#include <dirent.h> -#include <sys/stat.h> -#include <sys/types.h> -#include <sys/file.h> /* Macros */ #define SUCCESS (0) @@ -131,8 +131,6 @@ Boolean isfile(char *); Boolean isempty(char *); Boolean isURL(char *); char *fileGetURL(char *, char *); -char *fileURLFilename(char *, char *, int); -char *fileURLHost(char *, char *, int); char *fileFindByPath(char *, char *); char *fileGetContents(char *); void write_file(char *, char *); |