netwerk/srtp/src/crypto/kernel/err.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/netwerk/srtp/src/crypto/kernel/err.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,148 @@
     1.4 +/*
     1.5 + * err.c
     1.6 + *
     1.7 + * error status reporting functions
     1.8 + *
     1.9 + * David A. McGrew
    1.10 + * Cisco Systems, Inc.
    1.11 + */
    1.12 +/*
    1.13 + *	
    1.14 + * Copyright(c) 2001-2006 Cisco Systems, Inc.
    1.15 + * All rights reserved.
    1.16 + * 
    1.17 + * Redistribution and use in source and binary forms, with or without
    1.18 + * modification, are permitted provided that the following conditions
    1.19 + * are met:
    1.20 + * 
    1.21 + *   Redistributions of source code must retain the above copyright
    1.22 + *   notice, this list of conditions and the following disclaimer.
    1.23 + * 
    1.24 + *   Redistributions in binary form must reproduce the above
    1.25 + *   copyright notice, this list of conditions and the following
    1.26 + *   disclaimer in the documentation and/or other materials provided
    1.27 + *   with the distribution.
    1.28 + * 
    1.29 + *   Neither the name of the Cisco Systems, Inc. nor the names of its
    1.30 + *   contributors may be used to endorse or promote products derived
    1.31 + *   from this software without specific prior written permission.
    1.32 + * 
    1.33 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    1.34 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    1.35 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
    1.36 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
    1.37 + * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
    1.38 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    1.39 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    1.40 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    1.41 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
    1.42 + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    1.43 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
    1.44 + * OF THE POSSIBILITY OF SUCH DAMAGE.
    1.45 + *
    1.46 + */
    1.47 +
    1.48 +#include "err.h"
    1.49 +
    1.50 +#ifdef ERR_REPORTING_SYSLOG
    1.51 +# ifdef HAVE_SYSLOG_H
    1.52 +#  include <syslog.h>
    1.53 +# endif
    1.54 +#endif
    1.55 +
    1.56 +
    1.57 +/*  err_level reflects the level of errors that are reported  */
    1.58 +
    1.59 +err_reporting_level_t err_level = err_level_none;
    1.60 +
    1.61 +#ifdef SRTP_KERNEL_LINUX
    1.62 +err_status_t
    1.63 +err_reporting_init(char *ident) {
    1.64 +
    1.65 +  return err_status_ok;
    1.66 +}
    1.67 +
    1.68 +#else /* SRTP_KERNEL_LINUX */	
    1.69 +
    1.70 +/* err_file is the FILE to which errors are reported */
    1.71 +
    1.72 +static FILE *err_file = NULL;
    1.73 +
    1.74 +err_status_t
    1.75 +err_reporting_init(char *ident) {
    1.76 +#ifdef ERR_REPORTING_SYSLOG
    1.77 +  openlog(ident, LOG_PID, LOG_AUTHPRIV);
    1.78 +#endif
    1.79 +  
    1.80 +  /*
    1.81 +   * Believe it or not, openlog doesn't return an error on failure.
    1.82 +   * But then, neither does the syslog() call...
    1.83 +   */
    1.84 +
    1.85 +#ifdef ERR_REPORTING_STDOUT
    1.86 +  err_file = stdout;
    1.87 +#elif defined(USE_ERR_REPORTING_FILE)
    1.88 +  /* open file for error reporting */
    1.89 +  err_file = fopen(ERR_REPORTING_FILE, "w");
    1.90 +  if (err_file == NULL)
    1.91 +    return err_status_init_fail;
    1.92 +#endif
    1.93 +
    1.94 +  return err_status_ok;
    1.95 +}
    1.96 +
    1.97 +void
    1.98 +err_report(int priority, char *format, ...) {
    1.99 +  va_list args;
   1.100 +
   1.101 +  if ((err_reporting_level_t)priority <= err_level) {
   1.102 +
   1.103 +    va_start(args, format);
   1.104 +    if (err_file != NULL) {
   1.105 +      vfprintf(err_file, format, args);
   1.106 +	  /*      fprintf(err_file, "\n"); */
   1.107 +    }
   1.108 +#ifdef ERR_REPORTING_SYSLOG
   1.109 +    if (1) { /* FIXME: Make this a runtime option. */
   1.110 +      int syslogpri;
   1.111 +
   1.112 +      switch (priority) {
   1.113 +      case err_level_emergency:
   1.114 +	syslogpri = LOG_EMERG;
   1.115 +	break;
   1.116 +      case err_level_alert:
   1.117 +	syslogpri = LOG_ALERT;
   1.118 +	break;
   1.119 +      case err_level_critical:
   1.120 +	syslogpri = LOG_CRIT;
   1.121 +	break;
   1.122 +      case err_level_error:
   1.123 +	syslogpri = LOG_ERR;
   1.124 +	break;
   1.125 +      case err_level_warning:
   1.126 +	syslogpri = LOG_WARNING;
   1.127 +	break;
   1.128 +      case err_level_notice:
   1.129 +	syslogpri = LOG_NOTICE;
   1.130 +	break;
   1.131 +      case err_level_info:
   1.132 +	syslogpri = LOG_INFO;
   1.133 +	break;
   1.134 +      case err_level_debug:
   1.135 +      case err_level_none:
   1.136 +      default:
   1.137 +	syslogpri = LOG_DEBUG;
   1.138 +	break;
   1.139 +      }
   1.140 +
   1.141 +      vsyslog(syslogpri, format, args);
   1.142 +#endif
   1.143 +    va_end(args);
   1.144 +  }
   1.145 +}
   1.146 +#endif /* SRTP_KERNEL_LINUX */	
   1.147 +
   1.148 +void
   1.149 +err_reporting_set_level(err_reporting_level_t lvl) { 
   1.150 +  err_level = lvl;
   1.151 +}

mercurial