Refactored protocol code to use defined IDs rather then raw integers

This commit is contained in:
2015-05-11 09:30:44 +02:00
parent 0bcd3b06f6
commit bb7eb497de
4 changed files with 44 additions and 29 deletions

View File

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