- Fixed a few problems with hklscan
- Added transfer of zipped data to conman.c, histogram memory software in order to support the TRICS status display. - Upgraded TRICS data file writing. - First installment of triple axis spectrometer support: initialization of data structures and an implementation of the MAD dr(ive) command.
This commit is contained in:
237
conman.c
237
conman.c
@@ -17,6 +17,10 @@
|
||||
Mark Koennecke, January 1998
|
||||
|
||||
SCWriteBinary added. Mark Koennecke, April 1998
|
||||
|
||||
Revamped login to non telnet connection.
|
||||
Added compressed writing method.
|
||||
Mark Koennecke, October 2000
|
||||
|
||||
Copyright: see copyright.h
|
||||
-----------------------------------------------------------------------------*/
|
||||
@@ -26,7 +30,9 @@
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <zlib.h>
|
||||
#include <tcl.h>
|
||||
#include <time.h>
|
||||
#include "lld.h"
|
||||
#include "conman.h"
|
||||
#include "passwd.h"
|
||||
@@ -129,6 +135,8 @@ extern pServer pServ;
|
||||
pRes->eInterrupt = eContinue;
|
||||
pRes->lMagic = CONMAGIC;
|
||||
pRes->iDummy = 0;
|
||||
pRes->iLogin = 0;
|
||||
pRes->conStart = time(NULL);
|
||||
pRes->write = SCNormalWrite;
|
||||
for(i = 0; i < 10; i++)
|
||||
{
|
||||
@@ -213,6 +221,8 @@ extern pServer pServ;
|
||||
pRes->lMagic = CONMAGIC;
|
||||
pRes->eInterrupt = eContinue;
|
||||
pRes->iDummy = 0;
|
||||
pRes->iLogin = 0;
|
||||
pRes->conStart = time(NULL);
|
||||
pRes->write = SCNormalWrite;
|
||||
for(i = 0; i < 10; i++)
|
||||
{
|
||||
@@ -812,6 +822,179 @@ extern pServer pServ;
|
||||
free(pPtr);
|
||||
return iRet;
|
||||
}
|
||||
/*------------------------------------------------------------------------*/
|
||||
#define ZIPBUF 8192
|
||||
int SCWriteZipped(SConnection *self, char *pName, void *pData, int iDataLen)
|
||||
{
|
||||
char outBuf[65546], *pBuf = NULL, noutBuf[ZIPBUF];
|
||||
int compressedLength, iRet, iRet2, iCount;
|
||||
z_stream compStream;
|
||||
|
||||
/* 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 currupt compressed data!",
|
||||
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);
|
||||
sprintf(outBuf,"SICSBIN ZIP %s %d\r\n",pName,compressedLength);
|
||||
SCWrite(self,outBuf,eValue);
|
||||
|
||||
/* 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));
|
||||
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 && iRet != Z_OK)
|
||||
{
|
||||
sprintf(outBuf,"ERROR: zlib error: %d",iRet);
|
||||
SCWrite(self,outBuf,eError);
|
||||
return 0;
|
||||
}
|
||||
iRet = NETWrite(self->pSock,pBuf,compStream.total_out);
|
||||
if(iRet != 1)
|
||||
{
|
||||
sprintf(outBuf,"ERROR: network error %d on zipped send",iRet);
|
||||
SCWrite(self,outBuf,eError);
|
||||
return 0;
|
||||
}
|
||||
deflateEnd(&compStream);
|
||||
|
||||
|
||||
/*
|
||||
Writing smaller buffers. Seems not to be working properly
|
||||
with Java.
|
||||
*/
|
||||
/*
|
||||
compStream.next_in = (Bytef *)pData;
|
||||
compStream.avail_in = iDataLen;
|
||||
compStream.avail_out = ZIPBUF;
|
||||
compStream.next_out = (Bytef *)noutBuf;
|
||||
iCount = 0;
|
||||
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;
|
||||
}
|
||||
iRet = NETWrite(self->pSock,noutBuf,ZIPBUF - compStream.avail_out);
|
||||
if(iRet != 1)
|
||||
{
|
||||
sprintf(outBuf,"ERROR: network error %d on zipped send",iRet);
|
||||
SCWrite(self,outBuf,eError);
|
||||
return 0;
|
||||
}
|
||||
iCount += ZIPBUF - compStream.avail_out;
|
||||
compStream.next_out = (Bytef *)noutBuf;
|
||||
compStream.avail_out = ZIPBUF;
|
||||
}
|
||||
for(;;)
|
||||
{
|
||||
iRet = deflate(&compStream,Z_FINISH);
|
||||
iRet2 = NETWrite(self->pSock,noutBuf,ZIPBUF - compStream.avail_out);
|
||||
if(iRet2 != 1)
|
||||
{
|
||||
sprintf(outBuf,"ERROR: network error %d on zipped send",iRet);
|
||||
SCWrite(self,outBuf,eError);
|
||||
return 0;
|
||||
}
|
||||
iCount += ZIPBUF - compStream.avail_out;
|
||||
if(iRet == Z_STREAM_END) break;
|
||||
if(iRet != Z_OK)
|
||||
{
|
||||
sprintf(outBuf,"ERROR: zlib error: %d",iRet);
|
||||
SCWrite(self,outBuf,eError);
|
||||
return 0;
|
||||
}
|
||||
compStream.next_out = (Bytef *)noutBuf;
|
||||
compStream.avail_out = ZIPBUF;
|
||||
}
|
||||
deflateEnd(&compStream);
|
||||
*/
|
||||
|
||||
return 1;
|
||||
}
|
||||
/*-------------------------------------------------------------------------*/
|
||||
int SCSendOK(SConnection *self)
|
||||
{
|
||||
@@ -1382,6 +1565,7 @@ extern pServer pServ;
|
||||
SConnection *self = NULL;
|
||||
char *pPtr = NULL;
|
||||
int iRet;
|
||||
char *pUser = NULL, *pPassword = NULL;
|
||||
|
||||
self = (SConnection *)pData;
|
||||
if(!VerifyConnection(self))
|
||||
@@ -1401,6 +1585,14 @@ extern pServer pServ;
|
||||
}
|
||||
}
|
||||
|
||||
/* a timeout check on logins */
|
||||
if(!self->iLogin && time(NULL) > self->conStart + 120)
|
||||
{
|
||||
NetReadRemove(pServ->pReader,self->pSock);
|
||||
SCWrite(self, "No valid login in two minutes, closing..",eError);
|
||||
self->iEnd = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* pop and execute */
|
||||
iRet = CostaPop(self->pStack,&pPtr);
|
||||
@@ -1408,13 +1600,50 @@ extern pServer pServ;
|
||||
{
|
||||
if(pPtr)
|
||||
{
|
||||
CostaLock(self->pStack);
|
||||
SCInvoke(self,self->pSics,pPtr);
|
||||
CostaUnlock(self->pStack);
|
||||
/* SCWrite(self,"\b",eError); */
|
||||
if(self->iLogin)
|
||||
{
|
||||
/*
|
||||
normal processing, logged in
|
||||
but check for logoff
|
||||
*/
|
||||
if(strstr(pPtr,"logoff") != NULL)
|
||||
{
|
||||
NetReadRemove(pServ->pReader,self->pSock);
|
||||
self->iEnd = 1;
|
||||
free(pPtr);
|
||||
return 1;
|
||||
}
|
||||
/* invoke command */
|
||||
CostaLock(self->pStack);
|
||||
SCInvoke(self,self->pSics,pPtr);
|
||||
CostaUnlock(self->pStack);
|
||||
/* SCWrite(self,"\b",eError); */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* check for username and password */
|
||||
pUser = strtok(pPtr," \t");
|
||||
pPassword = strtok(NULL," \t\r\n");
|
||||
iRet = IsValidUser(pUser,pPassword);
|
||||
if(iRet >= 0)
|
||||
{
|
||||
SCWrite(self,"Login OK",eError);
|
||||
self->iLogin = 1;
|
||||
SCSetRights(self,iRet);
|
||||
free(pPtr);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
SCWrite(self,"ERROR: Bad login",eError);
|
||||
|
||||
}
|
||||
}
|
||||
free(pPtr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(self->iEnd)
|
||||
{
|
||||
if(self->inUse != 0)
|
||||
|
||||
Reference in New Issue
Block a user