Change to have a single library that works on both Win9x and WinNT.
As far as I understand, it still needs to be compiled on NT... Contributed by Arne Ansper <arne@ats.cyber.ee>
This commit is contained in:
parent
f03aa651c0
commit
fb3e1eeb93
1 changed files with 37 additions and 5 deletions
|
@ -118,6 +118,18 @@ static int MS_CALLBACK slg_free(BIO *data);
|
|||
static void xopenlog(BIO* bp, const char* name, int level);
|
||||
static void xsyslog(BIO* bp, int priority, const char* string);
|
||||
static void xcloselog(BIO* bp);
|
||||
#ifdef WIN32
|
||||
LONG (WINAPI *go_for_advapi)() = RegOpenKeyEx;
|
||||
HANDLE (WINAPI *register_event_source)() = NULL;
|
||||
BOOL (WINAPI *deregister_event_source)() = NULL;
|
||||
BOOL (WINAPI *report_event)() = NULL;
|
||||
#define DL_PROC(m,f) (GetProcAddress( m, f ))
|
||||
#ifdef UNICODE
|
||||
#define DL_PROC_X(m,f) DL_PROC( m, f "W" )
|
||||
#else
|
||||
#define DL_PROC_X(m,f) DL_PROC( m, f "A" )
|
||||
#endif
|
||||
#endif
|
||||
|
||||
static BIO_METHOD methods_slg=
|
||||
{
|
||||
|
@ -213,7 +225,27 @@ static int MS_CALLBACK slg_puts(BIO *bp, const char *str)
|
|||
|
||||
static void xopenlog(BIO* bp, const char* name, int level)
|
||||
{
|
||||
bp->ptr= (char *)RegisterEventSource(NULL, name);
|
||||
if ( !register_event_source )
|
||||
{
|
||||
HANDLE advapi;
|
||||
if ( !(advapi = GetModuleHandle("advapi32")) )
|
||||
return;
|
||||
register_event_source = (HANDLE (WINAPI *)())DL_PROC_X(advapi,
|
||||
"RegisterEventSource" );
|
||||
deregister_event_source = (BOOL (WINAPI *)())DL_PROC(advapi,
|
||||
"DeregisterEventSource");
|
||||
report_event = (BOOL (WINAPI *)())DL_PROC_X(advapi,
|
||||
"ReportEvent" );
|
||||
if ( !(register_event_source && deregister_event_source &&
|
||||
report_event) )
|
||||
{
|
||||
register_event_source = NULL;
|
||||
deregister_event_source = NULL;
|
||||
report_event = NULL;
|
||||
return;
|
||||
}
|
||||
}
|
||||
bp->ptr= (char *)register_event_source(NULL, name);
|
||||
}
|
||||
|
||||
static void xsyslog(BIO *bp, int priority, const char *string)
|
||||
|
@ -243,15 +275,15 @@ static void xsyslog(BIO *bp, int priority, const char *string)
|
|||
lpszStrings[0] = pidbuf;
|
||||
lpszStrings[1] = string;
|
||||
|
||||
if(bp->ptr)
|
||||
ReportEvent(bp->ptr, evtype, 0, 1024, NULL, 2, 0,
|
||||
if(report_event && bp->ptr)
|
||||
report_event(bp->ptr, evtype, 0, 1024, NULL, 2, 0,
|
||||
lpszStrings, NULL);
|
||||
}
|
||||
|
||||
static void xcloselog(BIO* bp)
|
||||
{
|
||||
if(bp->ptr)
|
||||
DeregisterEventSource((HANDLE)(bp->ptr));
|
||||
if(deregister_event_source && bp->ptr)
|
||||
deregister_event_source((HANDLE)(bp->ptr));
|
||||
bp->ptr= NULL;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue