[or-cvs] r14404: Archive miniupnp patches (now in a Vidalia branch) (in torbrowser/trunk/src: archived-patches current-patches)

sjm217 at seul.org sjm217 at seul.org
Mon Apr 21 19:34:36 UTC 2008


Author: sjm217
Date: 2008-04-21 15:34:36 -0400 (Mon, 21 Apr 2008)
New Revision: 14404

Added:
   torbrowser/trunk/src/archived-patches/vidalia-miniupnp.patch
Removed:
   torbrowser/trunk/src/current-patches/vidalia-miniupnp.patch
Log:
Archive miniupnp patches (now in a Vidalia branch)

Copied: torbrowser/trunk/src/archived-patches/vidalia-miniupnp.patch (from rev 14340, torbrowser/trunk/src/current-patches/vidalia-miniupnp.patch)
===================================================================
--- torbrowser/trunk/src/archived-patches/vidalia-miniupnp.patch	                        (rev 0)
+++ torbrowser/trunk/src/archived-patches/vidalia-miniupnp.patch	2008-04-21 19:34:36 UTC (rev 14404)
@@ -0,0 +1,185 @@
+Index: src/vidalia/config/serversettings.cpp
+===================================================================
+--- src/vidalia/config/serversettings.cpp	(revision 2498)
++++ src/vidalia/config/serversettings.cpp	(working copy)
+@@ -137,7 +137,7 @@
+   if (isServerEnabled()) {
+     /* Configure UPnP device to forward DirPort and OrPort */
+     /* TODO: does isServerEnabled() return true when a server is just set up? */
+-    configurePortForwarding();
++    configurePortForwarding(true);
+     rc = torControl()->setConf(confValues(), errmsg);
+   } else { 
+     QStringList resetKeys;
+@@ -156,6 +156,7 @@
+                 << SETTING_BANDWIDTH_BURST;
+     }
+     rc = torControl()->resetConf(resetKeys, errmsg);
++    configurePortForwarding(false);
+   }
+   return rc;
+ }
+@@ -165,11 +166,16 @@
+ /* TODO: init_upnp() will block for up to 2 seconds. We should fire off a thread */
+ /** Configure UPnP device to forward DirPort and ORPort */
+ void
+-ServerSettings::configurePortForwarding()
++ServerSettings::configurePortForwarding(boolean enable)
+ {
+ #ifdef USE_MINIUPNPC
+   UPNPControl *pUNPControl = UPNPControl::Instance();
+-  pUNPControl->forwardPort(getORPort());
++
++  if (enable) {
++    pUNPControl->forwardPort(getORPort());
++  } else {
++    pUNPControl->disableForwarding();
++  }
+ #endif
+ }
+ 
+Index: src/vidalia/config/serversettings.h
+===================================================================
+--- src/vidalia/config/serversettings.h	(revision 2498)
++++ src/vidalia/config/serversettings.h	(working copy)
+@@ -93,7 +93,7 @@
+   QHash<QString,QString> confValues();
+ 
+   /** Configure UPnP device to forward DirPort and ORPort */
+-  void configurePortForwarding();
++  void configurePortForwarding(boolean enable);
+ };
+ 
+ #endif
+Index: src/vidalia/config/upnpcontrol.cpp
+===================================================================
+--- src/vidalia/config/upnpcontrol.cpp	(revision 2498)
++++ src/vidalia/config/upnpcontrol.cpp	(working copy)
+@@ -27,6 +27,7 @@
+ UPNPControl::UPNPControl()
+ {
+   init_upnp();
++  forwardedPort = 0;
+ }
+ 
+ int
+@@ -68,9 +69,42 @@
+   
+   // Output the mapping
+   printf("(external):%s -> %s:%s\n", sPort, intClient, intPort);
++  fflush(stdout);
++
++  // Save the mapping
++  forwardedPort = port;
++
+   return 0;
+ }
+ 
++int
++UPNPControl::disableForwarding()
++{
++  char sPort[6];
++
++  if (0 == forwardedPort)
++    return 0;
++
++  // Convert the port number to a string
++  snprintf(sPort, sizeof(sPort), "%d", forwardedPort);
++
++  int retval = UPNP_DeletePortMapping(urls.controlURL, data.servicetype, sPort, "TCP");
++  if(UPNPCOMMAND_SUCCESS != retval) {
++    printf("DeletePortMapping() failed with code %d\n", retval);
++    return 1;
++  }
++
++  // Output the cancelled mapping
++  printf("(external):%s -> <>\n", sPort);
++  fflush(stdout);
++
++  // Save the mapping
++  forwardedPort = 0;
++
++  return 0;
++}
++
++
+ /** Based on http://miniupnp.free.fr/files/download.php?file=xchat-upnp20061022.patch */
+ void
+ UPNPControl::init_upnp()
+@@ -78,52 +112,13 @@
+   struct UPNPDev * devlist;
+   int retval;
+ 
+-  printf("TB : init_upnp()\n");
+-
+   memset(&urls, 0, sizeof(struct UPNPUrls));
+   memset(&data, 0, sizeof(struct IGDdatas));
+ 
+   devlist = upnpDiscover(2000, NULL, NULL);
+   retval = UPNP_GetValidIGD(devlist, &urls, &data, lanaddr, sizeof(lanaddr));
+-  printf("UPNP: %d", retval);
++  printf("GetValidIGD returned: %d\n", retval);
++  fflush(stdout);
+ 
+   freeUPNPDevlist(devlist);
+ }
+-
+-/** Based on http://miniupnp.free.fr/files/download.php?file=xchat-upnp20061022.patch */
+-void
+-UPNPControl::upnp_add_redir(const char * addr, int port)
+-{
+-	char port_str[16];
+-	int r;
+-	printf("TB : upnp_add_redir (%s, %d)\n", addr, port);
+-	if(urls.controlURL[0] == '\0')
+-	{
+-		printf("TB : the init was not done !\n");
+-		fflush(stdout);
+-		return;
+-	}
+-	
+-	r = UPNP_AddPortMapping(urls.controlURL, data.servicetype,
+-	                        port_str, port_str, addr, 0, "TCP");
+-	if(r==0)
+-		printf("AddPortMapping(%s, %s, %s) failed\n", port_str, port_str, addr);
+-	fflush(stdout);
+-}
+-
+-/** Based on http://miniupnp.free.fr/files/download.php?file=xchat-upnp20061022.patch */
+-void
+-UPNPControl::upnp_rem_redir(int port)
+-{
+-	char port_str[16];
+-	int t;
+-	printf("TB : upnp_rem_redir (%d)\n", port);
+-	if(urls.controlURL[0] == '\0')
+-	{
+-		printf("TB : the init was not done !\n");
+-		fflush(stdout);
+-		return;
+-	}
+-	sprintf(port_str, "%d", port);
+-	UPNP_DeletePortMapping(urls.controlURL, data.servicetype, port_str, "TCP");
+-}
+Index: src/vidalia/config/upnpcontrol.h
+===================================================================
+--- src/vidalia/config/upnpcontrol.h	(revision 2498)
++++ src/vidalia/config/upnpcontrol.h	(working copy)
+@@ -31,6 +31,7 @@
+ public:
+   static UPNPControl* Instance();
+   int forwardPort(quint16 port);
++  int disableForwarding();
+ protected:
+   UPNPControl();
+ private:
+@@ -43,6 +44,9 @@
+   void init_upnp();
+   void upnp_add_redir (const char * addr, int port);
+   void upnp_rem_redir(int port);
++
++  /* Currently forwarded port */
++  quint16 forwardedPort;
+ };
+ 
+ #endif 

Deleted: torbrowser/trunk/src/current-patches/vidalia-miniupnp.patch
===================================================================
--- torbrowser/trunk/src/current-patches/vidalia-miniupnp.patch	2008-04-20 05:23:31 UTC (rev 14403)
+++ torbrowser/trunk/src/current-patches/vidalia-miniupnp.patch	2008-04-21 19:34:36 UTC (rev 14404)
@@ -1,185 +0,0 @@
-Index: src/vidalia/config/serversettings.cpp
-===================================================================
---- src/vidalia/config/serversettings.cpp	(revision 2498)
-+++ src/vidalia/config/serversettings.cpp	(working copy)
-@@ -137,7 +137,7 @@
-   if (isServerEnabled()) {
-     /* Configure UPnP device to forward DirPort and OrPort */
-     /* TODO: does isServerEnabled() return true when a server is just set up? */
--    configurePortForwarding();
-+    configurePortForwarding(true);
-     rc = torControl()->setConf(confValues(), errmsg);
-   } else { 
-     QStringList resetKeys;
-@@ -156,6 +156,7 @@
-                 << SETTING_BANDWIDTH_BURST;
-     }
-     rc = torControl()->resetConf(resetKeys, errmsg);
-+    configurePortForwarding(false);
-   }
-   return rc;
- }
-@@ -165,11 +166,16 @@
- /* TODO: init_upnp() will block for up to 2 seconds. We should fire off a thread */
- /** Configure UPnP device to forward DirPort and ORPort */
- void
--ServerSettings::configurePortForwarding()
-+ServerSettings::configurePortForwarding(boolean enable)
- {
- #ifdef USE_MINIUPNPC
-   UPNPControl *pUNPControl = UPNPControl::Instance();
--  pUNPControl->forwardPort(getORPort());
-+
-+  if (enable) {
-+    pUNPControl->forwardPort(getORPort());
-+  } else {
-+    pUNPControl->disableForwarding();
-+  }
- #endif
- }
- 
-Index: src/vidalia/config/serversettings.h
-===================================================================
---- src/vidalia/config/serversettings.h	(revision 2498)
-+++ src/vidalia/config/serversettings.h	(working copy)
-@@ -93,7 +93,7 @@
-   QHash<QString,QString> confValues();
- 
-   /** Configure UPnP device to forward DirPort and ORPort */
--  void configurePortForwarding();
-+  void configurePortForwarding(boolean enable);
- };
- 
- #endif
-Index: src/vidalia/config/upnpcontrol.cpp
-===================================================================
---- src/vidalia/config/upnpcontrol.cpp	(revision 2498)
-+++ src/vidalia/config/upnpcontrol.cpp	(working copy)
-@@ -27,6 +27,7 @@
- UPNPControl::UPNPControl()
- {
-   init_upnp();
-+  forwardedPort = 0;
- }
- 
- int
-@@ -68,9 +69,42 @@
-   
-   // Output the mapping
-   printf("(external):%s -> %s:%s\n", sPort, intClient, intPort);
-+  fflush(stdout);
-+
-+  // Save the mapping
-+  forwardedPort = port;
-+
-   return 0;
- }
- 
-+int
-+UPNPControl::disableForwarding()
-+{
-+  char sPort[6];
-+
-+  if (0 == forwardedPort)
-+    return 0;
-+
-+  // Convert the port number to a string
-+  snprintf(sPort, sizeof(sPort), "%d", forwardedPort);
-+
-+  int retval = UPNP_DeletePortMapping(urls.controlURL, data.servicetype, sPort, "TCP");
-+  if(UPNPCOMMAND_SUCCESS != retval) {
-+    printf("DeletePortMapping() failed with code %d\n", retval);
-+    return 1;
-+  }
-+
-+  // Output the cancelled mapping
-+  printf("(external):%s -> <>\n", sPort);
-+  fflush(stdout);
-+
-+  // Save the mapping
-+  forwardedPort = 0;
-+
-+  return 0;
-+}
-+
-+
- /** Based on http://miniupnp.free.fr/files/download.php?file=xchat-upnp20061022.patch */
- void
- UPNPControl::init_upnp()
-@@ -78,52 +112,13 @@
-   struct UPNPDev * devlist;
-   int retval;
- 
--  printf("TB : init_upnp()\n");
--
-   memset(&urls, 0, sizeof(struct UPNPUrls));
-   memset(&data, 0, sizeof(struct IGDdatas));
- 
-   devlist = upnpDiscover(2000, NULL, NULL);
-   retval = UPNP_GetValidIGD(devlist, &urls, &data, lanaddr, sizeof(lanaddr));
--  printf("UPNP: %d", retval);
-+  printf("GetValidIGD returned: %d\n", retval);
-+  fflush(stdout);
- 
-   freeUPNPDevlist(devlist);
- }
--
--/** Based on http://miniupnp.free.fr/files/download.php?file=xchat-upnp20061022.patch */
--void
--UPNPControl::upnp_add_redir(const char * addr, int port)
--{
--	char port_str[16];
--	int r;
--	printf("TB : upnp_add_redir (%s, %d)\n", addr, port);
--	if(urls.controlURL[0] == '\0')
--	{
--		printf("TB : the init was not done !\n");
--		fflush(stdout);
--		return;
--	}
--	
--	r = UPNP_AddPortMapping(urls.controlURL, data.servicetype,
--	                        port_str, port_str, addr, 0, "TCP");
--	if(r==0)
--		printf("AddPortMapping(%s, %s, %s) failed\n", port_str, port_str, addr);
--	fflush(stdout);
--}
--
--/** Based on http://miniupnp.free.fr/files/download.php?file=xchat-upnp20061022.patch */
--void
--UPNPControl::upnp_rem_redir(int port)
--{
--	char port_str[16];
--	int t;
--	printf("TB : upnp_rem_redir (%d)\n", port);
--	if(urls.controlURL[0] == '\0')
--	{
--		printf("TB : the init was not done !\n");
--		fflush(stdout);
--		return;
--	}
--	sprintf(port_str, "%d", port);
--	UPNP_DeletePortMapping(urls.controlURL, data.servicetype, port_str, "TCP");
--}
-Index: src/vidalia/config/upnpcontrol.h
-===================================================================
---- src/vidalia/config/upnpcontrol.h	(revision 2498)
-+++ src/vidalia/config/upnpcontrol.h	(working copy)
-@@ -31,6 +31,7 @@
- public:
-   static UPNPControl* Instance();
-   int forwardPort(quint16 port);
-+  int disableForwarding();
- protected:
-   UPNPControl();
- private:
-@@ -43,6 +44,9 @@
-   void init_upnp();
-   void upnp_add_redir (const char * addr, int port);
-   void upnp_rem_redir(int port);
-+
-+  /* Currently forwarded port */
-+  quint16 forwardedPort;
- };
- 
- #endif 



More information about the tor-commits mailing list