- Added a listen mode to commandlog in order to support the batchEditor - Some small fixes to exe* for BatchEditor
160 lines
6.8 KiB
C
160 lines
6.8 KiB
C
|
|
/*--------------------------------------------------------------------------
|
|
C O N N E C T I O N O B J E C T
|
|
|
|
This file defines the connection object data structure and the interface to
|
|
this data structure. This is one of the most important SICS components.
|
|
|
|
|
|
Substantially revised from a prior version.
|
|
|
|
Mark Koennecke, September 1997
|
|
|
|
Mark Koennecke, Aprl 2003
|
|
|
|
Mark Koennecke, December 2004
|
|
|
|
copyright: see copyright.h
|
|
----------------------------------------------------------------------------*/
|
|
#ifndef SICSCONNECT
|
|
#define SICSCONNECT
|
|
#include <stdio.h>
|
|
#include "costa.h"
|
|
#include "SCinter.h"
|
|
#include "network.h"
|
|
#include "obdes.h"
|
|
|
|
#define MAXLOGFILES 10
|
|
|
|
typedef int (*writeFunc)(struct __SConnection *pCon,
|
|
char *pMessage, int iCode);
|
|
|
|
typedef struct __SConnection {
|
|
/* object basics */
|
|
pObjectDescriptor pDes;
|
|
long lMagic;
|
|
long ident;
|
|
struct __SConnection *next;
|
|
|
|
/* I/O control */
|
|
/* our socket */
|
|
mkChannel *pSock;
|
|
|
|
/* per connection log files */
|
|
FILE *pFiles[MAXLOGFILES];
|
|
int iFiles;
|
|
|
|
int iMacro; /* suppress I/O in macro*/
|
|
int iTelnet; /* telnet flag */
|
|
int iOutput;
|
|
writeFunc write; /* function doing
|
|
writing */
|
|
int listening; /* for listening to commandlog or other data */
|
|
|
|
/* execution context */
|
|
int eInterrupt;
|
|
int iUserRights;
|
|
int inUse;
|
|
int iGrab; /* grab flag for token*/
|
|
int parameterChange;
|
|
int sicsError;
|
|
|
|
/* a FIFO */
|
|
pCosta pStack;
|
|
|
|
/* callback registry */
|
|
int iList;
|
|
|
|
/* Tasking Stuff */
|
|
int iEnd;
|
|
/* for keeping track of the login
|
|
process on a non telnet connection.
|
|
Should only be used in SCTaskFunction
|
|
*/
|
|
int iLogin;
|
|
time_t conStart;
|
|
} SConnection;
|
|
|
|
#include "nserver.h"
|
|
|
|
/*------------------------------ live & death ----------------------------*/
|
|
SConnection *SCreateConnection(SicsInterp *pSics, mkChannel *pSock,
|
|
int iUserRights);
|
|
SConnection *SCCreateDummyConnection(SicsInterp *pSics);
|
|
void SCDeleteConnection(void *pVictim);
|
|
|
|
/*------------------------------- tasking --------------------------------*/
|
|
int SCTaskFunction(void *pCon);
|
|
void SCSignalFunction(void *pCon, int iSignal, void *pSigData);
|
|
/* ***************************** I/O ************************************** */
|
|
int SCAddLogFile(SConnection *self, char *name);
|
|
int SCDelLogFile(SConnection *pCon, int iFile);
|
|
void SCSetOutputClass(SConnection *self, int iClass);
|
|
int SCWrite(SConnection *self, char *pBuffer, int iOut);
|
|
int SCPrintf(SConnection *self, int iOut, char *fmt, ...);
|
|
int SCRead(SConnection *self, char *pBuffer, int iBufLen);
|
|
int SCPrompt(SConnection *pCon, char *pPrompt, char *pResult, int iLen);
|
|
int SCSendOK(SConnection *self);
|
|
int SCnoSock(SConnection *pCon);
|
|
int SCWriteUUencoded(SConnection *pCon, char *pName, void *iData, int iLen);
|
|
int SCWriteZipped(SConnection *pCon, char *pName, void *pData, int iDataLen);
|
|
writeFunc SCGetWriteFunc(SConnection *pCon);
|
|
void SCSetWriteFunc(SConnection *pCon, writeFunc x);
|
|
int SCOnlySockWrite(SConnection *self, char *buffer, int iOut);
|
|
int SCFileWrite(SConnection *self, char *buffer, int iOut);
|
|
int SCNotWrite(SConnection *self, char *buffer, int iOut);
|
|
/************************* CallBack *********************************** */
|
|
int SCRegister(SConnection *pCon, SicsInterp *pSics,
|
|
void *pInter, long lID);
|
|
int SCUnregister(SConnection *pCon, void *pInter);
|
|
/**
|
|
* delete a callback with the given ID
|
|
*/
|
|
int SCUnregisterID(SConnection *pCon, long ID);
|
|
/**
|
|
* retrieve the ID of a callback on the callback interface
|
|
* given in pData. This, together with SCUnregisterID allows to
|
|
* ceanly remove all callbacks on a connection
|
|
* returns -1 if no ID can be found.
|
|
*/
|
|
long SCgetCallbackID(SConnection *pCon, void *pData);
|
|
/******************************* Error **************************************/
|
|
void SCSetInterrupt(SConnection *self, int eCode);
|
|
int SCGetInterrupt(SConnection *self);
|
|
/****************************** Macro ***************************************/
|
|
int SCinMacro(SConnection *pCon);
|
|
int SCsetMacro(SConnection *pCon, int iMode);
|
|
/************************** parameters changed ? **************************/
|
|
void SCparChange(SConnection *pCon);
|
|
/* *************************** Info *************************************** */
|
|
int SCGetRights(SConnection *self);
|
|
int SCSetRights(SConnection *pCon, int iNew);
|
|
int SCMatchRights(SConnection *pCon, int iCode);
|
|
int SCGetOutClass(SConnection *self);
|
|
int SCGetGrab(SConnection *pCon);
|
|
int SCActive(SConnection *pCon);
|
|
/********************* simulation mode ************************************/
|
|
void SCSetSimMode(SConnection *pCon, int value);
|
|
int SCinSimMode(SConnection *pCon);
|
|
/* **************************** Invocation ******************************** */
|
|
int SCInvoke(SConnection *self,SicsInterp *pInter,char *pCommand);
|
|
|
|
/*************************** User Command **********************************/
|
|
int ConfigCon(SConnection *pCon, SicsInterp *pSics, void *pData,
|
|
int argc, char *argv[]);
|
|
int ConSicsAction(SConnection *pCon, SicsInterp *pSics, void *pData,
|
|
int argc, char *argv[]);
|
|
/******************************** Store ************************************/
|
|
typedef struct {
|
|
SConnection *pCon;
|
|
long ident;
|
|
} SCStore;
|
|
|
|
void SCSave(SCStore *con, SConnection *pCon);
|
|
/* save a connection for later use. */
|
|
|
|
SConnection *SCLoad(SCStore *con);
|
|
/* check con and return SConnection if still valid or NULL otherwise. */
|
|
|
|
#endif
|