Sophie

Sophie

distrib > Mandriva > 2010.2 > i586 > by-pkgid > 9601c7beb4ff23e834bfa171795ed560 > files > 351

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: TorSettings.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_695ba8f8357372e02d38c40b3c6dbe81.html">vidalia</a>&nbsp;&raquo;&nbsp;<a class="el" href="dir_738aec08306f4b898e01f7a551299457.html">config</a>
  </div>
</div>
<div class="contents">
<h1>TorSettings.cpp</h1><a href="_tor_settings_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 you</span>
<a name="l00004"></a>00004 <span class="comment">**  did not receive the LICENSE file with this file, you may obtain it from the</span>
<a name="l00005"></a>00005 <span class="comment">**  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 the</span>
<a name="l00008"></a>00008 <span class="comment">**  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 TorSettings.cpp</span>
<a name="l00013"></a>00013 <span class="comment">** \version $Id: TorSettings.cpp 3901 2009-06-27 01:57:05Z edmanm $</span>
<a name="l00014"></a>00014 <span class="comment">** \brief Settings used for starting and running Tor</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_settings_8h.html">TorSettings.h</a>&quot;</span>
<a name="l00018"></a>00018 <span class="preprocessor">#include &quot;<a class="code" href="_vidalia_8h.html">Vidalia.h</a>&quot;</span>
<a name="l00019"></a>00019 <span class="preprocessor">#include &quot;<a class="code" href="crypto_8h.html">crypto.h</a>&quot;</span>
<a name="l00020"></a>00020 <span class="preprocessor">#include &quot;<a class="code" href="file_8h.html">file.h</a>&quot;</span>
<a name="l00021"></a>00021 <span class="preprocessor">#include &quot;<a class="code" href="stringutil_8h.html">stringutil.h</a>&quot;</span>
<a name="l00022"></a>00022 <span class="preprocessor">#if defined(Q_OS_WIN32)</span>
<a name="l00023"></a>00023 <span class="preprocessor"></span><span class="preprocessor">#include &quot;<a class="code" href="win32_8h.html">win32.h</a>&quot;</span>
<a name="l00024"></a>00024 <span class="preprocessor">#include &lt;QFileInfo&gt;</span>
<a name="l00025"></a>00025 <span class="preprocessor">#endif</span>
<a name="l00026"></a>00026 <span class="preprocessor"></span>
<a name="l00027"></a>00027 <span class="preprocessor">#include &lt;QDir&gt;</span>
<a name="l00028"></a>00028 <span class="preprocessor">#include &lt;QProcess&gt;</span>
<a name="l00029"></a>00029 
<a name="l00030"></a>00030 <span class="comment">/* Tor Settings */</span>
<a name="l00031"></a><a class="code" href="_tor_settings_8cpp.html#a9f7343419389991f3445eea235746f45">00031</a> <span class="preprocessor">#define SETTING_TOR_EXECUTABLE      &quot;TorExecutable&quot;</span>
<a name="l00032"></a><a class="code" href="_tor_settings_8cpp.html#a7ebfd003f1ce02b50e961ed6ec5632ab">00032</a> <span class="preprocessor"></span><span class="preprocessor">#define SETTING_TORRC               &quot;Torrc&quot;</span>
<a name="l00033"></a><a class="code" href="_tor_settings_8cpp.html#aabf618cf77520f98c0874d7a80966e26">00033</a> <span class="preprocessor"></span><span class="preprocessor">#define SETTING_CONTROL_ADDR        &quot;ControlAddr&quot;</span>
<a name="l00034"></a><a class="code" href="_tor_settings_8cpp.html#a7efc6558b1a63f25f0b8c967bd5b3a5c">00034</a> <span class="preprocessor"></span><span class="preprocessor">#define SETTING_CONTROL_PORT        &quot;ControlPort&quot;</span>
<a name="l00035"></a><a class="code" href="_tor_settings_8cpp.html#a2164d490b9bbc4fcaa62c8eaab69ba10">00035</a> <span class="preprocessor"></span><span class="preprocessor">#define SETTING_AUTH_TOKEN          &quot;AuthToken&quot;</span>
<a name="l00036"></a><a class="code" href="_tor_settings_8cpp.html#a46e49fa8ef322ecbb6f80e21e7b41e60">00036</a> <span class="preprocessor"></span><span class="preprocessor">#define SETTING_TOR_USER            &quot;User&quot;</span>
<a name="l00037"></a><a class="code" href="_tor_settings_8cpp.html#aa69096ef7cee7a639dc377c0d30a87a0">00037</a> <span class="preprocessor"></span><span class="preprocessor">#define SETTING_TOR_GROUP           &quot;Group&quot;</span>
<a name="l00038"></a><a class="code" href="_tor_settings_8cpp.html#ad622f96474d39ed9634cb9424f25ca4b">00038</a> <span class="preprocessor"></span><span class="preprocessor">#define SETTING_DATA_DIRECTORY      &quot;DataDirectory&quot;</span>
<a name="l00039"></a><a class="code" href="_tor_settings_8cpp.html#acb286e7bc8db0ced255aa1c37b63d35d">00039</a> <span class="preprocessor"></span><span class="preprocessor">#define SETTING_AUTH_METHOD         &quot;AuthenticationMethod&quot;</span>
<a name="l00040"></a><a class="code" href="_tor_settings_8cpp.html#a6c1f94111e36e46c1af8b7d0d9655be2">00040</a> <span class="preprocessor"></span><span class="preprocessor">#define SETTING_CONTROL_PASSWORD    &quot;ControlPassword&quot;</span>
<a name="l00041"></a><a class="code" href="_tor_settings_8cpp.html#a0cf27e12bd3d0e16be94d94ecee286de">00041</a> <span class="preprocessor"></span><span class="preprocessor">#define SETTING_USE_RANDOM_PASSWORD &quot;UseRandomPassword&quot;</span>
<a name="l00042"></a><a class="code" href="_tor_settings_8cpp.html#a402f780bef956a4dfbb4908a00ee6663">00042</a> <span class="preprocessor"></span><span class="preprocessor">#define SETTING_WARN_PLAINTEXT_PORTS    &quot;WarnPlaintextPorts&quot;</span>
<a name="l00043"></a><a class="code" href="_tor_settings_8cpp.html#a0ea3b301f39a6253729c02eb41b4909d">00043</a> <span class="preprocessor"></span><span class="preprocessor">#define SETTING_REJECT_PLAINTEXT_PORTS  &quot;RejectPlaintextPorts&quot;</span>
<a name="l00044"></a>00044 <span class="preprocessor"></span><span class="comment"></span>
<a name="l00045"></a>00045 <span class="comment">/** Default to using hashed password authentication */</span>
<a name="l00046"></a><a class="code" href="_tor_settings_8cpp.html#ae7a03e40ee64f8c30a6b3993491ecbb7">00046</a> <span class="preprocessor">#define DEFAULT_AUTH_METHOD     PasswordAuth</span>
<a name="l00047"></a>00047 <span class="preprocessor"></span>
<a name="l00048"></a>00048 <span class="comment">/* Arguments we can pass to Tor on the command-line */</span>
<a name="l00049"></a><a class="code" href="_tor_settings_8cpp.html#ac05aac75dd4b6755649cf72ce308e627">00049</a> <span class="preprocessor">#define TOR_ARG_CONTROL_PORT    &quot;ControlPort&quot;</span>
<a name="l00050"></a><a class="code" href="_tor_settings_8cpp.html#a63b4c1ba9287402586d88d2d7b0a089e">00050</a> <span class="preprocessor"></span><span class="preprocessor">#define TOR_ARG_TORRC           &quot;-f&quot;</span>
<a name="l00051"></a><a class="code" href="_tor_settings_8cpp.html#a501170b1e2c3c7ea9ff2f220a81d260e">00051</a> <span class="preprocessor"></span><span class="preprocessor">#define TOR_ARG_DATA_DIRECTORY  &quot;DataDirectory&quot;</span>
<a name="l00052"></a><a class="code" href="_tor_settings_8cpp.html#a22efa30bbbf8617886fa71b1f8af0017">00052</a> <span class="preprocessor"></span><span class="preprocessor">#define TOR_ARG_HASHED_PASSWORD &quot;HashedControlPassword&quot;</span>
<a name="l00053"></a><a class="code" href="_tor_settings_8cpp.html#a80b05fa583c336c4ec8f20dfefe268f5">00053</a> <span class="preprocessor"></span><span class="preprocessor">#define TOR_ARG_COOKIE_AUTH     &quot;CookieAuthentication&quot;</span>
<a name="l00054"></a>00054 <span class="preprocessor"></span><span class="comment"></span>
<a name="l00055"></a>00055 <span class="comment">/** Generate random control passwords of 16 characters */</span>
<a name="l00056"></a><a class="code" href="_tor_settings_8cpp.html#a0fe437f408e254d25bd93c55b2a17371">00056</a> <span class="preprocessor">#define PASSWORD_LEN    16</span>
<a name="l00057"></a>00057 <span class="preprocessor"></span>
<a name="l00058"></a>00058 <span class="comment"></span>
<a name="l00059"></a>00059 <span class="comment">/** Default constructor */</span>
<a name="l00060"></a><a class="code" href="class_tor_settings.html#a3187309dd009d5584d240a596397e665">00060</a> <a class="code" href="class_tor_settings.html#a3187309dd009d5584d240a596397e665">TorSettings::TorSettings</a>(<a class="code" href="class_tor_control.html">TorControl</a> *torControl)
<a name="l00061"></a>00061 : <a class="code" href="class_abstract_tor_settings.html">AbstractTorSettings</a>(<span class="stringliteral">&quot;Tor&quot;</span>, torControl)
<a name="l00062"></a>00062 {
<a name="l00063"></a>00063 <span class="preprocessor">#if defined(Q_OS_WIN32)</span>
<a name="l00064"></a>00064 <span class="preprocessor"></span>  QString programFiles = <a class="code" href="win32_8cpp.html#a5ef88e21c0f27849306e01326118f477">win32_program_files_folder</a>();
<a name="l00065"></a>00065   <span class="keywordflow">if</span> (QFileInfo(programFiles + <span class="stringliteral">&quot;\\Vidalia Bundle\\Tor\\tor.exe&quot;</span>).exists())
<a name="l00066"></a>00066     <a class="code" href="class_v_settings.html#aebcf7105467fb91077fbb4470fcf9624">setDefault</a>(<a class="code" href="_tor_settings_8cpp.html#a9f7343419389991f3445eea235746f45">SETTING_TOR_EXECUTABLE</a>,
<a name="l00067"></a>00067                programFiles + <span class="stringliteral">&quot;\\Vidalia Bundle\\Tor\\tor.exe&quot;</span>);
<a name="l00068"></a>00068   <span class="keywordflow">else</span>
<a name="l00069"></a>00069     <a class="code" href="class_v_settings.html#aebcf7105467fb91077fbb4470fcf9624">setDefault</a>(<a class="code" href="_tor_settings_8cpp.html#a9f7343419389991f3445eea235746f45">SETTING_TOR_EXECUTABLE</a>, programFiles + <span class="stringliteral">&quot;\\Tor\\tor.exe&quot;</span>);
<a name="l00070"></a>00070 <span class="preprocessor">#else</span>
<a name="l00071"></a>00071 <span class="preprocessor"></span>  <a class="code" href="class_v_settings.html#aebcf7105467fb91077fbb4470fcf9624">setDefault</a>(<a class="code" href="_tor_settings_8cpp.html#a9f7343419389991f3445eea235746f45">SETTING_TOR_EXECUTABLE</a>, <span class="stringliteral">&quot;/usr/bin/tor&quot;</span>);
<a name="l00072"></a>00072 <span class="preprocessor">#endif</span>
<a name="l00073"></a>00073 <span class="preprocessor"></span>
<a name="l00074"></a>00074   <a class="code" href="class_v_settings.html#aebcf7105467fb91077fbb4470fcf9624">setDefault</a>(<a class="code" href="_tor_settings_8cpp.html#a7ebfd003f1ce02b50e961ed6ec5632ab">SETTING_TORRC</a>,         <span class="stringliteral">&quot;/etc/tor/torrc&quot;</span>);
<a name="l00075"></a>00075   <a class="code" href="class_v_settings.html#aebcf7105467fb91077fbb4470fcf9624">setDefault</a>(<a class="code" href="_tor_settings_8cpp.html#aabf618cf77520f98c0874d7a80966e26">SETTING_CONTROL_ADDR</a>,  <span class="stringliteral">&quot;127.0.0.1&quot;</span>);
<a name="l00076"></a>00076   <a class="code" href="class_v_settings.html#aebcf7105467fb91077fbb4470fcf9624">setDefault</a>(<a class="code" href="_tor_settings_8cpp.html#a7efc6558b1a63f25f0b8c967bd5b3a5c">SETTING_CONTROL_PORT</a>,  9051);
<a name="l00077"></a>00077   <a class="code" href="class_v_settings.html#aebcf7105467fb91077fbb4470fcf9624">setDefault</a>(<a class="code" href="_tor_settings_8cpp.html#acb286e7bc8db0ced255aa1c37b63d35d">SETTING_AUTH_METHOD</a>,   <a class="code" href="class_tor_settings.html#a59134577115f65c2c36f787c1b918aee">toString</a>(<a class="code" href="_tor_settings_8cpp.html#ae7a03e40ee64f8c30a6b3993491ecbb7">DEFAULT_AUTH_METHOD</a>));
<a name="l00078"></a>00078   <a class="code" href="class_v_settings.html#aebcf7105467fb91077fbb4470fcf9624">setDefault</a>(<a class="code" href="_tor_settings_8cpp.html#ad622f96474d39ed9634cb9424f25ca4b">SETTING_DATA_DIRECTORY</a>, <span class="stringliteral">&quot;/var/lib/tor&quot;</span>);
<a name="l00079"></a>00079   <a class="code" href="class_v_settings.html#aebcf7105467fb91077fbb4470fcf9624">setDefault</a>(<a class="code" href="_tor_settings_8cpp.html#a6c1f94111e36e46c1af8b7d0d9655be2">SETTING_CONTROL_PASSWORD</a>, <span class="stringliteral">&quot;&quot;</span>);
<a name="l00080"></a>00080   <a class="code" href="class_v_settings.html#aebcf7105467fb91077fbb4470fcf9624">setDefault</a>(<a class="code" href="_tor_settings_8cpp.html#a0cf27e12bd3d0e16be94d94ecee286de">SETTING_USE_RANDOM_PASSWORD</a>, <span class="keyword">true</span>);
<a name="l00081"></a>00081   <a class="code" href="class_v_settings.html#aebcf7105467fb91077fbb4470fcf9624">setDefault</a>(<a class="code" href="_tor_settings_8cpp.html#a402f780bef956a4dfbb4908a00ee6663">SETTING_WARN_PLAINTEXT_PORTS</a>, QList&lt;QVariant&gt;() &lt;&lt; 23 &lt;&lt; 109 
<a name="l00082"></a>00082                                                              &lt;&lt; 110 &lt;&lt; 143);
<a name="l00083"></a>00083   <a class="code" href="class_v_settings.html#aebcf7105467fb91077fbb4470fcf9624">setDefault</a>(<a class="code" href="_tor_settings_8cpp.html#a0ea3b301f39a6253729c02eb41b4909d">SETTING_REJECT_PLAINTEXT_PORTS</a>, QList&lt;QVariant&gt;());
<a name="l00084"></a>00084 }
<a name="l00085"></a>00085 <span class="comment"></span>
<a name="l00086"></a>00086 <span class="comment">/** Applies any changes to Tor&#39;s control port or authentication settings. */</span>
<a name="l00087"></a>00087 <span class="keywordtype">bool</span>
<a name="l00088"></a><a class="code" href="class_tor_settings.html#a0a8dd224241ffbc4daa24f831602380a">00088</a> <a class="code" href="class_tor_settings.html#a0a8dd224241ffbc4daa24f831602380a">TorSettings::apply</a>(QString *errmsg)
<a name="l00089"></a>00089 {
<a name="l00090"></a>00090   QHash&lt;QString, QString&gt; conf;
<a name="l00091"></a>00091   QString hashedPassword;
<a name="l00092"></a>00092 
<a name="l00093"></a>00093   conf.insert(<a class="code" href="_tor_settings_8cpp.html#a7efc6558b1a63f25f0b8c967bd5b3a5c">SETTING_CONTROL_PORT</a>,
<a name="l00094"></a>00094               <a class="code" href="class_abstract_tor_settings.html#a169f730fd477acb8f61cb5cf1026204f">localValue</a>(<a class="code" href="_tor_settings_8cpp.html#a7efc6558b1a63f25f0b8c967bd5b3a5c">SETTING_CONTROL_PORT</a>).<a class="code" href="class_tor_settings.html#a59134577115f65c2c36f787c1b918aee">toString</a>());
<a name="l00095"></a>00095   
<a name="l00096"></a>00096   <a class="code" href="class_tor_settings.html#a6b7351447aa44b7f19761e14544beff1">AuthenticationMethod</a> authMethod = 
<a name="l00097"></a>00097     <a class="code" href="class_tor_settings.html#a1b4a2453121cf03eacf4ae0fe72a9c17">toAuthenticationMethod</a>(<a class="code" href="class_abstract_tor_settings.html#a169f730fd477acb8f61cb5cf1026204f">localValue</a>(<a class="code" href="_tor_settings_8cpp.html#acb286e7bc8db0ced255aa1c37b63d35d">SETTING_AUTH_METHOD</a>).<a class="code" href="class_tor_settings.html#a59134577115f65c2c36f787c1b918aee">toString</a>());
<a name="l00098"></a>00098   <span class="keywordflow">switch</span> (authMethod) {
<a name="l00099"></a>00099     <span class="keywordflow">case</span> <a class="code" href="class_tor_settings.html#a6b7351447aa44b7f19761e14544beff1a435fe035b1a8fd9c131d67e94ee37fe8">CookieAuth</a>:
<a name="l00100"></a>00100       conf.insert(<a class="code" href="_tor_settings_8cpp.html#a80b05fa583c336c4ec8f20dfefe268f5">TOR_ARG_COOKIE_AUTH</a>,    <span class="stringliteral">&quot;1&quot;</span>);
<a name="l00101"></a>00101       conf.insert(<a class="code" href="_tor_settings_8cpp.html#a22efa30bbbf8617886fa71b1f8af0017">TOR_ARG_HASHED_PASSWORD</a>, <span class="stringliteral">&quot;&quot;</span>);
<a name="l00102"></a>00102       <span class="keywordflow">break</span>;
<a name="l00103"></a>00103     <span class="keywordflow">case</span> <a class="code" href="class_tor_settings.html#a6b7351447aa44b7f19761e14544beff1ae49465a79f8372aba78a866ef2502a3e">PasswordAuth</a>:
<a name="l00104"></a>00104       hashedPassword = <a class="code" href="class_tor_settings.html#aca0acbd8f89e1f5e6325dbb1ac2ea125">useRandomPassword</a>() 
<a name="l00105"></a>00105                           ? <a class="code" href="class_tor_settings.html#afb3a530555b3eaa1c9cb47b2ad3eb62d">hashPassword</a>(<a class="code" href="class_tor_settings.html#a1cc2e9149f5840a8b81a99f6710c4b00">randomPassword</a>())
<a name="l00106"></a>00106                           : <a class="code" href="class_tor_settings.html#afb3a530555b3eaa1c9cb47b2ad3eb62d">hashPassword</a>(<a class="code" href="class_tor_settings.html#a28dccb2d34d4dff1a808f7573c001d18">getControlPassword</a>());
<a name="l00107"></a>00107       <span class="keywordflow">if</span> (hashedPassword.isEmpty()) {
<a name="l00108"></a>00108         <span class="keywordflow">if</span> (errmsg)
<a name="l00109"></a>00109           *errmsg =  tr(<span class="stringliteral">&quot;Failed to hash the control password.&quot;</span>);
<a name="l00110"></a>00110         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00111"></a>00111       }
<a name="l00112"></a>00112       conf.insert(<a class="code" href="_tor_settings_8cpp.html#a80b05fa583c336c4ec8f20dfefe268f5">TOR_ARG_COOKIE_AUTH</a>,    <span class="stringliteral">&quot;0&quot;</span>);
<a name="l00113"></a>00113       conf.insert(<a class="code" href="_tor_settings_8cpp.html#a22efa30bbbf8617886fa71b1f8af0017">TOR_ARG_HASHED_PASSWORD</a>, hashedPassword);
<a name="l00114"></a>00114       <span class="keywordflow">break</span>;
<a name="l00115"></a>00115     <span class="keywordflow">default</span>:
<a name="l00116"></a>00116       conf.insert(<a class="code" href="_tor_settings_8cpp.html#a80b05fa583c336c4ec8f20dfefe268f5">TOR_ARG_COOKIE_AUTH</a>,    <span class="stringliteral">&quot;0&quot;</span>);
<a name="l00117"></a>00117       conf.insert(<a class="code" href="_tor_settings_8cpp.html#a22efa30bbbf8617886fa71b1f8af0017">TOR_ARG_HASHED_PASSWORD</a>, <span class="stringliteral">&quot;&quot;</span>);
<a name="l00118"></a>00118   }
<a name="l00119"></a>00119 
<a name="l00120"></a>00120   conf.insert(<a class="code" href="_tor_settings_8cpp.html#a402f780bef956a4dfbb4908a00ee6663">SETTING_WARN_PLAINTEXT_PORTS</a>,
<a name="l00121"></a>00121               <a class="code" href="class_abstract_tor_settings.html#a169f730fd477acb8f61cb5cf1026204f">localValue</a>(<a class="code" href="_tor_settings_8cpp.html#a402f780bef956a4dfbb4908a00ee6663">SETTING_WARN_PLAINTEXT_PORTS</a>).toStringList().join(<span class="stringliteral">&quot;,&quot;</span>));
<a name="l00122"></a>00122   conf.insert(<a class="code" href="_tor_settings_8cpp.html#a0ea3b301f39a6253729c02eb41b4909d">SETTING_REJECT_PLAINTEXT_PORTS</a>,
<a name="l00123"></a>00123               <a class="code" href="class_abstract_tor_settings.html#a169f730fd477acb8f61cb5cf1026204f">localValue</a>(<a class="code" href="_tor_settings_8cpp.html#a0ea3b301f39a6253729c02eb41b4909d">SETTING_REJECT_PLAINTEXT_PORTS</a>).toStringList().join(<span class="stringliteral">&quot;,&quot;</span>));
<a name="l00124"></a>00124 
<a name="l00125"></a>00125   <span class="keywordflow">return</span> <a class="code" href="class_abstract_tor_settings.html#a1fd0bb636bfa8131f6261b1bc11aeee4">torControl</a>()-&gt;<a class="code" href="class_tor_control.html#acd33beb0663b2a464a101c4efb425708">setConf</a>(conf, errmsg);
<a name="l00126"></a>00126 }
<a name="l00127"></a>00127 <span class="comment"></span>
<a name="l00128"></a>00128 <span class="comment">/** Gets the location of Tor&#39;s data directory. */</span>
<a name="l00129"></a>00129 QString
<a name="l00130"></a><a class="code" href="class_tor_settings.html#ad633bcf9223274b69a2b47cbf6299564">00130</a> <a class="code" href="class_tor_settings.html#ad633bcf9223274b69a2b47cbf6299564">TorSettings::getDataDirectory</a>()<span class="keyword"> const</span>
<a name="l00131"></a>00131 <span class="keyword"></span>{
<a name="l00132"></a>00132   <span class="keywordflow">return</span> QDir::convertSeparators(<a class="code" href="class_abstract_tor_settings.html#a6c2c0255bf7d89a14f1ad9ebdd6bf2ef">value</a>(<a class="code" href="_tor_settings_8cpp.html#ad622f96474d39ed9634cb9424f25ca4b">SETTING_DATA_DIRECTORY</a>).<a class="code" href="class_tor_settings.html#a59134577115f65c2c36f787c1b918aee">toString</a>());
<a name="l00133"></a>00133 }
<a name="l00134"></a>00134 <span class="comment"></span>
<a name="l00135"></a>00135 <span class="comment">/** Sets the location to use as Tor&#39;s data directory. */</span>
<a name="l00136"></a>00136 <span class="keywordtype">void</span>
<a name="l00137"></a><a class="code" href="class_tor_settings.html#ac07ec00839f3c07dc1c3064d0bb089fe">00137</a> <a class="code" href="class_tor_settings.html#ac07ec00839f3c07dc1c3064d0bb089fe">TorSettings::setDataDirectory</a>(<span class="keyword">const</span> QString &amp;dataDirectory)
<a name="l00138"></a>00138 {
<a name="l00139"></a>00139   <a class="code" href="class_abstract_tor_settings.html#a29b7abc52f7dfcb1453aafa28f902789">setValue</a>(<a class="code" href="_tor_settings_8cpp.html#ad622f96474d39ed9634cb9424f25ca4b">SETTING_DATA_DIRECTORY</a>, dataDirectory);
<a name="l00140"></a>00140 }
<a name="l00141"></a>00141 <span class="comment"></span>
<a name="l00142"></a>00142 <span class="comment">/** Returns a fully-qualified path to Tor&#39;s executable, including the</span>
<a name="l00143"></a>00143 <span class="comment"> * executable name. */</span>
<a name="l00144"></a>00144 QString
<a name="l00145"></a><a class="code" href="class_tor_settings.html#ae2a2125f7135926245a68ed1a9c59f91">00145</a> <a class="code" href="class_tor_settings.html#ae2a2125f7135926245a68ed1a9c59f91">TorSettings::getExecutable</a>()<span class="keyword"> const</span>
<a name="l00146"></a>00146 <span class="keyword"></span>{
<a name="l00147"></a>00147   QString tor = <a class="code" href="class_abstract_tor_settings.html#a169f730fd477acb8f61cb5cf1026204f">localValue</a>(<a class="code" href="_tor_settings_8cpp.html#a9f7343419389991f3445eea235746f45">SETTING_TOR_EXECUTABLE</a>).toString();
<a name="l00148"></a>00148   <span class="keywordflow">if</span> (tor.isEmpty()) <span class="comment">/* Don&#39;t let the Tor executable name be empty */</span>
<a name="l00149"></a>00149     tor = <a class="code" href="class_v_settings.html#a76db82d5e923b9710c9318b50bd6ad67">defaultValue</a>(<a class="code" href="_tor_settings_8cpp.html#a9f7343419389991f3445eea235746f45">SETTING_TOR_EXECUTABLE</a>).toString();
<a name="l00150"></a>00150   <span class="keywordflow">return</span> QDir::convertSeparators(tor);
<a name="l00151"></a>00151 }
<a name="l00152"></a>00152 <span class="comment"></span>
<a name="l00153"></a>00153 <span class="comment">/** Sets the location and name of Tor&#39;s executable to the given string. */</span>
<a name="l00154"></a>00154 <span class="keywordtype">void</span>
<a name="l00155"></a><a class="code" href="class_tor_settings.html#ae175fe3932319cb2a2fe6c1f7036bd26">00155</a> <a class="code" href="class_tor_settings.html#ae175fe3932319cb2a2fe6c1f7036bd26">TorSettings::setExecutable</a>(<span class="keyword">const</span> QString &amp;torExecutable)
<a name="l00156"></a>00156 {
<a name="l00157"></a>00157   <a class="code" href="class_abstract_tor_settings.html#a29b7abc52f7dfcb1453aafa28f902789">setValue</a>(<a class="code" href="_tor_settings_8cpp.html#a9f7343419389991f3445eea235746f45">SETTING_TOR_EXECUTABLE</a>, torExecutable);
<a name="l00158"></a>00158 }
<a name="l00159"></a>00159 <span class="comment"></span>
<a name="l00160"></a>00160 <span class="comment">/** Returns the torrc that will be used when starting Tor. */</span>
<a name="l00161"></a>00161 QString
<a name="l00162"></a><a class="code" href="class_tor_settings.html#a7a4536abf52cdfd8aa505b37b07c7812">00162</a> <a class="code" href="class_tor_settings.html#a7a4536abf52cdfd8aa505b37b07c7812">TorSettings::getTorrc</a>()<span class="keyword"> const</span>
<a name="l00163"></a>00163 <span class="keyword"></span>{
<a name="l00164"></a>00164   QString torrc;
<a name="l00165"></a>00165   <a class="code" href="class_tor_control.html">TorControl</a> *tc = <a class="code" href="class_abstract_tor_settings.html#a1fd0bb636bfa8131f6261b1bc11aeee4">torControl</a>();
<a name="l00166"></a>00166   <span class="keywordflow">if</span> (tc &amp;&amp; tc-&gt;<a class="code" href="class_tor_control.html#a5e39e327ca6c4ef5b4e2ce770a81a59f">isConnected</a>() &amp;&amp; tc-&gt;<a class="code" href="class_tor_control.html#a7bb6236b41505b30e8708c9f5cf8e8f7">getInfo</a>(<span class="stringliteral">&quot;config-file&quot;</span>, torrc))
<a name="l00167"></a>00167     <span class="keywordflow">return</span> QDir::convertSeparators(torrc);
<a name="l00168"></a>00168   <span class="keywordflow">return</span> QDir::convertSeparators(<a class="code" href="class_abstract_tor_settings.html#a169f730fd477acb8f61cb5cf1026204f">localValue</a>(<a class="code" href="_tor_settings_8cpp.html#a7ebfd003f1ce02b50e961ed6ec5632ab">SETTING_TORRC</a>).<a class="code" href="class_tor_settings.html#a59134577115f65c2c36f787c1b918aee">toString</a>());
<a name="l00169"></a>00169 }
<a name="l00170"></a>00170 <span class="comment"></span>
<a name="l00171"></a>00171 <span class="comment">/** Sets the torrc that will be used when starting Tor.</span>
<a name="l00172"></a>00172 <span class="comment"> * \param torrc The torrc to use. </span>
<a name="l00173"></a>00173 <span class="comment"> */</span>
<a name="l00174"></a>00174 <span class="keywordtype">void</span>
<a name="l00175"></a><a class="code" href="class_tor_settings.html#a8abb7f9f1b23f7bee7a4c74e3f8977bf">00175</a> <a class="code" href="class_tor_settings.html#a8abb7f9f1b23f7bee7a4c74e3f8977bf">TorSettings::setTorrc</a>(<span class="keyword">const</span> QString &amp;torrc)
<a name="l00176"></a>00176 {
<a name="l00177"></a>00177   <a class="code" href="class_abstract_tor_settings.html#a29b7abc52f7dfcb1453aafa28f902789">setValue</a>(<a class="code" href="_tor_settings_8cpp.html#a7ebfd003f1ce02b50e961ed6ec5632ab">SETTING_TORRC</a>, torrc);
<a name="l00178"></a>00178 }
<a name="l00179"></a>00179 <span class="comment"></span>
<a name="l00180"></a>00180 <span class="comment">/** Get the address or hostname used to connect to Tor */</span>
<a name="l00181"></a>00181 QHostAddress
<a name="l00182"></a><a class="code" href="class_tor_settings.html#a8c8e7b8fdfcf66b296027699be9df8c0">00182</a> <a class="code" href="class_tor_settings.html#a8c8e7b8fdfcf66b296027699be9df8c0">TorSettings::getControlAddress</a>()<span class="keyword"> const</span>
<a name="l00183"></a>00183 <span class="keyword"></span>{
<a name="l00184"></a>00184   QString addr = <a class="code" href="class_abstract_tor_settings.html#a169f730fd477acb8f61cb5cf1026204f">localValue</a>(<a class="code" href="_tor_settings_8cpp.html#aabf618cf77520f98c0874d7a80966e26">SETTING_CONTROL_ADDR</a>).toString();
<a name="l00185"></a>00185   <span class="keywordflow">return</span> QHostAddress(addr);
<a name="l00186"></a>00186 }
<a name="l00187"></a>00187 <span class="comment"></span>
<a name="l00188"></a>00188 <span class="comment">/** Set the address or hostname used to connect to Tor */</span>
<a name="l00189"></a>00189 <span class="keywordtype">void</span>
<a name="l00190"></a><a class="code" href="class_tor_settings.html#a26f979b7e0a362d2ad07019e45b3c067">00190</a> <a class="code" href="class_tor_settings.html#a26f979b7e0a362d2ad07019e45b3c067">TorSettings::setControlAddress</a>(<span class="keyword">const</span> QHostAddress &amp;addr)
<a name="l00191"></a>00191 {
<a name="l00192"></a>00192   <a class="code" href="class_abstract_tor_settings.html#a29b7abc52f7dfcb1453aafa28f902789">setValue</a>(<a class="code" href="_tor_settings_8cpp.html#aabf618cf77520f98c0874d7a80966e26">SETTING_CONTROL_ADDR</a>, addr.toString());
<a name="l00193"></a>00193 }
<a name="l00194"></a>00194 <span class="comment"></span>
<a name="l00195"></a>00195 <span class="comment">/** Get the control port used to connect to Tor */</span>
<a name="l00196"></a>00196 quint16
<a name="l00197"></a><a class="code" href="class_tor_settings.html#ac56fca68ce51ed303554b14ab840fbe9">00197</a> <a class="code" href="class_tor_settings.html#ac56fca68ce51ed303554b14ab840fbe9">TorSettings::getControlPort</a>()<span class="keyword"> const</span>
<a name="l00198"></a>00198 <span class="keyword"></span>{
<a name="l00199"></a>00199   <span class="keywordflow">return</span> (quint16)<a class="code" href="class_abstract_tor_settings.html#a6c2c0255bf7d89a14f1ad9ebdd6bf2ef">value</a>(<a class="code" href="_tor_settings_8cpp.html#a7efc6558b1a63f25f0b8c967bd5b3a5c">SETTING_CONTROL_PORT</a>).toInt();
<a name="l00200"></a>00200 }
<a name="l00201"></a>00201 <span class="comment"></span>
<a name="l00202"></a>00202 <span class="comment">/** Set the control port used to connect to Tor */</span>
<a name="l00203"></a>00203 <span class="keywordtype">void</span>
<a name="l00204"></a><a class="code" href="class_tor_settings.html#ac68423d0544dc204766d8d7560e1cc9b">00204</a> <a class="code" href="class_tor_settings.html#ac68423d0544dc204766d8d7560e1cc9b">TorSettings::setControlPort</a>(quint16 port)
<a name="l00205"></a>00205 {
<a name="l00206"></a>00206   <a class="code" href="class_abstract_tor_settings.html#a29b7abc52f7dfcb1453aafa28f902789">setValue</a>(<a class="code" href="_tor_settings_8cpp.html#a7efc6558b1a63f25f0b8c967bd5b3a5c">SETTING_CONTROL_PORT</a>, port);
<a name="l00207"></a>00207 }
<a name="l00208"></a>00208 <span class="comment"></span>
<a name="l00209"></a>00209 <span class="comment">/** Returns the plaintext (i.e., not hashed) control password used when</span>
<a name="l00210"></a>00210 <span class="comment"> * authenticating to Tor. */</span>
<a name="l00211"></a>00211 QString
<a name="l00212"></a><a class="code" href="class_tor_settings.html#a28dccb2d34d4dff1a808f7573c001d18">00212</a> <a class="code" href="class_tor_settings.html#a28dccb2d34d4dff1a808f7573c001d18">TorSettings::getControlPassword</a>()<span class="keyword"> const</span>
<a name="l00213"></a>00213 <span class="keyword"></span>{
<a name="l00214"></a>00214   <span class="keywordflow">return</span> <a class="code" href="class_abstract_tor_settings.html#a169f730fd477acb8f61cb5cf1026204f">localValue</a>(<a class="code" href="_tor_settings_8cpp.html#a6c1f94111e36e46c1af8b7d0d9655be2">SETTING_CONTROL_PASSWORD</a>).toString();
<a name="l00215"></a>00215 }
<a name="l00216"></a>00216 <span class="comment"></span>
<a name="l00217"></a>00217 <span class="comment">/** Sets the control password used when starting Tor with</span>
<a name="l00218"></a>00218 <span class="comment"> * HashedControlPassword to &lt;b&gt;password&lt;/b&gt;. */</span>
<a name="l00219"></a>00219 <span class="keywordtype">void</span>
<a name="l00220"></a><a class="code" href="class_tor_settings.html#a0095d806557ebc89ff5e4c77a29da2f4">00220</a> <a class="code" href="class_tor_settings.html#a0095d806557ebc89ff5e4c77a29da2f4">TorSettings::setControlPassword</a>(<span class="keyword">const</span> QString &amp;password)
<a name="l00221"></a>00221 {
<a name="l00222"></a>00222   <a class="code" href="class_abstract_tor_settings.html#a29b7abc52f7dfcb1453aafa28f902789">setValue</a>(<a class="code" href="_tor_settings_8cpp.html#a6c1f94111e36e46c1af8b7d0d9655be2">SETTING_CONTROL_PASSWORD</a>, password);
<a name="l00223"></a>00223 }
<a name="l00224"></a>00224 <span class="comment"></span>
<a name="l00225"></a>00225 <span class="comment">/** Returns true if a new, random control password is to be used each time Tor</span>
<a name="l00226"></a>00226 <span class="comment"> * is started. */</span>
<a name="l00227"></a>00227 <span class="keywordtype">bool</span>
<a name="l00228"></a><a class="code" href="class_tor_settings.html#aca0acbd8f89e1f5e6325dbb1ac2ea125">00228</a> <a class="code" href="class_tor_settings.html#aca0acbd8f89e1f5e6325dbb1ac2ea125">TorSettings::useRandomPassword</a>()<span class="keyword"> const</span>
<a name="l00229"></a>00229 <span class="keyword"></span>{
<a name="l00230"></a>00230   <span class="keywordflow">return</span> <a class="code" href="class_abstract_tor_settings.html#a169f730fd477acb8f61cb5cf1026204f">localValue</a>(<a class="code" href="_tor_settings_8cpp.html#a0cf27e12bd3d0e16be94d94ecee286de">SETTING_USE_RANDOM_PASSWORD</a>).toBool();
<a name="l00231"></a>00231 }
<a name="l00232"></a>00232 <span class="comment"></span>
<a name="l00233"></a>00233 <span class="comment">/** Sets whether or not to generate and use a random control password each</span>
<a name="l00234"></a>00234 <span class="comment"> * time Tor is started. */</span>
<a name="l00235"></a>00235 <span class="keywordtype">void</span>
<a name="l00236"></a><a class="code" href="class_tor_settings.html#a12d6d3a7cee7e93c329ac821151017af">00236</a> <a class="code" href="class_tor_settings.html#a12d6d3a7cee7e93c329ac821151017af">TorSettings::setUseRandomPassword</a>(<span class="keywordtype">bool</span> useRandomPassword)
<a name="l00237"></a>00237 {
<a name="l00238"></a>00238   <a class="code" href="class_abstract_tor_settings.html#a29b7abc52f7dfcb1453aafa28f902789">setValue</a>(<a class="code" href="_tor_settings_8cpp.html#a0cf27e12bd3d0e16be94d94ecee286de">SETTING_USE_RANDOM_PASSWORD</a>, useRandomPassword);
<a name="l00239"></a>00239 }
<a name="l00240"></a>00240 <span class="comment"></span>
<a name="l00241"></a>00241 <span class="comment">/** Returns the current authentication method used when connecting to Tor. */</span>
<a name="l00242"></a>00242 <a class="code" href="class_tor_settings.html#a6b7351447aa44b7f19761e14544beff1">TorSettings::AuthenticationMethod</a>
<a name="l00243"></a><a class="code" href="class_tor_settings.html#a0f3b0120adc4431eb94191c32004c585">00243</a> <a class="code" href="class_tor_settings.html#a0f3b0120adc4431eb94191c32004c585">TorSettings::getAuthenticationMethod</a>()<span class="keyword"> const</span>
<a name="l00244"></a>00244 <span class="keyword"></span>{
<a name="l00245"></a>00245   <a class="code" href="class_tor_settings.html#a6b7351447aa44b7f19761e14544beff1">AuthenticationMethod</a> type = <a class="code" href="class_tor_settings.html#a6b7351447aa44b7f19761e14544beff1ae3a62a8ce6b202b54676c74df5de92de">UnknownAuth</a>;
<a name="l00246"></a>00246   <a class="code" href="class_tor_control.html">TorControl</a> *tc = <a class="code" href="class_abstract_tor_settings.html#a1fd0bb636bfa8131f6261b1bc11aeee4">torControl</a>();
<a name="l00247"></a>00247 
<a name="l00248"></a>00248   <span class="keywordflow">if</span> (tc &amp;&amp; tc-&gt;<a class="code" href="class_tor_control.html#a5e39e327ca6c4ef5b4e2ce770a81a59f">isConnected</a>()) {
<a name="l00249"></a>00249     QHash&lt;QString,QString&gt; conf;
<a name="l00250"></a>00250     conf.insert(<a class="code" href="_tor_settings_8cpp.html#a80b05fa583c336c4ec8f20dfefe268f5">TOR_ARG_COOKIE_AUTH</a>, <span class="stringliteral">&quot;&quot;</span>);
<a name="l00251"></a>00251     conf.insert(<a class="code" href="_tor_settings_8cpp.html#a22efa30bbbf8617886fa71b1f8af0017">TOR_ARG_HASHED_PASSWORD</a>, <span class="stringliteral">&quot;&quot;</span>);
<a name="l00252"></a>00252     <span class="keywordflow">if</span> (tc-&gt;<a class="code" href="class_tor_control.html#ace854634f48d61319bcfd73b134aeba1">getConf</a>(conf)) {
<a name="l00253"></a>00253       <span class="keywordflow">if</span> (conf.value(<a class="code" href="_tor_settings_8cpp.html#a80b05fa583c336c4ec8f20dfefe268f5">TOR_ARG_COOKIE_AUTH</a>) == <span class="stringliteral">&quot;1&quot;</span>)
<a name="l00254"></a>00254         type = <a class="code" href="class_tor_settings.html#a6b7351447aa44b7f19761e14544beff1a435fe035b1a8fd9c131d67e94ee37fe8">CookieAuth</a>;
<a name="l00255"></a>00255       <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!conf.value(<a class="code" href="_tor_settings_8cpp.html#a22efa30bbbf8617886fa71b1f8af0017">TOR_ARG_HASHED_PASSWORD</a>).isEmpty())
<a name="l00256"></a>00256         type = <a class="code" href="class_tor_settings.html#a6b7351447aa44b7f19761e14544beff1ae49465a79f8372aba78a866ef2502a3e">PasswordAuth</a>;
<a name="l00257"></a>00257     }
<a name="l00258"></a>00258   }
<a name="l00259"></a>00259   <span class="keywordflow">if</span> (type == <a class="code" href="class_tor_settings.html#a6b7351447aa44b7f19761e14544beff1ae3a62a8ce6b202b54676c74df5de92de">UnknownAuth</a>)
<a name="l00260"></a>00260     type = <a class="code" href="class_tor_settings.html#a1b4a2453121cf03eacf4ae0fe72a9c17">toAuthenticationMethod</a>(<a class="code" href="class_abstract_tor_settings.html#a169f730fd477acb8f61cb5cf1026204f">localValue</a>(<a class="code" href="_tor_settings_8cpp.html#acb286e7bc8db0ced255aa1c37b63d35d">SETTING_AUTH_METHOD</a>).<a class="code" href="class_tor_settings.html#a59134577115f65c2c36f787c1b918aee">toString</a>());
<a name="l00261"></a>00261   <span class="keywordflow">return</span> (type == <a class="code" href="class_tor_settings.html#a6b7351447aa44b7f19761e14544beff1ae3a62a8ce6b202b54676c74df5de92de">UnknownAuth</a> ? <a class="code" href="_tor_settings_8cpp.html#ae7a03e40ee64f8c30a6b3993491ecbb7">DEFAULT_AUTH_METHOD</a> : type);
<a name="l00262"></a>00262 }
<a name="l00263"></a>00263 <span class="comment"></span>
<a name="l00264"></a>00264 <span class="comment">/** Sets the authentication method used when starting Tor to &lt;b&gt;method&lt;/b&gt;. */</span>
<a name="l00265"></a>00265 <span class="keywordtype">void</span>
<a name="l00266"></a><a class="code" href="class_tor_settings.html#a8ff01f3a19743f26426819f80dd6ce57">00266</a> <a class="code" href="class_tor_settings.html#a8ff01f3a19743f26426819f80dd6ce57">TorSettings::setAuthenticationMethod</a>(<a class="code" href="class_tor_settings.html#a6b7351447aa44b7f19761e14544beff1">AuthenticationMethod</a> method)
<a name="l00267"></a>00267 {
<a name="l00268"></a>00268   <a class="code" href="class_abstract_tor_settings.html#a29b7abc52f7dfcb1453aafa28f902789">setValue</a>(<a class="code" href="_tor_settings_8cpp.html#acb286e7bc8db0ced255aa1c37b63d35d">SETTING_AUTH_METHOD</a>, <a class="code" href="class_tor_settings.html#a59134577115f65c2c36f787c1b918aee">toString</a>(method));
<a name="l00269"></a>00269 }
<a name="l00270"></a>00270 <span class="comment"></span>
<a name="l00271"></a>00271 <span class="comment">/** Returns the current list of ports that will cause Tor to issue a warning</span>
<a name="l00272"></a>00272 <span class="comment"> * when the user tries to connect to one of them. */</span>
<a name="l00273"></a>00273 QList&lt;quint16&gt;
<a name="l00274"></a><a class="code" href="class_tor_settings.html#ae341a44c8f55a8674119220af4d5e9e3">00274</a> <a class="code" href="class_tor_settings.html#ae341a44c8f55a8674119220af4d5e9e3">TorSettings::getWarnPlaintextPorts</a>()<span class="keyword"> const</span>
<a name="l00275"></a>00275 <span class="keyword"></span>{
<a name="l00276"></a>00276   QList&lt;quint16&gt; out;
<a name="l00277"></a>00277   QList&lt;QVariant&gt; ports;
<a name="l00278"></a>00278 
<a name="l00279"></a>00279   ports = <a class="code" href="class_abstract_tor_settings.html#a6c2c0255bf7d89a14f1ad9ebdd6bf2ef">value</a>(<a class="code" href="_tor_settings_8cpp.html#a402f780bef956a4dfbb4908a00ee6663">SETTING_WARN_PLAINTEXT_PORTS</a>).toList();
<a name="l00280"></a>00280   <span class="keywordflow">foreach</span> (QVariant port, ports) {
<a name="l00281"></a>00281     out &lt;&lt; port.toUInt();
<a name="l00282"></a>00282   }
<a name="l00283"></a>00283   <span class="keywordflow">return</span> out;
<a name="l00284"></a>00284 }
<a name="l00285"></a>00285 <span class="comment"></span>
<a name="l00286"></a>00286 <span class="comment">/** Sets the list of ports that will cause Tor to issue a warning when the</span>
<a name="l00287"></a>00287 <span class="comment"> * user tries to connect to one of them. */</span>
<a name="l00288"></a>00288 <span class="keywordtype">void</span>
<a name="l00289"></a><a class="code" href="class_tor_settings.html#ad216e21e84955a170f0bb463b8a133dd">00289</a> <a class="code" href="class_tor_settings.html#ad216e21e84955a170f0bb463b8a133dd">TorSettings::setWarnPlaintextPorts</a>(<span class="keyword">const</span> QList&lt;quint16&gt; &amp;ports)
<a name="l00290"></a>00290 {
<a name="l00291"></a>00291   QList&lt;QVariant&gt; warnList;
<a name="l00292"></a>00292   <span class="keywordflow">foreach</span> (quint16 port, ports) {
<a name="l00293"></a>00293     warnList &lt;&lt; QVariant(port);
<a name="l00294"></a>00294   }
<a name="l00295"></a>00295   <a class="code" href="class_abstract_tor_settings.html#a29b7abc52f7dfcb1453aafa28f902789">setValue</a>(<a class="code" href="_tor_settings_8cpp.html#a402f780bef956a4dfbb4908a00ee6663">SETTING_WARN_PLAINTEXT_PORTS</a>, warnList);
<a name="l00296"></a>00296 }
<a name="l00297"></a>00297 <span class="comment"></span>
<a name="l00298"></a>00298 <span class="comment">/** Returns the current list of ports that will cause Tor to reject the</span>
<a name="l00299"></a>00299 <span class="comment"> * connection when the user tries to connect to one of them. */</span>
<a name="l00300"></a>00300 QList&lt;quint16&gt;
<a name="l00301"></a><a class="code" href="class_tor_settings.html#a9016f8716785364ceeef6ee4b17358d4">00301</a> <a class="code" href="class_tor_settings.html#a9016f8716785364ceeef6ee4b17358d4">TorSettings::getRejectPlaintextPorts</a>()<span class="keyword"> const</span>
<a name="l00302"></a>00302 <span class="keyword"></span>{
<a name="l00303"></a>00303   QList&lt;quint16&gt; out;
<a name="l00304"></a>00304   QList&lt;QVariant&gt; ports;
<a name="l00305"></a>00305 
<a name="l00306"></a>00306   ports = <a class="code" href="class_abstract_tor_settings.html#a6c2c0255bf7d89a14f1ad9ebdd6bf2ef">value</a>(<a class="code" href="_tor_settings_8cpp.html#a0ea3b301f39a6253729c02eb41b4909d">SETTING_REJECT_PLAINTEXT_PORTS</a>).toList();
<a name="l00307"></a>00307   <span class="keywordflow">foreach</span> (QVariant port, ports) {
<a name="l00308"></a>00308     out &lt;&lt; port.toUInt();
<a name="l00309"></a>00309   }
<a name="l00310"></a>00310   <span class="keywordflow">return</span> out;
<a name="l00311"></a>00311 }
<a name="l00312"></a>00312 <span class="comment"></span>
<a name="l00313"></a>00313 <span class="comment">/** Sets the list of ports that will cause Tor to reject the connection</span>
<a name="l00314"></a>00314 <span class="comment"> * when the user tries to connect to one of them. */</span>
<a name="l00315"></a>00315 <span class="keywordtype">void</span>
<a name="l00316"></a><a class="code" href="class_tor_settings.html#ad02f4a3de3d45b4b8bd45d94057cd98e">00316</a> <a class="code" href="class_tor_settings.html#ad02f4a3de3d45b4b8bd45d94057cd98e">TorSettings::setRejectPlaintextPorts</a>(<span class="keyword">const</span> QList&lt;quint16&gt; &amp;ports)
<a name="l00317"></a>00317 {
<a name="l00318"></a>00318   QList&lt;QVariant&gt; rejectList;
<a name="l00319"></a>00319   <span class="keywordflow">foreach</span> (quint16 port, ports) {
<a name="l00320"></a>00320     rejectList &lt;&lt; QVariant(port);
<a name="l00321"></a>00321   }
<a name="l00322"></a>00322   <a class="code" href="class_abstract_tor_settings.html#a29b7abc52f7dfcb1453aafa28f902789">setValue</a>(<a class="code" href="_tor_settings_8cpp.html#a0ea3b301f39a6253729c02eb41b4909d">SETTING_REJECT_PLAINTEXT_PORTS</a>, rejectList);
<a name="l00323"></a>00323 }
<a name="l00324"></a>00324 <span class="comment"></span>
<a name="l00325"></a>00325 <span class="comment">/** Returns the string description of the authentication method specified by</span>
<a name="l00326"></a>00326 <span class="comment"> * &lt;b&gt;method&lt;/b&gt;. The authentication method string is stored in Vidalia&#39;s</span>
<a name="l00327"></a>00327 <span class="comment"> * configuration file. */</span>
<a name="l00328"></a>00328 QString
<a name="l00329"></a><a class="code" href="class_tor_settings.html#a59134577115f65c2c36f787c1b918aee">00329</a> <a class="code" href="class_tor_settings.html#a59134577115f65c2c36f787c1b918aee">TorSettings::toString</a>(<a class="code" href="class_tor_settings.html#a6b7351447aa44b7f19761e14544beff1">AuthenticationMethod</a> method)<span class="keyword"> const</span>
<a name="l00330"></a>00330 <span class="keyword"></span>{
<a name="l00331"></a>00331   <span class="keywordflow">switch</span> (method) {
<a name="l00332"></a>00332     <span class="keywordflow">case</span> <a class="code" href="class_tor_settings.html#a6b7351447aa44b7f19761e14544beff1a79d67ba56428df159a0def329d86b42d">NullAuth</a>:  <span class="keywordflow">return</span> <span class="stringliteral">&quot;none&quot;</span>;
<a name="l00333"></a>00333     <span class="keywordflow">case</span> <a class="code" href="class_tor_settings.html#a6b7351447aa44b7f19761e14544beff1ae49465a79f8372aba78a866ef2502a3e">PasswordAuth</a>:  <span class="keywordflow">return</span> <span class="stringliteral">&quot;password&quot;</span>;
<a name="l00334"></a>00334     <span class="keywordflow">case</span> <a class="code" href="class_tor_settings.html#a6b7351447aa44b7f19761e14544beff1a435fe035b1a8fd9c131d67e94ee37fe8">CookieAuth</a>:  <span class="keywordflow">return</span> <span class="stringliteral">&quot;cookie&quot;</span>;
<a name="l00335"></a>00335     <span class="keywordflow">default</span>: <span class="keywordflow">break</span>;
<a name="l00336"></a>00336   }
<a name="l00337"></a>00337   <span class="keywordflow">return</span> <span class="stringliteral">&quot;unknown&quot;</span>;
<a name="l00338"></a>00338 }
<a name="l00339"></a>00339 <span class="comment"></span>
<a name="l00340"></a>00340 <span class="comment">/** Returns the AuthenticationMethod enum value for the string</span>
<a name="l00341"></a>00341 <span class="comment"> * description of the authentication method given in &lt;b&gt;authMethod&lt;/b&gt;. */</span>
<a name="l00342"></a>00342 <a class="code" href="class_tor_settings.html#a6b7351447aa44b7f19761e14544beff1">TorSettings::AuthenticationMethod</a>
<a name="l00343"></a><a class="code" href="class_tor_settings.html#a1b4a2453121cf03eacf4ae0fe72a9c17">00343</a> <a class="code" href="class_tor_settings.html#a1b4a2453121cf03eacf4ae0fe72a9c17">TorSettings::toAuthenticationMethod</a>(<span class="keyword">const</span> QString &amp;authMethod)<span class="keyword"> const</span>
<a name="l00344"></a>00344 <span class="keyword"></span>{ 
<a name="l00345"></a>00345   QString str = authMethod.toLower();
<a name="l00346"></a>00346   <span class="keywordflow">if</span> (str == <a class="code" href="class_tor_settings.html#a59134577115f65c2c36f787c1b918aee">toString</a>(<a class="code" href="class_tor_settings.html#a6b7351447aa44b7f19761e14544beff1a79d67ba56428df159a0def329d86b42d">NullAuth</a>))
<a name="l00347"></a>00347     <span class="keywordflow">return</span> <a class="code" href="class_tor_settings.html#a6b7351447aa44b7f19761e14544beff1a79d67ba56428df159a0def329d86b42d">NullAuth</a>;
<a name="l00348"></a>00348   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (str == <a class="code" href="class_tor_settings.html#a59134577115f65c2c36f787c1b918aee">toString</a>(<a class="code" href="class_tor_settings.html#a6b7351447aa44b7f19761e14544beff1ae49465a79f8372aba78a866ef2502a3e">PasswordAuth</a>))
<a name="l00349"></a>00349     <span class="keywordflow">return</span> <a class="code" href="class_tor_settings.html#a6b7351447aa44b7f19761e14544beff1ae49465a79f8372aba78a866ef2502a3e">PasswordAuth</a>;
<a name="l00350"></a>00350   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (str == <a class="code" href="class_tor_settings.html#a59134577115f65c2c36f787c1b918aee">toString</a>(<a class="code" href="class_tor_settings.html#a6b7351447aa44b7f19761e14544beff1a435fe035b1a8fd9c131d67e94ee37fe8">CookieAuth</a>))
<a name="l00351"></a>00351     <span class="keywordflow">return</span> <a class="code" href="class_tor_settings.html#a6b7351447aa44b7f19761e14544beff1a435fe035b1a8fd9c131d67e94ee37fe8">CookieAuth</a>;
<a name="l00352"></a>00352   <span class="keywordflow">return</span> <a class="code" href="class_tor_settings.html#a6b7351447aa44b7f19761e14544beff1ae3a62a8ce6b202b54676c74df5de92de">UnknownAuth</a>;
<a name="l00353"></a>00353 }
<a name="l00354"></a>00354 <span class="comment"></span>
<a name="l00355"></a>00355 <span class="comment">/** Generates a random control password consisting of PASSWORD_LEN characters. */</span>
<a name="l00356"></a>00356 QString
<a name="l00357"></a><a class="code" href="class_tor_settings.html#a1cc2e9149f5840a8b81a99f6710c4b00">00357</a> <a class="code" href="class_tor_settings.html#a1cc2e9149f5840a8b81a99f6710c4b00">TorSettings::randomPassword</a>()
<a name="l00358"></a>00358 {
<a name="l00359"></a>00359   <span class="keywordflow">return</span> <a class="code" href="crypto_8cpp.html#ad16013efda05090adfc906af39e91b41">crypto_rand_string</a>(<a class="code" href="_tor_settings_8cpp.html#a0fe437f408e254d25bd93c55b2a17371">PASSWORD_LEN</a>);
<a name="l00360"></a>00360 }
<a name="l00361"></a>00361 <span class="comment"></span>
<a name="l00362"></a>00362 <span class="comment">/** Returns the hash of &lt;b&gt;password&lt;/b&gt; as given by the command &quot;tor</span>
<a name="l00363"></a>00363 <span class="comment"> * --hash-password foo&quot;. */</span>
<a name="l00364"></a>00364 QString
<a name="l00365"></a><a class="code" href="class_tor_settings.html#afb3a530555b3eaa1c9cb47b2ad3eb62d">00365</a> <a class="code" href="class_tor_settings.html#afb3a530555b3eaa1c9cb47b2ad3eb62d">TorSettings::hashPassword</a>(<span class="keyword">const</span> QString &amp;password)
<a name="l00366"></a>00366 {
<a name="l00367"></a>00367   QByteArray salt;
<a name="l00368"></a>00368   
<a name="l00369"></a>00369   <span class="comment">/* Generate an 8 octet salt value. Bail if we fail to generate enough</span>
<a name="l00370"></a>00370 <span class="comment">   * random bytes (unlikely). */</span>
<a name="l00371"></a>00371   <span class="keywordflow">while</span> (salt.size() &lt; 8) {
<a name="l00372"></a>00372     QByteArray bytes = <a class="code" href="crypto_8cpp.html#af199e3bfee1379c8a84f61681e41526c">crypto_rand_bytes</a>(8-salt.size());
<a name="l00373"></a>00373     <span class="keywordflow">if</span> (bytes.isNull())
<a name="l00374"></a>00374       <span class="keywordflow">return</span> QString();
<a name="l00375"></a>00375     salt.append(bytes);
<a name="l00376"></a>00376   }
<a name="l00377"></a>00377 
<a name="l00378"></a>00378   <span class="comment">/* Generate the salted hash of the specified password. 96 is the one-octet</span>
<a name="l00379"></a>00379 <span class="comment">   * RFC 2440 coded count value hardcoded into Tor. Specifies that we should</span>
<a name="l00380"></a>00380 <span class="comment">   * hash 64K worth of data. */</span>
<a name="l00381"></a>00381   QByteArray key = <a class="code" href="crypto_8cpp.html#ac51151077f12ea463acd49abe58870a2">crypto_secret_to_key</a>(password, salt, 96);
<a name="l00382"></a>00382   <span class="keywordflow">if</span> (key.isNull())
<a name="l00383"></a>00383     <span class="keywordflow">return</span> QString();
<a name="l00384"></a>00384   salt.append(96); <span class="comment">/* Append the coded count value to the salt */</span>
<a name="l00385"></a>00385 
<a name="l00386"></a>00386   <span class="comment">/* Convert the result to hexadecimal and put it in the format Tor wants. */</span>
<a name="l00387"></a>00387   <span class="keywordflow">return</span> QString(<span class="stringliteral">&quot;16:%1%2&quot;</span>).arg(<a class="code" href="stringutil_8cpp.html#a4d5ac084308fee41bcc66b9ed3754d8f">base16_encode</a>(salt))
<a name="l00388"></a>00388                            .arg(<a class="code" href="stringutil_8cpp.html#a4d5ac084308fee41bcc66b9ed3754d8f">base16_encode</a>(key));
<a name="l00389"></a>00389 }
<a name="l00390"></a>00390 
</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>