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

[vidalia-svn] r4374: Add a TorControl::ipToCountry() method that will do a "GETIN (vidalia/trunk/src/torcontrol)



Author: edmanm
Date: 2010-08-05 16:05:41 -0400 (Thu, 05 Aug 2010)
New Revision: 4374

Modified:
   vidalia/trunk/src/torcontrol/TorControl.cpp
   vidalia/trunk/src/torcontrol/TorControl.h
Log:

Add a TorControl::ipToCountry() method that will do a "GETINFO
ip-to-country/$ip" for some value of $ip and return the country code
contained in Tor's response.


Modified: vidalia/trunk/src/torcontrol/TorControl.cpp
===================================================================
--- vidalia/trunk/src/torcontrol/TorControl.cpp	2010-08-05 20:04:33 UTC (rev 4373)
+++ vidalia/trunk/src/torcontrol/TorControl.cpp	2010-08-05 20:05:41 UTC (rev 4374)
@@ -1076,3 +1076,17 @@
   return addressMap;
 }
 
+/** Gets the ISO-3166 two-letter country code for <b>ip</b> from Tor.
+ * Returns a default-constructed QString on failure or if a country code
+ * is not known for <b>ip</b>. On failure, <b>errmsg</b> will be set if
+ * it's not NULL. */
+QString
+TorControl::ipToCountry(const QHostAddress &ip, QString *errmsg)
+{
+  QString request   = QString("ip-to-country/%1").arg(ip.toString());
+  QVariant response = getInfo(request, errmsg);
+  if (! response.isNull())
+    return response.toString();
+  return QString();
+}
+

Modified: vidalia/trunk/src/torcontrol/TorControl.h
===================================================================
--- vidalia/trunk/src/torcontrol/TorControl.h	2010-08-05 20:04:33 UTC (rev 4373)
+++ vidalia/trunk/src/torcontrol/TorControl.h	2010-08-05 20:05:41 UTC (rev 4374)
@@ -202,6 +202,12 @@
     AddressMap::AddressMapType type = AddressMap::AddressMapAll,
     QString *errmsg = 0);
 
+  /** Gets the ISO-3166 two-letter country code for <b>ip</b> from Tor.
+   * Returns a default-constructed QString on failure or if a country code
+   * is not known for <b>ip</b>. On failure, <b>errmsg</b> will be set if
+   * it's not NULL. */
+  QString ipToCountry(const QHostAddress &ip, QString *errmsg = 0);
+
 public slots:
   /** Closes the circuit specified by <b>circId</b>. If <b>ifUnused</b> is
    * true, then the circuit will not be closed unless it is unused. */