Back to index

php5  5.3.10
wsyslog.c
Go to the documentation of this file.
00001 /*
00002  * This file modified from sources for imap4 for use
00003  * in PHP 3
00004  */
00005 /*
00006  * Program:   Unix compatibility routines
00007  *
00008  * Author:  Mark Crispin
00009  *      Networks and Distributed Computing
00010  *      Computing & Communications
00011  *      University of Washington
00012  *      Administration Building, AG-44
00013  *      Seattle, WA  98195
00014  *      Internet: MRC@CAC.Washington.EDU
00015  *
00016  * Date:    14 September 1996
00017  * Last Edited: 22 October 1996
00018  *
00019  * Copyright 1996 by the University of Washington
00020  *
00021  *  Permission to use, copy, modify, and distribute this software and its
00022  * documentation for any purpose and without fee is hereby granted, provided
00023  * that the above copyright notice appears in all copies and that both the
00024  * above copyright notice and this permission notice appear in supporting
00025  * documentation, and that the name of the University of Washington not be
00026  * used in advertising or publicity pertaining to distribution of the software
00027  * without specific, written prior permission.  This software is made available
00028  * "as is", and
00029  * THE UNIVERSITY OF WASHINGTON DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED,
00030  * WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION ALL IMPLIED
00031  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND IN
00032  * NO EVENT SHALL THE UNIVERSITY OF WASHINGTON BE LIABLE FOR ANY SPECIAL,
00033  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
00034  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, TORT
00035  * (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF OR IN CONNECTION
00036  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00037  *
00038  */
00039 
00040 
00041 /*              DEDICATION
00042 
00043  *  This file is dedicated to my dog, Unix, also known as Yun-chan and
00044  * Unix J. Terwilliker Jehosophat Aloysius Monstrosity Animal Beast.  Unix
00045  * passed away at the age of 11 1/2 on September 14, 1996, 12:18 PM PDT, after
00046  * a two-month bout with cirrhosis of the liver.
00047  *
00048  *  He was a dear friend, and I miss him terribly.
00049  *
00050  *  Lift a leg, Yunie.  Luv ya forever!!!!
00051  */
00052 
00053 #include "php.h"                          /*php specific */
00054 #include "syslog.h"
00055 #include <stdio.h>
00056 #include <fcntl.h>
00057 #include <process.h>
00058 
00059 #include "php_win32_globals.h"
00060 #include "wsyslog.h"
00061 
00062 void closelog(void)
00063 {
00064        TSRMLS_FETCH();
00065        if (PW32G(log_source)) {
00066               DeregisterEventSource(PW32G(log_source));
00067               PW32G(log_source) = NULL;
00068        }
00069        if (PW32G(log_header)) {
00070               STR_FREE(PW32G(log_header));
00071               PW32G(log_header) = NULL;
00072        }
00073 }
00074 
00075 /* Emulator for BSD syslog() routine
00076  * Accepts: priority
00077  *      message
00078  *      parameters
00079  */
00080 
00081 void syslog(int priority, const char *message, ...)
00082 {
00083        va_list args;
00084        LPTSTR strs[2];
00085        unsigned short etype;
00086        char *tmp = NULL;
00087        DWORD evid;
00088        TSRMLS_FETCH();
00089 
00090        /* default event source */
00091        if (!PW32G(log_source))
00092               openlog("php", LOG_PID, LOG_SYSLOG);
00093 
00094        switch (priority) {                /* translate UNIX type into NT type */
00095               case LOG_ALERT:
00096                      etype = EVENTLOG_ERROR_TYPE;
00097                      evid = PHP_SYSLOG_ERROR_TYPE;
00098                      break;
00099               case LOG_INFO:
00100                      etype = EVENTLOG_INFORMATION_TYPE;
00101                      evid = PHP_SYSLOG_INFO_TYPE;
00102                      break;
00103               default:
00104                      etype = EVENTLOG_WARNING_TYPE;
00105                      evid = PHP_SYSLOG_WARNING_TYPE;
00106        }
00107        va_start(args, message);    /* initialize vararg mechanism */
00108        vspprintf(&tmp, 0, message, args); /* build message */
00109        strs[0] = PW32G(log_header);       /* write header */
00110        strs[1] = tmp;                            /* then the message */
00111        /* report the event */
00112        ReportEvent(PW32G(log_source), etype, (unsigned short) priority, evid, NULL, 2, 0, strs, NULL);
00113        va_end(args);
00114        efree(tmp);
00115 }
00116 
00117 
00118 /* Emulator for BSD openlog() routine
00119  * Accepts: identity
00120  *      options
00121  *      facility
00122  */
00123 
00124 void openlog(const char *ident, int logopt, int facility)
00125 {
00126        TSRMLS_FETCH();
00127 
00128        if (PW32G(log_source)) {
00129               closelog();
00130        }
00131 
00132        STR_FREE(PW32G(log_header));
00133 
00134        PW32G(log_source) = RegisterEventSource(NULL, "PHP-" PHP_VERSION);
00135        spprintf(&PW32G(log_header), 0, (logopt & LOG_PID) ? "%s[%d]" : "%s", ident, getpid());
00136 }