Switch to using a struct for the MountURL DControl call.

This allows us to return a better error code and provides for future extensibility.
This commit is contained in:
Stephen Heumann 2018-08-12 18:45:08 -05:00
parent 8fe8bbdf7e
commit 8b09d6bb7d
5 changed files with 57 additions and 12 deletions

View File

@ -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;
}

6
http.c
View File

@ -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;
}

View File

@ -1,19 +1,27 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <gsos.h>
#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);
}
}

15
mounturl.h Normal file
View File

@ -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

View File

@ -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,
};