From 28fd51d1752fbbfa4fe6d5aa3e624a517ca9afe5 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Sun, 30 Sep 2018 22:47:43 -0500 Subject: [PATCH] If the URL specifies HTTPS or FTP, offer to use HTTP instead. --- Makefile | 2 +- cdev.c | 32 +++++++++++++++++++++++++++++--- cdev.rez | 10 ++++++++++ 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 1763b5a..e565188 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ NETDISKINIT_OBJS = initstart.a netdiskinit.a hostname.a http.a readtcp.a seturl. # NETDISKINIT_RSRC = NETDISKINIT_PROG = NetDiskInit -NETDISKCDEV_OBJS = cdev.a cdevutil.a netdiskerror.a +NETDISKCDEV_OBJS = cdev.a cdevutil.a netdiskerror.a strcasecmp.a NETDISKCDEV_RSRC = cdev.rez NETDISKCDEV_CDEV = NetDisk diff --git a/cdev.c b/cdev.c index 43d5e42..bc4047b 100644 --- a/cdev.c +++ b/cdev.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -14,6 +15,7 @@ #include #include #include "mounturl.h" +#include "strcasecmp.h" #define MachineCDEV 1 #define BootCDEV 2 @@ -35,6 +37,8 @@ #define netDiskMissingError 3000 #define mountURLError 3001 +#define unsupportedProtocolAlert 3002 +#define yesBtn 1 /* number of "Yes" button in alert */ extern void FreeAllCDevMem(void); @@ -49,15 +53,36 @@ void DoMount(void) char numStr[6] = ""; char *subs[1] = {numStr}; static char alertString[200]; - - WaitCursor(); + enum {HTTPS, FTP, OTHER_PROTOCOL} protocol = OTHER_PROTOCOL; GetLETextByID(wPtr, urlLine, (StringPtr)&urlBuf); + if (strncasecmp(urlBuf+1, "https://", 8) == 0) { + protocol = HTTPS; + subs[0] = "HTTPS"; + strncpy(urlBuf+2, "http", 4); + mountURLRec.url = urlBuf + 2; + } else if (strncasecmp(urlBuf+1, "ftp://", 6) == 0) { + protocol = FTP; + subs[0] = "FTP"; + strncpy(urlBuf, "http", 4); + mountURLRec.url = urlBuf; + } else { + protocol = OTHER_PROTOCOL; + mountURLRec.url = urlBuf + 1; + } + + if (protocol == HTTPS || protocol == FTP) { + if (AlertWindow(awResource+awCString+awButtonLayout, + (Pointer)subs, unsupportedProtocolAlert) != yesBtn) { + return; + } + } + + WaitCursor(); TCPIPConnect(NULL); mountURLRec.result = NETDISK_NOT_PRESENT; - mountURLRec.url = urlBuf + 1; SendRequest(MountURL, sendToName|stopAfterOne, (Long)NETDISK_REQUEST_NAME, (Long)&mountURLRec, NULL); @@ -68,6 +93,7 @@ void DoMount(void) snprintf(numStr, sizeof(numStr), "%u", mountURLRec.result); snprintf(alertString, sizeof(alertString), "42~%.175s~^#0\0", ErrorString(mountURLRec.result)); + subs[0] = numStr; AlertWindow(awPointer+awCString+awButtonLayout, (Pointer)subs, (Ref)alertString); diff --git a/cdev.rez b/cdev.rez index cbd2acc..0841cbf 100644 --- a/cdev.rez +++ b/cdev.rez @@ -262,6 +262,7 @@ resource rTextForLETextBox2 (helpWindow+helpTxt) { #define netDiskMissingError 3000 #define mountURLError 3001 +#define unsupportedProtocolAlert 3002 resource rAlertString (netDiskMissingError) { "62/" @@ -275,3 +276,12 @@ resource rAlertString (mountURLError) { "MountURL error *0." ":^#0\$00" }; + +resource rAlertString (unsupportedProtocolAlert) { + "64:" + "NetDisk does not support the *0 protocol. Do you want to try " + "connecting using unencrypted HTTP instead? (The server may " + "or may not support this.)" + ":#3:^#2\$00" +}; +