Further enhancements to the new logging system
I removed traceCommand because I needed a more fine grained control of what goes into the log.
This commit is contained in:
178
conman.c
178
conman.c
@ -803,9 +803,18 @@ static int isOK(const char *buffer)
|
||||
/*--------------------------------------------------------------------------*/
|
||||
static void testAndWriteLog(SConnection * self, char *buffer, int iOut)
|
||||
{
|
||||
unsigned int severity;
|
||||
|
||||
/*
|
||||
first those which allways go into the log
|
||||
*/
|
||||
|
||||
if(SCGetRights(self) > usUser) {
|
||||
severity = DEBUG;
|
||||
} else {
|
||||
severity = INFO;
|
||||
}
|
||||
|
||||
switch(iOut){
|
||||
case eInternal:
|
||||
Log(ERROR,"sys","%s",buffer);
|
||||
@ -836,24 +845,32 @@ static void testAndWriteLog(SConnection * self, char *buffer, int iOut)
|
||||
Log(INFO,"notify","%s",buffer);
|
||||
break;
|
||||
case eLog:
|
||||
Log(INFO,"com","sock%03.3d:%s",self->sockHandle,buffer);
|
||||
Log(severity,"com","sock%03.3d:%s",self->sockHandle,buffer);
|
||||
break;
|
||||
case eLogError:
|
||||
Log(ERROR,"com","sock%03.3d:%s",self->sockHandle,buffer);
|
||||
break;
|
||||
case eError:
|
||||
if(!SCinMacro(self)){
|
||||
Log(ERROR,"com","sock%03.3d:%s",self->sockHandle,buffer);
|
||||
if(severity == DEBUG){
|
||||
Log(DEBUG,"com","sock%03.3d:%s",self->sockHandle,buffer);
|
||||
} else {
|
||||
Log(ERROR,"com","sock%03.3d:%s",self->sockHandle,buffer);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case eWarning:
|
||||
if(!SCinMacro(self)){
|
||||
Log(WARN,"com","sock%03.3d:%s",self->sockHandle,buffer);
|
||||
if(severity == DEBUG){
|
||||
Log(DEBUG,"com","sock%03.3d:%s",self->sockHandle,buffer);
|
||||
} else {
|
||||
Log(WARN,"com","sock%03.3d:%s",self->sockHandle,buffer);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case eValue:
|
||||
if(!SCinMacro(self)){
|
||||
Log(INFO,"com","sock%03.3d:%s",self->sockHandle,buffer);
|
||||
Log(severity,"com","sock%03.3d:%s",self->sockHandle,buffer);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -1223,7 +1240,7 @@ int SCWriteUUencoded(SConnection * pCon, char *pName, void *pData,
|
||||
ANETwrite(pCon->sockHandle, pPtr, iLength);
|
||||
}
|
||||
|
||||
traceCommand(ConID(pCon),"out:UUData %s %d", pName, iLength);
|
||||
Log(DEBUG,"com","%s:out:UUData %s %d",ConID(pCon) ,pName, iLength);
|
||||
|
||||
|
||||
#ifdef UUDEB
|
||||
@ -1326,7 +1343,7 @@ int SCWriteZipped(SConnection * self, char *pName, void *pData,
|
||||
SCWrite(self, "ERROR: out of memory in SCWriteZipped", eError);
|
||||
return 0;
|
||||
}
|
||||
traceCommand(ConID(self),"out:SICSBIN ZIP %s %d", pName, compressedLength);
|
||||
Log(DEBUG,"com", "%s:out:SICSBIN ZIP %s %d", ConID(self), pName, compressedLength);
|
||||
|
||||
|
||||
iRet = ANETwrite(self->sockHandle, pHeader, strlen(pHeader));
|
||||
@ -1401,7 +1418,7 @@ int SCWriteBinary(SConnection * self, char *pName, void *pData,
|
||||
SCWrite(self, "ERROR: out of memory in SCWriteBinary", eError);
|
||||
return 0;
|
||||
}
|
||||
traceCommand(ConID(self),"out:SICSBIN BIN %s %d", pName, iDataLen);
|
||||
Log(DEBUG,"com","%s:out:SICSBIN BIN %s %d", ConID(self), pName, iDataLen);
|
||||
|
||||
iRet = ANETwrite(self->sockHandle, pHeader, strlen(pHeader));
|
||||
iRet = ANETwrite(self->sockHandle, pData, iDataLen);
|
||||
@ -1416,147 +1433,6 @@ int SCWriteBinary(SConnection * self, char *pName, void *pData,
|
||||
|
||||
return 1;
|
||||
}
|
||||
/*--------------------------------------------------------------
|
||||
* left in for documentation............
|
||||
*/
|
||||
int SCWriteZippedOld(SConnection * self, char *pName, void *pData,
|
||||
int iDataLen)
|
||||
{
|
||||
char outBuf[65546], *pBuf = NULL, noutBuf[ZIPBUF], *pHeader = NULL;
|
||||
int compressedLength, iRet, iRet2, iCount, protocolID;
|
||||
z_stream compStream;
|
||||
commandContext cc;
|
||||
|
||||
/* check for a valid connection */
|
||||
if (!VerifyConnection(self)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* a telnet connection will corrupt the compressed stream, so
|
||||
stop it!
|
||||
*/
|
||||
if (self->iTelnet) {
|
||||
SCWrite(self,
|
||||
"ERROR: the telnet protocoll will corrupt compressed data!",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
do nothing if no data
|
||||
*/
|
||||
if (pName == NULL || pData == NULL) {
|
||||
SCWrite(self, "ERROR: no data to write in SCWriteZiped", eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* initialize the compression stuff */
|
||||
compStream.zalloc = (alloc_func) NULL;
|
||||
compStream.zfree = (free_func) NULL;
|
||||
compStream.opaque = (voidpf) NULL;
|
||||
|
||||
iRet = deflateInit(&compStream, Z_DEFAULT_COMPRESSION);
|
||||
if (iRet != Z_OK) {
|
||||
sprintf(outBuf, "ERROR: zlib error: %d", iRet);
|
||||
SCWrite(self, outBuf, eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* first pass: find out how the long the compressed buffer will be */
|
||||
compressedLength = 0;
|
||||
compStream.next_in = (Bytef *) pData;
|
||||
compStream.next_out = (Bytef *) outBuf;
|
||||
compStream.avail_in = iDataLen;
|
||||
compStream.avail_out = 65536;
|
||||
while (compStream.total_in < iDataLen) {
|
||||
iRet = deflate(&compStream, Z_NO_FLUSH);
|
||||
if (iRet != Z_OK) {
|
||||
sprintf(outBuf, "ERROR: zlib error: %d", iRet);
|
||||
SCWrite(self, outBuf, eError);
|
||||
return 0;
|
||||
}
|
||||
compStream.next_out = (Bytef *) outBuf;
|
||||
compStream.avail_out = 65536;
|
||||
}
|
||||
for (;;) {
|
||||
iRet = deflate(&compStream, Z_FINISH);
|
||||
if (iRet == Z_STREAM_END)
|
||||
break;
|
||||
if (iRet != Z_OK) {
|
||||
sprintf(outBuf, "ERROR: zlib error: %d", iRet);
|
||||
SCWrite(self, outBuf, eError);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
compressedLength = compStream.total_out;
|
||||
deflateEnd(&compStream);
|
||||
|
||||
/* write header line */
|
||||
memset(outBuf, 0, 65536);
|
||||
|
||||
protocolID = GetProtocolID(self);
|
||||
if (protocolID == PROTACT) {
|
||||
cc = SCGetContext(self);
|
||||
sprintf(outBuf, "SICSBIN ZIP %s %d %d\r\n", pName,
|
||||
compressedLength, cc.transID);
|
||||
} else {
|
||||
sprintf(outBuf, "SICSBIN ZIP %s %d \r\n", pName, compressedLength);
|
||||
}
|
||||
pHeader = strdup(outBuf);
|
||||
if (pHeader == NULL) {
|
||||
SCWrite(self, "ERROR: out of memory in SCWriteZipped", eError);
|
||||
return 0;
|
||||
}
|
||||
traceCommand(ConID(self),"out:SICSBIN ZIP %s %d", pName, compressedLength);
|
||||
|
||||
|
||||
/* now reset the deflater and do the same with writing data */
|
||||
compStream.zalloc = (alloc_func) NULL;
|
||||
compStream.zfree = (free_func) NULL;
|
||||
compStream.opaque = (voidpf) NULL;
|
||||
|
||||
|
||||
/*
|
||||
This is writing everything in one go as I found that writing in
|
||||
several chunks did not ensure that all the data arrived at the
|
||||
Java side.
|
||||
*/
|
||||
|
||||
iRet = deflateInit(&compStream, Z_DEFAULT_COMPRESSION);
|
||||
if (iRet != Z_OK) {
|
||||
sprintf(outBuf, "ERROR: zlib error: %d", iRet);
|
||||
SCWrite(self, outBuf, eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
pBuf = (char *) malloc((iDataLen + iDataLen / 10 + 50) * sizeof(char));
|
||||
memset(pBuf, 0, (iDataLen + iDataLen / 10 + 50) * sizeof(char));
|
||||
compStream.next_in = (Bytef *) pData;
|
||||
compStream.next_out = (Bytef *) pBuf;
|
||||
compStream.avail_in = iDataLen;
|
||||
compStream.avail_out = iDataLen + iDataLen / 10 + 50;
|
||||
iRet = deflate(&compStream, Z_FINISH);
|
||||
if (iRet != Z_STREAM_END) {
|
||||
sprintf(outBuf, "ERROR: zlib error: %d", iRet);
|
||||
SCWrite(self, outBuf, eError);
|
||||
return 0;
|
||||
}
|
||||
iRet = ANETwrite(self->sockHandle, pHeader, strlen(pHeader));
|
||||
iRet = ANETwrite(self->sockHandle, pBuf, compStream.total_out);
|
||||
if (iRet != 1) {
|
||||
sprintf(outBuf, "ERROR: network error %d on zipped send", iRet);
|
||||
SCWrite(self, outBuf, eError);
|
||||
return 0;
|
||||
}
|
||||
/* printf("Sent zipped data: %s with %d\n", pHeader, iRet); */
|
||||
|
||||
deflateEnd(&compStream);
|
||||
free(pHeader);
|
||||
free(pBuf);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
int SCSendOK(SConnection * self)
|
||||
{
|
||||
@ -1831,7 +1707,11 @@ int SCInvoke(SConnection * self, SicsInterp * pInter, char *pCommand)
|
||||
return 0;
|
||||
}
|
||||
strlcpy(pCopy->deviceID, pBueffel, SCDEVIDLEN);
|
||||
traceCommand(ConID(self),"in:%s", pCommand);
|
||||
if(SCGetRights(self) > usUser){
|
||||
Log(DEBUG,"com","%s:in:%s", ConID(self),pCommand);
|
||||
} else {
|
||||
Log(INFO,"com", "%s:in:%s", ConID(self),pCommand);
|
||||
}
|
||||
iRet = InterpExecute(pInter, pCopy, pCommand);
|
||||
SCDeleteConnection(pCopy);
|
||||
StatusFileTask(NULL); /* save changed parameters */
|
||||
|
Reference in New Issue
Block a user