Added sycformat function to replace tcl code.
This commit is contained in:
109
protocol.c
109
protocol.c
@ -191,7 +191,6 @@ static int ContextDo(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
|
||||
SCPushContext2(pCon,comCon);
|
||||
status = InterpExecute(pSics,pCon,command);
|
||||
SCWrite(pCon,"",eFinish);
|
||||
SCPopContext(pCon);
|
||||
return status;
|
||||
}
|
||||
@ -353,7 +352,7 @@ int ProtocolAction(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
assert(pPro);
|
||||
|
||||
/* You need to have User level access rights to use this facility */
|
||||
if(!SCMatchRights(pCon,usUser))
|
||||
if(!SCMatchRights(pCon,usSpy))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@ -422,28 +421,52 @@ static int InitDefaultProtocol(SConnection* pCon, Protocol *pPro)
|
||||
return pPro->isDefaultSet;
|
||||
}
|
||||
/*---------------------------------------------------------------------*/
|
||||
void sycformat(char *tag, OutCode msgFlag, pDynString msgString, pDynString msgOut) {
|
||||
char typePrefix[] = "type.";
|
||||
char statusPrefix[] = "status.";
|
||||
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 i, iPtr, iRet;
|
||||
int bDevIDdone = 0;
|
||||
int bFlagDone = 0;
|
||||
char pBueffel[MAXMSG];
|
||||
char pBueffel[MAXMSG], *pBufferFrom, *pBufferTo;
|
||||
long taskID = 0;
|
||||
/* char pPrefix[40];*/
|
||||
pDynString pMsg = NULL;
|
||||
pDynString pMsgOut = NULL;
|
||||
pDynString parseCmd = NULL;
|
||||
pDynString pMsgString = NULL;
|
||||
SicsInterp *pSics;
|
||||
TokenList *pList = NULL;
|
||||
TokenList *pCurrent;
|
||||
commandContext comCon;
|
||||
char *savedTclResult = NULL;
|
||||
|
||||
/* For calling sycParse from interpreter */
|
||||
char **argv = NULL;
|
||||
int argc;
|
||||
char *parser = "sycformat ";
|
||||
CommandList *pCommand = NULL;
|
||||
|
||||
if (strlen(pBuffer) == 0) {
|
||||
return 0;
|
||||
}
|
||||
/* Strip \r and \n */
|
||||
for (pBufferFrom=pBufferTo=pBuffer; ; pBufferFrom++) {
|
||||
if (*pBufferFrom == '\r' || *pBufferFrom == '\n')
|
||||
continue;
|
||||
*pBufferTo = *pBufferFrom;
|
||||
if (*pBufferTo == '\0')
|
||||
break;
|
||||
pBufferTo++;
|
||||
}
|
||||
|
||||
if(!SCVerifyConnection(pCon))
|
||||
{
|
||||
@ -495,21 +518,20 @@ int SCWriteSycamore(SConnection *pCon, char *pBuffer, int iOut)
|
||||
*/
|
||||
pSics = GetInterpreter();
|
||||
taskID = comCon.transID;
|
||||
taskID = taskID % 1000000;
|
||||
|
||||
pMsg = CreateDynString(INIT_STR_SIZE, STR_RESIZE_LENGTH);
|
||||
pMsgString = CreateDynString(INIT_STR_SIZE, STR_RESIZE_LENGTH);
|
||||
pBueffel[0] = '\0';
|
||||
|
||||
sprintf(pBueffel,"con%4.4d",(int)pCon->ident); /* field 1: connID */
|
||||
sprintf(pBueffel,"[con%4.4d:",(int)pCon->ident); /* field 1: connID */
|
||||
DynStringConcat(pMsg,pBueffel);
|
||||
sprintf(pBueffel," t%6.6d",(int)taskID); /* field 2: taskID */
|
||||
sprintf(pBueffel,"t%6.6d:",(int)taskID); /* field 2: taskID */
|
||||
DynStringConcat(pMsg,pBueffel);
|
||||
DynStringConcatChar(pMsg,' ');
|
||||
/* deviceID */
|
||||
DynStringConcat(pMsg,comCon.deviceID);
|
||||
DynStringConcatChar(pMsg,' ');
|
||||
DynStringConcatChar(pMsg,':');
|
||||
|
||||
/* msgFlag */
|
||||
/* msgFlag */
|
||||
switch(iOut) {
|
||||
case 5: /* eValue */
|
||||
DynStringConcat(pMsg,"out");
|
||||
@ -518,55 +540,32 @@ int SCWriteSycamore(SConnection *pCon, char *pBuffer, int iOut)
|
||||
DynStringConcat(pMsg,pCode[iOut]);
|
||||
break;
|
||||
}
|
||||
DynStringConcatChar(pMsg,' ');
|
||||
DynStringConcat(pMsg, " { ");
|
||||
DynStringConcat(pMsg, comCon.deviceID);
|
||||
DynStringConcat(pMsg, " } {");
|
||||
DynStringConcatChar(pMsg,']');
|
||||
if (iOut == eStart){
|
||||
DynStringConcat(pMsg, comCon.deviceID);
|
||||
DynStringConcat(pMsgString, comCon.deviceID);
|
||||
}
|
||||
parseCmd = CreateDynString(INIT_STR_SIZE, STR_RESIZE_LENGTH);
|
||||
DynStringCopy(parseCmd, parser);
|
||||
DynStringConcat(parseCmd,GetCharArray(pMsg));
|
||||
DynStringConcat(parseCmd,pBuffer);
|
||||
|
||||
if (iOut == eEvent) {
|
||||
DynStringConcat(parseCmd, " type.");
|
||||
DynStringConcat(parseCmd, pEventType[pCon->conEventType]);
|
||||
DynStringConcat(parseCmd, " status.");
|
||||
DynStringConcat(parseCmd, pStatus[pCon->conStatus]);
|
||||
}
|
||||
DynStringConcatChar(parseCmd, '}');
|
||||
savedTclResult = strdup(Tcl_GetStringResult(pSics->pTcl));
|
||||
Tcl_Eval(pSics->pTcl, GetCharArray(parseCmd));
|
||||
pMsgOut = CreateDynString(INIT_STR_SIZE, STR_RESIZE_LENGTH);
|
||||
DynStringCopy(pMsgOut, (char *)Tcl_GetStringResult(pSics->pTcl));
|
||||
if(savedTclResult != NULL){
|
||||
Tcl_SetResult(pSics->pTcl,savedTclResult,TCL_VOLATILE);
|
||||
free(savedTclResult);
|
||||
DynStringConcat(pMsgString, " type=");
|
||||
DynStringConcat(pMsgString, pEventType[pCon->conEventType]);
|
||||
/* DynStringConcat(pMsgString, " status=");
|
||||
DynStringConcat(pMsgString, pStatus[pCon->conStatus]);*/
|
||||
}
|
||||
DynStringConcat(pMsgString,pBuffer);
|
||||
sycformat(comCon.deviceID, iOut, pMsgString, pMsg);
|
||||
|
||||
/* is this really to be printed ? */
|
||||
if(iOut < pCon->iOutput)
|
||||
{
|
||||
if (parseCmd != NULL)
|
||||
DeleteDynString(parseCmd);
|
||||
if (pMsg != NULL)
|
||||
DeleteDynString(pMsg);
|
||||
if (pMsgOut != NULL)
|
||||
DeleteDynString(pMsgOut);
|
||||
return 0;
|
||||
}
|
||||
if(iOut < pCon->iOutput)
|
||||
{
|
||||
if (pMsg != NULL)
|
||||
DeleteDynString(pMsg);
|
||||
return 0;
|
||||
}
|
||||
/* first the socket */
|
||||
/*strcat(pMsg, pBueffel);*/
|
||||
iRet = SCDoSockWrite(pCon,GetCharArray(pMsgOut));
|
||||
SCWriteToLogFiles(pCon,GetCharArray(pMsgOut));
|
||||
iRet = SCDoSockWrite(pCon,GetCharArray(pMsg));
|
||||
SCWriteToLogFiles(pCon,GetCharArray(pMsg));
|
||||
}
|
||||
if (pMsgOut != NULL){
|
||||
DeleteDynString(pMsgOut);
|
||||
}
|
||||
if (parseCmd != NULL)
|
||||
DeleteDynString(parseCmd);
|
||||
if (pMsg != NULL)
|
||||
DeleteDynString(pMsg);
|
||||
return 1;
|
||||
|
Reference in New Issue
Block a user