Refactored protocol code to use defined IDs rather then raw integers
This commit is contained in:
10
conman.c
10
conman.c
@ -1086,7 +1086,7 @@ int SCPureSockWrite(SConnection * self, char *buffer, int iOut)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(self->iProtocolID == 5) {
|
||||
if(self->iProtocolID == 4) {
|
||||
if (strlen(buffer) + 30 > 1024) {
|
||||
pPtr = (char *) malloc((strlen(buffer) + 30) * sizeof(char));
|
||||
memset(pPtr, 0, strlen(buffer) + 20);
|
||||
@ -1119,7 +1119,7 @@ int SCLogWrite(SConnection * self, char *buffer, int iOut)
|
||||
WriteToCommandLogId(NULL, self->sockHandle, buffer);
|
||||
SetSendingConnection(NULL);
|
||||
|
||||
if(self->iProtocolID == 5) {
|
||||
if(self->iProtocolID == 4) {
|
||||
if (strlen(buffer) + 30 > 1024) {
|
||||
pPtr = (char *) malloc((strlen(buffer) + 30) * sizeof(char));
|
||||
memset(pPtr, 0, strlen(buffer) + 20);
|
||||
@ -1323,7 +1323,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);
|
||||
@ -1398,7 +1398,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);
|
||||
@ -1504,7 +1504,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);
|
||||
|
12
nread.c
12
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));
|
||||
|
43
protocol.c
43
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 */
|
||||
@ -271,29 +275,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);
|
||||
@ -332,11 +336,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;
|
||||
@ -441,7 +445,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;
|
||||
}
|
||||
@ -628,10 +632,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:
|
||||
@ -654,13 +659,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:
|
||||
|
@ -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[]);
|
||||
|
Reference in New Issue
Block a user