Article View: borland.public.cppbuilder.internet.socket
Article #2568Re: Indy 9 SysLog in a DLL
From: Paul
Date: Mon, 27 Mar 2006 19:36
Date: Mon, 27 Mar 2006 19:36
361 lines
10178 bytes
10178 bytes
Hi,
This is an extract of the DLL code for the 3 new functions of the DLL I put
in this morning; to create an instance of the TIdSyslog, destroy it, and
provide a send message interface.
Paul
//---------------------------------------------------------------------------
#ifdef CTS_BCB_DLL_STDCALL
bool __stdcall
#else
bool __cdecl
#endif
DllMain(HINSTANCE hinstDLL, DWORD fwdreason, LPVOID lpvReserved)
{
return TRUE;
}
//---------------------------------------------------------------------------
#ifdef CTS_BCB_DLL_STDCALL
unsigned long __stdcall
#else
unsigned long __cdecl
#endif
CtsSysLogCreate ( const char * In_ServerAddress,
const unsigned long In_ServerPort,
void** Out_ClientHandle )
{
CTSSYSLOGRESULT result = CTSSYSLOG_RESULT_OK;
try
{
// create client side
TIdSysLog * IdSysLog = new TIdSysLog(NULL);
if (IdSysLog)
{
IdSysLog->Host = In_ServerAddress;
IdSysLog->Port = In_ServerPort;
IdSysLog->Active = true;
*Out_ClientHandle = IdSysLog;
}
else
{
*Out_ClientHandle = NULL;
result = CTSSYSLOG_RESULT_COMPONENT_FAILURE;
}
}
catch (...)
{
result = CTSSYSLOG_RESULT_UNKNOWN_EXCEPTION;
}
return result;
}
//---------------------------------------------------------------------------
#ifdef CTS_BCB_DLL_STDCALL
unsigned long __stdcall
#else
unsigned long __cdecl
#endif
CtsSysLogDestroy ( void** In_ClientHandle )
{
CTSSYSLOGRESULT result = CTSSYSLOG_RESULT_OK;
try
{
if (In_ClientHandle)
{
if (*In_ClientHandle)
{
TIdSysLog * IdSysLog = (TIdSysLog *) *In_ClientHandle;
IdSysLog->Active = false;
delete IdSysLog;
IdSysLog = NULL;
*In_ClientHandle = NULL;
}
else
{
result = CTSSYSLOG_RESULT_PARAMETER_INVALID;
}
}
else
{
result = CTSSYSLOG_RESULT_PARAMETER_INVALID;
}
}
catch (...)
{
result = CTSSYSLOG_RESULT_UNKNOWN_EXCEPTION;
}
return result;
}
//---------------------------------------------------------------------------
#ifdef CTS_BCB_DLL_STDCALL
unsigned long __stdcall
#else
unsigned long __cdecl
#endif
Send( TIdSysLog * IdSysLog,
CTSSYSLOGSEVERITY severity,
CTSSYSLOGFACILITY facility,
char * message )
{
CTSSYSLOGRESULT result = CTSSYSLOG_RESULT_OK;
if (IdSysLog)
{
TIdSysLogMessage * sl = new TIdSysLogMessage(NULL);
TIdSyslogSeverity sv = slDebug;
TIdSyslogFacility fc = sfUserLevel;
switch (severity)
{
case CTS_SYSLOG_slEmergency:
{
sv = slEmergency;
break;
}
case CTS_SYSLOG_slAlert:
{
sv = slAlert;
break;
}
case CTS_SYSLOG_slCritical:
{
sv = slCritical;
break;
}
case CTS_SYSLOG_slError:
{
sv = slError;
break;
}
case CTS_SYSLOG_slWarning:
{
sv = slWarning;
break;
}
case CTS_SYSLOG_slNotice:
{
sv = slNotice;
break;
}
case CTS_SYSLOG_slInformational:
{
sv = slInformational;
break;
}
case CTS_SYSLOG_slDebug:
default:
{
sv = slDebug;
break;
}
}
switch (facility)
{
case CTS_SYSLOG_sfKernel:
{
fc = sfKernel;
break;
}
case CTS_SYSLOG_sfMailSystem:
{
fc = sfMailSystem;
break;
}
case CTS_SYSLOG_sfSystemDaemon:
{
fc = sfSystemDaemon;
break;
}
case CTS_SYSLOG_sfClockDaemonOne:
{
fc = sfClockDaemonOne;
break;
}
case CTS_SYSLOG_sfClockDaemonTwo:
{
fc = sfClockDaemonTwo;
break;
}
case CTS_SYSLOG_sfFTPDaemon:
{
fc = sfFTPDaemon;
break;
}
case CTS_SYSLOG_sfSecurityOne:
{
fc = sfSecurityOne;
break;
}
case CTS_SYSLOG_sfSecurityTwo:
{
fc = sfSecurityTwo;
break;
}
case CTS_SYSLOG_sfSysLogInternal:
{
fc = sfSysLogInternal;
break;
}
case CTS_SYSLOG_sfLogAlert:
{
fc = sfLogAlert;
break;
}
case CTS_SYSLOG_sfLPR:
{
fc = sfLPR;
break;
}
case CTS_SYSLOG_sfNNTP:
{
fc = sfNNTP;
break;
}
case CTS_SYSLOG_sfUUCP:
{
fc = sfUUCP;
break;
}
case CTS_SYSLOG_sfNTP:
{
fc = sfNTP;
break;
}
case CTS_SYSLOG_sfLocalUseZero:
{
fc = sfLocalUseZero;
break;
}
case CTS_SYSLOG_sfLocalUseOne:
{
fc = sfLocalUseOne;
break;
}
case CTS_SYSLOG_sfLocalUseTwo:
{
fc = sfLocalUseTwo;
break;
}
case CTS_SYSLOG_sfLocalUseThree:
{
fc = sfLocalUseThree;
break;
}
case CTS_SYSLOG_sfLocalUseFour:
{
fc = sfLocalUseFour;
break;
}
case CTS_SYSLOG_sfLocalUseFive:
{
fc = sfLocalUseFive;
break;
}
case CTS_SYSLOG_sfLocalUseSix:
{
fc = sfLocalUseSix;
break;
}
case CTS_SYSLOG_sfLocalUseSeven:
{
fc = sfLocalUseSeven;
break;
}
case CTS_SYSLOG_sfUserLevel:
default:
{
fc = sfUserLevel;
break;
}
}
// default data
sl->Msg->Process = "TestApp";
sl->Msg->PIDAvailable = true;
sl->Msg->PID = 1234;
// run time data
sl->TimeStamp = Now();
sl->Msg->Content = message;
sl->Severity = sv;
sl->Facility = fc;
// sl->Pri; // this is set by setting "Severity and Facility"
// sl->Peer; // this is?
// sl->Hostname // is this machines IP address unless you want to
change it
// sl->Version; // is built in Indy (read only)
IdSysLog->SendLogMessage( sl, false );
}
return result;
}
//---------------------------------------------------------------------------
#ifdef CTS_BCB_DLL_STDCALL
unsigned long __stdcall
#else
unsigned long __cdecl
#endif
CtsSysLogSend ( const void** In_ClientHandle,
const unsigned long In_Severity,
const unsigned long In_Facility,
const char * In_Message )
{
CTSSYSLOGRESULT result = CTSSYSLOG_RESULT_OK;
try
{
if (In_ClientHandle)
{
if (*In_ClientHandle)
{
Send( (TIdSysLog *) *In_ClientHandle,
(CTSSYSLOGSEVERITY) In_Severity,
(CTSSYSLOGFACILITY) In_Facility,
(char *) In_Message );
}
else
{
result = CTSSYSLOG_RESULT_PARAMETER_INVALID;
}
}
else
{
result = CTSSYSLOG_RESULT_PARAMETER_INVALID;
}
}
catch (...)
{
result = CTSSYSLOG_RESULT_UNKNOWN_EXCEPTION;
}
return result;
}
//---------------------------------------------------------------------------
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message
news:44282c7e$2@newsgroups.borland.com...
>
> Again, please show your actual code.
>
> Gambit
Technical Details
Message-ID:
<4428309f@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<442645a5@newsgroups.borland.com> <4427065d$3@newsgroups.borland.com> <4427a09f@newsgroups.borland.com> <44282c7e$2@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,a7a7e5cdcf8a0abf X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Paul" <plmacca@clara.co.uk> Newsgroups: borland.public.cppbuilder.internet.socket References: <442645a5@newsgroups.borland.com> <4427065d$3@newsgroups.borland.com> <4427a09f@newsgroups.borland.com> <44282c7e$2@newsgroups.borland.com> Subject: Re: Indy 9 SysLog in a DLL Date: Mon, 27 Mar 2006 19:36:25 -0000 Lines: 363 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Original NNTP-Posting-Host: 81.151.181.175 Message-ID: <4428309f@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1143484575 81.151.181.175 (27 Mar 2006 10:36:15 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail