diff --git a/conman.c b/conman.c index 8d99bb05..13a4dd2b 100644 --- a/conman.c +++ b/conman.c @@ -1138,7 +1138,7 @@ int SCLogWrite(SConnection * self, char *buffer, int iOut) WriteToCommandLogId(NULL, self->sockHandle, buffer); SetSendingConnection(NULL); - if(self->iProtocolID == 4) { /* act */ + if(self->iProtocolID == PROTACT) { /* act */ if (strlen(buffer) + 30 > 1024) { pPtr = (char *) malloc((strlen(buffer) + 30) * sizeof(char)); memset(pPtr, 0, strlen(buffer) + 20); @@ -1150,7 +1150,7 @@ int SCLogWrite(SConnection * self, char *buffer, int iOut) if(pPtr != pBueffel){ free(pPtr); } - } else if(self->iProtocolID == 2) { /* withcode */ + } else if(self->iProtocolID == PROTCODE) { /* withcode */ if (strlen(buffer) + 30 > 1024) { pPtr = (char *) malloc((strlen(buffer) + 30) * sizeof(char)); memset(pPtr, 0, strlen(buffer) + 20); @@ -1162,7 +1162,7 @@ int SCLogWrite(SConnection * self, char *buffer, int iOut) if(pPtr != pBueffel){ free(pPtr); } - } else if(self->iProtocolID == 3) { /* json */ + } else if(self->iProtocolID == PROTJSON) { /* json */ myJson = mkJSON_Object(self,buffer,iOut); if(myJson != NULL){ SCDoSockWrite(self,(char *)json_object_to_json_string(myJson)); @@ -1348,7 +1348,7 @@ int SCWriteZipped(SConnection * self, char *pName, void *pData, memset(outBuf, 0, 65536); protocolID = GetProtocolID(self); - if (protocolID == 4) { + if (protocolID == PROTACT) { cc = SCGetContext(self); sprintf(outBuf, "SICSBIN ZIP %s %d %d\r\n", pName, compressedLength, cc.transID); @@ -1423,7 +1423,7 @@ int SCWriteBinary(SConnection * self, char *pName, void *pData, memset(outBuf, 0, 65536); protocolID = GetProtocolID(self); - if (protocolID == 4) { + if (protocolID == PROTACT) { cc = SCGetContext(self); sprintf(outBuf, "SICSBIN BIN %s %d %d\r\n", pName, iDataLen, cc.transID); @@ -1529,7 +1529,7 @@ int SCWriteZippedOld(SConnection * self, char *pName, void *pData, memset(outBuf, 0, 65536); protocolID = GetProtocolID(self); - if (protocolID == 4) { + if (protocolID == PROTACT) { cc = SCGetContext(self); sprintf(outBuf, "SICSBIN ZIP %s %d %d\r\n", pName, compressedLength, cc.transID); diff --git a/nread.c b/nread.c index 3cb546e3..33b98f5a 100644 --- a/nread.c +++ b/nread.c @@ -42,6 +42,8 @@ #include "commandlog.h" #include "uselect.h" #include "trace.h" +#include "protocol.h" + extern pServer pServ; extern int VerifyChannel(mkChannel * self); /* defined in network.c */ @@ -296,7 +298,7 @@ static int NetReadRead(pNetRead self, pNetItem pItem) if (strlen(pItem->pHold) > 0) { strlcat(pItem->pHold, pPtr, 511); /* DFC locking for protocol zero only */ - if (pItem->pCon->iProtocolID == 0 && + if (pItem->pCon->iProtocolID == PROTSICS && CostaLocked(pItem->pCon->pStack)) iStat = 0; else @@ -308,7 +310,7 @@ static int NetReadRead(pNetRead self, pNetItem pItem) } else { /* no, normal command */ /* DFC locking for protocol zero only */ - if (pItem->pCon->iProtocolID == 0 && + if (pItem->pCon->iProtocolID == PROTSICS && CostaLocked(pItem->pCon->pStack)) iStat = 0; else @@ -498,7 +500,7 @@ static int TelnetRead(pNetRead self, pNetItem pItem) case '\r': case '\n': /* DFC locking for protocol zero only */ - if (pItem->pCon->iProtocolID == 0 && + if (pItem->pCon->iProtocolID == PROTSICS && CostaLocked(pItem->pCon->pStack)) iStat = 0; else @@ -1076,7 +1078,7 @@ static int CommandDataCB(int handle, void *userData) if (pPtr[i] == '\r' || pPtr[i] == '\n') { self->state = SKIPTERM; if (!testAndInvokeInterrupt(self, handle)) { - if (self->pCon->iProtocolID == 0 && CostaLocked(self->pCon->pStack)) + if (self->pCon->iProtocolID == PROTSICS && CostaLocked(self->pCon->pStack)) status = 0; else status = CostaTop(self->pCon->pStack, GetCharArray(self->command)); @@ -1180,7 +1182,7 @@ static int ANETTelnetProcess(int handle, void *usData) case '\r': case '\n': if (!testAndInvokeInterrupt(self, handle)) { - if (self->pCon->iProtocolID == 0 && CostaLocked(self->pCon->pStack)) + if (self->pCon->iProtocolID == PROTSICS && CostaLocked(self->pCon->pStack)) status = 0; else status = CostaTop(self->pCon->pStack, GetCharArray(self->command)); diff --git a/protocol.c b/protocol.c index 0d442d6f..800698e9 100644 --- a/protocol.c +++ b/protocol.c @@ -32,6 +32,10 @@ typedef struct __Protocol { int isDefaultSet; char *pProList[PROLISTLEN]; /* list of valid protocols? */ } Protocol; +/*================================================================================================ + WARNING: These two char arrays may replicate things defined elsewhere. They may be out of + sync with the rest of SIS. Keep in mind..... + ==================================================================================================*/ char *pEventType[] = { "VALUECHANGE", /* 0 */ @@ -277,29 +281,29 @@ static int ProtocolSet(SConnection * pCon, Protocol * pPro, char *pProName) return 0; break; - case 1: /* normal (connection start default) */ + case PROTNORM: /* normal (connection start default) */ SCSetWriteFunc(pMaster, SCNormalWrite); SCSetWriteFunc(pCon, SCNormalWrite); break; - case 2: /* outcodes */ + case PROTCODE: /* outcodes */ SCSetWriteFunc(pMaster, SCWriteWithOutcode); SCSetWriteFunc(pCon, SCWriteWithOutcode); break; - case 3: /* json */ + case PROTJSON: /* json */ SCSetWriteFunc(pCon, SCWriteJSON_String); SCSetWriteFunc(pMaster, SCWriteJSON_String); break; - case 4: /* ACT */ + case PROTACT: /* ACT */ SCSetWriteFunc(pMaster, SCACTWrite); SCSetWriteFunc(pCon, SCACTWrite); break; - case 5: + case PROTALL: SCSetWriteFunc(pMaster, SCAllWrite); SCSetWriteFunc(pCon, SCAllWrite); break; - case 0: /* default = psi_sics */ + case PROTSICS: /* default = psi_sics */ default: SCSetWriteFunc(pMaster, pPro->defaultWriter); SCSetWriteFunc(pCon, pPro->defaultWriter); @@ -338,11 +342,11 @@ int ProtocolGet(SConnection * pCon, void *pData, char *pProName, int len) /* check list of protocols for valid name */ switch (Index) { - case 0: /* default = psi_sics */ - case 1: /* normal (connection start default) */ - case 2: /* outcodes */ - case 3: /* json */ - case 4: /* act */ + case PROTSICS: /* default = psi_sics */ + case PROTNORM: /* normal (connection start default) */ + case PROTCODE: /* outcodes */ + case PROTJSON: /* json */ + case PROTACT: /* act */ pProName = pPro->pProList[Index]; return 1; break; @@ -447,7 +451,7 @@ static int InitDefaultProtocol(SConnection * pCon, Protocol * pPro) if (0 == pPro->isDefaultSet) { pPro->defaultWriter = SCGetWriteFunc(pCon); pPro->isDefaultSet = 1; - pCon->iProtocolID = 0; + pCon->iProtocolID = PROTSICS; } return pPro->isDefaultSet; } @@ -634,10 +638,11 @@ char *GetProtocolName(SConnection * pCon) /* check list of protocols for valid name */ switch (pCon->iProtocolID) { - case 0: /* default = psi_sics */ - case 1: /* normal (connection start default) */ - case 2: /* outcodes */ - case 3: /* json */ + case PROTSICS: /* default = psi_sics */ + case PROTNORM: /* normal (connection start default) */ + case PROTCODE: /* outcodes */ + case PROTJSON: /* json */ + case PROTACT: /* act */ return strdup(pPro->pProList[pCon->iProtocolID]); break; default: @@ -660,13 +665,13 @@ writeFunc GetProtocolWriteFunc(SConnection * pCon) { if (pCon != NULL) { switch (pCon->iProtocolID) { - case 2: /* outcodes */ + case PROTCODE: /* outcodes */ return SCWriteWithOutcode; break; - case 3: /* json */ + case PROTJSON: /* json */ return SCWriteJSON_String; break; - case 4: + case PROTACT: return SCACTWrite; break; default: diff --git a/protocol.h b/protocol.h index 4151b4f7..67316967 100644 --- a/protocol.h +++ b/protocol.h @@ -15,6 +15,14 @@ static char *pProTags[3] = { #define esStart -1 #define esFinish -2 +/*---------------------- protocol defines -------------------------------*/ +#define PROTSICS 0 +#define PROTNORM 1 +#define PROTCODE 2 +#define PROTJSON 3 +#define PROTACT 4 +#define PROTALL 5 + /*--------------------- lifecycle -------------------------------------- */ int InstallProtocol(SConnection * pCon, SicsInterp * pSics, void *pData, int argc, char *argv[]);