← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 3165: plugin API: add a way to retrieve a user object from a connection

 

------------------------------------------------------------
revno: 3165
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Thu 2012-12-27 22:11:22 +0100
message:
  plugin API: add a way to retrieve a user object from a connection
modified:
  changelog.txt
  dcpp/PluginApiImpl.cpp
  dcpp/PluginApiImpl.h
  dcpp/PluginDefs.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	2012-12-21 22:50:48 +0000
+++ changelog.txt	2012-12-27 21:11:22 +0000
@@ -3,7 +3,7 @@
 * Add "chunked" transfer encoding as per the HTTP/1.1 spec (crise)
 * [L#1072041] Fix DPI conversion problems (poy)
 * Remove the "Windows UPnP" port mapper in favor of MiniUPnP (poy)
-* Add a UI interface to the plugin API (poy)
+* Improve the plugin API (poy, crise)
 * Delete "View as text" files only when their window is closed (poy)
 * Fix queue matching when files have the same TTH but a different size (thanks irainman)
 * Update Boost to version 1.52

=== modified file 'dcpp/PluginApiImpl.cpp'
--- dcpp/PluginApiImpl.cpp	2012-11-14 19:53:25 +0000
+++ dcpp/PluginApiImpl.cpp	2012-12-27 21:11:22 +0000
@@ -109,7 +109,9 @@
 
 	&PluginApiImpl::sendUdpData,
 	&PluginApiImpl::sendProtocolCmd,
-	&PluginApiImpl::terminateConnection
+	&PluginApiImpl::terminateConnection,
+
+	&PluginApiImpl::getUserFromConn
 };
 
 DCHub PluginApiImpl::dcHub = {
@@ -442,6 +444,16 @@
 	try { getUdpSocket().writeTo(ip, Util::toString(port), data, n); } catch (const Exception&) { /* ... */ }
 }
 
+UserDataPtr PluginApiImpl::getUserFromConn(ConnectionDataPtr conn) {
+	auto user = reinterpret_cast<UserConnection*>(conn->object)->getHintedUser();
+	if(!user.user) { return nullptr; }
+
+	auto lock = ClientManager::getInstance()->lock();
+	auto ou = ClientManager::getInstance()->findOnlineUser(user);
+	if(!ou) { return nullptr; }
+	return ou->copyPluginObject();
+}
+
 // Functions for DCUtils
 size_t PluginApiImpl::toUtf8(char* dst, const char* src, size_t n) {
 	string sSrc(Text::toUtf8(src));

=== modified file 'dcpp/PluginApiImpl.h'
--- dcpp/PluginApiImpl.h	2012-11-15 18:32:12 +0000
+++ dcpp/PluginApiImpl.h	2012-12-27 21:11:22 +0000
@@ -79,6 +79,8 @@
 	static void DCAPI terminateConnection(ConnectionDataPtr conn, Bool graceless);
 	static void DCAPI sendUdpData(const char* ip, uint32_t port, dcptr_t data, size_t n);
 
+	static UserDataPtr DCAPI getUserFromConn(ConnectionDataPtr conn);
+
 	// Functions for DCUtils
 	static size_t DCAPI toUtf8(char* dst, const char* src, size_t n);
 	static size_t DCAPI fromUtf8(char* dst, const char* src, size_t n);

=== modified file 'dcpp/PluginDefs.h'
--- dcpp/PluginDefs.h	2012-11-15 18:32:12 +0000
+++ dcpp/PluginDefs.h	2012-12-27 21:11:22 +0000
@@ -65,7 +65,7 @@
 
 /* Optional interfaces */
 #define DCINTF_DCPP_CONNECTIONS		"dcpp.network.DCConnection"	/* Peer connections */
-#define DCINTF_DCPP_CONNECTIONS_VER	1
+#define DCINTF_DCPP_CONNECTIONS_VER	2
 
 #define DCINTF_DCPP_HUBS			"dcpp.network.DCHub"		/* Hubs */
 #define DCINTF_DCPP_HUBS_VER		1
@@ -357,6 +357,9 @@
 	void			(DCAPI *send_udp_data)			(const char* ip, uint32_t port, dcptr_t data, size_t n);
 	void			(DCAPI *send_protocol_cmd)		(ConnectionDataPtr hConn, const char* cmd);
 	void			(DCAPI *terminate_conn)			(ConnectionDataPtr hConn, Bool graceless);
+
+	/* Version 2 functions */
+	UserDataPtr		(DCAPI *get_user)				(ConnectionDataPtr hConn);
 } DCConnection, *DCConnectionPtr;
 
 /* Hubs */