Verifies that the size of the log file is less than the configured maximum size, and moves the file to *.old if it is larger.
returnCode = wcCheckLogSize(cntrlHandle);
int wcCheckLogSize(void *controlHandle)
| controlHandle | The handle to the control structure. |
| 0 | Success. |
| Error code | Failure or exception. For a list of possible error codes, see Error Messages. |
The following code shows how wcCheckLogSize( ) is used in UWC CGI driver.
int go(argc, argv)
int argc;
char *argv[];
{
void *wcp;
int ret;
static char *gpszVar[] =
{
"AUTH_TYPE",
"CONTENT_LENGTH",
"CONTENT_TYPE",
"GATEWAY_INTERFACE",
"HTTP_ACCEPT",
"HTTP_REFERER",
"HTTP_USER_AGENT",
"PATH_INFO",
"PATH_TRANSLATED",
"QUERY_STRING",
"REMOTE_ADDR",
"REMOTE_HOST",
"REMOTE_IDENT",
"REMOTE_USER",
"REQUEST_METHOD",
"SCRIPT_NAME",
"SERVER_NAME",
"SERVER_PORT",
"SERVER_PROTOCOL",
"SERVER_SOFTWARE",
"HTTP_COOKIE",
"MI_WEBDIR",
"MI_WEBCONFIG"
};
char* pszBuf[sizeof (gpszVar) / sizeof (gpszVar[0])];
/* Get Message context information... */
for (Index = 0; Index < ((sizeof (pszBuf) / sizeof (pszBuf[0])) ); Index++)
{
ptr = getenv (gpszVar[Index]);
if (ptr)
pszBuf[Index] = strdup (ptr);
else
pszBuf[Index] = 0;
}
ret = wcDriverInit(argv[0], &wcp, pszBuf);
if(ret == ERR_OK)
{
int nDataLen = 0;
void *pOutput = 0;
void *pInput = 0;
size_t ulSize = 0;
wcCheckLogSize(wcp);
ptr = wcGetEnv (wcp, (const char *) "REQUEST_METHOD");
if (ptr && !strcmp(ptr, "POST"))
{
ptr = wcGetEnv (wcp, (const char *) "CONTENT_LENGTH");
if ( ptr )
{
int count;
if ((count=sscanf(ptr, "%d", &nDataLen ))!=1)
nDataLen = atol(ptr);
}
else
nDataLen = 0;
pInput = malloc (nDataLen+3);
memset (pInput, 0, nDataLen+3);
#ifdef WIN32
_setmode(_fileno(stdin), _O_BINARY); /* need to set to binary for file upload */
#endif /* WIN32 */
nDataLen = fread (pInput, 1, nDataLen, stdin);
if (nDataLen <= 0)
return wcTraceErr(wcp, ERR_SOCK_IO);
}
ret = wcDriverCallApp (wcp, &pOutput, &ulSize, pInput, nDataLen);
wcLogPrintf(wcp, "-- WCDRVR ---, done with wcDriverCallApp\n");
if (pInput)
free (pInput);
if (ret==ERR_OK)
{
if (pOutput)
{
#ifdef WIN32
_setmode (_fileno (stdout), _O_BINARY);
#endif /* WIN32 */
ulSize = (size_t) _write (_fileno (stdout), pOutput, ulSize);
fflush (stdout);
close (fileno(stdout));
wcDriverFreeBuffer (pOutput);
}
/* change sesId so that wcFreeSession is not called in wcExit */
wcp->sesId = -1;
}
}
wcLogPrintf(wcp, "Webdriver terminating (%d).\n", ret);
wcExit(wcp);
#ifdef WIN32
WSACleanup();
#endif /* WIN32 */
for (Index = 0; Index < ((sizeof (pszBuf) / sizeof (pszBuf[0])) ); Index++)
{
if (pszBuf[Index])
free (pszBuf[Index]);
}
return (ret);
}