From 8b09d6bb7df75acc9d4bbe15295236777183a363 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Sun, 12 Aug 2018 18:45:08 -0500 Subject: [PATCH] Switch to using a struct for the MountURL DControl call. This allows us to return a better error code and provides for future extensibility. --- driver.c | 19 ++++++++++++++++--- http.c | 6 +++++- mounturl.c | 16 ++++++++++++---- mounturl.h | 15 +++++++++++++++ netdiskerror.h | 13 +++++++++---- 5 files changed, 57 insertions(+), 12 deletions(-) create mode 100644 mounturl.h diff --git a/driver.c b/driver.c index 6ee63e8..8aa636a 100644 --- a/driver.c +++ b/driver.c @@ -9,6 +9,7 @@ #include "readtcp.h" #include "tcpconnection.h" #include "asmglue.h" +#include "mounturl.h" #include "version.h" #define BLOCK_SIZE 512 @@ -221,23 +222,33 @@ static enum NetDiskError CheckTwoImg(Session *sess) { static Word DoMountURL(struct GSOSDP *dp) { enum NetDiskError err; + struct MountURLRec *mountURLRec = (struct MountURLRec *)dp->controlListPtr; + + if (mountURLRec->byteCount != sizeof(struct MountURLRec) + || mountURLRec->byteCount != dp->requestCount) + { + dp->transferCount = 0; + return drvrBadParm; + } if (dp->dibPointer->extendedDIBPtr != NULL) { dp->transferCount = 0; + mountURLRec->result = DISK_ALREADY_MOUNTED; return drvrBusy; } Session *sess = calloc(sizeof(*sess), 1); if (sess == NULL) { dp->transferCount = 0; + mountURLRec->result = OUT_OF_MEMORY; return drvrNoResrc; } - err = SetURL(sess, (char*)dp->controlListPtr, TRUE, FALSE); + err = SetURL(sess, mountURLRec->url, TRUE, FALSE); if (err != OPERATION_SUCCESSFUL) { - // TODO arrange for more detailed error reporting EndNetDiskSession(sess); dp->transferCount = 0; + mountURLRec->result = err; return drvrIOError; } @@ -246,6 +257,7 @@ static Word DoMountURL(struct GSOSDP *dp) { // TODO arrange for more detailed error reporting EndNetDiskSession(sess); dp->transferCount = 0; + mountURLRec->result = err; return drvrIOError; } @@ -258,8 +270,8 @@ static Word DoMountURL(struct GSOSDP *dp) { err = CheckTwoImg(sess); if (err != OPERATION_SUCCESSFUL) { EndNetDiskSession(sess); - // TODO better error dp->transferCount = 0; + mountURLRec->result = err; return drvrIOError; } @@ -267,6 +279,7 @@ static Word DoMountURL(struct GSOSDP *dp) { //TODO report disk switch + mountURLRec->result = OPERATION_SUCCESSFUL; return 0; } diff --git a/http.c b/http.c index 83c86e9..1cbaea3 100644 --- a/http.c +++ b/http.c @@ -206,7 +206,11 @@ netRetry: } default: - result = UNSUPPORTED_RESPONSE; + if (sess->responseCode < 400 || sess->responseCode > 599) { + result = UNSUPPORTED_RESPONSE; + } else { + result = sess->responseCode; + } goto errorReturn; } diff --git a/mounturl.c b/mounturl.c index d8da55e..c799a4c 100644 --- a/mounturl.c +++ b/mounturl.c @@ -1,19 +1,27 @@ #include #include +#include #include - -#define MountURL 0x8080 +#include "mounturl.h" int main(int argc, char **argv) { + struct MountURLRec mountURLRec; DAccessRecGS controlRec = {5}; if (argc < 3) return; + mountURLRec.byteCount = sizeof(mountURLRec); + mountURLRec.url = argv[2]; + controlRec.devNum = strtoul(argv[1], NULL, 0); controlRec.code = MountURL; - controlRec.list = argv[2]; - controlRec.requestCount = strlen(argv[2]) + 1; + controlRec.list = (Pointer)&mountURLRec; + controlRec.requestCount = sizeof(mountURLRec); DControl(&controlRec); + + if (mountURLRec.result != OPERATION_SUCCESSFUL) { + fprintf(stderr, "MountURL error %u\n", mountURLRec.result); + } } diff --git a/mounturl.h b/mounturl.h new file mode 100644 index 0000000..3a3feaa --- /dev/null +++ b/mounturl.h @@ -0,0 +1,15 @@ +#ifndef MOUNTURL_H +#define MOUNTURL_H + +#include "netdiskerror.h" + +/* Custom DControl code and request code for MountURL operation */ +#define MountURL 0x8080 + +struct MountURLRec { + Word byteCount; + enum NetDiskError result; /* output value */ + char *url; /* C-string; will be modified */ +}; + +#endif diff --git a/netdiskerror.h b/netdiskerror.h index 282b7c0..54315d3 100644 --- a/netdiskerror.h +++ b/netdiskerror.h @@ -3,9 +3,12 @@ enum NetDiskError { OPERATION_SUCCESSFUL = 0, + + DISK_ALREADY_MOUNTED = 100, + OUT_OF_MEMORY, /* SetURL errors */ - URL_TOO_LONG = 100, + URL_TOO_LONG = 200, INVALID_CHARACTER_IN_URL, BAD_URL_SYNTAX, UNSUPPORTED_URL_SCHEME, @@ -16,10 +19,9 @@ enum NetDiskError { IPV6_NOT_SUPPORTED, HOSTNAME_TOO_LONG, NAME_LOOKUP_FAILED, - OUT_OF_MEMORY, /* StartTCPConnection and DoHTTPRequest errors */ - NETWORK_ERROR = 200, + NETWORK_ERROR = 300, NO_RESPONSE, INVALID_RESPONSE, EXCESSIVE_REDIRECTS, @@ -29,8 +31,11 @@ enum NetDiskError { NOT_DESIRED_CONTENT, DIFFERENT_LENGTH, /* Might be considered successful later */ + /* Error values of 4xx and 5xx mean we got the corresponding HTTP error */ + HTTP_ERROR = 400, + /* File format errors */ - UNSUPPORTED_2IMG_FILE = 300, + UNSUPPORTED_2IMG_FILE = 600, };