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);
|
SCPushContext2(pCon,comCon);
|
||||||
status = InterpExecute(pSics,pCon,command);
|
status = InterpExecute(pSics,pCon,command);
|
||||||
SCWrite(pCon,"",eFinish);
|
|
||||||
SCPopContext(pCon);
|
SCPopContext(pCon);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@ -353,7 +352,7 @@ int ProtocolAction(SConnection *pCon, SicsInterp *pSics, void *pData,
|
|||||||
assert(pPro);
|
assert(pPro);
|
||||||
|
|
||||||
/* You need to have User level access rights to use this facility */
|
/* You need to have User level access rights to use this facility */
|
||||||
if(!SCMatchRights(pCon,usUser))
|
if(!SCMatchRights(pCon,usSpy))
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -422,28 +421,52 @@ static int InitDefaultProtocol(SConnection* pCon, Protocol *pPro)
|
|||||||
return pPro->isDefaultSet;
|
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 SCWriteSycamore(SConnection *pCon, char *pBuffer, int iOut)
|
||||||
{
|
{
|
||||||
int i, iPtr, iRet;
|
int i, iPtr, iRet;
|
||||||
int bDevIDdone = 0;
|
int bDevIDdone = 0;
|
||||||
int bFlagDone = 0;
|
int bFlagDone = 0;
|
||||||
char pBueffel[MAXMSG];
|
char pBueffel[MAXMSG], *pBufferFrom, *pBufferTo;
|
||||||
long taskID = 0;
|
long taskID = 0;
|
||||||
/* char pPrefix[40];*/
|
/* char pPrefix[40];*/
|
||||||
pDynString pMsg = NULL;
|
pDynString pMsg = NULL;
|
||||||
pDynString pMsgOut = NULL;
|
pDynString pMsgString = NULL;
|
||||||
pDynString parseCmd = NULL;
|
|
||||||
SicsInterp *pSics;
|
SicsInterp *pSics;
|
||||||
TokenList *pList = NULL;
|
TokenList *pList = NULL;
|
||||||
TokenList *pCurrent;
|
TokenList *pCurrent;
|
||||||
commandContext comCon;
|
commandContext comCon;
|
||||||
char *savedTclResult = NULL;
|
char *savedTclResult = NULL;
|
||||||
|
|
||||||
/* For calling sycParse from interpreter */
|
|
||||||
char **argv = NULL;
|
if (strlen(pBuffer) == 0) {
|
||||||
int argc;
|
return 0;
|
||||||
char *parser = "sycformat ";
|
}
|
||||||
CommandList *pCommand = NULL;
|
/* 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))
|
if(!SCVerifyConnection(pCon))
|
||||||
{
|
{
|
||||||
@ -495,21 +518,20 @@ int SCWriteSycamore(SConnection *pCon, char *pBuffer, int iOut)
|
|||||||
*/
|
*/
|
||||||
pSics = GetInterpreter();
|
pSics = GetInterpreter();
|
||||||
taskID = comCon.transID;
|
taskID = comCon.transID;
|
||||||
taskID = taskID % 1000000;
|
|
||||||
|
|
||||||
pMsg = CreateDynString(INIT_STR_SIZE, STR_RESIZE_LENGTH);
|
pMsg = CreateDynString(INIT_STR_SIZE, STR_RESIZE_LENGTH);
|
||||||
|
pMsgString = CreateDynString(INIT_STR_SIZE, STR_RESIZE_LENGTH);
|
||||||
pBueffel[0] = '\0';
|
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);
|
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);
|
DynStringConcat(pMsg,pBueffel);
|
||||||
DynStringConcatChar(pMsg,' ');
|
|
||||||
/* deviceID */
|
/* deviceID */
|
||||||
DynStringConcat(pMsg,comCon.deviceID);
|
DynStringConcat(pMsg,comCon.deviceID);
|
||||||
DynStringConcatChar(pMsg,' ');
|
DynStringConcatChar(pMsg,':');
|
||||||
|
|
||||||
/* msgFlag */
|
/* msgFlag */
|
||||||
switch(iOut) {
|
switch(iOut) {
|
||||||
case 5: /* eValue */
|
case 5: /* eValue */
|
||||||
DynStringConcat(pMsg,"out");
|
DynStringConcat(pMsg,"out");
|
||||||
@ -518,55 +540,32 @@ int SCWriteSycamore(SConnection *pCon, char *pBuffer, int iOut)
|
|||||||
DynStringConcat(pMsg,pCode[iOut]);
|
DynStringConcat(pMsg,pCode[iOut]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
DynStringConcatChar(pMsg,' ');
|
DynStringConcatChar(pMsg,']');
|
||||||
DynStringConcat(pMsg, " { ");
|
|
||||||
DynStringConcat(pMsg, comCon.deviceID);
|
|
||||||
DynStringConcat(pMsg, " } {");
|
|
||||||
if (iOut == eStart){
|
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) {
|
if (iOut == eEvent) {
|
||||||
DynStringConcat(parseCmd, " type.");
|
DynStringConcat(pMsgString, " type=");
|
||||||
DynStringConcat(parseCmd, pEventType[pCon->conEventType]);
|
DynStringConcat(pMsgString, pEventType[pCon->conEventType]);
|
||||||
DynStringConcat(parseCmd, " status.");
|
/* DynStringConcat(pMsgString, " status=");
|
||||||
DynStringConcat(parseCmd, pStatus[pCon->conStatus]);
|
DynStringConcat(pMsgString, 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,pBuffer);
|
||||||
|
sycformat(comCon.deviceID, iOut, pMsgString, pMsg);
|
||||||
|
|
||||||
/* is this really to be printed ? */
|
/* is this really to be printed ? */
|
||||||
if(iOut < pCon->iOutput)
|
if(iOut < pCon->iOutput)
|
||||||
{
|
{
|
||||||
if (parseCmd != NULL)
|
if (pMsg != NULL)
|
||||||
DeleteDynString(parseCmd);
|
DeleteDynString(pMsg);
|
||||||
if (pMsg != NULL)
|
return 0;
|
||||||
DeleteDynString(pMsg);
|
}
|
||||||
if (pMsgOut != NULL)
|
|
||||||
DeleteDynString(pMsgOut);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
/* first the socket */
|
/* first the socket */
|
||||||
/*strcat(pMsg, pBueffel);*/
|
/*strcat(pMsg, pBueffel);*/
|
||||||
iRet = SCDoSockWrite(pCon,GetCharArray(pMsgOut));
|
iRet = SCDoSockWrite(pCon,GetCharArray(pMsg));
|
||||||
SCWriteToLogFiles(pCon,GetCharArray(pMsgOut));
|
SCWriteToLogFiles(pCon,GetCharArray(pMsg));
|
||||||
}
|
}
|
||||||
if (pMsgOut != NULL){
|
|
||||||
DeleteDynString(pMsgOut);
|
|
||||||
}
|
|
||||||
if (parseCmd != NULL)
|
|
||||||
DeleteDynString(parseCmd);
|
|
||||||
if (pMsg != NULL)
|
if (pMsg != NULL)
|
||||||
DeleteDynString(pMsg);
|
DeleteDynString(pMsg);
|
||||||
return 1;
|
return 1;
|
||||||
|
Reference in New Issue
Block a user