Sophie

Sophie

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

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: RouterStatus.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>RouterStatus.cpp</h1><a href="_router_status_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 RouterStatus.cpp</span>
<a name="l00013"></a>00013 <span class="comment">** \version $Id: RouterStatus.cpp 3735 2009-04-28 20:28:01Z edmanm $</span>
<a name="l00014"></a>00014 <span class="comment">** \brief Parses a blob of router status text from 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="_router_status_8h.html">RouterStatus.h</a>&quot;</span>
<a name="l00018"></a>00018 
<a name="l00019"></a>00019 <span class="preprocessor">#include &quot;<a class="code" href="stringutil_8h.html">stringutil.h</a>&quot;</span>
<a name="l00020"></a>00020 <span class="comment"></span>
<a name="l00021"></a>00021 <span class="comment">/** Defines the time format used when parsing the published date and time from</span>
<a name="l00022"></a>00022 <span class="comment"> * a router&#39;s status. */</span>
<a name="l00023"></a><a class="code" href="_router_status_8cpp.html#af54a2d4a37ffb240c80d6bd1202a1104">00023</a> <span class="preprocessor">#define TIME_FORMAT  &quot;yyyy-MM-dd HH:mm:ss&quot;</span>
<a name="l00024"></a>00024 <span class="preprocessor"></span>
<a name="l00025"></a>00025 <span class="comment"></span>
<a name="l00026"></a>00026 <span class="comment">/** Constructor. Parses &lt;b&gt;status&lt;/b&gt; for router status information. The given</span>
<a name="l00027"></a>00027 <span class="comment"> * string should match the router status entry format from Tor&#39;s dir-spec.txt.</span>
<a name="l00028"></a>00028 <span class="comment"> * The currently recognized lines are:</span>
<a name="l00029"></a>00029 <span class="comment"> *</span>
<a name="l00030"></a>00030 <span class="comment"> *  &quot;r&quot; SP nickname SP identity SP digest SP publication SP IP SP ORPort</span>
<a name="l00031"></a>00031 <span class="comment"> *      SP DirPort NL</span>
<a name="l00032"></a>00032 <span class="comment"> *  &quot;s&quot; SP Flags NL</span>
<a name="l00033"></a>00033 <span class="comment"> *</span>
<a name="l00034"></a>00034 <span class="comment"> * Unrecognized lines are currently ignored.</span>
<a name="l00035"></a>00035 <span class="comment"> *</span>
<a name="l00036"></a>00036 <span class="comment"> * */</span>
<a name="l00037"></a><a class="code" href="class_router_status.html#a30dc04da22e07bad1e6cce94be8acd42">00037</a> <a class="code" href="class_router_status.html#a30dc04da22e07bad1e6cce94be8acd42">RouterStatus::RouterStatus</a>(<span class="keyword">const</span> QStringList &amp;status)
<a name="l00038"></a>00038 {
<a name="l00039"></a>00039   <span class="keywordtype">bool</span> ok;
<a name="l00040"></a>00040 
<a name="l00041"></a>00041   <a class="code" href="class_router_status.html#abdac24aa747ee4b38d8bb158b1baceb4">_valid</a> = <span class="keyword">false</span>;
<a name="l00042"></a>00042   <a class="code" href="class_router_status.html#a4654bbeb6b695f2591fd001a76810206">_flags</a> = 0;
<a name="l00043"></a>00043 
<a name="l00044"></a>00044   <span class="keywordflow">foreach</span> (QString line, status) {
<a name="l00045"></a>00045     <span class="keywordflow">if</span> (line.startsWith(<span class="stringliteral">&quot;r &quot;</span>)) {
<a name="l00046"></a>00046       QStringList parts = line.split(<span class="stringliteral">&quot; &quot;</span>, QString::SkipEmptyParts);
<a name="l00047"></a>00047       <span class="keywordflow">if</span> (parts.size() &lt; 9)
<a name="l00048"></a>00048         <span class="keywordflow">return</span>;
<a name="l00049"></a>00049 
<a name="l00050"></a>00050       <span class="comment">/* Nickname */</span>
<a name="l00051"></a>00051       <a class="code" href="class_router_status.html#a9fd12f7b8e676e2e233d708c5630d793">_name</a> = parts.at(1);
<a name="l00052"></a>00052       <span class="comment">/* Identity key digest */</span>
<a name="l00053"></a>00053       <a class="code" href="class_router_status.html#ad82dc178650da28c3b43b678604a1659">_id</a> = <a class="code" href="stringutil_8cpp.html#a4d5ac084308fee41bcc66b9ed3754d8f">base16_encode</a>(QByteArray::fromBase64(parts.at(2).toAscii()));
<a name="l00054"></a>00054       <span class="keywordflow">if</span> (<a class="code" href="class_router_status.html#ad82dc178650da28c3b43b678604a1659">_id</a>.isEmpty())
<a name="l00055"></a>00055         <span class="keywordflow">return</span>;
<a name="l00056"></a>00056       <span class="comment">/* Most recent descriptor digest */</span>
<a name="l00057"></a>00057       <a class="code" href="class_router_status.html#a49c80243fa12157cc50c1dd735a50f41">_digest</a> = <a class="code" href="stringutil_8cpp.html#a4d5ac084308fee41bcc66b9ed3754d8f">base16_encode</a>(QByteArray::fromBase64(parts.at(3).toAscii()));
<a name="l00058"></a>00058       <span class="keywordflow">if</span> (<a class="code" href="class_router_status.html#a49c80243fa12157cc50c1dd735a50f41">_digest</a>.isEmpty())
<a name="l00059"></a>00059         <span class="keywordflow">return</span>;
<a name="l00060"></a>00060       <span class="comment">/* Most recent publication date */</span>
<a name="l00061"></a>00061       <a class="code" href="class_router_status.html#ad056d26a710668e1c4e2543b2f1821e2">_published</a> = QDateTime::fromString(parts.at(4) + <span class="stringliteral">&quot; &quot;</span> + parts.at(5),
<a name="l00062"></a>00062                                          <a class="code" href="_router_status_8cpp.html#af54a2d4a37ffb240c80d6bd1202a1104">TIME_FORMAT</a>);
<a name="l00063"></a>00063       <span class="keywordflow">if</span> (!<a class="code" href="class_router_status.html#ad056d26a710668e1c4e2543b2f1821e2">_published</a>.isValid())
<a name="l00064"></a>00064         <span class="keywordflow">return</span>;
<a name="l00065"></a>00065       <span class="comment">/* IP address */</span>
<a name="l00066"></a>00066       <a class="code" href="class_router_status.html#ad38bb5dbeefd9e39d95d14862ecce342">_ipAddress</a> = QHostAddress(parts.at(6));
<a name="l00067"></a>00067       <span class="keywordflow">if</span> (<a class="code" href="class_router_status.html#ad38bb5dbeefd9e39d95d14862ecce342">_ipAddress</a>.isNull())
<a name="l00068"></a>00068         <span class="keywordflow">return</span>;
<a name="l00069"></a>00069       <span class="comment">/* ORPort */</span>
<a name="l00070"></a>00070       <a class="code" href="class_router_status.html#a6188114d0a7f97d338f068b87700960e">_orPort</a> = parts.at(7).toUInt(&amp;ok);
<a name="l00071"></a>00071       <span class="keywordflow">if</span> (!ok)
<a name="l00072"></a>00072         <span class="keywordflow">return</span>;
<a name="l00073"></a>00073       <span class="comment">/* DirPort */</span>
<a name="l00074"></a>00074       <a class="code" href="class_router_status.html#af55cc179563a96140e0eb305f7735b12">_dirPort</a> = parts.at(8).toUInt(&amp;ok);
<a name="l00075"></a>00075       <span class="keywordflow">if</span> (!ok)
<a name="l00076"></a>00076         <span class="keywordflow">return</span>;
<a name="l00077"></a>00077 
<a name="l00078"></a>00078       <a class="code" href="class_router_status.html#abdac24aa747ee4b38d8bb158b1baceb4">_valid</a> = <span class="keyword">true</span>;
<a name="l00079"></a>00079     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (line.startsWith(<span class="stringliteral">&quot;s &quot;</span>)) {
<a name="l00080"></a>00080       <span class="comment">/* Status flags */</span>
<a name="l00081"></a>00081       QStringList <a class="code" href="class_router_status.html#a7ae44fcf11fdfcc684cf317bf3306d95">flags</a> = line.split(<span class="stringliteral">&quot; &quot;</span>, QString::SkipEmptyParts);
<a name="l00082"></a>00082       flags.removeFirst(); <span class="comment">/* Remove the &quot;s&quot; */</span>
<a name="l00083"></a>00083 
<a name="l00084"></a>00084       <span class="keywordflow">foreach</span> (QString flag, flags) {
<a name="l00085"></a>00085         <a class="code" href="class_router_status.html#a4654bbeb6b695f2591fd001a76810206">_flags</a> |= <a class="code" href="class_router_status.html#a9286bc89d3131ee09a6e64bf543eecca">flagValue</a>(flag);
<a name="l00086"></a>00086       }
<a name="l00087"></a>00087     }
<a name="l00088"></a>00088   }
<a name="l00089"></a>00089 }
<a name="l00090"></a>00090 <span class="comment"></span>
<a name="l00091"></a>00091 <span class="comment">/** Returns a Flags enum value for the given router status &lt;b&gt;flag&lt;/b&gt;. If</span>
<a name="l00092"></a>00092 <span class="comment"> * &lt;b&gt;flag&lt;/b&gt; is not recognized, then &lt;i&gt;Unknown&lt;/i&gt; is returned. */</span>
<a name="l00093"></a>00093 <a class="code" href="class_router_status.html#a79bbd308f257cf7b6d221ec1d63488f3">RouterStatus::Flag</a>
<a name="l00094"></a><a class="code" href="class_router_status.html#a9286bc89d3131ee09a6e64bf543eecca">00094</a> <a class="code" href="class_router_status.html#a9286bc89d3131ee09a6e64bf543eecca">RouterStatus::flagValue</a>(<span class="keyword">const</span> QString &amp;flag)
<a name="l00095"></a>00095 {
<a name="l00096"></a>00096   <span class="keywordflow">if</span> (!flag.compare(<span class="stringliteral">&quot;Authority&quot;</span>, Qt::CaseInsensitive))
<a name="l00097"></a>00097     <span class="keywordflow">return</span> <a class="code" href="class_router_status.html#a79bbd308f257cf7b6d221ec1d63488f3aa97c30cea7fc633292dd1c11c2fa2ed5">Authority</a>;
<a name="l00098"></a>00098   <span class="keywordflow">if</span> (!flag.compare(<span class="stringliteral">&quot;BadExit&quot;</span>, Qt::CaseInsensitive))
<a name="l00099"></a>00099     <span class="keywordflow">return</span> <a class="code" href="class_router_status.html#a79bbd308f257cf7b6d221ec1d63488f3a7026fb54bbe440ab0fa49e750bf7be4a">BadExit</a>;
<a name="l00100"></a>00100   <span class="keywordflow">if</span> (!flag.compare(<span class="stringliteral">&quot;BadDirectory&quot;</span>, Qt::CaseInsensitive))
<a name="l00101"></a>00101     <span class="keywordflow">return</span> <a class="code" href="class_router_status.html#a79bbd308f257cf7b6d221ec1d63488f3ae34fd7fe102b4143bba19e7b49d5a6b1">BadDirectory</a>;
<a name="l00102"></a>00102   <span class="keywordflow">if</span> (!flag.compare(<span class="stringliteral">&quot;Exit&quot;</span>, Qt::CaseInsensitive))
<a name="l00103"></a>00103     <span class="keywordflow">return</span> <a class="code" href="class_router_status.html#a79bbd308f257cf7b6d221ec1d63488f3a011d7cd436e3805332fbaa604dc6f98f">Exit</a>;
<a name="l00104"></a>00104   <span class="keywordflow">if</span> (!flag.compare(<span class="stringliteral">&quot;Fast&quot;</span>, Qt::CaseInsensitive))
<a name="l00105"></a>00105     <span class="keywordflow">return</span> <a class="code" href="class_router_status.html#a79bbd308f257cf7b6d221ec1d63488f3a8893a77dbdac75e2747a8c91e00eaedc">Fast</a>;
<a name="l00106"></a>00106   <span class="keywordflow">if</span> (!flag.compare(<span class="stringliteral">&quot;Guard&quot;</span>, Qt::CaseInsensitive))
<a name="l00107"></a>00107     <span class="keywordflow">return</span> <a class="code" href="class_router_status.html#a79bbd308f257cf7b6d221ec1d63488f3aa046a81d28c897a447f1af554908dd32">Guard</a>;
<a name="l00108"></a>00108   <span class="keywordflow">if</span> (!flag.compare(<span class="stringliteral">&quot;HSDir&quot;</span>, Qt::CaseInsensitive))
<a name="l00109"></a>00109     <span class="keywordflow">return</span> <a class="code" href="class_router_status.html#a79bbd308f257cf7b6d221ec1d63488f3a349ef87f35c1c6b4bba59a2d94d79b34">HSDir</a>;
<a name="l00110"></a>00110   <span class="keywordflow">if</span> (!flag.compare(<span class="stringliteral">&quot;Named&quot;</span>, Qt::CaseInsensitive))
<a name="l00111"></a>00111     <span class="keywordflow">return</span> <a class="code" href="class_router_status.html#a79bbd308f257cf7b6d221ec1d63488f3add86b1dbc8c86cd49408cfff58006e8f">Named</a>;
<a name="l00112"></a>00112   <span class="keywordflow">if</span> (!flag.compare(<span class="stringliteral">&quot;Running&quot;</span>, Qt::CaseInsensitive))
<a name="l00113"></a>00113     <span class="keywordflow">return</span> <a class="code" href="class_router_status.html#a79bbd308f257cf7b6d221ec1d63488f3a4ee0f3f3b0ee6bdfc23b672ca588e56b">Running</a>;
<a name="l00114"></a>00114   <span class="keywordflow">if</span> (!flag.compare(<span class="stringliteral">&quot;Stable&quot;</span>, Qt::CaseInsensitive))
<a name="l00115"></a>00115     <span class="keywordflow">return</span> <a class="code" href="class_router_status.html#a79bbd308f257cf7b6d221ec1d63488f3a02628199a8269948276355844100121b">Stable</a>;
<a name="l00116"></a>00116   <span class="keywordflow">if</span> (!flag.compare(<span class="stringliteral">&quot;Valid&quot;</span>, Qt::CaseInsensitive))
<a name="l00117"></a>00117     <span class="keywordflow">return</span> <a class="code" href="class_router_status.html#a79bbd308f257cf7b6d221ec1d63488f3afd85078743ff4bc361bed3e7c22eee3f">Valid</a>;
<a name="l00118"></a>00118   <span class="keywordflow">if</span> (!flag.compare(<span class="stringliteral">&quot;V2Dir&quot;</span>, Qt::CaseInsensitive))
<a name="l00119"></a>00119     <span class="keywordflow">return</span> <a class="code" href="class_router_status.html#a79bbd308f257cf7b6d221ec1d63488f3a12c76bacab2734f4b36588426cbfc7b6">V2Dir</a>;
<a name="l00120"></a>00120   <span class="keywordflow">if</span> (!flag.compare(<span class="stringliteral">&quot;V3Dir&quot;</span>, Qt::CaseInsensitive))
<a name="l00121"></a>00121     <span class="keywordflow">return</span> <a class="code" href="class_router_status.html#a79bbd308f257cf7b6d221ec1d63488f3a5c5d214c77d06a72a4624eaaadeec5e5">V3Dir</a>;
<a name="l00122"></a>00122   <span class="keywordflow">return</span> <a class="code" href="class_router_status.html#a79bbd308f257cf7b6d221ec1d63488f3a2bcc404adfb53cc5abc85950d8909b56">Unknown</a>; <span class="comment">/* Unknown status flag */</span>
<a name="l00123"></a>00123 }
<a name="l00124"></a>00124 
</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>