mirror of
https://github.com/sheumann/NetDisk.git
synced 2024-11-27 19:49:38 +00:00
Switch to unified set of error codes. Also, do more checks for 2IMG files.
This commit is contained in:
parent
ccc9594412
commit
610a638e5c
42
driver.c
42
driver.c
@ -11,7 +11,7 @@
|
||||
#include "asmglue.h"
|
||||
#include "version.h"
|
||||
|
||||
#define TWO_IMG_MAGIC ('2' | 'I'<<8 | (LongWord)'M'<<16 | (LongWord)'G'<<24)
|
||||
#define BLOCK_SIZE 512
|
||||
|
||||
struct DIB dibs[NDIBS] = {0};
|
||||
struct DIBList dibList = {NDIBS};
|
||||
@ -192,20 +192,36 @@ Word DriverDispatch(Word callNum, struct GSOSDP *dp) {
|
||||
}
|
||||
#pragma databank 0
|
||||
|
||||
|
||||
static Word CheckTwoImg(Session *sess) {
|
||||
/*
|
||||
* Check for a 2IMG file, and process its header if one is found.
|
||||
* Returns a non-zero error code for an invalid or unsupported 2IMG file,
|
||||
* OPERATION_SUCCESSFUL otherwise (whether it's a 2IMG file or not).
|
||||
*/
|
||||
static enum NetDiskError CheckTwoImg(Session *sess) {
|
||||
struct TwoImgHeader *hdr = &sess->fileHeader.twoImgHeader;
|
||||
|
||||
/* Check if it's a 2IMG file */
|
||||
if (hdr->twoImgID != TWO_IMG_MAGIC)
|
||||
return 0;
|
||||
return OPERATION_SUCCESSFUL;
|
||||
|
||||
/* It's a 2IMG file, but is it one we can handle? */
|
||||
if (hdr->version > 1)
|
||||
return UNSUPPORTED_2IMG_FILE;
|
||||
if (hdr->imgFormat != IMAGE_FORMAT_PRODOS_ORDER)
|
||||
return UNSUPPORTED_2IMG_FILE;
|
||||
if (hdr->dataLength % BLOCK_SIZE != 0)
|
||||
return UNSUPPORTED_2IMG_FILE;
|
||||
|
||||
// TODO more checks
|
||||
|
||||
sess->dataOffset = hdr->dataOffset;
|
||||
|
||||
return 0;
|
||||
return OPERATION_SUCCESSFUL;
|
||||
}
|
||||
|
||||
static Word DoMountURL(struct GSOSDP *dp) {
|
||||
enum NetDiskError err;
|
||||
|
||||
if (dp->dibPointer->extendedDIBPtr != NULL) {
|
||||
dp->transferCount = 0;
|
||||
return drvrBusy;
|
||||
@ -217,16 +233,16 @@ static Word DoMountURL(struct GSOSDP *dp) {
|
||||
return drvrNoResrc;
|
||||
}
|
||||
|
||||
enum SetURLResult setResult = SetURL(sess, (char*)dp->controlListPtr, TRUE, FALSE);
|
||||
if (setResult != SETURL_SUCCESSFUL) {
|
||||
err = SetURL(sess, (char*)dp->controlListPtr, TRUE, FALSE);
|
||||
if (err != OPERATION_SUCCESSFUL) {
|
||||
// TODO arrange for more detailed error reporting
|
||||
EndNetDiskSession(sess);
|
||||
dp->transferCount = 0;
|
||||
return drvrIOError;
|
||||
}
|
||||
|
||||
enum RequestResult requestResult = DoHTTPRequest(sess, 0, sizeof(sess->fileHeader) - 1);
|
||||
if (requestResult != REQUEST_SUCCESSFUL) {
|
||||
err = DoHTTPRequest(sess, 0, sizeof(sess->fileHeader) - 1);
|
||||
if (err != OPERATION_SUCCESSFUL) {
|
||||
// TODO arrange for more detailed error reporting
|
||||
EndNetDiskSession(sess);
|
||||
dp->transferCount = 0;
|
||||
@ -239,8 +255,8 @@ static Word DoMountURL(struct GSOSDP *dp) {
|
||||
/* keep reading */ ;
|
||||
//TODO detect errors
|
||||
|
||||
Word checkResult = CheckTwoImg(sess);
|
||||
if (checkResult != 0) {
|
||||
err = CheckTwoImg(sess);
|
||||
if (err != OPERATION_SUCCESSFUL) {
|
||||
EndNetDiskSession(sess);
|
||||
// TODO error
|
||||
}
|
||||
@ -265,8 +281,8 @@ static Word DoRead(struct GSOSDP *dp) {
|
||||
unsigned long readStart = dp->blockNum * dp->blockSize + sess->dataOffset;
|
||||
unsigned long readEnd = readStart + dp->requestCount - 1;
|
||||
|
||||
enum RequestResult requestResult = DoHTTPRequest(sess, readStart, readEnd);
|
||||
if (requestResult != REQUEST_SUCCESSFUL) {
|
||||
enum NetDiskError err = DoHTTPRequest(sess, readStart, readEnd);
|
||||
if (err != OPERATION_SUCCESSFUL) {
|
||||
// TODO arrange for more detailed error reporting
|
||||
dp->transferCount = 0;
|
||||
return drvrIOError;
|
||||
|
8
http.c
8
http.c
@ -90,13 +90,13 @@ Boolean BuildHTTPRequest(Session *sess, char *resourceStr) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
enum RequestResult
|
||||
enum NetDiskError
|
||||
DoHTTPRequest(Session *sess, unsigned long start, unsigned long end) {
|
||||
top:;
|
||||
rlrBuff rlrBuff = {0};
|
||||
Word tcpError;
|
||||
Boolean wantRedirect = FALSE, gotRedirect = FALSE;
|
||||
enum RequestResult result;
|
||||
enum NetDiskError result;
|
||||
|
||||
UpdateRequestRange(sess, start, end);
|
||||
|
||||
@ -300,7 +300,7 @@ netRetry:
|
||||
goto errorReturn;
|
||||
if (wantRedirect) {
|
||||
*endPtr = '\0';
|
||||
if (SetURL(sess, response, FALSE, TRUE) != SETURL_SUCCESSFUL) {
|
||||
if (SetURL(sess, response, FALSE, TRUE) != OPERATION_SUCCESSFUL) {
|
||||
result = REDIRECT_ERROR;
|
||||
goto errorReturn;
|
||||
}
|
||||
@ -354,7 +354,7 @@ netRetry:
|
||||
&& sess->contentLength != (sess->desiredEnd - sess->desiredStart + 1))
|
||||
goto errorReturn;
|
||||
|
||||
result = REQUEST_SUCCESSFUL;
|
||||
result = OPERATION_SUCCESSFUL;
|
||||
DisposeHandle(rlrBuff.rlrBuffHandle);
|
||||
return result;
|
||||
|
||||
|
16
http.h
16
http.h
@ -3,21 +3,9 @@
|
||||
|
||||
#include <types.h>
|
||||
#include "session.h"
|
||||
|
||||
enum RequestResult {
|
||||
REQUEST_SUCCESSFUL = 0,
|
||||
NETWORK_ERROR,
|
||||
NO_RESPONSE,
|
||||
INVALID_RESPONSE,
|
||||
EXCESSIVE_REDIRECTS,
|
||||
UNSUPPORTED_RESPONSE,
|
||||
UNSUPPORTED_HEADER_VALUE,
|
||||
REDIRECT_ERROR,
|
||||
NOT_DESIRED_CONTENT,
|
||||
DIFFERENT_LENGTH, /* Might be considered successful later */
|
||||
};
|
||||
#include "netdiskerror.h"
|
||||
|
||||
Boolean BuildHTTPRequest(Session *sess, char *resourceStr);
|
||||
enum RequestResult DoHTTPRequest(Session *sess, unsigned long start, unsigned long end);
|
||||
enum NetDiskError DoHTTPRequest(Session *sess, unsigned long start, unsigned long end);
|
||||
|
||||
#endif
|
10
httptest.c
10
httptest.c
@ -39,9 +39,9 @@ int main(int argc, char **argv) {
|
||||
|
||||
char *url = (argc > 1) ? argv[1] : defaultURL;
|
||||
|
||||
enum SetURLResult result = SetURL(&sess, url, TRUE, FALSE);
|
||||
enum NetDiskError result = SetURL(&sess, url, TRUE, FALSE);
|
||||
|
||||
if (result != SETURL_SUCCESSFUL) {
|
||||
if (result != OPERATION_SUCCESSFUL) {
|
||||
printf("SetURL error %i\n", (int)result);
|
||||
goto exit;
|
||||
}
|
||||
@ -62,12 +62,12 @@ int main(int argc, char **argv) {
|
||||
printf("=========\n");
|
||||
printf("\n");
|
||||
|
||||
enum RequestResult requestResult;
|
||||
enum NetDiskError requestResult;
|
||||
requestResult = DoHTTPRequest(&sess, startByte, startByte + 511);
|
||||
printf("RequestResult %i\n", requestResult);
|
||||
printf("Response code %lu\n", sess.responseCode);
|
||||
|
||||
if (requestResult == REQUEST_SUCCESSFUL) {
|
||||
if (requestResult == OPERATION_SUCCESSFUL) {
|
||||
printf("rangeStart = %lu\n", sess.rangeStart);
|
||||
printf("rangeEnd = %lu\n", sess.rangeEnd);
|
||||
printf("totalLength = %lu\n", sess.totalLength);
|
||||
@ -87,7 +87,7 @@ int main(int argc, char **argv) {
|
||||
printf("RequestResult %i\n", requestResult);
|
||||
printf("Response code %lu\n", sess.responseCode);
|
||||
|
||||
if (requestResult == REQUEST_SUCCESSFUL) {
|
||||
if (requestResult == OPERATION_SUCCESSFUL) {
|
||||
printf("rangeStart = %lu\n", sess.rangeStart);
|
||||
printf("rangeEnd = %lu\n", sess.rangeEnd);
|
||||
printf("totalLength = %lu\n", sess.totalLength);
|
||||
|
37
netdiskerror.h
Normal file
37
netdiskerror.h
Normal file
@ -0,0 +1,37 @@
|
||||
#ifndef NETDISKERROR_H
|
||||
#define NETDISKERROR_H
|
||||
|
||||
enum NetDiskError {
|
||||
OPERATION_SUCCESSFUL = 0,
|
||||
|
||||
/* SetURL errors */
|
||||
URL_TOO_LONG = 100,
|
||||
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,
|
||||
OUT_OF_MEMORY,
|
||||
|
||||
/* StartTCPConnection and DoHTTPRequest errors */
|
||||
NETWORK_ERROR = 200,
|
||||
NO_RESPONSE,
|
||||
INVALID_RESPONSE,
|
||||
EXCESSIVE_REDIRECTS,
|
||||
UNSUPPORTED_RESPONSE,
|
||||
UNSUPPORTED_HEADER_VALUE,
|
||||
REDIRECT_ERROR,
|
||||
NOT_DESIRED_CONTENT,
|
||||
DIFFERENT_LENGTH, /* Might be considered successful later */
|
||||
|
||||
/* File format errors */
|
||||
UNSUPPORTED_2IMG_FILE = 300,
|
||||
|
||||
};
|
||||
|
||||
#endif
|
13
session.h
13
session.h
@ -2,18 +2,7 @@
|
||||
#define SESSION_H
|
||||
|
||||
#include <types.h>
|
||||
|
||||
struct TwoImgHeader {
|
||||
LongWord twoImgID;
|
||||
LongWord appTag;
|
||||
Word headerLength;
|
||||
Word version;
|
||||
LongWord imgFormat;
|
||||
LongWord flag;
|
||||
LongWord nBlocks;
|
||||
LongWord dataOffset;
|
||||
LongWord dataLength;
|
||||
};
|
||||
#include "twoimg.h"
|
||||
|
||||
typedef struct Session {
|
||||
/* Marinetti TCP connection status */
|
||||
|
4
seturl.c
4
seturl.c
@ -18,7 +18,7 @@
|
||||
#define MAX_URL_LENGTH 30000
|
||||
|
||||
|
||||
enum SetURLResult
|
||||
enum NetDiskError
|
||||
SetURL(Session *sess, char *url, Boolean permissive, Boolean partialOK) {
|
||||
if (strlen(url) > MAX_URL_LENGTH) {
|
||||
return URL_TOO_LONG;
|
||||
@ -95,5 +95,5 @@ SetURL(Session *sess, char *url, Boolean permissive, Boolean partialOK) {
|
||||
/* End any existing TCP connection to old URL */
|
||||
EndTCPConnection(sess);
|
||||
|
||||
return SETURL_SUCCESSFUL;
|
||||
return OPERATION_SUCCESSFUL;
|
||||
}
|
||||
|
18
seturl.h
18
seturl.h
@ -1,23 +1,9 @@
|
||||
#ifndef SETURL_H
|
||||
#define SETURL_H
|
||||
|
||||
enum SetURLResult {
|
||||
SETURL_SUCCESSFUL = 0,
|
||||
URL_TOO_LONG,
|
||||
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,
|
||||
OUT_OF_MEMORY
|
||||
};
|
||||
#include "netdiskerror.h"
|
||||
|
||||
enum SetURLResult
|
||||
enum NetDiskError
|
||||
SetURL(Session *sess, char *url, Boolean permissive, Boolean partialOK);
|
||||
|
||||
#endif
|
||||
|
@ -15,7 +15,7 @@
|
||||
* On success, returns 0 and sets sess->ipid.
|
||||
* On failure, returns an error code.
|
||||
*/
|
||||
Word StartTCPConnection(Session *sess) {
|
||||
enum NetDiskError StartTCPConnection(Session *sess) {
|
||||
Word tcperr;
|
||||
srBuff mySRBuff;
|
||||
LongWord initialTime;
|
||||
@ -26,15 +26,15 @@ Word StartTCPConnection(Session *sess) {
|
||||
sess->ipid =
|
||||
TCPIPLogin(userid(), sess->ipAddr, sess->port, 0, 0x40);
|
||||
if (toolerror())
|
||||
return NETWORK_ERR;
|
||||
return NETWORK_ERROR;
|
||||
|
||||
tcperr = TCPIPOpenTCP(sess->ipid);
|
||||
if (toolerror()) {
|
||||
TCPIPLogout(sess->ipid);
|
||||
return NETWORK_ERR;
|
||||
return NETWORK_ERROR;
|
||||
} else if (tcperr != tcperrOK) {
|
||||
TCPIPLogout(sess->ipid);
|
||||
return NO_RESP_ERR;
|
||||
return NO_RESPONSE;
|
||||
}
|
||||
|
||||
initialTime = GetTick();
|
||||
@ -45,7 +45,7 @@ Word StartTCPConnection(Session *sess) {
|
||||
if (mySRBuff.srState != TCPSESTABLISHED) {
|
||||
TCPIPAbortTCP(sess->ipid);
|
||||
TCPIPLogout(sess->ipid);
|
||||
return NO_RESP_ERR;
|
||||
return NO_RESPONSE;
|
||||
}
|
||||
|
||||
sess->tcpLoggedIn = TRUE;
|
||||
|
@ -2,8 +2,9 @@
|
||||
#define TCPCONNECTION_H
|
||||
|
||||
#include "session.h"
|
||||
#include "netdiskerror.h"
|
||||
|
||||
Word StartTCPConnection(Session *sess);
|
||||
enum NetDiskError StartTCPConnection(Session *sess);
|
||||
void EndTCPConnection(Session *sess);
|
||||
|
||||
#endif
|
||||
|
23
twoimg.h
Normal file
23
twoimg.h
Normal file
@ -0,0 +1,23 @@
|
||||
#ifndef TWOIMG_H
|
||||
#define TWOIMG_H
|
||||
|
||||
#define TWO_IMG_MAGIC ('2' | 'I'<<8 | (LongWord)'M'<<16 | (LongWord)'G'<<24)
|
||||
|
||||
#define IMAGE_FORMAT_DOS_33_ORDER 0
|
||||
#define IMAGE_FORMAT_PRODOS_ORDER 1
|
||||
#define IMAGE_FORMAT_NIBBLIZED 2
|
||||
|
||||
struct TwoImgHeader {
|
||||
LongWord twoImgID;
|
||||
LongWord appTag;
|
||||
Word headerLength;
|
||||
Word version;
|
||||
LongWord imgFormat;
|
||||
LongWord flag;
|
||||
LongWord nBlocks;
|
||||
LongWord dataOffset;
|
||||
LongWord dataLength;
|
||||
/* Remaining header fields are unimportant for us */
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user