From 8c7ef2e3318f7816ea98ffe6f2cf7a8213a536d8 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Fri, 12 Apr 2019 19:38:46 -0500 Subject: [PATCH] Check for presence of NetDisk and Marinetti, and bail out if they're missing. --- diskbrowser.c | 24 +++++++++++++++++++++++ mounturl.h | 31 +++++++++++++++++++++++++++++ netdiskerror.h | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 mounturl.h create mode 100644 netdiskerror.h diff --git a/diskbrowser.c b/diskbrowser.c index 3b60413..fb0fbcd 100644 --- a/diskbrowser.c +++ b/diskbrowser.c @@ -14,6 +14,8 @@ #include #include #include +#include +#include "mounturl.h" static char menuTitle[] = "\pArchive.org Disk Browser\xC9"; static char windowTitle[] = "\p Archive.org Disk Browser "; @@ -59,6 +61,8 @@ struct diskListEntry { struct diskListEntry diskList[DISK_LIST_LENGTH]; +static struct MountURLRec mountURLRec = {sizeof(struct MountURLRec)}; + /* Record about our system window, to support processing by Desk Manager. */ /* See Prog. Ref. for System 6.0, page 20. */ static NDASysWindRecord sysWindRecord; @@ -365,6 +369,21 @@ static pascal Word requestProc(Word reqCode, Long dataIn, void *dataOut) { #pragma toolparms 0 #pragma databank 0 +boolean NetDiskPresent(void) +{ + mountURLRec.result = NETDISK_NOT_PRESENT; + mountURLRec.url = ""; + mountURLRec.flags = flgUseCache; + + SendRequest(MountURL, sendToName|stopAfterOne, (Long)NETDISK_REQUEST_NAME, + (Long)&mountURLRec, NULL); + + if (mountURLRec.result == NETDISK_NOT_PRESENT) { + return false; + } + + return true; +} int main(void) { myUserID = MMStartUp(); //userid() & 0xF0FF; @@ -373,5 +392,10 @@ int main(void) { ResourceStartUp(myUserID); SetCurResourceApp(origResourceApp); + /* Bail out if NetDisk or Marinetti is not present */ + if (!NetDiskPresent() || !TCPIPStatus() || toolerror()) { + return 1; + } + AcceptRequests(diskbrowserRequestName, myUserID, &requestProc); } diff --git a/mounturl.h b/mounturl.h new file mode 100644 index 0000000..53b7bce --- /dev/null +++ b/mounturl.h @@ -0,0 +1,31 @@ +#ifndef MOUNTURL_H +#define MOUNTURL_H + +#include "netdiskerror.h" + +/* Custom DControl code and request code for MountURL operation */ +#define MountURL 0x8080 + +#define NETDISK_REQUEST_NAME "\pSTH~NetDisk~" + +/* Bits in flags */ +#define flgUseCache 0x0001 + +enum DiskImageFormat { + formatAutoDetect = 0, + format2mg, + formatRaw, + formatDOSOrder, + formatDiskCopy42 +}; + +struct MountURLRec { + Word byteCount; + enum NetDiskError result; /* output value */ + char *url; /* C-string; will be modified */ + Word flags; + enum DiskImageFormat format; /* input/output value */ + Word devNum; /* output value: device number */ +}; + +#endif diff --git a/netdiskerror.h b/netdiskerror.h new file mode 100644 index 0000000..dcaa521 --- /dev/null +++ b/netdiskerror.h @@ -0,0 +1,53 @@ +#ifndef NETDISKERROR_H +#define NETDISKERROR_H + +enum NetDiskError { + OPERATION_SUCCESSFUL = 0, + + NETDISK_NOT_PRESENT = 100, + DISK_ALREADY_MOUNTED, + NO_DIBS_AVAILABLE, + OUT_OF_MEMORY, + + /* SetURL errors */ + URL_TOO_LONG = 200, + INVALID_CHARACTER_IN_URL, + BAD_URL_SYNTAX, + UNSUPPORTED_URL_SCHEME, + AUTHENTICATION_NOT_SUPPORTED, + FRAGMENT_NOT_SUPPORTED, + INVALID_PORT_NUMBER, + NO_HOST_SPECIFIED, + IPV6_NOT_SUPPORTED, + HOSTNAME_TOO_LONG, + NAME_LOOKUP_FAILED, + + /* StartTCPConnection and DoHTTPRequest errors */ + NETWORK_ERROR = 300, + NO_RESPONSE, + INVALID_RESPONSE, + EXCESSIVE_REDIRECTS, + UNSUPPORTED_RESPONSE, + UNSUPPORTED_HEADER_VALUE, + REDIRECT_ERROR, + NOT_DESIRED_CONTENT, + DIFFERENT_LENGTH, + + /* Error values of 4xx and 5xx mean we got the corresponding HTTP error */ + HTTP_ERROR = 400, + + /* File format errors */ + UNSUPPORTED_2IMG_FILE = 600, + NOT_MULTIPLE_OF_BLOCK_SIZE, + NOT_SPECIFIED_IMAGE_TYPE + +}; + + +/* + * Return a string describing the error. It may contain the substitution + * string "*0", which should be replaced by the error number. + */ +char *ErrorString(enum NetDiskError err); + +#endif