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

[vidalia-svn] r1549: Be a little more correct about what we consider to be a vali (trunk/src/util/geoip)



Author: edmanm
Date: 2006-12-23 04:27:38 -0500 (Sat, 23 Dec 2006)
New Revision: 1549

Modified:
   trunk/src/util/geoip/geoip.cpp
   trunk/src/util/geoip/geoip.h
Log:
Be a little more correct about what we consider to be a valid lat/long. I
doubt anyone is running a Tor server in the Atlantic Ocean 380 miles off the
coast of Ghana, but hey, they could.


Modified: trunk/src/util/geoip/geoip.cpp
===================================================================
--- trunk/src/util/geoip/geoip.cpp	2006-12-23 09:03:55 UTC (rev 1548)
+++ trunk/src/util/geoip/geoip.cpp	2006-12-23 09:27:38 UTC (rev 1549)
@@ -29,11 +29,17 @@
 
 #include "geoip.h"
 
+/** Verifies a latitude is between -90.0 and 90.0 degrees. */
+#define IS_VALID_LATITUDE(x)    (((x) >= -90.0) && ((x) <= 90.0))
+/** Verifies a longitude is between -180.0 and 180.0 degrees. */
+#define IS_VALID_LONGITUDE(x)   (((x) >= -180.0) && ((x) <= 180.0))
+
+
 /** Constructor */
 GeoIp::GeoIp(QHostAddress ip)
 {
   _ip = ip;
-  _latitude = _longitude = 0.0;
+  _latitude = _longitude = 0xFFFF;
 }
 
 /** Constructor. */
@@ -96,7 +102,9 @@
 bool
 GeoIp::isEmpty() const
 {
-  return (_ip.isNull() && !_latitude && !_longitude);
+  return (_ip.isNull() && 
+          !IS_VALID_LATITUDE(_latitude) && 
+          !IS_VALID_LONGITUDE(_longitude));
 }
 
 /** Returns true if the GeoIp object is valid, but no location information
@@ -104,7 +112,9 @@
 bool
 GeoIp::isUnknown() const
 {
-  return (!_ip.isNull() && !_latitude && !_longitude);
+  return (!_ip.isNull() && 
+          !IS_VALID_LATITUDE(_latitude) && 
+          !IS_VALID_LONGITUDE(_longitude));
 }
 
 /** Returns a human-readable string of GeoIp location information. */

Modified: trunk/src/util/geoip/geoip.h
===================================================================
--- trunk/src/util/geoip/geoip.h	2006-12-23 09:03:55 UTC (rev 1548)
+++ trunk/src/util/geoip/geoip.h	2006-12-23 09:27:38 UTC (rev 1549)
@@ -36,7 +36,7 @@
 {
 public:
   /** Default constructor */
-  GeoIp() : _latitude(0), _longitude(0) {}
+  GeoIp() : _latitude(0xFFFF), _longitude(0xFFFF) {}
   /** Constructor. */
   GeoIp(QHostAddress ip);