Vidalia  0.2.21
tcglobal.cpp
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.cpp
13 ** \brief Provides common methods and constants used by the torcontrol library
14 */
15 
16 #include "tcglobal.h"
17 
18 
19 namespace tc {
20 
21 /* Creates a new message using <b>fmt</b> and a severity level of
22  * QtDebugMsg. */
24 debug(const QString &fmt)
25 {
26  return DebugMessage(QtDebugMsg, fmt);
27 }
28 
29 /* Creates a new message using <b>fmt</b> and a severity level of
30  * QtWarningMsg. */
31 DebugMessage
32 warn(const QString &fmt)
33 {
34  return DebugMessage(QtWarningMsg, fmt);
35 }
36 
37 /* Creates a new message using <b>fmt</b> and a severity level of
38  * QtCriticalMsg. */
39 DebugMessage
40 error(const QString &fmt)
41 {
42  return DebugMessage(QtCriticalMsg, fmt);
43 }
44 
45 /* Creates a new message using <b>fmt</b> and a severity level of
46  * QtFatalMsg. */
47 DebugMessage
48 fatal(const QString &fmt)
49 {
50  return DebugMessage(QtFatalMsg, fmt);
51 }
52 
53 /* Converts <b>str</b> to a ConnectionStatusReason enum value. */
56 {
57  if (str.isEmpty())
58  return UnrecognizedReason;
59  if (!str.compare("MISC", Qt::CaseInsensitive))
60  return MiscellaneousReason;
61  if (!str.compare("IDENTITY", Qt::CaseInsensitive))
62  return IdentityMismatch;
63  if (!str.compare("RESOURCELIMIT", Qt::CaseInsensitive))
64  return ResourceLimitReached;
65  if (!str.compare("DONE", Qt::CaseInsensitive))
66  return ConnectionDone;
67  if (!str.compare("CONNECTREFUSED"))
68  return ConnectionRefused;
69  if (!str.compare("CONNECTRESET", Qt::CaseInsensitive))
70  return ConnectionRefused;
71  if (!str.compare("TIMEOUT", Qt::CaseInsensitive))
72  return ConnectionTimeout;
73  if (!str.compare("NOROUTE", Qt::CaseInsensitive))
74  return NoRouteToHost;
75  if (!str.compare("IOERROR", Qt::CaseInsensitive))
76  return ConnectionIoError;
77  return UnrecognizedReason;
78 }
79 
80 /* Converts <b>str</b> to a Severity enum value. */
82 severityFromString(const QString &str)
83 {
84  if (!str.compare("DEBUG", Qt::CaseInsensitive))
85  return DebugSeverity;
86  if (!str.compare("INFO", Qt::CaseInsensitive))
87  return InfoSeverity;
88  if (!str.compare("NOTICE", Qt::CaseInsensitive))
89  return NoticeSeverity;
90  if (!str.compare("WARN", Qt::CaseInsensitive))
91  return WarnSeverity;
92  if (!str.compare("ERR", Qt::CaseInsensitive))
93  return ErrorSeverity;
94  return UnrecognizedSeverity;
95 }
96 
97 }
98