 +
 +/* TODO: We should call this periodically, in case the router gets rebooted or forgets its UPnP settings */
 +/* TODO: Remove port forwarding when Tor is shutdown or the ORPort changes */
++/* 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()
 +{
-+  ;
++  init_upnp();
 +}
 +
  /** Virtual method called when we retrieve a server-related setting from Tor.
   * Currently this just translates BandwidthFoo to RelayBandwidthFoo when
   * appropriate. */
+@@ -321,3 +390,4 @@
+   setValue(SETTING_BANDWIDTH_BURST, rate);
+ }
+ 
++
 Index: src/vidalia/config/serversettings.h
 ===================================================================
---- src/vidalia/config/serversettings.h	(revision 2423)
+--- src/vidalia/config/serversettings.h	(revision 2465)
 +++ src/vidalia/config/serversettings.h	(working copy)
-@@ -20,6 +20,9 @@
+@@ -20,6 +20,10 @@
  #include "abstracttorsettings.h"
  #include "exitpolicy.h"
  
++#define STATICLIB
 +#include <miniupnpc/miniwget.h>
 +#include <miniupnpc/miniupnpc.h>
 +#include <miniupnpc/upnpcommands.h>
  
  class ServerSettings : public AbstractTorSettings
  {
-@@ -89,8 +92,18 @@
+@@ -89,9 +93,20 @@
    virtual QVariant torValue(const QString &key) const;
  
  private:
 +  /** Used by miniupnpc library */
-+  static struct UPNPUrls urls;
-+  static struct IGDdatas data;
++  struct UPNPUrls urls;
++  struct IGDdatas data;
 +  void init_upnp();
 +  void upnp_add_redir (const char * addr, int port);
 +  void upnp_rem_redir(int port);

+ServerSettings::init_upnp()
+{
+  struct UPNPDev * devlist;
+  struct UPNPDev * dev;
+  char * descXML;
+  int descXMLsize = 0;
+  printf("TB : init_upnp()\n");
+  memset(&urls, 0, sizeof(struct UPNPUrls));
+  memset(&data, 0, sizeof(struct IGDdatas));
+  devlist = upnpDiscover(2000);
+  if (devlist)
+    {
+      dev = devlist;
+      while (dev)
+	{
+	  if (strstr (dev->st, "InternetGatewayDevice"))
+	    break;
+	  dev = dev->pNext;
+	}
+      if (!dev)
+	dev = devlist; /* defaulting to first device */
+
+      printf("UPnP device :\n"
+	     " desc: %s\n st: %s\n",
+	     dev->descURL, dev->st);
+
+      descXML = miniwget(dev->descURL, &descXMLsize);
+      if (descXML)
+	{
+	  parserootdesc (descXML, descXMLsize, &data);
+	  free (descXML); descXML = 0;
+	  GetUPNPUrls (&urls, &data, dev->descURL);
+	}
+      freeUPNPDevlist(devlist);
+    }
+
+}
+
+/** Based on http://miniupnp.free.fr/files/download.php?file=xchat-upnp20061022.patch */

 };
 
 #endif
 
+
