← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2361: update miniupnpc & ameliorate the initial device selection

 

------------------------------------------------------------
revno: 2361
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Wed 2010-12-22 19:35:14 +0100
message:
  update miniupnpc & ameliorate the initial device selection
modified:
  changelog.txt
  miniupnpc/Changelog.txt
  miniupnpc/connecthostport.c
  miniupnpc/igd_desc_parse.c
  miniupnpc/minisoap.c
  miniupnpc/miniupnpc.c
  miniupnpc/miniwget.c
  win32/UPnP_MiniUPnPc.cpp


--
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	2010-12-21 14:40:47 +0000
+++ changelog.txt	2010-12-22 18:35:14 +0000
@@ -60,6 +60,7 @@
 * Select a better default font (poy)
 * [L#681754] Fonts and dialogs respect DPI settings - mark DC++ as DPI aware (poy)
 * Update MiniUPnPc (poy)
+* Ameliorate the MiniUPnPc device selection
 * Prevent an endless loop on connection failure (thanks bigmuscle)
 
 -- 0.770 2010-07-05 --

=== modified file 'miniupnpc/Changelog.txt'
--- miniupnpc/Changelog.txt	2010-12-12 21:16:33 +0000
+++ miniupnpc/Changelog.txt	2010-12-22 18:35:14 +0000
@@ -1,9 +1,16 @@
-$Id: Changelog.txt,v 1.122 2010/12/09 16:11:31 nanard Exp $
+$Id: Changelog.txt,v 1.125 2010/12/21 16:13:13 nanard Exp $
 miniUPnP client Changelog.
 
+2010/12/21:
+  use NO_GETADDRINFO macro to disable the use of getaddrinfo/freeaddrinfo
+
+2010/12/11:
+  Improvements on getHTTPResponse() code.
+
 2010/12/09:
   new code for miniwget that handle Chunked transfer encoding
   using getHTTPResponse() in SOAP call code
+  Adding MANIFEST.in for 'python setup.py bdist_rpm'
 
 2010/11/25:
   changes to minissdpc.c to compile under Win32.

=== modified file 'miniupnpc/connecthostport.c'
--- miniupnpc/connecthostport.c	2010-06-18 12:09:55 +0000
+++ miniupnpc/connecthostport.c	2010-12-22 18:35:14 +0000
@@ -1,4 +1,4 @@
-/* $Id: connecthostport.c,v 1.2 2010/04/05 00:08:15 nanard Exp $ */
+/* $Id: connecthostport.c,v 1.3 2010/12/21 16:13:14 nanard Exp $ */
 /* Project : miniupnp
  * Author : Thomas Bernard
  * Copyright (c) 2010 Thomas Bernard
@@ -7,7 +7,9 @@
 
 /* use getaddrinfo() or gethostbyname()
  * uncomment the following line in order to use gethostbyname() */
-/* #define USE_GETHOSTBYNAME */
+#ifdef NO_GETADDRINFO
+#define USE_GETHOSTBYNAME
+#endif
 
 #include <string.h>
 #include <stdio.h>

=== modified file 'miniupnpc/igd_desc_parse.c'
--- miniupnpc/igd_desc_parse.c	2010-06-18 12:09:55 +0000
+++ miniupnpc/igd_desc_parse.c	2010-12-22 18:35:14 +0000
@@ -1,4 +1,4 @@
-/* $Id: igd_desc_parse.c,v 1.10 2010/04/05 20:36:59 nanard Exp $ */
+/* $Id: igd_desc_parse.c,v 1.11 2010/12/11 17:56:51 nanard Exp $ */
 /* Project : miniupnp
  * http://miniupnp.free.fr/
  * Author : Thomas Bernard
@@ -97,7 +97,7 @@
 	printf(" controlURL = '%s'\n", d->CIF.controlurl);
 	printf(" eventSubURL = '%s'\n", d->CIF.eventsuburl);
 	printf(" SCPDURL = '%s'\n", d->CIF.scpdurl);
-	printf("WAN Connection Device (IP or PPP Connection):\n");
+	printf("primary WAN Connection Device (IP or PPP Connection):\n");
 	/*printf(" deviceType = '%s'\n", d->first.devicetype);*/
 	printf(" servicetype = '%s'\n", d->first.servicetype);
 	printf(" controlURL = '%s'\n", d->first.controlurl);

=== modified file 'miniupnpc/minisoap.c'
--- miniupnpc/minisoap.c	2010-06-18 12:09:55 +0000
+++ miniupnpc/minisoap.c	2010-12-22 18:35:14 +0000
@@ -1,4 +1,4 @@
-/* $Id: minisoap.c,v 1.19 2010/04/12 20:39:41 nanard Exp $ */
+/* $Id: minisoap.c,v 1.20 2010/12/11 17:56:51 nanard Exp $ */
 /* Project : miniupnp
  * Author : Thomas Bernard
  * Copyright (c) 2005-2009 Thomas Bernard
@@ -106,8 +106,12 @@
 					   "\r\n",
 					   url, httpversion, host, portstr, bodysize, action);
 #ifdef DEBUG
-	printf("SOAP request : headersize=%d bodysize=%d\n",
+	/*printf("SOAP request : headersize=%d bodysize=%d\n",
 	       headerssize, bodysize);
+	*/
+	printf("SOAP request : POST %s HTTP/%s - Host: %s%s\n",
+	        url, httpversion, host, portstr);
+	printf("SOAPAction: \"%s\" - Content-Length: %d\n", action, bodysize);
 	/*printf("%s", headerbuf);*/
 #endif
 	return httpWrite(fd, body, bodysize, headerbuf, headerssize);

=== modified file 'miniupnpc/miniupnpc.c'
--- miniupnpc/miniupnpc.c	2010-12-12 21:16:33 +0000
+++ miniupnpc/miniupnpc.c	2010-12-22 18:35:14 +0000
@@ -1,4 +1,4 @@
-/* $Id: miniupnpc.c,v 1.83 2010/12/09 16:11:32 nanard Exp $ */
+/* $Id: miniupnpc.c,v 1.85 2010/12/21 16:13:14 nanard Exp $ */
 /* Project : miniupnp
  * Author : Thomas BERNARD
  * copyright (c) 2005-2010 Thomas Bernard
@@ -301,6 +301,9 @@
 	buf = getHTTPResponse(s, &n);
 	if(n > 0 && buf)
 	{
+#ifdef DEBUG
+		printf("SOAP Response :\n%.*s\n", n, buf);
+#endif
 		if(*bufsize > n)
 		{
 			memcpy(buffer, buf, n);
@@ -441,8 +444,12 @@
 	int n;
 	struct sockaddr sockudp_r;
 	unsigned int mx;
+#ifdef NO_GETADDRINFO
+	struct sockaddr_in sockudp_w;
+#else
 	int rv;
 	struct addrinfo hints, *servinfo, *p;
+#endif
 #ifdef WIN32
 	MIB_IPFORWARDROW ip_forward;
 #endif
@@ -487,13 +494,6 @@
 			p->sin_port = htons(PORT);
 		p->sin_addr.s_addr = INADDR_ANY;
 	}
-#if 0
-	/* emission */
-	memset(&sockudp_w, 0, sizeof(struct sockaddr_in));
-	sockudp_w.sin_family = AF_INET;
-	sockudp_w.sin_port = htons(PORT);
-	sockudp_w.sin_addr.s_addr = inet_addr(UPNP_MCAST_ADDR);
-#endif
 #ifdef WIN32
 /* This code could help us to use the right Network interface for 
  * SSDP multicast traffic */
@@ -596,7 +596,13 @@
 		n = snprintf(bufr, sizeof(bufr),
 		             MSearchMsgFmt, deviceList[deviceIndex++], mx);
 		/*printf("Sending %s", bufr);*/
-#if 0
+#ifdef NO_GETADDRINFO
+		/* the following code is not using getaddrinfo */
+		/* emission */
+		memset(&sockudp_w, 0, sizeof(struct sockaddr_in));
+		sockudp_w.sin_family = AF_INET;
+		sockudp_w.sin_port = htons(PORT);
+		sockudp_w.sin_addr.s_addr = inet_addr(UPNP_MCAST_ADDR);
 		n = sendto(sudp, bufr, n, 0,
 		           (struct sockaddr *)&sockudp_w, sizeof(struct sockaddr_in));
 		if (n < 0) {
@@ -604,7 +610,7 @@
 			closesocket(sudp);
 			return devlist;
 		}
-#endif
+#else /* #ifdef NO_GETADDRINFO */
 		memset(&hints, 0, sizeof(hints));
 		hints.ai_family = AF_UNSPEC; // AF_INET6 or AF_INET
 		hints.ai_socktype = SOCK_DGRAM;
@@ -629,6 +635,7 @@
 			closesocket(sudp);
 			return devlist;
 		}
+#endif /* #ifdef NO_GETADDRINFO */
 	}
 	/* Waiting for SSDP REPLY packet to M-SEARCH */
 	n = ReceiveData(sudp, bufr, sizeof(bufr), delay);

=== modified file 'miniupnpc/miniwget.c'
--- miniupnpc/miniwget.c	2010-12-12 21:16:33 +0000
+++ miniupnpc/miniwget.c	2010-12-22 18:35:14 +0000
@@ -1,4 +1,4 @@
-/* $Id: miniwget.c,v 1.38 2010/12/09 15:54:25 nanard Exp $ */
+/* $Id: miniwget.c,v 1.41 2010/12/12 23:52:02 nanard Exp $ */
 /* Project : miniupnp
  * Author : Thomas Bernard
  * Copyright (c) 2005-2010 Thomas Bernard
@@ -17,6 +17,7 @@
 #define MAXHOSTNAMELEN 64
 #define MIN(x,y) (((x)<(y))?(x):(y))
 #define snprintf _snprintf
+#define socklen_t int
 #ifdef strncasecmp
 #undef strncasecmp
 #endif
@@ -25,7 +26,6 @@
 #else /* defined(_MSC_VER) && (_MSC_VER >= 1400) */
 #define strncasecmp memicmp
 #endif /* defined(_MSC_VER) && (_MSC_VER >= 1400) */
-#define socklen_t int
 #else /* #ifdef WIN32 */
 #include <unistd.h>
 #include <sys/param.h>
@@ -63,6 +63,7 @@
 	int chunked = 0;
 	int content_length = -1;
 	unsigned int chunksize = 0;
+	unsigned int bytestocopy = 0;
 	/* buffers : */
 	char * header_buf;
 	int header_buf_len = 2048;
@@ -137,43 +138,44 @@
 					{
 						if(chunked)
 						{
-							while(i<header_buf_used && isxdigit(header_buf[i]))
-							{
-								if(header_buf[i] >= '0' && header_buf[i] <= '9')
-									chunksize = (chunksize << 4) + (header_buf[i] - '0');
-								else
-									chunksize = (chunksize << 4) + ((header_buf[i] | 32) - 'a' + 10);
-								i++;
-							}
-							/* discarding chunk-extension */
-							while(i < header_buf_used && header_buf[i] != '\r') i++;
-							if(i < header_buf_used && header_buf[i] == '\r') i++;
-							if(i < header_buf_used && header_buf[i] == '\n') i++;
-#ifdef DEBUG
-							printf("chunksize = %u (%x)\n", chunksize, chunksize);
-#endif
-							if(chunksize == 0)
-							{
-#ifdef DEBUG
-								printf("end of stream !\n");
-#endif
-								goto end_of_stream;	
-							}
-							if(header_buf_used - i <= chunksize)
-							{
-								if(content_buf_len < header_buf_used - i)
-								{
-									content_buf = realloc(content_buf, header_buf_used - i);
-									content_buf_len = header_buf_used - i;
-								}
-								memcpy(content_buf, header_buf + i, header_buf_used - i);
-								content_buf_used = header_buf_used - i;
-								chunksize -= (header_buf_used - i);
-								i = header_buf_used;
-							}
-							else
-							{
-								printf("arg ! chunksize < (header_buf_used - i)\n");
+							while(i<header_buf_used)
+							{
+								while(i<header_buf_used && isxdigit(header_buf[i]))
+								{
+									if(header_buf[i] >= '0' && header_buf[i] <= '9')
+										chunksize = (chunksize << 4) + (header_buf[i] - '0');
+									else
+										chunksize = (chunksize << 4) + ((header_buf[i] | 32) - 'a' + 10);
+									i++;
+								}
+								/* discarding chunk-extension */
+								while(i < header_buf_used && header_buf[i] != '\r') i++;
+								if(i < header_buf_used && header_buf[i] == '\r') i++;
+								if(i < header_buf_used && header_buf[i] == '\n') i++;
+#ifdef DEBUG
+								printf("chunksize = %u (%x)\n", chunksize, chunksize);
+#endif
+								if(chunksize == 0)
+								{
+#ifdef DEBUG
+									printf("end of HTTP content !\n");
+#endif
+									goto end_of_stream;	
+								}
+								bytestocopy = ((int)chunksize < header_buf_used - i)?chunksize:(header_buf_used - i);
+#ifdef DEBUG
+								printf("chunksize=%u bytestocopy=%u (i=%d header_buf_used=%d)\n",
+								       chunksize, bytestocopy, i, header_buf_used);
+#endif
+								if(content_buf_len < (int)(content_buf_used + bytestocopy))
+								{
+									content_buf = realloc(content_buf, content_buf_used + bytestocopy);
+									content_buf_len = content_buf_used + bytestocopy;
+								}
+								memcpy(content_buf + content_buf_used, header_buf + i, bytestocopy);
+								content_buf_used += bytestocopy;
+								chunksize -= bytestocopy;
+								i += bytestocopy;
 							}
 						}
 						else
@@ -185,6 +187,7 @@
 							}
 							memcpy(content_buf, header_buf + i, header_buf_used - i);
 							content_buf_used = header_buf_used - i;
+							i = header_buf_used;
 						}
 					}
 				}
@@ -196,7 +199,6 @@
 			if(chunked)
 			{
 				int i = 0;
-				unsigned bytestocopy;
 				while(i < n)
 				{
 					if(chunksize == 0)
@@ -221,14 +223,14 @@
 						if(chunksize == 0)
 						{
 #ifdef DEBUG
-							printf("end of stream - %d %d\n", i, n);
+							printf("end of HTTP content - %d %d\n", i, n);
 							/*printf("'%.*s'\n", n-i, buf+i);*/
 #endif
 							goto end_of_stream;
 						}
 					}
-					bytestocopy = (chunksize < n - i)?chunksize:(n - i);
-					if(content_buf_used + bytestocopy > content_buf_len)
+					bytestocopy = ((int)chunksize < n - i)?chunksize:(n - i);
+					if((int)(content_buf_used + bytestocopy) > content_buf_len)
 					{
 						content_buf = (char *)realloc((void *)content_buf, 
 						                              content_buf_used + bytestocopy);
@@ -255,7 +257,7 @@
 		if(content_length > 0 && content_buf_used >= content_length)
 		{
 #ifdef DEBUG
-			printf("termine!\n");
+			printf("End of HTTP content\n");
 #endif
 			break;
 		}

=== modified file 'win32/UPnP_MiniUPnPc.cpp'
--- win32/UPnP_MiniUPnPc.cpp	2010-09-09 18:16:26 +0000
+++ win32/UPnP_MiniUPnPc.cpp	2010-12-22 18:35:14 +0000
@@ -26,7 +26,6 @@
 #define STATICLIB
 #endif
 #include <miniupnpc/miniupnpc.h>
-#include <miniupnpc/miniwget.h>
 #include <miniupnpc/upnpcommands.h>
 
 static UPNPUrls urls;
@@ -38,31 +37,7 @@
 	if(!devices)
 		return false;
 
-	UPNPDev* device = 0;
-	if(devices) {
-		device = devices;
-		while(device) {
-			if(strstr(device->st, "InternetGatewayDevice"))
-				break;
-			device = device->pNext;
-		}
-	}
-	if(!device)
-		device = devices; /* defaulting to first device */
-
-	bool ret = false;
-
-	int descXMLsize = 0;
-	char* descXML = reinterpret_cast<char*>(miniwget(device->descURL, &descXMLsize));
-	if(descXML) {
-		memset(&urls, 0, sizeof(UPNPUrls));
-		memset(&data, 0, sizeof(IGDdatas));
-		parserootdesc(descXML, descXMLsize, &data);
-		delete descXML;
-
-		GetUPNPUrls(&urls, &data, device->descURL);
-		ret = true;
-	}
+	bool ret = UPNP_GetValidIGD(devices, &urls, &data, 0, 0);
 
 	freeUPNPDevlist(devices);