Merge branch 'conclean' into rhel7
Conflicts: SCinter.c telnet.c
This commit is contained in:
338
conman.c
338
conman.c
@ -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)
|
||||
{
|
||||
@ -2331,117 +2282,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)
|
||||
{
|
||||
@ -2501,3 +2341,171 @@ int SCPopContext(SConnection * pCon)
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
/*--------------------------------------------------------*/
|
||||
int SCGetRunLevel(SConnection *pCon)
|
||||
{
|
||||
if (!VerifyConnection(pCon)) {
|
||||
return 0;
|
||||
}
|
||||
return pCon->runLevel;
|
||||
}
|
||||
/*--------------------------------------------------------*/
|
||||
long 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;
|
||||
}
|
||||
/*-------------------------------------------------------*/
|
||||
int SCGetEnd(SConnection *pCon)
|
||||
{
|
||||
if (!VerifyConnection(pCon)) {
|
||||
return 0;
|
||||
}
|
||||
return pCon->iEnd;
|
||||
}
|
||||
/*-------------------------------------------------------*/
|
||||
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;
|
||||
}
|
||||
/*--------------------------------------------------------*/
|
||||
void SCCostaLock(SConnection *pCon)
|
||||
{
|
||||
if (!VerifyConnection(pCon)) {
|
||||
return;
|
||||
}
|
||||
CostaLock(pCon->pStack);
|
||||
}
|
||||
/*---------------------------------------------------------*/
|
||||
void SCCostaUnLock(SConnection *pCon){
|
||||
if (!VerifyConnection(pCon)) {
|
||||
return;
|
||||
}
|
||||
CostaUnlock(pCon->pStack);
|
||||
}
|
||||
/*---------------------------------------------------------*/
|
||||
int SCCostaLocked(SConnection *pCon)
|
||||
{
|
||||
if (!VerifyConnection(pCon)) {
|
||||
return 0;
|
||||
}
|
||||
return CostaLocked(pCon->pStack);
|
||||
}
|
||||
/*----------------------------------------------------------*/
|
||||
int SCCostaTop(SConnection *pCon, char *command)
|
||||
{
|
||||
if (!VerifyConnection(pCon)) {
|
||||
return 0;
|
||||
}
|
||||
return CostaTop(pCon->pStack, command);
|
||||
}
|
||||
/*----------------------------------------------------------*/
|
||||
void SCSetGrab(SConnection *pCon, int iGrab)
|
||||
{
|
||||
if (!VerifyConnection(pCon)) {
|
||||
return;
|
||||
}
|
||||
pCon->iGrab = iGrab;
|
||||
}
|
||||
/*------------------------------------------------------------*/
|
||||
void SCSetEnd(SConnection *pCon, int val)
|
||||
{
|
||||
if (!VerifyConnection(pCon)) {
|
||||
return;
|
||||
}
|
||||
pCon->iEnd = val;
|
||||
}
|
||||
/*------------------------------------------------------------*/
|
||||
void SCSetTelnet(SConnection *pCon, int val)
|
||||
{
|
||||
if (!VerifyConnection(pCon)) {
|
||||
return;
|
||||
}
|
||||
pCon->iTelnet = val;
|
||||
}
|
||||
/*------------------------------------------------------------*/
|
||||
void SCClose(SConnection *pCon)
|
||||
{
|
||||
if (!VerifyConnection(pCon)) {
|
||||
return;
|
||||
}
|
||||
ANETclose(pCon->sockHandle);
|
||||
pCon->iEnd = 1;
|
||||
}
|
||||
|
Reference in New Issue
Block a user