- Added additional cnvrt files from sicspsi
- Removed unused sycamore protocol from the code base
This commit is contained in:
156
protocol.c
156
protocol.c
@ -21,7 +21,7 @@
|
||||
#define MAXMSG 1024
|
||||
#define INIT_STR_SIZE 256
|
||||
#define STR_RESIZE_LENGTH 256
|
||||
#define NUMPROS 7
|
||||
#define NUMPROS 6
|
||||
#define PROLISTLEN 8
|
||||
typedef struct __Protocol {
|
||||
pObjectDescriptor pDes; /* required as first field */
|
||||
@ -97,7 +97,6 @@ pProtocol CreateProtocol(void)
|
||||
char *pPros[] = { "default",
|
||||
"normal",
|
||||
"withcode",
|
||||
"sycamore",
|
||||
"json",
|
||||
"act",
|
||||
"all",
|
||||
@ -282,19 +281,15 @@ static int ProtocolSet(SConnection * pCon, Protocol * pPro, char *pProName)
|
||||
SCSetWriteFunc(pCon, SCWriteWithOutcode);
|
||||
break;
|
||||
|
||||
case 3: /* sycamore */
|
||||
SCSetWriteFunc(pMaster, SCWriteSycamore);
|
||||
SCSetWriteFunc(pCon, SCWriteSycamore);
|
||||
break;
|
||||
case 4: /* json */
|
||||
case 3: /* json */
|
||||
SCSetWriteFunc(pCon, SCWriteJSON_String);
|
||||
SCSetWriteFunc(pMaster, SCWriteJSON_String);
|
||||
break;
|
||||
case 5: /* ACT */
|
||||
case 4: /* ACT */
|
||||
SCSetWriteFunc(pMaster, SCACTWrite);
|
||||
SCSetWriteFunc(pCon, SCACTWrite);
|
||||
break;
|
||||
case 6:
|
||||
case 5:
|
||||
SCSetWriteFunc(pMaster, SCAllWrite);
|
||||
SCSetWriteFunc(pCon, SCAllWrite);
|
||||
break;
|
||||
@ -340,9 +335,8 @@ int ProtocolGet(SConnection * pCon, void *pData, char *pProName, int len)
|
||||
case 0: /* default = psi_sics */
|
||||
case 1: /* normal (connection start default) */
|
||||
case 2: /* outcodes */
|
||||
case 3: /* sycamore */
|
||||
case 4: /* json */
|
||||
case 5: /* act */
|
||||
case 3: /* json */
|
||||
case 4: /* act */
|
||||
pProName = pPro->pProList[Index];
|
||||
return 1;
|
||||
break;
|
||||
@ -451,133 +445,7 @@ static int InitDefaultProtocol(SConnection * pCon, Protocol * pPro)
|
||||
}
|
||||
return pPro->isDefaultSet;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------*/
|
||||
void sycformat(char *tag, OutCode msgFlag, pDynString msgString,
|
||||
pDynString msgOut)
|
||||
{
|
||||
DynStringConcat(msgOut, " ");
|
||||
switch (msgFlag) {
|
||||
eEvent:
|
||||
break;
|
||||
eFinish:
|
||||
break;
|
||||
default:
|
||||
DynStringConcat(msgOut, tag);
|
||||
DynStringConcat(msgOut, "={");
|
||||
DynStringConcat(msgOut, GetCharArray(msgString));
|
||||
DynStringConcat(msgOut, "}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
int SCWriteSycamore(SConnection * pCon, char *pBuffer, int iOut)
|
||||
{
|
||||
int iRet;
|
||||
char pBueffel[MAXMSG];
|
||||
long taskID = 0;
|
||||
/* char pPrefix[40];*/
|
||||
pDynString pMsg = NULL;
|
||||
pDynString pMsgString = NULL;
|
||||
commandContext comCon;
|
||||
|
||||
|
||||
if (strlen(pBuffer) == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!SCVerifyConnection(pCon)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* log it for any case */
|
||||
if (pCon->pSock) {
|
||||
iRet = pCon->pSock->sockid;
|
||||
} else {
|
||||
iRet = 0;
|
||||
}
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "Next line intended for socket: %d", iRet);
|
||||
SICSLogWrite(pBueffel, eInternal);
|
||||
SICSLogWrite(pBuffer, iOut);
|
||||
|
||||
/* write to commandlog if user or manager privilege */
|
||||
if (SCGetRights(pCon) <= usUser) {
|
||||
WriteToCommandLogId(NULL, iRet, pBuffer);
|
||||
}
|
||||
|
||||
/* put it into the interpreter if present */
|
||||
if (SCinMacro(pCon)) {
|
||||
InterpWrite(pServ->pSics, pBuffer);
|
||||
/* print it to client if error message */
|
||||
/* FIXME should report errors via sycamore
|
||||
if((iOut== eError) || (iOut == eWarning) )
|
||||
iRet = SCDoSockWrite(pCon,GetCharArray(pMsgOut)); */
|
||||
} else { /* not in interpreter, normal logic */
|
||||
|
||||
comCon = SCGetContext(pCon);
|
||||
|
||||
/* Return 0 without dying if no message data */
|
||||
if (pBuffer == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
taskID = comCon.transID;
|
||||
|
||||
pMsg = CreateDynString(INIT_STR_SIZE, STR_RESIZE_LENGTH);
|
||||
pMsgString = CreateDynString(INIT_STR_SIZE, STR_RESIZE_LENGTH);
|
||||
pBueffel[0] = '\0';
|
||||
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "[con%4.4d:", (int) pCon->ident); /* field 1: connID */
|
||||
DynStringConcat(pMsg, pBueffel);
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "t%6.6d:", (int) taskID); /* field 2: taskID */
|
||||
DynStringConcat(pMsg, pBueffel);
|
||||
/* deviceID */
|
||||
DynStringConcat(pMsg, comCon.deviceID);
|
||||
DynStringConcatChar(pMsg, ':');
|
||||
|
||||
/* msgFlag */
|
||||
switch (iOut) {
|
||||
case 5: /* eValue */
|
||||
DynStringConcat(pMsg, "out");
|
||||
break;
|
||||
default:
|
||||
DynStringConcat(pMsg, pCode[iOut]);
|
||||
break;
|
||||
}
|
||||
DynStringConcatChar(pMsg, ']');
|
||||
if (iOut == eStart) {
|
||||
DynStringConcat(pMsgString, comCon.deviceID);
|
||||
}
|
||||
|
||||
if (iOut == eEvent) {
|
||||
DynStringConcat(pMsgString, " type=");
|
||||
/* Default type to VALUECHANGE if conEventType not set */
|
||||
if (-1 == pCon->conEventType)
|
||||
DynStringConcat(pMsgString, pEventType[0]);
|
||||
else
|
||||
DynStringConcat(pMsgString, pEventType[pCon->conEventType]);
|
||||
/* DynStringConcat(pMsgString, " status=");
|
||||
DynStringConcat(pMsgString, pStatus[pCon->conStatus]);*/
|
||||
DynStringConcat(pMsgString, ",");
|
||||
}
|
||||
DynStringConcat(pMsgString, " ");
|
||||
DynStringConcat(pMsgString, pBuffer);
|
||||
sycformat(comCon.deviceID, iOut, pMsgString, pMsg);
|
||||
|
||||
/* is this really to be printed ? */
|
||||
if (iOut < pCon->iOutput) {
|
||||
if (pMsg != NULL)
|
||||
DeleteDynString(pMsg);
|
||||
return 0;
|
||||
}
|
||||
/* first the socket */
|
||||
/*strcat(pMsg, pBueffel); */
|
||||
iRet = SCDoSockWrite(pCon, GetCharArray(pMsg));
|
||||
}
|
||||
if (pMsg != NULL)
|
||||
DeleteDynString(pMsg);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
/* Only work for hipadaba commands, hlist, hset, hget, hnotify
|
||||
* A multiline string (ie have crnl) will be converted to an array.
|
||||
* Strings with '=' will be converted to name value pairs
|
||||
@ -763,8 +631,7 @@ char *GetProtocolName(SConnection * pCon)
|
||||
case 0: /* default = psi_sics */
|
||||
case 1: /* normal (connection start default) */
|
||||
case 2: /* outcodes */
|
||||
case 3: /* sycamore */
|
||||
case 4: /* json */
|
||||
case 3: /* json */
|
||||
return strdup(pPro->pProList[pCon->iProtocolID]);
|
||||
break;
|
||||
default:
|
||||
@ -790,13 +657,10 @@ writeFunc GetProtocolWriteFunc(SConnection * pCon)
|
||||
case 2: /* outcodes */
|
||||
return SCWriteWithOutcode;
|
||||
break;
|
||||
case 3: /* sycamore */
|
||||
return SCWriteSycamore;
|
||||
break;
|
||||
case 4: /* json */
|
||||
case 3: /* json */
|
||||
return SCWriteJSON_String;
|
||||
break;
|
||||
case 5:
|
||||
case 4:
|
||||
return SCACTWrite;
|
||||
break;
|
||||
default:
|
||||
|
Reference in New Issue
Block a user