← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2411: miniupnp tweaks

 

------------------------------------------------------------
revno: 2411
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Wed 2011-02-02 17:46:25 +0100
message:
  miniupnp tweaks
modified:
  changelog.txt
  dcpp/UPnP.h
  dcpp/UPnPManager.cpp
  dcpp/UPnPManager.h
  miniupnpc/igd_desc_parse.c
  miniupnpc/igd_desc_parse.h
  miniupnpc/miniupnpcstrings.h
  win32/UPnP_COM.cpp
  win32/UPnP_COM.h
  win32/UPnP_MiniUPnPc.cpp
  win32/UPnP_MiniUPnPc.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	2011-02-01 20:32:13 +0000
+++ changelog.txt	2011-02-02 16:46:25 +0000
@@ -4,6 +4,8 @@
 * Avoid crashes when closing from the taskbar too often (poy)
 * [L#580051] Restore DC++ colors to the fav hub window (poy)
 * Favorite user nicks are saved in Users.xml
+* Be stricter when determining whether MiniUPnP has succeeded (poy)
+* Display the name of the device MiniUPnP has bound to (poy)
 
 -- 0.781 2011-01-12 --
 * Add a dummy serial number to TLS certs to satisfy some parsers (poy)

=== modified file 'dcpp/UPnP.h'
--- dcpp/UPnP.h	2011-01-02 17:12:02 +0000
+++ dcpp/UPnP.h	2011-02-02 16:46:25 +0000
@@ -39,7 +39,9 @@
 	bool close();
 	bool hasRules() const;
 
+	virtual string getDeviceName() = 0;
 	virtual string getExternalIP() = 0;
+
 	virtual const string& getName() const = 0;
 
 protected:

=== modified file 'dcpp/UPnPManager.cpp'
--- dcpp/UPnPManager.cpp	2011-01-03 18:48:46 +0000
+++ dcpp/UPnPManager.cpp	2011-02-02 16:46:25 +0000
@@ -45,7 +45,7 @@
 	if(portMapping.test_and_set()) {
 		log(_("Another UPnP port mapping attempt is in progress..."));
 		return false;
-	} 
+	}
 
 	start();
 
@@ -64,7 +64,7 @@
 		conn_port = ConnectionManager::getInstance()->getPort(),
 		secure_port = ConnectionManager::getInstance()->getSecurePort(),
 		search_port = SearchManager::getInstance()->getPort();
-	
+
 	for(Impls::iterator i = impls.begin(); i != impls.end(); ++i) {
 		UPnP& impl = *i;
 
@@ -79,7 +79,7 @@
 			log(str(F_("The %1% interface has failed to map the %2% %3% port") % impl.getName() % "TCP" % conn_port));
 			continue;
 		}
-		
+
 		if(secure_port != 0 && !impl.open(secure_port, UPnP::PROTOCOL_TCP, str(F_(APPNAME " Encrypted Transfer Port (%1% TCP)") % secure_port))) {
 			log(str(F_("The %1% interface has failed to map the %2% %3% port") % impl.getName() % "TLS" % secure_port));
 			continue;
@@ -92,7 +92,8 @@
 
 		opened = true;
 
-		log(str(F_("Successfully created port mappings (TCP: %1%, UDP: %2%, TLS: %3%), mapped using the %4% interface") % conn_port % search_port % secure_port % impl.getName()));
+		log(str(F_("Successfully created port mappings (TCP: %1%, UDP: %2%, TLS: %3%) on the %4% device with the %5% interface") %
+			conn_port % search_port % secure_port % deviceString(impl) % impl.getName()));
 
 		if(!BOOLSETTING(NO_IP_OVERRIDE)) {
 			// now lets configure the external IP (connect to me) address
@@ -123,8 +124,9 @@
 
 void UPnPManager::close(UPnP& impl) {
 	if(impl.hasRules()) {
-		log(impl.close() ? str(F_("Successfully removed port mappings with the %1% interface") % impl.getName()) :
-			str(F_("Failed to remove port mappings with the %1% interface") % impl.getName()));
+		log(impl.close() ?
+			str(F_("Successfully removed port mappings from the %1% device with the %2% interface") % deviceString(impl) % impl.getName()) :
+			str(F_("Failed to remove port mappings from the %1% device with the %2% interface") % deviceString(impl) % impl.getName()));
 	}
 }
 
@@ -132,4 +134,11 @@
 	ConnectivityManager::getInstance()->log(str(F_("UPnP: %1%") % message));
 }
 
+string UPnPManager::deviceString(UPnP& impl) const {
+	string name(impl.getDeviceName());
+	if(name.empty())
+		name = _("Generic");
+	return '"' + name + '"';
+}
+
 } // namespace dcpp

=== modified file 'dcpp/UPnPManager.h'
--- dcpp/UPnPManager.h	2011-01-02 17:12:02 +0000
+++ dcpp/UPnPManager.h	2011-02-02 16:46:25 +0000
@@ -62,6 +62,7 @@
 
 	void close(UPnP& impl);
 	void log(const string& message);
+	string deviceString(UPnP& impl) const;
 };
 
 } // namespace dcpp

=== modified file 'miniupnpc/igd_desc_parse.c'
--- miniupnpc/igd_desc_parse.c	2010-12-22 18:35:14 +0000
+++ miniupnpc/igd_desc_parse.c	2011-02-02 16:46:25 +0000
@@ -69,6 +69,8 @@
            datas->level, datas->cureltname, l, data);	*/
 	if( !strcmp(datas->cureltname, "URLBase") )
 		dstmember = datas->urlbase;
+	else if( !strcmp(datas->cureltname, "modelName") )
+		dstmember = datas->modelName;
 	else if( !strcmp(datas->cureltname, "serviceType") )
 		dstmember = datas->tmp.servicetype;
 	else if( !strcmp(datas->cureltname, "controlURL") )

=== modified file 'miniupnpc/igd_desc_parse.h'
--- miniupnpc/igd_desc_parse.h	2010-06-18 12:09:55 +0000
+++ miniupnpc/igd_desc_parse.h	2011-02-02 16:46:25 +0000
@@ -23,6 +23,7 @@
 struct IGDdatas {
 	char cureltname[MINIUPNPC_URL_MAXSIZE];
 	char urlbase[MINIUPNPC_URL_MAXSIZE];
+	char modelName[MINIUPNPC_URL_MAXSIZE];
 	int level;
 	/*int state;*/
 	/* "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1" */

=== modified file 'miniupnpc/miniupnpcstrings.h'
--- miniupnpc/miniupnpcstrings.h	2009-12-06 18:07:44 +0000
+++ miniupnpc/miniupnpcstrings.h	2011-02-02 16:46:25 +0000
@@ -9,7 +9,7 @@
 #define __MINIUPNPCSTRINGS_H__
 
 #define OS_STRING "OS/version"
-#define MINIUPNPC_VERSION_STRING "1.4"
+#define MINIUPNPC_VERSION_STRING "1.5"
 
 #endif
 

=== modified file 'win32/UPnP_COM.cpp'
--- win32/UPnP_COM.cpp	2011-01-02 17:12:02 +0000
+++ win32/UPnP_COM.cpp	2011-02-02 16:46:25 +0000
@@ -93,6 +93,11 @@
 	return ret;
 }
 
+string UPnP_COM::getDeviceName() {
+	/// @todo use IUPnPDevice::ModelName <http://msdn.microsoft.com/en-us/library/aa381670(VS.85).aspx>?
+	return Util::emptyString;
+}
+
 string UPnP_COM::getExternalIP() {
 	// Get the External IP from the last added mapping
 	if(!lastPort)
@@ -162,6 +167,10 @@
 	return false;
 }
 
+string UPnP_COM::getDeviceName() {
+	return Util::emptyString;
+}
+
 string UPnP_COM::getExternalIP() {
 	return Util::emptyString;
 }

=== modified file 'win32/UPnP_COM.h'
--- win32/UPnP_COM.h	2011-01-02 17:12:02 +0000
+++ win32/UPnP_COM.h	2011-02-02 16:46:25 +0000
@@ -24,6 +24,7 @@
 struct IUPnPNAT;
 struct IStaticPortMappingCollection;
 
+/// @todo this class is far from complete (should register callbacks, etc)
 class UPnP_COM : public UPnP
 {
 public:
@@ -34,13 +35,15 @@
 
 	bool add(const unsigned short port, const Protocol protocol, const string& description);
 	bool remove(const unsigned short port, const Protocol protocol);
+
+	string getDeviceName();
+	string getExternalIP();
+
+	static const string name;
 	const string& getName() const {
 		return name;
 	}
 
-	string getExternalIP();
-	static const string name;
-
 	IUPnPNAT* pUN;
 	// this one can become invalidated so we can't cache it
 	IStaticPortMappingCollection* getStaticPortMappingCollection();

=== modified file 'win32/UPnP_MiniUPnPc.cpp'
--- win32/UPnP_MiniUPnPc.cpp	2011-01-02 17:12:02 +0000
+++ win32/UPnP_MiniUPnPc.cpp	2011-02-02 16:46:25 +0000
@@ -37,7 +37,7 @@
 	if(!devices)
 		return false;
 
-	bool ret = UPNP_GetValidIGD(devices, &urls, &data, 0, 0);
+	bool ret = UPNP_GetValidIGD(devices, &urls, &data, 0, 0) == 1;
 
 	freeUPNPDevlist(devices);
 
@@ -55,6 +55,10 @@
 		protocols[protocol], 0) == UPNPCOMMAND_SUCCESS;
 }
 
+string UPnP_MiniUPnPc::getDeviceName() {
+	return data.modelName;
+}
+
 string UPnP_MiniUPnPc::getExternalIP() {
 	char buf[16] = { 0 };
 	if(UPNP_GetExternalIPAddress(urls.controlURL, data.first.servicetype, buf) == UPNPCOMMAND_SUCCESS)

=== modified file 'win32/UPnP_MiniUPnPc.h'
--- win32/UPnP_MiniUPnPc.h	2011-01-02 17:12:02 +0000
+++ win32/UPnP_MiniUPnPc.h	2011-02-02 16:46:25 +0000
@@ -31,12 +31,14 @@
 
 	bool add(const unsigned short port, const Protocol protocol, const string& description);
 	bool remove(const unsigned short port, const Protocol protocol);
+
+	string getDeviceName();
+	string getExternalIP();
+
+	static const string name;
 	const string& getName() const {
 		return name;
 	}
-
-	string getExternalIP();
-	static const string name;
 };
 
 #endif