First commit towards replacing pCon-> with someFunc(pCon)

This is accompanied with the removal of dead code in conman.c and else
This commit is contained in:
2016-10-31 08:33:36 +01:00
parent fd5451e8fd
commit 0e2605b570
21 changed files with 171 additions and 433 deletions

View File

@ -295,9 +295,9 @@ int InterpExecute(SicsInterp * self, SConnection * pCon, char *pText)
assert(pCon);
/* write info to Log
if (pCon->sockHandle >= 0) {
if (SCGetSockHandle(pCon) >= 0) {
snprintf(pBueffel,1023, "Executing -> %s <- from socket %d", pText,
pCon->sockHandle);
SCGetSockHandle(pCon));
SICSLogWrite(pBueffel, eCommand);
} else {
snprintf(pBueffel,1023, "Executing -> %s <- from dummy socket\n", pText);
@ -348,14 +348,14 @@ int InterpExecute(SicsInterp * self, SConnection * pCon, char *pText)
self->eOut = eValue;
Tcl_ResetResult((Tcl_Interp *) self->pTcl);
MacroPush(pCon);
pCon->conStatus = 0;
SCSetConStatus(pCon,0);
old = StatisticsBegin(pCommand->stat);
iRet = pCommand->OFunc(pCon, self, pCommand->pData, argc, argv);
StatisticsEnd(old);
/* If a task is registered with the dev exec then conStatus is HWBusy */
if (pCon->conStatus != HWBusy) {
if (SCGetConStatus(pCon) != HWBusy) {
/*comCon = SCGetContext(pCon); */
if (0 != strcmp("contextdo", pCon->deviceID))
if (0 != strcmp("contextdo", SCGetDeviceID(pCon)))
SCWrite(pCon, "", eFinish);
}
MacroPop();

View File

@ -60,7 +60,7 @@ static int ReplacementCheckStatus(void *pData, SConnection * pCon)
myCollider->isDirty = 0;
StartDevice(pServ->pExecutor,
"anticollider", myCollider->pDes, myCollider,
pCon,pCon->runLevel, 77.77);
pCon,SCGetRunLevel(pCon), 77.77);
return HWIdle;
} else {
return HWIdle;

268
conman.c
View File

@ -45,6 +45,11 @@
substantially revised for asynchronous I/O
Mark Koennecke, January 2009
Removed old cruft including SCStore. Added accessor functions to make the
connection object more private
Mark Koennecke, October 2016
-----------------------------------------------------------------------------*/
#include "fortify.h"
#include <stdlib.h>
@ -115,14 +120,6 @@ static long lastIdent = 0;
/*------------- sending connection (prevent double write when listening) ----*/
static SConnection *sendingConnection = NULL;
static int sendingSockHandle = 0;
/*------------- storing connection and context for later use ----*/
struct SCStore {
SConnection *pCon;
long ident;
int inMacro;
long macroStack;
commandContext cc;
};
/*
* This will return the value of a SICS int variable called "sicsdebug"
@ -168,11 +165,6 @@ static void FreeConnection(SConnection * pCon)
free(pCon);
}
/*------------------------------------------------------------------------*/
void KillFreeConnections()
{
}
/*---------------------------------------------------------------------------*/
SConnection *GetSendingConnection(void)
{
@ -550,47 +542,6 @@ static int HasNL(char *buffer)
#define TXT 0
#define LF 1
int TelnetWrite(mkChannel * pSock, char *pBuffer)
{
char *pStart = NULL, *pPtr;
int iCount, iState;
int iRet = 1;
pStart = pBuffer;
pPtr = pStart;
iState = TXT;
iCount = 0;
while (*pPtr != '\0') {
switch (iState) {
case TXT:
if ((*pPtr == '\r') || (*pPtr == '\n')) {
iState = LF;
iRet = NETWrite(pSock, pStart, iCount);
iRet = NETWrite(pSock, "\r\n", 2);
iCount = 0;
} else {
iCount++;
}
break;
case LF:
if ((*pPtr != '\r') && (*pPtr != '\n')) {
pStart = pPtr;
iCount = 1;
iState = TXT;
} else {
/* do nothing */
}
break;
}
pPtr++;
}
if (iCount > 0) {
iRet = NETWrite(pSock, pStart, iCount);
iRet = NETWrite(pSock, "\r\n", 2);
}
return iRet;
}
/*-----------------------------------------------------------*/
int TelnetWriteANET(int sockHandle, char *pBuffer)
{
@ -2330,117 +2281,6 @@ int SCActive(SConnection * self)
}
return 0;
}
/*--------------------------------------------------------------------------*/
SCStore *SCSave(SConnection * pCon, SCStore * oldStore)
{
commandContext cc;
if (oldStore == NULL) {
oldStore = calloc(1, sizeof(*oldStore));
assert(oldStore);
}
oldStore->pCon = pCon;
if (pCon) {
oldStore->ident = pCon->ident;
oldStore->inMacro = pCon->iMacro;
oldStore->cc = SCGetContext(pCon);
oldStore->macroStack = 0;
}
return oldStore;
}
/*--------------------------------------------------------------------------*/
SConnection *SCLoad(SCStore * conStore)
{
SConnection *pCon = NULL;
commandContext old;
if (conStore) {
pCon = conStore->pCon;
}
if (pCon) {
if (conStore->ident != pCon->ident) {
conStore->pCon = NULL; /* connection is dead */
pCon = NULL;
}
}
if (pCon) {
return pCon;
}
return pServ->dummyCon;
}
/*--------------------------------------------------------------------------*/
SConnection *SCStorePush(SCStore * conStore)
{
SConnection *pCon;
pCon = SCLoad(conStore);
/* push macro flag on stack */
conStore->macroStack <<= 1;
conStore->macroStack |= (pCon->iMacro != 0);
SCsetMacro(pCon, conStore->inMacro);
SCPushContext2(pCon, conStore->cc);
return pCon;
}
/*--------------------------------------------------------------------------*/
void SCStorePop(SCStore * conStore)
{
SConnection *pCon;
pCon = SCLoad(conStore);
SCPopContext(pCon);
/* pop macro flag from stack
SCsetMacro(pCon,conStore->macroStack);
*/
SCsetMacro(pCon, (conStore->macroStack & 1));
conStore->macroStack >>= 1;
}
/*--------------------------------------------------------------------------*/
int SCStoreConnected(SCStore * conStore)
{
return (conStore &&
conStore->pCon && conStore->pCon->ident == conStore->ident);
}
/*--------------------------------------------------------------------------*/
void SCStoreFree(SCStore * conStore)
{
free(conStore);
}
/* --------------------------------------------------------------------------*/
long SCTagContext(SConnection * self, char *tagName)
{
commandContext a;
if (NULL == self)
return -1;
a = SCGetContext(self);
strlcpy(a.deviceID, tagName, SCDEVIDLEN);
/*
SCGetContext will already have advanced the stack pointer to the
last position
*/
LLDnodeDataTo(self->contextStack, &a);
return 1;
}
/* --------------------------------------------------------------------------*/
long SCAdvanceContext(SConnection * self, char *tagName)
{
if (NULL == self)
return -1;
self->iCmdCtr++;
if (999999 < self->iCmdCtr) {
self->iCmdCtr = 0;
}
return SCPushContext(self, self->iCmdCtr, tagName);
}
/*------------------------------------------------------------------------*/
int SCVerifyConnection(SConnection * self)
{
@ -2500,3 +2340,101 @@ int SCPopContext(SConnection * pCon)
}
return 1;
}
/*--------------------------------------------------------*/
int SCGetRunLevel(SConnection *pCon)
{
if (!VerifyConnection(pCon)) {
return 0;
}
return pCon->runLevel;
}
/*--------------------------------------------------------*/
int SCGetIdent(SConnection *pCon)
{
if (!VerifyConnection(pCon)) {
return 0;
}
return pCon->ident;
}
/*--------------------------------------------------------*/
int SCGetSicsError(SConnection *pCon)
{
if (!VerifyConnection(pCon)) {
return 0;
}
return pCon->sicsError;
}
/*--------------------------------------------------------*/
int SCGetTransID(SConnection *pCon)
{
if (!VerifyConnection(pCon)) {
return 0;
}
return pCon->transID;
}
/*--------------------------------------------------------*/
int SCGetProtocolID(SConnection *pCon)
{
if (!VerifyConnection(pCon)) {
return 0;
}
return pCon->iProtocolID;
}
/*--------------------------------------------------------*/
int SCGetSockHandle(SConnection *pCon)
{
if (!VerifyConnection(pCon)) {
return 0;
}
return pCon->sockHandle;
}
/*--------------------------------------------------------*/
int SCGetConStatus(SConnection *pCon)
{
if (!VerifyConnection(pCon)) {
return 0;
}
return pCon->conStatus;
}
/*--------------------------------------------------------*/
char *SCGetDeviceID(SConnection *pCon)
{
if (!VerifyConnection(pCon)) {
return 0;
}
return pCon->deviceID;
}
/*-------------------------------------------------------*/
void SCSetConStatus(SConnection *pCon, int conStatus)
{
if (!VerifyConnection(pCon)) {
return;
}
pCon->conStatus = conStatus;
}
/*-------------------------------------------------------*/
void SCSetEventType(SConnection *pCon, int eventType)
{
if (!VerifyConnection(pCon)) {
return;
}
pCon->conEventType = eventType;
}
/*-------------------------------------------------------*/
void SCSetSicsError(SConnection *pCon, int sicsError)
{
if (!VerifyConnection(pCon)) {
return;
}
pCon->sicsError = sicsError;
}
/*-------------------------------------------------------*/
void SCSetProtocolID(SConnection *pCon, int id)
{
if (!VerifyConnection(pCon)) {
return;
}
pCon->iProtocolID = id;
}

View File

@ -140,6 +140,20 @@ int SCMatchRights(SConnection * pCon, int iCode);
int SCGetOutClass(SConnection * self);
int SCGetGrab(SConnection * pCon);
int SCActive(SConnection * pCon);
int SCGetRunLevel(SConnection *pCon);
int SCGetIdent(SConnection *pCon);
int SCGetSicsError(SConnection *pCon);
int SCGetTransID(SConnection *pCon);
int SCGetProtocolID(SConnection *pCon);
int SCGetSockHandle(SConnection *pCon);
int SCGetConStatus(SConnection *pCon);
char *SCGetDeviceID(SConnection *pCon);
/************************* connection parameter change **********************/
void SCSetConStatus(SConnection *pCon, int conStatus);
void SCSetEventType(SConnection *pCon, int eventType);
void SCSetSicsError(SConnection *pCon, int sicsError);
void SCSetProtocolID(SConnection *pCon, int proID);
/* **************************** Invocation ******************************** */
int SCInvoke(SConnection * self, SicsInterp * pInter, char *pCommand);
@ -166,28 +180,6 @@ int SCPushContext(SConnection * pCon, int ID, char *deviceID);
int SCPushContext2(SConnection * pCon, commandContext cc);
int SCPopContext(SConnection * pCon);
commandContext SCGetContext(SConnection * pCon);
/******************************** Store ************************************/
typedef struct SCStore SCStore;
SCStore *SCSave(SConnection * pCon, SCStore * oldStore);
/* save a connection and its context for later use. */
SConnection *SCLoad(SCStore * conStore);
/* check con and return SConnection if still valid or a dummy connection otherwise. */
SConnection *SCStorePush(SCStore * conStore);
/* load connection and push stored context. Must be paired with an SCStorePop command */
void SCStorePop(SCStore * conStore);
/* pop context */
int SCStoreConnected(SCStore * conStore);
/* check if a stored connection is not closed */
void SCStoreFree(SCStore * conStore);
/* free an SCStore */
void KillFreeConnections(void);
/************************* CallBack *********************************** */
int SCRegister(SConnection * pCon, SicsInterp * pSics,
void *pInter, long lID);

View File

@ -256,7 +256,7 @@ int StartDevice(pExeList self, char *name, pObjectDescriptor pDes,
/* may we? */
if (self->pOwner != NULL) {
if (pCon->ident != self->pOwner->ident) {
if (SCGetIdent(pCon) != SCGetIdent(self->pOwner)) {
/* this hack helps on rita2, when using the sendsics script
which opens a client for every command */
if (overwriteOwner < 0) {
@ -329,7 +329,7 @@ int StartDevice(pExeList self, char *name, pObjectDescriptor pDes,
DevExecSignal,
NULL, self,TASK_PRIO_HIGH);
}
pCon->conStatus = HWBusy;
SCSetConStatus(pCon,HWBusy);
return 1;
} else {
snprintf(pBueffel,131, "ERROR: cannot start device %s", name);

View File

@ -835,7 +835,7 @@ int EVCDrive(pEVControl self, SConnection * pCon, float fVal)
/* start executing */
iRet = StartDevice(GetExecutor(), self->pName, self->pDes,
self, pCon, pCon->runLevel, fVal);
self, pCon, SCGetRunLevel(pCon), fVal);
if (!iRet) {
snprintf(pBueffel,255, "ERROR: Failure to start %s", self->pName);
SCWrite(pCon, pBueffel, eError);
@ -1022,7 +1022,7 @@ static int EVCallBack(int iEvent, void *pEventData, void *pUserData)
}
if (iEvent == VALUECHANGE && pCon != NULL) {
pCon->conEventType = POSITION;
SCSetEventType(pCon,POSITION);
SCWrite(pCon, pBuf, eEvent);
return 1;
}

View File

@ -304,7 +304,7 @@ int exeBufProcess(pExeBuf self, SicsInterp * pSics,
Log(INFO,"com","%s:batch:%s", ConID(pCon), cmd);
status = Tcl_Eval(pTcl, cmd);
if (status != TCL_OK) {
if (pCon->sicsError == 0) {
if (SCGetSicsError(pCon) == 0) {
/*
Tcl Error
*/
@ -314,7 +314,7 @@ int exeBufProcess(pExeBuf self, SicsInterp * pSics,
}
} else {
SCWrite(pCon, pTcl->result, eError);
pCon->sicsError = 0;
SCSetSicsError(pCon,0);
}
SCWrite(pCon, "ERROR: above error was in block:", eError);
SCWrite(pCon, cmd, eError);

View File

@ -255,8 +255,8 @@ static int DriveTaskFunc(void *data)
ExeInterest(pServ->pExecutor,taskData->name, "finished with problem");
}
traceSys("drive","DriveTask %s finished with state %d", taskData->name,status);
if(taskData->pCon->transID > 100000) {
SCPrintf(taskData->pCon,eLog,"TASKEND %d", taskData->pCon->transID);
if(SCGetTransID(taskData->pCon) > 100000) {
SCPrintf(taskData->pCon,eLog,"TASKEND %d", SCGetTransID(taskData->pCon));
}
return 0;
}
@ -288,8 +288,8 @@ long StartDriveTask(void *obj, SConnection *pCon, char *name, float fTarget)
ExeInterest(pServ->pExecutor,name,"started");
DevexecLog("START",name);
InvokeNewTarget(pServ->pExecutor,name,fTarget);
if(pCon->transID > 100000) {
SCPrintf(pCon,eLog,"TASKSTART %d", pCon->transID);
if(SCGetTransID(pCon) > 100000) {
SCPrintf(pCon,eLog,"TASKSTART %d", SCGetTransID(pCon));
}
taskData->id = DRIVEID;
@ -415,8 +415,8 @@ static int CountTaskFunc(void *data)
ExeInterest(pServ->pExecutor,taskData->name, "finished with problem");
}
traceSys("count","CountTask %s finished with state %d", taskData->name,status);
if(taskData->pCon->transID > 100000) {
SCPrintf(taskData->pCon,eLog,"TASKEND %d", taskData->pCon->transID);
if(SCGetTransID(taskData->pCon) > 100000) {
SCPrintf(taskData->pCon,eLog,"TASKEND %d", SCGetTransID(taskData->pCon));
}
return 0;
}
@ -443,8 +443,8 @@ long StartCountTask(void *obj, SConnection *pCon, char *name)
}
ExeInterest(pServ->pExecutor,name,"started");
DevexecLog("START",name);
if(pCon->transID > 100000) {
SCPrintf(pCon,eLog,"TASKSTART %d", pCon->transID);
if(SCGetTransID(pCon) > 100000) {
SCPrintf(pCon,eLog,"TASKSTART %d", SCGetTransID(pCon));
}
taskData->id = COUNTID;

View File

@ -171,7 +171,7 @@ static int SicsUnknownProc(ClientData pData, Tcl_Interp * pInter,
}
/* invoke */
pCon->sicsError = 0;
SCSetSicsError(pCon,0);
iMacro = SCinMacro(pCon);
SCsetMacro(pCon, 1);
old = StatisticsBegin(pCommand->stat);
@ -202,7 +202,7 @@ static int SicsUnknownProc(ClientData pData, Tcl_Interp * pInter,
return TCL_OK;
} else {
Tcl_SetVar(pInter, SICSERROR, "yes", TCL_GLOBAL_ONLY);
pCon->sicsError = 1;
SCSetSicsError(pCon,1);
return TCL_ERROR;
}
}

View File

@ -1227,7 +1227,7 @@ static int EndScriptCallback(int iEvent, void *pEvent, void *pUser)
pMotInfo pMoti = (pMotInfo) pUserData;
SConnection *pCon = (SConnection*) context;
if (VerifyConnection(pCon) && VerifyConnection(pMoti->pCon)) {
if (pMoti->pCon->ident == pCon->ident)
if (SCGetIdent(pMoti->pCon) == SCGetIdent(pCon))
return 0;
}
return 1;

View File

@ -118,7 +118,7 @@ int StartRegMot(pMotReg self, SConnection * pCon, float fValue)
pDriv->SetValue = self->originalSetValue;
ret = StartDevice(pServ->pExecutor, self->motorName,
FindDescriptor(self->motorData),
self->motorData, pCon, pCon->runLevel, fValue);
self->motorData, pCon, SCGetRunLevel(pCon), fValue);
/*
snprintf(pBueffel,sizeof(pBueffel)-1,"anticollision started %s to %f",self->motorName,
fValue);

View File

@ -361,7 +361,6 @@ void StopServer(pServer self)
*/
killTclDrivable();
KillFreeConnections();
killSICSHipadaba();

View File

@ -307,8 +307,8 @@ static int ProtocolSet(SConnection * pCon, Protocol * pPro, char *pProName)
SCSetWriteFunc(pCon, pPro->defaultWriter);
break;
}
pCon->iProtocolID = proID;
pMaster->iProtocolID = proID;
SCSetProtocolID(pCon,proID);
SCSetProtocolID(pMaster,proID);
SCSendOK(pCon);
return 1;
}
@ -323,7 +323,7 @@ int ProtocolGet(SConnection * pCon, void *pData, char *pProName, int len)
}
if (pData == NULL) {
pCon->iProtocolID = 0;
SCSetProtocolID(pCon,0);
return 1;
}
@ -331,12 +331,12 @@ int ProtocolGet(SConnection * pCon, void *pData, char *pProName, int len)
if (0 == pPro->isDefaultSet) {
pPro->defaultWriter = SCGetWriteFunc(pCon);
pPro->isDefaultSet = 1;
pCon->iProtocolID = 0;
SCSetProtocolID(pCon,0);
}
strlcpy(pProName, pPro->pProList[pCon->iProtocolID], len);
strlcpy(pProName, pPro->pProList[SCGetProtocolID(pCon)], len);
return 1;
#if 0
Index = pCon->iProtocolID;
Index = SCGetProtocolID(pCon);
/* check list of protocols for valid name */
switch (Index) {
@ -449,7 +449,7 @@ static int InitDefaultProtocol(SConnection * pCon, Protocol * pPro)
if (0 == pPro->isDefaultSet) {
pPro->defaultWriter = SCGetWriteFunc(pCon);
pPro->isDefaultSet = 1;
pCon->iProtocolID = PROTSICS;
SCSetProtocolID(pCon,PROTSICS);
}
return pPro->isDefaultSet;
}
@ -499,7 +499,7 @@ struct json_object *mkJSON_Object(SConnection * pCon, char *pBuffer,
}
/* field 1: connID */
json_object_object_add(msg_json, "con",
json_object_new_int(pCon->ident));
json_object_new_int(SCGetIdent(pCon)));
/* field 2: taskID */
json_object_object_add(msg_json, "trans", json_object_new_int(taskID));
/* deviceID */
@ -566,11 +566,7 @@ int SCWriteJSON_String(SConnection * pCon, char *pBuffer, int iOut)
return 1;
/* log it for any case */
if (pCon->pSock) {
iRet = pCon->pSock->sockid;
} else {
iRet = 0;
}
iRet = SCGetSockHandle(pCon);
/* write to commandlog if user or manager privilege */
if (SCGetRights(pCon) <= usUser && !SCinMacro(pCon)) {
@ -628,13 +624,13 @@ char *GetProtocolName(SConnection * pCon)
InitDefaultProtocol(pCon, pPro);
/* check list of protocols for valid name */
switch (pCon->iProtocolID) {
switch (SCGetProtocolID(pCon)) {
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]);
return strdup(pPro->pProList[SCGetProtocolID(pCon)]);
break;
default:
return strdup("invalid");
@ -645,17 +641,14 @@ char *GetProtocolName(SConnection * pCon)
/*----------------------------------*/
int GetProtocolID(SConnection * pCon)
{
if (NULL != pCon) {
return pCon->iProtocolID;
}
return -1;
return SCGetProtocolID(pCon);
}
/*---------------------------------------------------------------------------*/
writeFunc GetProtocolWriteFunc(SConnection * pCon)
{
if (pCon != NULL) {
switch (pCon->iProtocolID) {
switch (SCGetProtocolID(pCon)) {
case PROTCODE: /* outcodes */
return SCWriteWithOutcode;
break;

View File

@ -294,7 +294,7 @@ static hdbCallbackReturn ProxyCallback(pHdb node, void *userData,
GetHdbProperty(node, "proxy", proxyDev, 80);
status = StartDevice(pServ->pExecutor, proxyDev,
self->pDes, self, pCon,
pCon->runLevel, (float) set->v->v.doubleValue);
SCGetRunLevel(pCon), (float) set->v->v.doubleValue);
if (status == 1) {
return hdbContinue;
} else {

8
scan.c
View File

@ -1308,7 +1308,7 @@ static int ScanUUInterest(int iEvent, void *pEventData, void *pUser)
assert(self);
assert(pCon);
/*
printf("ScanUUInterest called for pCon = %p handle %d\n", pCon, pCon->sockHandle);
printf("ScanUUInterest called for pCon = %p handle %d\n", pCon, SCGetSockHandle(pCon));
*/
if (!SCisConnected(pCon)) {
return -1;
@ -1812,7 +1812,7 @@ int ScanWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
/*-------- interest */
else if (strcmp(argv[1], "interest") == 0) {
/*
printf("Registering scan callbacks on handle %d\n", pCon->sockHandle);
printf("Registering scan callbacks on handle %d\n", SCGetSockHandle(pCon));
*/
lID = RegisterCallback(self->pCall, SCANSTART, ScanInterest,
SCCopyConnection(pCon), SCDeleteConnection);
@ -1826,7 +1826,7 @@ int ScanWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
/*-------- interest */
else if (strcmp(argv[1], "dyninterest") == 0) {
/*
printf("Registering scanDyn callbacks on handle %d\n", pCon->sockHandle);
printf("Registering scanDyn callbacks on handle %d\n", SCGetSockHandle(pCon));
*/
lID = RegisterCallback(self->pCall, SCANSTART, ScanDynInterest,
SCCopyConnection(pCon), SCDeleteConnection);
@ -1841,7 +1841,7 @@ int ScanWrapper(SConnection * pCon, SicsInterp * pSics, void *pData,
else if (strcmp(argv[1], "uuinterest") == 0) {
/*
printf("Registering scanUU callbacks on handle %d, con = %p\n",
conSave->sockHandle, conSave);
SCGetSockHandle(conSave), conSave);
*/
lID = RegisterCallback(self->pCall, SCANSTART, ScanUUInterest,
SCCopyConnection(pCon), SCDeleteConnection);

View File

@ -614,13 +614,13 @@ int MonoRun(pSicsSelector self, SConnection * pCon, float fWaveLength)
/* start each motor in turn */
iRet = StartDevice(GetExecutor(), self->pTheta->name,
self->pTheta->pDescriptor,
self->pTheta, pCon, pCon->runLevel, sNeu.fTheta);
self->pTheta, pCon, SCGetRunLevel(pCon), sNeu.fTheta);
if (!iRet) {
return 0;
}
iRet = StartDevice(GetExecutor(), self->pTwoTheta->name,
self->pTwoTheta->pDescriptor,
self->pTwoTheta, pCon, pCon->runLevel, sNeu.fTwoTheta);
self->pTwoTheta, pCon, SCGetRunLevel(pCon), sNeu.fTwoTheta);
if (!iRet) {
return 0;
}
@ -630,7 +630,7 @@ int MonoRun(pSicsSelector self, SConnection * pCon, float fWaveLength)
if (self->pBend1) {
iRet = StartDevice(GetExecutor(), self->pBend1->name,
self->pBend1->pDescriptor,
self->pBend1, pCon, pCon->runLevel, sNeu.fVert);
self->pBend1, pCon, SCGetRunLevel(pCon), sNeu.fVert);
if (!iRet) {
return 0;
}
@ -639,7 +639,7 @@ int MonoRun(pSicsSelector self, SConnection * pCon, float fWaveLength)
if (self->pBend2) {
iRet = StartDevice(GetExecutor(), self->pBend2->name,
self->pBend2->pDescriptor,
self->pBend2, pCon, pCon->runLevel, sNeu.fHor);
self->pBend2, pCon, SCGetRunLevel(pCon), sNeu.fHor);
if (!iRet) {
return 0;
}

View File

@ -316,7 +316,7 @@ static hdbCallbackReturn SICSDriveCallback(pHdb node, void *userData,
userData, pCon, RUNDRIVE, (float) v.v.doubleValue);
} else {
status = StartDevice(pServ->pExecutor, node->name, dum->pDescriptor,
userData, pCon, pCon->runLevel, (float) v.v.doubleValue);
userData, pCon, SCGetRunLevel(pCon), (float) v.v.doubleValue);
}
if (status == 1) {
return hdbContinue;
@ -617,7 +617,7 @@ static hdbCallbackReturn SICSNotifyCallback(pHdb node, void *userData,
}
if ((cmm = GetKillPtrMessage(message)) != NULL) {
tstCon = cmm->pPtr;
if (tstCon != NULL && tstCon->ident == cbInfo->pCon->ident) {
if (tstCon != NULL && SCGetIdent(tstCon) == SCGetIdent(cbInfo->pCon)) {
return hdbKill;
} else {
return hdbContinue;
@ -769,7 +769,7 @@ static hdbCallbackReturn TreeChangeCallback(pHdb node, void *userData,
}
if ((cmm = GetKillPtrMessage(message)) != NULL) {
tstCon = cmm->pPtr;
if (tstCon != NULL && tstCon->ident == cbInfo->pCon->ident) {
if (tstCon != NULL && SCGetIdent(tstCon) == SCGetIdent(cbInfo->pCon)) {
return hdbKill;
} else {
return hdbContinue;
@ -2769,7 +2769,7 @@ static int BinReadHdbNode(SConnection *pCon, SicsInterp *pSics,
return 0;
}
if(data != NULL){
ANETwrite(pCon->sockHandle,data,(val.arrayLength+2)*sizeof(int));
ANETwrite(SCGetSockHandle(pCon),data,(val.arrayLength+2)*sizeof(int));
free(data);
}

View File

@ -305,7 +305,7 @@ int StateMonFactory(SConnection * pCon, SicsInterp * pSics, void *pData,
SConnection *pKon = (SConnection*) pUserData;
SConnection *pCon = (SConnection*) context;
if (VerifyConnection(pCon) && VerifyConnection(pKon)) {
if (pCon->ident == pKon->ident)
if (SCGetIdent(pCon) == SCGetIdent(pKon))
return 0;
}
return 1;

View File

@ -118,14 +118,6 @@ void KillStatus(void *pData)
/*--------------------------------------------------------------------------*/
void SetStatus(Status eNew)
{
/* if (!fixed) {
if (eCode == eNew) {
return;
}
eCode = eNew;
InvokeCallBack(pCall, VALUECHANGE, NULL);
}
*/
/*
This now only manages the userWait status
*/
@ -141,12 +133,7 @@ void SetStatus(Status eNew)
/*----------------------------------------------------------------------*/
void SetStatusFixed(Status eNew)
{
// if (eCode == eNew) {
// return;
// }
// eCode = eNew;
// InvokeCallBack(pCall, VALUECHANGE, NULL);
// fixed = 1;
/* pass */
}
/*----------------------------------------------------------------------*/
@ -309,57 +296,6 @@ int ResetStatus(SConnection * pCon, SicsInterp * pSics, void *pData,
return 1;
}
/* ===================== Control Connection Management ====================*/
static SConnection *pOwner = NULL;
void SetControl(SConnection * pCon)
{
pOwner = pCon;
}
/*--------------------------------------------------------------------------*/
int IsControl(SConnection * pCon)
{
if (pCon == pOwner) {
return 1;
} else {
return 0;
}
}
/*--------------------------------------------------------------------------*/
SConnection *GetControl(void)
{
return pOwner;
}
/*--------------------------------------------------------------------------*/
int RedirectControl(SConnection * pCon, SicsInterp * pSics, void *pData,
int argc, char *argv[])
{
assert(pCon);
assert(pSics);
/* check user Rights */
if (!SCMatchRights(pCon, usUser)) {
SCWrite(pCon,
"You have NO, I repeat NO, Privilege to grab a control connection",
eError);
return 0;
}
/* check if the connection is dead at all */
if (pCon->sockHandle < 0) {
SCWrite(pCon,
"GOTCHA!!! Control still lives! You CANNOT grab it! FUCK OFF",
eError);
return 0;
}
/* now the wizardry */
pOwner->sockHandle = pCon->sockHandle;
return 1;
}
/*----------------------------------------------------------------------------
Message pipe based new status calculation code
------------------------------------------------------------------------------*/

View File

@ -370,13 +370,13 @@ int RestoreStatus(SConnection * pCon, SicsInterp * pSics, void *pData,
LLDdeleteBlob(self->errList);
self->errList = LLDstringCreate();
iRights = SCGetRights(pCon);
pCon->iUserRights = usInternal;
SCSetRights(pCon,usInternal);
oldWrite = SCGetWriteFunc(pCon);
SCSetWriteFunc(pCon, SCNotWrite);
iRet = exeBufProcessErrList(buffi, pSics, pCon, self->errList);
restoreOccurred = 1;
SCSetWriteFunc(pCon, oldWrite);
pCon->iUserRights = iRights;
SCSetRights(pCon,iRights);
exeBufDelete(buffi);
/*
if we do not override parameterChange here, the backup file

120
telnet.c
View File

@ -99,113 +99,6 @@ static void SendGA(SConnection * pCon)
NETWrite(pCon->pSock, pReply, 2);
}
/*--------------------------------------------------------------------------*/
int TelnetTaskOld(void *pData)
{
pTelTask self = NULL;
char *pPtr = NULL;
char *pLogin = NULL;
char *pUser = NULL, *pPasswd = NULL;
char pBuffer[512], pHost[131];
int iRet;
time_t shit;
self = (pTelTask) pData;
assert(self);
if (self->pCon->iEnd) {
if (SCActive(self->pCon)) {
return 1;
} else {
return 0;
}
}
/* pop and execute */
iRet = CostaPop(self->pCon->pStack, &pPtr);
if (iRet) {
if (pPtr) {
if (self->iLogin) { /* handle normal command */
/* check for logoff */
if (strstr(pPtr, "logoff") != NULL) {
NetReadRemove(pServ->pReader, self->pCon->pSock);
free(pPtr);
self->pCon->iEnd = 1;
return 0;
}
/* invoke command */
CostaLock(self->pCon->pStack);
SCInvoke(self->pCon, pServ->pSics, pPtr);
CostaUnlock(self->pCon->pStack);
SendGA(self->pCon);
free(pPtr);
} else { /* handle login messages */
pLogin = strstr(pPtr, self->pLoginWord);
if (!pLogin) {
SCWrite(self->pCon,
"------------------- Get Lost -------------------",
eError);
if (time(&shit) > self->tStart + LOGINWAIT) {
SCWrite(self->pCon,
"I cannot stand your login attempts anymore!", eError);
NetReadRemove(pServ->pReader, self->pCon->pSock);
self->pCon->iEnd = 1;
free(pPtr);
return 0;
}
free(pPtr);
return 1;
} else { /* check username / password */
pLogin += strlen(self->pLoginWord);
pUser = strtok(pLogin, " \t");
pPasswd = strtok(NULL, " \t\r\n");
iRet = IsValidUser(pUser, pPasswd);
if (iRet < 0) {
snprintf(pBuffer,sizeof(pBuffer)-1, "SYSTEM ATTACK by %s / %s", pUser, pPasswd);
Log(FATAL,"sys","%s",pBuffer);
SCWrite(self->pCon,
"I do not know you, I do not let you in", eError);
SendGA(self->pCon);
free(pPtr);
return 1;
} else {
NETInfo(self->pCon->pSock, pHost, 131);
snprintf(pBuffer,sizeof(pBuffer)-1, "Accepted connection on socket %d from %s",
self->pCon->pSock->sockid, pHost);
Log(INFO,"com",pBuffer);
SendWelcome(self->pCon);
SCSetRights(self->pCon, iRet);
self->iLogin = 1;
SendGA(self->pCon);
free(pPtr);
return 1;
}
}
}
}
}
/* check for no commands but timeout on telnet */
if (!self->iLogin && (time(&shit) > self->tStart + LOGINWAIT)) {
self->pCon->iEnd = 1;
NetReadRemove(pServ->pReader, self->pCon->pSock);
return 0;
}
/* check for end */
if (self->pCon->iEnd) {
if (SCActive(self->pCon)) {
return 1;
} else {
return 0;
}
}
return 1;
}
/*--------------------------------------------------------------------------*/
int TelnetTask(void *pData)
{
@ -357,18 +250,6 @@ void InstallTelnet(void)
return;
}
i = sscanf(pPtr, "%d", &iPort);
/*
if(i > 0)
{
pTelnet = NETOpenPort(iPort);
}
if(pTelnet)
{
NetReadRegister(pServ->pReader,pTelnet, taccept, NULL);
}
*/
/* when we have a port have the NetReader listen and handle it */
NetReadInstallANETPort(pServ->pReader, taccept, iPort);
}
@ -378,7 +259,6 @@ void KillTelnet(void)
{
if (pTelnet) {
NETClosePort(pTelnet);
/* NetReadRemove(pServ->pReader,pTelnet); */
free(pTelnet);
pTelnet = NULL;
}