[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[vidalia-svn] r3800: Update the miniupnpc code to the 2009/04/17 release tarball, (in vidalia/trunk/src: miniupnpc vidalia/config)



Author: edmanm
Date: 2009-05-29 20:36:22 -0400 (Fri, 29 May 2009)
New Revision: 3800

Added:
   vidalia/trunk/src/miniupnpc/codelength.h
   vidalia/trunk/src/miniupnpc/miniupnpcstrings.h
Modified:
   vidalia/trunk/src/miniupnpc/igd_desc_parse.c
   vidalia/trunk/src/miniupnpc/igd_desc_parse.h
   vidalia/trunk/src/miniupnpc/minisoap.c
   vidalia/trunk/src/miniupnpc/minissdpc.c
   vidalia/trunk/src/miniupnpc/miniupnpc.c
   vidalia/trunk/src/miniupnpc/miniupnpc.h
   vidalia/trunk/src/miniupnpc/miniupnpcmodule.c
   vidalia/trunk/src/miniupnpc/miniwget.c
   vidalia/trunk/src/miniupnpc/upnpcommands.c
   vidalia/trunk/src/miniupnpc/upnpcommands.h
   vidalia/trunk/src/miniupnpc/upnperrors.c
   vidalia/trunk/src/miniupnpc/upnperrors.h
   vidalia/trunk/src/vidalia/config/UPNPControlThread.cpp
Log:

Update the miniupnpc code to the 2009/04/17 release tarball, and make
UPNPControlThread work with the updated library again.


Added: vidalia/trunk/src/miniupnpc/codelength.h
===================================================================
--- vidalia/trunk/src/miniupnpc/codelength.h	                        (rev 0)
+++ vidalia/trunk/src/miniupnpc/codelength.h	2009-05-30 00:36:22 UTC (rev 3800)
@@ -0,0 +1,24 @@
+/* $Id: codelength.h,v 1.1 2008/10/06 22:04:06 nanard Exp $ */
+/* Project : miniupnp
+ * Author : Thomas BERNARD
+ * copyright (c) 2005-2008 Thomas Bernard
+ * This software is subjet to the conditions detailed in the
+ * provided LICENCE file. */
+#ifndef __CODELENGTH_H__
+#define __CODELENGTH_H__
+
+/* Encode length by using 7bit per Byte :
+ * Most significant bit of each byte specifies that the
+ * following byte is part of the code */
+#define DECODELENGTH(n, p) n = 0; \
+                           do { n = (n << 7) | (*p & 0x7f); } \
+                           while(*(p++)&0x80);
+
+#define CODELENGTH(n, p) if(n>=268435456) *(p++) = (n >> 28) | 0x80; \
+                         if(n>=2097152) *(p++) = (n >> 21) | 0x80; \
+                         if(n>=16384) *(p++) = (n >> 14) | 0x80; \
+                         if(n>=128) *(p++) = (n >> 7) | 0x80; \
+                         *(p++) = n & 0x7f;
+
+#endif
+

Modified: vidalia/trunk/src/miniupnpc/igd_desc_parse.c
===================================================================
--- vidalia/trunk/src/miniupnpc/igd_desc_parse.c	2009-05-29 22:27:23 UTC (rev 3799)
+++ vidalia/trunk/src/miniupnpc/igd_desc_parse.c	2009-05-30 00:36:22 UTC (rev 3800)
@@ -1,8 +1,8 @@
-/* $Id: igd_desc_parse.c,v 1.7 2006/11/19 22:32:33 nanard Exp $ */
+/* $Id: igd_desc_parse.c,v 1.8 2008/04/23 11:51:06 nanard Exp $ */
 /* Project : miniupnp
  * http://miniupnp.free.fr/
  * Author : Thomas Bernard
- * Copyright (c) 2005 Thomas Bernard
+ * Copyright (c) 2005-2008 Thomas Bernard
  * This software is subject to the conditions detailed in the
  * LICENCE file provided in this distribution.
  * */
@@ -10,6 +10,9 @@
 #include <stdio.h>
 #include <string.h>
 
+/* TODO : rewrite this code so it correctly handle descriptions with
+ * both WANIPConnection and/or WANPPPConnection */
+
 /* Start element handler :
  * update nesting level counter and copy element name */
 void IGDstartelt(void * d, const char * name, int l)
@@ -18,6 +21,12 @@
 	memcpy( datas->cureltname, name, l);
 	datas->cureltname[l] = '\0';
 	datas->level++;
+	if( (l==7) && !memcmp(name, "service", l) ) {
+		datas->controlurl_tmp[0] = '\0';
+		datas->eventsuburl_tmp[0] = '\0';
+		datas->scpdurl_tmp[0] = '\0';
+		datas->servicetype_tmp[0] = '\0';
+	}
 }
 
 /* End element handler :
@@ -30,7 +39,6 @@
 	/*printf("endelt %2d %.*s\n", datas->level, l, name);*/
 	if( (l==7) && !memcmp(name, "service", l) )
 	{
-		/*datas->state++; */
 		/*
 		if( datas->state < 1
 			&& !strcmp(datas->servicetype,
@@ -38,15 +46,21 @@
 				"urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1"))
 			datas->state ++;
 		*/
-		if(0==strcmp(datas->servicetype_CIF,
-				"urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1"))
-			datas->state = 2;
-		if(0==strcmp(datas->servicetype,
-				"urn:schemas-upnp-org:service:WANIPConnection:1") )
-			datas->state = 3;
-/*		if(0==strcmp(datas->servicetype,
-				"urn:schemas-upnp-org:service:WANPPPConnection:1") )
-			datas->state = 4; */
+		if(0==strcmp(datas->servicetype_tmp,
+				"urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1")) {
+			memcpy(datas->controlurl_CIF, datas->controlurl_tmp, MINIUPNPC_URL_MAXSIZE);
+			memcpy(datas->eventsuburl_CIF, datas->eventsuburl_tmp, MINIUPNPC_URL_MAXSIZE);
+			memcpy(datas->scpdurl_CIF, datas->scpdurl_tmp, MINIUPNPC_URL_MAXSIZE);
+			memcpy(datas->servicetype_CIF, datas->servicetype_tmp, MINIUPNPC_URL_MAXSIZE);
+		} else if(0==strcmp(datas->servicetype_tmp,
+				"urn:schemas-upnp-org:service:WANIPConnection:1")
+				 || 0==strcmp(datas->servicetype_tmp,
+				"urn:schemas-upnp-org:service:WANPPPConnection:1") ) {
+			memcpy(datas->controlurl, datas->controlurl_tmp, MINIUPNPC_URL_MAXSIZE);
+			memcpy(datas->eventsuburl, datas->eventsuburl_tmp, MINIUPNPC_URL_MAXSIZE);
+			memcpy(datas->scpdurl, datas->scpdurl_tmp, MINIUPNPC_URL_MAXSIZE);
+			memcpy(datas->servicetype, datas->servicetype_tmp, MINIUPNPC_URL_MAXSIZE);
+		}
 	}
 }
 
@@ -60,32 +74,16 @@
            datas->level, datas->cureltname, l, data);	*/
 	if( !strcmp(datas->cureltname, "URLBase") )
 		dstmember = datas->urlbase;
-	else if(datas->state<=1)
-	{
-		if( !strcmp(datas->cureltname, "serviceType") )
-			dstmember = datas->servicetype_CIF;
-		else if( !strcmp(datas->cureltname, "controlURL") )
-			dstmember = datas->controlurl_CIF;
-		else if( !strcmp(datas->cureltname, "eventSubURL") )
-			dstmember = datas->eventsuburl_CIF;
-		else if( !strcmp(datas->cureltname, "SCPDURL") )
-			dstmember = datas->scpdurl_CIF;
-		else if( !strcmp(datas->cureltname, "deviceType") )
-			dstmember = datas->devicetype_CIF;
-	}
-	else if(datas->state==2)
-	{
-		if( !strcmp(datas->cureltname, "serviceType") )
-			dstmember = datas->servicetype;
-		else if( !strcmp(datas->cureltname, "controlURL") )
-			dstmember = datas->controlurl;
-		else if( !strcmp(datas->cureltname, "eventSubURL") )
-			dstmember = datas->eventsuburl;
-		else if( !strcmp(datas->cureltname, "SCPDURL") )
-			dstmember = datas->scpdurl;
-		else if( !strcmp(datas->cureltname, "deviceType") )
-			dstmember = datas->devicetype;
-	}
+	else if( !strcmp(datas->cureltname, "serviceType") )
+		dstmember = datas->servicetype_tmp;
+	else if( !strcmp(datas->cureltname, "controlURL") )
+		dstmember = datas->controlurl_tmp;
+	else if( !strcmp(datas->cureltname, "eventSubURL") )
+		dstmember = datas->eventsuburl_tmp;
+	else if( !strcmp(datas->cureltname, "SCPDURL") )
+		dstmember = datas->scpdurl_tmp;
+/*	else if( !strcmp(datas->cureltname, "deviceType") )
+		dstmember = datas->devicetype_tmp;*/
 	if(dstmember)
 	{
 		if(l>=MINIUPNPC_URL_MAXSIZE)
@@ -99,13 +97,13 @@
 {
 	printf("urlbase = %s\n", d->urlbase);
 	printf("WAN Device (Common interface config) :\n");
-	printf(" deviceType = %s\n", d->devicetype_CIF);
+	/*printf(" deviceType = %s\n", d->devicetype_CIF);*/
 	printf(" serviceType = %s\n", d->servicetype_CIF);
 	printf(" controlURL = %s\n", d->controlurl_CIF);
 	printf(" eventSubURL = %s\n", d->eventsuburl_CIF);
 	printf(" SCPDURL = %s\n", d->scpdurl_CIF);
-	printf("WAN Connection Device :\n");
-	printf(" deviceType = %s\n", d->devicetype);
+	printf("WAN Connection Device (IP or PPP Connection):\n");
+	/*printf(" deviceType = %s\n", d->devicetype);*/
 	printf(" servicetype = %s\n", d->servicetype);
 	printf(" controlURL = %s\n", d->controlurl);
 	printf(" eventSubURL = %s\n", d->eventsuburl);

Modified: vidalia/trunk/src/miniupnpc/igd_desc_parse.h
===================================================================
--- vidalia/trunk/src/miniupnpc/igd_desc_parse.h	2009-05-29 22:27:23 UTC (rev 3799)
+++ vidalia/trunk/src/miniupnpc/igd_desc_parse.h	2009-05-30 00:36:22 UTC (rev 3800)
@@ -1,8 +1,8 @@
-/* $Id: igd_desc_parse.h,v 1.5 2007/04/11 15:21:09 nanard Exp $ */
+/* $Id: igd_desc_parse.h,v 1.6 2008/04/23 11:51:07 nanard Exp $ */
 /* Project : miniupnp
  * http://miniupnp.free.fr/
  * Author : Thomas Bernard
- * Copyright (c) 2005 Thomas Bernard
+ * Copyright (c) 2005-2008 Thomas Bernard
  * This software is subject to the conditions detailed in the
  * LICENCE file provided in this distribution.
  * */
@@ -16,17 +16,26 @@
 	char cureltname[MINIUPNPC_URL_MAXSIZE];
 	char urlbase[MINIUPNPC_URL_MAXSIZE];
 	int level;
-	int state;
+	/*int state;*/
+	/* "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1" */
 	char controlurl_CIF[MINIUPNPC_URL_MAXSIZE];
 	char eventsuburl_CIF[MINIUPNPC_URL_MAXSIZE];
 	char scpdurl_CIF[MINIUPNPC_URL_MAXSIZE];
 	char servicetype_CIF[MINIUPNPC_URL_MAXSIZE];
-	char devicetype_CIF[MINIUPNPC_URL_MAXSIZE];
+	/*char devicetype_CIF[MINIUPNPC_URL_MAXSIZE];*/
+	/* "urn:schemas-upnp-org:service:WANIPConnection:1"
+	 * "urn:schemas-upnp-org:service:WANPPPConnection:1" */
 	char controlurl[MINIUPNPC_URL_MAXSIZE];
 	char eventsuburl[MINIUPNPC_URL_MAXSIZE];
 	char scpdurl[MINIUPNPC_URL_MAXSIZE];
 	char servicetype[MINIUPNPC_URL_MAXSIZE];
-	char devicetype[MINIUPNPC_URL_MAXSIZE];
+	/*char devicetype[MINIUPNPC_URL_MAXSIZE];*/
+	/* tmp */
+	char controlurl_tmp[MINIUPNPC_URL_MAXSIZE];
+	char eventsuburl_tmp[MINIUPNPC_URL_MAXSIZE];
+	char scpdurl_tmp[MINIUPNPC_URL_MAXSIZE];
+	char servicetype_tmp[MINIUPNPC_URL_MAXSIZE];
+	/*char devicetype_tmp[MINIUPNPC_URL_MAXSIZE];*/
 };
 
 void IGDstartelt(void *, const char *, int);

Modified: vidalia/trunk/src/miniupnpc/minisoap.c
===================================================================
--- vidalia/trunk/src/miniupnpc/minisoap.c	2009-05-29 22:27:23 UTC (rev 3799)
+++ vidalia/trunk/src/miniupnpc/minisoap.c	2009-05-30 00:36:22 UTC (rev 3800)
@@ -1,4 +1,4 @@
-/* $Id: minisoap.c,v 1.15 2008/02/17 17:57:07 nanard Exp $ */
+/* $Id: minisoap.c,v 1.16 2008/10/11 16:39:29 nanard Exp $ */
 /* Project : miniupnp
  * Author : Thomas Bernard
  * Copyright (c) 2005 Thomas Bernard
@@ -19,6 +19,7 @@
 #include <sys/socket.h>
 #endif
 #include "minisoap.h"
+#include "miniupnpcstrings.h"
 
 /* only for malloc */
 #include <stdlib.h>
@@ -92,7 +93,7 @@
                        "POST %s HTTP/1.1\r\n"
 /*                       "POST %s HTTP/1.0\r\n"*/
 	                   "Host: %s%s\r\n"
-					   "User-Agent: POSIX, UPnP/1.0, miniUPnPc/1.0\r\n"
+					   "User-Agent: " OS_STRING ", UPnP/1.0, MiniUPnPc/" MINIUPNPC_VERSION_STRING "\r\n"
 	                   "Content-Length: %d\r\n"
 					   "Content-Type: text/xml\r\n"
 					   "SOAPAction: \"%s\"\r\n"

Modified: vidalia/trunk/src/miniupnpc/minissdpc.c
===================================================================
--- vidalia/trunk/src/miniupnpc/minissdpc.c	2009-05-29 22:27:23 UTC (rev 3799)
+++ vidalia/trunk/src/miniupnpc/minissdpc.c	2009-05-30 00:36:22 UTC (rev 3800)
@@ -1,7 +1,7 @@
-/* $Id: minissdpc.c,v 1.4 2007/12/19 14:56:58 nanard Exp $ */
+/* $Id: minissdpc.c,v 1.7 2008/12/18 17:45:48 nanard Exp $ */
 /* Project : miniupnp
  * Author : Thomas BERNARD
- * copyright (c) 2005-2007 Thomas Bernard
+ * copyright (c) 2005-2008 Thomas Bernard
  * This software is subjet to the conditions detailed in the
  * provided LICENCE file. */
 /*#include <syslog.h>*/
@@ -10,17 +10,19 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <sys/types.h>
+#ifdef WIN32
+#include <winsock2.h>
+#include <Ws2tcpip.h>
+#include <io.h>
+#else
 #include <sys/socket.h>
 #include <sys/un.h>
+#endif
 
 #include "minissdpc.h"
 #include "miniupnpc.h"
 
-#define DECODELENGTH(n, p) n = 0; \
-                           do { n = (n << 7) | (*p & 0x7f); } \
-                           while(*(p++)&0x80);
-#define CODELENGTH(n, p) do { *p = (n & 0x7f) | ((n > 0x7f) ? 0x80 : 0); \
-                              p++; n >>= 7; } while(n);
+#include "codelength.h"
 
 struct UPNPDev *
 getDevicesFromMiniSSDPD(const char * devtype, const char * socketpath)
@@ -52,7 +54,7 @@
 		return NULL;
 	}
 	stsize = strlen(devtype);
-	buffer[0] = 1;
+	buffer[0] = 1; /* request type 1 : request devices/services by type */
 	p = buffer + 1;
 	l = stsize;	CODELENGTH(l, p);
 	memcpy(p, devtype, stsize);

Modified: vidalia/trunk/src/miniupnpc/miniupnpc.c
===================================================================
--- vidalia/trunk/src/miniupnpc/miniupnpc.c	2009-05-29 22:27:23 UTC (rev 3799)
+++ vidalia/trunk/src/miniupnpc/miniupnpc.c	2009-05-30 00:36:22 UTC (rev 3800)
@@ -1,4 +1,4 @@
-/* $Id: miniupnpc.c,v 1.52 2008/02/18 13:28:33 nanard Exp $ */
+/* $Id: miniupnpc.c,v 1.57 2008/12/18 17:46:36 nanard Exp $ */
 /* Project : miniupnp
  * Author : Thomas BERNARD
  * copyright (c) 2005-2007 Thomas Bernard
@@ -8,13 +8,19 @@
 #include <stdlib.h>
 #include <string.h>
 #ifdef WIN32
+/* Win32 Specific includes and defines */
 #include <winsock2.h>
 #include <Ws2tcpip.h>
 #include <io.h>
 #define snprintf _snprintf
+#if defined(_MSC_VER) && (_MSC_VER >= 1400)
+#define strncasecmp _memicmp
+#else
 #define strncasecmp memicmp
+#endif
 #define MAXHOSTNAMELEN 64
 #else
+/* Standard POSIX includes */
 #include <unistd.h>
 #include <sys/socket.h>
 #include <sys/types.h>
@@ -32,18 +38,16 @@
 #include "minixml.h"
 #include "upnpcommands.h"
 
-/* Uncomment the following to transmit the msearch from the same port
- * as the UPnP multicast port. With WinXP this seems to result in the
- * responses to the msearch being lost, thus if things dont work then
- * comment this out. */
-/* #define TX_FROM_UPNP_PORT */
-
 #ifdef WIN32
 #define PRINT_SOCKET_ERROR(x)    printf("Socket error: %s, %d\n", x, WSAGetLastError());
 #else
 #define PRINT_SOCKET_ERROR(x) perror(x)
 #endif
 
+#define SOAPPREFIX "s"
+#define SERVICEPREFIX "u"
+#define SERVICEPREFIX2 'u'
+
 /* root description parsing */
 void parserootdesc(const char * buffer, int bufsize, struct IGDdatas * data)
 {
@@ -57,7 +61,7 @@
 	parser.datafunc = IGDdata;
 	parser.attfunc = 0;
 	parsexml(&parser);
-#ifndef NDEBUG
+#ifdef DEBUG
 	printIGD(data);
 #endif
 }
@@ -141,7 +145,6 @@
 	char * path;
 	char soapact[128];
 	char soapbody[2048];
-	int soapbodylen;
 	char * buf;
 	int buffree;
     int n;
@@ -149,37 +152,29 @@
 	snprintf(soapact, sizeof(soapact), "%s#%s", service, action);
 	if(args==NULL)
 	{
-		/*soapbodylen = snprintf(soapbody, sizeof(soapbody),
+		/*soapbodylen = */snprintf(soapbody, sizeof(soapbody),
 						"<?xml version=\"1.0\"?>\r\n"
-	    	              "<SOAP-ENV:Envelope "
-						  "xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"; "
-						  "SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\";>"
-						  "<SOAP-ENV:Body>"
-						  "<m:%s xmlns:m=\"%s\"/>"
-						  "</SOAP-ENV:Body></SOAP-ENV:Envelope>"
-					 	  "\r\n", action, service);*/
-		soapbodylen = snprintf(soapbody, sizeof(soapbody),
-						"<?xml version=\"1.0\"?>\r\n"
-	    	              "<s:Envelope "
-						  "xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"; "
-						  "s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\";>"
-						  "<s:Body>"
-						  "<m:%s xmlns:m=\"%s\">"
-						  "</m:%s>"
-						  "</s:Body></s:Envelope>"
+	    	              "<" SOAPPREFIX ":Envelope "
+						  "xmlns:" SOAPPREFIX "=\"http://schemas.xmlsoap.org/soap/envelope/\"; "
+						  SOAPPREFIX ":encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\";>"
+						  "<" SOAPPREFIX ":Body>"
+						  "<" SERVICEPREFIX ":%s xmlns:" SERVICEPREFIX "=\"%s\">"
+						  "</" SERVICEPREFIX ":%s>"
+						  "</" SOAPPREFIX ":Body></" SOAPPREFIX ":Envelope>"
 					 	  "\r\n", action, service, action);
 	}
 	else
 	{
 		char * p;
 		const char * pe, * pv;
+		int soapbodylen;
 		soapbodylen = snprintf(soapbody, sizeof(soapbody),
 						"<?xml version=\"1.0\"?>\r\n"
-	    	            "<SOAP-ENV:Envelope "
-						"xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"; "
-						"SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\";>"
-						"<SOAP-ENV:Body>"
-						"<m:%s xmlns:m=\"%s\">",
+	    	            "<" SOAPPREFIX ":Envelope "
+						"xmlns:" SOAPPREFIX "=\"http://schemas.xmlsoap.org/soap/envelope/\"; "
+						SOAPPREFIX ":encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\";>"
+						"<" SOAPPREFIX ":Body>"
+						"<" SERVICEPREFIX ":%s xmlns:" SERVICEPREFIX "=\"%s\">",
 						action, service);
 		p = soapbody + soapbodylen;
 		while(args->elt)
@@ -211,12 +206,12 @@
 		}
 		*(p++) = '<';
 		*(p++) = '/';
-		*(p++) = 'm';
+		*(p++) = SERVICEPREFIX2;
 		*(p++) = ':';
 		pe = action;
 		while(*pe)
 			*(p++) = *(pe++);
-		strncpy(p, "></SOAP-ENV:Body></SOAP-ENV:Envelope>\r\n",
+		strncpy(p, "></" SOAPPREFIX ":Body></" SOAPPREFIX ":Envelope>\r\n",
 		        soapbody + sizeof(soapbody) - p);
 	}
 	if(!parseURL(url, hostname, &port, &path)) return -1;
@@ -335,7 +330,9 @@
 }
 
 /* port upnp discover : SSDP protocol */
-#define PORT (1900)
+#define PORT 1900
+#define XSTR(s) STR(s)
+#define STR(s) #s
 #define UPNP_MCAST_ADDR "239.255.255.250"
 
 /* upnpDiscover() :
@@ -344,14 +341,14 @@
  * It is up to the caller to free the chained list
  * delay is in millisecond (poll) */
 struct UPNPDev * upnpDiscover(int delay, const char * multicastif,
-                              const char * minissdpdsock)
+                              const char * minissdpdsock, int sameport)
 {
 	struct UPNPDev * tmp;
 	struct UPNPDev * devlist = 0;
 	int opt = 1;
 	static const char MSearchMsgFmt[] = 
 	"M-SEARCH * HTTP/1.1\r\n"
-	"HOST: " UPNP_MCAST_ADDR ":" "1900" "\r\n"
+	"HOST: " UPNP_MCAST_ADDR ":" XSTR(PORT) "\r\n"
 	"ST: %s\r\n"
 	"MAN: \"ssdp:discover\"\r\n"
 	"MX: 3\r\n"
@@ -397,9 +394,8 @@
     /* reception */
     memset(&sockudp_r, 0, sizeof(struct sockaddr_in));
     sockudp_r.sin_family = AF_INET;
-#ifdef TX_FROM_UPNP_PORT
-    sockudp_r.sin_port = htons(PORT);
-#endif
+	if(sameport)
+    	sockudp_r.sin_port = htons(PORT);
     sockudp_r.sin_addr.s_addr = INADDR_ANY;
     /* emission */
     memset(&sockudp_w, 0, sizeof(struct sockaddr_in));

Modified: vidalia/trunk/src/miniupnpc/miniupnpc.h
===================================================================
--- vidalia/trunk/src/miniupnpc/miniupnpc.h	2009-05-29 22:27:23 UTC (rev 3799)
+++ vidalia/trunk/src/miniupnpc/miniupnpc.h	2009-05-30 00:36:22 UTC (rev 3800)
@@ -1,4 +1,4 @@
-/* $Id: miniupnpc.h,v 1.17 2007/12/19 14:58:54 nanard Exp $ */
+/* $Id: miniupnpc.h,v 1.18 2008/09/25 18:02:50 nanard Exp $ */
 /* Project: miniupnp
  * http://miniupnp.free.fr/
  * Author: Thomas Bernard
@@ -39,9 +39,11 @@
  * Default path for minissdpd socket will be used if minissdpdsock argument
  * is NULL.
  * If multicastif is not NULL, it will be used instead of the default
- * multicast interface for sending SSDP discover packets. */
+ * multicast interface for sending SSDP discover packets.
+ * If sameport is not null, SSDP packets will be sent from the source port
+ * 1900 (same as destination port) otherwise system assign a source port. */
 LIBSPEC struct UPNPDev * upnpDiscover(int delay, const char * multicastif,
-                                      const char * minissdpdsock);
+                                      const char * minissdpdsock, int sameport);
 /* freeUPNPDevlist()
  * free list returned by upnpDiscover() */
 LIBSPEC void freeUPNPDevlist(struct UPNPDev * devlist);

Modified: vidalia/trunk/src/miniupnpc/miniupnpcmodule.c
===================================================================
--- vidalia/trunk/src/miniupnpc/miniupnpcmodule.c	2009-05-29 22:27:23 UTC (rev 3799)
+++ vidalia/trunk/src/miniupnpc/miniupnpcmodule.c	2009-05-30 00:36:22 UTC (rev 3800)
@@ -1,4 +1,4 @@
-/* $Id: miniupnpcmodule.c,v 1.7 2007/12/19 15:00:47 nanard Exp $*/
+/* $Id: miniupnpcmodule.c,v 1.13 2009/04/17 20:59:42 nanard Exp $*/
 /* Project : miniupnp
  * Author : Thomas BERNARD
  * website : http://miniupnp.tuxfamily.org/
@@ -10,6 +10,7 @@
 #include "structmember.h"
 #include "miniupnpc.h"
 #include "upnpcommands.h"
+#include "upnperrors.h"
 
 /* for compatibility with Python < 2.4 */
 #ifndef Py_RETURN_NONE
@@ -74,7 +75,8 @@
 	}
 	self->devlist = upnpDiscover((int)self->discoverdelay/*timeout in ms*/,
 	                             0/* multicast if*/,
-	                             0/*minissdpd socket*/);
+	                             0/*minissdpd socket*/,
+								 0/*sameport flag*/);
 	/* Py_RETURN_NONE ??? */
 	for(dev = self->devlist, i = 0; dev; dev = dev->pNext)
 		i++;
@@ -134,36 +136,60 @@
 UPnP_statusinfo(UPnPObject *self)
 {
 	char status[64];
+	char lastconnerror[64];
 	unsigned int uptime = 0;
+	int r;
 	status[0] = '\0';
-	UPNP_GetStatusInfo(self->urls.controlURL, self->data.servicetype,
-	                   status, &uptime);
-	return Py_BuildValue("(s,I)", status, uptime);
+	lastconnerror[0] = '\0';
+	r = UPNP_GetStatusInfo(self->urls.controlURL, self->data.servicetype,
+	                   status, &uptime, lastconnerror);
+	if(r==UPNPCOMMAND_SUCCESS) {
+		return Py_BuildValue("(s,I,s)", status, uptime, lastconnerror);
+	} else {
+		/* TODO: have our own exception type ! */
+		PyErr_SetString(PyExc_Exception, strupnperror(r));
+		return NULL;
+	}
 }
 
 static PyObject *
 UPnP_connectiontype(UPnPObject *self)
 {
 	char connectionType[64];
+	int r;
 	connectionType[0] = '\0';
-	UPNP_GetConnectionTypeInfo(self->urls.controlURL,
-	                           self->data.servicetype,
-							   connectionType);
-	return Py_BuildValue("s", connectionType);
+	r = UPNP_GetConnectionTypeInfo(self->urls.controlURL,
+	                               self->data.servicetype,
+	                               connectionType);
+	if(r==UPNPCOMMAND_SUCCESS) {
+		return Py_BuildValue("s", connectionType);
+	} else {
+		/* TODO: have our own exception type ! */
+		PyErr_SetString(PyExc_Exception, strupnperror(r));
+		return NULL;
+	}
 }
 
 static PyObject *
 UPnP_externalipaddress(UPnPObject *self)
 {
 	char externalIPAddress[16];
+	int r;
 	externalIPAddress[0] = '\0';
-	UPNP_GetExternalIPAddress(self->urls.controlURL,
-	                          self->data.servicetype,
-							  externalIPAddress);
-	return Py_BuildValue("s", externalIPAddress);
+	r = UPNP_GetExternalIPAddress(self->urls.controlURL,
+	                              self->data.servicetype,
+	                              externalIPAddress);
+	if(r==UPNPCOMMAND_SUCCESS) {
+		return Py_BuildValue("s", externalIPAddress);
+	} else {
+		/* TODO: have our own exception type ! */
+		PyErr_SetString(PyExc_Exception, strupnperror(r));
+		return NULL;
+	}
 }
 
-/* AddPortMapping(externalPort, protocol, internalHost, internalPort, desc) 
+/* AddPortMapping(externalPort, protocol, internalHost, internalPort, desc,
+ *                remoteHost) 
  * protocol is 'UDP' or 'TCP' */
 static PyObject *
 UPnP_addportmapping(UPnPObject *self, PyObject *args)
@@ -175,25 +201,31 @@
 	const char * proto;
 	const char * host;
 	const char * desc;
+	const char * remoteHost;
 	int r;
-	if (!PyArg_ParseTuple(args, "HssHs", &ePort, &proto,
-	                                     &host, &iPort, &desc))
+	if (!PyArg_ParseTuple(args, "HssHss", &ePort, &proto,
+	                                     &host, &iPort, &desc, &remoteHost))
         return NULL;
 	sprintf(extPort, "%hu", ePort);
 	sprintf(inPort, "%hu", iPort);
 	r = UPNP_AddPortMapping(self->urls.controlURL, self->data.servicetype,
-	                        extPort, inPort, host, desc, proto);
-	if(r)
+	                        extPort, inPort, host, desc, proto, remoteHost);
+	if(r==UPNPCOMMAND_SUCCESS)
 	{
 		Py_RETURN_TRUE;
 	}
 	else
 	{
-		Py_RETURN_FALSE;
+		// TODO: RAISE an Exception. See upnpcommands.h for errors codes.
+		// upnperrors.c
+		//Py_RETURN_FALSE;
+		/* TODO: have our own exception type ! */
+		PyErr_SetString(PyExc_Exception, strupnperror(r));
+		return NULL;
 	}
 }
 
-/* DeletePortMapping(extPort, proto)
+/* DeletePortMapping(extPort, proto, removeHost='')
  * proto = 'UDP', 'TCP' */
 static PyObject *
 UPnP_deleteportmapping(UPnPObject *self, PyObject *args)
@@ -201,22 +233,37 @@
 	char extPort[6];
 	unsigned short ePort;
 	const char * proto;
-	if(!PyArg_ParseTuple(args, "Hs", &ePort, &proto))
+	const char * remoteHost = "";
+	int r;
+	if(!PyArg_ParseTuple(args, "Hs|z", &ePort, &proto, &remoteHost))
 		return NULL;
 	sprintf(extPort, "%hu", ePort);
-	UPNP_DeletePortMapping(self->urls.controlURL, self->data.servicetype,
-	                       extPort, proto);
-	Py_RETURN_TRUE;
+	r = UPNP_DeletePortMapping(self->urls.controlURL, self->data.servicetype,
+	                           extPort, proto, remoteHost);
+	if(r==UPNPCOMMAND_SUCCESS) {
+		Py_RETURN_TRUE;
+	} else {
+		/* TODO: have our own exception type ! */
+		PyErr_SetString(PyExc_Exception, strupnperror(r));
+		return NULL;
+	}
 }
 
 static PyObject *
 UPnP_getportmappingnumberofentries(UPnPObject *self)
 {
 	unsigned int n = 0;
-	UPNP_GetPortMappingNumberOfEntries(self->urls.controlURL,
+	int r;
+	r = UPNP_GetPortMappingNumberOfEntries(self->urls.controlURL,
 	                                   self->data.servicetype,
 									   &n);
-	return Py_BuildValue("I", n);
+	if(r==UPNPCOMMAND_SUCCESS) {
+		return Py_BuildValue("I", n);
+	} else {
+		/* TODO: have our own exception type ! */
+		PyErr_SetString(PyExc_Exception, strupnperror(r));
+		return NULL;
+	}
 }
 
 /* GetSpecificPortMapping(ePort, proto) 
@@ -277,12 +324,8 @@
 										extPort, intClient, intPort,
 										protocol, desc, enabled, rHost,
 										duration);
-	if(r)
+	if(r==UPNPCOMMAND_SUCCESS)
 	{
-		Py_RETURN_NONE;
-	}
-	else
-	{
 		ePort = (unsigned short)atoi(extPort);
 		iPort = (unsigned short)atoi(intPort);
 		dur = (unsigned int)strtoul(duration, 0, 0);
@@ -290,6 +333,10 @@
 		                     ePort, protocol, intClient, iPort,
 		                     desc, enabled, rHost, dur);
 	}
+	else
+	{
+		Py_RETURN_NONE;
+	}
 }
 
 /* miniupnpc.UPnP object Method Table */

Added: vidalia/trunk/src/miniupnpc/miniupnpcstrings.h
===================================================================
--- vidalia/trunk/src/miniupnpc/miniupnpcstrings.h	                        (rev 0)
+++ vidalia/trunk/src/miniupnpc/miniupnpcstrings.h	2009-05-30 00:36:22 UTC (rev 3800)
@@ -0,0 +1,15 @@
+/* $Id: miniupnpcstrings.h,v 1.2 2008/10/14 17:39:04 nanard Exp $ */
+/* Project: miniupnp
+ * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
+ * Author: Thomas Bernard
+ * Copyright (c) 2005-2008 Thomas Bernard
+ * This software is subjects to the conditions detailed
+ * in the LICENCE file provided within this distribution */
+#ifndef __MINIUPNPCSTRINGS_H__
+#define __MINIUPNPCSTRINGS_H__
+
+#define OS_STRING "Debian/4.0"
+#define MINIUPNPC_VERSION_STRING "1.2"
+
+#endif
+

Modified: vidalia/trunk/src/miniupnpc/miniwget.c
===================================================================
--- vidalia/trunk/src/miniupnpc/miniwget.c	2009-05-29 22:27:23 UTC (rev 3799)
+++ vidalia/trunk/src/miniupnpc/miniwget.c	2009-05-30 00:36:22 UTC (rev 3800)
@@ -1,4 +1,4 @@
-/* $Id: miniwget.c,v 1.19 2007/11/02 14:16:19 nanard Exp $ */
+/* $Id: miniwget.c,v 1.22 2009/02/28 10:36:35 nanard Exp $ */
 /* Project : miniupnp
  * Author : Thomas Bernard
  * Copyright (c) 2005 Thomas Bernard
@@ -26,11 +26,12 @@
 #include <arpa/inet.h>
 #define closesocket close
 #endif
-/* for MIN() macro : */
 #if defined(__sun) || defined(sun)
-#include <utility.h>
+#define MIN(x,y) (((x)<(y))?(x):(y))
 #endif
 
+#include "miniupnpcstrings.h"
+
 /* miniwget2() :
  * */
 static void *
@@ -96,6 +97,8 @@
                  "GET %s HTTP/1.1\r\n"
 			     "Host: %s:%d\r\n"
 				 "Connection: Close\r\n"
+				 "User-Agent: " OS_STRING ", UPnP/1.0, MiniUPnPc/" MINIUPNPC_VERSION_STRING "\r\n"
+
 				 "\r\n",
 		    path, host, port);
 	/*write(s, buf, strlen(buf));*/
@@ -137,7 +140,7 @@
 			}
 		}
 		*size = allreadyread;
-#ifndef NDEBUG
+#ifdef DEBUG
 		printf("%d bytes read\n", *size);
 #endif
 		closesocket(s);

Modified: vidalia/trunk/src/miniupnpc/upnpcommands.c
===================================================================
--- vidalia/trunk/src/miniupnpc/upnpcommands.c	2009-05-29 22:27:23 UTC (rev 3799)
+++ vidalia/trunk/src/miniupnpc/upnpcommands.c	2009-05-30 00:36:22 UTC (rev 3800)
@@ -1,7 +1,7 @@
-/* $Id: upnpcommands.c,v 1.19 2008/02/18 13:27:23 nanard Exp $ */
+/* $Id: upnpcommands.c,v 1.24 2009/04/17 21:21:19 nanard Exp $ */
 /* Project : miniupnp
  * Author : Thomas Bernard
- * Copyright (c) 2005 Thomas Bernard
+ * Copyright (c) 2005-2009 Thomas Bernard
  * This software is subject to the conditions detailed in the
  * LICENCE file provided in this distribution.
  * */
@@ -11,15 +11,15 @@
 #include "upnpcommands.h"
 #include "miniupnpc.h"
 
-static unsigned int
+static UNSIGNED_INTEGER
 my_atoui(const char * s)
 {
-	return s ? ((unsigned int)strtoul(s, NULL, 0)) : 0;
+	return s ? ((UNSIGNED_INTEGER)STRTOUI(s, NULL, 0)) : 0;
 }
 
 /*
  * */
-unsigned int
+UNSIGNED_INTEGER
 UPNP_GetTotalBytesSent(const char * controlURL,
 					const char * servicetype)
 {
@@ -39,7 +39,7 @@
 
 /*
  * */
-unsigned int
+UNSIGNED_INTEGER
 UPNP_GetTotalBytesReceived(const char * controlURL,
 						const char * servicetype)
 {
@@ -59,7 +59,7 @@
 
 /*
  * */
-unsigned int
+UNSIGNED_INTEGER
 UPNP_GetTotalPacketsSent(const char * controlURL,
 						const char * servicetype)
 {
@@ -79,7 +79,7 @@
 
 /*
  * */
-unsigned int
+UNSIGNED_INTEGER
 UPNP_GetTotalPacketsReceived(const char * controlURL,
 						const char * servicetype)
 {
@@ -303,7 +303,8 @@
 					const char * inPort,
 					const char * inClient,
 					const char * desc,
-					const char * proto)
+					const char * proto,
+                    const char * remoteHost)
 {
 	struct UPNParg * AddPortMappingArgs;
 	char buffer[4096];
@@ -317,6 +318,7 @@
 
 	AddPortMappingArgs = calloc(9, sizeof(struct UPNParg));
 	AddPortMappingArgs[0].elt = "NewRemoteHost";
+	AddPortMappingArgs[0].val = remoteHost;
 	AddPortMappingArgs[1].elt = "NewExternalPort";
 	AddPortMappingArgs[1].val = extPort;
 	AddPortMappingArgs[2].elt = "NewProtocol";
@@ -351,7 +353,8 @@
 
 int
 UPNP_DeletePortMapping(const char * controlURL, const char * servicetype,
-                       const char * extPort, const char * proto)
+                       const char * extPort, const char * proto,
+                       const char * remoteHost)
 {
 	/*struct NameValueParserData pdata;*/
 	struct UPNParg * DeletePortMappingArgs;
@@ -366,6 +369,7 @@
 
 	DeletePortMappingArgs = calloc(4, sizeof(struct UPNParg));
 	DeletePortMappingArgs[0].elt = "NewRemoteHost";
+	DeletePortMappingArgs[0].val = remoteHost;
 	DeletePortMappingArgs[1].elt = "NewExternalPort";
 	DeletePortMappingArgs[1].val = extPort;
 	DeletePortMappingArgs[2].elt = "NewProtocol";
@@ -484,7 +488,7 @@
  	char* p;
 	int ret = UPNPCOMMAND_UNKNOWN_ERROR;
  	simpleUPnPcommand(-1, controlURL, servicetype, "GetPortMappingNumberOfEntries", 0, buffer, &bufsize);
-#ifndef NDEBUG
+#ifdef DEBUG
 	DisplayNameValueList(buffer, bufsize);
 #endif
  	ParseNameValue(buffer, bufsize, &pdata);

Modified: vidalia/trunk/src/miniupnpc/upnpcommands.h
===================================================================
--- vidalia/trunk/src/miniupnpc/upnpcommands.h	2009-05-29 22:27:23 UTC (rev 3799)
+++ vidalia/trunk/src/miniupnpc/upnpcommands.h	2009-05-30 00:36:22 UTC (rev 3800)
@@ -1,7 +1,7 @@
-/* $Id: upnpcommands.h,v 1.13 2008/02/18 13:27:24 nanard Exp $ */
+/* $Id: upnpcommands.h,v 1.17 2009/04/17 21:21:19 nanard Exp $ */
 /* Miniupnp project : http://miniupnp.free.fr/
  * Author : Thomas Bernard
- * Copyright (c) 2005-2006 Thomas Bernard
+ * Copyright (c) 2005-2008 Thomas Bernard
  * This software is subject to the conditions detailed in the
  * LICENCE file provided within this distribution */
 #ifndef __UPNPCOMMANDS_H__
@@ -19,19 +19,27 @@
 extern "C" {
 #endif
 
-LIBSPEC unsigned int
+#if (defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L)
+#define UNSIGNED_INTEGER unsigned long long
+#define STRTOUI	strtoull
+#else
+#define UNSIGNED_INTEGER unsigned int
+#define STRTOUI	strtoul
+#endif
+
+LIBSPEC UNSIGNED_INTEGER
 UPNP_GetTotalBytesSent(const char * controlURL,
 					const char * servicetype);
 
-LIBSPEC unsigned int
+LIBSPEC UNSIGNED_INTEGER
 UPNP_GetTotalBytesReceived(const char * controlURL,
 						const char * servicetype);
 
-LIBSPEC unsigned int
+LIBSPEC UNSIGNED_INTEGER
 UPNP_GetTotalPacketsSent(const char * controlURL,
 					const char * servicetype);
 
-LIBSPEC unsigned int
+LIBSPEC UNSIGNED_INTEGER
 UPNP_GetTotalPacketsReceived(const char * controlURL,
 					const char * servicetype);
 
@@ -86,6 +94,8 @@
 							unsigned int * bitrateUp);
 
 /* UPNP_AddPortMapping()
+ * if desc is NULL, it will be defaulted to "libminiupnpc"
+ * remoteHost is usually NULL because IGD don't support it.
  *
  * Return values :
  * 0 : SUCCESS
@@ -114,9 +124,12 @@
 				    const char * inPort,
 					const char * inClient,
 					const char * desc,
-                    const char * proto);
+                    const char * proto,
+                    const char * remoteHost);
 
 /* UPNP_DeletePortMapping()
+ * Use same argument values as what was used for AddPortMapping().
+ * remoteHost is usually NULL because IGD don't support it.
  * Return Values :
  * 0 : SUCCESS
  * NON ZERO : error. Either an UPnP error code or an undefined error.
@@ -126,7 +139,8 @@
  * 714 NoSuchEntryInArray - The specified value does not exist in the array */
 LIBSPEC int
 UPNP_DeletePortMapping(const char * controlURL, const char * servicetype,
-                       const char * extPort, const char * proto);
+                       const char * extPort, const char * proto,
+                       const char * remoteHost);
 
 /* UPNP_GetPortMappingNumberOfEntries()
  * not supported by all routers */

Modified: vidalia/trunk/src/miniupnpc/upnperrors.c
===================================================================
--- vidalia/trunk/src/miniupnpc/upnperrors.c	2009-05-29 22:27:23 UTC (rev 3799)
+++ vidalia/trunk/src/miniupnpc/upnperrors.c	2009-05-30 00:36:22 UTC (rev 3800)
@@ -1,17 +1,28 @@
-/* $Id: upnperrors.c,v 1.2 2008/02/05 12:50:22 nanard Exp $ */
+/* $Id: upnperrors.c,v 1.3 2008/04/27 17:21:51 nanard Exp $ */
 /* Project : miniupnp
  * Author : Thomas BERNARD
  * copyright (c) 2007 Thomas Bernard
  * All Right reserved.
+ * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
  * This software is subjet to the conditions detailed in the
  * provided LICENCE file. */
 #include <string.h>
 #include "upnperrors.h"
+#include "upnpcommands.h"
 
 const char * strupnperror(int err)
 {
 	const char * s = NULL;
 	switch(err) {
+	case UPNPCOMMAND_SUCCESS:
+		s = "Success";
+		break;
+	case UPNPCOMMAND_UNKNOWN_ERROR:
+		s = "Miniupnpc Unknown Error";
+		break;
+	case UPNPCOMMAND_INVALID_ARGS:
+		s = "Miniupnpc Invalid Arguments";
+		break;
 	case 401:
 		s = "Invalid Action";
 		break;

Modified: vidalia/trunk/src/miniupnpc/upnperrors.h
===================================================================
--- vidalia/trunk/src/miniupnpc/upnperrors.h	2009-05-29 22:27:23 UTC (rev 3799)
+++ vidalia/trunk/src/miniupnpc/upnperrors.h	2009-05-30 00:36:22 UTC (rev 3800)
@@ -1,4 +1,4 @@
-/* $Id: upnperrors.h,v 1.1 2007/12/22 11:28:04 nanard Exp $ */
+/* $Id: upnperrors.h,v 1.2 2008/07/02 23:31:15 nanard Exp $ */
 /* (c) 2007 Thomas Bernard
  * All rights reserved.
  * MiniUPnP Project.
@@ -8,9 +8,19 @@
 #ifndef __UPNPERRORS_H__
 #define __UPNPERRORS_H__
 
+#include "declspec.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /* strupnperror()
  * Return a string description of the UPnP error code 
  * or NULL for undefinded errors */
-const char * strupnperror(int err);
+LIBSPEC const char * strupnperror(int err);
 
+#ifdef __cplusplus
+}
 #endif
+
+#endif

Modified: vidalia/trunk/src/vidalia/config/UPNPControlThread.cpp
===================================================================
--- vidalia/trunk/src/vidalia/config/UPNPControlThread.cpp	2009-05-29 22:27:23 UTC (rev 3799)
+++ vidalia/trunk/src/vidalia/config/UPNPControlThread.cpp	2009-05-30 00:36:22 UTC (rev 3800)
@@ -246,7 +246,7 @@
 
   UPNPControl::instance()->setState(UPNPControl::DiscoverState);
 
-  devlist = upnpDiscover(UPNPCONTROL_DISCOVER_TIMEOUT, NULL, NULL);
+  devlist = upnpDiscover(UPNPCONTROL_DISCOVER_TIMEOUT, NULL, NULL, 0);
   if (NULL == devlist) {
     vWarn("upnpDiscover returned: NULL");
     return UPNPControl::NoUPNPDevicesFound;
@@ -281,7 +281,7 @@
   // Add the port mapping of external:port -> internal:port
   retval = UPNP_AddPortMapping(urls.controlURL, data.servicetype,
                                qPrintable(sPort), qPrintable(sPort), lanaddr,
-                               "Tor relay", "TCP");
+                               "Tor relay", "TCP", NULL);
   if(UPNPCOMMAND_SUCCESS != retval) {
     vWarn("AddPortMapping(%1, %2, %3) failed with code %4")
             .arg(sPort).arg(sPort).arg(lanaddr).arg(retval);
@@ -317,7 +317,7 @@
 
   // Remove the mapping
   int retval = UPNP_DeletePortMapping(urls.controlURL, data.servicetype,
-                                      qPrintable(sPort), "TCP");
+                                      qPrintable(sPort), "TCP", NULL);
   if(UPNPCOMMAND_SUCCESS != retval) {
     vWarn("DeletePortMapping() failed with code %1").arg(retval);
     return UPNPControl::DeletePortMappingFailed;