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

[vidalia-svn] r1259: Add methods for getting one or more router descriptors by na (in trunk/src: control gui/network)



Author: edmanm
Date: 2006-10-02 22:28:33 -0400 (Mon, 02 Oct 2006)
New Revision: 1259

Modified:
   trunk/src/control/torcontrol.cpp
   trunk/src/control/torcontrol.h
   trunk/src/gui/network/netviewer.cpp
Log:
Add methods for getting one or more router descriptors by name.


Modified: trunk/src/control/torcontrol.cpp
===================================================================
--- trunk/src/control/torcontrol.cpp	2006-10-02 05:54:33 UTC (rev 1258)
+++ trunk/src/control/torcontrol.cpp	2006-10-03 02:28:33 UTC (rev 1259)
@@ -550,14 +550,29 @@
   return resetConf(QStringList() << key, errmsg);
 }
 
+/** Gets the descriptor for the specified router name. */
+RouterDescriptor
+TorControl::getDescriptorByName(QString name, QString *errmsg)
+{
+  QList<RouterDescriptor> rdlist;
+  RouterDescriptor rd;
+  
+  rdlist = getDescriptorListByName(QStringList() << name, errmsg);
+  if (!rdlist.isEmpty()) {
+    rd = (RouterDescriptor)rdlist.takeFirst();
+    return rd;
+  }
+  return RouterDescriptor();
+}
+
 /** Gets the descriptor for the specified ID. */
 RouterDescriptor
-TorControl::getRouterDescriptor(QString id, QString *errmsg)
+TorControl::getDescriptorById(QString id, QString *errmsg)
 {
   QList<RouterDescriptor> rdlist;
   RouterDescriptor rd;
   
-  rdlist = getRouterDescriptors(QStringList() << id, errmsg);
+  rdlist = getDescriptorListById(QStringList() << id, errmsg);
   if (!rdlist.isEmpty()) {
     rd = (RouterDescriptor)rdlist.takeFirst();
     return rd;
@@ -565,9 +580,40 @@
   return RouterDescriptor();
 }
 
+/** Gets router descriptors for all names in <b>nameList</b>. */
+QList<RouterDescriptor>
+TorControl::getDescriptorListByName(QStringList nameList, QString *errmsg)
+{
+  ControlCommand cmd("GETINFO");
+  ControlReply reply;
+  QList<RouterDescriptor> rdlist;
+  
+  /* If there are no IDs in the list, then return now. */
+  if (nameList.isEmpty()) {
+    return QList<RouterDescriptor>();
+  }
+  
+  /* Build up the the getinfo arguments from the list of names */
+  foreach (QString name, nameList) {
+    cmd.addArgument("desc/name/"+ name);
+  }
+  
+  /* Request the list of router descriptors */
+  if (send(cmd, reply, errmsg)) {
+    foreach (ReplyLine line, reply.getLines()) {
+      /* Check if we got a "250 OK" and descriptor data. */
+      if (line.getStatus() == "250" && !line.getData().isEmpty()) {
+        /* Parse the router descriptor data */
+        rdlist << RouterDescriptor(line.getData());
+      }
+    }
+  }
+  return rdlist;
+}
+
 /** Gets router descriptors for all IDs in <b>idlist</b>. */
 QList<RouterDescriptor>
-TorControl::getRouterDescriptors(QStringList idlist, QString *errmsg)
+TorControl::getDescriptorListById(QStringList idlist, QString *errmsg)
 {
   ControlCommand cmd("GETINFO");
   ControlReply reply;
@@ -613,7 +659,7 @@
   /* Get a list of all router IDs Tor currently know about */
   QStringList idList = getRouterIDList(errmsg);
   /* Get descriptors for each of those routers */
-  return getRouterDescriptors(idList, errmsg);
+  return getDescriptorListById(idList, errmsg);
 }
 
 /** Gets a list of router IDs for all routers Tor knows about. */

Modified: trunk/src/control/torcontrol.h
===================================================================
--- trunk/src/control/torcontrol.h	2006-10-02 05:54:33 UTC (rev 1258)
+++ trunk/src/control/torcontrol.h	2006-10-03 02:28:33 UTC (rev 1259)
@@ -104,10 +104,14 @@
   /** Tells Tor to reset a configuration key back to its default value. */
   bool resetConf(QString key, QString *errmsg = 0);
 
+  /** Gets a descriptor for the given router name. */
+  RouterDescriptor getDescriptorByName(QString name, QString *errmsg = 0);
   /** Gets a descriptor for the given router ID. */
-  RouterDescriptor getRouterDescriptor(QString id, QString *errmsg = 0);
+  RouterDescriptor getDescriptorById(QString id, QString *errmsg = 0);
+  /** Gets descriptors for the given list of router names. */
+  QList<RouterDescriptor> getDescriptorListByName(QStringList names, QString *errmsg = 0);
   /** Gets descriptors for the given list of router IDs. */
-  QList<RouterDescriptor> getRouterDescriptors(QStringList ids, QString *errmsg = 0);
+  QList<RouterDescriptor> getDescriptorListById(QStringList ids, QString *errmsg = 0);
   /** Gets a list of descriptors for all routers Tor knows about. */
   QList<RouterDescriptor> getRouterList(QString *errmsg = 0);
   /** Gets a list of router IDs for all routers Tor knows about. */

Modified: trunk/src/gui/network/netviewer.cpp
===================================================================
--- trunk/src/gui/network/netviewer.cpp	2006-10-02 05:54:33 UTC (rev 1258)
+++ trunk/src/gui/network/netviewer.cpp	2006-10-03 02:28:33 UTC (rev 1259)
@@ -229,7 +229,7 @@
 NetViewer::loadDescriptors(QStringList ids)
 {
   /* Get descriptors for all the given IDs */
-  QList<RouterDescriptor> rds = _torControl->getRouterDescriptors(ids);
+  QList<RouterDescriptor> rds = _torControl->getDescriptorListById(ids);
   
   foreach (RouterDescriptor rd, rds) {
     /* Load the router descriptor and add it to the router list. */