- Adapted indenation to new agreed upon system

- Added support for second generation scriptcontext based counter
This commit is contained in:
koennecke
2009-02-13 09:00:03 +00:00
parent a3dcad2bfa
commit 91d4af0541
405 changed files with 88101 additions and 88173 deletions

425
servlog.c
View File

@@ -66,54 +66,46 @@
The server log output can be captured by a client. In order to implement
this the following code is necessary.
*/
typedef struct __LogLog{
SConnection *pCon;
OutCode iOut;
int iAllFlag;
struct __LogLog *pNext;
struct __LogLog *pPrevious;
} CaptureEntry, *pCaptureEntry;
typedef struct __LogLog {
SConnection *pCon;
OutCode iOut;
int iAllFlag;
struct __LogLog *pNext;
struct __LogLog *pPrevious;
} CaptureEntry, *pCaptureEntry;
static pCaptureEntry pCapture = NULL;
static pCaptureEntry pCapture = NULL;
/*------------------------------------------------------------------------*/
int KillCapture(SConnection *pCon)
{
pCaptureEntry pCurrent, pTemp;
/* find first */
pCurrent = pCapture;
while(pCurrent != NULL)
{
if(pCon == pCurrent->pCon)
{
/* relink */
if(pCurrent->pPrevious)
{
pCurrent->pPrevious->pNext = pCurrent->pNext;
}
else
{
pCapture = pCurrent->pNext;
}
if(pCurrent->pNext)
{
pCurrent->pNext->pPrevious = pCurrent->pPrevious;
}
pTemp = pCurrent->pNext;
/* get rid of pCurrent */
free(pCurrent);
pCurrent = pTemp;
}
else
{
pCurrent = pCurrent->pNext;
}
}
return 1;
}
int KillCapture(SConnection * pCon)
{
pCaptureEntry pCurrent, pTemp;
/* find first */
pCurrent = pCapture;
while (pCurrent != NULL) {
if (pCon == pCurrent->pCon) {
/* relink */
if (pCurrent->pPrevious) {
pCurrent->pPrevious->pNext = pCurrent->pNext;
} else {
pCapture = pCurrent->pNext;
}
if (pCurrent->pNext) {
pCurrent->pNext->pPrevious = pCurrent->pPrevious;
}
pTemp = pCurrent->pNext;
/* get rid of pCurrent */
free(pCurrent);
pCurrent = pTemp;
} else {
pCurrent = pCurrent->pNext;
}
}
return 1;
}
/* ------------------------------------------------------------------------
the command function:
Syntax:
@@ -121,206 +113,181 @@
Log OutCode starts loggin OutCode events
All starts logging all events
-------------------------------------------------------------------------- */
#include "outcode.c" /* for pCode */
int LogCapture(SConnection *pCon, SicsInterp *pSics, void *pData,
int argc, char *argv[])
{
pCaptureEntry pNew = NULL;
char pBueffel[512];
int i;
/* check no af args */
if(argc < 2)
{
sprintf(pBueffel,"Insufficient number of argumenst to %s",argv[0]);
SCWrite(pCon,pBueffel,eError);
return 0;
}
argtolower(argc,argv);
/* Branch according to argv[1] */
if(strcmp(argv[1],"kill") == 0 )
{
KillCapture(pCon);
return 1;
}
else if(strcmp(argv[1],"all") == 0)
{
pNew = (pCaptureEntry)malloc(sizeof(CaptureEntry));
if(!pNew)
{
SICSLogWrite("Out of memory in LogCapture",eInternal);
return 0;
}
if(pCapture)
{
pCapture->pPrevious = pNew;
}
pNew->pPrevious = NULL;
pNew->pNext = pCapture;
pCapture = pNew;
pNew->iAllFlag = 1;
pNew->pCon = pCon;
return 1;
}
else
{
/* must be outcode, try find it */
i = 0;
while(pCode[i] != NULL)
{
if(strcmp(argv[1],pCode[i]) == 0)
{
break;
}
i++;
}
if(i > iNoCodes)
{
sprintf(pBueffel,"OutPutCode %s not recognized in %s",argv[1],
argv[0]);
SCWrite(pCon,pBueffel,eError);
return 0;
}
/* create a new one */
pNew = (pCaptureEntry)malloc(sizeof(CaptureEntry));
if(!pNew)
{
SICSLogWrite("Out of memory in LogCapture",eInternal);
return 0;
}
if(pCapture)
{
pCapture->pPrevious = pNew;
}
pNew->pPrevious = NULL;
pNew->pNext = pCapture;
pCapture = pNew;
pNew->iAllFlag = 0;
pNew->pCon = pCon;
pNew->iOut = i;
return 1;
}
#include "outcode.c" /* for pCode */
int LogCapture(SConnection * pCon, SicsInterp * pSics, void *pData,
int argc, char *argv[])
{
pCaptureEntry pNew = NULL;
char pBueffel[512];
int i;
/* check no af args */
if (argc < 2) {
sprintf(pBueffel, "Insufficient number of argumenst to %s", argv[0]);
SCWrite(pCon, pBueffel, eError);
return 0;
}
argtolower(argc, argv);
/* Branch according to argv[1] */
if (strcmp(argv[1], "kill") == 0) {
KillCapture(pCon);
return 1;
} else if (strcmp(argv[1], "all") == 0) {
pNew = (pCaptureEntry) malloc(sizeof(CaptureEntry));
if (!pNew) {
SICSLogWrite("Out of memory in LogCapture", eInternal);
return 0;
}
if (pCapture) {
pCapture->pPrevious = pNew;
}
pNew->pPrevious = NULL;
pNew->pNext = pCapture;
pCapture = pNew;
pNew->iAllFlag = 1;
pNew->pCon = pCon;
return 1;
} else {
/* must be outcode, try find it */
i = 0;
while (pCode[i] != NULL) {
if (strcmp(argv[1], pCode[i]) == 0) {
break;
}
i++;
}
if (i > iNoCodes) {
sprintf(pBueffel, "OutPutCode %s not recognized in %s", argv[1],
argv[0]);
SCWrite(pCon, pBueffel, eError);
return 0;
}
/* create a new one */
pNew = (pCaptureEntry) malloc(sizeof(CaptureEntry));
if (!pNew) {
SICSLogWrite("Out of memory in LogCapture", eInternal);
return 0;
}
if (pCapture) {
pCapture->pPrevious = pNew;
}
pNew->pPrevious = NULL;
pNew->pNext = pCapture;
pCapture = pNew;
pNew->iAllFlag = 0;
pNew->pCon = pCon;
pNew->iOut = i;
return 1;
}
return 0;
}
/*--------------------------------------------------------------------------*/
static int HasLineFeed(char *pText)
{
int i;
for(i = strlen(pText); i > 0; i--)
{
if(pText[i] == '\n')
{
return 1;
}
if(isalpha(pText[i]))
{
return 0;
}
}
return 1;
}
static int HasLineFeed(char *pText)
{
int i;
for (i = strlen(pText); i > 0; i--) {
if (pText[i] == '\n') {
return 1;
}
if (isalpha(pText[i])) {
return 0;
}
}
return 1;
}
/*---------------------------------------------------------------------------*/
#define MAXLOG 10000
#define MAXFILES 20
static FILE *fLogFile = NULL;
static int iFile = 0;
static int iLineCount = 0;
static int iLogUsable = 1;
static FILE *fLogFile = NULL;
static int iFile = 0;
static int iLineCount = 0;
static int iLogUsable = 1;
/*---------------------------------------------------------------------------*/
int OpenVerifyLogFile()
{
char pFile[256];
char filnam[512];
char *pChar = NULL;
int OpenVerifyLogFile()
{
char pFile[256];
char filnam[512];
char *pChar = NULL;
pChar = IFindOption(pSICSOptions,"LogFileBaseName");
if(!pChar)
{ /* Try to write to file "server" in*/
strcpy(pFile,"server");
}
else
{
strncpy(pFile,pChar,255);
}
snprintf(filnam,511,"%s%2.2d.log",pFile, iFile);
fLogFile = fopen(filnam,"w");
if(!fLogFile)
{
fprintf(stderr,"ERROR: Cannot open logfile %s for writing\n",pFile);
fLogFile = NULL;
return 0;
}
else
{
return 1;
}
pChar = IFindOption(pSICSOptions, "LogFileBaseName");
if (!pChar) { /* Try to write to file "server" in */
strcpy(pFile, "server");
} else {
strncpy(pFile, pChar, 255);
}
/*---------------------------------------------------------------------------*/
void SICSLogEnable(int flag) {
iLogUsable=flag;
snprintf(filnam, 511, "%s%2.2d.log", pFile, iFile);
fLogFile = fopen(filnam, "w");
if (!fLogFile) {
fprintf(stderr, "ERROR: Cannot open logfile %s for writing\n", pFile);
fLogFile = NULL;
return 0;
} else {
return 1;
}
}
/*---------------------------------------------------------------------------*/
void SICSLogWrite(char *pText, OutCode eOut)
{
char pFile[256];
char *pChar = NULL;
pCaptureEntry pCurrent;
char pBueffel[256];
void SICSLogEnable(int flag)
{
iLogUsable = flag;
}
/*---------------------------------------------------------------------------*/
void SICSLogWrite(char *pText, OutCode eOut)
{
char pFile[256];
char *pChar = NULL;
pCaptureEntry pCurrent;
char pBueffel[256];
#ifdef NOLOG
return ;
#endif
return;
#endif
/* do all captured */
pCurrent = pCapture;
while(pCurrent)
{
if( (pCurrent->iOut == eOut) || (pCurrent->iAllFlag == 1) )
{
ANETwrite(pCurrent->pCon->sockHandle,pText,strlen(pText));
ANETwrite(pCurrent->pCon->sockHandle,"\n",1);
}
pCurrent = pCurrent->pNext;
}
if(0 == iLogUsable) return;
if(fLogFile == NULL) /* first time of use*/
{
/* no options: startup or serious trouble, print to stdout*/
if(!pSICSOptions)
{
printf("WARNING: Cannot log(%s)\n",pText);
return;
}
iLogUsable = OpenVerifyLogFile();
}
/* switch file if too many lines */
if(iLineCount >= MAXLOG)
{
fclose(fLogFile);
fLogFile = NULL;
iFile++;
iLineCount = 0;
if(iFile >= MAXFILES)
{
iFile = 0;
}
iLogUsable = OpenVerifyLogFile();
}
if(1 == iLogUsable)
{
fprintf(fLogFile,"%s\n",pText);
fflush(fLogFile);
iLineCount++;
/* do all captured */
pCurrent = pCapture;
while (pCurrent) {
if ((pCurrent->iOut == eOut) || (pCurrent->iAllFlag == 1)) {
ANETwrite(pCurrent->pCon->sockHandle, pText, strlen(pText));
ANETwrite(pCurrent->pCon->sockHandle, "\n", 1);
}
pCurrent = pCurrent->pNext;
}
if (0 == iLogUsable)
return;
if (fLogFile == NULL) { /* first time of use */
/* no options: startup or serious trouble, print to stdout */
if (!pSICSOptions) {
printf("WARNING: Cannot log(%s)\n", pText);
return;
}
iLogUsable = OpenVerifyLogFile();
}
/* switch file if too many lines */
if (iLineCount >= MAXLOG) {
fclose(fLogFile);
fLogFile = NULL;
iFile++;
iLineCount = 0;
if (iFile >= MAXFILES) {
iFile = 0;
}
iLogUsable = OpenVerifyLogFile();
}
if (1 == iLogUsable) {
fprintf(fLogFile, "%s\n", pText);
fflush(fLogFile);
iLineCount++;
}
}