[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[vidalia-svn] r2574: Add a method for fetching descriptor annotations for a route (in vidalia: . trunk/src/torcontrol)



Author: edmanm
Date: 2008-05-12 21:42:47 -0400 (Mon, 12 May 2008)
New Revision: 2574

Modified:
   vidalia/
   vidalia/trunk/src/torcontrol/torcontrol.cpp
   vidalia/trunk/src/torcontrol/torcontrol.h
Log:
 r304@thebe:  edmanm | 2008-05-12 21:35:52 -0400
 Add a method for fetching descriptor annotations for a router given its ID.



Property changes on: vidalia
___________________________________________________________________
 svk:merge ticket from /local/vidalia [r304] on 45a62a8a-8088-484c-baad-c7b3e776dd32

Modified: vidalia/trunk/src/torcontrol/torcontrol.cpp
===================================================================
--- vidalia/trunk/src/torcontrol/torcontrol.cpp	2008-05-10 13:19:53 UTC (rev 2573)
+++ vidalia/trunk/src/torcontrol/torcontrol.cpp	2008-05-13 01:42:47 UTC (rev 2574)
@@ -907,6 +907,34 @@
   return networkStatus;
 }
 
+/** Returns the annotations for the router whose fingerprint matches
+ * <b>id</b>. If <b>id</b> is invalid or the router's annotations cannot be
+ * parsed, then an empty DescriptorAnnotations is returned and <b>errmsg</b>
+ * is set if it's not NULL. (Tor >= 0.2.0.13-alpha only) */
+DescriptorAnnotations
+TorControl::getDescriptorAnnotations(const QString &id, QString *errmsg)
+{
+  QStringList lines = getInfo("desc-annotations/id/"+id, errmsg).toStringList();
+  DescriptorAnnotations annotations;
+  QString key, value;
+
+  foreach (QString line, lines) {
+    int idx = line.indexOf(" ");
+    
+    /* Extract the annotation key */
+    key = line.mid(0, idx); 
+    if (key.startsWith("@"))
+      key = key.remove(0, 1);
+    
+    /* Extract the annotation value (if present) */
+    if (idx > 0 && idx < line.length()-1)
+      annotations.insert(key, line.mid(idx + 1).trimmed());
+    else
+      annotations.insert(key, QString());
+  }
+  return annotations;
+}
+
 /** Gets a list of current circuits. */
 QList<Circuit>
 TorControl::getCircuits(QString *errmsg)

Modified: vidalia/trunk/src/torcontrol/torcontrol.h
===================================================================
--- vidalia/trunk/src/torcontrol/torcontrol.h	2008-05-10 13:19:53 UTC (rev 2573)
+++ vidalia/trunk/src/torcontrol/torcontrol.h	2008-05-13 01:42:47 UTC (rev 2574)
@@ -37,6 +37,11 @@
 #endif
 
 
+/** DescriptorAnnotations stores a map of annotation keys to (possibly empty)
+ * annotation values. */
+typedef QHash<QString,QString> DescriptorAnnotations;
+
+
 class TorControl : public QObject
 {
   Q_OBJECT
@@ -168,8 +173,13 @@
    * the network status document cannot be parsed, then an empty NetworkStatus
    * is returned. */
   NetworkStatus getNetworkStatus(QString *errmsg = 0);
+  /** Returns the annotations for the router whose fingerprint matches
+   * <b>id</b>. If <b>id</b> is invalid or the router's descriptor cannot be
+   * parsed, then an empty DescriptorAnnotations is returned and
+   * <b>errmsg</b> is set if it's not NULL. (Tor >= 0.2.0.13-alpha only) */
+  DescriptorAnnotations getDescriptorAnnotations(const QString &id,
+                                                 QString *errmsg = 0);
 
-
   /** Gets a list of current circuits. */
   CircuitList getCircuits(QString *errmsg = 0);
   /** Gets a list of current streams. */