- added SCPf function (general SCPrintf)
- removed sendingConnection stuff (no longer used) - removed COMLOG Signal handling (no longer used)
This commit is contained in:
65
conman.c
65
conman.c
@ -85,6 +85,8 @@
|
|||||||
extern struct json_object *mkJSON_Object(SConnection * pCon, char *pBuffer,
|
extern struct json_object *mkJSON_Object(SConnection * pCon, char *pBuffer,
|
||||||
int iOut);
|
int iOut);
|
||||||
|
|
||||||
|
/* from loglisten.c */
|
||||||
|
void LogListenRegister(SConnection * pCon);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#define UUDEB 1
|
#define UUDEB 1
|
||||||
@ -117,9 +119,6 @@ typedef struct {
|
|||||||
/*------------- a number for generating automatic names --------------------*/
|
/*------------- a number for generating automatic names --------------------*/
|
||||||
static int iName = 0;
|
static int iName = 0;
|
||||||
static long lastIdent = 0;
|
static long lastIdent = 0;
|
||||||
/*------------- sending connection (prevent double write when listening) ----*/
|
|
||||||
static SConnection *sendingConnection = NULL;
|
|
||||||
static int sendingSockHandle = 0;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This will return the value of a SICS int variable called "sicsdebug"
|
* This will return the value of a SICS int variable called "sicsdebug"
|
||||||
@ -165,24 +164,7 @@ static void FreeConnection(SConnection * pCon)
|
|||||||
free(pCon);
|
free(pCon);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
SConnection *GetSendingConnection(void)
|
|
||||||
{
|
|
||||||
return sendingConnection;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
static void SetSendingConnection(SConnection *pCon)
|
|
||||||
{
|
|
||||||
sendingConnection = pCon;
|
|
||||||
if (pCon) {
|
|
||||||
sendingSockHandle = pCon->sockHandle;
|
|
||||||
} else {
|
|
||||||
sendingSockHandle = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
|
||||||
static SConnection *SCMakeConnection()
|
static SConnection *SCMakeConnection()
|
||||||
{
|
{
|
||||||
SConnection *pRes = NULL;
|
SConnection *pRes = NULL;
|
||||||
@ -656,6 +638,35 @@ int SCPrintf(SConnection * self, int iOut, char *fmt, ...)
|
|||||||
return SCWrite(self, buf, iOut);
|
return SCWrite(self, buf, iOut);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*-------------------------------------------------------------------------*/
|
||||||
|
int SCPf(writeFunc func, SConnection * self, int iOut, char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
char buf[256];
|
||||||
|
char *dyn;
|
||||||
|
unsigned int l;
|
||||||
|
int res;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
l = vsnprintf(buf, sizeof buf, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
if (l >= sizeof buf) {
|
||||||
|
/* we have probably a C99 conforming snprintf and
|
||||||
|
need a larger buffer
|
||||||
|
*/
|
||||||
|
dyn = malloc(l + 1);
|
||||||
|
if (dyn != NULL) {
|
||||||
|
va_start(ap, fmt);
|
||||||
|
vsnprintf(dyn, l + 1, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
res = func(self, dyn, iOut);
|
||||||
|
free(dyn);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return func(self, buf, iOut);
|
||||||
|
}
|
||||||
|
|
||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
writeFunc SCGetWriteFunc(SConnection * self)
|
writeFunc SCGetWriteFunc(SConnection * self)
|
||||||
{
|
{
|
||||||
@ -1072,9 +1083,7 @@ int SCLogWrite(SConnection * self, char *buffer, int iOut)
|
|||||||
if (!VerifyConnection(self)) {
|
if (!VerifyConnection(self)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
SetSendingConnection(self);
|
Log(INFO,"com","sock%03.3d:%s", self->sockHandle, buffer);
|
||||||
Log(INFO,"com","sock%03.3d%s", self->sockHandle, buffer);
|
|
||||||
SetSendingConnection(NULL);
|
|
||||||
|
|
||||||
if(self->iProtocolID == PROTACT) { /* act */
|
if(self->iProtocolID == PROTACT) { /* act */
|
||||||
if (strlen(buffer) + 30 > 1024) {
|
if (strlen(buffer) + 30 > 1024) {
|
||||||
@ -1627,7 +1636,6 @@ int SCInvoke(SConnection * self, SicsInterp * pInter, char *pCommand)
|
|||||||
* case
|
* case
|
||||||
*/
|
*/
|
||||||
if (SCGetWriteFunc(self) != SCNotWrite) {
|
if (SCGetWriteFunc(self) != SCNotWrite) {
|
||||||
SetSendingConnection(self);
|
|
||||||
if (self->sockHandle >= 0) {
|
if (self->sockHandle >= 0) {
|
||||||
if(strstr(pCommand,"Poch") == NULL){
|
if(strstr(pCommand,"Poch") == NULL){
|
||||||
Log(INFO,"com","sock%03.3d:",self->sockHandle, pCommand);
|
Log(INFO,"com","sock%03.3d:",self->sockHandle, pCommand);
|
||||||
@ -1635,7 +1643,6 @@ int SCInvoke(SConnection * self, SicsInterp * pInter, char *pCommand)
|
|||||||
} else {
|
} else {
|
||||||
Log(INFO,"sys","CRON:%s", pCommand);
|
Log(INFO,"sys","CRON:%s", pCommand);
|
||||||
}
|
}
|
||||||
SetSendingConnection(NULL);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1738,6 +1745,7 @@ int ConfigCon(SConnection * pCon, SicsInterp * pSics, void *pData,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
pMaster->listening = pCon->listening;
|
pMaster->listening = pCon->listening;
|
||||||
|
LogListenRegister(pMaster);
|
||||||
SCSendOK(pCon);
|
SCSendOK(pCon);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -2251,11 +2259,6 @@ void SCSignalFunction(void *pData, int iSignal, void *pSigData)
|
|||||||
if (pPtr != NULL) {
|
if (pPtr != NULL) {
|
||||||
SCPureSockWrite(self, pPtr, eWarning);
|
SCPureSockWrite(self, pPtr, eWarning);
|
||||||
}
|
}
|
||||||
} else if (iSignal == COMLOG && self->listening == 1) {
|
|
||||||
pPtr = (char *) pSigData;
|
|
||||||
if (pPtr != NULL && self->sockHandle != sendingSockHandle) {
|
|
||||||
doSockWrite(self, pPtr);
|
|
||||||
}
|
|
||||||
} else if (iSignal == TOKENRELEASE) {
|
} else if (iSignal == TOKENRELEASE) {
|
||||||
self->iGrab = 0;
|
self->iGrab = 0;
|
||||||
} else if (iSignal == TOKENGRAB) {
|
} else if (iSignal == TOKENGRAB) {
|
||||||
|
1
conman.h
1
conman.h
@ -100,6 +100,7 @@ int SCWrite(SConnection * self, char *pBuffer, int iOut);
|
|||||||
#define G_GNUC_PRINTF( format_idx, arg_idx )
|
#define G_GNUC_PRINTF( format_idx, arg_idx )
|
||||||
#endif
|
#endif
|
||||||
int SCPrintf(SConnection * self, int iOut, char *fmt, ...) G_GNUC_PRINTF (3, 4);
|
int SCPrintf(SConnection * self, int iOut, char *fmt, ...) G_GNUC_PRINTF (3, 4);
|
||||||
|
int SCPf(writeFunc func, SConnection * self, int iOut, char *fmt, ...) G_GNUC_PRINTF (4, 5);
|
||||||
#undef G_GNUC_PRINTF
|
#undef G_GNUC_PRINTF
|
||||||
int SCRead(SConnection * self, char *pBuffer, int iBufLen);
|
int SCRead(SConnection * self, char *pBuffer, int iBufLen);
|
||||||
int SCPrompt(SConnection * pCon, char *pPrompt, char *pResult, int iLen);
|
int SCPrompt(SConnection * pCon, char *pPrompt, char *pResult, int iLen);
|
||||||
|
Reference in New Issue
Block a user