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

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;
}