← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 3203: Preserve encodings in some search results

 

------------------------------------------------------------
revno: 3203
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Sun 2013-02-03 23:26:48 +0100
message:
  Preserve encodings in some search results
modified:
  changelog.txt
  dcpp/ClientManager.cpp
  dcpp/ClientManager.h
  dcpp/HintedUser.h
  dcpp/SearchManager.cpp
  win32/WinUtil.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	2013-02-01 16:42:33 +0000
+++ changelog.txt	2013-02-03 22:26:48 +0000
@@ -1,4 +1,5 @@
 * Fix status bar parts when the window is too small (poy)
+* [L#534440] [NMDC] Preserve encodings in some search results (poy)
 
 -- 0.810 2013-01-30 --
 * Fix a race condition on file list download (thanks bigmuscle)

=== modified file 'dcpp/ClientManager.cpp'
--- dcpp/ClientManager.cpp	2013-01-28 21:32:53 +0000
+++ dcpp/ClientManager.cpp	2013-02-03 22:26:48 +0000
@@ -234,18 +234,24 @@
 	return Text::systemCharset;
 }
 
-UserPtr ClientManager::findLegacyUser(const string& aNick) const noexcept {
-	if (aNick.empty())
-		return UserPtr();
+HintedUser ClientManager::findLegacyUser(const string& nick) const noexcept {
+	if(nick.empty())
+		return HintedUser();
 
 	Lock l(cs);
 
 	for(auto& i: onlineUsers) {
-		const OnlineUser* ou = i.second;
-		if(ou->getUser()->isSet(User::NMDC) && Util::stricmp(ou->getIdentity().getNick(), aNick) == 0)
-			return ou->getUser();
+		auto& ou = *i.second;
+		if(ou.getUser()->isSet(User::NMDC) &&
+			/** @todo this conv runs each time on ever user; remove it when we store non-UTF-8
+			nicks as well... */
+			Util::stricmp(ou.getIdentity().getNick(), Text::toUtf8(nick, ou.getClient().getEncoding())) == 0)
+		{
+			return HintedUser(ou);
+		}
 	}
-	return UserPtr();
+
+	return HintedUser();
 }
 
 UserPtr ClientManager::getUser(const string& aNick, const string& aHubUrl) noexcept {

=== modified file 'dcpp/ClientManager.h'
--- dcpp/ClientManager.h	2013-01-28 19:41:11 +0000
+++ dcpp/ClientManager.h	2013-02-03 22:26:48 +0000
@@ -100,7 +100,9 @@
 
 	UserPtr findUser(const string& aNick, const string& aHubUrl) const noexcept { return findUser(makeCid(aNick, aHubUrl)); }
 	UserPtr findUser(const CID& cid) const noexcept;
-	UserPtr findLegacyUser(const string& aNick) const noexcept;
+	/** Find an online NMDC user by nick only (random user returned if multiple hubs share users
+	with the same nick). The nick is given in hub-dependant encoding. */
+	HintedUser findLegacyUser(const string& nick) const noexcept;
 
 	bool isOnline(const UserPtr& aUser) const {
 		Lock l(cs);

=== modified file 'dcpp/HintedUser.h'
--- dcpp/HintedUser.h	2013-01-28 19:41:11 +0000
+++ dcpp/HintedUser.h	2013-02-03 22:26:48 +0000
@@ -35,6 +35,7 @@
 	UserPtr user;
 	string hint;
 
+	HintedUser() : user(nullptr) { }
 	HintedUser(const UserPtr& user, const string& hint) : user(user), hint(hint) { }
 	HintedUser(const OnlineUser& ou) : HintedUser(ou.getUser(), ou.getClient().getHubUrl()) { }
 
@@ -47,6 +48,8 @@
 	}
 
 	operator UserPtr() const { return user; }
+
+	explicit operator bool() const { return user; }
 };
 
 }

=== modified file 'dcpp/SearchManager.cpp'
--- dcpp/SearchManager.cpp	2013-01-29 15:38:58 +0000
+++ dcpp/SearchManager.cpp	2013-02-03 22:26:48 +0000
@@ -233,18 +233,23 @@
 			return;
 		}
 
-		string hubIpPort = x.substr(i, j-i);
-		string url = ClientManager::getInstance()->findHub(hubIpPort);
-
-		string encoding = ClientManager::getInstance()->findHubEncoding(url);
+		HintedUser user;
+
+		user.hint = ClientManager::getInstance()->findHub(x.substr(i, j - i));
+		if(user.hint.empty()) {
+			// Could happen if hub has multiple URLs / IPs
+			user = ClientManager::getInstance()->findLegacyUser(nick);
+			if(!user)
+				return;
+		}
+
+		string encoding = ClientManager::getInstance()->findHubEncoding(user.hint);
 		nick = Text::toUtf8(nick, encoding);
 		file = Text::toUtf8(file, encoding);
 		hubName = Text::toUtf8(hubName, encoding);
 
-		UserPtr user = ClientManager::getInstance()->findUser(nick, url);
 		if(!user) {
-			// Could happen if hub has multiple URLs / IPs
-			user = ClientManager::getInstance()->findLegacyUser(nick);
+			user.user = ClientManager::getInstance()->findUser(nick, user.hint);
 			if(!user)
 				return;
 		}
@@ -252,7 +257,7 @@
 		string tth;
 		if(hubName.compare(0, 4, "TTH:") == 0) {
 			tth = hubName.substr(4);
-			StringList names = ClientManager::getInstance()->getHubNames(user->getCID(), Util::emptyString);
+			StringList names = ClientManager::getInstance()->getHubNames(user);
 			hubName = names.empty() ? _("Offline") : Util::toString(names);
 		}
 
@@ -260,9 +265,8 @@
 			return;
 		}
 
-		fire(SearchManagerListener::SR(), SearchResultPtr(new SearchResult(HintedUser(user, url),
-			type, slots, freeSlots, size, file, hubName, remoteIp, TTHValue(tth),
-			Util::emptyString)));
+		fire(SearchManagerListener::SR(), SearchResultPtr(new SearchResult(user, type, slots,
+			freeSlots, size, file, hubName, remoteIp, TTHValue(tth), Util::emptyString)));
 
 	} else if(x.compare(1, 4, "RES ") == 0 && x[x.length() - 1] == 0x0a) {
 		AdcCommand c(x.substr(0, x.length()-1));

=== modified file 'win32/WinUtil.cpp'
--- win32/WinUtil.cpp	2013-01-21 18:43:48 +0000
+++ win32/WinUtil.cpp	2013-02-03 22:26:48 +0000
@@ -1384,21 +1384,7 @@
 	{
 		HubFrame::openWindow(mainWindow->getTabView(), url);
 
-		if(!file.empty()) {
-			if(file[0] == '/') {
-				// Remove any '/' in from of the file
-				file = file.substr(1);
-				if(file.empty()) return true;
-			}
-			try {
-				UserPtr user = ClientManager::getInstance()->findLegacyUser(file);
-				if(user)
-					QueueManager::getInstance()->addList(HintedUser(user, url), QueueItem::FLAG_CLIENT_VIEW | QueueItem::FLAG_PARTIAL_LIST);
-				// @todo else report error
-			} catch (const Exception&) {
-				// ...
-			}
-		}
+		/// @todo parse other params when RFCs for these schemes have been published.
 
 		return true;