diff --git a/usr.sbin/sushi/functions.c b/usr.sbin/sushi/functions.c index 15458a65020e..152e77b2710b 100644 --- a/usr.sbin/sushi/functions.c +++ b/usr.sbin/sushi/functions.c @@ -1,4 +1,4 @@ -/* $NetBSD: functions.c,v 1.1 2001/01/05 01:28:35 garbled Exp $ */ +/* $NetBSD: functions.c,v 1.2 2001/01/24 09:30:30 garbled Exp $ */ /* * Copyright (c) 2000 The NetBSD Foundation, Inc. @@ -69,6 +69,7 @@ void ftp_stop(void); func_record func_map[] = { { "ftp_pkglist", ftp_pkglist }, + { "ftp_pkgcats", ftp_pkgcats }, { "script_do", script_do }, { "log_do", log_do }, {(char *)NULL, (char **(*)(char *))NULL}, @@ -228,6 +229,94 @@ ftp_pkglist(char *subdir) return list; } +/* + * Return list of package categories available at the given url + * or NULL on error. Returned pointer can be free(3)d + * later. + */ +/* ARGSUSED */ +char ** +ftp_pkgcats(char *subdir) +{ + int rc, tfd; + char tmpname[FILENAME_MAX]; + char buf[FILENAME_MAX]; + char url[FILENAME_MAX]; + char **list; + FILE *f; + int nlines; + + extern int ftp_start(char *url); /* pkg_install/lib stuff */ + extern int Verbose; /* pkg_install/lib stuff */ + Verbose=0; /* debugging */ + + /* ftp(1) must have a trailing '/' for directories */ + snprintf(url, sizeof(url), "%s/", ftp_base(0)); + + /* + * Start FTP coprocess + */ + rc = ftp_start(url); + if (rc == -1) + bailout(catgets(catalog, 1, 3, "ftp_start failed")); + + /* + * Generate tmp file + */ + strcpy(tmpname, TMPFILE_NAME); + tfd=mkstemp(tmpname); + if (tfd == -1) + bailout("mkstemp: %s", strerror(errno)); + + close(tfd); /* We don't need the file descriptor, but will use + the file in a second */ + /* + * Setup & run the command for ftp(1) + */ + (void) snprintf(buf, sizeof(buf), "ls -1F %s\n", + tmpname); + rc = ftp_cmd(buf, "\n(550|226).*\n"); /* catch errors */ + if (rc != 226) { + unlink(tmpname); /* remove clutter */ + bailout(catgets(catalog, 1, 4, "nlist failed")); + } + + f = fopen(tmpname, "r"); + if (!f) + bailout("fopen: %s", strerror(errno)); + + /* Read through file once to find out how many lines it has */ + nlines=0; + while(fgets(buf, sizeof(buf), f)) + nlines++; + rewind(f); + + list = malloc((nlines + 1) * sizeof(char *)); + if (list == NULL) + bailout("malloc: %s", strerror(errno)); + + /* alloc space for each line now */ + nlines = 0; + while(fgets(buf, sizeof(buf), f)) { + list[nlines] = strdup(buf); + if (list[nlines][strlen(list[nlines])-2] == '/') { + list[nlines][strlen(list[nlines])-2] = '\0'; + nlines++; + } + } + list[nlines] = NULL; + + fclose(f); + unlink(tmpname); + + /* + * Stop FTP coprocess + */ + ftp_stop(); + + return list; +} + /* * Return patch where binary packages for this OS version/arch * are expected. If mirror is NULL, ftp.netbsd.org is used. diff --git a/usr.sbin/sushi/functions.h b/usr.sbin/sushi/functions.h index 2f1f2796fb1a..2a3d5241060a 100644 --- a/usr.sbin/sushi/functions.h +++ b/usr.sbin/sushi/functions.h @@ -1,4 +1,4 @@ -/* $NetBSD: functions.h,v 1.2 2001/01/05 18:57:25 thorpej Exp $ */ +/* $NetBSD: functions.h,v 1.3 2001/01/24 09:30:30 garbled Exp $ */ /* * Copyright (c) 2000 The NetBSD Foundation, Inc. @@ -47,6 +47,7 @@ char **testf(char *junk); char **script_do(char *what); char **log_do(char *what); char **ftp_pkglist(char *); +char **ftp_pkgcats(char *); #define LOGFILE_NAME "sushi.log" #define SCRIPTFILE_NAME "sushi.script" diff --git a/usr.sbin/sushi/scanform.c b/usr.sbin/sushi/scanform.c index 30a131484aff..162a95ec2096 100644 --- a/usr.sbin/sushi/scanform.c +++ b/usr.sbin/sushi/scanform.c @@ -1,4 +1,4 @@ -/* $NetBSD: scanform.c,v 1.9 2001/01/24 08:29:56 garbled Exp $ */ +/* $NetBSD: scanform.c,v 1.10 2001/01/24 09:30:30 garbled Exp $ */ /* * Copyright (c) 2000 The NetBSD Foundation, Inc. @@ -929,9 +929,9 @@ gen_list(FTREE_ENTRY *ftp, int max, char **args) } static void -gen_func(FTREE_ENTRY *ftp) +gen_func(FTREE_ENTRY *ftp, int max, char **args) { - int i; + int i, cur; char *p, *q; p = strsep(&ftp->data, ","); @@ -944,7 +944,11 @@ gen_func(FTREE_ENTRY *ftp) bailout("%s: %s", catgets(catalog, 1, 5, "function not found"), p); - ftp->list = func_map[i].function(q); + cur = tstring(max, q); + if (cur) + ftp->list = func_map[i].function(args[cur-1]); + else + ftp->list = func_map[i].function(q); } static void @@ -1117,7 +1121,7 @@ form_generate(struct cqForm *cqf, char *basedir, char **args) case DATAT_FUNC: F[i].type = ENUM; F[i].v = strdup(ftp->data); - gen_func(ftp); + gen_func(ftp, max, args); F[i].list = ftp->list; break; case DATAT_SCRIPT: @@ -1135,7 +1139,7 @@ form_generate(struct cqForm *cqf, char *basedir, char **args) case DATAT_MFUNC: F[i].type = MULTI; F[i].v = strdup(ftp->data); - gen_func(ftp); + gen_func(ftp, max, args); F[i].list = ftp->list; break; case DATAT_MSCRIPT: