Sophie

Sophie

distrib > Mandriva > 2010.2 > i586 > media > contrib-backports > by-pkgid > 9601c7beb4ff23e834bfa171795ed560 > files > 319

vidalia-0.2.9-1mdv2010.1.i586.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Vidalia: TorControl.cpp Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Generated by Doxygen 1.6.3 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li><a href="dirs.html"><span>Directories</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
      <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
    </ul>
  </div>
  <div class="navpath"><a class="el" href="dir_b47abd1aad201a152869566145babb61.html">src</a>&nbsp;&raquo;&nbsp;<a class="el" href="dir_67a2ce25601334632bdc5ef4a72c0f17.html">torcontrol</a>
  </div>
</div>
<div class="contents">
<h1>TorControl.cpp</h1><a href="_tor_control_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment">**  This file is part of Vidalia, and is subject to the license terms in the</span>
<a name="l00003"></a>00003 <span class="comment">**  LICENSE file, found in the top level directory of this distribution. If</span>
<a name="l00004"></a>00004 <span class="comment">**  you did not receive the LICENSE file with this file, you may obtain it</span>
<a name="l00005"></a>00005 <span class="comment">**  from the Vidalia source package distributed by the Vidalia Project at</span>
<a name="l00006"></a>00006 <span class="comment">**  http://www.vidalia-project.net/. No part of Vidalia, including this file,</span>
<a name="l00007"></a>00007 <span class="comment">**  may be copied, modified, propagated, or distributed except according to</span>
<a name="l00008"></a>00008 <span class="comment">**  the terms described in the LICENSE file.</span>
<a name="l00009"></a>00009 <span class="comment">*/</span>
<a name="l00010"></a>00010 
<a name="l00011"></a>00011 <span class="comment">/*</span>
<a name="l00012"></a>00012 <span class="comment">** \file TorControl.cpp</span>
<a name="l00013"></a>00013 <span class="comment">** \version $Id: TorControl.cpp 4100 2009-09-01 13:54:27Z edmanm $</span>
<a name="l00014"></a>00014 <span class="comment">** \brief Object for interacting with the Tor process and control interface</span>
<a name="l00015"></a>00015 <span class="comment">*/</span>
<a name="l00016"></a>00016 
<a name="l00017"></a>00017 <span class="preprocessor">#include &quot;<a class="code" href="_tor_control_8h.html">TorControl.h</a>&quot;</span>
<a name="l00018"></a>00018 <span class="preprocessor">#include &quot;<a class="code" href="_router_descriptor_8h.html">RouterDescriptor.h</a>&quot;</span>
<a name="l00019"></a>00019 <span class="preprocessor">#include &quot;<a class="code" href="_protocol_info_8h.html">ProtocolInfo.h</a>&quot;</span>
<a name="l00020"></a>00020 <span class="preprocessor">#include &quot;<a class="code" href="_router_status_8h.html">RouterStatus.h</a>&quot;</span>
<a name="l00021"></a>00021 <span class="preprocessor">#include &quot;<a class="code" href="file_8h.html">file.h</a>&quot;</span>
<a name="l00022"></a>00022 <span class="preprocessor">#include &quot;<a class="code" href="stringutil_8h.html">stringutil.h</a>&quot;</span>
<a name="l00023"></a>00023 
<a name="l00024"></a>00024 <span class="preprocessor">#include &lt;QHostAddress&gt;</span>
<a name="l00025"></a>00025 <span class="preprocessor">#include &lt;QVariantMap&gt;</span>
<a name="l00026"></a>00026 
<a name="l00027"></a>00027 <span class="comment"></span>
<a name="l00028"></a>00028 <span class="comment">/** Default constructor */</span>
<a name="l00029"></a><a class="code" href="class_tor_control.html#a3bcb4b2f38f0ddb34d45b417c847082e">00029</a> <a class="code" href="class_tor_control.html#a3bcb4b2f38f0ddb34d45b417c847082e">TorControl::TorControl</a>()
<a name="l00030"></a>00030 {
<a name="l00031"></a>00031 <span class="preprocessor">#define RELAY_SIGNAL(src, sig) \</span>
<a name="l00032"></a>00032 <span class="preprocessor">  QObject::connect((src), (sig), this, (sig))</span>
<a name="l00033"></a>00033 <span class="preprocessor"></span>
<a name="l00034"></a>00034   <span class="comment">/* Create a TorEvents object to receive and parse asynchronous events</span>
<a name="l00035"></a>00035 <span class="comment">   * from Tor&#39;s control port, and relay them as external signals from</span>
<a name="l00036"></a>00036 <span class="comment">   * this TorControl object. */</span>
<a name="l00037"></a>00037   <a class="code" href="class_tor_control.html#ae5f6211f798be2e442b5fc3fb6f3d09e">_eventHandler</a> = <span class="keyword">new</span> <a class="code" href="class_tor_events.html">TorEvents</a>(<span class="keyword">this</span>);
<a name="l00038"></a>00038   <a class="code" href="_tor_control_8cpp.html#affa8ac255dc59c416e615eae17e0ab47">RELAY_SIGNAL</a>(<a class="code" href="class_tor_control.html#ae5f6211f798be2e442b5fc3fb6f3d09e">_eventHandler</a>, SIGNAL(<a class="code" href="class_tor_control.html#a28b4b60a0092a39dbe1484e3193dcb83">circuitEstablished</a>()));
<a name="l00039"></a>00039   <a class="code" href="_tor_control_8cpp.html#affa8ac255dc59c416e615eae17e0ab47">RELAY_SIGNAL</a>(<a class="code" href="class_tor_control.html#ae5f6211f798be2e442b5fc3fb6f3d09e">_eventHandler</a>, SIGNAL(<a class="code" href="class_tor_control.html#a564b2d92a1107cee2280966c67fd847f">dangerousTorVersion</a>(<a class="code" href="namespacetc.html#a8389db682e80cb6921e26b529e2ec52c">tc::TorVersionStatus</a>,
<a name="l00040"></a>00040                                                          QString, QStringList)));
<a name="l00041"></a>00041   <a class="code" href="_tor_control_8cpp.html#affa8ac255dc59c416e615eae17e0ab47">RELAY_SIGNAL</a>(<a class="code" href="class_tor_control.html#ae5f6211f798be2e442b5fc3fb6f3d09e">_eventHandler</a>, SIGNAL(<a class="code" href="class_tor_control.html#a472410fd4c295304639dfa3191b78530">addressMapped</a>(QString,QString,QDateTime)));
<a name="l00042"></a>00042   <a class="code" href="_tor_control_8cpp.html#affa8ac255dc59c416e615eae17e0ab47">RELAY_SIGNAL</a>(<a class="code" href="class_tor_control.html#ae5f6211f798be2e442b5fc3fb6f3d09e">_eventHandler</a>, SIGNAL(<a class="code" href="class_tor_control.html#a85ad0e4ccd9c7b37ddf91c694f5c3651">bandwidthUpdate</a>(quint64, quint64)));
<a name="l00043"></a>00043   <a class="code" href="_tor_control_8cpp.html#affa8ac255dc59c416e615eae17e0ab47">RELAY_SIGNAL</a>(<a class="code" href="class_tor_control.html#ae5f6211f798be2e442b5fc3fb6f3d09e">_eventHandler</a>, SIGNAL(<a class="code" href="class_tor_control.html#a607627fbee13b0292408f558994634a5">circuitStatusChanged</a>(<a class="code" href="class_circuit.html">Circuit</a>)));
<a name="l00044"></a>00044   <a class="code" href="_tor_control_8cpp.html#affa8ac255dc59c416e615eae17e0ab47">RELAY_SIGNAL</a>(<a class="code" href="class_tor_control.html#ae5f6211f798be2e442b5fc3fb6f3d09e">_eventHandler</a>, SIGNAL(<a class="code" href="class_tor_control.html#aa8bbc2d13f1e8c1c4f564172b5db6a5b">streamStatusChanged</a>(<a class="code" href="class_stream.html">Stream</a>)));
<a name="l00045"></a>00045   <a class="code" href="_tor_control_8cpp.html#affa8ac255dc59c416e615eae17e0ab47">RELAY_SIGNAL</a>(<a class="code" href="class_tor_control.html#ae5f6211f798be2e442b5fc3fb6f3d09e">_eventHandler</a>, SIGNAL(<a class="code" href="class_tor_control.html#a352852cedb94e6e753a62035a1c73535">newDescriptors</a>(QStringList)));
<a name="l00046"></a>00046   <a class="code" href="_tor_control_8cpp.html#affa8ac255dc59c416e615eae17e0ab47">RELAY_SIGNAL</a>(<a class="code" href="class_tor_control.html#ae5f6211f798be2e442b5fc3fb6f3d09e">_eventHandler</a>, SIGNAL(<a class="code" href="class_tor_control.html#a9c881f31a2afc32ba6c488f247c20bc8">logMessage</a>(<a class="code" href="namespacetc.html#abb893107129c283d2eb0238e46eb3d4c">tc::Severity</a>, QString)));
<a name="l00047"></a>00047   <a class="code" href="_tor_control_8cpp.html#affa8ac255dc59c416e615eae17e0ab47">RELAY_SIGNAL</a>(<a class="code" href="class_tor_control.html#ae5f6211f798be2e442b5fc3fb6f3d09e">_eventHandler</a>, SIGNAL(<a class="code" href="class_tor_control.html#aa21eaeb2d515025ab7b96f039c88a696">dangerousPort</a>(quint16, <span class="keywordtype">bool</span>)));
<a name="l00048"></a>00048   <a class="code" href="_tor_control_8cpp.html#affa8ac255dc59c416e615eae17e0ab47">RELAY_SIGNAL</a>(<a class="code" href="class_tor_control.html#ae5f6211f798be2e442b5fc3fb6f3d09e">_eventHandler</a>, SIGNAL(<a class="code" href="class_tor_control.html#a7acccb4dc3af3bd2d9b1d71abfb67a8d">socksError</a>(<a class="code" href="namespacetc.html#ab29556af3a71a9c8768ab9ae1e822191">tc::SocksError</a>, QString)));
<a name="l00049"></a>00049   <a class="code" href="_tor_control_8cpp.html#affa8ac255dc59c416e615eae17e0ab47">RELAY_SIGNAL</a>(<a class="code" href="class_tor_control.html#ae5f6211f798be2e442b5fc3fb6f3d09e">_eventHandler</a>, SIGNAL(<a class="code" href="class_tor_control.html#aa2fc6aab78e45f29cd2366a62cd937d6">bootstrapStatusChanged</a>(<a class="code" href="class_bootstrap_status.html">BootstrapStatus</a>)));
<a name="l00050"></a>00050   <a class="code" href="_tor_control_8cpp.html#affa8ac255dc59c416e615eae17e0ab47">RELAY_SIGNAL</a>(<a class="code" href="class_tor_control.html#ae5f6211f798be2e442b5fc3fb6f3d09e">_eventHandler</a>, SIGNAL(<a class="code" href="class_tor_control.html#acfa0a2e89f5a23da5f20119a40e7f030">clockSkewed</a>(<span class="keywordtype">int</span>, QString)));
<a name="l00051"></a>00051   <a class="code" href="_tor_control_8cpp.html#affa8ac255dc59c416e615eae17e0ab47">RELAY_SIGNAL</a>(<a class="code" href="class_tor_control.html#ae5f6211f798be2e442b5fc3fb6f3d09e">_eventHandler</a>, SIGNAL(<a class="code" href="class_tor_control.html#aa53c9a7d4520ba1096c4c79d2caa6040">bug</a>(QString)));
<a name="l00052"></a>00052   <a class="code" href="_tor_control_8cpp.html#affa8ac255dc59c416e615eae17e0ab47">RELAY_SIGNAL</a>(<a class="code" href="class_tor_control.html#ae5f6211f798be2e442b5fc3fb6f3d09e">_eventHandler</a>, SIGNAL(<a class="code" href="class_tor_control.html#abea0a2e32ce3d4ce21acd7550b99240e">dnsHijacked</a>()));
<a name="l00053"></a>00053   <a class="code" href="_tor_control_8cpp.html#affa8ac255dc59c416e615eae17e0ab47">RELAY_SIGNAL</a>(<a class="code" href="class_tor_control.html#ae5f6211f798be2e442b5fc3fb6f3d09e">_eventHandler</a>, SIGNAL(<a class="code" href="class_tor_control.html#a01e5e24bf02df357e0f4fb29199a8076">dnsUseless</a>()));
<a name="l00054"></a>00054   <a class="code" href="_tor_control_8cpp.html#affa8ac255dc59c416e615eae17e0ab47">RELAY_SIGNAL</a>(<a class="code" href="class_tor_control.html#ae5f6211f798be2e442b5fc3fb6f3d09e">_eventHandler</a>,
<a name="l00055"></a>00055                SIGNAL(<a class="code" href="class_tor_control.html#a075796a1fd07b635de4650b35caa1c72">externalAddressChanged</a>(QHostAddress, QString)));
<a name="l00056"></a>00056   <a class="code" href="_tor_control_8cpp.html#affa8ac255dc59c416e615eae17e0ab47">RELAY_SIGNAL</a>(<a class="code" href="class_tor_control.html#ae5f6211f798be2e442b5fc3fb6f3d09e">_eventHandler</a>,
<a name="l00057"></a>00057                SIGNAL(<a class="code" href="class_tor_control.html#a836851a0ca43a810d46db7e5d5652b0c">checkingOrPortReachability</a>(QHostAddress, quint16)));
<a name="l00058"></a>00058   <a class="code" href="_tor_control_8cpp.html#affa8ac255dc59c416e615eae17e0ab47">RELAY_SIGNAL</a>(<a class="code" href="class_tor_control.html#ae5f6211f798be2e442b5fc3fb6f3d09e">_eventHandler</a>,
<a name="l00059"></a>00059                SIGNAL(<a class="code" href="class_tor_control.html#ad859922c242da4d04724f1401933d9d7">orPortReachabilityFinished</a>(QHostAddress,quint16,<span class="keywordtype">bool</span>)));
<a name="l00060"></a>00060   <a class="code" href="_tor_control_8cpp.html#affa8ac255dc59c416e615eae17e0ab47">RELAY_SIGNAL</a>(<a class="code" href="class_tor_control.html#ae5f6211f798be2e442b5fc3fb6f3d09e">_eventHandler</a>,
<a name="l00061"></a>00061                SIGNAL(<a class="code" href="class_tor_control.html#a2ab0973067a4bbfd1d330ab19fa9e740">checkingDirPortReachability</a>(QHostAddress, quint16)));
<a name="l00062"></a>00062   <a class="code" href="_tor_control_8cpp.html#affa8ac255dc59c416e615eae17e0ab47">RELAY_SIGNAL</a>(<a class="code" href="class_tor_control.html#ae5f6211f798be2e442b5fc3fb6f3d09e">_eventHandler</a>,
<a name="l00063"></a>00063                SIGNAL(<a class="code" href="class_tor_control.html#aef409a918c06974076095d947aa942cf">dirPortReachabilityFinished</a>(QHostAddress,quint16,<span class="keywordtype">bool</span>)));
<a name="l00064"></a>00064   <a class="code" href="_tor_control_8cpp.html#affa8ac255dc59c416e615eae17e0ab47">RELAY_SIGNAL</a>(<a class="code" href="class_tor_control.html#ae5f6211f798be2e442b5fc3fb6f3d09e">_eventHandler</a>,
<a name="l00065"></a>00065                SIGNAL(<a class="code" href="class_tor_control.html#ae9663b94a72a6a120ece2b4671577262">serverDescriptorRejected</a>(QHostAddress, quint16, QString)));
<a name="l00066"></a>00066   <a class="code" href="_tor_control_8cpp.html#affa8ac255dc59c416e615eae17e0ab47">RELAY_SIGNAL</a>(<a class="code" href="class_tor_control.html#ae5f6211f798be2e442b5fc3fb6f3d09e">_eventHandler</a>,
<a name="l00067"></a>00067                SIGNAL(<a class="code" href="class_tor_control.html#ab70abe10e1362bc181ac6075d30f66bb">serverDescriptorAccepted</a>(QHostAddress, quint16)));
<a name="l00068"></a>00068   <a class="code" href="_tor_control_8cpp.html#affa8ac255dc59c416e615eae17e0ab47">RELAY_SIGNAL</a>(<a class="code" href="class_tor_control.html#ae5f6211f798be2e442b5fc3fb6f3d09e">_eventHandler</a>, SIGNAL(<a class="code" href="class_tor_control.html#ab70abe10e1362bc181ac6075d30f66bb">serverDescriptorAccepted</a>()));
<a name="l00069"></a>00069 
<a name="l00070"></a>00070   <span class="comment">/* Create an instance of a connection to Tor&#39;s control interface and give</span>
<a name="l00071"></a>00071 <span class="comment">   * it an object to use to handle asynchronous events. */</span>
<a name="l00072"></a>00072   <a class="code" href="class_tor_control.html#ac6ddb7eea451a3f7fd26188cdf18c1ef">_controlConn</a> = <span class="keyword">new</span> <a class="code" href="class_control_connection.html">ControlConnection</a>(<a class="code" href="class_tor_control.html#ae5f6211f798be2e442b5fc3fb6f3d09e">_eventHandler</a>);
<a name="l00073"></a>00073   <a class="code" href="_tor_control_8cpp.html#affa8ac255dc59c416e615eae17e0ab47">RELAY_SIGNAL</a>(<a class="code" href="class_tor_control.html#ac6ddb7eea451a3f7fd26188cdf18c1ef">_controlConn</a>, SIGNAL(<a class="code" href="class_tor_control.html#a3ad15312fbcaaec7436602d8f3905b43">connected</a>()));
<a name="l00074"></a>00074   <a class="code" href="_tor_control_8cpp.html#affa8ac255dc59c416e615eae17e0ab47">RELAY_SIGNAL</a>(<a class="code" href="class_tor_control.html#ac6ddb7eea451a3f7fd26188cdf18c1ef">_controlConn</a>, SIGNAL(<a class="code" href="class_tor_control.html#a5aa616427f91b9d28b7e6ab2631eca88">connectFailed</a>(QString)));
<a name="l00075"></a>00075   <a class="code" href="class_tor_control.html#a5395e9f73ba5686b50763f23b63c2741">QObject::connect</a>(<a class="code" href="class_tor_control.html#ac6ddb7eea451a3f7fd26188cdf18c1ef">_controlConn</a>, SIGNAL(<a class="code" href="class_tor_control.html#ac1558d714cedb526cb8996059a9b6f05">disconnected</a>()),
<a name="l00076"></a>00076                    <span class="keyword">this</span>, SLOT(<a class="code" href="class_tor_control.html#ad5ce0ff3c3d2a316ef32a3758e170e39">onDisconnected</a>()));
<a name="l00077"></a>00077 
<a name="l00078"></a>00078   <span class="comment">/* Create an object used to start and stop a Tor process. */</span>
<a name="l00079"></a>00079   <a class="code" href="class_tor_control.html#a611caf8981a576fc33ab2705b8435fa3">_torProcess</a> = <span class="keyword">new</span> <a class="code" href="class_tor_process.html">TorProcess</a>(<span class="keyword">this</span>);
<a name="l00080"></a>00080   <a class="code" href="_tor_control_8cpp.html#affa8ac255dc59c416e615eae17e0ab47">RELAY_SIGNAL</a>(<a class="code" href="class_tor_control.html#a611caf8981a576fc33ab2705b8435fa3">_torProcess</a>, SIGNAL(<a class="code" href="class_tor_control.html#ab4e8473e774ba83aeb3f031628d5b8f8">started</a>()));
<a name="l00081"></a>00081   <a class="code" href="_tor_control_8cpp.html#affa8ac255dc59c416e615eae17e0ab47">RELAY_SIGNAL</a>(<a class="code" href="class_tor_control.html#a611caf8981a576fc33ab2705b8435fa3">_torProcess</a>, SIGNAL(<a class="code" href="class_tor_control.html#a783be13ea1c7bece803f085cc65e3272">startFailed</a>(QString)));
<a name="l00082"></a>00082   <a class="code" href="class_tor_control.html#a5395e9f73ba5686b50763f23b63c2741">QObject::connect</a>(<a class="code" href="class_tor_control.html#a611caf8981a576fc33ab2705b8435fa3">_torProcess</a>, SIGNAL(finished(<span class="keywordtype">int</span>, QProcess::ExitStatus)),
<a name="l00083"></a>00083                    <span class="keyword">this</span>, SLOT(<a class="code" href="class_tor_control.html#a97b802a813f0f925d04a959a581ea939">onStopped</a>(<span class="keywordtype">int</span>, QProcess::ExitStatus)));
<a name="l00084"></a>00084   <a class="code" href="class_tor_control.html#a5395e9f73ba5686b50763f23b63c2741">QObject::connect</a>(<a class="code" href="class_tor_control.html#a611caf8981a576fc33ab2705b8435fa3">_torProcess</a>, SIGNAL(log(QString, QString)),
<a name="l00085"></a>00085                    <span class="keyword">this</span>, SLOT(<a class="code" href="class_tor_control.html#ae262d8b5b5eeebadf36fa14fe1cffe4e">onLogStdout</a>(QString, QString)));
<a name="l00086"></a>00086 
<a name="l00087"></a>00087 <span class="preprocessor">#if defined(Q_OS_WIN32)</span>
<a name="l00088"></a>00088 <span class="preprocessor"></span>  _torService = <span class="keyword">new</span> <a class="code" href="class_tor_service.html">TorService</a>(<span class="keyword">this</span>);
<a name="l00089"></a>00089   <a class="code" href="_tor_control_8cpp.html#affa8ac255dc59c416e615eae17e0ab47">RELAY_SIGNAL</a>(_torService, SIGNAL(<a class="code" href="class_tor_control.html#ab4e8473e774ba83aeb3f031628d5b8f8">started</a>()));
<a name="l00090"></a>00090   <a class="code" href="_tor_control_8cpp.html#affa8ac255dc59c416e615eae17e0ab47">RELAY_SIGNAL</a>(_torService, SIGNAL(<a class="code" href="class_tor_control.html#a783be13ea1c7bece803f085cc65e3272">startFailed</a>(QString)));
<a name="l00091"></a>00091   <a class="code" href="class_tor_control.html#a5395e9f73ba5686b50763f23b63c2741">QObject::connect</a>(_torService, SIGNAL(finished(<span class="keywordtype">int</span>, QProcess::ExitStatus)),
<a name="l00092"></a>00092                    <span class="keyword">this</span>, SLOT(<a class="code" href="class_tor_control.html#a97b802a813f0f925d04a959a581ea939">onStopped</a>(<span class="keywordtype">int</span>, QProcess::ExitStatus)));
<a name="l00093"></a>00093 <span class="preprocessor">#endif</span>
<a name="l00094"></a>00094 <span class="preprocessor"></span><span class="preprocessor">#undef RELAY_SIGNAL</span>
<a name="l00095"></a>00095 <span class="preprocessor"></span>}
<a name="l00096"></a>00096 <span class="comment"></span>
<a name="l00097"></a>00097 <span class="comment">/** Default destructor */</span>
<a name="l00098"></a><a class="code" href="class_tor_control.html#aeb845e44a8ceadf02d6df31cbf93e819">00098</a> <a class="code" href="class_tor_control.html#aeb845e44a8ceadf02d6df31cbf93e819">TorControl::~TorControl</a>()
<a name="l00099"></a>00099 {
<a name="l00100"></a>00100   <span class="comment">/* Disconnect the control socket */</span>
<a name="l00101"></a>00101   <span class="keywordflow">if</span> (<a class="code" href="class_tor_control.html#a5e39e327ca6c4ef5b4e2ce770a81a59f">isConnected</a>()) {
<a name="l00102"></a>00102     <a class="code" href="class_tor_control.html#a60f52470bbc94d0939b08e0d022e138e">disconnect</a>();
<a name="l00103"></a>00103   }
<a name="l00104"></a>00104   <span class="comment">/* If we started our own Tor, stop it now */</span>
<a name="l00105"></a>00105   <span class="keywordflow">if</span> (<a class="code" href="class_tor_control.html#a3b8daa188aa325d28d75c62219c56c71">isVidaliaRunningTor</a>()) {
<a name="l00106"></a>00106     <a class="code" href="class_tor_control.html#ae4a495462e3aa5db88502c58d1fa771f">stop</a>();
<a name="l00107"></a>00107   }
<a name="l00108"></a>00108   <span class="keyword">delete</span> <a class="code" href="class_tor_control.html#ac6ddb7eea451a3f7fd26188cdf18c1ef">_controlConn</a>;
<a name="l00109"></a>00109 }
<a name="l00110"></a>00110 <span class="comment"></span>
<a name="l00111"></a>00111 <span class="comment">/** Start the Tor process using the executable &lt;b&gt;tor&lt;/b&gt; and the list of</span>
<a name="l00112"></a>00112 <span class="comment"> * arguments in &lt;b&gt;args&lt;/b&gt;. */</span>
<a name="l00113"></a>00113 <span class="keywordtype">void</span>
<a name="l00114"></a><a class="code" href="class_tor_control.html#a473cddffe582b00988f58a7e8cd8d12d">00114</a> <a class="code" href="class_tor_control.html#a473cddffe582b00988f58a7e8cd8d12d">TorControl::start</a>(<span class="keyword">const</span> QString &amp;tor, <span class="keyword">const</span> QStringList &amp;args)
<a name="l00115"></a>00115 {
<a name="l00116"></a>00116   <span class="keywordflow">if</span> (<a class="code" href="class_tor_control.html#abe44c7f9281547aab2d317972519bd49">isRunning</a>()) {
<a name="l00117"></a>00117     emit <a class="code" href="class_tor_control.html#ab4e8473e774ba83aeb3f031628d5b8f8">started</a>();
<a name="l00118"></a>00118   } <span class="keywordflow">else</span> {
<a name="l00119"></a>00119 <span class="preprocessor">#if defined(Q_OS_WIN32)</span>
<a name="l00120"></a>00120 <span class="preprocessor"></span>    <span class="comment">/* If the Tor service is installed, run that. Otherwise, start a new</span>
<a name="l00121"></a>00121 <span class="comment">     * Tor process. */</span>
<a name="l00122"></a>00122     <span class="keywordflow">if</span> (<a class="code" href="class_tor_service.html#ad9f8db8e338a5393cdad6315e95bcbf9">TorService::isSupported</a>() &amp;&amp; _torService-&gt;isInstalled())
<a name="l00123"></a>00123       _torService-&gt;start();
<a name="l00124"></a>00124     <span class="keywordflow">else</span>
<a name="l00125"></a>00125       <a class="code" href="class_tor_control.html#a611caf8981a576fc33ab2705b8435fa3">_torProcess</a>-&gt;<a class="code" href="class_tor_process.html#a2960d800606ab1b4843756519d3d5cbb">start</a>(<a class="code" href="file_8cpp.html#aaa3960262cc91df6d2400eb7ba888ae5">expand_filename</a>(tor), args);
<a name="l00126"></a>00126 <span class="preprocessor">#else</span>
<a name="l00127"></a>00127 <span class="preprocessor"></span>    <span class="comment">/* Start a new Tor process */</span>
<a name="l00128"></a>00128     <a class="code" href="class_tor_control.html#a611caf8981a576fc33ab2705b8435fa3">_torProcess</a>-&gt;<a class="code" href="class_tor_process.html#a2960d800606ab1b4843756519d3d5cbb">start</a>(<a class="code" href="file_8cpp.html#aaa3960262cc91df6d2400eb7ba888ae5">expand_filename</a>(tor), args);
<a name="l00129"></a>00129 <span class="preprocessor">#endif</span>
<a name="l00130"></a>00130 <span class="preprocessor"></span>  }
<a name="l00131"></a>00131 }
<a name="l00132"></a>00132 <span class="comment"></span>
<a name="l00133"></a>00133 <span class="comment">/** Stop the Tor process. */</span>
<a name="l00134"></a>00134 <span class="keywordtype">bool</span>
<a name="l00135"></a><a class="code" href="class_tor_control.html#ae4a495462e3aa5db88502c58d1fa771f">00135</a> <a class="code" href="class_tor_control.html#ae4a495462e3aa5db88502c58d1fa771f">TorControl::stop</a>(QString *errmsg)
<a name="l00136"></a>00136 {
<a name="l00137"></a>00137   <span class="keywordtype">bool</span> rc = <span class="keyword">false</span>;
<a name="l00138"></a>00138   <span class="keywordflow">if</span> (<a class="code" href="class_tor_control.html#ac6ddb7eea451a3f7fd26188cdf18c1ef">_controlConn</a>-&gt;<a class="code" href="class_control_connection.html#a9503aa0c9eab967da5686ffa4edc447f">isConnected</a>())
<a name="l00139"></a>00139     rc = <a class="code" href="class_tor_control.html#a373ecec8dbb7af273099d72a82a4d797">signal</a>(<a class="code" href="class_tor_signal.html#ab1820803604813483f918d131bcf281fabd399b688a1686f33d609e04d3a578e9">TorSignal::Halt</a>, errmsg);
<a name="l00140"></a>00140   <span class="keywordflow">if</span> (!rc)
<a name="l00141"></a>00141     rc = <a class="code" href="class_tor_control.html#a611caf8981a576fc33ab2705b8435fa3">_torProcess</a>-&gt;<a class="code" href="class_tor_process.html#ab326cc43224cd475efa4b210531e4f6e">stop</a>(errmsg);
<a name="l00142"></a>00142   <span class="keywordflow">return</span> rc;
<a name="l00143"></a>00143 }
<a name="l00144"></a>00144 <span class="comment"></span>
<a name="l00145"></a>00145 <span class="comment">/** Emits a signal that the Tor process stopped */</span>
<a name="l00146"></a>00146 <span class="keywordtype">void</span>
<a name="l00147"></a><a class="code" href="class_tor_control.html#a97b802a813f0f925d04a959a581ea939">00147</a> <a class="code" href="class_tor_control.html#a97b802a813f0f925d04a959a581ea939">TorControl::onStopped</a>(<span class="keywordtype">int</span> exitCode, QProcess::ExitStatus exitStatus)
<a name="l00148"></a>00148 {
<a name="l00149"></a>00149   <span class="keywordflow">if</span> (<a class="code" href="class_tor_control.html#ac6ddb7eea451a3f7fd26188cdf18c1ef">_controlConn</a>-&gt;<a class="code" href="class_control_connection.html#a34bcf7d414507cba5dd9905b78282f17">status</a>() == <a class="code" href="class_control_connection.html#a60fe264cf74ba322bc0fe4693e2e77adabd3d25f7cb53a85649ed2e47c19fef97">ControlConnection::Connecting</a>)
<a name="l00150"></a>00150     <a class="code" href="class_tor_control.html#ac6ddb7eea451a3f7fd26188cdf18c1ef">_controlConn</a>-&gt;<a class="code" href="class_control_connection.html#a0f737e7f32923003556eb6787a089ccd">cancelConnect</a>();
<a name="l00151"></a>00151 
<a name="l00152"></a>00152   emit <a class="code" href="class_tor_control.html#a3a43d3d21293f2238ac19eec9262837c">stopped</a>();
<a name="l00153"></a>00153   emit <a class="code" href="class_tor_control.html#a3a43d3d21293f2238ac19eec9262837c">stopped</a>(exitCode, exitStatus);
<a name="l00154"></a>00154 }
<a name="l00155"></a>00155 <span class="comment"></span>
<a name="l00156"></a>00156 <span class="comment">/** Detects if the Tor process is running under Vidalia. Returns true if</span>
<a name="l00157"></a>00157 <span class="comment"> * Vidalia owns the Tor process, or false if it was an independent Tor. */</span>
<a name="l00158"></a>00158 <span class="keywordtype">bool</span>
<a name="l00159"></a><a class="code" href="class_tor_control.html#a3b8daa188aa325d28d75c62219c56c71">00159</a> <a class="code" href="class_tor_control.html#a3b8daa188aa325d28d75c62219c56c71">TorControl::isVidaliaRunningTor</a>()
<a name="l00160"></a>00160 {
<a name="l00161"></a>00161   <span class="keywordflow">return</span> (<a class="code" href="class_tor_control.html#a611caf8981a576fc33ab2705b8435fa3">_torProcess</a>-&gt;state() != QProcess::NotRunning);
<a name="l00162"></a>00162 }
<a name="l00163"></a>00163 <span class="comment"></span>
<a name="l00164"></a>00164 <span class="comment">/** Detect if the Tor process is running. */</span>
<a name="l00165"></a>00165 <span class="keywordtype">bool</span>
<a name="l00166"></a><a class="code" href="class_tor_control.html#abe44c7f9281547aab2d317972519bd49">00166</a> <a class="code" href="class_tor_control.html#abe44c7f9281547aab2d317972519bd49">TorControl::isRunning</a>()
<a name="l00167"></a>00167 {
<a name="l00168"></a>00168   <span class="keywordflow">return</span> (<a class="code" href="class_tor_control.html#a611caf8981a576fc33ab2705b8435fa3">_torProcess</a>-&gt;state() != QProcess::NotRunning
<a name="l00169"></a>00169             || <a class="code" href="class_tor_control.html#ac6ddb7eea451a3f7fd26188cdf18c1ef">_controlConn</a>-&gt;<a class="code" href="class_control_connection.html#a9503aa0c9eab967da5686ffa4edc447f">isConnected</a>());
<a name="l00170"></a>00170 }
<a name="l00171"></a>00171 <span class="comment"></span>
<a name="l00172"></a>00172 <span class="comment">/** Stops reading log messages from the Tor process&#39;s stdout. This has no</span>
<a name="l00173"></a>00173 <span class="comment"> * effect if isVidaliaRunningTor() is false. */</span>
<a name="l00174"></a>00174 <span class="keywordtype">void</span>
<a name="l00175"></a><a class="code" href="class_tor_control.html#aff3b0c7fe437bbfc27c0705b5ac569ee">00175</a> <a class="code" href="class_tor_control.html#aff3b0c7fe437bbfc27c0705b5ac569ee">TorControl::closeTorStdout</a>()
<a name="l00176"></a>00176 {
<a name="l00177"></a>00177   <span class="keywordflow">if</span> (<a class="code" href="class_tor_control.html#a611caf8981a576fc33ab2705b8435fa3">_torProcess</a>)
<a name="l00178"></a>00178     <a class="code" href="class_tor_control.html#a611caf8981a576fc33ab2705b8435fa3">_torProcess</a>-&gt;<a class="code" href="class_tor_process.html#aee62d3364ab83002863c1f43ed0d8613">closeStdout</a>();
<a name="l00179"></a>00179 }
<a name="l00180"></a>00180 <span class="comment"></span>
<a name="l00181"></a>00181 <span class="comment">/** Called when Tor has printed a log message to stdout. */</span>
<a name="l00182"></a>00182 <span class="keywordtype">void</span>
<a name="l00183"></a><a class="code" href="class_tor_control.html#ae262d8b5b5eeebadf36fa14fe1cffe4e">00183</a> <a class="code" href="class_tor_control.html#ae262d8b5b5eeebadf36fa14fe1cffe4e">TorControl::onLogStdout</a>(<span class="keyword">const</span> QString &amp;severity, <span class="keyword">const</span> QString &amp;message)
<a name="l00184"></a>00184 {
<a name="l00185"></a>00185   emit <a class="code" href="class_tor_control.html#a9c881f31a2afc32ba6c488f247c20bc8">logMessage</a>(<a class="code" href="namespacetc.html#ab895ea051eb9251ab84ade452579b981">tc::severityFromString</a>(severity), message.trimmed());
<a name="l00186"></a>00186 }
<a name="l00187"></a>00187 <span class="comment"></span>
<a name="l00188"></a>00188 <span class="comment">/** Connect to Tor&#39;s control port. The control port to use is determined by</span>
<a name="l00189"></a>00189 <span class="comment"> * Vidalia&#39;s configuration file. */</span>
<a name="l00190"></a>00190 <span class="keywordtype">void</span>
<a name="l00191"></a><a class="code" href="class_tor_control.html#a5395e9f73ba5686b50763f23b63c2741">00191</a> <a class="code" href="class_tor_control.html#a5395e9f73ba5686b50763f23b63c2741">TorControl::connect</a>(<span class="keyword">const</span> QHostAddress &amp;address, quint16 port)
<a name="l00192"></a>00192 {
<a name="l00193"></a>00193   <a class="code" href="class_tor_control.html#ac6ddb7eea451a3f7fd26188cdf18c1ef">_controlConn</a>-&gt;<a class="code" href="class_control_connection.html#a08bef3c75868948687a0f33aa02a32b8">connect</a>(address, port);
<a name="l00194"></a>00194 }
<a name="l00195"></a>00195 <span class="comment"></span>
<a name="l00196"></a>00196 <span class="comment">/** Disconnect from Tor&#39;s control port */</span>
<a name="l00197"></a>00197 <span class="keywordtype">void</span>
<a name="l00198"></a><a class="code" href="class_tor_control.html#a60f52470bbc94d0939b08e0d022e138e">00198</a> <a class="code" href="class_tor_control.html#a60f52470bbc94d0939b08e0d022e138e">TorControl::disconnect</a>()
<a name="l00199"></a>00199 {
<a name="l00200"></a>00200   <span class="keywordflow">if</span> (<a class="code" href="class_tor_control.html#a5e39e327ca6c4ef5b4e2ce770a81a59f">isConnected</a>())
<a name="l00201"></a>00201     <a class="code" href="class_tor_control.html#ac6ddb7eea451a3f7fd26188cdf18c1ef">_controlConn</a>-&gt;<a class="code" href="class_control_connection.html#a63ff0aa4d96112e21566a64f5a25d8a7">disconnect</a>();
<a name="l00202"></a>00202 }
<a name="l00203"></a>00203 <span class="comment"></span>
<a name="l00204"></a>00204 <span class="comment">/** Emits a signal that the control socket disconnected from Tor */</span>
<a name="l00205"></a>00205 <span class="keywordtype">void</span>
<a name="l00206"></a><a class="code" href="class_tor_control.html#ad5ce0ff3c3d2a316ef32a3758e170e39">00206</a> <a class="code" href="class_tor_control.html#ad5ce0ff3c3d2a316ef32a3758e170e39">TorControl::onDisconnected</a>()
<a name="l00207"></a>00207 {
<a name="l00208"></a>00208   <span class="keywordflow">if</span> (<a class="code" href="class_tor_control.html#a611caf8981a576fc33ab2705b8435fa3">_torProcess</a>) {
<a name="l00209"></a>00209     <span class="comment">/* If we&#39;re running a Tor process, then start reading logs from stdout</span>
<a name="l00210"></a>00210 <span class="comment">     * again, in case our control connection just died but Tor is still</span>
<a name="l00211"></a>00211 <span class="comment">     * running. In this case, there may be relevant information in the logs. */</span>
<a name="l00212"></a>00212     <a class="code" href="class_tor_control.html#a611caf8981a576fc33ab2705b8435fa3">_torProcess</a>-&gt;<a class="code" href="class_tor_process.html#a4a6956ca20e13905543ce638c8ce1c93">openStdout</a>();
<a name="l00213"></a>00213   }
<a name="l00214"></a>00214   <span class="comment">/* Tor isn&#39;t running, so it has no version */</span>
<a name="l00215"></a>00215   <a class="code" href="class_tor_control.html#aa27560cf64f335477f0404ec28d24051">_torVersion</a> = QString();
<a name="l00216"></a>00216 
<a name="l00217"></a>00217   <span class="comment">/* Let interested parties know we lost our control connection */</span>
<a name="l00218"></a>00218   emit <a class="code" href="class_tor_control.html#ac1558d714cedb526cb8996059a9b6f05">disconnected</a>();
<a name="l00219"></a>00219 }
<a name="l00220"></a>00220 <span class="comment"></span>
<a name="l00221"></a>00221 <span class="comment">/** Check if the control socket is connected */</span>
<a name="l00222"></a>00222 <span class="keywordtype">bool</span>
<a name="l00223"></a><a class="code" href="class_tor_control.html#a5e39e327ca6c4ef5b4e2ce770a81a59f">00223</a> <a class="code" href="class_tor_control.html#a5e39e327ca6c4ef5b4e2ce770a81a59f">TorControl::isConnected</a>()
<a name="l00224"></a>00224 {
<a name="l00225"></a>00225   <span class="keywordflow">return</span> <a class="code" href="class_tor_control.html#ac6ddb7eea451a3f7fd26188cdf18c1ef">_controlConn</a>-&gt;<a class="code" href="class_control_connection.html#a9503aa0c9eab967da5686ffa4edc447f">isConnected</a>();
<a name="l00226"></a>00226 }
<a name="l00227"></a>00227 <span class="comment"></span>
<a name="l00228"></a>00228 <span class="comment">/** Send a message to Tor and reads the response. If Vidalia was unable to</span>
<a name="l00229"></a>00229 <span class="comment"> * send the command to Tor or read its response, false is returned. If the</span>
<a name="l00230"></a>00230 <span class="comment"> * response was read and the status code is not 250 OK, false is also</span>
<a name="l00231"></a>00231 <span class="comment"> * returned. */</span>
<a name="l00232"></a>00232 <span class="keywordtype">bool</span>
<a name="l00233"></a><a class="code" href="class_tor_control.html#a2f2b9eb90d984ae4cfdafb777897e322">00233</a> <a class="code" href="class_tor_control.html#a2f2b9eb90d984ae4cfdafb777897e322">TorControl::send</a>(<a class="code" href="class_control_command.html">ControlCommand</a> cmd, <a class="code" href="class_control_reply.html">ControlReply</a> &amp;reply, QString *errmsg)
<a name="l00234"></a>00234 {
<a name="l00235"></a>00235   <span class="keywordflow">if</span> (<a class="code" href="class_tor_control.html#ac6ddb7eea451a3f7fd26188cdf18c1ef">_controlConn</a>-&gt;<a class="code" href="class_control_connection.html#aa5e4ff44b7c6e0773eda0a2f90505657">send</a>(cmd, reply, errmsg)) {
<a name="l00236"></a>00236     <span class="keywordflow">if</span> (reply.<a class="code" href="class_control_reply.html#a8b7a7275546b3ba8f5a3ec6296d971f0">getStatus</a>() == <span class="stringliteral">&quot;250&quot;</span>) {
<a name="l00237"></a>00237       <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00238"></a>00238     }
<a name="l00239"></a>00239     <span class="keywordflow">if</span> (errmsg) {
<a name="l00240"></a>00240       *errmsg = reply.<a class="code" href="class_control_reply.html#a13b0ec6e2d3d97932297cf2002c25578">getMessage</a>();
<a name="l00241"></a>00241     }
<a name="l00242"></a>00242   }
<a name="l00243"></a>00243   <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00244"></a>00244 }
<a name="l00245"></a>00245 <span class="comment"></span>
<a name="l00246"></a>00246 <span class="comment">/** Sends a message to Tor and discards the response. */</span>
<a name="l00247"></a>00247 <span class="keywordtype">bool</span>
<a name="l00248"></a><a class="code" href="class_tor_control.html#a9f52fc341a5b75bd0a636581423f0a92">00248</a> <a class="code" href="class_tor_control.html#a2f2b9eb90d984ae4cfdafb777897e322">TorControl::send</a>(<a class="code" href="class_control_command.html">ControlCommand</a> cmd, QString *errmsg)
<a name="l00249"></a>00249 {
<a name="l00250"></a>00250   <a class="code" href="class_control_reply.html">ControlReply</a> reply;
<a name="l00251"></a>00251   <span class="keywordflow">return</span> <a class="code" href="class_tor_control.html#a2f2b9eb90d984ae4cfdafb777897e322">send</a>(cmd, reply, errmsg);
<a name="l00252"></a>00252 }
<a name="l00253"></a>00253 <span class="comment"></span>
<a name="l00254"></a>00254 <span class="comment">/** Sends an authentication cookie to Tor. The syntax is:</span>
<a name="l00255"></a>00255 <span class="comment"> *</span>
<a name="l00256"></a>00256 <span class="comment"> *   &quot;AUTHENTICATE&quot; SP 1*HEXDIG CRLF</span>
<a name="l00257"></a>00257 <span class="comment"> */</span>
<a name="l00258"></a>00258 <span class="keywordtype">bool</span>
<a name="l00259"></a><a class="code" href="class_tor_control.html#a2aa1d6903e8180eb685963bbf8f62b19">00259</a> <a class="code" href="class_tor_control.html#a2aa1d6903e8180eb685963bbf8f62b19">TorControl::authenticate</a>(<span class="keyword">const</span> QByteArray cookie, QString *errmsg)
<a name="l00260"></a>00260 {
<a name="l00261"></a>00261   <a class="code" href="class_control_command.html">ControlCommand</a> cmd(<span class="stringliteral">&quot;AUTHENTICATE&quot;</span>, <a class="code" href="stringutil_8cpp.html#a4d5ac084308fee41bcc66b9ed3754d8f">base16_encode</a>(cookie));
<a name="l00262"></a>00262   <a class="code" href="class_control_reply.html">ControlReply</a> reply;
<a name="l00263"></a>00263   QString str;
<a name="l00264"></a>00264 
<a name="l00265"></a>00265   <span class="keywordflow">if</span> (!<a class="code" href="class_tor_control.html#a2f2b9eb90d984ae4cfdafb777897e322">send</a>(cmd, reply, &amp;str)) {
<a name="l00266"></a>00266     emit <a class="code" href="class_tor_control.html#a89b5f36c6fc54e84c39002443a929a1c">authenticationFailed</a>(str);
<a name="l00267"></a>00267     <span class="keywordflow">return</span> <a class="code" href="stringutil_8cpp.html#a6e3f242b28c9165146182aec25e351a3">err</a>(errmsg, str);
<a name="l00268"></a>00268   }
<a name="l00269"></a>00269   <a class="code" href="class_tor_control.html#a197532cfd0b755b2ba5dad58cd043f59">onAuthenticated</a>();
<a name="l00270"></a>00270   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00271"></a>00271 }
<a name="l00272"></a>00272 <span class="comment"></span>
<a name="l00273"></a>00273 <span class="comment">/** Sends an authentication password to Tor. The syntax is:</span>
<a name="l00274"></a>00274 <span class="comment"> *</span>
<a name="l00275"></a>00275 <span class="comment"> *   &quot;AUTHENTICATE&quot; SP QuotedString CRLF</span>
<a name="l00276"></a>00276 <span class="comment"> */</span>
<a name="l00277"></a>00277 <span class="keywordtype">bool</span>
<a name="l00278"></a><a class="code" href="class_tor_control.html#a234266ab317bd8c7258806c89e92f508">00278</a> <a class="code" href="class_tor_control.html#a2aa1d6903e8180eb685963bbf8f62b19">TorControl::authenticate</a>(<span class="keyword">const</span> QString &amp;password, QString *errmsg)
<a name="l00279"></a>00279 {
<a name="l00280"></a>00280   <a class="code" href="class_control_command.html">ControlCommand</a> cmd(<span class="stringliteral">&quot;AUTHENTICATE&quot;</span>, <a class="code" href="stringutil_8cpp.html#a2323f625d9f361167e0455447c3fc83a">string_escape</a>(password));
<a name="l00281"></a>00281   <a class="code" href="class_control_reply.html">ControlReply</a> reply;
<a name="l00282"></a>00282   QString str;
<a name="l00283"></a>00283 
<a name="l00284"></a>00284   <span class="keywordflow">if</span> (!<a class="code" href="class_tor_control.html#a2f2b9eb90d984ae4cfdafb777897e322">send</a>(cmd, reply, &amp;str)) {
<a name="l00285"></a>00285     emit <a class="code" href="class_tor_control.html#a89b5f36c6fc54e84c39002443a929a1c">authenticationFailed</a>(str);
<a name="l00286"></a>00286     <span class="keywordflow">return</span> <a class="code" href="stringutil_8cpp.html#a6e3f242b28c9165146182aec25e351a3">err</a>(errmsg, str);
<a name="l00287"></a>00287   }
<a name="l00288"></a>00288   <a class="code" href="class_tor_control.html#a197532cfd0b755b2ba5dad58cd043f59">onAuthenticated</a>();
<a name="l00289"></a>00289   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00290"></a>00290 }
<a name="l00291"></a>00291 <span class="comment"></span>
<a name="l00292"></a>00292 <span class="comment">/** Called when the controller has successfully authenticated to Tor. */</span>
<a name="l00293"></a>00293 <span class="keywordtype">void</span>
<a name="l00294"></a><a class="code" href="class_tor_control.html#a197532cfd0b755b2ba5dad58cd043f59">00294</a> <a class="code" href="class_tor_control.html#a197532cfd0b755b2ba5dad58cd043f59">TorControl::onAuthenticated</a>()
<a name="l00295"></a>00295 {
<a name="l00296"></a>00296   <span class="comment">/* The version of Tor isn&#39;t going to change while we&#39;re connected to it, so</span>
<a name="l00297"></a>00297 <span class="comment">   * save it for later. */</span>
<a name="l00298"></a>00298   <a class="code" href="class_tor_control.html#a7bb6236b41505b30e8708c9f5cf8e8f7">getInfo</a>(<span class="stringliteral">&quot;version&quot;</span>, <a class="code" href="class_tor_control.html#aa27560cf64f335477f0404ec28d24051">_torVersion</a>);
<a name="l00299"></a>00299   <span class="comment">/* We want to use verbose names in events and GETINFO results. */</span>
<a name="l00300"></a>00300   <a class="code" href="class_tor_control.html#ac347e773fee2f68f16b445f131e164cf">useFeature</a>(<span class="stringliteral">&quot;VERBOSE_NAMES&quot;</span>);
<a name="l00301"></a>00301   <span class="comment">/* We want to use extended events in all async events */</span>
<a name="l00302"></a>00302   <a class="code" href="class_tor_control.html#ac347e773fee2f68f16b445f131e164cf">useFeature</a>(<span class="stringliteral">&quot;EXTENDED_EVENTS&quot;</span>);
<a name="l00303"></a>00303 
<a name="l00304"></a>00304   emit <a class="code" href="class_tor_control.html#a5233d923de9e4c5220c54bf88affcce2">authenticated</a>();
<a name="l00305"></a>00305 }
<a name="l00306"></a>00306 <span class="comment"></span>
<a name="l00307"></a>00307 <span class="comment">/** Sends a PROTOCOLINFO command to Tor and parses the response. */</span>
<a name="l00308"></a>00308 <a class="code" href="class_protocol_info.html">ProtocolInfo</a>
<a name="l00309"></a><a class="code" href="class_tor_control.html#ae8585adc887fffe1aa2ce276b01dd99d">00309</a> <a class="code" href="class_tor_control.html#ae8585adc887fffe1aa2ce276b01dd99d">TorControl::protocolInfo</a>(QString *errmsg)
<a name="l00310"></a>00310 {
<a name="l00311"></a>00311   <a class="code" href="class_control_command.html">ControlCommand</a> cmd(<span class="stringliteral">&quot;PROTOCOLINFO&quot;</span>, <span class="stringliteral">&quot;1&quot;</span>);
<a name="l00312"></a>00312   <a class="code" href="class_control_reply.html">ControlReply</a> reply;
<a name="l00313"></a>00313   <a class="code" href="class_protocol_info.html">ProtocolInfo</a> pi;
<a name="l00314"></a>00314   QString msg, topic;
<a name="l00315"></a>00315   QHash&lt;QString,QString&gt; keyvals;
<a name="l00316"></a>00316   <span class="keywordtype">int</span> idx;
<a name="l00317"></a>00317   <span class="keywordtype">bool</span> ok;
<a name="l00318"></a>00318 
<a name="l00319"></a>00319   <span class="keywordflow">if</span> (!<a class="code" href="class_tor_control.html#a2f2b9eb90d984ae4cfdafb777897e322">send</a>(cmd, reply, errmsg))
<a name="l00320"></a>00320     <span class="keywordflow">return</span> <a class="code" href="class_protocol_info.html">ProtocolInfo</a>();
<a name="l00321"></a>00321 
<a name="l00322"></a>00322   <span class="keywordflow">foreach</span> (<a class="code" href="class_reply_line.html">ReplyLine</a> line, reply.<a class="code" href="class_control_reply.html#a4ff2ea9c2c8035be7c5caf468da744f6">getLines</a>()) {
<a name="l00323"></a>00323     <span class="keywordflow">if</span> (line.<a class="code" href="class_reply_line.html#ace92edce42f4d1b93929ebde0ebfaceb">getStatus</a>() != <span class="stringliteral">&quot;250&quot;</span>)
<a name="l00324"></a>00324       <span class="keywordflow">continue</span>;
<a name="l00325"></a>00325 
<a name="l00326"></a>00326     msg = line.<a class="code" href="class_reply_line.html#ad22f50e33e6809eb25a07c090c8a960a">getMessage</a>().trimmed();
<a name="l00327"></a>00327     idx = msg.indexOf(<span class="stringliteral">&quot; &quot;</span>);
<a name="l00328"></a>00328     topic = msg.mid(0, idx).toUpper();
<a name="l00329"></a>00329 
<a name="l00330"></a>00330     <span class="keywordflow">if</span> (idx &gt; 0) {
<a name="l00331"></a>00331       keyvals = <a class="code" href="stringutil_8cpp.html#a2be53af228dd65232621f02a47bd8488">string_parse_keyvals</a>(msg.mid(idx+1), &amp;ok);
<a name="l00332"></a>00332       <span class="keywordflow">if</span> (!ok)
<a name="l00333"></a>00333         <span class="keywordflow">continue</span>; <span class="comment">/* Ignore malformed lines */</span>
<a name="l00334"></a>00334     } <span class="keywordflow">else</span> {
<a name="l00335"></a>00335       keyvals = QHash&lt;QString,QString&gt;();
<a name="l00336"></a>00336     }
<a name="l00337"></a>00337 
<a name="l00338"></a>00338     <span class="keywordflow">if</span> (topic == <span class="stringliteral">&quot;AUTH&quot;</span>) {
<a name="l00339"></a>00339       <span class="keywordflow">if</span> (keyvals.contains(<span class="stringliteral">&quot;METHODS&quot;</span>))
<a name="l00340"></a>00340         pi.<a class="code" href="class_protocol_info.html#af7e5946d54fdd1855c5625632c45ed3c">setAuthMethods</a>(keyvals.value(<span class="stringliteral">&quot;METHODS&quot;</span>));
<a name="l00341"></a>00341       <span class="keywordflow">if</span> (keyvals.contains(<span class="stringliteral">&quot;COOKIEFILE&quot;</span>))
<a name="l00342"></a>00342         pi.<a class="code" href="class_protocol_info.html#ad0733b6d7b047741ac52ccbcbc7ae511">setCookieAuthFile</a>(keyvals.value(<span class="stringliteral">&quot;COOKIEFILE&quot;</span>));
<a name="l00343"></a>00343     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (topic == <span class="stringliteral">&quot;VERSION&quot;</span>) {
<a name="l00344"></a>00344       <span class="keywordflow">if</span> (keyvals.contains(<span class="stringliteral">&quot;Tor&quot;</span>))
<a name="l00345"></a>00345         pi.<a class="code" href="class_protocol_info.html#a4fed1115f41df472f76b4f801b0923de">setTorVersion</a>(keyvals.value(<span class="stringliteral">&quot;Tor&quot;</span>));
<a name="l00346"></a>00346     }
<a name="l00347"></a>00347   }
<a name="l00348"></a>00348   <span class="keywordflow">return</span> pi;
<a name="l00349"></a>00349 }
<a name="l00350"></a>00350 <span class="comment"></span>
<a name="l00351"></a>00351 <span class="comment">/** Tells Tor the controller wants to enable &lt;b&gt;feature&lt;/b&gt; via the</span>
<a name="l00352"></a>00352 <span class="comment"> * USEFEATURE control command. Returns true if the given feature was</span>
<a name="l00353"></a>00353 <span class="comment"> * successfully enabled. */</span>
<a name="l00354"></a>00354 <span class="keywordtype">bool</span>
<a name="l00355"></a><a class="code" href="class_tor_control.html#ac347e773fee2f68f16b445f131e164cf">00355</a> <a class="code" href="class_tor_control.html#ac347e773fee2f68f16b445f131e164cf">TorControl::useFeature</a>(<span class="keyword">const</span> QString &amp;feature, QString *errmsg)
<a name="l00356"></a>00356 {
<a name="l00357"></a>00357   <a class="code" href="class_control_command.html">ControlCommand</a> cmd(<span class="stringliteral">&quot;USEFEATURE&quot;</span>, feature);
<a name="l00358"></a>00358   <span class="keywordflow">return</span> <a class="code" href="class_tor_control.html#a2f2b9eb90d984ae4cfdafb777897e322">send</a>(cmd, errmsg);
<a name="l00359"></a>00359 }
<a name="l00360"></a>00360 
<a name="l00361"></a>00361 <a class="code" href="class_bootstrap_status.html">BootstrapStatus</a>
<a name="l00362"></a><a class="code" href="class_tor_control.html#a1f43146b9e125f2229a23f3509f73cf7">00362</a> <a class="code" href="class_tor_control.html#a1f43146b9e125f2229a23f3509f73cf7">TorControl::bootstrapStatus</a>(QString *errmsg)
<a name="l00363"></a>00363 {
<a name="l00364"></a>00364   QString str = <a class="code" href="class_tor_control.html#a7bb6236b41505b30e8708c9f5cf8e8f7">getInfo</a>(<span class="stringliteral">&quot;status/bootstrap-phase&quot;</span>).toString();
<a name="l00365"></a>00365   <span class="keywordflow">if</span> (!str.isEmpty()) {
<a name="l00366"></a>00366     <a class="code" href="namespacetc.html#abb893107129c283d2eb0238e46eb3d4c">tc::Severity</a> severity = <a class="code" href="namespacetc.html#ab895ea051eb9251ab84ade452579b981">tc::severityFromString</a>(str.section(<span class="charliteral">&#39; &#39;</span>, 0, 0));
<a name="l00367"></a>00367     QHash&lt;QString,QString&gt; args = <a class="code" href="stringutil_8cpp.html#a2be53af228dd65232621f02a47bd8488">string_parse_keyvals</a>(str);
<a name="l00368"></a>00368     <span class="keywordflow">return</span> <a class="code" href="class_bootstrap_status.html">BootstrapStatus</a>(severity,
<a name="l00369"></a>00369               <a class="code" href="class_bootstrap_status.html#a0e878a9a8ca87d06c565f3511bc1dd66">BootstrapStatus::statusFromString</a>(args.value(<span class="stringliteral">&quot;TAG&quot;</span>)),
<a name="l00370"></a>00370               args.value(<span class="stringliteral">&quot;PROGRESS&quot;</span>).toInt(),
<a name="l00371"></a>00371               args.value(<span class="stringliteral">&quot;SUMMARY&quot;</span>),
<a name="l00372"></a>00372               args.value(<span class="stringliteral">&quot;WARNING&quot;</span>),
<a name="l00373"></a>00373               <a class="code" href="namespacetc.html#abebccd78ae0875fead37fd92936b465d">tc::connectionStatusReasonFromString</a>(args.value(<span class="stringliteral">&quot;REASON&quot;</span>)),
<a name="l00374"></a>00374               <a class="code" href="class_bootstrap_status.html#a4bd91a88d99ad7157520e0d4c9b9fdf2">BootstrapStatus::actionFromString</a>(
<a name="l00375"></a>00375                 args.value(<span class="stringliteral">&quot;RECOMMENDATION&quot;</span>)));
<a name="l00376"></a>00376   }
<a name="l00377"></a>00377   <span class="keywordflow">return</span> <a class="code" href="class_bootstrap_status.html">BootstrapStatus</a>();
<a name="l00378"></a>00378 }
<a name="l00379"></a>00379 <span class="comment"></span>
<a name="l00380"></a>00380 <span class="comment">/** Returns true if Tor either has an open circuit or (on Tor &gt;=</span>
<a name="l00381"></a>00381 <span class="comment"> * 0.2.0.1-alpha) has previously decided it&#39;s able to establish a circuit. */</span>
<a name="l00382"></a>00382 <span class="keywordtype">bool</span>
<a name="l00383"></a><a class="code" href="class_tor_control.html#a2b389a9436a6beb699dac04b95ace7ac">00383</a> <a class="code" href="class_tor_control.html#a2b389a9436a6beb699dac04b95ace7ac">TorControl::isCircuitEstablished</a>()
<a name="l00384"></a>00384 {
<a name="l00385"></a>00385   <span class="comment">/* If Tor is recent enough, we can &#39;getinfo status/circuit-established&#39; to</span>
<a name="l00386"></a>00386 <span class="comment">   * see if Tor has an open circuit */</span>
<a name="l00387"></a>00387   <span class="keywordflow">if</span> (<a class="code" href="class_tor_control.html#acd37862e652425dec4329acef6df4f3e">getTorVersion</a>() &gt;= 0x020001) {
<a name="l00388"></a>00388     QString tmp;
<a name="l00389"></a>00389     <span class="keywordflow">if</span> (<a class="code" href="class_tor_control.html#a7bb6236b41505b30e8708c9f5cf8e8f7">getInfo</a>(<span class="stringliteral">&quot;status/circuit-established&quot;</span>, tmp))
<a name="l00390"></a>00390       <span class="keywordflow">return</span> (tmp == <span class="stringliteral">&quot;1&quot;</span>);
<a name="l00391"></a>00391   }
<a name="l00392"></a>00392 
<a name="l00393"></a>00393   <span class="comment">/* Either Tor was too old or our getinfo failed, so try to get a list of all</span>
<a name="l00394"></a>00394 <span class="comment">   * circuits and check their statuses. */</span>
<a name="l00395"></a>00395   <a class="code" href="_circuit_8h.html#a5c7c01bcee10c15862fdf844c3d1538c">CircuitList</a> circs = <a class="code" href="class_tor_control.html#ab2180f731d4e74f83441618a62c036d6">getCircuits</a>();
<a name="l00396"></a>00396   <span class="keywordflow">foreach</span> (<a class="code" href="class_circuit.html">Circuit</a> circ, circs) {
<a name="l00397"></a>00397     <span class="keywordflow">if</span> (circ.<a class="code" href="class_circuit.html#a33c78724c92b50c7aa28b247a88a79f4">status</a>() == <a class="code" href="class_circuit.html#ae831da69eb5ffd2af9f470d90c613d0aad2f6d14053da3729ae9063cfa8125037">Circuit::Built</a>)
<a name="l00398"></a>00398       <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00399"></a>00399   }
<a name="l00400"></a>00400   <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00401"></a>00401 }
<a name="l00402"></a>00402 <span class="comment"></span>
<a name="l00403"></a>00403 <span class="comment">/** Sends a GETINFO message to Tor based on the given map of keyvals. The</span>
<a name="l00404"></a>00404 <span class="comment"> * syntax is:</span>
<a name="l00405"></a>00405 <span class="comment"> *</span>
<a name="l00406"></a>00406 <span class="comment"> *    &quot;GETINFO&quot; 1*(SP keyword) CRLF</span>
<a name="l00407"></a>00407 <span class="comment"> */</span>
<a name="l00408"></a>00408 <span class="keywordtype">bool</span>
<a name="l00409"></a><a class="code" href="class_tor_control.html#a7bb6236b41505b30e8708c9f5cf8e8f7">00409</a> <a class="code" href="class_tor_control.html#a7bb6236b41505b30e8708c9f5cf8e8f7">TorControl::getInfo</a>(QHash&lt;QString,QString&gt; &amp;map, QString *errmsg)
<a name="l00410"></a>00410 {
<a name="l00411"></a>00411   <a class="code" href="class_control_command.html">ControlCommand</a> cmd(<span class="stringliteral">&quot;GETINFO&quot;</span>);
<a name="l00412"></a>00412   <a class="code" href="class_control_reply.html">ControlReply</a> reply;
<a name="l00413"></a>00413 
<a name="l00414"></a>00414   <span class="comment">/* Add the keys as arguments to the GETINFO message */</span>
<a name="l00415"></a>00415   <span class="keywordflow">foreach</span> (QString key, map.keys()) {
<a name="l00416"></a>00416     cmd.<a class="code" href="class_control_command.html#a4f8c58a007da880191178044ae569ec0">addArgument</a>(key);
<a name="l00417"></a>00417   }
<a name="l00418"></a>00418 
<a name="l00419"></a>00419   <span class="comment">/* Ask Tor for the specified info values */</span>
<a name="l00420"></a>00420   <span class="keywordflow">if</span> (<a class="code" href="class_tor_control.html#a2f2b9eb90d984ae4cfdafb777897e322">send</a>(cmd, reply, errmsg)) {
<a name="l00421"></a>00421     <span class="comment">/* Parse the response for the returned values */</span>
<a name="l00422"></a>00422     <span class="keywordflow">foreach</span> (<a class="code" href="class_reply_line.html">ReplyLine</a> line, reply.<a class="code" href="class_control_reply.html#a4ff2ea9c2c8035be7c5caf468da744f6">getLines</a>()) {
<a name="l00423"></a>00423       <span class="comment">/* Split the &quot;key=val&quot; line and map them */</span>
<a name="l00424"></a>00424       QStringList keyval = line.<a class="code" href="class_reply_line.html#ad22f50e33e6809eb25a07c090c8a960a">getMessage</a>().split(<span class="stringliteral">&quot;=&quot;</span>);
<a name="l00425"></a>00425       <span class="keywordflow">if</span> (keyval.size() == 2) {
<a name="l00426"></a>00426         map.insert(keyval.at(0), keyval.at(1));
<a name="l00427"></a>00427       }
<a name="l00428"></a>00428     }
<a name="l00429"></a>00429     <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00430"></a>00430   }
<a name="l00431"></a>00431   <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00432"></a>00432 }
<a name="l00433"></a>00433 <span class="comment"></span>
<a name="l00434"></a>00434 <span class="comment">/** Sends a GETINFO message to Tor using the given list of &lt;b&gt;keys&lt;/b&gt; and</span>
<a name="l00435"></a>00435 <span class="comment"> * returns a QVariantMap containing the specified keys and their values as</span>
<a name="l00436"></a>00436 <span class="comment"> * returned  by Tor. Returns a default constructed QVariantMap on failure. */</span>
<a name="l00437"></a>00437 QVariantMap
<a name="l00438"></a><a class="code" href="class_tor_control.html#a7cdc3109cdf9f8f099a07f600b6e388e">00438</a> <a class="code" href="class_tor_control.html#a7bb6236b41505b30e8708c9f5cf8e8f7">TorControl::getInfo</a>(<span class="keyword">const</span> QStringList &amp;keys, QString *errmsg)
<a name="l00439"></a>00439 {
<a name="l00440"></a>00440   <a class="code" href="class_control_command.html">ControlCommand</a> cmd(<span class="stringliteral">&quot;GETINFO&quot;</span>);
<a name="l00441"></a>00441   <a class="code" href="class_control_reply.html">ControlReply</a> reply;
<a name="l00442"></a>00442   QVariantMap infoMap;
<a name="l00443"></a>00443 
<a name="l00444"></a>00444   cmd.<a class="code" href="class_control_command.html#ab5981c4f2760b6f23797ab23b7dc491b">addArguments</a>(keys);
<a name="l00445"></a>00445   <span class="keywordflow">if</span> (!<a class="code" href="class_tor_control.html#a2f2b9eb90d984ae4cfdafb777897e322">send</a>(cmd, reply, errmsg))
<a name="l00446"></a>00446     <span class="keywordflow">return</span> QVariantMap();
<a name="l00447"></a>00447 
<a name="l00448"></a>00448   <span class="keywordflow">foreach</span> (<a class="code" href="class_reply_line.html">ReplyLine</a> line, reply.<a class="code" href="class_control_reply.html#a4ff2ea9c2c8035be7c5caf468da744f6">getLines</a>()) {
<a name="l00449"></a>00449     QString msg = line.<a class="code" href="class_reply_line.html#ad22f50e33e6809eb25a07c090c8a960a">getMessage</a>();
<a name="l00450"></a>00450     <span class="keywordtype">int</span> index   = msg.indexOf(<span class="stringliteral">&quot;=&quot;</span>);
<a name="l00451"></a>00451     QString key = msg.mid(0, index);
<a name="l00452"></a>00452     QStringList val;
<a name="l00453"></a>00453 
<a name="l00454"></a>00454     <span class="keywordflow">if</span> (index &gt; 0 &amp;&amp; index &lt; msg.length()-1)
<a name="l00455"></a>00455       val &lt;&lt; msg.mid(index+1);
<a name="l00456"></a>00456     <span class="keywordflow">if</span> (line.<a class="code" href="class_reply_line.html#ab9348288bc34d48a55a3d0506f9cb380">hasData</a>())
<a name="l00457"></a>00457       val &lt;&lt; line.<a class="code" href="class_reply_line.html#a91aee47e5e25623268fb52986bc954ee">getData</a>();
<a name="l00458"></a>00458 
<a name="l00459"></a>00459     <span class="keywordflow">if</span> (infoMap.contains(key)) {
<a name="l00460"></a>00460       QStringList values = infoMap.value(key).toStringList();
<a name="l00461"></a>00461       values &lt;&lt; val;
<a name="l00462"></a>00462       infoMap.insert(key, values);
<a name="l00463"></a>00463     } <span class="keywordflow">else</span> {
<a name="l00464"></a>00464       infoMap.insert(key, val);
<a name="l00465"></a>00465     }
<a name="l00466"></a>00466   }
<a name="l00467"></a>00467   <span class="keywordflow">return</span> infoMap;
<a name="l00468"></a>00468 }
<a name="l00469"></a>00469 <span class="comment"></span>
<a name="l00470"></a>00470 <span class="comment">/** Sends a GETINFO message to Tor with a single &lt;b&gt;key&lt;/b&gt; and returns a</span>
<a name="l00471"></a>00471 <span class="comment"> * QVariant containing the value returned by Tor. Returns a default</span>
<a name="l00472"></a>00472 <span class="comment"> * constructed QVariant on failure. */</span>
<a name="l00473"></a>00473 QVariant
<a name="l00474"></a><a class="code" href="class_tor_control.html#a22a40af6255f19959690b7001da19aea">00474</a> <a class="code" href="class_tor_control.html#a7bb6236b41505b30e8708c9f5cf8e8f7">TorControl::getInfo</a>(<span class="keyword">const</span> QString &amp;key, QString *errmsg)
<a name="l00475"></a>00475 {
<a name="l00476"></a>00476   QVariantMap map = <a class="code" href="class_tor_control.html#a7bb6236b41505b30e8708c9f5cf8e8f7">getInfo</a>(QStringList() &lt;&lt; key, errmsg);
<a name="l00477"></a>00477   <span class="keywordflow">return</span> map.value(key);
<a name="l00478"></a>00478 }
<a name="l00479"></a>00479 <span class="comment"></span>
<a name="l00480"></a>00480 <span class="comment">/** Overloaded method to send a GETINFO command for a single info value */</span>
<a name="l00481"></a>00481 <span class="keywordtype">bool</span>
<a name="l00482"></a><a class="code" href="class_tor_control.html#ab423e8aa9da7c7dd66abbb78332876eb">00482</a> <a class="code" href="class_tor_control.html#a7bb6236b41505b30e8708c9f5cf8e8f7">TorControl::getInfo</a>(QString key, QString &amp;val, QString *errmsg)
<a name="l00483"></a>00483 {
<a name="l00484"></a>00484   QHash&lt;QString,QString&gt; map;
<a name="l00485"></a>00485   map.insert(key, <span class="stringliteral">&quot;&quot;</span>);
<a name="l00486"></a>00486 
<a name="l00487"></a>00487   <span class="keywordflow">if</span> (<a class="code" href="class_tor_control.html#a7bb6236b41505b30e8708c9f5cf8e8f7">getInfo</a>(map, errmsg)) {
<a name="l00488"></a>00488     val = map.value(key);
<a name="l00489"></a>00489     <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00490"></a>00490   }
<a name="l00491"></a>00491   <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00492"></a>00492 }
<a name="l00493"></a>00493 <span class="comment"></span>
<a name="l00494"></a>00494 <span class="comment">/** Sends a signal to Tor */</span>
<a name="l00495"></a>00495 <span class="keywordtype">bool</span>
<a name="l00496"></a><a class="code" href="class_tor_control.html#a373ecec8dbb7af273099d72a82a4d797">00496</a> <a class="code" href="class_tor_control.html#a373ecec8dbb7af273099d72a82a4d797">TorControl::signal</a>(<a class="code" href="class_tor_signal.html#ab1820803604813483f918d131bcf281f">TorSignal::Signal</a> sig, QString *errmsg)
<a name="l00497"></a>00497 {
<a name="l00498"></a>00498   <a class="code" href="class_control_command.html">ControlCommand</a> cmd(<span class="stringliteral">&quot;SIGNAL&quot;</span>);
<a name="l00499"></a>00499   cmd.<a class="code" href="class_control_command.html#a4f8c58a007da880191178044ae569ec0">addArgument</a>(<a class="code" href="class_tor_signal.html#abc419fca491a9dbee03b8488bf26d545">TorSignal::toString</a>(sig));
<a name="l00500"></a>00500 
<a name="l00501"></a>00501   <span class="keywordflow">if</span> (sig == <a class="code" href="class_tor_signal.html#ab1820803604813483f918d131bcf281fa7a524d8ade4d072184e7b60e41753dde">TorSignal::Shutdown</a> || sig == <a class="code" href="class_tor_signal.html#ab1820803604813483f918d131bcf281fabd399b688a1686f33d609e04d3a578e9">TorSignal::Halt</a>) {
<a name="l00502"></a>00502     <span class="comment">/* Tor closes the connection before giving us a response to any commands</span>
<a name="l00503"></a>00503 <span class="comment">     * asking it to stop running, so don&#39;t try to get a response. */</span>
<a name="l00504"></a>00504     <span class="keywordflow">return</span> <a class="code" href="class_tor_control.html#ac6ddb7eea451a3f7fd26188cdf18c1ef">_controlConn</a>-&gt;<a class="code" href="class_control_connection.html#aa5e4ff44b7c6e0773eda0a2f90505657">send</a>(cmd, errmsg);
<a name="l00505"></a>00505   }
<a name="l00506"></a>00506   <span class="keywordflow">return</span> <a class="code" href="class_tor_control.html#a2f2b9eb90d984ae4cfdafb777897e322">send</a>(cmd, errmsg);
<a name="l00507"></a>00507 }
<a name="l00508"></a>00508 <span class="comment"></span>
<a name="l00509"></a>00509 <span class="comment">/** Returns an address on which Tor is listening for application</span>
<a name="l00510"></a>00510 <span class="comment"> * requests. If none are available, a null QHostAddress is returned. */</span>
<a name="l00511"></a>00511 QHostAddress
<a name="l00512"></a><a class="code" href="class_tor_control.html#a2fb569a54bd8c0e73e81ba76a28f47fc">00512</a> <a class="code" href="class_tor_control.html#a2fb569a54bd8c0e73e81ba76a28f47fc">TorControl::getSocksAddress</a>(QString *errmsg)
<a name="l00513"></a>00513 {
<a name="l00514"></a>00514   QHostAddress socksAddr;
<a name="l00515"></a>00515 
<a name="l00516"></a>00516   <span class="comment">/* If SocksPort is 0, then Tor is not accepting any application requests. */</span>
<a name="l00517"></a>00517   <span class="keywordflow">if</span> (<a class="code" href="class_tor_control.html#ac58ed8ff6dc3a7fdf7fe16779e444b9a">getSocksPort</a>() == 0) {
<a name="l00518"></a>00518     <span class="keywordflow">return</span> QHostAddress::Null;
<a name="l00519"></a>00519   }
<a name="l00520"></a>00520 
<a name="l00521"></a>00521   <span class="comment">/* Get a list of SocksListenAddress lines and return the first valid IP</span>
<a name="l00522"></a>00522 <span class="comment">   * address parsed from the list. */</span>
<a name="l00523"></a>00523   QStringList addrList = <a class="code" href="class_tor_control.html#af00e73ae83a68ff12f076244356d6913">getSocksAddressList</a>(errmsg);
<a name="l00524"></a>00524   <span class="keywordflow">foreach</span> (QString addr, addrList) {
<a name="l00525"></a>00525     addr = addr.mid(0, addr.indexOf(<span class="stringliteral">&quot;:&quot;</span>));
<a name="l00526"></a>00526     <span class="keywordflow">if</span> (socksAddr.setAddress(addr)) {
<a name="l00527"></a>00527       <span class="keywordflow">return</span> socksAddr;
<a name="l00528"></a>00528     }
<a name="l00529"></a>00529   }
<a name="l00530"></a>00530   <span class="comment">/* Otherwise Tor is listening on its default 127.0.0.1 */</span>
<a name="l00531"></a>00531   <span class="keywordflow">return</span> QHostAddress::LocalHost;
<a name="l00532"></a>00532 }
<a name="l00533"></a>00533 <span class="comment"></span>
<a name="l00534"></a>00534 <span class="comment">/** Returns a (possibly empty) list of all currently configured</span>
<a name="l00535"></a>00535 <span class="comment"> * SocksListenAddress entries. */</span>
<a name="l00536"></a>00536 QStringList
<a name="l00537"></a><a class="code" href="class_tor_control.html#af00e73ae83a68ff12f076244356d6913">00537</a> <a class="code" href="class_tor_control.html#af00e73ae83a68ff12f076244356d6913">TorControl::getSocksAddressList</a>(QString *errmsg)
<a name="l00538"></a>00538 {
<a name="l00539"></a>00539   QStringList addrList;
<a name="l00540"></a>00540   <span class="keywordflow">if</span> (<a class="code" href="class_tor_control.html#ace854634f48d61319bcfd73b134aeba1">getConf</a>(<span class="stringliteral">&quot;SocksListenAddress&quot;</span>, addrList, errmsg)) {
<a name="l00541"></a>00541     <span class="keywordflow">return</span> addrList;
<a name="l00542"></a>00542   }
<a name="l00543"></a>00543   <span class="keywordflow">return</span> QStringList();
<a name="l00544"></a>00544 }
<a name="l00545"></a>00545 <span class="comment"></span>
<a name="l00546"></a>00546 <span class="comment">/** Returns a valid SOCKS port for Tor, or 0 if Tor is not accepting</span>
<a name="l00547"></a>00547 <span class="comment"> * application requests. */</span>
<a name="l00548"></a>00548 quint16
<a name="l00549"></a><a class="code" href="class_tor_control.html#ac58ed8ff6dc3a7fdf7fe16779e444b9a">00549</a> <a class="code" href="class_tor_control.html#ac58ed8ff6dc3a7fdf7fe16779e444b9a">TorControl::getSocksPort</a>(QString *errmsg)
<a name="l00550"></a>00550 {
<a name="l00551"></a>00551   QList&lt;quint16&gt; portList = <a class="code" href="class_tor_control.html#a927de53d699f7a8fe44d91672240b8e0">getSocksPortList</a>(errmsg);
<a name="l00552"></a>00552   <span class="keywordflow">if</span> (portList.size() &gt; 0) {
<a name="l00553"></a>00553     <span class="keywordflow">return</span> portList.at(0);
<a name="l00554"></a>00554   }
<a name="l00555"></a>00555   <span class="keywordflow">return</span> 0;
<a name="l00556"></a>00556 }
<a name="l00557"></a>00557 <span class="comment"></span>
<a name="l00558"></a>00558 <span class="comment">/** Returns a list of all currently configured SOCKS ports. If Tor is not</span>
<a name="l00559"></a>00559 <span class="comment"> * accepting any application connections, an empty list will be returned. */</span>
<a name="l00560"></a>00560 QList&lt;quint16&gt;
<a name="l00561"></a><a class="code" href="class_tor_control.html#a927de53d699f7a8fe44d91672240b8e0">00561</a> <a class="code" href="class_tor_control.html#a927de53d699f7a8fe44d91672240b8e0">TorControl::getSocksPortList</a>(QString *errmsg)
<a name="l00562"></a>00562 {
<a name="l00563"></a>00563   <span class="keywordtype">bool</span> valid;
<a name="l00564"></a>00564   quint16 port, socksPort;
<a name="l00565"></a>00565   QString portString;
<a name="l00566"></a>00566   QList&lt;quint16&gt; portList;
<a name="l00567"></a>00567 
<a name="l00568"></a>00568   <span class="comment">/* Get the value of the SocksPort configuration variable */</span>
<a name="l00569"></a>00569   <span class="keywordflow">if</span> (<a class="code" href="class_tor_control.html#ace854634f48d61319bcfd73b134aeba1">getConf</a>(<span class="stringliteral">&quot;SocksPort&quot;</span>, portString, errmsg)) {
<a name="l00570"></a>00570     socksPort = (quint16)portString.toUInt(&amp;valid);
<a name="l00571"></a>00571     <span class="keywordflow">if</span> (valid) {
<a name="l00572"></a>00572       <span class="keywordflow">if</span> (socksPort == 0) {
<a name="l00573"></a>00573         <span class="comment">/* A SocksPort of 0 means Tor is not accepting any application</span>
<a name="l00574"></a>00574 <span class="comment">         * connections. */</span>
<a name="l00575"></a>00575         <span class="keywordflow">return</span> QList&lt;quint16&gt;();
<a name="l00576"></a>00576       }
<a name="l00577"></a>00577     }
<a name="l00578"></a>00578   }
<a name="l00579"></a>00579   <span class="comment">/* Get a list of SOCKS ports from SocksListenAddress entries */</span>
<a name="l00580"></a>00580   QStringList addrList = <a class="code" href="class_tor_control.html#af00e73ae83a68ff12f076244356d6913">getSocksAddressList</a>(errmsg);
<a name="l00581"></a>00581   <span class="keywordflow">foreach</span> (QString addr, addrList) {
<a name="l00582"></a>00582     <span class="keywordflow">if</span> (addr.contains(<span class="stringliteral">&quot;:&quot;</span>)) {
<a name="l00583"></a>00583       portString = addr.mid(addr.indexOf(<span class="stringliteral">&quot;:&quot;</span>)+1);
<a name="l00584"></a>00584       port = (quint16)portString.toUInt(&amp;valid);
<a name="l00585"></a>00585       <span class="keywordflow">if</span> (valid) {
<a name="l00586"></a>00586         portList &lt;&lt; port;
<a name="l00587"></a>00587       }
<a name="l00588"></a>00588     }
<a name="l00589"></a>00589   }
<a name="l00590"></a>00590   <span class="comment">/* If there were no SocksListenAddress entries, or one or more of them did</span>
<a name="l00591"></a>00591 <span class="comment">   * not specify a port, then add the value of SocksPort, too */</span>
<a name="l00592"></a>00592   <span class="keywordflow">if</span> (!portList.size() || (portList.size() != addrList.size())) {
<a name="l00593"></a>00593     portList &lt;&lt; socksPort;
<a name="l00594"></a>00594   }
<a name="l00595"></a>00595   <span class="keywordflow">return</span> portList;
<a name="l00596"></a>00596 }
<a name="l00597"></a>00597 <span class="comment"></span>
<a name="l00598"></a>00598 <span class="comment">/** Reeturns Tor&#39;s version as a string. */</span>
<a name="l00599"></a>00599 QString
<a name="l00600"></a><a class="code" href="class_tor_control.html#aea1d9b4599cd0c5800f7c063f03a5262">00600</a> <a class="code" href="class_tor_control.html#aea1d9b4599cd0c5800f7c063f03a5262">TorControl::getTorVersionString</a>()
<a name="l00601"></a>00601 {
<a name="l00602"></a>00602   <span class="keywordflow">return</span> <a class="code" href="class_tor_control.html#aa27560cf64f335477f0404ec28d24051">_torVersion</a>;
<a name="l00603"></a>00603 }
<a name="l00604"></a>00604 <span class="comment"></span>
<a name="l00605"></a>00605 <span class="comment">/** Returns Tor&#39;s version as a numeric value. Note that this discards any</span>
<a name="l00606"></a>00606 <span class="comment"> * version status flag, such as &quot;-alpha&quot; or &quot;-rc&quot;. */</span>
<a name="l00607"></a>00607 quint32
<a name="l00608"></a><a class="code" href="class_tor_control.html#acd37862e652425dec4329acef6df4f3e">00608</a> <a class="code" href="class_tor_control.html#acd37862e652425dec4329acef6df4f3e">TorControl::getTorVersion</a>()
<a name="l00609"></a>00609 {
<a name="l00610"></a>00610   <span class="keyword">static</span> QString versionString;
<a name="l00611"></a>00611   <span class="keyword">static</span> quint32 version = 0;
<a name="l00612"></a>00612   quint8 major, minor, micro, patch;
<a name="l00613"></a>00613 
<a name="l00614"></a>00614   <span class="comment">/* Only recompute the version number if the version string changed */</span>
<a name="l00615"></a>00615   <span class="keywordflow">if</span> (versionString == <a class="code" href="class_tor_control.html#aa27560cf64f335477f0404ec28d24051">_torVersion</a>)
<a name="l00616"></a>00616     <span class="keywordflow">return</span> version;
<a name="l00617"></a>00617   versionString = <a class="code" href="class_tor_control.html#aa27560cf64f335477f0404ec28d24051">_torVersion</a>;
<a name="l00618"></a>00618 
<a name="l00619"></a>00619   <span class="comment">/* Split the version string at either &quot;.&quot; or &quot;-&quot; characters */</span>
<a name="l00620"></a>00620   QStringList parts = versionString.split(QRegExp(<span class="stringliteral">&quot;\\.|-|\\ &quot;</span>));
<a name="l00621"></a>00621   <span class="keywordflow">if</span> (parts.size() &gt;= 4) {
<a name="l00622"></a>00622     major = (quint8)parts.at(0).toUInt();
<a name="l00623"></a>00623     minor = (quint8)parts.at(1).toUInt();
<a name="l00624"></a>00624     micro = (quint8)parts.at(2).toUInt();
<a name="l00625"></a>00625     patch = (quint8)parts.at(3).toUInt();
<a name="l00626"></a>00626     version = ((major &lt;&lt; 24) | (minor &lt;&lt; 16) | (micro &lt;&lt; 8) | patch);
<a name="l00627"></a>00627   } <span class="keywordflow">else</span> {
<a name="l00628"></a>00628     <span class="comment">/* Couldn&#39;t parse the version string */</span>
<a name="l00629"></a>00629     version = 0;
<a name="l00630"></a>00630   }
<a name="l00631"></a>00631   <span class="keywordflow">return</span> version;
<a name="l00632"></a>00632 }
<a name="l00633"></a>00633 <span class="comment"></span>
<a name="l00634"></a>00634 <span class="comment">/** Sets an event and its handler. If add is true, then the event is added,</span>
<a name="l00635"></a>00635 <span class="comment"> * otherwise it is removed. If set is true, then the given event will be</span>
<a name="l00636"></a>00636 <span class="comment"> * registered with Tor. */</span>
<a name="l00637"></a>00637 <span class="keywordtype">bool</span>
<a name="l00638"></a><a class="code" href="class_tor_control.html#ab3dd744e5f82c562ef380a8ca447c3a3">00638</a> <a class="code" href="class_tor_control.html#ab3dd744e5f82c562ef380a8ca447c3a3">TorControl::setEvent</a>(<a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bf">TorEvents::Event</a> e, <span class="keywordtype">bool</span> add, <span class="keywordtype">bool</span> <span class="keyword">set</span>, QString *errmsg)
<a name="l00639"></a>00639 {
<a name="l00640"></a>00640   <a class="code" href="class_tor_control.html#aecf9cf541ec32de0e7206b9a17a409f5">_events</a> = (add ? (<a class="code" href="class_tor_control.html#aecf9cf541ec32de0e7206b9a17a409f5">_events</a> | e) : (<a class="code" href="class_tor_control.html#aecf9cf541ec32de0e7206b9a17a409f5">_events</a> &amp; ~e));
<a name="l00641"></a>00641   <span class="keywordflow">if</span> (<span class="keyword">set</span> &amp;&amp; <a class="code" href="class_tor_control.html#a5e39e327ca6c4ef5b4e2ce770a81a59f">isConnected</a>())
<a name="l00642"></a>00642     <span class="keywordflow">return</span> <a class="code" href="class_tor_control.html#a303b58f6d75569ee54478d55ede26464">setEvents</a>(errmsg);
<a name="l00643"></a>00643   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00644"></a>00644 }
<a name="l00645"></a>00645 <span class="comment"></span>
<a name="l00646"></a>00646 <span class="comment">/** Register for the events currently in the event list */</span>
<a name="l00647"></a>00647 <span class="keywordtype">bool</span>
<a name="l00648"></a><a class="code" href="class_tor_control.html#a303b58f6d75569ee54478d55ede26464">00648</a> <a class="code" href="class_tor_control.html#a303b58f6d75569ee54478d55ede26464">TorControl::setEvents</a>(QString *errmsg)
<a name="l00649"></a>00649 {
<a name="l00650"></a>00650   <a class="code" href="class_control_command.html">ControlCommand</a> cmd(<span class="stringliteral">&quot;SETEVENTS&quot;</span>);
<a name="l00651"></a>00651 
<a name="l00652"></a>00652   <span class="keywordflow">for</span> (<a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bf">TorEvents::Event</a> e = <a class="code" href="class_tor_events.html#a7153bf04e68d4f74e16efe2c9dcb1787">TorEvents::EVENT_MIN</a>; e &lt;= <a class="code" href="class_tor_events.html#a49369e2a61ceae0feffd8987c40d8d84">TorEvents::EVENT_MAX</a>;) {
<a name="l00653"></a>00653     <span class="keywordflow">if</span> (<a class="code" href="class_tor_control.html#aecf9cf541ec32de0e7206b9a17a409f5">_events</a> &amp; e)
<a name="l00654"></a>00654       cmd.<a class="code" href="class_control_command.html#a4f8c58a007da880191178044ae569ec0">addArgument</a>(<a class="code" href="class_tor_events.html#a8c62c55a950118cdeba5a7de34ac157b">TorEvents::toString</a>(e));
<a name="l00655"></a>00655     e = <span class="keyword">static_cast&lt;</span><a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bf">TorEvents::Event</a><span class="keyword">&gt;</span>(e &lt;&lt; 1);
<a name="l00656"></a>00656   }
<a name="l00657"></a>00657   <span class="keywordflow">return</span> <a class="code" href="class_tor_control.html#a2f2b9eb90d984ae4cfdafb777897e322">send</a>(cmd, errmsg);
<a name="l00658"></a>00658 }
<a name="l00659"></a>00659 <span class="comment"></span>
<a name="l00660"></a>00660 <span class="comment">/** Sets each configuration key in &lt;b&gt;map&lt;/b&gt; to the value associated</span>
<a name="l00661"></a>00661 <span class="comment"> * with its key. */</span>
<a name="l00662"></a>00662 <span class="keywordtype">bool</span>
<a name="l00663"></a><a class="code" href="class_tor_control.html#acd33beb0663b2a464a101c4efb425708">00663</a> <a class="code" href="class_tor_control.html#acd33beb0663b2a464a101c4efb425708">TorControl::setConf</a>(QHash&lt;QString,QString&gt; map, QString *errmsg)
<a name="l00664"></a>00664 {
<a name="l00665"></a>00665   <a class="code" href="class_control_command.html">ControlCommand</a> cmd(<span class="stringliteral">&quot;SETCONF&quot;</span>);
<a name="l00666"></a>00666 
<a name="l00667"></a>00667   <span class="comment">/* Add each keyvalue to the argument list */</span>
<a name="l00668"></a>00668   <span class="keywordflow">foreach</span> (QString key, map.uniqueKeys()) {
<a name="l00669"></a>00669     <span class="comment">/* If a key has multiple values (e.g., a QMultiHash), they are stored</span>
<a name="l00670"></a>00670 <span class="comment">     * in order from most recently inserted to least recently inserted.</span>
<a name="l00671"></a>00671 <span class="comment">     * So, walk the list in reverse so that we append the configuration</span>
<a name="l00672"></a>00672 <span class="comment">     * values to the SETCONF command in the same order they were inserted</span>
<a name="l00673"></a>00673 <span class="comment">     * into the QHash. */</span>
<a name="l00674"></a>00674     QList&lt;QString&gt; values = map.values(key);
<a name="l00675"></a>00675     <span class="keywordflow">for</span> (<span class="keywordtype">int</span> <a class="code" href="html_8cpp.html#a4a5dba6492ea149585950c59c210ff47">i</a> = values.size()-1; <a class="code" href="html_8cpp.html#a4a5dba6492ea149585950c59c210ff47">i</a> &gt;= 0; <a class="code" href="html_8cpp.html#a4a5dba6492ea149585950c59c210ff47">i</a>--) {
<a name="l00676"></a>00676       QString value = values.at(<a class="code" href="html_8cpp.html#a4a5dba6492ea149585950c59c210ff47">i</a>);
<a name="l00677"></a>00677       <span class="keywordflow">if</span> (value.length() &gt; 0)
<a name="l00678"></a>00678         cmd.<a class="code" href="class_control_command.html#a4f8c58a007da880191178044ae569ec0">addArgument</a>(key + <span class="stringliteral">&quot;=&quot;</span> + <a class="code" href="stringutil_8cpp.html#a2323f625d9f361167e0455447c3fc83a">string_escape</a>(value));
<a name="l00679"></a>00679       <span class="keywordflow">else</span>
<a name="l00680"></a>00680         cmd.<a class="code" href="class_control_command.html#a4f8c58a007da880191178044ae569ec0">addArgument</a>(key);
<a name="l00681"></a>00681     }
<a name="l00682"></a>00682   }
<a name="l00683"></a>00683   <span class="keywordflow">return</span> <a class="code" href="class_tor_control.html#a2f2b9eb90d984ae4cfdafb777897e322">send</a>(cmd, errmsg);
<a name="l00684"></a>00684 }
<a name="l00685"></a>00685 <span class="comment"></span>
<a name="l00686"></a>00686 <span class="comment">/** Sets a single configuration key to the given value. */</span>
<a name="l00687"></a>00687 <span class="keywordtype">bool</span>
<a name="l00688"></a><a class="code" href="class_tor_control.html#aed32048556282a91aa8bbe6c348c3b0f">00688</a> <a class="code" href="class_tor_control.html#acd33beb0663b2a464a101c4efb425708">TorControl::setConf</a>(QString key, QString value, QString *errmsg)
<a name="l00689"></a>00689 {
<a name="l00690"></a>00690   QHash&lt;QString,QString&gt; map;
<a name="l00691"></a>00691   map.insert(key, value);
<a name="l00692"></a>00692   <span class="keywordflow">return</span> <a class="code" href="class_tor_control.html#acd33beb0663b2a464a101c4efb425708">setConf</a>(map, errmsg);
<a name="l00693"></a>00693 }
<a name="l00694"></a>00694 <span class="comment"></span>
<a name="l00695"></a>00695 <span class="comment">/** Sets a single configuration string that is formatted &lt;key=escaped value&gt;.*/</span>
<a name="l00696"></a>00696 <span class="keywordtype">bool</span>
<a name="l00697"></a><a class="code" href="class_tor_control.html#a997b399f20e27df85bac0b515a69a8e1">00697</a> <a class="code" href="class_tor_control.html#acd33beb0663b2a464a101c4efb425708">TorControl::setConf</a>(QString keyAndValue, QString *errmsg)
<a name="l00698"></a>00698 {
<a name="l00699"></a>00699   QHash&lt;QString,QString&gt; map;
<a name="l00700"></a>00700   map.insert(keyAndValue, <span class="stringliteral">&quot;&quot;</span>);
<a name="l00701"></a>00701   <span class="keywordflow">return</span> <a class="code" href="class_tor_control.html#acd33beb0663b2a464a101c4efb425708">setConf</a>(map, errmsg);
<a name="l00702"></a>00702 }
<a name="l00703"></a>00703 <span class="comment"></span>
<a name="l00704"></a>00704 <span class="comment">/** Gets values for a set of configuration keys, each of which has a single</span>
<a name="l00705"></a>00705 <span class="comment"> * value. */</span>
<a name="l00706"></a>00706 <span class="keywordtype">bool</span>
<a name="l00707"></a><a class="code" href="class_tor_control.html#ace854634f48d61319bcfd73b134aeba1">00707</a> <a class="code" href="class_tor_control.html#ace854634f48d61319bcfd73b134aeba1">TorControl::getConf</a>(QHash&lt;QString,QString&gt; &amp;map, QString *errmsg)
<a name="l00708"></a>00708 {
<a name="l00709"></a>00709   QHash&lt;QString,QStringList&gt; multiMap;
<a name="l00710"></a>00710   <span class="keywordflow">foreach</span> (QString key, map.keys()) {
<a name="l00711"></a>00711     multiMap.insert(key, QStringList());
<a name="l00712"></a>00712   }
<a name="l00713"></a>00713   <span class="keywordflow">if</span> (<a class="code" href="class_tor_control.html#ace854634f48d61319bcfd73b134aeba1">getConf</a>(multiMap, errmsg)) {
<a name="l00714"></a>00714     <span class="keywordflow">foreach</span> (QString key, multiMap.keys()) {
<a name="l00715"></a>00715       <span class="keywordflow">if</span> (map.contains(key)) {
<a name="l00716"></a>00716         map.insert(key, multiMap.value(key).join(<span class="stringliteral">&quot;\n&quot;</span>));
<a name="l00717"></a>00717       }
<a name="l00718"></a>00718     }
<a name="l00719"></a>00719   }
<a name="l00720"></a>00720   <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00721"></a>00721 }
<a name="l00722"></a>00722 <span class="comment"></span>
<a name="l00723"></a>00723 <span class="comment">/** Gets a set of configuration keyvalues and stores them in &lt;b&gt;map&lt;/b&gt;. */</span>
<a name="l00724"></a>00724 <span class="keywordtype">bool</span>
<a name="l00725"></a><a class="code" href="class_tor_control.html#a027b8d23519adb59f6f583b6fbf38d79">00725</a> <a class="code" href="class_tor_control.html#ace854634f48d61319bcfd73b134aeba1">TorControl::getConf</a>(QHash&lt;QString,QStringList&gt; &amp;map, QString *errmsg)
<a name="l00726"></a>00726 {
<a name="l00727"></a>00727   <a class="code" href="class_control_command.html">ControlCommand</a> cmd(<span class="stringliteral">&quot;GETCONF&quot;</span>);
<a name="l00728"></a>00728   <a class="code" href="class_control_reply.html">ControlReply</a> reply;
<a name="l00729"></a>00729   QStringList confValue;
<a name="l00730"></a>00730   QString confKey;
<a name="l00731"></a>00731 
<a name="l00732"></a>00732   <span class="comment">/* Add the keys as arguments to the GETINFO message */</span>
<a name="l00733"></a>00733   <span class="keywordflow">foreach</span> (QString key, map.keys()) {
<a name="l00734"></a>00734     cmd.<a class="code" href="class_control_command.html#a4f8c58a007da880191178044ae569ec0">addArgument</a>(key);
<a name="l00735"></a>00735   }
<a name="l00736"></a>00736 
<a name="l00737"></a>00737   <span class="comment">/* Ask Tor for the specified info values */</span>
<a name="l00738"></a>00738   <span class="keywordflow">if</span> (<a class="code" href="class_tor_control.html#a2f2b9eb90d984ae4cfdafb777897e322">send</a>(cmd, reply, errmsg)) {
<a name="l00739"></a>00739     <span class="comment">/* Parse the response for the returned values */</span>
<a name="l00740"></a>00740     <span class="keywordflow">foreach</span> (<a class="code" href="class_reply_line.html">ReplyLine</a> line, reply.<a class="code" href="class_control_reply.html#a4ff2ea9c2c8035be7c5caf468da744f6">getLines</a>()) {
<a name="l00741"></a>00741       <span class="comment">/* Split the &quot;key=val&quot; line and map them */</span>
<a name="l00742"></a>00742       QStringList keyval = line.<a class="code" href="class_reply_line.html#ad22f50e33e6809eb25a07c090c8a960a">getMessage</a>().split(<span class="stringliteral">&quot;=&quot;</span>);
<a name="l00743"></a>00743       <span class="keywordflow">if</span> (keyval.size() == 2) {
<a name="l00744"></a>00744         confKey = keyval.at(0);
<a name="l00745"></a>00745 
<a name="l00746"></a>00746         <span class="keywordflow">if</span> (map.contains(confKey)) {
<a name="l00747"></a>00747           <span class="comment">/* This configuration key has multiple values, so add this one to</span>
<a name="l00748"></a>00748 <span class="comment">           * the list. */</span>
<a name="l00749"></a>00749           confValue = map.value(confKey);
<a name="l00750"></a>00750         }
<a name="l00751"></a>00751         confValue &lt;&lt; keyval.at(1);
<a name="l00752"></a>00752         map.insert(keyval.at(0), confValue);
<a name="l00753"></a>00753       }
<a name="l00754"></a>00754     }
<a name="l00755"></a>00755     <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00756"></a>00756   }
<a name="l00757"></a>00757   <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00758"></a>00758 }
<a name="l00759"></a>00759 <span class="comment"></span>
<a name="l00760"></a>00760 <span class="comment">/** Gets a single configuration value for &lt;b&gt;key&lt;/b&gt;. */</span>
<a name="l00761"></a>00761 <span class="keywordtype">bool</span>
<a name="l00762"></a><a class="code" href="class_tor_control.html#afa4aefbc3685be2a2fd84cb595ad82a4">00762</a> <a class="code" href="class_tor_control.html#ace854634f48d61319bcfd73b134aeba1">TorControl::getConf</a>(QString key, QString &amp;value, QString *errmsg)
<a name="l00763"></a>00763 {
<a name="l00764"></a>00764   QStringList confValues;
<a name="l00765"></a>00765   <span class="keywordflow">if</span> (<a class="code" href="class_tor_control.html#ace854634f48d61319bcfd73b134aeba1">getConf</a>(key, confValues, errmsg)) {
<a name="l00766"></a>00766     value = confValues.join(<span class="stringliteral">&quot;\n&quot;</span>);
<a name="l00767"></a>00767     <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00768"></a>00768   }
<a name="l00769"></a>00769   <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00770"></a>00770 }
<a name="l00771"></a>00771 <span class="comment"></span>
<a name="l00772"></a>00772 <span class="comment">/** Gets a list of configuration values for &lt;b&gt;key&lt;/b&gt;. */</span>
<a name="l00773"></a>00773 <span class="keywordtype">bool</span>
<a name="l00774"></a><a class="code" href="class_tor_control.html#a636dbee9658697a32da1dae16c6f4280">00774</a> <a class="code" href="class_tor_control.html#ace854634f48d61319bcfd73b134aeba1">TorControl::getConf</a>(QString key, QStringList &amp;value, QString *errmsg)
<a name="l00775"></a>00775 {
<a name="l00776"></a>00776   QHash&lt;QString,QStringList&gt; map;
<a name="l00777"></a>00777   map.insert(key, QStringList());
<a name="l00778"></a>00778 
<a name="l00779"></a>00779   <span class="keywordflow">if</span> (<a class="code" href="class_tor_control.html#ace854634f48d61319bcfd73b134aeba1">getConf</a>(map, errmsg)) {
<a name="l00780"></a>00780     value = map.value(key);
<a name="l00781"></a>00781     <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00782"></a>00782   }
<a name="l00783"></a>00783   <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00784"></a>00784 }
<a name="l00785"></a>00785 <span class="comment"></span>
<a name="l00786"></a>00786 <span class="comment">/** Sends a GETICONF message to Tor using the given list of &lt;b&gt;keys&lt;/b&gt; and</span>
<a name="l00787"></a>00787 <span class="comment"> * returns a QVariantMap containing the specified keys and their values as</span>
<a name="l00788"></a>00788 <span class="comment"> * returned  by Tor. Returns a default constructed QVariantMap on failure. */</span>
<a name="l00789"></a>00789 QVariantMap
<a name="l00790"></a><a class="code" href="class_tor_control.html#abdc2d9a160ab3ceab9b080fd82a25660">00790</a> <a class="code" href="class_tor_control.html#ace854634f48d61319bcfd73b134aeba1">TorControl::getConf</a>(<span class="keyword">const</span> QStringList &amp;keys, QString *errmsg)
<a name="l00791"></a>00791 {
<a name="l00792"></a>00792   <a class="code" href="class_control_command.html">ControlCommand</a> cmd(<span class="stringliteral">&quot;GETCONF&quot;</span>);
<a name="l00793"></a>00793   <a class="code" href="class_control_reply.html">ControlReply</a> reply;
<a name="l00794"></a>00794   QVariantMap confMap;
<a name="l00795"></a>00795 
<a name="l00796"></a>00796   cmd.<a class="code" href="class_control_command.html#ab5981c4f2760b6f23797ab23b7dc491b">addArguments</a>(keys);
<a name="l00797"></a>00797   <span class="keywordflow">if</span> (!<a class="code" href="class_tor_control.html#a2f2b9eb90d984ae4cfdafb777897e322">send</a>(cmd, reply, errmsg))
<a name="l00798"></a>00798     <span class="keywordflow">return</span> QVariantMap();
<a name="l00799"></a>00799 
<a name="l00800"></a>00800   <span class="keywordflow">foreach</span> (<a class="code" href="class_reply_line.html">ReplyLine</a> line, reply.<a class="code" href="class_control_reply.html#a4ff2ea9c2c8035be7c5caf468da744f6">getLines</a>()) {
<a name="l00801"></a>00801     QString msg = line.<a class="code" href="class_reply_line.html#ad22f50e33e6809eb25a07c090c8a960a">getMessage</a>();
<a name="l00802"></a>00802     <span class="keywordtype">int</span> index   = msg.indexOf(<span class="stringliteral">&quot;=&quot;</span>);
<a name="l00803"></a>00803     QString key = msg.mid(0, index);
<a name="l00804"></a>00804     QString val;
<a name="l00805"></a>00805 
<a name="l00806"></a>00806     <span class="keywordflow">if</span> (index &gt; 0 &amp;&amp; index &lt; msg.length()-1)
<a name="l00807"></a>00807       val = msg.mid(index+1);
<a name="l00808"></a>00808 
<a name="l00809"></a>00809     <span class="keywordflow">if</span> (confMap.contains(key)) {
<a name="l00810"></a>00810       QStringList values = confMap.value(key).toStringList();
<a name="l00811"></a>00811       values &lt;&lt; val;
<a name="l00812"></a>00812       confMap.insert(key, values);
<a name="l00813"></a>00813     } <span class="keywordflow">else</span> {
<a name="l00814"></a>00814       confMap.insert(key, val);
<a name="l00815"></a>00815     }
<a name="l00816"></a>00816   }
<a name="l00817"></a>00817   <span class="keywordflow">return</span> confMap;
<a name="l00818"></a>00818 }
<a name="l00819"></a>00819 <span class="comment"></span>
<a name="l00820"></a>00820 <span class="comment">/** Sends a GETCONF message to Tor with a single &lt;b&gt;key&lt;/b&gt; and returns a</span>
<a name="l00821"></a>00821 <span class="comment"> * QVariant containing the value returned by Tor. Returns a default</span>
<a name="l00822"></a>00822 <span class="comment"> * constructed QVariant on failure. */</span>
<a name="l00823"></a>00823 QVariant
<a name="l00824"></a><a class="code" href="class_tor_control.html#ae91cf9459e5d687f82ae005a7dd63865">00824</a> <a class="code" href="class_tor_control.html#ace854634f48d61319bcfd73b134aeba1">TorControl::getConf</a>(<span class="keyword">const</span> QString &amp;key, QString *errmsg)
<a name="l00825"></a>00825 {
<a name="l00826"></a>00826   QVariantMap map = <a class="code" href="class_tor_control.html#ace854634f48d61319bcfd73b134aeba1">getConf</a>(QStringList() &lt;&lt; key, errmsg);
<a name="l00827"></a>00827   <span class="keywordflow">return</span> map.value(key);
<a name="l00828"></a>00828 }
<a name="l00829"></a>00829 <span class="comment"></span>
<a name="l00830"></a>00830 <span class="comment">/** Sends a GETCONF message to Tor with the single key and returns a QString</span>
<a name="l00831"></a>00831 <span class="comment"> * containing the value returned by Tor */</span>
<a name="l00832"></a>00832 QString
<a name="l00833"></a><a class="code" href="class_tor_control.html#a75f4cc50bb7c17f3cedc2822a47bcd0c">00833</a> <a class="code" href="class_tor_control.html#a75f4cc50bb7c17f3cedc2822a47bcd0c">TorControl::getHiddenServiceConf</a>(<span class="keyword">const</span> QString &amp;key, QString *errmsg)
<a name="l00834"></a>00834 {
<a name="l00835"></a>00835   <a class="code" href="class_control_command.html">ControlCommand</a> cmd(<span class="stringliteral">&quot;GETCONF&quot;</span>);
<a name="l00836"></a>00836   <a class="code" href="class_control_reply.html">ControlReply</a> reply;
<a name="l00837"></a>00837   QVariantMap confMap;
<a name="l00838"></a>00838 
<a name="l00839"></a>00839   cmd.<a class="code" href="class_control_command.html#a4f8c58a007da880191178044ae569ec0">addArgument</a>(key);
<a name="l00840"></a>00840   <span class="keywordflow">if</span> (!<a class="code" href="class_tor_control.html#a2f2b9eb90d984ae4cfdafb777897e322">send</a>(cmd, reply, errmsg))
<a name="l00841"></a>00841     <span class="keywordflow">return</span> <span class="stringliteral">&quot;&quot;</span>;
<a name="l00842"></a>00842 
<a name="l00843"></a>00843   <span class="keywordflow">return</span> reply.<a class="code" href="class_control_reply.html#ad03c1cb6d54f7809975b733c4a33d38f">toString</a>();
<a name="l00844"></a>00844 }
<a name="l00845"></a>00845 <span class="comment"></span>
<a name="l00846"></a>00846 <span class="comment">/** Asks Tor to save the current configuration to its torrc. */</span>
<a name="l00847"></a>00847 <span class="keywordtype">bool</span>
<a name="l00848"></a><a class="code" href="class_tor_control.html#a020ad2cfbd1adbfeda679aebb4bac966">00848</a> <a class="code" href="class_tor_control.html#a020ad2cfbd1adbfeda679aebb4bac966">TorControl::saveConf</a>(QString *errmsg)
<a name="l00849"></a>00849 {
<a name="l00850"></a>00850   <a class="code" href="class_control_command.html">ControlCommand</a> cmd(<span class="stringliteral">&quot;SAVECONF&quot;</span>);
<a name="l00851"></a>00851   <span class="keywordflow">return</span> <a class="code" href="class_tor_control.html#a2f2b9eb90d984ae4cfdafb777897e322">send</a>(cmd, errmsg);
<a name="l00852"></a>00852 }
<a name="l00853"></a>00853 <span class="comment"></span>
<a name="l00854"></a>00854 <span class="comment">/** Tells Tor to reset the given configuration keys back to defaults. */</span>
<a name="l00855"></a>00855 <span class="keywordtype">bool</span>
<a name="l00856"></a><a class="code" href="class_tor_control.html#aba22570eab1b0ca3735d1a32dbcd3de9">00856</a> <a class="code" href="class_tor_control.html#aba22570eab1b0ca3735d1a32dbcd3de9">TorControl::resetConf</a>(QStringList keys, QString *errmsg)
<a name="l00857"></a>00857 {
<a name="l00858"></a>00858   <a class="code" href="class_control_command.html">ControlCommand</a> cmd(<span class="stringliteral">&quot;RESETCONF&quot;</span>);
<a name="l00859"></a>00859 
<a name="l00860"></a>00860   <span class="comment">/* Add each key to the argument list */</span>
<a name="l00861"></a>00861   <span class="keywordflow">foreach</span> (QString key, keys) {
<a name="l00862"></a>00862     cmd.<a class="code" href="class_control_command.html#a4f8c58a007da880191178044ae569ec0">addArgument</a>(key);
<a name="l00863"></a>00863   }
<a name="l00864"></a>00864   <span class="keywordflow">return</span> <a class="code" href="class_tor_control.html#a2f2b9eb90d984ae4cfdafb777897e322">send</a>(cmd, errmsg);
<a name="l00865"></a>00865 }
<a name="l00866"></a>00866 <span class="comment"></span>
<a name="l00867"></a>00867 <span class="comment">/** Tells Tor to reset a single given configuration key back to its default</span>
<a name="l00868"></a>00868 <span class="comment"> * value. */</span>
<a name="l00869"></a>00869 <span class="keywordtype">bool</span>
<a name="l00870"></a><a class="code" href="class_tor_control.html#ad361a33af10e55e06f1a7b8a57c43e8a">00870</a> <a class="code" href="class_tor_control.html#aba22570eab1b0ca3735d1a32dbcd3de9">TorControl::resetConf</a>(QString key, QString *errmsg)
<a name="l00871"></a>00871 {
<a name="l00872"></a>00872   <span class="keywordflow">return</span> <a class="code" href="class_tor_control.html#aba22570eab1b0ca3735d1a32dbcd3de9">resetConf</a>(QStringList() &lt;&lt; key, errmsg);
<a name="l00873"></a>00873 }
<a name="l00874"></a>00874 <span class="comment"></span>
<a name="l00875"></a>00875 <span class="comment">/** Returns an unparsed router descriptor for the router whose fingerprint</span>
<a name="l00876"></a>00876 <span class="comment"> * matches &lt;b&gt;id&lt;/b&gt;. The returned text can later be parsed by the</span>
<a name="l00877"></a>00877 <span class="comment"> * RouterDescriptor class. If &lt;b&gt;id&lt;/b&gt; is invalid, then an empty</span>
<a name="l00878"></a>00878 <span class="comment"> * QStringList is returned. */</span>
<a name="l00879"></a>00879 QStringList
<a name="l00880"></a><a class="code" href="class_tor_control.html#a4e1892fd5e35f076ac199936c3446b53">00880</a> <a class="code" href="class_tor_control.html#a4e1892fd5e35f076ac199936c3446b53">TorControl::getRouterDescriptorText</a>(<span class="keyword">const</span> QString &amp;<span class="keywordtype">id</span>, QString *errmsg)
<a name="l00881"></a>00881 {
<a name="l00882"></a>00882   <span class="keywordflow">return</span> <a class="code" href="class_tor_control.html#a7bb6236b41505b30e8708c9f5cf8e8f7">getInfo</a>(<span class="stringliteral">&quot;desc/id/&quot;</span> + <span class="keywordtype">id</span>, errmsg).toStringList();
<a name="l00883"></a>00883 }
<a name="l00884"></a>00884 <span class="comment"></span>
<a name="l00885"></a>00885 <span class="comment">/** Returns the descriptor for the router whose fingerprint matches</span>
<a name="l00886"></a>00886 <span class="comment"> * &lt;b&gt;id&lt;/b&gt;. If &lt;b&gt;id&lt;/b&gt; is invalid or the router&#39;s descriptor cannot</span>
<a name="l00887"></a>00887 <span class="comment"> * be parsed, then an invalid RouterDescriptor is returned. */</span>
<a name="l00888"></a>00888 <a class="code" href="class_router_descriptor.html">RouterDescriptor</a>
<a name="l00889"></a><a class="code" href="class_tor_control.html#ad308e247d95f72400da3dfaf107477e0">00889</a> <a class="code" href="class_tor_control.html#ad308e247d95f72400da3dfaf107477e0">TorControl::getRouterDescriptor</a>(<span class="keyword">const</span> QString &amp;<span class="keywordtype">id</span>, QString *errmsg)
<a name="l00890"></a>00890 {
<a name="l00891"></a>00891   <span class="keywordflow">return</span> <a class="code" href="class_router_descriptor.html">RouterDescriptor</a>(<a class="code" href="class_tor_control.html#a4e1892fd5e35f076ac199936c3446b53">getRouterDescriptorText</a>(<span class="keywordtype">id</span>, errmsg));
<a name="l00892"></a>00892 }
<a name="l00893"></a>00893 <span class="comment"></span>
<a name="l00894"></a>00894 <span class="comment">/** Returns the status of the router whose fingerprint matches &lt;b&gt;id&lt;/b&gt;. If</span>
<a name="l00895"></a>00895 <span class="comment"> * &lt;b&gt;id&lt;/b&gt; is invalid or the router&#39;s status cannot be parsed, then an</span>
<a name="l00896"></a>00896 <span class="comment"> * invalid RouterStatus is returned. */</span>
<a name="l00897"></a>00897 <a class="code" href="class_router_status.html">RouterStatus</a>
<a name="l00898"></a><a class="code" href="class_tor_control.html#a25362380480443a5c1cbe37b64efee1c">00898</a> <a class="code" href="class_tor_control.html#a25362380480443a5c1cbe37b64efee1c">TorControl::getRouterStatus</a>(<span class="keyword">const</span> QString &amp;<span class="keywordtype">id</span>, QString *errmsg)
<a name="l00899"></a>00899 {
<a name="l00900"></a>00900   QStringList status = <a class="code" href="class_tor_control.html#a7bb6236b41505b30e8708c9f5cf8e8f7">getInfo</a>(<span class="stringliteral">&quot;ns/id/&quot;</span> + <span class="keywordtype">id</span>, errmsg).toStringList();
<a name="l00901"></a>00901   <span class="keywordflow">return</span> <a class="code" href="class_router_status.html">RouterStatus</a>(status);
<a name="l00902"></a>00902 }
<a name="l00903"></a>00903 <span class="comment"></span>
<a name="l00904"></a>00904 <span class="comment">/** Returns a RouterStatus object for every known router in the network. If</span>
<a name="l00905"></a>00905 <span class="comment"> * the network status document cannot be parsed, then an empty NetworkStatus</span>
<a name="l00906"></a>00906 <span class="comment"> * is returned. */</span>
<a name="l00907"></a>00907 <a class="code" href="_router_status_8h.html#a0043af5f764cd62f178e35cbd74f494b">NetworkStatus</a>
<a name="l00908"></a><a class="code" href="class_tor_control.html#a43e60487d83b03bf401afddb0a17a60a">00908</a> <a class="code" href="class_tor_control.html#a43e60487d83b03bf401afddb0a17a60a">TorControl::getNetworkStatus</a>(QString *errmsg)
<a name="l00909"></a>00909 {
<a name="l00910"></a>00910   QStringList networkStatusLines = <a class="code" href="class_tor_control.html#a7bb6236b41505b30e8708c9f5cf8e8f7">getInfo</a>(<span class="stringliteral">&quot;ns/all&quot;</span>, errmsg).toStringList();
<a name="l00911"></a>00911   QList&lt;RouterStatus&gt; networkStatus;
<a name="l00912"></a>00912   <span class="keywordtype">int</span> len = networkStatusLines.size();
<a name="l00913"></a>00913   <span class="keywordtype">int</span> <a class="code" href="html_8cpp.html#a4a5dba6492ea149585950c59c210ff47">i</a> = 0;
<a name="l00914"></a>00914 
<a name="l00915"></a>00915   <span class="keywordflow">while</span> (i &lt; len) {
<a name="l00916"></a>00916     <span class="comment">/* Extract the &quot;r&quot;, &quot;s&quot;, and whatever other status lines */</span>
<a name="l00917"></a>00917     QStringList routerStatusLines;
<a name="l00918"></a>00918     <span class="keywordflow">do</span> {
<a name="l00919"></a>00919       routerStatusLines &lt;&lt; networkStatusLines.at(i);
<a name="l00920"></a>00920     } <span class="keywordflow">while</span> (++i &lt; len &amp;&amp; ! networkStatusLines.at(i).startsWith(<span class="stringliteral">&quot;r &quot;</span>));
<a name="l00921"></a>00921 
<a name="l00922"></a>00922     <span class="comment">/* Create a new RouterStatus object and add it to the network status, if</span>
<a name="l00923"></a>00923 <span class="comment">     * it&#39;s valid. */</span>
<a name="l00924"></a>00924     <a class="code" href="class_router_status.html">RouterStatus</a> routerStatus(routerStatusLines);
<a name="l00925"></a>00925     <span class="keywordflow">if</span> (routerStatus.<a class="code" href="class_router_status.html#a81f921247025b634a9b9b0a3ee185d99">isValid</a>())
<a name="l00926"></a>00926       networkStatus &lt;&lt; routerStatus;
<a name="l00927"></a>00927   }
<a name="l00928"></a>00928   <span class="keywordflow">return</span> networkStatus;
<a name="l00929"></a>00929 }
<a name="l00930"></a>00930 <span class="comment"></span>
<a name="l00931"></a>00931 <span class="comment">/** Returns the annotations for the router whose fingerprint matches</span>
<a name="l00932"></a>00932 <span class="comment"> * &lt;b&gt;id&lt;/b&gt;. If &lt;b&gt;id&lt;/b&gt; is invalid or the router&#39;s annotations cannot be</span>
<a name="l00933"></a>00933 <span class="comment"> * parsed, then an empty DescriptorAnnotations is returned and &lt;b&gt;errmsg&lt;/b&gt;</span>
<a name="l00934"></a>00934 <span class="comment"> * is set if it&#39;s not NULL. (Tor &gt;= 0.2.0.13-alpha only) */</span>
<a name="l00935"></a>00935 <a class="code" href="_tor_control_8h.html#a53ee5ca0a1f990092916e579bb23103a">DescriptorAnnotations</a>
<a name="l00936"></a><a class="code" href="class_tor_control.html#a98b04340a13e19df051c5d533a4419b1">00936</a> <a class="code" href="class_tor_control.html#a98b04340a13e19df051c5d533a4419b1">TorControl::getDescriptorAnnotations</a>(<span class="keyword">const</span> QString &amp;<span class="keywordtype">id</span>, QString *errmsg)
<a name="l00937"></a>00937 {
<a name="l00938"></a>00938   QStringList lines = <a class="code" href="class_tor_control.html#a7bb6236b41505b30e8708c9f5cf8e8f7">getInfo</a>(<span class="stringliteral">&quot;desc-annotations/id/&quot;</span>+<span class="keywordtype">id</span>, errmsg).toStringList();
<a name="l00939"></a>00939   <a class="code" href="_tor_control_8h.html#a53ee5ca0a1f990092916e579bb23103a">DescriptorAnnotations</a> annotations;
<a name="l00940"></a>00940   QString key, value;
<a name="l00941"></a>00941 
<a name="l00942"></a>00942   <span class="keywordflow">foreach</span> (QString line, lines) {
<a name="l00943"></a>00943     <span class="keywordtype">int</span> idx = line.indexOf(<span class="stringliteral">&quot; &quot;</span>);
<a name="l00944"></a>00944 
<a name="l00945"></a>00945     <span class="comment">/* Extract the annotation key */</span>
<a name="l00946"></a>00946     key = line.mid(0, idx);
<a name="l00947"></a>00947     <span class="keywordflow">if</span> (key.startsWith(<span class="stringliteral">&quot;@&quot;</span>))
<a name="l00948"></a>00948       key = key.remove(0, 1);
<a name="l00949"></a>00949 
<a name="l00950"></a>00950     <span class="comment">/* Extract the annotation value (if present) */</span>
<a name="l00951"></a>00951     <span class="keywordflow">if</span> (idx &gt; 0 &amp;&amp; idx &lt; line.length()-1)
<a name="l00952"></a>00952       annotations.insert(key, line.mid(idx + 1).trimmed());
<a name="l00953"></a>00953     <span class="keywordflow">else</span>
<a name="l00954"></a>00954       annotations.insert(key, QString());
<a name="l00955"></a>00955   }
<a name="l00956"></a>00956   <span class="keywordflow">return</span> annotations;
<a name="l00957"></a>00957 }
<a name="l00958"></a>00958 <span class="comment"></span>
<a name="l00959"></a>00959 <span class="comment">/** Gets a list of current circuits. */</span>
<a name="l00960"></a>00960 QList&lt;Circuit&gt;
<a name="l00961"></a><a class="code" href="class_tor_control.html#ab2180f731d4e74f83441618a62c036d6">00961</a> <a class="code" href="class_tor_control.html#ab2180f731d4e74f83441618a62c036d6">TorControl::getCircuits</a>(QString *errmsg)
<a name="l00962"></a>00962 {
<a name="l00963"></a>00963   <a class="code" href="class_control_command.html">ControlCommand</a> cmd(<span class="stringliteral">&quot;GETINFO&quot;</span>, <span class="stringliteral">&quot;circuit-status&quot;</span>);
<a name="l00964"></a>00964   <a class="code" href="class_control_reply.html">ControlReply</a> reply;
<a name="l00965"></a>00965   <a class="code" href="_circuit_8h.html#a5c7c01bcee10c15862fdf844c3d1538c">CircuitList</a> circuits;
<a name="l00966"></a>00966 
<a name="l00967"></a>00967   <span class="keywordflow">if</span> (!<a class="code" href="class_tor_control.html#a2f2b9eb90d984ae4cfdafb777897e322">send</a>(cmd, reply, errmsg))
<a name="l00968"></a>00968     <span class="keywordflow">return</span> <a class="code" href="_circuit_8h.html#a5c7c01bcee10c15862fdf844c3d1538c">CircuitList</a>();
<a name="l00969"></a>00969 
<a name="l00970"></a>00970   <span class="comment">/* The rest of the circuits just come as data, one per line */</span>
<a name="l00971"></a>00971   <span class="keywordflow">foreach</span>(QString line, reply.<a class="code" href="class_control_reply.html#a4c14d998eeb24a4e47bbcafc8192d09f">getData</a>()) {
<a name="l00972"></a>00972     <a class="code" href="class_circuit.html">Circuit</a> circ(line);
<a name="l00973"></a>00973     <span class="keywordflow">if</span> (circ.<a class="code" href="class_circuit.html#ae723c9138712a7b0b9b99e156583f9c5">isValid</a>())
<a name="l00974"></a>00974       circuits &lt;&lt; circ;
<a name="l00975"></a>00975   }
<a name="l00976"></a>00976   <span class="keywordflow">return</span> circuits;
<a name="l00977"></a>00977 }
<a name="l00978"></a>00978 <span class="comment"></span>
<a name="l00979"></a>00979 <span class="comment">/** Closes the circuit specified by &lt;b&gt;circId&lt;/b&gt;. If &lt;b&gt;ifUnused&lt;/b&gt; is</span>
<a name="l00980"></a>00980 <span class="comment"> * true, then the circuit will not be closed unless it is unused. */</span>
<a name="l00981"></a>00981 <span class="keywordtype">bool</span>
<a name="l00982"></a><a class="code" href="class_tor_control.html#a7a1234a058e1c09c9c30fc77b41ba1ea">00982</a> <a class="code" href="class_tor_control.html#a7a1234a058e1c09c9c30fc77b41ba1ea">TorControl::closeCircuit</a>(<span class="keyword">const</span> <a class="code" href="_circuit_8h.html#a8b7b0182a6d1ff0aab7ab31df9c3f83d">CircuitId</a> &amp;circId, <span class="keywordtype">bool</span> ifUnused, QString *errmsg)
<a name="l00983"></a>00983 {
<a name="l00984"></a>00984   <a class="code" href="class_control_command.html">ControlCommand</a> cmd(<span class="stringliteral">&quot;CLOSECIRCUIT&quot;</span>, circId);
<a name="l00985"></a>00985   <span class="keywordflow">if</span> (ifUnused) {
<a name="l00986"></a>00986     cmd.<a class="code" href="class_control_command.html#a4f8c58a007da880191178044ae569ec0">addArgument</a>(<span class="stringliteral">&quot;IfUnused&quot;</span>);
<a name="l00987"></a>00987   }
<a name="l00988"></a>00988   <span class="keywordflow">return</span> <a class="code" href="class_tor_control.html#a2f2b9eb90d984ae4cfdafb777897e322">send</a>(cmd, errmsg);
<a name="l00989"></a>00989 }
<a name="l00990"></a>00990 <span class="comment"></span>
<a name="l00991"></a>00991 <span class="comment">/** Gets a list of current streams. */</span>
<a name="l00992"></a>00992 QList&lt;Stream&gt;
<a name="l00993"></a><a class="code" href="class_tor_control.html#ada4852a5804eafaebfd26eaaee3859ab">00993</a> <a class="code" href="class_tor_control.html#ada4852a5804eafaebfd26eaaee3859ab">TorControl::getStreams</a>(QString *errmsg)
<a name="l00994"></a>00994 {
<a name="l00995"></a>00995   <a class="code" href="class_control_command.html">ControlCommand</a> cmd(<span class="stringliteral">&quot;GETINFO&quot;</span>, <span class="stringliteral">&quot;stream-status&quot;</span>);
<a name="l00996"></a>00996   <a class="code" href="class_control_reply.html">ControlReply</a> reply;
<a name="l00997"></a>00997   QList&lt;Stream&gt; streams;
<a name="l00998"></a>00998   <a class="code" href="class_stream.html">Stream</a> s;
<a name="l00999"></a>00999 
<a name="l01000"></a>01000   <span class="keywordflow">if</span> (<a class="code" href="class_tor_control.html#a2f2b9eb90d984ae4cfdafb777897e322">send</a>(cmd, reply, errmsg)) {
<a name="l01001"></a>01001     <span class="comment">/* Sometimes there is a stream on the first message line */</span>
<a name="l01002"></a>01002     QString msg = reply.<a class="code" href="class_control_reply.html#a13b0ec6e2d3d97932297cf2002c25578">getMessage</a>();
<a name="l01003"></a>01003     s = <a class="code" href="class_stream.html#aeaff90f7abf81399e207c480d1bee8a0">Stream::fromString</a>(msg.mid(msg.indexOf(<span class="stringliteral">&quot;=&quot;</span>)+1));
<a name="l01004"></a>01004     <span class="keywordflow">if</span> (s.<a class="code" href="class_stream.html#a347b15c4c22b5c84145433725c9637e3">isValid</a>())
<a name="l01005"></a>01005       streams &lt;&lt; s;
<a name="l01006"></a>01006 
<a name="l01007"></a>01007     <span class="comment">/* The rest of the streams just come as data, one per line */</span>
<a name="l01008"></a>01008     <span class="keywordflow">foreach</span> (QString line, reply.<a class="code" href="class_control_reply.html#a4c14d998eeb24a4e47bbcafc8192d09f">getData</a>()) {
<a name="l01009"></a>01009       s = <a class="code" href="class_stream.html#aeaff90f7abf81399e207c480d1bee8a0">Stream::fromString</a>(line);
<a name="l01010"></a>01010       <span class="keywordflow">if</span> (s.<a class="code" href="class_stream.html#a347b15c4c22b5c84145433725c9637e3">isValid</a>())
<a name="l01011"></a>01011         streams &lt;&lt; s;
<a name="l01012"></a>01012     }
<a name="l01013"></a>01013   }
<a name="l01014"></a>01014   <span class="keywordflow">return</span> streams;
<a name="l01015"></a>01015 }
<a name="l01016"></a>01016 <span class="comment"></span>
<a name="l01017"></a>01017 <span class="comment">/** Closes the stream specified by &lt;b&gt;streamId&lt;/b&gt;. */</span>
<a name="l01018"></a>01018 <span class="keywordtype">bool</span>
<a name="l01019"></a><a class="code" href="class_tor_control.html#aa93a27e4936ed77d45aab1eaf16539ed">01019</a> <a class="code" href="class_tor_control.html#aa93a27e4936ed77d45aab1eaf16539ed">TorControl::closeStream</a>(<span class="keyword">const</span> <a class="code" href="_stream_8h.html#a90d94d8a7b979b4c7e07f5869a431064">StreamId</a> &amp;streamId, QString *errmsg)
<a name="l01020"></a>01020 {
<a name="l01021"></a>01021   <a class="code" href="class_control_command.html">ControlCommand</a> cmd(<span class="stringliteral">&quot;CLOSESTREAM&quot;</span>, streamId);
<a name="l01022"></a>01022   cmd.<a class="code" href="class_control_command.html#a4f8c58a007da880191178044ae569ec0">addArgument</a>(<span class="stringliteral">&quot;1&quot;</span>); <span class="comment">/* 1 == REASON_MISC (tor-spec.txt) */</span>
<a name="l01023"></a>01023   <span class="keywordflow">return</span> <a class="code" href="class_tor_control.html#a2f2b9eb90d984ae4cfdafb777897e322">send</a>(cmd, errmsg);
<a name="l01024"></a>01024 }
<a name="l01025"></a>01025 <span class="comment"></span>
<a name="l01026"></a>01026 <span class="comment"> /** Gets a list of address mappings of the type specified by &lt;b&gt;type&lt;/b&gt;</span>
<a name="l01027"></a>01027 <span class="comment">  * (defaults to &lt;i&gt;AddressMapAll&lt;/i&gt;. */</span>
<a name="l01028"></a>01028 <a class="code" href="class_address_map.html">AddressMap</a>
<a name="l01029"></a><a class="code" href="class_tor_control.html#a3fa594dd2b11b0451fdeca36bbd7c18d">01029</a> <a class="code" href="class_tor_control.html#a3fa594dd2b11b0451fdeca36bbd7c18d">TorControl::getAddressMap</a>(<a class="code" href="class_address_map.html#a06fbb154318e85e74c8f910bc919c699">AddressMap::AddressMapType</a> type, QString *errmsg)
<a name="l01030"></a>01030 {
<a name="l01031"></a>01031   <a class="code" href="class_address_map.html">AddressMap</a> addressMap;
<a name="l01032"></a>01032   QStringList entries;
<a name="l01033"></a>01033 
<a name="l01034"></a>01034   <span class="keywordflow">switch</span> (type) {
<a name="l01035"></a>01035     <span class="keywordflow">case</span> <a class="code" href="class_address_map.html#a06fbb154318e85e74c8f910bc919c699ad7d4a9ef73ce448f61e4722c2f418951">AddressMap::AddressMapConfig</a>:
<a name="l01036"></a>01036       entries = <a class="code" href="class_tor_control.html#a7bb6236b41505b30e8708c9f5cf8e8f7">getInfo</a>(<span class="stringliteral">&quot;address-mappings/config&quot;</span>).toStringList();
<a name="l01037"></a>01037       <span class="keywordflow">break</span>;
<a name="l01038"></a>01038     <span class="keywordflow">case</span> <a class="code" href="class_address_map.html#a06fbb154318e85e74c8f910bc919c699a8879352eb46e6b9b030b6dd481ad04ea">AddressMap::AddressMapCache</a>:
<a name="l01039"></a>01039       entries = <a class="code" href="class_tor_control.html#a7bb6236b41505b30e8708c9f5cf8e8f7">getInfo</a>(<span class="stringliteral">&quot;address-mappings/cache&quot;</span>).toStringList();
<a name="l01040"></a>01040       <span class="keywordflow">break</span>;
<a name="l01041"></a>01041     <span class="keywordflow">case</span> <a class="code" href="class_address_map.html#a06fbb154318e85e74c8f910bc919c699ad5b426af09f0b2f329bea8818045cb64">AddressMap::AddressMapControl</a>:
<a name="l01042"></a>01042       entries = <a class="code" href="class_tor_control.html#a7bb6236b41505b30e8708c9f5cf8e8f7">getInfo</a>(<span class="stringliteral">&quot;address-mappings/control&quot;</span>).toStringList();
<a name="l01043"></a>01043       <span class="keywordflow">break</span>;
<a name="l01044"></a>01044     <span class="keywordflow">default</span>:
<a name="l01045"></a>01045       entries = <a class="code" href="class_tor_control.html#a7bb6236b41505b30e8708c9f5cf8e8f7">getInfo</a>(<span class="stringliteral">&quot;address-mappings/all&quot;</span>).toStringList();
<a name="l01046"></a>01046   }
<a name="l01047"></a>01047 
<a name="l01048"></a>01048   <span class="keywordflow">foreach</span> (QString entry, entries) {
<a name="l01049"></a>01049     addressMap.<a class="code" href="class_address_map.html#a1bb12511981bfe02622253b514748698">add</a>(entry);
<a name="l01050"></a>01050   }
<a name="l01051"></a>01051   <span class="keywordflow">return</span> addressMap;
<a name="l01052"></a>01052 }
<a name="l01053"></a>01053 
</pre></div></div>
<hr class="footer"/><address style="text-align: right;"><small>Generated on Mon Aug 30 22:58:55 2010 for Vidalia by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.3 </small></address>
</body>
</html>