Sophie

Sophie

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

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: Circuit.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>Circuit.cpp</h1><a href="_circuit_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 Circuit.cpp</span>
<a name="l00013"></a>00013 <span class="comment">** \version $Id: Circuit.cpp 3735 2009-04-28 20:28:01Z edmanm $</span>
<a name="l00014"></a>00014 <span class="comment">** \brief Object representing a Tor circuit</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="tcglobal_8h.html">tcglobal.h</a>&quot;</span>
<a name="l00018"></a>00018 <span class="preprocessor">#include &quot;<a class="code" href="_circuit_8h.html">Circuit.h</a>&quot;</span>
<a name="l00019"></a>00019 
<a name="l00020"></a>00020 <span class="preprocessor">#include &lt;QStringList&gt;</span>
<a name="l00021"></a>00021 <span class="preprocessor">#include &lt;QRegExp&gt;</span>
<a name="l00022"></a>00022 
<a name="l00023"></a>00023 <span class="comment"></span>
<a name="l00024"></a>00024 <span class="comment">/** Default constructor. */</span>
<a name="l00025"></a><a class="code" href="class_circuit.html#a6a9c21735a28f1222797d71ece99521c">00025</a> <a class="code" href="class_circuit.html#a6a9c21735a28f1222797d71ece99521c">Circuit::Circuit</a>()
<a name="l00026"></a>00026 {
<a name="l00027"></a>00027   <a class="code" href="class_circuit.html#a470c834decedb2ae3f15b8774bae36b3">_status</a>  = <a class="code" href="class_circuit.html#ae831da69eb5ffd2af9f470d90c613d0aa8fc7fad3a4f3f006c763f50919d0921a">Unknown</a>;
<a name="l00028"></a>00028   <a class="code" href="class_circuit.html#a8b4f6ac4382c7beb4e431fd9977912b5">_isValid</a> = <span class="keyword">false</span>;
<a name="l00029"></a>00029 }
<a name="l00030"></a>00030 <span class="comment"></span>
<a name="l00031"></a>00031 <span class="comment">/** Parses the string given in Tor control protocol format for a circuit. The</span>
<a name="l00032"></a>00032 <span class="comment"> * format is:</span>
<a name="l00033"></a>00033 <span class="comment"> * </span>
<a name="l00034"></a>00034 <span class="comment"> *      CircuitID SP CircStatus [SP Path]</span>
<a name="l00035"></a>00035 <span class="comment"> *</span>
<a name="l00036"></a>00036 <span class="comment"> * If the status is &quot;LAUNCHED&quot;, the Path is empty. Server names in the path</span>
<a name="l00037"></a>00037 <span class="comment"> * must follow Tor&#39;s VERBOSE_NAMES format.</span>
<a name="l00038"></a>00038 <span class="comment"> */</span>
<a name="l00039"></a><a class="code" href="class_circuit.html#a5997686fc73e528393c1ba041c4d01c4">00039</a> <a class="code" href="class_circuit.html#a6a9c21735a28f1222797d71ece99521c">Circuit::Circuit</a>(<span class="keyword">const</span> QString &amp;circuit)
<a name="l00040"></a>00040 {
<a name="l00041"></a>00041   QStringList parts = circuit.split(<span class="stringliteral">&quot; &quot;</span>, QString::SkipEmptyParts);
<a name="l00042"></a>00042   <span class="keywordflow">if</span> (parts.size() &gt;= 2) {
<a name="l00043"></a>00043     <span class="comment">/* Get the circuit ID */</span>
<a name="l00044"></a>00044     <a class="code" href="class_circuit.html#ab3fa1786f61e0ca83f6d0209ae85b305">_circId</a> = parts.at(0);
<a name="l00045"></a>00045     <span class="keywordflow">if</span> (! <a class="code" href="class_circuit.html#a440c821a5d795deb029848a064d9f3fd">isValidCircuitId</a>(<a class="code" href="class_circuit.html#ab3fa1786f61e0ca83f6d0209ae85b305">_circId</a>))
<a name="l00046"></a>00046       <span class="keywordflow">goto</span> <a class="code" href="stringutil_8cpp.html#a6e3f242b28c9165146182aec25e351a3">err</a>;
<a name="l00047"></a>00047 
<a name="l00048"></a>00048     <span class="comment">/* Get the circuit status value */</span>
<a name="l00049"></a>00049     <a class="code" href="class_circuit.html#a470c834decedb2ae3f15b8774bae36b3">_status</a> = <a class="code" href="class_circuit.html#aa4a57b1e38c6502fc48e9a1d34092e5f">Circuit::toStatus</a>(parts.at(1));
<a name="l00050"></a>00050 
<a name="l00051"></a>00051     <span class="comment">/* Get the circuit path (list of routers) */</span>
<a name="l00052"></a>00052     <span class="keywordflow">if</span> (parts.size() &gt; 2 &amp;&amp; parts.at(2).startsWith(<span class="stringliteral">&quot;$&quot;</span>)) {
<a name="l00053"></a>00053       <span class="keywordflow">foreach</span> (QString hop, parts.at(2).split(<span class="stringliteral">&quot;,&quot;</span>)) {
<a name="l00054"></a>00054         QStringList parts = hop.split(QRegExp(<span class="stringliteral">&quot;[=~]&quot;</span>));
<a name="l00055"></a>00055         <span class="keywordflow">if</span> (parts.size() != 2)
<a name="l00056"></a>00056           <span class="keywordflow">goto</span> <a class="code" href="stringutil_8cpp.html#a6e3f242b28c9165146182aec25e351a3">err</a>;
<a name="l00057"></a>00057 
<a name="l00058"></a>00058         <a class="code" href="class_circuit.html#a2ef793cb7c1f1133d4a558a430998a94">_ids</a>   &lt;&lt; parts.at(0).mid(1);
<a name="l00059"></a>00059         <a class="code" href="class_circuit.html#a6b25d5c485ecbc67e31dfb8e8048c739">_names</a> &lt;&lt; parts.at(1);
<a name="l00060"></a>00060       }
<a name="l00061"></a>00061     }
<a name="l00062"></a>00062 
<a name="l00063"></a>00063     <a class="code" href="class_circuit.html#a8b4f6ac4382c7beb4e431fd9977912b5">_isValid</a> = <span class="keyword">true</span>;
<a name="l00064"></a>00064   }
<a name="l00065"></a>00065   <span class="keywordflow">return</span>;
<a name="l00066"></a>00066   
<a name="l00067"></a>00067 <a class="code" href="stringutil_8cpp.html#a6e3f242b28c9165146182aec25e351a3">err</a>:
<a name="l00068"></a>00068   <a class="code" href="namespacetc.html#a161e534a110ff1f23f8a13a9ebdc00ee">tc::warn</a>(<span class="stringliteral">&quot;Improperly formatted circuit: &#39;%1&#39;&quot;</span>).arg(circuit);
<a name="l00069"></a>00069   <a class="code" href="class_circuit.html#a8b4f6ac4382c7beb4e431fd9977912b5">_isValid</a> = <span class="keyword">false</span>;
<a name="l00070"></a>00070 }
<a name="l00071"></a>00071 <span class="comment"></span>
<a name="l00072"></a>00072 <span class="comment">/** Returns true iff &lt;b&gt;circId&lt;/b&gt; consists of only between 1 and 16</span>
<a name="l00073"></a>00073 <span class="comment"> * (inclusive) ASCII-encoded letters and numbers. */</span>
<a name="l00074"></a>00074 <span class="keywordtype">bool</span>
<a name="l00075"></a><a class="code" href="class_circuit.html#a440c821a5d795deb029848a064d9f3fd">00075</a> <a class="code" href="class_circuit.html#a440c821a5d795deb029848a064d9f3fd">Circuit::isValidCircuitId</a>(<span class="keyword">const</span> <a class="code" href="_circuit_8h.html#a8b7b0182a6d1ff0aab7ab31df9c3f83d">CircuitId</a> &amp;circId)
<a name="l00076"></a>00076 {
<a name="l00077"></a>00077   <span class="keywordtype">int</span> <a class="code" href="class_circuit.html#a9659daf54fc25df9d178c0bb38871095">length</a> = circId.length();
<a name="l00078"></a>00078   <span class="keywordflow">if</span> (length &lt; 1 || length &gt; 16)
<a name="l00079"></a>00079     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00080"></a>00080 
<a name="l00081"></a>00081   <span class="keywordflow">for</span> (<span class="keywordtype">int</span> <a class="code" href="html_8cpp.html#a4a5dba6492ea149585950c59c210ff47">i</a> = 0; <a class="code" href="html_8cpp.html#a4a5dba6492ea149585950c59c210ff47">i</a> &lt; length; <a class="code" href="html_8cpp.html#a4a5dba6492ea149585950c59c210ff47">i</a>++) {
<a name="l00082"></a>00082     <span class="keywordtype">char</span> c = circId[<a class="code" href="html_8cpp.html#a4a5dba6492ea149585950c59c210ff47">i</a>].toAscii();
<a name="l00083"></a>00083     <span class="keywordflow">if</span> (c &lt; &#39;0&#39; &amp;&amp; c &gt; <span class="charliteral">&#39;9&#39;</span> &amp;&amp; c &lt; &#39;A&#39; &amp;&amp; c &gt; <span class="charliteral">&#39;Z&#39;</span> &amp;&amp; c &lt; &#39;a&#39; &amp;&amp; c &gt; <span class="charliteral">&#39;z&#39;</span>)
<a name="l00084"></a>00084       <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00085"></a>00085   }
<a name="l00086"></a>00086   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00087"></a>00087 }
<a name="l00088"></a>00088 <span class="comment"></span>
<a name="l00089"></a>00089 <span class="comment">/** Converts the circuit status string to its proper enum value */</span>
<a name="l00090"></a>00090 <a class="code" href="class_circuit.html#ae831da69eb5ffd2af9f470d90c613d0a">Circuit::Status</a>
<a name="l00091"></a><a class="code" href="class_circuit.html#aa4a57b1e38c6502fc48e9a1d34092e5f">00091</a> <a class="code" href="class_circuit.html#aa4a57b1e38c6502fc48e9a1d34092e5f">Circuit::toStatus</a>(<span class="keyword">const</span> QString &amp;status)
<a name="l00092"></a>00092 {
<a name="l00093"></a>00093   <span class="keywordflow">if</span> (!status.compare(<span class="stringliteral">&quot;LAUNCHED&quot;</span>, Qt::CaseInsensitive))
<a name="l00094"></a>00094     <span class="keywordflow">return</span> <a class="code" href="class_circuit.html#ae831da69eb5ffd2af9f470d90c613d0aa3159446c00c57be721566ad88ad6e517">Launched</a>;
<a name="l00095"></a>00095   <span class="keywordflow">if</span> (!status.compare(<span class="stringliteral">&quot;BUILT&quot;</span>, Qt::CaseInsensitive))
<a name="l00096"></a>00096     <span class="keywordflow">return</span> <a class="code" href="class_circuit.html#ae831da69eb5ffd2af9f470d90c613d0aad2f6d14053da3729ae9063cfa8125037">Built</a>;
<a name="l00097"></a>00097   <span class="keywordflow">if</span> (!status.compare(<span class="stringliteral">&quot;EXTENDED&quot;</span>, Qt::CaseInsensitive))
<a name="l00098"></a>00098     <span class="keywordflow">return</span> <a class="code" href="class_circuit.html#ae831da69eb5ffd2af9f470d90c613d0aaff3f0927c5139d09f47cbda207b4049e">Extended</a>;
<a name="l00099"></a>00099   <span class="keywordflow">if</span> (!status.compare(<span class="stringliteral">&quot;FAILED&quot;</span>, Qt::CaseInsensitive))
<a name="l00100"></a>00100     <span class="keywordflow">return</span> <a class="code" href="class_circuit.html#ae831da69eb5ffd2af9f470d90c613d0aa28e1a44a072277cd8ff8610a66e1ef90">Failed</a>;
<a name="l00101"></a>00101   <span class="keywordflow">if</span> (!status.compare(<span class="stringliteral">&quot;CLOSED&quot;</span>, Qt::CaseInsensitive))
<a name="l00102"></a>00102     <span class="keywordflow">return</span> <a class="code" href="class_circuit.html#ae831da69eb5ffd2af9f470d90c613d0aa870aea6e455b0bfec4f9ff3764c9623f">Closed</a>;
<a name="l00103"></a>00103   <span class="keywordflow">return</span> <a class="code" href="class_circuit.html#ae831da69eb5ffd2af9f470d90c613d0aa8fc7fad3a4f3f006c763f50919d0921a">Unknown</a>;
<a name="l00104"></a>00104 }
<a name="l00105"></a>00105 <span class="comment"></span>
<a name="l00106"></a>00106 <span class="comment">/** Returns a string representation of the circuit&#39;s status. */</span>
<a name="l00107"></a>00107 QString
<a name="l00108"></a><a class="code" href="class_circuit.html#a559fa04641a22358b18e63e6c876eef1">00108</a> <a class="code" href="class_circuit.html#a559fa04641a22358b18e63e6c876eef1">Circuit::statusString</a>()<span class="keyword"> const</span>
<a name="l00109"></a>00109 <span class="keyword"></span>{
<a name="l00110"></a>00110   QString <a class="code" href="class_circuit.html#a33c78724c92b50c7aa28b247a88a79f4">status</a>;
<a name="l00111"></a>00111   <span class="keywordflow">switch</span> (<a class="code" href="class_circuit.html#a470c834decedb2ae3f15b8774bae36b3">_status</a>) {
<a name="l00112"></a>00112     <span class="keywordflow">case</span> <a class="code" href="class_circuit.html#ae831da69eb5ffd2af9f470d90c613d0aa3159446c00c57be721566ad88ad6e517">Launched</a>:    status = tr(<span class="stringliteral">&quot;New&quot;</span>); <span class="keywordflow">break</span>;
<a name="l00113"></a>00113     <span class="keywordflow">case</span> <a class="code" href="class_circuit.html#ae831da69eb5ffd2af9f470d90c613d0aad2f6d14053da3729ae9063cfa8125037">Built</a>:       status = tr(<span class="stringliteral">&quot;Open&quot;</span>); <span class="keywordflow">break</span>;
<a name="l00114"></a>00114     <span class="keywordflow">case</span> <a class="code" href="class_circuit.html#ae831da69eb5ffd2af9f470d90c613d0aaff3f0927c5139d09f47cbda207b4049e">Extended</a>:    status = tr(<span class="stringliteral">&quot;Building&quot;</span>); <span class="keywordflow">break</span>;
<a name="l00115"></a>00115     <span class="keywordflow">case</span> <a class="code" href="class_circuit.html#ae831da69eb5ffd2af9f470d90c613d0aa28e1a44a072277cd8ff8610a66e1ef90">Failed</a>:      status = tr(<span class="stringliteral">&quot;Failed&quot;</span>);  <span class="keywordflow">break</span>;
<a name="l00116"></a>00116     <span class="keywordflow">case</span> <a class="code" href="class_circuit.html#ae831da69eb5ffd2af9f470d90c613d0aa870aea6e455b0bfec4f9ff3764c9623f">Closed</a>:      status = tr(<span class="stringliteral">&quot;Closed&quot;</span>); <span class="keywordflow">break</span>;
<a name="l00117"></a>00117     <span class="keywordflow">default</span>:          status = tr(<span class="stringliteral">&quot;Unknown&quot;</span>); <span class="keywordflow">break</span>;
<a name="l00118"></a>00118   }
<a name="l00119"></a>00119   <span class="keywordflow">return</span> status;
<a name="l00120"></a>00120 }
<a name="l00121"></a>00121 
</pre></div></div>
<hr class="footer"/><address style="text-align: right;"><small>Generated on Mon Aug 30 22:58:54 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>