downloadlog.c

Exemplo de download de logs.

Veja Nota sobre os exemplos.
#include <windows.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dinamo.h> /* header do Dinamo */
#define HOST_ADDR "10.10.4.67"
#define USER_ID "master"
#define USER_PWD "12345678"
void main ()
{
int nret = 0;
struct AUTH_PWD authPwd;
HSESSIONCTX hSession = 0;
DWORD dwLogServerSize = 0;
DWORD dwLogSize = 0;
BYTE *cbLog = 0;
/* inicializa a biblioteca do Dinamo */
nret = DInitialize (0);
if ( nret!=0 ) {
printf ( "Falha na inicialização da biblioteca do Dinamo. Codigo %d\n", nret );
exit (1);
}
printf ("Biblioteca inicializada.\n");
/* inicializa a estrutura para conexao com o Dinamo */
strncpy(authPwd.szAddr, HOST_ADDR, sizeof(authPwd.szAddr));
authPwd.nPort = DEFAULT_PORT;
strncpy(authPwd.szUserId, USER_ID, sizeof(authPwd.szUserId));
strncpy(authPwd.szPassword, USER_PWD, sizeof(authPwd.szPassword));
/* abre um sessao encriptada e ao mesmo tempo efetuando 'bypass' no balanceamento de carga */
nret = DOpenSession ( &hSession, SS_USER_PWD, (BYTE *)&authPwd, sizeof(authPwd), CLEAR_CONN|LB_BYPASS );
if ( nret!=0 ) {
printf ("Erro na abertura da sessão com o Dinamo. Código %d\n", nret);
exit (1);
}
printf ( "Sessao aberta.\n" );
/* ******************************************************* */
/* aqui comeca o tratamento para receber o log do servidor */
/* ******************************************************* */
/* obtem tamanho do LOG no servidor */
nret = DGetStatLogSize ( hSession, &dwLogServerSize );
if ( nret == 0 ) {
printf ("Tamanho do LOG no servidor sem formatacao: %d byte(s).\n",dwLogServerSize);
}
if ( dwLogServerSize>0 ) {
cbLog = DAlloc ( dwLogServerSize ); /* aloca memoria */
if ( cbLog ) {
/* recebe todo o conteudo do log. */
nret = DGetStatLog (hSession, GET_LOG_START_FULL, GET_LOG_END_FULL, &dwLogSize, &cbLog );
DFree ( cbLog ); /* libera memoria */
}
}
/* fechamento da sessao */
if ( hSession )
{
DCloseSession ( &hSession, 0 );
printf ( "Sessao encerrada.\n" );
}
/* encerra a biblioteca do Dinamo */
}