Vidalia 0.3.1
tcglobal.h
Go to the documentation of this file.
1/*
2** This file is part of Vidalia, and is subject to the license terms in the
3** LICENSE file, found in the top level directory of this distribution. If you
4** did not receive the LICENSE file with this file, you may obtain it from the
5** Vidalia source package distributed by the Vidalia Project at
6** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
7** including this file, may be copied, modified, propagated, or distributed
8** except according to the terms described in the LICENSE file.
9*/
10
11/*
12** \file tcglobal.h
13** \brief Provides common methods and constants used by the torcontrol library
14*/
15
16#ifndef _TCGLOBAL_H
17#define _TCGLOBAL_H
18
19#include <QString>
20#include <QMetaType>
21
22namespace tc {
23 /** Helper class to handle formatting log messages with arguments. */
25 struct Stream {
26 Stream(QtMsgType t, const QString &fmt)
27 : type(t), buf(fmt), ref(1) {}
28 QtMsgType type; /**< DebugMessage severity level. */
29 QString buf; /**< Log message buffer. */
30 int ref; /**< Reference counter. */
32
33 public:
34 /** Constructs a new DebugMessage with severity <b>t</b> and the message
35 * format <b>fmt</b>. */
36 inline DebugMessage(QtMsgType t, const QString &fmt)
37 : stream(new Stream(t, fmt)) {}
38 inline DebugMessage(const DebugMessage &o)
39 : stream(o.stream) { ++stream->ref; }
40 virtual ~DebugMessage() {
41 if (!--stream->ref) {
42 stream->buf.prepend("torcontrol: ");
43 qt_message_output(stream->type, qPrintable(stream->buf));
44 delete stream;
45 }
46 }
47
48 inline DebugMessage arg(const QString &a)
49 { stream->buf = stream->buf.arg(a); return *this; }
50 inline DebugMessage arg(int a)
51 { stream->buf = stream->buf.arg(a); return *this; }
52 };
53}
54
55namespace tc {
67 };
68 /** Severity values used in log message and status events. */
69 enum Severity {
70 UnrecognizedSeverity = 0, /**< An unrecognized severity value. */
71 DebugSeverity = (1u<<4), /**< Hyper-verbose events used for debugging. */
72 InfoSeverity = (1u<<3), /**< Verbose events that can occur frequently. */
73 NoticeSeverity = (1u<<2), /**< A not-so-bad event. */
74 WarnSeverity = (1u<<1), /**< An important, but non-fatal event. */
75 ErrorSeverity = (1u<<0) /**< A critical event. */
76 };
77 /** SOCKS error types used by Tor status event notifications. These are
78 * emitted in the TorControl::socksError() signal. */
80 DangerousSocksTypeError, /**< The SOCKS type uses only IP addresses. */
81 UnknownSocksProtocolError, /**< Unknown SOCKS protocol type. */
82 BadSocksHostnameError /**< Application provided an invalid hostname. */
83 };
84 /** Reasons that use of the user's current Tor version would be
85 * discouraged. */
90 };
91
92 /** Converts <b>str</b> to a Severity enum value. */
93 Severity severityFromString(const QString &str);
94
95 /** Converts <b>str</b> to a ConnectionStatusReason enum value. */
97
98 /** Creates a new message using <b>fmt</b> and a severity level of
99 * QtDebugMsg. */
100 DebugMessage debug(const QString &fmt);
101
102 /** Creates a new message using <b>fmt</b> and a severity level of
103 * QtWarningMsg. */
104 DebugMessage warn(const QString &fmt);
105
106 /** Creates a new message using <b>fmt</b> and a severity level of
107 * QtCriticalMsg. */
108 DebugMessage error(const QString &fmt);
109
110 /** Creates a new message using <b>fmt</b> and a severity level of
111 * QtFatalMsg. */
112 DebugMessage fatal(const QString &fmt);
113}
114
118
119#endif
120
Q_DECLARE_METATYPE(BootstrapStatus)
DebugMessage(const DebugMessage &o)
Definition: tcglobal.h:38
DebugMessage arg(const QString &a)
Definition: tcglobal.h:48
virtual ~DebugMessage()
Definition: tcglobal.h:40
DebugMessage arg(int a)
Definition: tcglobal.h:50
DebugMessage(QtMsgType t, const QString &fmt)
Definition: tcglobal.h:36
struct tc::DebugMessage::Stream * stream
Definition: tcglobal.cpp:19
DebugMessage warn(const QString &fmt)
Definition: tcglobal.cpp:32
TorVersionStatus
Definition: tcglobal.h:86
@ NewTorVersion
Definition: tcglobal.h:89
@ UnrecommendedTorVersion
Definition: tcglobal.h:88
@ ObsoleteTorVersion
Definition: tcglobal.h:87
DebugMessage fatal(const QString &fmt)
Definition: tcglobal.cpp:48
DebugMessage error(const QString &fmt)
Definition: tcglobal.cpp:40
ConnectionStatusReason
Definition: tcglobal.h:56
@ ConnectionReset
Definition: tcglobal.h:62
@ NoRouteToHost
Definition: tcglobal.h:65
@ UnrecognizedReason
Definition: tcglobal.h:57
@ ResourceLimitReached
Definition: tcglobal.h:66
@ ConnectionTimeout
Definition: tcglobal.h:63
@ ConnectionRefused
Definition: tcglobal.h:61
@ MiscellaneousReason
Definition: tcglobal.h:58
@ ConnectionIoError
Definition: tcglobal.h:64
@ IdentityMismatch
Definition: tcglobal.h:59
@ ConnectionDone
Definition: tcglobal.h:60
SocksError
Definition: tcglobal.h:79
@ UnknownSocksProtocolError
Definition: tcglobal.h:81
@ DangerousSocksTypeError
Definition: tcglobal.h:80
@ BadSocksHostnameError
Definition: tcglobal.h:82
Severity severityFromString(const QString &str)
Definition: tcglobal.cpp:82
Severity
Definition: tcglobal.h:69
@ UnrecognizedSeverity
Definition: tcglobal.h:70
@ DebugSeverity
Definition: tcglobal.h:71
@ NoticeSeverity
Definition: tcglobal.h:73
@ ErrorSeverity
Definition: tcglobal.h:75
@ WarnSeverity
Definition: tcglobal.h:74
@ InfoSeverity
Definition: tcglobal.h:72
ConnectionStatusReason connectionStatusReasonFromString(const QString &str)
Definition: tcglobal.cpp:55
DebugMessage debug(const QString &fmt)
Definition: tcglobal.cpp:24
Stream(QtMsgType t, const QString &fmt)
Definition: tcglobal.h:26