* Tollef Fog Heen 

| * Joey Hess 
| 
| | Move over to choose-mirror; you can probably add a loop in the right
| | place there to ensure that there are always values available.
| 
| I'll look into it.

And I did.  And I added ftp support to choose-mirror as well.  It
should be pretty trivial to add support for ftp to the wget retriever
- I'll look into that as well.

Sorry it has taken so long, but here is the patch, taken with a 'cvs
diff' inside debian-install/retriever/choose-mirror:

? Mirrors.masterlist
? mirrors_http.h
? choose-mirror
? mirrors_ftp.h
Index: Makefile
===================================================================
RCS file: /cvs/debian-boot/debian-installer/retriever/choose-mirror/Makefile,v
retrieving revision 1.2
diff -c -u -r1.2 Makefile
--- Makefile    2000/12/12 03:29:31     1.2
+++ Makefile    2001/01/20 23:26:39
@@ -25,7 +25,7 @@
 mirrors_ftp.h: Mirrors.masterlist
        ./makeheader.pl ftp
 
-choose-mirror.c: mirrors_http.h
+choose-mirror.c: mirrors_http.h mirrors_ftp.h
 
 $(BIN): $(OBJS)
        $(CC) -o $(BIN) $(OBJS) $(LIBS)
Index: choose-mirror.c
===================================================================
RCS file: /cvs/debian-boot/debian-installer/retriever/choose-mirror/choose-mirror.c,v
retrieving revision 1.5
diff -c -u -r1.5 choose-mirror.c
--- choose-mirror.c     2000/12/12 03:29:32     1.5
+++ choose-mirror.c     2001/01/20 23:26:51
@@ -7,6 +7,8 @@
 #include <stdlib.h>
 #include "mirrors.h"
 #include "mirrors_http.h"
+#include "mirrors_ftp.h"
+#include <stdio.h>
 
 struct debconfclient *debconf;
 
@@ -34,11 +36,31 @@
 
 /* Returns an array of hostnames of mirrors in the specified country. */
 char **mirrors_in(char *country) {
-       char **ret=malloc(100 * sizeof(char *)); // TODO: don't hardcode size
-       int i, j;
-       for (i = j = 0; mirrors_http[i].country != NULL; i++)
-               if (strcmp(mirrors_http[i].country, country) == 0)
-                       ret[j++]=mirrors_http[i].site;
+        static char **ret;
+       int i, j, num = 32;
+       struct mirror_t *mirrors;
+
+       debconf->command(debconf, "GET", DEBCONF_BASE "protocol", NULL);
+
+       if (strcasecmp(debconf->value,"http") == 0) {
+               mirrors = mirrors_http;
+       } else if (strcasecmp(debconf->value,"ftp") == 0) {
+               mirrors = mirrors_ftp;
+       } else {
+               /* FIXME, don't use fprintf */
+               fprintf(stderr,"Unknown protocol: %s\n",debconf->value);
+       }
+
+       ret = malloc(num * sizeof(char *));
+       for (i = j = 0; mirrors[i].country != NULL; i++) {
+               if (j == num-1) {
+                       num *= 2;
+                       ret = realloc(ret,num * sizeof(char*));
+               }
+       if (strcmp(mirrors[i].country, country) == 0) {
+                       ret[j++]=mirrors[i].site;
+               }
+       }
        ret[j]=NULL;
        return ret;
 }
@@ -46,46 +68,100 @@
 /* Returns the root of the mirror, given the hostname. */
 char *mirror_root(char *mirror) {
        int i;
+
+       struct mirror_t *mirrors;
 
-       for (i = 0; mirrors_http[i].site != NULL; i++)
-               if (strcmp(mirrors_http[i].site, mirror) == 0)
-                       return mirrors_http[i].root;
+       debconf->command(debconf, "GET", DEBCONF_BASE "protocol", NULL);
 
+       if (strcasecmp(debconf->value,"http") == 0) {
+               mirrors = mirrors_http;
+       } else if (strcasecmp(debconf->value,"ftp") == 0) {
+               mirrors = mirrors_ftp;
+       }
+
+       for (i = 0; mirrors[i].site != NULL; i++)
+               if (strcmp(mirrors[i].site, mirror) == 0)
+                       return mirrors[i].root;
+
        return NULL;
 }
+
+int choose_country(void) {
+       char *list;
+
+       debconf->command(debconf, "GET", DEBCONF_BASE "protocol", NULL);
+
+       if (strcasecmp(debconf->value,"http") == 0) {
+               list = debconf_list(countries_http);
+       } else if (strcasecmp(debconf->value,"ftp") == 0) {
+               list = debconf_list(countries_ftp);
+       }
 
-void choose_country(void) {
-       char *list=debconf_list(countries_http);
        debconf->command(debconf, "SUBST", DEBCONF_BASE "country", "countries", list, 
NULL);
        free(list);
        debconf->command(debconf, "INPUT", "high", DEBCONF_BASE "country", NULL);
+       return 0;
+}
+
+int choose_protocol(void) {
+       debconf->command(debconf, "SUBST", DEBCONF_BASE "protocol", "protocols", 
+"http, ftp", NULL);
+       debconf->command(debconf, "INPUT", "high", DEBCONF_BASE "protocol", NULL);
+       return 0;
 }
 
 int manual_entry;
 
-void choose_mirror(void) {
+int choose_mirror(void) {
        char *list;
-
+       char *protocol;
+       debconf->command(debconf, "GET", DEBCONF_BASE "protocol", NULL);
+       protocol = strdup(debconf->value);
+               
        debconf->command(debconf, "GET", DEBCONF_BASE "country", NULL);
        manual_entry = ! strcmp(debconf->value, "enter information manually");
        if (! manual_entry) {
-               /* Prompt for mirror in selected country. */
-               list=debconf_list(mirrors_in(debconf->value));
-               debconf->command(debconf, "SUBST", DEBCONF_BASE "http/mirror", 
"mirrors", list, NULL);
-               free(list);
-               debconf->command(debconf, "INPUT", "medium", DEBCONF_BASE 
"http/mirror", NULL);
+                /* Prompt for mirror in selected country. */
+               if (strcasecmp(protocol,"http") == 0) {
+                       list=debconf_list(mirrors_in(debconf->value));
+                       debconf->command(debconf, "SUBST", DEBCONF_BASE "http/mirror", 
+"mirrors", list, NULL);
+                       free(list);
+                       debconf->command(debconf, "INPUT", "medium", DEBCONF_BASE 
+"http/mirror", NULL);
+               } else {
+                       list=debconf_list(mirrors_in(debconf->value));
+                       debconf->command(debconf, "SUBST", DEBCONF_BASE "ftp/mirror", 
+"mirrors", list, NULL);
+                       free(list);
+                       debconf->command(debconf, "INPUT", "medium", DEBCONF_BASE 
+"ftp/mirror", NULL);
+
+               }
        }
        else {
                /* Manual entry. */
-               debconf->command(debconf, "INPUT", "critical", DEBCONF_BASE 
"http/hostname", NULL);
-               debconf->command(debconf, "INPUT", "critical", DEBCONF_BASE 
"http/directory", NULL);
+               if (strcasecmp(protocol,"http") == 0) {
+                       debconf->command(debconf, "INPUT", "critical", DEBCONF_BASE 
+"http/hostname", NULL);
+                 
+                       debconf->command(debconf, "INPUT", "critical", DEBCONF_BASE 
+"http/directory", NULL);
+               } else if (strcasecmp(protocol,"ftp") == 0) {
+                       debconf->command(debconf, "INPUT", "critical", DEBCONF_BASE 
+"ftp/hostname", NULL);
+                       debconf->command(debconf, "INPUT", "critical", DEBCONF_BASE 
+"ftp/directory", NULL);
+               }
        }
        /* Always ask about a proxy. */
+       if (strcasecmp(protocol,"http") == 0) {
+       
        debconf->command(debconf, "INPUT", "high", DEBCONF_BASE "http/proxy", NULL);
+       } else if (strcasecmp(protocol,"ftp") == 0) {
+               debconf->command(debconf, "INPUT", "high", DEBCONF_BASE "http/proxy", 
+NULL);
+       }
+       free(protocol);
+       return 0;
 }
 
-void validate_mirror(void) {
+int validate_mirror(void) {
        char *mirror;
+       char *protocol;
+
+       debconf->command(debconf, "GET", DEBCONF_BASE "protocol", NULL);
+       protocol = strdup(debconf->value);
 
        if (! manual_entry) {
                /*
@@ -94,19 +170,45 @@
                 * which is the standard location other
                 *tools can look at.
                 */
-               debconf->command(debconf, "GET", DEBCONF_BASE "http/mirror", NULL);
-               mirror=strdup(debconf->value);
-               debconf->command(debconf, "SET", DEBCONF_BASE "http/hostname", mirror, 
NULL);
-               debconf->command(debconf, "SET", DEBCONF_BASE "http/directory",
-                       mirror_root(mirror), NULL);
+               if (strcasecmp(protocol,"http") == 0) {
+                       debconf->command(debconf, "GET", DEBCONF_BASE "http/mirror", 
+NULL);
+                       mirror=strdup(debconf->value);
+                       debconf->command(debconf, "SET", DEBCONF_BASE "http/hostname", 
+mirror, NULL);
+                       debconf->command(debconf, "SET", DEBCONF_BASE "http/directory",
+                                        mirror_root(mirror), NULL);
+               } else {
+                       debconf->command(debconf, "GET", DEBCONF_BASE "ftp/mirror", 
+NULL);
+                       mirror=strdup(debconf->value);
+                       debconf->command(debconf, "SET", DEBCONF_BASE "ftp/hostname", 
+mirror, NULL);
+                       debconf->command(debconf, "SET", DEBCONF_BASE "ftp/directory",
+                                        mirror_root(mirror), NULL);
+               }
                free(mirror);
+               return 0;
+       } else {
+               int not_ok = 0; /* Is 0 if everything is ok, 1 else, aka retval */
+               /* Manual entry - check that the mirror is somewhat valid */
+               debconf->command(debconf, "GET", DEBCONF_BASE "http/hostname", NULL);  
+         
+               if (debconf->value == NULL || strcmp(debconf->value,"") == 0) {
+                       debconf->command(debconf, "fset", DEBCONF_BASE 
+"http/hostname", "seen", "false", NULL);
+                       not_ok = 1;
+               }
+               debconf->command(debconf, "GET", DEBCONF_BASE "http/directory", NULL); 
+         
+               if (debconf->value == NULL || strcmp(debconf->value,"") == 0) {
+                       debconf->command(debconf, "fset", DEBCONF_BASE 
+"http/directory", "seen", "false", NULL);
+                       not_ok = 1;
+               }
+               return not_ok;
        }
+       return 0;
 }
 
 int main (int argc, char **argv) {
        /* Use a state machine with a function to run in each state */
        int state = 0;
-       void (*states[])() = {
+       int ret;
+       int (*states[])() = {
+               choose_protocol,
                choose_country,
                choose_mirror,
                validate_mirror,
@@ -122,10 +224,10 @@
         * forward and back by one state always. Enough for our purposes.
         */
        while (state >= 0 && states[state]) {
-               states[state]();
-               if (debconf->command(debconf, "GO", NULL) == 0)
+               ret = states[state]();
+               if (ret == 0 && debconf->command(debconf, "GO", NULL) == 0) {
                        state++;
-               else
+               } else
                        state--; /* back up */
        }
 

I had to change the return types of choose_country, choose_mirror and
validate_mirror to int, in order to be able to actually validate, as I
saw no other way of returning wheter this is a sane and valid mirror
(really telling debconf to back up), without doing it that way.

Sorry about the length of this mail.

-- 

Tollef Fog Heen
Unix _IS_ user friendly... It's just selective about who its friends are.


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to