linuxdcpp-team team mailing list archive
-
linuxdcpp-team team
-
Mailing list archive
-
Message #02019
[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2250: Blacklist rogue hub-lists
Merge authors:
poy (poy)
------------------------------------------------------------
revno: 2250 [merge]
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Thu 2010-09-30 19:34:28 +0200
message:
Blacklist rogue hub-lists
modified:
changelog.txt
dcpp/FavoriteManager.cpp
dcpp/FavoriteManager.h
dcpp/SettingsManager.cpp
win32/MainWindow.cpp
win32/PublicHubsFrame.cpp
win32/PublicHubsFrame.h
--
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-09-28 21:29:06 +0000
+++ changelog.txt 2010-09-30 17:34:28 +0000
@@ -19,6 +19,7 @@
* Removed stlport support (probably defunct by now...)
* Modernize the installer and make it translatable (poy)
* Customize the font selection dialog, save the charset (poy)
+* Blacklist rogue hub-lists (poy)
-- 0.770 2010-07-05 --
* [L#550300] Catch more potential file corruptions (thanks bigmuscle)
=== modified file 'dcpp/FavoriteManager.cpp'
--- dcpp/FavoriteManager.cpp 2010-03-26 22:49:37 +0000
+++ dcpp/FavoriteManager.cpp 2010-09-30 17:34:28 +0000
@@ -41,6 +41,9 @@
ClientManager::getInstance()->addListener(this);
File::ensureDirectory(Util::getHubListsPath());
+
+ blacklist.insert(make_pair("adchublist.com", "Domain used for spam purposes."));
+ blacklist.insert(make_pair("openhublist.org", "Domain used for spam purposes."));
}
FavoriteManager::~FavoriteManager() throw() {
@@ -640,6 +643,35 @@
return lists.getTokens();
}
+const string& FavoriteManager::blacklisted() const {
+ if(publicListServer.empty())
+ return Util::emptyString;
+
+ // get the host
+ string server;
+ uint16_t port = 0;
+ string file;
+ Util::decodeUrl(publicListServer, server, port, file);
+ // only keep the last 2 words (example.com)
+ size_t pos = server.rfind('.');
+ if(pos == string::npos || pos == 0 || pos >= server.size() - 2)
+ return Util::emptyString;
+ pos = server.rfind('.', pos - 1);
+ if(pos != string::npos)
+ server = server.substr(pos + 1);
+
+ StringMap::const_iterator i = blacklist.find(server);
+ if(i == blacklist.end())
+ return Util::emptyString;
+ return i->second;
+}
+
+void FavoriteManager::addBlacklist(const string& url, const string& reason) {
+ if(url.empty() || reason.empty())
+ return;
+ blacklist[url] = reason;
+}
+
FavoriteHubEntryList::iterator FavoriteManager::getFavoriteHub(const string& aServer) {
for(FavoriteHubEntryList::iterator i = favoriteHubs.begin(); i != favoriteHubs.end(); ++i) {
if(Util::stricmp((*i)->getServer(), aServer) == 0) {
@@ -768,14 +800,13 @@
}
}
void FavoriteManager::on(Complete, HttpConnection*, const string& aLine, bool fromCoral) throw() {
- bool parseSuccess;
-
+ bool parseSuccess = false;
c->removeListener(this);
if(useHttp) {
parseSuccess = onHttpFinished(true);
}
running = false;
- if(useHttp && parseSuccess) {
+ if(parseSuccess) {
fire(FavoriteManagerListener::DownloadFinished(), aLine, fromCoral);
}
}
=== modified file 'dcpp/FavoriteManager.h'
--- dcpp/FavoriteManager.h 2010-02-11 21:44:13 +0000
+++ dcpp/FavoriteManager.h 2010-09-30 17:34:28 +0000
@@ -58,6 +58,10 @@
return publicListMatrix[publicListServer];
}
bool isDownloading() { return (useHttp && running); }
+ const string& getCurrentHubList() const { return publicListServer; }
+ /// @return ref to the reason string the current list is blacklisted; or empty string otherwise.
+ const string& blacklisted() const;
+ void addBlacklist(const string& url, const string& reason);
// Favorite Users
typedef unordered_map<CID, FavoriteUser> FavoriteMap;
@@ -132,6 +136,7 @@
int lastServer;
HubTypes listType;
string downloadBuf;
+ StringMap blacklist;
/** Used during loading to prevent saving. */
bool dontSave;
=== modified file 'dcpp/SettingsManager.cpp'
--- dcpp/SettingsManager.cpp 2010-08-29 12:27:09 +0000
+++ dcpp/SettingsManager.cpp 2010-09-30 17:34:28 +0000
@@ -157,7 +157,7 @@
setDefault(IGNORE_BOT_PMS, false);
setDefault(LIST_DUPES, true);
setDefault(BUFFER_SIZE, 64);
- setDefault(HUBLIST_SERVERS, "http://dchublist.com/hublist.xml.bz2;http://www.hublista.hu/hublist.xml.bz2;http://hublist.openhublist.org/hublist.xml.bz2;");
+ setDefault(HUBLIST_SERVERS, "http://dchublist.com/hublist.xml.bz2;http://www.hublista.hu/hublist.xml.bz2");
setDefault(DOWNLOAD_SLOTS, 6);
setDefault(MAX_DOWNLOAD_SPEED, 0);
setDefault(LOG_DIRECTORY, Util::getPath(Util::PATH_USER_LOCAL) + "Logs" PATH_SEPARATOR_STR);
=== modified file 'win32/MainWindow.cpp'
--- win32/MainWindow.cpp 2010-09-02 18:16:12 +0000
+++ win32/MainWindow.cpp 2010-09-30 17:34:28 +0000
@@ -1136,6 +1136,7 @@
}
}
}
+
xml.resetCurrentChild();
if(xml.findChild("Links")) {
xml.stepIn();
@@ -1180,6 +1181,22 @@
}
xml.stepOut();
}
+
+ xml.resetCurrentChild();
+ if(xml.findChild("Blacklist")) {
+ xml.stepIn();
+ while(xml.findChild("Blacklisted")) {
+ const string& url = xml.getChildAttrib("Url");
+ if(url.empty())
+ continue;
+ const string& reason = xml.getChildAttrib("Reason");
+ if(reason.empty())
+ continue;
+ FavoriteManager::getInstance()->addBlacklist(url, reason);
+ }
+ xml.stepOut();
+ }
+
xml.stepOut();
} catch (const Exception&) {
// ...
=== modified file 'win32/PublicHubsFrame.cpp'
--- win32/PublicHubsFrame.cpp 2010-07-10 14:36:48 +0000
+++ win32/PublicHubsFrame.cpp 2010-09-30 17:34:28 +0000
@@ -78,6 +78,8 @@
PublicHubsFrame::PublicHubsFrame(dwt::TabView* mdiParent) :
BaseType(mdiParent, T_("Public Hubs"), IDH_PUBLIC_HUBS, IDI_PUBLICHUBS, false),
grid(0),
+upper(0),
+blacklist(0),
hubs(0),
filter(0),
filterSel(0),
@@ -91,10 +93,28 @@
grid->row(0).align = GridInfo::STRETCH;
{
- WidgetHubs::Seed cs;
- cs.style |= LVS_SINGLESEL;
- hubs = grid->addChild(cs);
- addWidget(hubs);
+ upper = grid->addChild(Grid::Seed(2, 1));
+ upper->setSpacing(0);
+ upper->column(0).mode = GridInfo::FILL;
+ upper->row(0).size = 0;
+ upper->row(0).mode = GridInfo::STATIC;
+ upper->row(1).mode = GridInfo::FILL;
+ upper->row(1).align = GridInfo::STRETCH;
+
+ {
+ TextBox::Seed seed = WinUtil::Seeds::textBox;
+ seed.style |= WS_DISABLED | ES_MULTILINE | WS_VSCROLL | ES_READONLY;
+ seed.lines = 8;
+ blacklist = upper->addChild(seed);
+ addWidget(blacklist);
+ }
+
+ {
+ WidgetHubs::Seed seed;
+ seed.style |= LVS_SINGLESEL;
+ hubs = upper->addChild(seed);
+ addWidget(hubs);
+ }
WinUtil::makeColumns(hubs, hubsColumns, COLUMN_LAST, SETTING(PUBLICHUBSFRAME_ORDER), SETTING(PUBLICHUBSFRAME_WIDTHS));
hubs->setSort(COLUMN_USERS, false);
@@ -239,19 +259,39 @@
void PublicHubsFrame::updateList() {
dcdebug("PublicHubsFrame::updateList\n");
- hubs->clear();
+ const string& blacklisted = FavoriteManager::getInstance()->blacklisted();
+ if(blacklisted.empty()) {
+ if(blacklist->getEnabled()) {
+ blacklist->setEnabled(false);
+ blacklist->setVisible(false);
+ upper->row(0).mode = GridInfo::STATIC;
+ layout();
+ }
+ } else {
+ blacklist->setText(str(TF_(
+ "Warning: fraudulent hub list detected!\r\n\r\n"
+ "The current hub list (%1%) has been blacklisted by DC++ for the following reason:\r\n"
+ "%2%\r\n\r\n"
+ "It is strongly recommended that you do not connect to any of the hubs listed here "
+ "and that you remove this hub list from your collection by using the \"Configure\" "
+ "button below."
+ ) % Text::toT(FavoriteManager::getInstance()->getCurrentHubList()) % Text::toT(blacklisted)));
+ blacklist->setEnabled(true);
+ blacklist->setVisible(true);
+ upper->row(0).mode = GridInfo::AUTO;
+ layout();
+ }
+
users = 0;
visibleHubs = 0;
- HoldRedraw hold(hubs);
-
+ int sel = filterSel->getSelected();
+ FilterModes mode = NONE;
double size = -1;
- FilterModes mode = NONE;
-
- int sel = filterSel->getSelected();
-
bool doSizeCompare = parseFilter(mode, size);
+ HoldRedraw hold(hubs);
+ hubs->clear();
for(HubEntryList::const_iterator i = entries.begin(); i != entries.end(); ++i) {
if(matchFilter(*i, sel, doSizeCompare, mode, size)) {
hubs->insert(hubs->size(), new HubInfo(&(*i)));
=== modified file 'win32/PublicHubsFrame.h'
--- win32/PublicHubsFrame.h 2010-02-11 21:44:13 +0000
+++ win32/PublicHubsFrame.h 2010-09-30 17:34:28 +0000
@@ -90,6 +90,9 @@
GridPtr grid;
+ GridPtr upper;
+ TextBoxPtr blacklist;
+
typedef TypedTable<HubInfo> WidgetHubs;
typedef WidgetHubs* WidgetHubsPtr;
WidgetHubsPtr hubs;