Remove deleted function from header file, update mkfiles.pl
[openssl.git] / crypto / bio / bss_log.c
index c715c106311ab74879ac79feedb78337c9653595..bb676a83a9fe0e0e86d4a54c61747ab5154cae88 100644 (file)
 #include <stdio.h>
 #include <errno.h>
 
-#if defined(WIN32)
+#include "cryptlib.h"
+
+#if defined(OPENSSL_SYS_WINCE)
+#elif defined(OPENSSL_SYS_WIN32)
 #  include <process.h>
-#elif defined(VMS) || defined(__VMS)
+#elif defined(OPENSSL_SYS_VMS)
 #  include <opcdef.h>
 #  include <descrip.h>
 #  include <lib$routines.h>
 #  include <starlet.h>
 #elif defined(__ultrix)
 #  include <sys/syslog.h>
-#elif !defined(MSDOS) /* Unix */
+#elif defined(OPENSSL_SYS_NETWARE)
+#  define NO_SYSLOG
+#elif (!defined(MSDOS) || defined(WATT32)) && !defined(OPENSSL_SYS_VXWORKS) && !defined(NO_SYSLOG)
 #  include <syslog.h>
 #endif
 
-#include "cryptlib.h"
 #include <openssl/buffer.h>
 #include <openssl/err.h>
 
 #ifndef NO_SYSLOG
 
-#if defined(WIN32)
+#if defined(OPENSSL_SYS_WIN32)
 #define LOG_EMERG      0
 #define LOG_ALERT      1
 #define LOG_CRIT       2
 #define LOG_DEBUG      7
 
 #define LOG_DAEMON     (3<<3)
-#elif defined(VMS)
+#elif defined(OPENSSL_SYS_VMS)
 /* On VMS, we don't really care about these, but we need them to compile */
 #define LOG_EMERG      0
 #define LOG_ALERT      1
@@ -118,7 +122,7 @@ static int MS_CALLBACK slg_free(BIO *data);
 static void xopenlog(BIO* bp, char* name, int level);
 static void xsyslog(BIO* bp, int priority, const char* string);
 static void xcloselog(BIO* bp);
-#ifdef WIN32
+#ifdef OPENSSL_SYS_WIN32
 LONG   (WINAPI *go_for_advapi)()       = RegOpenKeyEx;
 HANDLE (WINAPI *register_event_source)()       = NULL;
 BOOL   (WINAPI *deregister_event_source)()     = NULL;
@@ -170,7 +174,36 @@ static int MS_CALLBACK slg_write(BIO *b, const char *in, int inl)
        int ret= inl;
        char* buf;
        char* pp;
-       int priority;
+       int priority, i;
+       static const struct
+               {
+               int strl;
+               char str[10];
+               int log_level;
+               }
+       mapping[] =
+               {
+               { 6, "PANIC ", LOG_EMERG },
+               { 6, "EMERG ", LOG_EMERG },
+               { 4, "EMR ", LOG_EMERG },
+               { 6, "ALERT ", LOG_ALERT },
+               { 4, "ALR ", LOG_ALERT },
+               { 5, "CRIT ", LOG_CRIT },
+               { 4, "CRI ", LOG_CRIT },
+               { 6, "ERROR ", LOG_ERR },
+               { 4, "ERR ", LOG_ERR },
+               { 8, "WARNING ", LOG_WARNING },
+               { 5, "WARN ", LOG_WARNING },
+               { 4, "WAR ", LOG_WARNING },
+               { 7, "NOTICE ", LOG_NOTICE },
+               { 5, "NOTE ", LOG_NOTICE },
+               { 4, "NOT ", LOG_NOTICE },
+               { 5, "INFO ", LOG_INFO },
+               { 4, "INF ", LOG_INFO },
+               { 6, "DEBUG ", LOG_DEBUG },
+               { 4, "DBG ", LOG_DEBUG },
+               { 0, "", LOG_ERR } /* The default */
+               };
 
        if((buf= (char *)OPENSSL_malloc(inl+ 1)) == NULL){
                return(0);
@@ -178,19 +211,10 @@ static int MS_CALLBACK slg_write(BIO *b, const char *in, int inl)
        strncpy(buf, in, inl);
        buf[inl]= '\0';
 
-       if(strncmp(buf, "ERR ", 4) == 0){
-               priority= LOG_ERR;
-               pp= buf+ 4;
-       }else if(strncmp(buf, "WAR ", 4) == 0){
-               priority= LOG_WARNING;
-               pp= buf+ 4;
-       }else if(strncmp(buf, "INF ", 4) == 0){
-               priority= LOG_INFO;
-               pp= buf+ 4;
-       }else{
-               priority= LOG_ERR;
-               pp= buf;
-       }
+       i = 0;
+       while(strncmp(buf, mapping[i].str, mapping[i].strl) != 0) i++;
+       priority = mapping[i].log_level;
+       pp = buf + mapping[i].strl;
 
        xsyslog(b, priority, pp);
 
@@ -221,7 +245,7 @@ static int MS_CALLBACK slg_puts(BIO *bp, const char *str)
        return(ret);
        }
 
-#if defined(WIN32)
+#if defined(OPENSSL_SYS_WIN32)
 
 static void xopenlog(BIO* bp, char* name, int level)
 {
@@ -253,20 +277,26 @@ static void xsyslog(BIO *bp, int priority, const char *string)
        LPCSTR lpszStrings[2];
        WORD evtype= EVENTLOG_ERROR_TYPE;
        int pid = _getpid();
-       char pidbuf[20];
+       char pidbuf[DECIMAL_SIZE(pid)+4];
 
        switch (priority)
                {
+       case LOG_EMERG:
+       case LOG_ALERT:
+       case LOG_CRIT:
        case LOG_ERR:
                evtype = EVENTLOG_ERROR_TYPE;
                break;
        case LOG_WARNING:
                evtype = EVENTLOG_WARNING_TYPE;
                break;
+       case LOG_NOTICE:
        case LOG_INFO:
+       case LOG_DEBUG:
                evtype = EVENTLOG_INFORMATION_TYPE;
                break;
-       default:
+       default:                /* Should never happen, but set it
+                                  as error anyway. */
                evtype = EVENTLOG_ERROR_TYPE;
                break;
                }
@@ -287,7 +317,7 @@ static void xcloselog(BIO* bp)
        bp->ptr= NULL;
 }
 
-#elif defined(VMS)
+#elif defined(OPENSSL_SYS_VMS)
 
 static int VMS_OPC_target = LOG_DAEMON;
 
@@ -346,11 +376,15 @@ static void xcloselog(BIO* bp)
 {
 }
 
-#else /* Unix */
+#else /* Unix/Watt32 */
 
 static void xopenlog(BIO* bp, char* name, int level)
 {
+#ifdef WATT32   /* djgpp/DOS */
+       openlog(name, LOG_PID|LOG_CONS|LOG_NDELAY, level);
+#else
        openlog(name, LOG_PID|LOG_CONS, level);
+#endif
 }
 
 static void xsyslog(BIO *bp, int priority, const char *string)