The new zwickroll driver with separation of out-of-band messages appears to

be working
This commit is contained in:
2015-02-04 14:19:42 +01:00
parent 1cf0e3351a
commit eb09725a1c

View File

@ -12,15 +12,58 @@
* *
* Created on: December, 4, 2013 * Created on: December, 4, 2013
* Author: koennecke * Author: koennecke
*
* Revised to identify out-of-band messages and to pass them on to a separate
* handler script
*
* Mark Koennecke, December 2014
*/ */
#include <errno.h> #include <errno.h>
#include <ascon.h> #include <ascon.h>
#include <ascon.i> #include <ascon.i>
#include <lld.h>
#include <lld_str.h>
#include <stptok.h>
#include <trace.h>
/*----------------------------------------------------------- static char *outofBandHandler = NULL;
* I am abusing the echo field as a flag if we are reading static int outofBandList = -1;
* an echo char or not /*----------------------------------------------------------------------------*/
-----------------------------------------------------------*/ static int outofBandHandled(Ascon *a)
{
int status;
char testString[80];
char command[1024];
char *toTest;
if(outofBandList < 0){
return 0;
}
status = LLDnodePtr2First(outofBandList);
toTest = GetCharArray(a->rdBuffer);
/* printf("outofBandHandler processing: %s\n", toTest); */
while(status != 0){
LLDstringData(outofBandList, testString);
if(strstr(toTest, testString) != NULL){
strcpy(command,outofBandHandler);
strncat(command," \"",sizeof(command));
strncat(command,GetCharArray(a->rdBuffer),sizeof(command));
strncat(command,"\"",sizeof(command));
/* printf("outofBandHandler found match with %s\n", testString); */
status = Tcl_Eval(InterpGetTcl(pServ->pSics), command);
if(status != TCL_OK){
traceIO("zwickroll","Tcl Error %s while processing out-of-band", Tcl_GetStringResult(InterpGetTcl(pServ->pSics)));
/* printf("Tcl Error %s while processing out-of-band\n", Tcl_GetStringResult(InterpGetTcl(pServ->pSics))); */
}
DynStringClear(a->rdBuffer);
return 1;
}
status = LLDnodePtr2Next(outofBandList);
}
return 0;
}
/*----------------------------------------------------------------------------*/
static int ZwickrollHandler(Ascon *a) static int ZwickrollHandler(Ascon *a)
{ {
int ret, l; int ret, l;
@ -39,11 +82,44 @@ static int ZwickrollHandler(Ascon *a)
} }
break; break;
case AsconReading: case AsconReading:
ret = AsconStdHandler(a);
if(a->state == AsconReadDone){
if(outofBandHandled(a)){
a->state = AsconReading;
}
}
return ret;
default: default:
return AsconStdHandler(a); return AsconStdHandler(a);
} }
return 1; return 1;
} }
/*------------------------------------------------------------------------*/
static int ZwickRollInit(Ascon *a, SConnection *con, int argc, char *argv[])
{
char token[80], *pPtr;
assert(argc>1);
a->hostport = strdup(argv[1]);
a->sendTerminator = strdup("\r\n");
a->replyTerminator = strdup("\n");
a->timeout = 2.;
if(argc > 3){
outofBandHandler = strdup(argv[3]);
outofBandList = LLDstringCreate();
pPtr = argv[2];
while(pPtr != NULL){
pPtr = stptok(pPtr,token,sizeof(token),":");
if(pPtr != NULL){
LLDstringAdd(outofBandList,token);
}
}
}
return 1;
}
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
void AddZwickrollProtocoll() void AddZwickrollProtocoll()
{ {
@ -51,7 +127,7 @@ void AddZwickrollProtocoll()
prot = calloc(sizeof(AsconProtocol), 1); prot = calloc(sizeof(AsconProtocol), 1);
prot->name = strdup("zwickroll"); prot->name = strdup("zwickroll");
prot->init = AsconStdInit; prot->init = ZwickRollInit;
prot->handler = ZwickrollHandler; prot->handler = ZwickrollHandler;
AsconInsertProtocol(prot); AsconInsertProtocol(prot);
} }