forked from php/php-src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wsyslog.c
138 lines (122 loc) · 3.87 KB
/
wsyslog.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
* This file modified from sources for imap4 for use
* in PHP 3
*/
/*
* Program: Unix compatibility routines
*
* Author: Mark Crispin
* Networks and Distributed Computing
* Computing & Communications
* University of Washington
* Administration Building, AG-44
* Seattle, WA 98195
* Internet: [email protected]
*
* Date: 14 September 1996
* Last Edited: 22 October 1996
*
* Copyright 1996 by the University of Washington
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose and without fee is hereby granted, provided
* that the above copyright notice appears in all copies and that both the
* above copyright notice and this permission notice appear in supporting
* documentation, and that the name of the University of Washington not be
* used in advertising or publicity pertaining to distribution of the software
* without specific, written prior permission. This software is made available
* "as is", and
* THE UNIVERSITY OF WASHINGTON DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED,
* WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION ALL IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND IN
* NO EVENT SHALL THE UNIVERSITY OF WASHINGTON BE LIABLE FOR ANY SPECIAL,
* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, TORT
* (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF OR IN CONNECTION
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
*/
/* DEDICATION
* This file is dedicated to my dog, Unix, also known as Yun-chan and
* Unix J. Terwilliker Jehosophat Aloysius Monstrosity Animal Beast. Unix
* passed away at the age of 11 1/2 on September 14, 1996, 12:18 PM PDT, after
* a two-month bout with cirrhosis of the liver.
*
* He was a dear friend, and I miss him terribly.
*
* Lift a leg, Yunie. Luv ya forever!!!!
*/
#include "php.h" /*php specific */
#include "syslog.h"
#include <stdio.h>
#include <fcntl.h>
#include <process.h>
#include "php_win32_globals.h"
#include "wsyslog.h"
void closelog(void)
{
if (INVALID_HANDLE_VALUE != PW32G(log_source)) {
DeregisterEventSource(PW32G(log_source));
PW32G(log_source) = INVALID_HANDLE_VALUE;
}
if (PW32G(log_header)) {
efree(PW32G(log_header));
PW32G(log_header) = NULL;
}
}
/* Emulator for BSD syslog() routine
* Accepts: priority
* message
* parameters
*/
void syslog(int priority, const char *message, ...)
{
va_list args;
LPTSTR strs[2];
unsigned short etype;
char *tmp = NULL;
DWORD evid;
/* default event source */
if (INVALID_HANDLE_VALUE == PW32G(log_source))
openlog("php", LOG_PID, LOG_SYSLOG);
switch (priority) { /* translate UNIX type into NT type */
case LOG_ALERT:
etype = EVENTLOG_ERROR_TYPE;
evid = PHP_SYSLOG_ERROR_TYPE;
break;
case LOG_INFO:
etype = EVENTLOG_INFORMATION_TYPE;
evid = PHP_SYSLOG_INFO_TYPE;
break;
default:
etype = EVENTLOG_WARNING_TYPE;
evid = PHP_SYSLOG_WARNING_TYPE;
}
va_start(args, message); /* initialize vararg mechanism */
vspprintf(&tmp, 0, message, args); /* build message */
strs[0] = PW32G(log_header); /* write header */
strs[1] = tmp; /* then the message */
/* report the event */
ReportEvent(PW32G(log_source), etype, (unsigned short) priority, evid, NULL, 2, 0, strs, NULL);
va_end(args);
efree(tmp);
}
/* Emulator for BSD openlog() routine
* Accepts: identity
* options
* facility
*/
void openlog(const char *ident, int logopt, int facility)
{
closelog();
PW32G(log_source) = RegisterEventSource(NULL, "PHP-" PHP_VERSION);
spprintf(&PW32G(log_header), 0, (logopt & LOG_PID) ? "%s[%d]" : "%s", ident, getpid());
}
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: sw=4 ts=4 fdm=marker
* vim<600: sw=4 ts=4
*/