You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
3.6 KiB

27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
27 years ago
  1. /*
  2. * This file modified from sources for imap4 for use
  3. * in PHP 3
  4. */
  5. /*
  6. * Program: Unix compatibility routines
  7. *
  8. * Author: Mark Crispin
  9. * Networks and Distributed Computing
  10. * Computing & Communications
  11. * University of Washington
  12. * Administration Building, AG-44
  13. * Seattle, WA 98195
  14. * Internet: MRC@CAC.Washington.EDU
  15. *
  16. * Date: 14 September 1996
  17. * Last Edited: 22 October 1996
  18. *
  19. * Copyright 1996 by the University of Washington
  20. *
  21. * Permission to use, copy, modify, and distribute this software and its
  22. * documentation for any purpose and without fee is hereby granted, provided
  23. * that the above copyright notice appears in all copies and that both the
  24. * above copyright notice and this permission notice appear in supporting
  25. * documentation, and that the name of the University of Washington not be
  26. * used in advertising or publicity pertaining to distribution of the software
  27. * without specific, written prior permission. This software is made available
  28. * "as is", and
  29. * THE UNIVERSITY OF WASHINGTON DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED,
  30. * WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION ALL IMPLIED
  31. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND IN
  32. * NO EVENT SHALL THE UNIVERSITY OF WASHINGTON BE LIABLE FOR ANY SPECIAL,
  33. * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  34. * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, TORT
  35. * (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF OR IN CONNECTION
  36. * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  37. *
  38. */
  39. /* DEDICATION
  40. * This file is dedicated to my dog, Unix, also known as Yun-chan and
  41. * Unix J. Terwilliker Jehosophat Aloysius Monstrosity Animal Beast. Unix
  42. * passed away at the age of 11 1/2 on September 14, 1996, 12:18 PM PDT, after
  43. * a two-month bout with cirrhosis of the liver.
  44. *
  45. * He was a dear friend, and I miss him terribly.
  46. *
  47. * Lift a leg, Yunie. Luv ya forever!!!!
  48. */
  49. #include "php.h" /*php specific */
  50. #include "syslog.h"
  51. #include <stdio.h>
  52. #include <fcntl.h>
  53. #include <process.h>
  54. #ifndef THREAD_SAFE
  55. static char *loghdr; /* log file header string */
  56. static HANDLE loghdl = NULL; /* handle of event source */
  57. #endif
  58. void closelog(void)
  59. {
  60. DeregisterEventSource(loghdl);
  61. efree(loghdr);
  62. }
  63. /* Emulator for BSD syslog() routine
  64. * Accepts: priority
  65. * message
  66. * parameters
  67. */
  68. void syslog(int priority, const char *message,...)
  69. {
  70. va_list args;
  71. LPTSTR strs[2];
  72. char tmp[1024]; /* callers must be careful not to pop this */
  73. unsigned short etype;
  74. /* default event source */
  75. if (!loghdl)
  76. openlog("c-client", LOG_PID, LOG_MAIL);
  77. switch (priority) { /* translate UNIX type into NT type */
  78. case LOG_ALERT:
  79. etype = EVENTLOG_ERROR_TYPE;
  80. break;
  81. case LOG_INFO:
  82. etype = EVENTLOG_INFORMATION_TYPE;
  83. break;
  84. default:
  85. etype = EVENTLOG_WARNING_TYPE;
  86. }
  87. va_start(args, message); /* initialize vararg mechanism */
  88. vsprintf(tmp, message, args); /* build message */
  89. strs[0] = loghdr; /* write header */
  90. strs[1] = tmp; /* then the message */
  91. /* report the event */
  92. ReportEvent(loghdl, etype, (unsigned short) priority, 2000, NULL, 2, 0, strs, NULL);
  93. va_end(args);
  94. }
  95. /* Emulator for BSD openlog() routine
  96. * Accepts: identity
  97. * options
  98. * facility
  99. */
  100. void openlog(const char *ident, int logopt, int facility)
  101. {
  102. char tmp[1024];
  103. if (loghdl) {
  104. closelog();
  105. }
  106. loghdl = RegisterEventSource(NULL, ident);
  107. sprintf(tmp, (logopt & LOG_PID) ? "%s[%d]" : "%s", ident, getpid());
  108. loghdr = estrdup(tmp); /* save header for later */
  109. }