Vidalia
0.2.15
|
00001 /* 00002 ** This file is part of Vidalia, and is subject to the license terms in the 00003 ** LICENSE file, found in the top level directory of this distribution. If you 00004 ** did not receive the LICENSE file with this file, you may obtain it from the 00005 ** Vidalia source package distributed by the Vidalia Project at 00006 ** http://www.torproject.org/projects/vidalia.html. No part of Vidalia, 00007 ** including this file, may be copied, modified, propagated, or distributed 00008 ** except according to the terms described in the LICENSE file. 00009 */ 00010 00011 /* 00012 ** \file tcglobal.h 00013 ** \brief Provides common methods and constants used by the torcontrol library 00014 */ 00015 00016 #ifndef _TCGLOBAL_H 00017 #define _TCGLOBAL_H 00018 00019 #include <QString> 00020 #include <QMetaType> 00021 00022 namespace tc { 00023 /** Helper class to handle formatting log messages with arguments. */ 00024 class DebugMessage { 00025 struct Stream { 00026 Stream(QtMsgType t, const QString &fmt) 00027 : type(t), buf(fmt), ref(1) {} 00028 QtMsgType type; /**< DebugMessage severity level. */ 00029 QString buf; /**< Log message buffer. */ 00030 int ref; /**< Reference counter. */ 00031 } *stream; 00032 00033 public: 00034 /** Constructs a new DebugMessage with severity <b>t</b> and the message 00035 * format <b>fmt</b>. */ 00036 inline DebugMessage(QtMsgType t, const QString &fmt) 00037 : stream(new Stream(t, fmt)) {} 00038 inline DebugMessage(const DebugMessage &o) 00039 : stream(o.stream) { ++stream->ref; } 00040 virtual ~DebugMessage() { 00041 if (!--stream->ref) { 00042 stream->buf.prepend("torcontrol: "); 00043 qt_message_output(stream->type, qPrintable(stream->buf)); 00044 delete stream; 00045 } 00046 } 00047 00048 inline DebugMessage arg(const QString &a) 00049 { stream->buf = stream->buf.arg(a); return *this; } 00050 inline DebugMessage arg(int a) 00051 { stream->buf = stream->buf.arg(a); return *this; } 00052 }; 00053 } 00054 00055 namespace tc { 00056 enum ConnectionStatusReason { 00057 UnrecognizedReason, 00058 MiscellaneousReason, 00059 IdentityMismatch, 00060 ConnectionDone, 00061 ConnectionRefused, 00062 ConnectionReset, 00063 ConnectionTimeout, 00064 ConnectionIoError, 00065 NoRouteToHost, 00066 ResourceLimitReached 00067 }; 00068 /** Severity values used in log message and status events. */ 00069 enum Severity { 00070 UnrecognizedSeverity = 0, /**< An unrecognized severity value. */ 00071 DebugSeverity = (1u<<4), /**< Hyper-verbose events used for debugging. */ 00072 InfoSeverity = (1u<<3), /**< Verbose events that can occur frequently. */ 00073 NoticeSeverity = (1u<<2), /**< A not-so-bad event. */ 00074 WarnSeverity = (1u<<1), /**< An important, but non-fatal event. */ 00075 ErrorSeverity = (1u<<0) /**< A critical event. */ 00076 }; 00077 /** SOCKS error types used by Tor status event notifications. These are 00078 * emitted in the TorControl::socksError() signal. */ 00079 enum SocksError { 00080 DangerousSocksTypeError, /**< The SOCKS type uses only IP addresses. */ 00081 UnknownSocksProtocolError, /**< Unknown SOCKS protocol type. */ 00082 BadSocksHostnameError /**< Application provided an invalid hostname. */ 00083 }; 00084 /** Reasons that use of the user's current Tor version would be 00085 * discouraged. */ 00086 enum TorVersionStatus { 00087 ObsoleteTorVersion, 00088 UnrecommendedTorVersion, 00089 NewTorVersion 00090 }; 00091 00092 /** Converts <b>str</b> to a Severity enum value. */ 00093 Severity severityFromString(const QString &str); 00094 00095 /** Converts <b>str</b> to a ConnectionStatusReason enum value. */ 00096 ConnectionStatusReason connectionStatusReasonFromString(const QString &str); 00097 00098 /** Creates a new message using <b>fmt</b> and a severity level of 00099 * QtDebugMsg. */ 00100 DebugMessage debug(const QString &fmt); 00101 00102 /** Creates a new message using <b>fmt</b> and a severity level of 00103 * QtWarningMsg. */ 00104 DebugMessage warn(const QString &fmt); 00105 00106 /** Creates a new message using <b>fmt</b> and a severity level of 00107 * QtCriticalMsg. */ 00108 DebugMessage error(const QString &fmt); 00109 00110 /** Creates a new message using <b>fmt</b> and a severity level of 00111 * QtFatalMsg. */ 00112 DebugMessage fatal(const QString &fmt); 00113 } 00114 00115 Q_DECLARE_METATYPE(tc::Severity) 00116 Q_DECLARE_METATYPE(tc::SocksError) 00117 Q_DECLARE_METATYPE(tc::TorVersionStatus) 00118 00119 #endif 00120