This removes the separate FTP and HTTP network method dialogs in the loader and replaces them with a single configuration dialog that asks the user to input a URL. It also modified the secondary config screen to prompt just for a proxy and simplifies a lot of the conversion from URL to UI and back. --- loader2/loader.c | 9 +- loader2/method.c | 2 +- loader2/method.h | 4 +- loader2/net.c | 10 +-- loader2/urlinstall.c | 78 ++---------------- loader2/urls.c | 223 ++++++++++++++++---------------------------------- loader2/urls.h | 5 +- 7 files changed, 88 insertions(+), 243 deletions(-) diff --git a/loader2/loader.c b/loader2/loader.c index ce00bd7..f376121 100644 --- a/loader2/loader.c +++ b/loader2/loader.c @@ -118,12 +118,11 @@ int post_link_sleep = 0; static struct installMethod installMethods[] = { #if !defined(__s390__) && !defined(__s390x__) - { N_("Local CD/DVD"), "cdrom", 0, CLASS_CDROM, mountCdromImage }, + { N_("Local CD/DVD"), 0, CLASS_CDROM, mountCdromImage }, #endif - { N_("Hard drive"), "hd", 0, CLASS_HD, mountHardDrive }, - { N_("NFS directory"), "nfs", 1, CLASS_NETWORK, mountNfsImage }, - { "FTP", "ftp", 1, CLASS_NETWORK, mountUrlImage }, - { "HTTP", "http", 1, CLASS_NETWORK, mountUrlImage }, + { N_("Hard drive"), 0, CLASS_HD, mountHardDrive }, + { N_("NFS directory"), 1, CLASS_NETWORK, mountNfsImage }, + { "URL", 1, CLASS_NETWORK, mountUrlImage }, }; static int numMethods = sizeof(installMethods) / sizeof(struct installMethod); diff --git a/loader2/method.c b/loader2/method.c index 13fd9f1..beb6ed4 100644 --- a/loader2/method.c +++ b/loader2/method.c @@ -674,7 +674,7 @@ void setMethodFromCmdline(char * arg, struct loaderData_s * ld) { } } else if (!strncmp(arg, "ftp:", 4) || !strncmp(arg, "http:", 5)) { - ld->method = strncmp(arg, "ftp", 3) ? METHOD_HTTP : METHOD_FTP; + ld->method = METHOD_URL; ld->methodData = calloc(sizeof(struct urlInstallData *), 1); ((struct urlInstallData *)ld->methodData)->url = strdup(arg); #if !defined(__s390__) && !defined(__s390x__) diff --git a/loader2/method.h b/loader2/method.h index bd9969a..112e725 100644 --- a/loader2/method.h +++ b/loader2/method.h @@ -13,13 +13,11 @@ enum { #endif METHOD_HD, METHOD_NFS, - METHOD_FTP, - METHOD_HTTP + METHOD_URL }; struct installMethod { char * name; - char * shortname; int network; enum deviceClass deviceType; /* for pcmcia */ char * (*mountImage)(struct installMethod * method, diff --git a/loader2/net.c b/loader2/net.c index 0f806e8..2cb94dd 100644 --- a/loader2/net.c +++ b/loader2/net.c @@ -56,11 +56,8 @@ extern uint64_t flags; char *netServerPrompt = \ - N_("Please enter the following information:\n" - "\n" - " o the name or IP number of your %s server\n" - " o the directory on that server containing\n" - " %s for your architecture\n"); + N_("Please enter the URL containing %s on your\n" + "server.\n"); /** * Callback function for the CIDR entry boxes on the manual TCP/IP @@ -1713,8 +1710,7 @@ void setKickstartNetwork(struct loaderData_s * loaderData, int argc, /* Make sure the network is always up if there's a network line in the * kickstart file, as %post/%pre scripts might require that. */ - if (loaderData->method != METHOD_NFS && loaderData->method != METHOD_FTP && - loaderData->method != METHOD_HTTP) { + if (loaderData->method != METHOD_NFS && loaderData->method != METHOD_URL) { initLoopback(); if (kickstartNetworkUp(loaderData, &cfg)) logMessage(ERROR, "unable to bring up network"); diff --git a/loader2/urlinstall.c b/loader2/urlinstall.c index f8bd3cc..d3940d1 100644 --- a/loader2/urlinstall.c +++ b/loader2/urlinstall.c @@ -168,55 +168,20 @@ static int loadUrlImages(struct iurlinfo * ui) { } -static char * getLoginName(char * login, struct iurlinfo ui) { - int i; - - i = 0; - /* password w/o login isn't useful */ - if (ui.login && strlen(ui.login)) { - i += strlen(ui.login) + 5; - if (strlen(ui.password)) - i += 3*strlen(ui.password) + 5; - - if (ui.login || ui.password) { - login = malloc(i); - strcpy(login, ui.login); - if (ui.password) { - char * chptr; - char code[4]; - - strcat(login, ":"); - for (chptr = ui.password; *chptr; chptr++) { - sprintf(code, "%%%2x", *chptr); - strcat(login, code); - } - strcat(login, "@"); - } - } - } - - return login; -} - char * mountUrlImage(struct installMethod * method, char * location, struct loaderData_s * loaderData, moduleInfoSet modInfo, moduleList modLoaded, moduleDeps * modDeps) { int rc; - char * url, *p; + char * url; struct iurlinfo ui; char needsSecondary = ' '; int dir = 1; - char * login; - char * finalPrefix; char * cdurl; enum { URL_STAGE_MAIN, URL_STAGE_SECOND, URL_STAGE_FETCH, URL_STAGE_DONE } stage = URL_STAGE_MAIN; - enum urlprotocol_t proto = - !strcmp(method->name, "FTP") ? URL_METHOD_FTP : URL_METHOD_HTTP; - /* JKFIXME: we used to do another ram check here... keep it? */ memset(&ui, 0, sizeof(ui)); @@ -224,12 +189,8 @@ char * mountUrlImage(struct installMethod * method, while (stage != URL_STAGE_DONE) { switch(stage) { case URL_STAGE_MAIN: - if ((loaderData->method == METHOD_FTP || - loaderData->method == METHOD_HTTP) && - loaderData->methodData) { - + if (loaderData->method == METHOD_URL && loaderData->methodData) { url = ((struct urlInstallData *)loaderData->methodData)->url; - logMessage(INFO, "URL_STAGE_MAIN - url is %s", url); if (!url) { @@ -237,7 +198,7 @@ char * mountUrlImage(struct installMethod * method, loaderData->method = -1; break; } - + /* explode url into ui struct */ convertURLToUI(url, &ui); @@ -245,7 +206,7 @@ char * mountUrlImage(struct installMethod * method, stage = URL_STAGE_FETCH; dir = 1; break; - } else if (urlMainSetupPanel(&ui, proto, &needsSecondary)) { + } else if (urlMainSetupPanel(&ui, &needsSecondary)) { return NULL; } @@ -256,7 +217,7 @@ char * mountUrlImage(struct installMethod * method, break; case URL_STAGE_SECOND: - rc = urlSecondarySetupPanel(&ui, proto); + rc = urlSecondarySetupPanel(&ui); if (rc) { stage = URL_STAGE_MAIN; dir = -1; @@ -322,28 +283,7 @@ char * mountUrlImage(struct installMethod * method, } } - login = ""; - login = getLoginName(login, ui); - - if (!strcmp(ui.prefix, "/")) - finalPrefix = "/."; - else - finalPrefix = ui.prefix; - - url = malloc(strlen(finalPrefix) + 25 + strlen(ui.address) + - strlen(login)); - - /* sanitize url so we dont have problems like bug #101265 */ - /* basically avoid duplicate /'s */ - if (ui.protocol == URL_METHOD_HTTP) { - for (p=finalPrefix; *p == '/'; p++); - finalPrefix = p; - } - - sprintf(url, "%s://%s%s/%s", - ui.protocol == URL_METHOD_FTP ? "ftp" : "http", - login, ui.address, finalPrefix); - + url = convertUIToURL(&ui); return url; } @@ -496,10 +436,8 @@ void setKickstartUrl(struct loaderData_s * loaderData, int argc, } /* determine install type */ - if (strstr(url, "http://")) - loaderData->method = METHOD_HTTP; - else if (strstr(url, "ftp://")) - loaderData->method = METHOD_FTP; + if (strstr(url, "http://") || strstr(url, "ftp://")) + loaderData->method = METHOD_URL; else { newtWinMessage(_("Kickstart Error"), _("OK"), _("Unknown Url method %s"), url); diff --git a/loader2/urls.c b/loader2/urls.c index 2be1df1..b692d2a 100644 --- a/loader2/urls.c +++ b/loader2/urls.c @@ -127,9 +127,7 @@ static char * getLoginName(char * login, struct iurlinfo *ui) { /* convert a UI to a URL, returns allocated string */ char *convertUIToURL(struct iurlinfo *ui) { - char * login; - char * finalPrefix; - char * url; + char *login, *finalPrefix, *url, *p; if (!strcmp(ui->prefix, "/")) finalPrefix = "/."; @@ -138,8 +136,16 @@ char *convertUIToURL(struct iurlinfo *ui) { login = ""; login = getLoginName(login, ui); - + url = malloc(strlen(finalPrefix) + 25 + strlen(ui->address) + strlen(login)); + + /* sanitize url so we dont have problems like bug #101265 */ + /* basically avoid duplicate /'s */ + if (ui->protocol == URL_METHOD_HTTP) { + for (p=finalPrefix; *p == '/'; p++); + finalPrefix = p; + } + sprintf(url, "%s://%s%s/%s", ui->protocol == URL_METHOD_FTP ? "ftp" : "http", login, ui->address, finalPrefix); @@ -261,142 +267,86 @@ char * addrToIp(char * hostname) { return NULL; } -int urlMainSetupPanel(struct iurlinfo * ui, urlprotocol protocol, - char * doSecondarySetup) { - newtComponent form, okay, cancel, siteEntry, dirEntry; - newtComponent answer, text; - newtComponent cb = NULL; - char * site, * dir; +int urlMainSetupPanel(struct iurlinfo * ui, char * doSecondarySetup) { + newtComponent form, okay, cancel, urlEntry; + newtComponent answer, text, proxyCheckbox; + char *url; char * reflowedText = NULL; int width, height; - newtGrid entryGrid, buttons, grid; + newtGrid buttons, grid; char * chptr; char * buf = NULL; int r; - if (ui->address) { - site = ui->address; - dir = ui->prefix; - } else { - site = ""; - dir = ""; - } - if (ui->login || ui->password || ui->proxy || ui->proxyPort) - *doSecondarySetup = '*'; + *doSecondarySetup = '*'; else - *doSecondarySetup = ' '; + *doSecondarySetup = ' '; + + /* Populate the UI with whatever initial value we've got. */ + url = convertUIToURL(ui); buttons = newtButtonBar(_("OK"), &okay, _("Back"), &cancel, NULL); - - switch (protocol) { - case URL_METHOD_FTP: - r = asprintf(&buf, _(netServerPrompt), _("FTP"), getProductName()); - reflowedText = newtReflowText(buf, 47, 5, 5, &width, &height); - free(buf); - break; - case URL_METHOD_HTTP: - r = asprintf(&buf, _(netServerPrompt), _("Web"), getProductName()); - reflowedText = newtReflowText(buf, 47, 5, 5, &width, &height); - free(buf); - break; - } + + r = asprintf(&buf, _(netServerPrompt), getProductName()); + reflowedText = newtReflowText(buf, 47, 5, 5, &width, &height); + free(buf); + text = newtTextbox(-1, -1, width, height, NEWT_TEXTBOX_WRAP); newtTextboxSetText(text, reflowedText); free(reflowedText); - siteEntry = newtEntry(22, 8, site, 24, (const char **) &site, - NEWT_ENTRY_SCROLL); - dirEntry = newtEntry(22, 9, dir, 24, (const char **) &dir, + urlEntry = newtEntry(22, 8, url, 24, (const char **) &url, NEWT_ENTRY_SCROLL); - - entryGrid = newtCreateGrid(2, 2); - newtGridSetField(entryGrid, 0, 0, NEWT_GRID_COMPONENT, - newtLabel(-1, -1, (protocol == URL_METHOD_FTP) ? - _("FTP site name:") : - _("Web site name:")), - 0, 0, 1, 0, NEWT_ANCHOR_LEFT, 0); - r = asprintf(&buf, _("%s directory:"), getProductName()); - newtGridSetField(entryGrid, 0, 1, NEWT_GRID_COMPONENT, - newtLabel(-1, -1, buf), - 0, 0, 1, 0, NEWT_ANCHOR_LEFT, 0); - newtGridSetField(entryGrid, 1, 0, NEWT_GRID_COMPONENT, siteEntry, - 0, 0, 0, 0, 0, 0); - newtGridSetField(entryGrid, 1, 1, NEWT_GRID_COMPONENT, dirEntry, - 0, 0, 0, 0, 0, 0); + proxyCheckbox = newtCheckbox(-1, -1, _("Configure proxy"), *doSecondarySetup, + NULL, doSecondarySetup); grid = newtCreateGrid(1, 4); newtGridSetField(grid, 0, 0, NEWT_GRID_COMPONENT, text, 0, 0, 0, 1, 0, 0); - newtGridSetField(grid, 0, 1, NEWT_GRID_SUBGRID, entryGrid, + newtGridSetField(grid, 0, 1, NEWT_GRID_SUBGRID, urlEntry, + 0, 0, 0, 1, 0, 0); + newtGridSetField(grid, 0, 2, NEWT_GRID_COMPONENT, proxyCheckbox, 0, 0, 0, 1, 0, 0); - - if (protocol == URL_METHOD_FTP) { - cb = newtCheckbox(3, 11, _("Use non-anonymous ftp"), - *doSecondarySetup, NULL, doSecondarySetup); - newtGridSetField(grid, 0, 2, NEWT_GRID_COMPONENT, cb, - 0, 0, 0, 1, NEWT_ANCHOR_LEFT, 0); - } - newtGridSetField(grid, 0, 3, NEWT_GRID_SUBGRID, buttons, 0, 0, 0, 0, 0, NEWT_GRID_FLAG_GROWX); - newtGridWrappedWindow(grid, (protocol == URL_METHOD_FTP) ? _("FTP Setup") : - _("HTTP Setup")); + newtGridWrappedWindow(grid, _("URL Setup")); form = newtForm(NULL, NULL, 0); - newtGridAddComponentsToForm(grid, form, 1); + newtGridAddComponentsToForm(grid, form, 1); do { answer = newtRunForm(form); if (answer != cancel) { - if (!strlen(site)) { + if (!strlen(url)) { newtWinMessage(_("Error"), _("OK"), - _("You must enter a server name.")); - continue; - } - if (!strlen(dir)) { - newtWinMessage(_("Error"), _("OK"), - _("You must enter a directory.")); + _("You must enter a URL.")); continue; } - if (!addrToIp(site)) { + /* Now split up the URL we were given into its components for + * ease of checking. + */ + convertURLToUI(url, ui); + + if (!addrToIp(ui->address)) { newtWinMessage(_("Unknown Host"), _("OK"), - _("%s is not a valid hostname."), site); + _("%s is not a valid hostname."), ui->address); continue; } } break; } while (1); - + free(buf); if (answer == cancel) { newtFormDestroy(form); newtPopWindow(); - - return LOADER_BACK; - } - /* if the user entered the protocol type, trim it */ - if (!strncmp(site, "http://", 7)) - site += 7; - else if (!strncmp(site, "ftp://", 6)) - site += 6; - - if (ui->address) free(ui->address); - r = asprintf(&ui->address, "%s", site); - - if (ui->prefix) free(ui->prefix); - - /* add a slash at the start of the dir if it is missing */ - if (*dir != '/') { - if (asprintf(&(ui->prefix), "/%s", dir) == -1) - ui->prefix = strdup(dir); - } else { - ui->prefix = strdup(dir); + return LOADER_BACK; } /* Get rid of trailing /'s */ @@ -406,18 +356,13 @@ int urlMainSetupPanel(struct iurlinfo * ui, urlprotocol protocol, *chptr = '\0'; if (*doSecondarySetup != '*') { - if (ui->login) - free(ui->login); - if (ui->password) - free(ui->password); if (ui->proxy) free(ui->proxy); if (ui->proxyPort) free(ui->proxyPort); - ui->login = ui->password = ui->proxy = ui->proxyPort = NULL; - } - ui->protocol = protocol; + ui->proxy = ui->proxyPort = NULL; + } newtFormDestroy(form); newtPopWindow(); @@ -425,56 +370,40 @@ int urlMainSetupPanel(struct iurlinfo * ui, urlprotocol protocol, return 0; } -int urlSecondarySetupPanel(struct iurlinfo * ui, urlprotocol protocol) { - newtComponent form, okay, cancel, answer, text, accountEntry = NULL; - newtComponent passwordEntry = NULL, proxyEntry = NULL; +int urlSecondarySetupPanel(struct iurlinfo * ui) { + newtComponent form, okay, cancel, answer, text; + newtComponent proxyEntry = NULL; newtComponent proxyPortEntry = NULL; - char * account, * password, * proxy, * proxyPort; + char * proxy, * proxyPort; newtGrid buttons, entryGrid, grid; char * reflowedText = NULL; int width, height; - if (protocol == URL_METHOD_FTP) { - reflowedText = newtReflowText( - _("If you are using non anonymous ftp, enter the account name and " - "password you wish to use below."), - 47, 5, 5, &width, &height); - } else { - reflowedText = newtReflowText( + reflowedText = newtReflowText( _("If you are using a HTTP proxy server " "enter the name of the HTTP proxy server to use."), 47, 5, 5, &width, &height); - } + text = newtTextbox(-1, -1, width, height, NEWT_TEXTBOX_WRAP); newtTextboxSetText(text, reflowedText); free(reflowedText); - if (protocol == URL_METHOD_FTP) { - accountEntry = newtEntry(-1, -1, NULL, 24, (const char **) &account, - NEWT_FLAG_SCROLL); - passwordEntry = newtEntry(-1, -1, NULL, 24, (const char **) &password, - NEWT_FLAG_SCROLL | NEWT_FLAG_PASSWORD); - } proxyEntry = newtEntry(-1, -1, ui->proxy, 24, (const char **) &proxy, NEWT_ENTRY_SCROLL); proxyPortEntry = newtEntry(-1, -1, ui->proxyPort, 6, (const char **) &proxyPort, NEWT_FLAG_SCROLL); - entryGrid = newtCreateGrid(2, 4); - if (protocol == URL_METHOD_FTP) { - newtGridSetField(entryGrid, 0, 0, NEWT_GRID_COMPONENT, - newtLabel(-1, -1, _("Account name:")), + entryGrid = newtCreateGrid(2, 2); + newtGridSetField(entryGrid, 0, 0, NEWT_GRID_COMPONENT, + newtLabel(-1, -1, _("Proxy Name:")), 0, 0, 2, 0, NEWT_ANCHOR_LEFT, 0); - newtGridSetField(entryGrid, 0, 1, NEWT_GRID_COMPONENT, - newtLabel(-1, -1, _("Password:")), + newtGridSetField(entryGrid, 1, 0, NEWT_GRID_COMPONENT, proxyEntry, + 0, 0, 0, 0, 0, 0); + newtGridSetField(entryGrid, 0, 1, NEWT_GRID_COMPONENT, + newtLabel(-1, -1, _("Proxy Port:")), 0, 0, 2, 0, NEWT_ANCHOR_LEFT, 0); - } - if (protocol == URL_METHOD_FTP) { - newtGridSetField(entryGrid, 1, 0, NEWT_GRID_COMPONENT, accountEntry, - 0, 0, 0, 0, 0, 0); - newtGridSetField(entryGrid, 1, 1, NEWT_GRID_COMPONENT, passwordEntry, - 0, 0, 0, 0, 0, 0); - } + newtGridSetField(entryGrid, 1, 1, NEWT_GRID_COMPONENT, proxyPortEntry, + 0, 0, 0, 0, 0, 0); buttons = newtButtonBar(_("OK"), &okay, _("Back"), &cancel, NULL); @@ -485,12 +414,7 @@ int urlSecondarySetupPanel(struct iurlinfo * ui, urlprotocol protocol) { newtGridSetField(grid, 0, 2, NEWT_GRID_SUBGRID, buttons, 0, 1, 0, 0, 0, NEWT_GRID_FLAG_GROWX); - if (protocol == URL_METHOD_FTP) { - newtGridWrappedWindow(grid, _("Further FTP Setup")); - } else { - if (protocol == URL_METHOD_HTTP) - newtGridWrappedWindow(grid, _("Further HTTP Setup")); - } + newtGridWrappedWindow(grid, _("Further Setup")); form = newtForm(NULL, NULL, 0); newtGridAddComponentsToForm(grid, form, 1); @@ -500,24 +424,15 @@ int urlSecondarySetupPanel(struct iurlinfo * ui, urlprotocol protocol) { if (answer == cancel) { newtFormDestroy(form); newtPopWindow(); - + return LOADER_BACK; } - - if (protocol == URL_METHOD_FTP) { - if (ui->login) free(ui->login); - if (strlen(account)) - ui->login = strdup(account); - else - ui->login = NULL; - - if (ui->password) free(ui->password); - if (strlen(password)) - ui->password = strdup(password); - else - ui->password = NULL; - } - + + if (strlen(proxy)) + ui->proxy = strdup(proxy); + if (strlen(proxyPort)) + ui->proxyPort = strdup(proxyPort); + newtFormDestroy(form); newtPopWindow(); diff --git a/loader2/urls.h b/loader2/urls.h index d6ead30..cef3559 100644 --- a/loader2/urls.h +++ b/loader2/urls.h @@ -19,9 +19,8 @@ int convertURLToUI(char *url, struct iurlinfo *ui); char *convertUIToURL(struct iurlinfo *ui); int setupRemote(struct iurlinfo * ui); -int urlMainSetupPanel(struct iurlinfo * ui, urlprotocol protocol, - char * doSecondarySetup); -int urlSecondarySetupPanel(struct iurlinfo * ui, urlprotocol protocol); +int urlMainSetupPanel(struct iurlinfo * ui, char * doSecondarySetup); +int urlSecondarySetupPanel(struct iurlinfo * ui); int urlinstStartTransfer(struct iurlinfo * ui, char * filename, char *extraHeaders); int urlinstFinishTransfer(struct iurlinfo * ui, int fd); -- 1.5.3.4 _______________________________________________ Anaconda-devel-list mailing list Anaconda-devel-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/anaconda-devel-list