Sophie

Sophie

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

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: TorEvents.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>TorEvents.cpp</h1><a href="_tor_events_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 TorEvents.cpp</span>
<a name="l00013"></a>00013 <span class="comment">** \version $Id: TorEvents.cpp 4100 2009-09-01 13:54:27Z edmanm $</span>
<a name="l00014"></a>00014 <span class="comment">** \brief Parses and dispatches events from Tor</span>
<a name="l00015"></a>00015 <span class="comment">*/</span>
<a name="l00016"></a>00016 
<a name="l00017"></a>00017 
<a name="l00018"></a>00018 <span class="preprocessor">#include &quot;<a class="code" href="_tor_events_8h.html">TorEvents.h</a>&quot;</span>
<a name="l00019"></a>00019 <span class="preprocessor">#include &quot;<a class="code" href="_control_reply_8h.html">ControlReply.h</a>&quot;</span>
<a name="l00020"></a>00020 <span class="preprocessor">#include &quot;<a class="code" href="_reply_line_8h.html">ReplyLine.h</a>&quot;</span>
<a name="l00021"></a>00021 <span class="preprocessor">#include &quot;<a class="code" href="_circuit_8h.html">Circuit.h</a>&quot;</span>
<a name="l00022"></a>00022 <span class="preprocessor">#include &quot;<a class="code" href="_stream_8h.html">Stream.h</a>&quot;</span>
<a name="l00023"></a>00023 <span class="preprocessor">#include &quot;<a class="code" href="_bootstrap_status_8h.html">BootstrapStatus.h</a>&quot;</span>
<a name="l00024"></a>00024 
<a name="l00025"></a>00025 <span class="preprocessor">#include &quot;<a class="code" href="stringutil_8h.html">stringutil.h</a>&quot;</span>
<a name="l00026"></a>00026 
<a name="l00027"></a>00027 <span class="preprocessor">#include &lt;QHostAddress&gt;</span>
<a name="l00028"></a>00028 <span class="preprocessor">#include &lt;QMetaType&gt;</span>
<a name="l00029"></a>00029 <span class="comment"></span>
<a name="l00030"></a>00030 <span class="comment">/** Format of expiry times in address map events. */</span>
<a name="l00031"></a><a class="code" href="_tor_events_8cpp.html#ab88071d2dae07659090a23e67a1e4d7f">00031</a> <span class="preprocessor">#define DATE_FMT &quot;\&quot;yyyy-MM-dd HH:mm:ss\&quot;&quot;</span>
<a name="l00032"></a>00032 <span class="preprocessor"></span>
<a name="l00033"></a>00033 <span class="comment"></span>
<a name="l00034"></a>00034 <span class="comment">/** Default constructor */</span>
<a name="l00035"></a><a class="code" href="class_tor_events.html#a7640c5e646ac7c699995b2e046028749">00035</a> <a class="code" href="class_tor_events.html#a7640c5e646ac7c699995b2e046028749">TorEvents::TorEvents</a>(QObject *parent)
<a name="l00036"></a>00036   : QObject(parent)
<a name="l00037"></a>00037 {
<a name="l00038"></a>00038   qRegisterMetaType&lt;tc::Severity&gt;();
<a name="l00039"></a>00039   qRegisterMetaType&lt;tc::SocksError&gt;();
<a name="l00040"></a>00040   qRegisterMetaType&lt;tc::TorVersionStatus&gt;();
<a name="l00041"></a>00041 
<a name="l00042"></a>00042   qRegisterMetaType&lt;BootstrapStatus&gt;(<span class="stringliteral">&quot;BootstrapStatus&quot;</span>);
<a name="l00043"></a>00043   qRegisterMetaType&lt;Circuit&gt;(<span class="stringliteral">&quot;Circuit&quot;</span>);
<a name="l00044"></a>00044   qRegisterMetaType&lt;Stream&gt;(<span class="stringliteral">&quot;Stream&quot;</span>);
<a name="l00045"></a>00045 
<a name="l00046"></a>00046   qRegisterMetaType&lt;QHostAddress&gt;(<span class="stringliteral">&quot;QHostAddress&quot;</span>);
<a name="l00047"></a>00047   qRegisterMetaType&lt;QDateTime&gt;(<span class="stringliteral">&quot;QDateTime&quot;</span>);
<a name="l00048"></a>00048 }
<a name="l00049"></a>00049 <span class="comment"></span>
<a name="l00050"></a>00050 <span class="comment">/** Converts an event type to a string Tor understands */</span>
<a name="l00051"></a>00051 QString
<a name="l00052"></a><a class="code" href="class_tor_events.html#a8c62c55a950118cdeba5a7de34ac157b">00052</a> <a class="code" href="class_tor_events.html#a8c62c55a950118cdeba5a7de34ac157b">TorEvents::toString</a>(<a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bf">Event</a> e)
<a name="l00053"></a>00053 {
<a name="l00054"></a>00054   QString event;
<a name="l00055"></a>00055   <span class="keywordflow">switch</span> (e) {
<a name="l00056"></a>00056     <span class="keywordflow">case</span> <a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bfa37aa333e6b9acdb8cf240fbafeba4e38">Bandwidth</a>: <span class="keyword">event</span> = <span class="stringliteral">&quot;BW&quot;</span>; <span class="keywordflow">break</span>;
<a name="l00057"></a>00057     <span class="keywordflow">case</span> <a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bfa4920e9d8dc81811068c197c2dcb4661a">LogDebug</a>:  <span class="keyword">event</span> = <span class="stringliteral">&quot;DEBUG&quot;</span>; <span class="keywordflow">break</span>;
<a name="l00058"></a>00058     <span class="keywordflow">case</span> <a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bfaf829e003d41f5c29746c593273107013">LogInfo</a>:   <span class="keyword">event</span> = <span class="stringliteral">&quot;INFO&quot;</span>; <span class="keywordflow">break</span>;
<a name="l00059"></a>00059     <span class="keywordflow">case</span> <a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bfaf6c5726f1703ac0dbefb3753383d1c54">LogNotice</a>: <span class="keyword">event</span> = <span class="stringliteral">&quot;NOTICE&quot;</span>; <span class="keywordflow">break</span>;
<a name="l00060"></a>00060     <span class="keywordflow">case</span> <a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bfaecfea72c14b492ec436d71991b11a4f4">LogWarn</a>:   <span class="keyword">event</span> = <span class="stringliteral">&quot;WARN&quot;</span>; <span class="keywordflow">break</span>;
<a name="l00061"></a>00061     <span class="keywordflow">case</span> <a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bfa1588b65cd76aad1ada9925be377eee27">LogError</a>:  <span class="keyword">event</span> = <span class="stringliteral">&quot;ERR&quot;</span>; <span class="keywordflow">break</span>;
<a name="l00062"></a>00062     <span class="keywordflow">case</span> <a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bfaf51a978d8fb4a086d815518b13c6ccc4">CircuitStatus</a>:   <span class="keyword">event</span> = <span class="stringliteral">&quot;CIRC&quot;</span>; <span class="keywordflow">break</span>;
<a name="l00063"></a>00063     <span class="keywordflow">case</span> <a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bfa92d48f0cdb62ea444713b7574ab31d34">StreamStatus</a>:    <span class="keyword">event</span> = <span class="stringliteral">&quot;STREAM&quot;</span>; <span class="keywordflow">break</span>;
<a name="l00064"></a>00064     <span class="keywordflow">case</span> <a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bfad4e1c3f57606b56d335885d3f36bf20c">NewDescriptor</a>:   <span class="keyword">event</span> = <span class="stringliteral">&quot;NEWDESC&quot;</span>; <span class="keywordflow">break</span>;
<a name="l00065"></a>00065     <span class="keywordflow">case</span> <a class="code" href="class_address_map.html">AddressMap</a>:      <span class="keyword">event</span> = <span class="stringliteral">&quot;ADDRMAP&quot;</span>; <span class="keywordflow">break</span>;
<a name="l00066"></a>00066     <span class="keywordflow">case</span> <a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bfa0f4ce116650cb34661bfe23344562765">GeneralStatus</a>:   <span class="keyword">event</span> = <span class="stringliteral">&quot;STATUS_GENERAL&quot;</span>; <span class="keywordflow">break</span>;
<a name="l00067"></a>00067     <span class="keywordflow">case</span> <a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bfa5f1d41f1693f31d72e3e6c037cf7ff01">ClientStatus</a>:    <span class="keyword">event</span> = <span class="stringliteral">&quot;STATUS_CLIENT&quot;</span>; <span class="keywordflow">break</span>;
<a name="l00068"></a>00068     <span class="keywordflow">case</span> <a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bfa1a28286d958ff505ab63722214395e8f">ServerStatus</a>:    <span class="keyword">event</span> = <span class="stringliteral">&quot;STATUS_SERVER&quot;</span>; <span class="keywordflow">break</span>;
<a name="l00069"></a>00069     <span class="keywordflow">default</span>: <span class="keyword">event</span> = <span class="stringliteral">&quot;UNKNOWN&quot;</span>; <span class="keywordflow">break</span>;
<a name="l00070"></a>00070   }
<a name="l00071"></a>00071   <span class="keywordflow">return</span> event;
<a name="l00072"></a>00072 }
<a name="l00073"></a>00073 <span class="comment"></span>
<a name="l00074"></a>00074 <span class="comment">/** Converts an event in the string form sent by Tor to its enum value */</span>
<a name="l00075"></a>00075 <a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bf">TorEvents::Event</a>
<a name="l00076"></a><a class="code" href="class_tor_events.html#aab44fb9ba9b80d85b95ebe7ac9bc25f9">00076</a> <a class="code" href="class_tor_events.html#aab44fb9ba9b80d85b95ebe7ac9bc25f9">TorEvents::toTorEvent</a>(<span class="keyword">const</span> QString &amp;event)
<a name="l00077"></a>00077 {
<a name="l00078"></a>00078   <a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bf">Event</a> e;
<a name="l00079"></a>00079   <span class="keywordflow">if</span> (event == <span class="stringliteral">&quot;BW&quot;</span>) {
<a name="l00080"></a>00080     e = <a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bfa37aa333e6b9acdb8cf240fbafeba4e38">Bandwidth</a>;
<a name="l00081"></a>00081   } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (event == <span class="stringliteral">&quot;CIRC&quot;</span>) {
<a name="l00082"></a>00082     e = <a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bfaf51a978d8fb4a086d815518b13c6ccc4">CircuitStatus</a>;
<a name="l00083"></a>00083   } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (event == <span class="stringliteral">&quot;STREAM&quot;</span>) {
<a name="l00084"></a>00084     e = <a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bfa92d48f0cdb62ea444713b7574ab31d34">StreamStatus</a>;
<a name="l00085"></a>00085   } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (event == <span class="stringliteral">&quot;DEBUG&quot;</span>) {
<a name="l00086"></a>00086     e = <a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bfa4920e9d8dc81811068c197c2dcb4661a">LogDebug</a>;
<a name="l00087"></a>00087   } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (event == <span class="stringliteral">&quot;INFO&quot;</span>) {
<a name="l00088"></a>00088     e = <a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bfaf829e003d41f5c29746c593273107013">LogInfo</a>;
<a name="l00089"></a>00089   } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (event == <span class="stringliteral">&quot;NOTICE&quot;</span>) {
<a name="l00090"></a>00090     e = <a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bfaf6c5726f1703ac0dbefb3753383d1c54">LogNotice</a>;
<a name="l00091"></a>00091   } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (event == <span class="stringliteral">&quot;WARN&quot;</span>) {
<a name="l00092"></a>00092     e = <a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bfaecfea72c14b492ec436d71991b11a4f4">LogWarn</a>;
<a name="l00093"></a>00093   } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (event == <span class="stringliteral">&quot;ERR&quot;</span>) {
<a name="l00094"></a>00094     e = <a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bfa1588b65cd76aad1ada9925be377eee27">LogError</a>;
<a name="l00095"></a>00095   } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (event == <span class="stringliteral">&quot;NEWDESC&quot;</span>) {
<a name="l00096"></a>00096     e = <a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bfad4e1c3f57606b56d335885d3f36bf20c">NewDescriptor</a>;
<a name="l00097"></a>00097   } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (event == <span class="stringliteral">&quot;ADDRMAP&quot;</span>) {
<a name="l00098"></a>00098     e = <a class="code" href="class_address_map.html">AddressMap</a>;
<a name="l00099"></a>00099   } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (event == <span class="stringliteral">&quot;STATUS_GENERAL&quot;</span>) {
<a name="l00100"></a>00100     e = <a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bfa0f4ce116650cb34661bfe23344562765">GeneralStatus</a>;
<a name="l00101"></a>00101   } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (event == <span class="stringliteral">&quot;STATUS_CLIENT&quot;</span>) {
<a name="l00102"></a>00102     e = <a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bfa5f1d41f1693f31d72e3e6c037cf7ff01">ClientStatus</a>;
<a name="l00103"></a>00103   } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (event == <span class="stringliteral">&quot;STATUS_SERVER&quot;</span>) {
<a name="l00104"></a>00104     e = <a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bfa1a28286d958ff505ab63722214395e8f">ServerStatus</a>;
<a name="l00105"></a>00105   } <span class="keywordflow">else</span> {
<a name="l00106"></a>00106     e = <a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bfacd780c024e79d1b356c6338fcbfbb9c6">Unknown</a>;
<a name="l00107"></a>00107   }
<a name="l00108"></a>00108   <span class="keywordflow">return</span> e;
<a name="l00109"></a>00109 }
<a name="l00110"></a>00110 <span class="comment"></span>
<a name="l00111"></a>00111 <span class="comment">/** Parse the event type out of a message line and return the corresponding</span>
<a name="l00112"></a>00112 <span class="comment"> * Event enum value */</span>
<a name="l00113"></a>00113 <a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bf">TorEvents::Event</a>
<a name="l00114"></a><a class="code" href="class_tor_events.html#a6f2415a207877518622e3a4c3259b571">00114</a> <a class="code" href="class_tor_events.html#a6f2415a207877518622e3a4c3259b571">TorEvents::parseEventType</a>(<span class="keyword">const</span> <a class="code" href="class_reply_line.html">ReplyLine</a> &amp;line)
<a name="l00115"></a>00115 {
<a name="l00116"></a>00116   QString msg = line.<a class="code" href="class_reply_line.html#ad22f50e33e6809eb25a07c090c8a960a">getMessage</a>();
<a name="l00117"></a>00117   <span class="keywordtype">int</span> <a class="code" href="html_8cpp.html#a4a5dba6492ea149585950c59c210ff47">i</a> = msg.indexOf(<span class="stringliteral">&quot; &quot;</span>);
<a name="l00118"></a>00118   <span class="keywordflow">return</span> <a class="code" href="class_tor_events.html#aab44fb9ba9b80d85b95ebe7ac9bc25f9">toTorEvent</a>(msg.mid(0, i));
<a name="l00119"></a>00119 }
<a name="l00120"></a>00120 <span class="comment"></span>
<a name="l00121"></a>00121 <span class="comment">/** Handles an event message from Tor. An event message can potentially have</span>
<a name="l00122"></a>00122 <span class="comment"> * more than one line, so we will iterate through them all and dispatch the</span>
<a name="l00123"></a>00123 <span class="comment"> * necessary events. */</span>
<a name="l00124"></a>00124 <span class="keywordtype">void</span>
<a name="l00125"></a><a class="code" href="class_tor_events.html#a0b5f60ca782a3d0af243ce77c7189379">00125</a> <a class="code" href="class_tor_events.html#a0b5f60ca782a3d0af243ce77c7189379">TorEvents::handleEvent</a>(<span class="keyword">const</span> <a class="code" href="class_control_reply.html">ControlReply</a> &amp;reply)
<a name="l00126"></a>00126 {
<a name="l00127"></a>00127   <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="l00128"></a>00128     <span class="keywordflow">switch</span> (<a class="code" href="class_tor_events.html#a6f2415a207877518622e3a4c3259b571">parseEventType</a>(line)) {
<a name="l00129"></a>00129       <span class="keywordflow">case</span> <a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bfa37aa333e6b9acdb8cf240fbafeba4e38">Bandwidth</a>:      <a class="code" href="class_tor_events.html#a789ec0c0e8662d8b05b0bb3e85333464">handleBandwidthUpdate</a>(line); <span class="keywordflow">break</span>;
<a name="l00130"></a>00130       <span class="keywordflow">case</span> <a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bfaf51a978d8fb4a086d815518b13c6ccc4">CircuitStatus</a>:  <a class="code" href="class_tor_events.html#ae7ae522be9c3671f3ea705fb436b0b1e">handleCircuitStatus</a>(line); <span class="keywordflow">break</span>;
<a name="l00131"></a>00131       <span class="keywordflow">case</span> <a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bfa92d48f0cdb62ea444713b7574ab31d34">StreamStatus</a>:   <a class="code" href="class_tor_events.html#a94672855e722c561fff41d25b2fcddfe">handleStreamStatus</a>(line); <span class="keywordflow">break</span>;
<a name="l00132"></a>00132       <span class="keywordflow">case</span> <a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bfad4e1c3f57606b56d335885d3f36bf20c">NewDescriptor</a>:  <a class="code" href="class_tor_events.html#a7ace5ed4fcac504482c18f63b1e21348">handleNewDescriptor</a>(line); <span class="keywordflow">break</span>;
<a name="l00133"></a>00133       <span class="keywordflow">case</span> <a class="code" href="class_address_map.html">AddressMap</a>:     <a class="code" href="class_tor_events.html#a162d8b646b47cc3f66d3db437d103bca">handleAddressMap</a>(line); <span class="keywordflow">break</span>;
<a name="l00134"></a>00134 
<a name="l00135"></a>00135       <span class="keywordflow">case</span> <a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bfa0f4ce116650cb34661bfe23344562765">GeneralStatus</a>:
<a name="l00136"></a>00136         <a class="code" href="class_tor_events.html#aef7e7863cf6d8ce36018bbdccca3a1f8">handleStatusEvent</a>(<a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bfa0f4ce116650cb34661bfe23344562765">GeneralStatus</a>, line); <span class="keywordflow">break</span>;
<a name="l00137"></a>00137       <span class="keywordflow">case</span> <a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bfa5f1d41f1693f31d72e3e6c037cf7ff01">ClientStatus</a>:
<a name="l00138"></a>00138         <a class="code" href="class_tor_events.html#aef7e7863cf6d8ce36018bbdccca3a1f8">handleStatusEvent</a>(<a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bfa5f1d41f1693f31d72e3e6c037cf7ff01">ClientStatus</a>, line); <span class="keywordflow">break</span>;
<a name="l00139"></a>00139       <span class="keywordflow">case</span> <a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bfa1a28286d958ff505ab63722214395e8f">ServerStatus</a>:
<a name="l00140"></a>00140         <a class="code" href="class_tor_events.html#aef7e7863cf6d8ce36018bbdccca3a1f8">handleStatusEvent</a>(<a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bfa1a28286d958ff505ab63722214395e8f">ServerStatus</a>, line); <span class="keywordflow">break</span>;
<a name="l00141"></a>00141 
<a name="l00142"></a>00142       <span class="keywordflow">case</span> <a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bfa4920e9d8dc81811068c197c2dcb4661a">LogDebug</a>: 
<a name="l00143"></a>00143       <span class="keywordflow">case</span> <a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bfaf829e003d41f5c29746c593273107013">LogInfo</a>:
<a name="l00144"></a>00144       <span class="keywordflow">case</span> <a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bfaf6c5726f1703ac0dbefb3753383d1c54">LogNotice</a>:
<a name="l00145"></a>00145       <span class="keywordflow">case</span> <a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bfaecfea72c14b492ec436d71991b11a4f4">LogWarn</a>:
<a name="l00146"></a>00146       <span class="keywordflow">case</span> <a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bfa1588b65cd76aad1ada9925be377eee27">LogError</a>:
<a name="l00147"></a>00147         <a class="code" href="class_tor_events.html#ae83a736104b606ccad26daaa657b4ae2">handleLogMessage</a>(line); <span class="keywordflow">break</span>;
<a name="l00148"></a>00148       <span class="keywordflow">default</span>: <span class="keywordflow">break</span>;
<a name="l00149"></a>00149     }
<a name="l00150"></a>00150   }
<a name="l00151"></a>00151 }
<a name="l00152"></a>00152 <span class="comment"></span>
<a name="l00153"></a>00153 <span class="comment">/** Handle a bandwidth update event, to inform the controller of the bandwidth</span>
<a name="l00154"></a>00154 <span class="comment"> * used in the last second. The format of this message is:</span>
<a name="l00155"></a>00155 <span class="comment"> *</span>
<a name="l00156"></a>00156 <span class="comment"> *     &quot;650&quot; SP &quot;BW&quot; SP BytesRead SP BytesWritten</span>
<a name="l00157"></a>00157 <span class="comment"> *     BytesRead = 1*DIGIT</span>
<a name="l00158"></a>00158 <span class="comment"> *     BytesWritten = 1*DIGIT</span>
<a name="l00159"></a>00159 <span class="comment"> */</span>
<a name="l00160"></a>00160 <span class="keywordtype">void</span>
<a name="l00161"></a><a class="code" href="class_tor_events.html#a789ec0c0e8662d8b05b0bb3e85333464">00161</a> <a class="code" href="class_tor_events.html#a789ec0c0e8662d8b05b0bb3e85333464">TorEvents::handleBandwidthUpdate</a>(<span class="keyword">const</span> <a class="code" href="class_reply_line.html">ReplyLine</a> &amp;line)
<a name="l00162"></a>00162 {
<a name="l00163"></a>00163   QStringList msg = line.<a class="code" href="class_reply_line.html#ad22f50e33e6809eb25a07c090c8a960a">getMessage</a>().split(<span class="stringliteral">&quot; &quot;</span>);
<a name="l00164"></a>00164   <span class="keywordflow">if</span> (msg.size() &gt;= 3) {
<a name="l00165"></a>00165     quint64 bytesIn = (quint64)msg.at(1).toULongLong();
<a name="l00166"></a>00166     quint64 bytesOut = (quint64)msg.at(2).toULongLong();
<a name="l00167"></a>00167   
<a name="l00168"></a>00168     <span class="comment">/* Post the event to each of the interested targets */</span>
<a name="l00169"></a>00169     emit <a class="code" href="class_tor_events.html#afaa9d5d1de4fbdd2236980569c22b3ba">bandwidthUpdate</a>(bytesIn, bytesOut);
<a name="l00170"></a>00170   }
<a name="l00171"></a>00171 }
<a name="l00172"></a>00172 <span class="comment"></span>
<a name="l00173"></a>00173 <span class="comment">/** Handle a circuit status event. The format of this message is:</span>
<a name="l00174"></a>00174 <span class="comment"> *</span>
<a name="l00175"></a>00175 <span class="comment"> *    &quot;650&quot; SP &quot;CIRC&quot; SP CircuitID SP CircStatus SP Path</span>
<a name="l00176"></a>00176 <span class="comment"> *    CircStatus =</span>
<a name="l00177"></a>00177 <span class="comment"> *             &quot;LAUNCHED&quot; / ; circuit ID assigned to new circuit</span>
<a name="l00178"></a>00178 <span class="comment"> *             &quot;BUILT&quot;    / ; all hops finished, can now accept streams</span>
<a name="l00179"></a>00179 <span class="comment"> *             &quot;EXTENDED&quot; / ; one more hop has been completed</span>
<a name="l00180"></a>00180 <span class="comment"> *             &quot;FAILED&quot;   / ; circuit closed (was not built)</span>
<a name="l00181"></a>00181 <span class="comment"> *             &quot;CLOSED&quot;     ; circuit closed (was built)</span>
<a name="l00182"></a>00182 <span class="comment"> *    Path = ServerID *(&quot;,&quot; ServerID)</span>
<a name="l00183"></a>00183 <span class="comment"> */</span>
<a name="l00184"></a>00184 <span class="keywordtype">void</span>
<a name="l00185"></a><a class="code" href="class_tor_events.html#ae7ae522be9c3671f3ea705fb436b0b1e">00185</a> <a class="code" href="class_tor_events.html#ae7ae522be9c3671f3ea705fb436b0b1e">TorEvents::handleCircuitStatus</a>(<span class="keyword">const</span> <a class="code" href="class_reply_line.html">ReplyLine</a> &amp;line)
<a name="l00186"></a>00186 {
<a name="l00187"></a>00187   QString msg = line.<a class="code" href="class_reply_line.html#ad22f50e33e6809eb25a07c090c8a960a">getMessage</a>().trimmed();
<a name="l00188"></a>00188   <span class="keywordtype">int</span> <a class="code" href="html_8cpp.html#a4a5dba6492ea149585950c59c210ff47">i</a> = msg.indexOf(<span class="stringliteral">&quot; &quot;</span>) + 1;
<a name="l00189"></a>00189   <span class="keywordflow">if</span> (i &gt; 0) {
<a name="l00190"></a>00190     <span class="comment">/* Post the event to each of the interested targets */</span>
<a name="l00191"></a>00191     <a class="code" href="class_circuit.html">Circuit</a> circ(msg.mid(i));
<a name="l00192"></a>00192     <span class="keywordflow">if</span> (circ.isValid())
<a name="l00193"></a>00193       emit <a class="code" href="class_tor_events.html#ace5346dc0a16406d1955f785d078df69">circuitStatusChanged</a>(circ);
<a name="l00194"></a>00194   }
<a name="l00195"></a>00195 }
<a name="l00196"></a>00196 <span class="comment"></span>
<a name="l00197"></a>00197 <span class="comment">/** Handle a stream status event. The format of this message is:</span>
<a name="l00198"></a>00198 <span class="comment"> *     </span>
<a name="l00199"></a>00199 <span class="comment"> *    &quot;650&quot; SP &quot;STREAM&quot; SP StreamID SP StreamStatus SP CircID SP Target SP </span>
<a name="l00200"></a>00200 <span class="comment"> *     StreamStatus =</span>
<a name="l00201"></a>00201 <span class="comment"> *                 &quot;NEW&quot;          / ; New request to connect</span>
<a name="l00202"></a>00202 <span class="comment"> *                 &quot;NEWRESOLVE&quot;   / ; New request to resolve an address</span>
<a name="l00203"></a>00203 <span class="comment"> *                 &quot;SENTCONNECT&quot;  / ; Sent a connect cell along a circuit</span>
<a name="l00204"></a>00204 <span class="comment"> *                 &quot;SENTRESOLVE&quot;  / ; Sent a resolve cell along a circuit</span>
<a name="l00205"></a>00205 <span class="comment"> *                 &quot;SUCCEEDED&quot;    / ; Received a reply; stream established</span>
<a name="l00206"></a>00206 <span class="comment"> *                 &quot;FAILED&quot;       / ; Stream failed and not retriable.</span>
<a name="l00207"></a>00207 <span class="comment"> *                 &quot;CLOSED&quot;       / ; Stream closed</span>
<a name="l00208"></a>00208 <span class="comment"> *                 &quot;DETACHED&quot;       ; Detached from circuit; still retriable.</span>
<a name="l00209"></a>00209 <span class="comment"> *      Target = Address &quot;:&quot; Port</span>
<a name="l00210"></a>00210 <span class="comment"> *</span>
<a name="l00211"></a>00211 <span class="comment"> *  If the circuit ID is 0, then the stream is unattached.      </span>
<a name="l00212"></a>00212 <span class="comment"> */</span>
<a name="l00213"></a>00213 <span class="keywordtype">void</span>
<a name="l00214"></a><a class="code" href="class_tor_events.html#a94672855e722c561fff41d25b2fcddfe">00214</a> <a class="code" href="class_tor_events.html#a94672855e722c561fff41d25b2fcddfe">TorEvents::handleStreamStatus</a>(<span class="keyword">const</span> <a class="code" href="class_reply_line.html">ReplyLine</a> &amp;line)
<a name="l00215"></a>00215 {
<a name="l00216"></a>00216   QString msg = line.<a class="code" href="class_reply_line.html#ad22f50e33e6809eb25a07c090c8a960a">getMessage</a>().trimmed();
<a name="l00217"></a>00217   <span class="keywordtype">int</span> <a class="code" href="html_8cpp.html#a4a5dba6492ea149585950c59c210ff47">i</a>  = msg.indexOf(<span class="stringliteral">&quot; &quot;</span>) + 1;
<a name="l00218"></a>00218   <span class="keywordflow">if</span> (i &gt; 0) {
<a name="l00219"></a>00219     <a class="code" href="class_stream.html">Stream</a> stream = <a class="code" href="class_stream.html#aeaff90f7abf81399e207c480d1bee8a0">Stream::fromString</a>(msg.mid(i));
<a name="l00220"></a>00220     <span class="keywordflow">if</span> (stream.<a class="code" href="class_stream.html#a347b15c4c22b5c84145433725c9637e3">isValid</a>())
<a name="l00221"></a>00221       emit <a class="code" href="class_tor_events.html#a1249b178f2b514979ce5407659cfdd24">streamStatusChanged</a>(stream);
<a name="l00222"></a>00222   }
<a name="l00223"></a>00223 }
<a name="l00224"></a>00224 <span class="comment"></span>
<a name="l00225"></a>00225 <span class="comment">/** Handle a log message event. The format of this message is:</span>
<a name="l00226"></a>00226 <span class="comment"> *  The syntax is:</span>
<a name="l00227"></a>00227 <span class="comment"> *</span>
<a name="l00228"></a>00228 <span class="comment"> *     &quot;650&quot; SP Severity SP ReplyText</span>
<a name="l00229"></a>00229 <span class="comment"> *       or</span>
<a name="l00230"></a>00230 <span class="comment"> *     &quot;650+&quot; Severity CRLF Data</span>
<a name="l00231"></a>00231 <span class="comment"> *     Severity = &quot;DEBUG&quot; / &quot;INFO&quot; / &quot;NOTICE&quot; / &quot;WARN&quot;/ &quot;ERR&quot;</span>
<a name="l00232"></a>00232 <span class="comment"> */</span>
<a name="l00233"></a>00233 <span class="keywordtype">void</span>
<a name="l00234"></a><a class="code" href="class_tor_events.html#ae83a736104b606ccad26daaa657b4ae2">00234</a> <a class="code" href="class_tor_events.html#ae83a736104b606ccad26daaa657b4ae2">TorEvents::handleLogMessage</a>(<span class="keyword">const</span> <a class="code" href="class_reply_line.html">ReplyLine</a> &amp;line)
<a name="l00235"></a>00235 {
<a name="l00236"></a>00236   QString msg = line.<a class="code" href="class_reply_line.html#ad22f50e33e6809eb25a07c090c8a960a">getMessage</a>();
<a name="l00237"></a>00237   <span class="keywordtype">int</span> <a class="code" href="html_8cpp.html#a4a5dba6492ea149585950c59c210ff47">i</a> = msg.indexOf(<span class="stringliteral">&quot; &quot;</span>);
<a name="l00238"></a>00238   <a class="code" href="namespacetc.html#abb893107129c283d2eb0238e46eb3d4c">tc::Severity</a> severity = <a class="code" href="namespacetc.html#ab895ea051eb9251ab84ade452579b981">tc::severityFromString</a>(msg.mid(0, i));
<a name="l00239"></a>00239   QString logLine = (line.<a class="code" href="class_reply_line.html#a91aee47e5e25623268fb52986bc954ee">getData</a>().size() &gt; 0 ? line.<a class="code" href="class_reply_line.html#a91aee47e5e25623268fb52986bc954ee">getData</a>().join(<span class="stringliteral">&quot;\n&quot;</span>) :
<a name="l00240"></a>00240                                                  msg.mid(i+1));
<a name="l00241"></a>00241 
<a name="l00242"></a>00242   emit <a class="code" href="class_tor_events.html#a39a5f40a4793ee05e0622dd781a204d3">logMessage</a>(severity, logLine);
<a name="l00243"></a>00243 }
<a name="l00244"></a>00244 <span class="comment"></span>
<a name="l00245"></a>00245 <span class="comment">/** Handles a new descriptor event. The format for event messages of this type</span>
<a name="l00246"></a>00246 <span class="comment"> * is:</span>
<a name="l00247"></a>00247 <span class="comment"> *  </span>
<a name="l00248"></a>00248 <span class="comment"> *   &quot;650&quot; SP &quot;NEWDESC&quot; 1*(SP ServerID)</span>
<a name="l00249"></a>00249 <span class="comment"> */</span>
<a name="l00250"></a>00250 <span class="keywordtype">void</span>
<a name="l00251"></a><a class="code" href="class_tor_events.html#a7ace5ed4fcac504482c18f63b1e21348">00251</a> <a class="code" href="class_tor_events.html#a7ace5ed4fcac504482c18f63b1e21348">TorEvents::handleNewDescriptor</a>(<span class="keyword">const</span> <a class="code" href="class_reply_line.html">ReplyLine</a> &amp;line)
<a name="l00252"></a>00252 {
<a name="l00253"></a>00253   QString descs = line.<a class="code" href="class_reply_line.html#ad22f50e33e6809eb25a07c090c8a960a">getMessage</a>();
<a name="l00254"></a>00254   QStringList descList = descs.mid(descs.indexOf(<span class="stringliteral">&quot; &quot;</span>)+1).split(<span class="stringliteral">&quot; &quot;</span>);
<a name="l00255"></a>00255   emit <a class="code" href="class_tor_events.html#aafd39f6ef97ff4bc0537776148529606">newDescriptors</a>(descList);
<a name="l00256"></a>00256 }
<a name="l00257"></a>00257 <span class="comment"></span>
<a name="l00258"></a>00258 <span class="comment">/** Handles a new or updated address mapping event. The format for event</span>
<a name="l00259"></a>00259 <span class="comment"> * messages of this type is:</span>
<a name="l00260"></a>00260 <span class="comment"> *</span>
<a name="l00261"></a>00261 <span class="comment"> *   &quot;650&quot; SP &quot;ADDRMAP&quot; SP Address SP Address SP Expiry</span>
<a name="l00262"></a>00262 <span class="comment"> *   Expiry = DQUOTE ISOTime DQUOTE / &quot;NEVER&quot;</span>
<a name="l00263"></a>00263 <span class="comment"> *</span>
<a name="l00264"></a>00264 <span class="comment"> *   Expiry is expressed as the local time (rather than GMT).</span>
<a name="l00265"></a>00265 <span class="comment"> */</span>
<a name="l00266"></a>00266 <span class="keywordtype">void</span>
<a name="l00267"></a><a class="code" href="class_tor_events.html#a162d8b646b47cc3f66d3db437d103bca">00267</a> <a class="code" href="class_tor_events.html#a162d8b646b47cc3f66d3db437d103bca">TorEvents::handleAddressMap</a>(<span class="keyword">const</span> <a class="code" href="class_reply_line.html">ReplyLine</a> &amp;line)
<a name="l00268"></a>00268 {
<a name="l00269"></a>00269   QStringList msg = line.<a class="code" href="class_reply_line.html#ad22f50e33e6809eb25a07c090c8a960a">getMessage</a>().split(<span class="stringliteral">&quot; &quot;</span>);
<a name="l00270"></a>00270   <span class="keywordflow">if</span> (msg.size() &gt;= 4) {
<a name="l00271"></a>00271     QDateTime expires;
<a name="l00272"></a>00272     <span class="keywordflow">if</span> (msg.size() &gt;= 5 &amp;&amp; msg.at(3) != <span class="stringliteral">&quot;NEVER&quot;</span>)
<a name="l00273"></a>00273       expires = QDateTime::fromString(msg.at(3) + <span class="stringliteral">&quot; &quot;</span> + msg.at(4), <a class="code" href="_address_map_8cpp.html#ab88071d2dae07659090a23e67a1e4d7f">DATE_FMT</a>);
<a name="l00274"></a>00274     emit <a class="code" href="class_tor_events.html#a4a92733016b756111b95e51c335d269c">addressMapped</a>(msg.at(1), msg.at(2), expires);
<a name="l00275"></a>00275   }
<a name="l00276"></a>00276 }
<a name="l00277"></a>00277 <span class="comment"></span>
<a name="l00278"></a>00278 <span class="comment">/** Handles a Tor status event. The format for event messages of this type is:</span>
<a name="l00279"></a>00279 <span class="comment"> *</span>
<a name="l00280"></a>00280 <span class="comment"> *  &quot;650&quot; SP StatusType SP StatusSeverity SP StatusAction</span>
<a name="l00281"></a>00281 <span class="comment"> *                                           [SP StatusArguments] CRLF</span>
<a name="l00282"></a>00282 <span class="comment"> *</span>
<a name="l00283"></a>00283 <span class="comment"> *  StatusType = &quot;STATUS_GENERAL&quot; / &quot;STATUS_CLIENT&quot; / &quot;STATUS_SERVER&quot;</span>
<a name="l00284"></a>00284 <span class="comment"> *  StatusSeverity = &quot;NOTICE&quot; / &quot;WARN&quot; / &quot;ERR&quot;</span>
<a name="l00285"></a>00285 <span class="comment"> *  StatusAction = 1*ALPHA</span>
<a name="l00286"></a>00286 <span class="comment"> *  StatusArguments = StatusArgument *(SP StatusArgument)</span>
<a name="l00287"></a>00287 <span class="comment"> *  StatusArgument = StatusKeyword &#39;=&#39; StatusValue</span>
<a name="l00288"></a>00288 <span class="comment"> *  StatusKeyword = 1*(ALNUM / &quot;_&quot;)</span>
<a name="l00289"></a>00289 <span class="comment"> *  StatusValue = 1*(ALNUM / &#39;_&#39;)  / QuotedString</span>
<a name="l00290"></a>00290 <span class="comment"> */</span>
<a name="l00291"></a>00291 <span class="keywordtype">void</span>
<a name="l00292"></a><a class="code" href="class_tor_events.html#aef7e7863cf6d8ce36018bbdccca3a1f8">00292</a> <a class="code" href="class_tor_events.html#aef7e7863cf6d8ce36018bbdccca3a1f8">TorEvents::handleStatusEvent</a>(<a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bf">Event</a> e, <span class="keyword">const</span> <a class="code" href="class_reply_line.html">ReplyLine</a> &amp;line)
<a name="l00293"></a>00293 {
<a name="l00294"></a>00294   QString status;
<a name="l00295"></a>00295   <a class="code" href="namespacetc.html#abb893107129c283d2eb0238e46eb3d4c">tc::Severity</a> severity;
<a name="l00296"></a>00296   QHash&lt;QString,QString&gt; args;
<a name="l00297"></a>00297   QString msg = line.<a class="code" href="class_reply_line.html#ad22f50e33e6809eb25a07c090c8a960a">getMessage</a>();
<a name="l00298"></a>00298   
<a name="l00299"></a>00299   severity = <a class="code" href="namespacetc.html#ab895ea051eb9251ab84ade452579b981">tc::severityFromString</a>(msg.section(<span class="charliteral">&#39; &#39;</span>, 1, 1));
<a name="l00300"></a>00300   status   = msg.section(<span class="charliteral">&#39; &#39;</span>, 2, 2);
<a name="l00301"></a>00301   args     = <a class="code" href="stringutil_8cpp.html#a2be53af228dd65232621f02a47bd8488">string_parse_keyvals</a>(msg.section(<span class="charliteral">&#39; &#39;</span>, 3));
<a name="l00302"></a>00302   <span class="keywordflow">switch</span> (e) {
<a name="l00303"></a>00303     <span class="keywordflow">case</span> <a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bfa5f1d41f1693f31d72e3e6c037cf7ff01">ClientStatus</a>:
<a name="l00304"></a>00304       <a class="code" href="class_tor_events.html#a3a7aad7a92cf95b351712af01649a636">handleClientStatusEvent</a>(severity, status, args);
<a name="l00305"></a>00305       <span class="keywordflow">break</span>;
<a name="l00306"></a>00306 
<a name="l00307"></a>00307     <span class="keywordflow">case</span> <a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bfa1a28286d958ff505ab63722214395e8f">ServerStatus</a>:
<a name="l00308"></a>00308       <a class="code" href="class_tor_events.html#afbbd10a91a6a7b71a7b40ef4194f35fa">handleServerStatusEvent</a>(severity, status, args);
<a name="l00309"></a>00309       <span class="keywordflow">break</span>;
<a name="l00310"></a>00310 
<a name="l00311"></a>00311     <span class="keywordflow">case</span> <a class="code" href="class_tor_events.html#a08aed30fd27832e89f96114617da72bfa0f4ce116650cb34661bfe23344562765">GeneralStatus</a>:
<a name="l00312"></a>00312       <a class="code" href="class_tor_events.html#a2289790fffbb6b224a135359d337a8dc">handleGeneralStatusEvent</a>(severity, status, args);
<a name="l00313"></a>00313       <span class="keywordflow">break</span>;
<a name="l00314"></a>00314 
<a name="l00315"></a>00315     <span class="keywordflow">default</span>:
<a name="l00316"></a>00316       <span class="keywordflow">break</span>;
<a name="l00317"></a>00317   }
<a name="l00318"></a>00318 }
<a name="l00319"></a>00319 <span class="comment"></span>
<a name="l00320"></a>00320 <span class="comment">/** Parses and emits a general Tor status event. */</span>
<a name="l00321"></a>00321 <span class="keywordtype">void</span>
<a name="l00322"></a><a class="code" href="class_tor_events.html#a2289790fffbb6b224a135359d337a8dc">00322</a> <a class="code" href="class_tor_events.html#a2289790fffbb6b224a135359d337a8dc">TorEvents::handleGeneralStatusEvent</a>(<a class="code" href="namespacetc.html#abb893107129c283d2eb0238e46eb3d4c">tc::Severity</a> severity,
<a name="l00323"></a>00323                                     <span class="keyword">const</span> QString &amp;action,
<a name="l00324"></a>00324                                     <span class="keyword">const</span> QHash&lt;QString,QString&gt; &amp;args)
<a name="l00325"></a>00325 {
<a name="l00326"></a>00326   <span class="keywordflow">if</span> (! action.compare(<span class="stringliteral">&quot;DANGEROUS_TOR_VERSION&quot;</span>, Qt::CaseInsensitive)) {
<a name="l00327"></a>00327     QString reason = args.value(<span class="stringliteral">&quot;REASON&quot;</span>);
<a name="l00328"></a>00328     QString current = args.value(<span class="stringliteral">&quot;CURRENT&quot;</span>);
<a name="l00329"></a>00329     QStringList recommended = args.value(<span class="stringliteral">&quot;RECOMMENDED&quot;</span>)
<a name="l00330"></a>00330                                   .split(<span class="stringliteral">&quot;,&quot;</span>, QString::SkipEmptyParts);
<a name="l00331"></a>00331     <span class="keywordflow">if</span> (! reason.compare(<span class="stringliteral">&quot;NEW&quot;</span>, Qt::CaseInsensitive))
<a name="l00332"></a>00332       emit <a class="code" href="class_tor_events.html#a79a575fba25756532a78ab48276c3283">dangerousTorVersion</a>(<a class="code" href="namespacetc.html#a8389db682e80cb6921e26b529e2ec52ca0a66096868442d23856085d115addb0b">tc::NewTorVersion</a>, current, recommended);
<a name="l00333"></a>00333     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (! reason.compare(<span class="stringliteral">&quot;UNRECOMMENDED&quot;</span>, Qt::CaseInsensitive))
<a name="l00334"></a>00334       emit <a class="code" href="class_tor_events.html#a79a575fba25756532a78ab48276c3283">dangerousTorVersion</a>(<a class="code" href="namespacetc.html#a8389db682e80cb6921e26b529e2ec52ca2edcd3c836745226bda504279710e413">tc::UnrecommendedTorVersion</a>, current, recommended);
<a name="l00335"></a>00335     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (! reason.compare(<span class="stringliteral">&quot;OBSOLETE&quot;</span>, Qt::CaseInsensitive)
<a name="l00336"></a>00336                || ! reason.compare(<span class="stringliteral">&quot;OLD&quot;</span>, Qt::CaseInsensitive))
<a name="l00337"></a>00337       emit <a class="code" href="class_tor_events.html#a79a575fba25756532a78ab48276c3283">dangerousTorVersion</a>(<a class="code" href="namespacetc.html#a8389db682e80cb6921e26b529e2ec52cae640350a91e5d706c041b20d8209946c">tc::ObsoleteTorVersion</a>, current, recommended);
<a name="l00338"></a>00338   } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (! action.compare(<span class="stringliteral">&quot;CLOCK_SKEW&quot;</span>, Qt::CaseInsensitive)) {
<a name="l00339"></a>00339     <span class="keywordtype">int</span> skew;
<a name="l00340"></a>00340     <span class="keywordtype">bool</span> ok = <span class="keyword">false</span>;
<a name="l00341"></a>00341     <span class="keywordflow">if</span> (args.contains(<span class="stringliteral">&quot;SKEW&quot;</span>))
<a name="l00342"></a>00342       skew = args.value(<span class="stringliteral">&quot;SKEW&quot;</span>).toInt(&amp;ok);
<a name="l00343"></a>00343     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (args.contains(<span class="stringliteral">&quot;MIN_SKEW&quot;</span>))
<a name="l00344"></a>00344       skew = args.value(<span class="stringliteral">&quot;MIN_SKEW&quot;</span>).toInt(&amp;ok);
<a name="l00345"></a>00345     <span class="keywordflow">if</span> (ok)
<a name="l00346"></a>00346       emit <a class="code" href="class_tor_events.html#a6e7c92749d962b11441563b19d713148">clockSkewed</a>(skew, args.value(<span class="stringliteral">&quot;SOURCE&quot;</span>));
<a name="l00347"></a>00347   } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (! action.compare(<span class="stringliteral">&quot;BUG&quot;</span>, Qt::CaseInsensitive)) {
<a name="l00348"></a>00348     emit <a class="code" href="class_tor_events.html#a90f62a5621b32c182b2a786807392902">bug</a>(args.value(<span class="stringliteral">&quot;REASON&quot;</span>));
<a name="l00349"></a>00349   }
<a name="l00350"></a>00350 }
<a name="l00351"></a>00351 <span class="comment"></span>
<a name="l00352"></a>00352 <span class="comment">/** Parses and emits a Tor client status event. */</span>
<a name="l00353"></a>00353 <span class="keywordtype">void</span>
<a name="l00354"></a><a class="code" href="class_tor_events.html#a3a7aad7a92cf95b351712af01649a636">00354</a> <a class="code" href="class_tor_events.html#a3a7aad7a92cf95b351712af01649a636">TorEvents::handleClientStatusEvent</a>(<a class="code" href="namespacetc.html#abb893107129c283d2eb0238e46eb3d4c">tc::Severity</a> severity,
<a name="l00355"></a>00355                                    <span class="keyword">const</span> QString &amp;action,
<a name="l00356"></a>00356                                    <span class="keyword">const</span> QHash&lt;QString,QString&gt; &amp;args)
<a name="l00357"></a>00357 {
<a name="l00358"></a>00358   <span class="keywordflow">if</span> (! action.compare(<span class="stringliteral">&quot;CIRCUIT_ESTABLISHED&quot;</span>, Qt::CaseInsensitive)) {
<a name="l00359"></a>00359     emit <a class="code" href="class_tor_events.html#a49355793c98b0bc802be587d7db1a318">circuitEstablished</a>();
<a name="l00360"></a>00360   } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (! action.compare(<span class="stringliteral">&quot;DANGEROUS_PORT&quot;</span>, Qt::CaseInsensitive)) {
<a name="l00361"></a>00361     <span class="keywordtype">bool</span> reject = ! args.value(<span class="stringliteral">&quot;RESULT&quot;</span>).compare(<span class="stringliteral">&quot;REJECT&quot;</span>, Qt::CaseInsensitive);
<a name="l00362"></a>00362     emit <a class="code" href="class_tor_events.html#a25fdc7f80b893ecdf9fd66776fd09170">dangerousPort</a>(args.value(<span class="stringliteral">&quot;PORT&quot;</span>).toUInt(), reject);
<a name="l00363"></a>00363   } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (! action.compare(<span class="stringliteral">&quot;DANGEROUS_SOCKS&quot;</span>, Qt::CaseInsensitive)) {
<a name="l00364"></a>00364     emit <a class="code" href="class_tor_events.html#a79fded852c2c70fa0c8539b2e9441fc0">socksError</a>(<a class="code" href="namespacetc.html#ab29556af3a71a9c8768ab9ae1e822191a47637981959f7c19b522f1bfc5cba28e">tc::DangerousSocksTypeError</a>, args.value(<span class="stringliteral">&quot;ADDRESS&quot;</span>));
<a name="l00365"></a>00365   } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (! action.compare(<span class="stringliteral">&quot;SOCKS_UNKNOWN_PROTOCOL&quot;</span>, Qt::CaseInsensitive)) {
<a name="l00366"></a>00366     emit <a class="code" href="class_tor_events.html#a79fded852c2c70fa0c8539b2e9441fc0">socksError</a>(<a class="code" href="namespacetc.html#ab29556af3a71a9c8768ab9ae1e822191a096c8386571a05a98bf00d4977cd3e21">tc::UnknownSocksProtocolError</a>, QString());
<a name="l00367"></a>00367   } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (! action.compare(<span class="stringliteral">&quot;SOCKS_BAD_HOSTNAME&quot;</span>, Qt::CaseInsensitive)) {
<a name="l00368"></a>00368     emit <a class="code" href="class_tor_events.html#a79fded852c2c70fa0c8539b2e9441fc0">socksError</a>(<a class="code" href="namespacetc.html#ab29556af3a71a9c8768ab9ae1e822191adca6b3ddd766b061bd5ef470c14ab4fb">tc::BadSocksHostnameError</a>, args.value(<span class="stringliteral">&quot;HOSTNAME&quot;</span>));
<a name="l00369"></a>00369   } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (! action.compare(<span class="stringliteral">&quot;BOOTSTRAP&quot;</span>, Qt::CaseInsensitive)) {
<a name="l00370"></a>00370     <a class="code" href="class_bootstrap_status.html">BootstrapStatus</a> status
<a name="l00371"></a>00371       = <a class="code" href="class_bootstrap_status.html">BootstrapStatus</a>(severity,
<a name="l00372"></a>00372                         <a class="code" href="class_bootstrap_status.html#a0e878a9a8ca87d06c565f3511bc1dd66">BootstrapStatus::statusFromString</a>(args.value(<span class="stringliteral">&quot;TAG&quot;</span>)),
<a name="l00373"></a>00373                         args.value(<span class="stringliteral">&quot;PROGRESS&quot;</span>).toInt(),
<a name="l00374"></a>00374                         args.value(<span class="stringliteral">&quot;SUMMARY&quot;</span>),
<a name="l00375"></a>00375                         args.value(<span class="stringliteral">&quot;WARNING&quot;</span>),
<a name="l00376"></a>00376                         <a class="code" href="namespacetc.html#abebccd78ae0875fead37fd92936b465d">tc::connectionStatusReasonFromString</a>(args.value(<span class="stringliteral">&quot;REASON&quot;</span>)),
<a name="l00377"></a>00377                         <a class="code" href="class_bootstrap_status.html#a4bd91a88d99ad7157520e0d4c9b9fdf2">BootstrapStatus::actionFromString</a>(
<a name="l00378"></a>00378                         args.value(<span class="stringliteral">&quot;RECOMMENDATION&quot;</span>)));
<a name="l00379"></a>00379     emit <a class="code" href="class_tor_events.html#a77bb1fb761e4ad941a56a046bc0d0cf4">bootstrapStatusChanged</a>(status);
<a name="l00380"></a>00380   }
<a name="l00381"></a>00381 }
<a name="l00382"></a>00382 <span class="comment"></span>
<a name="l00383"></a>00383 <span class="comment">/** Parses and emits a Tor server status event. */</span>
<a name="l00384"></a>00384 <span class="keywordtype">void</span>
<a name="l00385"></a><a class="code" href="class_tor_events.html#afbbd10a91a6a7b71a7b40ef4194f35fa">00385</a> <a class="code" href="class_tor_events.html#afbbd10a91a6a7b71a7b40ef4194f35fa">TorEvents::handleServerStatusEvent</a>(<a class="code" href="namespacetc.html#abb893107129c283d2eb0238e46eb3d4c">tc::Severity</a> severity,
<a name="l00386"></a>00386                                    <span class="keyword">const</span> QString &amp;action,
<a name="l00387"></a>00387                                    <span class="keyword">const</span> QHash&lt;QString,QString&gt; &amp;args)
<a name="l00388"></a>00388 {
<a name="l00389"></a>00389   <span class="keywordflow">if</span> (! action.compare(<span class="stringliteral">&quot;EXTERNAL_ADDRESS&quot;</span>, Qt::CaseInsensitive)) {
<a name="l00390"></a>00390     emit <a class="code" href="class_tor_events.html#a4a7eb62b180f3706301d201fa5f18de4">externalAddressChanged</a>(QHostAddress(args.value(<span class="stringliteral">&quot;ADDRESS&quot;</span>)),
<a name="l00391"></a>00391                                 args.value(<span class="stringliteral">&quot;HOSTNAME&quot;</span>));
<a name="l00392"></a>00392   } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (! action.compare(<span class="stringliteral">&quot;CHECKING_REACHABILITY&quot;</span>, Qt::CaseInsensitive)) {
<a name="l00393"></a>00393     <span class="keywordflow">if</span> (args.contains(<span class="stringliteral">&quot;ORADDRESS&quot;</span>)) {
<a name="l00394"></a>00394       QPair&lt;QHostAddress,quint16&gt; pair = <a class="code" href="class_tor_events.html#a50b675f00d56916ed7997191ca3d06cb">splitAddress</a>(args.value(<span class="stringliteral">&quot;ORADDRESS&quot;</span>));
<a name="l00395"></a>00395       <span class="keywordflow">if</span> (! pair.first.isNull())
<a name="l00396"></a>00396         emit <a class="code" href="class_tor_events.html#a84d5c8946323cdd327a883958fc549de">checkingOrPortReachability</a>(pair.first, pair.second);
<a name="l00397"></a>00397     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (args.contains(<span class="stringliteral">&quot;DIRADDRESS&quot;</span>)) {
<a name="l00398"></a>00398       QPair&lt;QHostAddress,quint16&gt; pair = <a class="code" href="class_tor_events.html#a50b675f00d56916ed7997191ca3d06cb">splitAddress</a>(args.value(<span class="stringliteral">&quot;DIRADDRESS&quot;</span>));
<a name="l00399"></a>00399       <span class="keywordflow">if</span> (! pair.first.isNull())
<a name="l00400"></a>00400         emit <a class="code" href="class_tor_events.html#ad0f0f00e1cdd9cdfcf65029059ac7f15">checkingDirPortReachability</a>(pair.first, pair.second);
<a name="l00401"></a>00401     }
<a name="l00402"></a>00402   } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (! action.compare(<span class="stringliteral">&quot;REACHABILITY_SUCCEEDED&quot;</span>, Qt::CaseInsensitive)) {
<a name="l00403"></a>00403     <span class="keywordflow">if</span> (args.contains(<span class="stringliteral">&quot;ORADDRESS&quot;</span>)) {
<a name="l00404"></a>00404       QPair&lt;QHostAddress,quint16&gt; pair = <a class="code" href="class_tor_events.html#a50b675f00d56916ed7997191ca3d06cb">splitAddress</a>(args.value(<span class="stringliteral">&quot;ORADDRESS&quot;</span>));
<a name="l00405"></a>00405       <span class="keywordflow">if</span> (! pair.first.isNull())
<a name="l00406"></a>00406         emit <a class="code" href="class_tor_events.html#a32a9aaa46971b5f301ad76a68a96803d">orPortReachabilityFinished</a>(pair.first, pair.second, <span class="keyword">true</span>);
<a name="l00407"></a>00407     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (args.contains(<span class="stringliteral">&quot;DIRADDRESS&quot;</span>)) {
<a name="l00408"></a>00408       QPair&lt;QHostAddress,quint16&gt; pair = <a class="code" href="class_tor_events.html#a50b675f00d56916ed7997191ca3d06cb">splitAddress</a>(args.value(<span class="stringliteral">&quot;DIRADDRESS&quot;</span>));
<a name="l00409"></a>00409       <span class="keywordflow">if</span> (! pair.first.isNull())
<a name="l00410"></a>00410         emit <a class="code" href="class_tor_events.html#ae2cb999a7c9fbbb416cbac396ce9877b">dirPortReachabilityFinished</a>(pair.first, pair.second, <span class="keyword">true</span>);
<a name="l00411"></a>00411     }
<a name="l00412"></a>00412   } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (! action.compare(<span class="stringliteral">&quot;REACHABILITY_FAILED&quot;</span>, Qt::CaseInsensitive)) {
<a name="l00413"></a>00413     <span class="keywordflow">if</span> (args.contains(<span class="stringliteral">&quot;ORADDRESS&quot;</span>)) {
<a name="l00414"></a>00414       QPair&lt;QHostAddress,quint16&gt; pair = <a class="code" href="class_tor_events.html#a50b675f00d56916ed7997191ca3d06cb">splitAddress</a>(args.value(<span class="stringliteral">&quot;ORADDRESS&quot;</span>));
<a name="l00415"></a>00415       <span class="keywordflow">if</span> (! pair.first.isNull())
<a name="l00416"></a>00416         emit <a class="code" href="class_tor_events.html#a32a9aaa46971b5f301ad76a68a96803d">orPortReachabilityFinished</a>(pair.first, pair.second, <span class="keyword">false</span>);
<a name="l00417"></a>00417     } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (args.contains(<span class="stringliteral">&quot;DIRADDRESS&quot;</span>)) {
<a name="l00418"></a>00418       QPair&lt;QHostAddress,quint16&gt; pair = <a class="code" href="class_tor_events.html#a50b675f00d56916ed7997191ca3d06cb">splitAddress</a>(args.value(<span class="stringliteral">&quot;DIRADDRESS&quot;</span>));
<a name="l00419"></a>00419       <span class="keywordflow">if</span> (! pair.first.isNull())
<a name="l00420"></a>00420         emit <a class="code" href="class_tor_events.html#ae2cb999a7c9fbbb416cbac396ce9877b">dirPortReachabilityFinished</a>(pair.first, pair.second, <span class="keyword">false</span>);
<a name="l00421"></a>00421     }
<a name="l00422"></a>00422   } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (! action.compare(<span class="stringliteral">&quot;GOOD_SERVER_DESCRIPTOR&quot;</span>, Qt::CaseInsensitive)) {
<a name="l00423"></a>00423     emit <a class="code" href="class_tor_events.html#a72175cc254e18a1cedb2e0231749645f">serverDescriptorAccepted</a>();
<a name="l00424"></a>00424   } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (! action.compare(<span class="stringliteral">&quot;ACCEPTED_SERVER_DESCRIPTOR&quot;</span>, Qt::CaseInsensitive)) {
<a name="l00425"></a>00425     QPair&lt;QHostAddress,quint16&gt; pair = <a class="code" href="class_tor_events.html#a50b675f00d56916ed7997191ca3d06cb">splitAddress</a>(args.value(<span class="stringliteral">&quot;DIRAUTH&quot;</span>));
<a name="l00426"></a>00426     <span class="keywordflow">if</span> (! pair.first.isNull())
<a name="l00427"></a>00427       emit <a class="code" href="class_tor_events.html#a72175cc254e18a1cedb2e0231749645f">serverDescriptorAccepted</a>(pair.first, pair.second);
<a name="l00428"></a>00428   } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (! action.compare(<span class="stringliteral">&quot;BAD_SERVER_DESCRIPTOR&quot;</span>, Qt::CaseInsensitive)) {
<a name="l00429"></a>00429     QPair&lt;QHostAddress,quint16&gt; pair = <a class="code" href="class_tor_events.html#a50b675f00d56916ed7997191ca3d06cb">splitAddress</a>(args.value(<span class="stringliteral">&quot;DIRAUTH&quot;</span>));
<a name="l00430"></a>00430     <span class="keywordflow">if</span> (! pair.first.isNull())
<a name="l00431"></a>00431       emit <a class="code" href="class_tor_events.html#a0a0344391536bd8757d2a4f3a81a4ab5">serverDescriptorRejected</a>(pair.first, pair.second,
<a name="l00432"></a>00432                                     args.value(<span class="stringliteral">&quot;REASON&quot;</span>));
<a name="l00433"></a>00433   } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (! action.compare(<span class="stringliteral">&quot;DNS_HIJACKED&quot;</span>, Qt::CaseInsensitive)) {
<a name="l00434"></a>00434     emit <a class="code" href="class_tor_events.html#a9598447c031fa8886b71b6d860f098d5">dnsHijacked</a>();
<a name="l00435"></a>00435   } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (! action.compare(<span class="stringliteral">&quot;DNS_USELESS&quot;</span>, Qt::CaseInsensitive)) {
<a name="l00436"></a>00436     emit <a class="code" href="class_tor_events.html#ac911333c453887fdffd74e2a074864ca">dnsUseless</a>();
<a name="l00437"></a>00437   }
<a name="l00438"></a>00438 }
<a name="l00439"></a>00439 <span class="comment"></span>
<a name="l00440"></a>00440 <span class="comment">/** Splits a string in the form &quot;IP:PORT&quot; into a QHostAddress and quint16</span>
<a name="l00441"></a>00441 <span class="comment"> * pair. If either portion is invalid, a default-constructed QPair() is</span>
<a name="l00442"></a>00442 <span class="comment"> * returned. */</span>
<a name="l00443"></a>00443 QPair&lt;QHostAddress,quint16&gt;
<a name="l00444"></a><a class="code" href="class_tor_events.html#a50b675f00d56916ed7997191ca3d06cb">00444</a> <a class="code" href="class_tor_events.html#a50b675f00d56916ed7997191ca3d06cb">TorEvents::splitAddress</a>(<span class="keyword">const</span> QString &amp;address)
<a name="l00445"></a>00445 {
<a name="l00446"></a>00446   <span class="keywordtype">bool</span> ok;
<a name="l00447"></a>00447   <span class="keywordtype">int</span> idx = address.indexOf(<span class="stringliteral">&quot;:&quot;</span>);
<a name="l00448"></a>00448   <span class="keywordflow">if</span> (idx &lt;= 0 || idx &gt;= address.length()-1)
<a name="l00449"></a>00449     <span class="keywordflow">return</span> QPair&lt;QHostAddress,quint16&gt;();
<a name="l00450"></a>00450 
<a name="l00451"></a>00451   QHostAddress ip = QHostAddress(address.mid(0, idx));
<a name="l00452"></a>00452   quint16 port = <span class="keyword">static_cast&lt;</span>quint16<span class="keyword">&gt;</span>(address.mid(idx+1).toUInt(&amp;ok));
<a name="l00453"></a>00453   <span class="keywordflow">if</span> (ip.isNull() || ! ok)
<a name="l00454"></a>00454     <span class="keywordflow">return</span> QPair&lt;QHostAddress,quint16&gt;();
<a name="l00455"></a>00455   <span class="keywordflow">return</span> QPair&lt;QHostAddress,quint16&gt;(ip, port);
<a name="l00456"></a>00456 }
<a name="l00457"></a>00457 
<a name="l00458"></a>00458 
</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>