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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /*
     2  * err.c
     3  *
     4  * error status reporting functions
     5  *
     6  * David A. McGrew
     7  * Cisco Systems, Inc.
     8  */
     9 /*
    10  *	
    11  * Copyright(c) 2001-2006 Cisco Systems, Inc.
    12  * All rights reserved.
    13  * 
    14  * Redistribution and use in source and binary forms, with or without
    15  * modification, are permitted provided that the following conditions
    16  * are met:
    17  * 
    18  *   Redistributions of source code must retain the above copyright
    19  *   notice, this list of conditions and the following disclaimer.
    20  * 
    21  *   Redistributions in binary form must reproduce the above
    22  *   copyright notice, this list of conditions and the following
    23  *   disclaimer in the documentation and/or other materials provided
    24  *   with the distribution.
    25  * 
    26  *   Neither the name of the Cisco Systems, Inc. nor the names of its
    27  *   contributors may be used to endorse or promote products derived
    28  *   from this software without specific prior written permission.
    29  * 
    30  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    31  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    32  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
    33  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
    34  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
    35  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    36  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    37  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
    39  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    40  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
    41  * OF THE POSSIBILITY OF SUCH DAMAGE.
    42  *
    43  */
    45 #include "err.h"
    47 #ifdef ERR_REPORTING_SYSLOG
    48 # ifdef HAVE_SYSLOG_H
    49 #  include <syslog.h>
    50 # endif
    51 #endif
    54 /*  err_level reflects the level of errors that are reported  */
    56 err_reporting_level_t err_level = err_level_none;
    58 #ifdef SRTP_KERNEL_LINUX
    59 err_status_t
    60 err_reporting_init(char *ident) {
    62   return err_status_ok;
    63 }
    65 #else /* SRTP_KERNEL_LINUX */	
    67 /* err_file is the FILE to which errors are reported */
    69 static FILE *err_file = NULL;
    71 err_status_t
    72 err_reporting_init(char *ident) {
    73 #ifdef ERR_REPORTING_SYSLOG
    74   openlog(ident, LOG_PID, LOG_AUTHPRIV);
    75 #endif
    77   /*
    78    * Believe it or not, openlog doesn't return an error on failure.
    79    * But then, neither does the syslog() call...
    80    */
    82 #ifdef ERR_REPORTING_STDOUT
    83   err_file = stdout;
    84 #elif defined(USE_ERR_REPORTING_FILE)
    85   /* open file for error reporting */
    86   err_file = fopen(ERR_REPORTING_FILE, "w");
    87   if (err_file == NULL)
    88     return err_status_init_fail;
    89 #endif
    91   return err_status_ok;
    92 }
    94 void
    95 err_report(int priority, char *format, ...) {
    96   va_list args;
    98   if ((err_reporting_level_t)priority <= err_level) {
   100     va_start(args, format);
   101     if (err_file != NULL) {
   102       vfprintf(err_file, format, args);
   103 	  /*      fprintf(err_file, "\n"); */
   104     }
   105 #ifdef ERR_REPORTING_SYSLOG
   106     if (1) { /* FIXME: Make this a runtime option. */
   107       int syslogpri;
   109       switch (priority) {
   110       case err_level_emergency:
   111 	syslogpri = LOG_EMERG;
   112 	break;
   113       case err_level_alert:
   114 	syslogpri = LOG_ALERT;
   115 	break;
   116       case err_level_critical:
   117 	syslogpri = LOG_CRIT;
   118 	break;
   119       case err_level_error:
   120 	syslogpri = LOG_ERR;
   121 	break;
   122       case err_level_warning:
   123 	syslogpri = LOG_WARNING;
   124 	break;
   125       case err_level_notice:
   126 	syslogpri = LOG_NOTICE;
   127 	break;
   128       case err_level_info:
   129 	syslogpri = LOG_INFO;
   130 	break;
   131       case err_level_debug:
   132       case err_level_none:
   133       default:
   134 	syslogpri = LOG_DEBUG;
   135 	break;
   136       }
   138       vsyslog(syslogpri, format, args);
   139 #endif
   140     va_end(args);
   141   }
   142 }
   143 #endif /* SRTP_KERNEL_LINUX */	
   145 void
   146 err_reporting_set_level(err_reporting_level_t lvl) { 
   147   err_level = lvl;
   148 }

mercurial