linuxdcpp-team team mailing list archive
-
linuxdcpp-team team
-
Mailing list archive
-
Message #02712
[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2339: Display full country names rather than abbreviations
------------------------------------------------------------
revno: 2339
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Fri 2010-12-10 23:16:24 +0100
message:
Display full country names rather than abbreviations
modified:
changelog.txt
dcpp/User.cpp
dcpp/User.h
dcpp/Util.cpp
dcpp/Util.h
win32/SearchFrame.cpp
win32/TransferView.cpp
--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk
Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'changelog.txt'
--- changelog.txt 2010-12-08 22:58:41 +0000
+++ changelog.txt 2010-12-10 22:16:24 +0000
@@ -53,6 +53,7 @@
* [L#395464] [ADC] Send "000" as the STA success code
* Add user information tooltips (poy)
* Avoid parallel hub list downloads (emtee)
+* Display full country names rather than abbreviations (poy)
-- 0.770 2010-07-05 --
* [L#550300] Catch more potential file corruptions (thanks bigmuscle)
=== modified file 'dcpp/User.cpp'
--- dcpp/User.cpp 2010-12-08 16:54:29 +0000
+++ dcpp/User.cpp 2010-12-10 22:16:24 +0000
@@ -90,7 +90,7 @@
get("HR") + "/" + get("HO") + ",S:" + get("SL") + ">";
}
-string Identity::getCountry() const {
+const string& Identity::getCountry() const {
return Util::getIpCountry(getIp());
}
=== modified file 'dcpp/User.h'
--- dcpp/User.h 2010-12-08 16:54:29 +0000
+++ dcpp/User.h 2010-12-10 22:16:24 +0000
@@ -139,7 +139,7 @@
void setBot(bool bot) { set("BO", bot ? "1" : Util::emptyString); }
void setHidden(bool hidden) { set("HI", hidden ? "1" : Util::emptyString); }
string getTag() const;
- string getCountry() const;
+ const string& getCountry() const;
bool supports(const string& name) const;
bool isHub() const { return isClientType(CT_HUB) || isSet("HU"); }
bool isOp() const { return isClientType(CT_OP) || isClientType(CT_SU) || isClientType(CT_OWNER) || isSet("OP"); }
=== modified file 'dcpp/Util.cpp'
--- dcpp/Util.cpp 2010-12-08 16:54:29 +0000
+++ dcpp/Util.cpp 2010-12-10 22:16:24 +0000
@@ -204,12 +204,13 @@
string::size_type comma2 = 0;
string::size_type comma3 = 0;
string::size_type comma4 = 0;
+ string::size_type comma5 = 0;
string::size_type lineend = 0;
- CountryIter last = countries.end();
+ auto last = countries.end();
uint32_t startIP = 0;
uint32_t endIP = 0, endIPprev = 0;
- for(;;) {
+ while(true) {
comma1 = data.find(',', linestart);
if(comma1 == string::npos) break;
comma2 = data.find(',', comma1 + 1);
@@ -218,15 +219,17 @@
if(comma3 == string::npos) break;
comma4 = data.find(',', comma3 + 1);
if(comma4 == string::npos) break;
- lineend = data.find('\n', comma4);
+ comma5 = data.find(',', comma4 + 1);
+ if(comma5 == string::npos) break;
+ lineend = data.find('\n', comma5);
if(lineend == string::npos) break;
startIP = Util::toUInt32(start + comma2 + 2);
endIP = Util::toUInt32(start + comma3 + 2);
- uint16_t* country = (uint16_t*)(start + comma4 + 2);
if((startIP-1) != endIPprev)
- last = countries.insert(last, make_pair((startIP-1), (uint16_t)16191));
- last = countries.insert(last, make_pair(endIP, *country));
+ last = countries.insert(last, make_pair((startIP-1), _("Unknown")));
+ auto nameStart = comma5 + 2;
+ last = countries.insert(last, make_pair(endIP, string(start + nameStart, lineend - 1 - nameStart)));
endIPprev = endIP;
linestart = lineend + 1;
@@ -372,7 +375,7 @@
}
bool Util::checkExtension(const string& tmp) {
- for(int i = 0; i < tmp.length(); i++) {
+ for(size_t i = 0, n = tmp.size(); i < n; ++i) {
if (tmp[i] < 0 || tmp[i] == 32 || tmp[i] == ':') {
return false;
}
@@ -895,11 +898,10 @@
}
/* getIpCountry
- This function returns the country(Abbreviation) of an ip
- for exemple: it returns "PT", whitch standards for "Portugal"
+ This function returns the full country name of an ip, eg "Portugal".
more info: http://www.maxmind.com/app/csv
*/
-string Util::getIpCountry(const string& IP) {
+const string& Util::getIpCountry(const string& IP) {
if(BOOLSETTING(GET_USER_COUNTRY)) {
if(count(IP.begin(), IP.end(), '.') != 3)
return Util::emptyString;
@@ -914,10 +916,9 @@
(Util::toUInt32(IP.c_str() + b + 1) << 8) |
(Util::toUInt32(IP.c_str() + c + 1) );
- CountryIter i = countries.lower_bound(ipnum);
-
+ auto i = countries.lower_bound(ipnum);
if(i != countries.end()) {
- return string((char*)&(i->second), 2);
+ return i->second;
}
}
=== modified file 'dcpp/Util.h'
--- dcpp/Util.h 2010-12-08 16:54:29 +0000
+++ dcpp/Util.h 2010-12-10 22:16:24 +0000
@@ -412,7 +412,7 @@
static int stricmp(const wstring& a, const wstring& b) { return stricmp(a.c_str(), b.c_str()); }
static int strnicmp(const wstring& a, const wstring& b, size_t n) { return strnicmp(a.c_str(), b.c_str(), n); }
- static string getIpCountry(const string& IP);
+ static const string& getIpCountry(const string& IP);
static bool getAway() { return away; }
static void setAway(bool aAway) {
@@ -446,9 +446,7 @@
static string awayMsg;
static time_t awayTime;
- typedef map<uint32_t, uint16_t> CountryList;
- typedef CountryList::iterator CountryIter;
-
+ typedef map<uint32_t, string> CountryList;
static CountryList countries;
static void loadBootConfig();
=== modified file 'win32/SearchFrame.cpp'
--- win32/SearchFrame.cpp 2010-11-30 18:21:53 +0000
+++ win32/SearchFrame.cpp 2010-12-10 22:16:24 +0000
@@ -474,11 +474,11 @@
columns[COLUMN_CONNECTION] = Text::toT(ClientManager::getInstance()->getConnection(sr->getUser()->getCID()));
columns[COLUMN_SLOTS] = Text::toT(sr->getSlotString());
columns[COLUMN_IP] = Text::toT(sr->getIP());
- if (!columns[COLUMN_IP].empty()) {
+ if(!columns[COLUMN_IP].empty()) {
// Only attempt to grab a country mapping if we actually have an IP address
- tstring tmpCountry = Text::toT(Util::getIpCountry(sr->getIP()));
- if(!tmpCountry.empty())
- columns[COLUMN_IP] = tmpCountry + _T(" (") + columns[COLUMN_IP] + _T(")");
+ const string& country = Util::getIpCountry(sr->getIP());
+ if(!country.empty())
+ columns[COLUMN_IP] = Text::toT(country) + _T(" (") + columns[COLUMN_IP] + _T(")");
}
columns[COLUMN_HUB] = Text::toT(sr->getHubName());
columns[COLUMN_CID] = Text::toT(sr->getUser()->getCID().toBase32());
=== modified file 'win32/TransferView.cpp'
--- win32/TransferView.cpp 2010-12-08 16:54:29 +0000
+++ win32/TransferView.cpp 2010-12-10 22:16:24 +0000
@@ -741,9 +741,9 @@
ui->setChunk(t->getPos(), t->getSize());
const UserConnection& uc = t->getUserConnection();
ui->setCipher(Text::toT(uc.getCipherName()));
- tstring country = Text::toT(Util::getIpCountry(uc.getRemoteIp()));
+ const string& country = Util::getIpCountry(uc.getRemoteIp());
if(!country.empty())
- ui->setCountry(country);
+ ui->setCountry(Text::toT(country));
ui->setIP(Text::toT(uc.getRemoteIp()));
}