From 695f2d861170f2b134c28eaa36a69d2f8234dcd5 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Fri, 14 Apr 2017 22:16:55 -0500 Subject: [PATCH] Implement infrastructure (in init and CDev) to support options encoded in the zone name. --- Makefile.mk | 6 +++--- afpcdev.c | 18 +++++++++++------- afpoptions.c | 13 +++++++++++++ afpoptions.h | 14 ++++++++++++++ afpurlparser.c | 13 +------------ atipmapping.c | 27 ++++++++++++++++++++------- atipmapping.h | 3 +++ strncasecmp.c | 20 ++++++++++++++++++++ strncasecmp.h | 6 ++++++ 9 files changed, 91 insertions(+), 29 deletions(-) create mode 100644 afpoptions.c create mode 100644 afpoptions.h create mode 100644 strncasecmp.c create mode 100644 strncasecmp.h diff --git a/Makefile.mk b/Makefile.mk index 23ef4ba..932111a 100644 --- a/Makefile.mk +++ b/Makefile.mk @@ -4,7 +4,7 @@ COMMAND = $(!eq,$(CMNDNAME),$(CC) $(CMNDNAME) $(USEORCALIBS)&&$(CC)) $(CMNDARGS) CFLAGS = -i -w -O95 -DSITEST_OBJS = dsitest.o aspinterface.o dsi.o readtcp.o endian.o tcpconnection.o atipmapping.o asmglue.o cmdproc.o installcmds.o +DSITEST_OBJS = dsitest.o aspinterface.o dsi.o readtcp.o endian.o tcpconnection.o atipmapping.o asmglue.o cmdproc.o installcmds.o afpoptions.o strncasecmp.o DSITEST_PROG = dsitest MOUNTAFP_OBJS = afpmounter.o callat.o endian.o @@ -13,10 +13,10 @@ MOUNTAFP_PROG = mountafp DUMPCMDTBL_OBJS = dumpcmdtbl.o asmglue.o DUMPCMDTBL_PROG = dumpcmdtbl -AFPBRIDGE_OBJS = afpinit.o afpbridge.o aspinterface.o dsi.o readtcp.o endian.o tcpconnection.o atipmapping.o asmglue.o installcmds.o cmdproc.o callat.o +AFPBRIDGE_OBJS = afpinit.o afpbridge.o aspinterface.o dsi.o readtcp.o endian.o tcpconnection.o atipmapping.o asmglue.o installcmds.o cmdproc.o callat.o afpoptions.o strncasecmp.o AFPBRIDGE_PROG = AFPBridge -AFPMOUNTER_OBJS = cdevstart.o afpcdev.o afpurlparser.o +AFPMOUNTER_OBJS = cdevstart.o afpcdev.o afpurlparser.o afpoptions.o strncasecmp.o AFPMOUNTER_RSRC = afpcdev.rez AFPMOUNTER_CDEV = AFPMounter diff --git a/afpcdev.c b/afpcdev.c index baf7cd3..643ec21 100644 --- a/afpcdev.c +++ b/afpcdev.c @@ -19,7 +19,9 @@ #include #include #include +#include "afpoptions.h" #include "afpurlparser.h" +#include "strncasecmp.h" #include "cdevutil.h" #define MachineCDEV 1 @@ -75,8 +77,6 @@ typedef struct EasyMountRec { EasyMountRec easyMountRec; -char afpOverTCPZone[] = "AFP over TCP"; - typedef struct GSString1024 { Word length; char text[1024]; @@ -105,10 +105,7 @@ SFReplyRec2 sfReplyRec; Word modifiers = 0; -#define fLargeReads 0x0001 -#define fForceAFP22 0x0002 - -Word flags = fLargeReads; /* for AFP over TCP connections */ +unsigned int flags = fLargeReads; /* for AFP over TCP connections */ void fillEasyMountRec(char *server, char *zone, char *volume, char *user, char *password, char *volpass) @@ -233,6 +230,8 @@ int writeAlias(GSString255Ptr file) void finalizeURLParts(AFPURLParts *urlParts) { + unsigned int i; + if (urlParts->server == NULL) urlParts->server = ""; if (urlParts->zone == NULL) @@ -262,7 +261,12 @@ void finalizeURLParts(AFPURLParts *urlParts) } if (urlParts->protocol == proto_TCP) { - urlParts->zone = afpOverTCPZone; + urlParts->zone = afpOptions[0].zoneString; + for (i = 0; afpOptions[i].zoneString != NULL; i++) { + if (afpOptions[i].flags == flags) { + urlParts->zone = afpOptions[i].zoneString; + } + } } } diff --git a/afpoptions.c b/afpoptions.c new file mode 100644 index 0000000..1246442 --- /dev/null +++ b/afpoptions.c @@ -0,0 +1,13 @@ +#pragma noroot + +#include "afpoptions.h" + +AFPOptions afpOptions[] = +{ + /*12345678901234567890123456789012 <- max length = 32 */ + {"AFP over TCP", 0}, + {"AFP over TCP (LargeReads)", fLargeReads}, + {"AFP over TCP (AFP2.2)", fForceAFP22}, + {"AFP over TCP (LargeReads,AFP2.2)", fLargeReads | fForceAFP22}, + {0, 0} +}; diff --git a/afpoptions.h b/afpoptions.h new file mode 100644 index 0000000..00de274 --- /dev/null +++ b/afpoptions.h @@ -0,0 +1,14 @@ +#ifndef AFPOPTIONS_H +#define AFPOPTIONS_H + +#define fLargeReads 0x0001 +#define fForceAFP22 0x0002 + +typedef struct AFPOptions { + char *zoneString; + unsigned int flags; +} AFPOptions; + +extern AFPOptions afpOptions[]; + +#endif diff --git a/afpurlparser.c b/afpurlparser.c index b71fa53..7ebbf61 100644 --- a/afpurlparser.c +++ b/afpurlparser.c @@ -1,7 +1,7 @@ #include #include #include "afpurlparser.h" - +#include "strncasecmp.h" #ifdef AFPURLPARSER_TEST # include @@ -11,17 +11,6 @@ # endif #endif -int strncasecmp(const char *s1, const char *s2, size_t n) -{ - while (tolower(*s1) == tolower(*s2) && *s1 != 0 && n > 1) { - s1++; - s2++; - n--; - } - - return (int)*s1 - (int)*s2; -} - static int hextonum(char c) { if (c >= '0' && c <= '9') return c - '0'; diff --git a/atipmapping.c b/atipmapping.c index dfcb74c..cbc12cb 100644 --- a/atipmapping.c +++ b/atipmapping.c @@ -11,13 +11,15 @@ #include "aspinterface.h" #include "installcmds.h" #include "cmdproc.h" +#include "afpoptions.h" +#include "strncasecmp.h" struct ATIPMapping atipMapping; #define DEFAULT_DSI_PORT 548 static char ATIPTypeName[] = "\pAFPServer"; -static char ATIPZoneName[] = "\pAFP over TCP"; +static char DefaultZoneName[] = "\p*"; // Next numbers to use for new mappings static int nextNode = 1; @@ -39,15 +41,16 @@ LongWord DoLookupName(NBPLookupNameRec *commandRec) { NBPLUNameBufferRec *resultBuf; LongWord initialTime; Word stateReg; + unsigned int flags; stateReg = ForceRomIn(); // Length needed for result, assuming the request is for our type/zone count = offsetof(NBPLUNameBufferRec, entityName) - + ((EntName*)commandRec->entityPtr)->buffer[0] - + ATIPTypeName[0] + ATIPZoneName[0]; + + ((EntName*)commandRec->entityPtr)->buffer[0] + 1 + + ATIPTypeName[0] + 1 + DefaultZoneName[0] + 1; if (count > commandRec->bufferLength) - return_error(nbpBufferErr); + goto passThrough; resultBuf = (NBPLUNameBufferRec *)commandRec->bufferPtr; @@ -69,10 +72,19 @@ LongWord DoLookupName(NBPLookupNameRec *commandRec) { *dest++ = ATIPTypeName[count]; } nameLen = *curr; + flags = 0xFFFF; + for (count = 0; afpOptions[count].zoneString != NULL; count++) { + if (strncasecmp(afpOptions[count].zoneString, curr+1, nameLen) == 0) { + flags = afpOptions[count].flags; + break; + } + } + if (flags == 0xFFFF) + goto passThrough; + + nameLen = *DefaultZoneName; for (count = 0; count <= nameLen; count++) { - if (toupper(*curr++) != toupper(ATIPZoneName[count])) - goto passThrough; - *dest++ = ATIPTypeName[count]; + *dest++ = DefaultZoneName[count]; } if (TCPIPValidateIPString(&resultBuf->entityName.buffer[0])) { @@ -138,6 +150,7 @@ LongWord DoLookupName(NBPLookupNameRec *commandRec) { nextSocket = 1; haveMapping: + atipMapping.flags = flags; resultBuf->netNum = atipMapping.networkNumber; resultBuf->nodeNum = atipMapping.node; resultBuf->socketNum = atipMapping.socket; diff --git a/atipmapping.h b/atipmapping.h index 90a817c..e98d38d 100644 --- a/atipmapping.h +++ b/atipmapping.h @@ -13,6 +13,9 @@ typedef struct ATIPMapping { /* IP address/port */ LongWord ipAddr; Word port; + + /* Flags for AFP over TCP (defined in afpoptions.h) */ + unsigned int flags; } ATIPMapping; extern struct ATIPMapping atipMapping; diff --git a/strncasecmp.c b/strncasecmp.c new file mode 100644 index 0000000..8318ad3 --- /dev/null +++ b/strncasecmp.c @@ -0,0 +1,20 @@ +# ifdef __ORCAC__ +# pragma noroot +# endif + +#include +#include + +int strncasecmp(const char *s1, const char *s2, size_t n) +{ + if (n == 0) + return 0; + + while (n > 1 && *s1 != 0 && tolower(*s1) == tolower(*s2)) { + s1++; + s2++; + n--; + } + + return (int)*s1 - (int)*s2; +} diff --git a/strncasecmp.h b/strncasecmp.h new file mode 100644 index 0000000..ae20a64 --- /dev/null +++ b/strncasecmp.h @@ -0,0 +1,6 @@ +#ifndef STRNCASECMP_H +#define STRNCASECMP_H + +int strncasecmp(const char *s1, const char *s2, size_t n); + +#endif