⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 error.h

📁 OpenVPN is a robust and highly flexible tunneling application that uses all of the encryption, authe
💻 H
字号:
/* *  OpenVPN -- An application to securely tunnel IP networks *             over a single TCP/UDP port, with support for SSL/TLS-based *             session authentication and key exchange, *             packet encryption, packet authentication, and *             packet compression. * *  Copyright (C) 2002-2004 James Yonan <jim@yonan.net> * *  This program is free software; you can redistribute it and/or modify *  it under the terms of the GNU General Public License as published by *  the Free Software Foundation; either version 2 of the License, or *  (at your option) any later version. * *  This program is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *  GNU General Public License for more details. * *  You should have received a copy of the GNU General Public License *  along with this program (see the file COPYING included with this *  distribution); if not, write to the Free Software Foundation, Inc., *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */#ifndef ERROR_H#define ERROR_H#include "basic.h"#include "thread.h"struct gc_arena;/* * Where should messages be printed before syslog is opened? * Not used if OPENVPN_DEBUG_COMMAND_LINE is defined. */#define OPENVPN_MSG_FP stdout/* * Exit status codes */#define OPENVPN_EXIT_STATUS_GOOD                    0#define OPENVPN_EXIT_STATUS_ERROR                   1#define OPENVPN_EXIT_STATUS_USAGE                   1#define OPENVPN_EXIT_STATUS_CANNOT_OPEN_DEBUG_FILE  1/* * Special command line debugging mode. * If OPENVPN_DEBUG_COMMAND_LINE * is defined, contents of argc/argv will * be dumped to OPENVPN_DEBUG_FILE as well * as all other OpenVPN messages. *//* #define OPENVPN_DEBUG_COMMAND_LINE */#define OPENVPN_DEBUG_FILE PACKAGE ".log"/* String and Error functions */#ifdef WIN32# define openvpn_errno()             GetLastError()# define openvpn_errno_socket()      WSAGetLastError()# define openvpn_strerror(e, gc)     strerror_win32(e, gc)  const char *strerror_win32 (DWORD errnum, struct gc_arena *gc);#else# define openvpn_errno()             errno# define openvpn_errno_socket()      errno# define openvpn_strerror(x, gc)     strerror(x)#endif/* * These globals should not be accessed directly, * but rather through macros or inline functions defined below. */extern unsigned int x_debug_level;extern int x_msg_line_num;/* msg() flags */#define M_DEBUG_LEVEL     (0x0F)	 /* debug level mask */#define M_FATAL           (1<<4)	 /* exit program */#define M_NONFATAL        (1<<5)	 /* non-fatal error */#define M_WARN	          (1<<6)	 /* call syslog with LOG_WARNING */#define M_DEBUG           (1<<7)#define M_ERRNO           (1<<8)	 /* show errno description */#define M_ERRNO_SOCK      (1<<9)	 /* show socket errno description */#define M_SSL             (1<<10)	 /* show SSL error */#define M_NOLOCK          (1<<11)        /* don't lock/unlock mutex */      #define M_NOMUTE          (1<<12)        /* don't do mute processing */#define M_NOPREFIX        (1<<13)        /* don't show date/time prefix */#define M_USAGE_SMALL     (1<<14)        /* fatal options error, call usage_small *//* flag combinations which are frequently used */#define M_ERR     (M_FATAL | M_ERRNO)#define M_SOCKERR (M_FATAL | M_ERRNO_SOCK)#define M_SSLERR  (M_FATAL | M_SSL)#define M_USAGE   (M_USAGE_SMALL | M_NOPREFIX)/* * Mute levels are designed to avoid large numbers of * mostly similar messages clogging the log file. * * A mute level of 0 is always printed. */#define MUTE_LEVEL_SHIFT 16#define MUTE_LEVEL_MASK 0xFF#define ENCODE_MUTE_LEVEL(mute_level) (((mute_level) & MUTE_LEVEL_MASK) << MUTE_LEVEL_SHIFT)#define DECODE_MUTE_LEVEL(flags) (((flags) >> MUTE_LEVEL_SHIFT) & MUTE_LEVEL_MASK)/* * log_level:  verbosity level n (--verb n) must be >= log_level to print. * mute_level: don't print more than n (--mute n) consecutive messages at *             a given mute level, or if 0 disable muting and print everything. */#define LOGLEV(log_level, mute_level, other) (((log_level)-1) | ENCODE_MUTE_LEVEL(mute_level) | other)/* * If compiler supports variable arguments in macros, define * msg() as a macro for optimization win. */#define MSG_TEST(flags) ((((unsigned int)flags) & M_DEBUG_LEVEL) < x_debug_level || ((flags) & M_FATAL))#if defined(HAVE_CPP_VARARG_MACRO_ISO) && !defined(__LCLINT__)#define HAVE_VARARG_MACROS#define msg(flags, ...) do { if (MSG_TEST(flags)) x_msg((flags), __VA_ARGS__); } while (false)#elif defined(HAVE_CPP_VARARG_MACRO_GCC) && !defined(__LCLINT__)#define HAVE_VARARG_MACROS#define msg(flags, args...) do { if (MSG_TEST(flags)) x_msg((flags), args); } while (false)#else#warning this compiler appears to lack vararg macros which will cause a significant degradation in efficiency (you can ignore this warning if you are using LCLINT)#define msg x_msg#endifvoid x_msg (unsigned int flags, const char *format, ...)#ifdef __GNUC__    __attribute__ ((format (printf, 2, 3)))#endif    ; /* should be called via msg above *//* * Function prototypes */void error_reset (void);void set_debug_level (int level);void set_mute_cutoff (int cutoff);/* * File to print messages to before syslog is opened. */FILE *msg_fp(void);/* Fatal logic errors */#define ASSERT(x) do { if (!(x)) assert_failed(__FILE__, __LINE__); } while (false)void assert_failed (const char *filename, int line);/* Inline functions */static inline boolcheck_debug_level (unsigned int level){  return (level & M_DEBUG_LEVEL) < x_debug_level;}/* syslog output */void open_syslog (const char *pgmname);void close_syslog ();/* log file output */void redirect_stdout_stderr (const char *file, bool append);/* print out-of-memory error and exit */void out_of_memory (void);/* exit program */void openvpn_exit (int status);/* * Check the return status of read/write routines. */struct link_socket;struct tuntap;extern unsigned int x_cs_info_level;extern unsigned int x_cs_verbose_level;extern unsigned int x_cs_err_delay_ms;void reset_check_status (void);void set_check_status (unsigned int info_level, unsigned int verbose_level);void x_check_status (int status,		     const char *description,		     struct link_socket *sock,		     struct tuntap *tt);static inline voidcheck_status (int status, const char *description, struct link_socket *sock, struct tuntap *tt){  if (status < 0 || check_debug_level (x_cs_verbose_level))    x_check_status (status, description, sock, tt);}static inline voidset_check_status_error_delay (unsigned int milliseconds){  x_cs_err_delay_ms = milliseconds;}/* * In multiclient mode, put a client-specific prefix * before each message. * * TODO: x_msg_prefix should be thread-local */extern const char *x_msg_prefix;#ifdef USE_PTHREADextern pthread_key_t x_msg_prefix_key;#endifvoid msg_thread_init (void);void msg_thread_uninit (void);static inline voidmsg_set_prefix (const char *prefix){#ifdef USE_PTHREAD  if (openvpn_thread_enabled ())    {      ASSERT (!pthread_setspecific (x_msg_prefix_key, prefix));    }  else#endif    x_msg_prefix = prefix;}static inline const char *msg_get_prefix (void){#ifdef USE_PTHREAD  if (openvpn_thread_enabled ())    return (const char *) pthread_getspecific (x_msg_prefix_key);  else#endif    return x_msg_prefix;}#include "errlevel.h"#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -