Replace {Log,Kill}Capture with a more generic hook.
This commit is contained in:
81
conman.c
81
conman.c
@ -82,6 +82,10 @@ extern pServer pServ;
|
||||
|
||||
#include "outcode.c" /* text for OutCode */
|
||||
|
||||
int KillCapture(SConnection * pCon);
|
||||
|
||||
int LogCapture(SConnection * pCon, SicsInterp * pInter, void *pData,
|
||||
int argc, char *argv[]);
|
||||
|
||||
/*------ Max Size of Command Stack */
|
||||
#define MAXSTACK 1024
|
||||
@ -2113,6 +2117,83 @@ int ConSicsAction(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void hookFunc(const char *pText, OutCode eOut, void*pData)
|
||||
{
|
||||
SConnection *pCon = (SConnection *) pData;
|
||||
int text_len = strlen(pText);
|
||||
|
||||
ANETwrite(pCon->sockHandle, pText, text_len);
|
||||
if (pText[text_len - 1] != '\n')
|
||||
ANETwrite(pCon->sockHandle, "\n", 1);
|
||||
}
|
||||
|
||||
int KillCapture(SConnection * pCon)
|
||||
{
|
||||
RemSICSLogHook(pCon);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------
|
||||
the command function:
|
||||
Syntax:
|
||||
Kill kills all logging
|
||||
Log OutCode starts loggin OutCode events
|
||||
All starts logging all events
|
||||
-------------------------------------------------------------------------- */
|
||||
|
||||
int LogCapture(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
int argc, char *argv[])
|
||||
{
|
||||
char pBueffel[512];
|
||||
int i;
|
||||
|
||||
/* check no af args */
|
||||
if (argc < 2) {
|
||||
snprintf(pBueffel,sizeof(pBueffel)-1, "Insufficient number of arguments 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) {
|
||||
AddSICSLogHook(hookFunc, "all", pCon);
|
||||
return 1;
|
||||
} else if (argc == 2) {
|
||||
/* must be outcode, try find it */
|
||||
AddSICSLogHook(hookFunc, argv[1], pCon);
|
||||
return 1;
|
||||
} else {
|
||||
/* make it a list */
|
||||
int i, len;
|
||||
char *pBuff;
|
||||
for (i = 1, len = 0; i < argc; ++i)
|
||||
len += strlen(argv[i]) + 1;
|
||||
if (len > sizeof(pBueffel))
|
||||
pBuff = malloc(len);
|
||||
else
|
||||
pBuff = pBueffel;
|
||||
if (pBuff == NULL) {
|
||||
SCWrite(pCon, "Out of memory in LogCapture\n", eError);
|
||||
return 1;
|
||||
}
|
||||
for (i = 1, len = 0; i < argc; ++i) {
|
||||
if (i > 1)
|
||||
pBuff[len++] = ',';
|
||||
strcpy(&pBuff[len], argv[i]);
|
||||
len += strlen(argv[i]);
|
||||
}
|
||||
AddSICSLogHook(hookFunc, pBuff, pCon);
|
||||
if (pBuff != pBueffel)
|
||||
free(pBuff);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*--------------------------------------------------------------------------*/
|
||||
int SCTaskFunction(void *pData)
|
||||
{
|
||||
|
Reference in New Issue
Block a user