Browse Source

Update miniupnpc to latest version (included library)

Adam Ierymenko 7 years ago
parent
commit
531842dc6b
42 changed files with 146 additions and 2071 deletions
  1. 15 1
      ext/miniupnpc/Changelog.txt
  2. 1 1
      ext/miniupnpc/LICENSE
  3. 0 5
      ext/miniupnpc/MANIFEST.in
  4. 3 4
      ext/miniupnpc/README
  5. 0 172
      ext/miniupnpc/apiversions.txt
  6. 3 5
      ext/miniupnpc/connecthostport.c
  7. 0 4
      ext/miniupnpc/external-ip.sh
  8. 0 659
      ext/miniupnpc/minihttptestserver.c
  9. 2 2
      ext/miniupnpc/minisoap.c
  10. 30 12
      ext/miniupnpc/minissdpc.c
  11. 1 1
      ext/miniupnpc/miniupnpc.h
  12. 12 4
      ext/miniupnpc/miniupnpcmodule.c
  13. 10 9
      ext/miniupnpc/miniwget.c
  14. 6 4
      ext/miniupnpc/minixml.c
  15. 0 88
      ext/miniupnpc/pymoduletest.py
  16. 2 2
      ext/miniupnpc/receivedata.c
  17. 0 14
      ext/miniupnpc/testdesc/linksys_WAG200G_desc.values
  18. 0 110
      ext/miniupnpc/testdesc/linksys_WAG200G_desc.xml
  19. 0 20
      ext/miniupnpc/testdesc/new_LiveBox_desc.values
  20. 0 90
      ext/miniupnpc/testdesc/new_LiveBox_desc.xml
  21. 0 187
      ext/miniupnpc/testigddescparse.c
  22. 0 55
      ext/miniupnpc/testminiwget.c
  23. 0 96
      ext/miniupnpc/testminiwget.sh
  24. 0 89
      ext/miniupnpc/testminixml.c
  25. 0 151
      ext/miniupnpc/testportlistingparse.c
  26. 0 3
      ext/miniupnpc/testreplyparse/DeletePortMapping.namevalue
  27. 0 6
      ext/miniupnpc/testreplyparse/DeletePortMapping.xml
  28. 0 2
      ext/miniupnpc/testreplyparse/GetExternalIPAddress.namevalue
  29. 0 2
      ext/miniupnpc/testreplyparse/GetExternalIPAddress.xml
  30. 0 3
      ext/miniupnpc/testreplyparse/GetSpecificPortMappingEntryReq.namevalue
  31. 0 3
      ext/miniupnpc/testreplyparse/GetSpecificPortMappingEntryReq.xml
  32. 0 5
      ext/miniupnpc/testreplyparse/GetSpecificPortMappingEntryResp.namevalue
  33. 0 2
      ext/miniupnpc/testreplyparse/GetSpecificPortMappingEntryResp.xml
  34. 0 1
      ext/miniupnpc/testreplyparse/SetDefaultConnectionService.namevalue
  35. 0 1
      ext/miniupnpc/testreplyparse/SetDefaultConnectionService.xml
  36. 0 7
      ext/miniupnpc/testreplyparse/readme.txt
  37. 0 84
      ext/miniupnpc/testupnpigd.py
  38. 0 96
      ext/miniupnpc/testupnpreplyparse.c
  39. 0 14
      ext/miniupnpc/testupnpreplyparse.sh
  40. 7 5
      ext/miniupnpc/upnpc.c
  41. 47 44
      ext/miniupnpc/upnpcommands.c
  42. 7 8
      ext/miniupnpc/upnpreplyparse.c

+ 15 - 1
ext/miniupnpc/Changelog.txt

@@ -1,6 +1,20 @@
-$Id: Changelog.txt,v 1.223 2016/04/19 21:06:20 nanard Exp $
+$Id: Changelog.txt,v 1.229 2017/12/12 11:26:25 nanard Exp $
 miniUPnP client Changelog.
 miniUPnP client Changelog.
 
 
+2017/12/11:
+  Fix buffer over run in minixml.c
+  Fix uninitialized variable access in upnpreplyparse.c
+
+2017/05/05:
+  Fix CVE-2017-8798   Thanks to tin/Team OSTStrom
+
+2016/11/11:
+  check strlen before memcmp in XML parsing portlistingparse.c
+  fix build under SOLARIS and CYGWIN
+
+2016/10/11:
+  Add python 3 compatibility to IGD test
+
 VERSION 2.0 : released 2016/04/19
 VERSION 2.0 : released 2016/04/19
 
 
 2016/01/24:
 2016/01/24:

+ 1 - 1
ext/miniupnpc/LICENSE

@@ -1,5 +1,5 @@
 MiniUPnPc
 MiniUPnPc
-Copyright (c) 2005-2015, Thomas BERNARD
+Copyright (c) 2005-2016, Thomas BERNARD
 All rights reserved.
 All rights reserved.
 
 
 Redistribution and use in source and binary forms, with or without
 Redistribution and use in source and binary forms, with or without

+ 0 - 5
ext/miniupnpc/MANIFEST.in

@@ -1,5 +0,0 @@
-include README
-include miniupnpcmodule.c
-include setup.py
-include *.h
-include libminiupnpc.a

+ 3 - 4
ext/miniupnpc/README

@@ -1,9 +1,8 @@
 Project: miniupnp
 Project: miniupnp
-Project web page: http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
+Project web page: http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/
 github: https://github.com/miniupnp/miniupnp
 github: https://github.com/miniupnp/miniupnp
-freecode: http://freecode.com/projects/miniupnp
 Author: Thomas Bernard
 Author: Thomas Bernard
-Copyright (c) 2005-2016 Thomas Bernard
+Copyright (c) 2005-2017 Thomas Bernard
 This software is subject to the conditions detailed in the
 This software is subject to the conditions detailed in the
 LICENSE file provided within this distribution.
 LICENSE file provided within this distribution.
 
 
@@ -58,7 +57,7 @@ If you are using libminiupnpc in your application, please
 send me an email !
 send me an email !
 
 
 For any question, you can use the web forum :
 For any question, you can use the web forum :
-http://miniupnp.tuxfamily.org/forum/
+https://miniupnp.tuxfamily.org/forum/
 
 
 Bugs should be reported on github :
 Bugs should be reported on github :
 https://github.com/miniupnp/miniupnp/issues
 https://github.com/miniupnp/miniupnp/issues

+ 0 - 172
ext/miniupnpc/apiversions.txt

@@ -1,172 +0,0 @@
-$Id: apiversions.txt,v 1.9 2016/01/24 17:24:36 nanard Exp $
-
-Differences in API between miniUPnPc versions
-
-API version 16
-  added "status_code" argument to getHTTPResponse(), miniwget() and miniwget_getaddr()
-  updated macro :
-    #define MINIUPNPC_API_VERSION 16
-
-API version 15
-  changed "sameport" argument of upnpDiscover() upnpDiscoverAll() upnpDiscoverDevice()
-    to "localport". When 0 or 1, behaviour is not changed, but it can take
-    any other value between 2 and 65535
-    Existing programs should be compatible
-  updated macro :
-    #define MINIUPNPC_API_VERSION  15
-
-API version 14
-miniupnpc.h
-  add ttl argument to upnpDiscover() upnpDiscoverAll() upnpDiscoverDevice()
-  upnpDiscoverDevices()
-  getDevicesFromMiniSSDPD() :
-    connectToMiniSSDPD() / disconnectFromMiniSSDPD()
-    requestDevicesFromMiniSSDPD() / receiveDevicesFromMiniSSDPD()
-  updated macro :
-    #define MINIUPNPC_API_VERSION  14
-
-API version 13
-miniupnpc.h:
-  add searchalltype param to upnpDiscoverDevices() function
-  updated macro :
-    #define MINIUPNPC_API_VERSION  13
-
-API version 12
-miniupnpc.h :
-  add upnpDiscoverAll() / upnpDiscoverDevice() / upnpDiscoverDevices()
-    functions
-  updated macros :
-    #define MINIUPNPC_API_VERSION  12
-
-API version 11
-
-upnpreplyparse.h / portlistingparse.h :
-  removed usage of sys/queue.h / bsdqueue.h
-
-miniupnpc.h:
-  updated macros :
-    #define MINIUPNPC_API_VERSION  11
-
-====================== miniUPnPc version 1.9 ======================
-API version 10
-
-upnpcommands.h:
-  added argument remoteHost to UPNP_GetSpecificPortMappingEntry()
-
-miniupnpc.h:
-  updated macros :
-    #define MINIUPNPC_VERSION      "1.9"
-    #define MINIUPNPC_API_VERSION  10
-
-====================== miniUPnPc version 1.8 ======================
-API version 9
-
-miniupnpc.h:
-  updated macros :
-    #define MINIUPNPC_VERSION      "1.8"
-    #define MINIUPNPC_API_VERSION  9
-  added "unsigned int scope_id;" to struct UPNPDev
-  added scope_id argument to GetUPNPUrls()
-
-
-
-====================== miniUPnPc version 1.7 ======================
-API version 8
-
-miniupnpc.h :
-  add new macros :
-    #define MINIUPNPC_VERSION      "1.7"
-    #define MINIUPNPC_API_VERSION  8
-  add rootdescURL to struct UPNPUrls
-
-
-
-====================== miniUPnPc version 1.6 ======================
-API version 8
-
-Adding support for IPv6.
-igd_desc_parse.h :
-  struct IGDdatas_service :
-    add char presentationurl[MINIUPNPC_URL_MAXSIZE];
-  struct IGDdatas :
-    add struct IGDdatas_service IPv6FC;
-miniupnpc.h :
-  new macros :
-    #define UPNPDISCOVER_SUCCESS (0)
-    #define UPNPDISCOVER_UNKNOWN_ERROR (-1)
-    #define UPNPDISCOVER_SOCKET_ERROR (-101)
-    #define UPNPDISCOVER_MEMORY_ERROR (-102)
-  simpleUPnPcommand() prototype changed (but is normaly not used by API users)
-  add arguments ipv6 and error to upnpDiscover() :
-     struct UPNPDev *
-     upnpDiscover(int delay, const char * multicastif,
-                  const char * minissdpdsock, int sameport,
-                  int ipv6,
-                  int * error);
-  add controlURL_6FC member to struct UPNPUrls :
-    struct UPNPUrls {
-       char * controlURL;
-       char * ipcondescURL;
-       char * controlURL_CIF;
-       char * controlURL_6FC;
-    };
-
-upnpcommands.h :
-  add leaseDuration argument to UPNP_AddPortMapping()
-  add desc, enabled and leaseDuration arguments to UPNP_GetSpecificPortMappingEntry()
-  add UPNP_GetListOfPortMappings() function (IGDv2)
-  add IGDv2 IPv6 related functions :
-    UPNP_GetFirewallStatus()
-    UPNP_GetOutboundPinholeTimeout()
-    UPNP_AddPinhole()
-    UPNP_UpdatePinhole()
-    UPNP_DeletePinhole()
-    UPNP_CheckPinholeWorking()
-    UPNP_GetPinholePackets()
-
-
-
-====================== miniUPnPc version 1.5 ======================
-API version 5
-
-new function :
-int UPNPIGD_IsConnected(struct UPNPUrls *, struct IGDdatas *);
-new macro in upnpcommands.h :
-#define UPNPCOMMAND_HTTP_ERROR
-
-====================== miniUPnPc version 1.4 ======================
-Same API as version 1.3
-
-====================== miniUPnPc version 1.3 ======================
-API version 4
-
-Use UNSIGNED_INTEGER type for
-UPNP_GetTotalBytesSent(), UPNP_GetTotalBytesReceived(),
-UPNP_GetTotalPacketsSent(), UPNP_GetTotalPacketsReceived()
-Add remoteHost argument to UPNP_AddPortMapping() and UPNP_DeletePortMapping()
-
-====================== miniUPnPc version 1.2 ======================
-API version 3
-
-added sameport argument to upnpDiscover()
-struct UPNPDev *
-upnpDiscover(int delay, const char * multicastif,
-             const char * minissdpdsock, int sameport);
-
-====================== miniUPnPc Version 1.1 ======================
-Same API as 1.0
-
-
-====================== miniUPnPc Version 1.0 ======================
-API version 2
-
-
-struct UPNPDev {
-      struct UPNPDev * pNext;
-      char * descURL;
-      char * st;
-      char buffer[2];
-};
-struct UPNPDev * upnpDiscover(int delay, const char * multicastif,
-                              const char * minissdpdsock);
-

+ 3 - 5
ext/miniupnpc/connecthostport.c

@@ -1,7 +1,7 @@
-/* $Id: connecthostport.c,v 1.16 2016/12/16 08:57:53 nanard Exp $ */
+/* $Id: connecthostport.c,v 1.17 2017/04/21 09:58:30 nanard Exp $ */
 /* Project : miniupnp
 /* Project : miniupnp
  * Author : Thomas Bernard
  * Author : Thomas Bernard
- * Copyright (c) 2010-2016 Thomas Bernard
+ * Copyright (c) 2010-2017 Thomas Bernard
  * This software is subject to the conditions detailed in the
  * This software is subject to the conditions detailed in the
  * LICENCE file provided in this distribution. */
  * LICENCE file provided in this distribution. */
 
 
@@ -36,15 +36,13 @@
 /* defining MINIUPNPC_IGNORE_EINTR enable the ignore of interruptions
 /* defining MINIUPNPC_IGNORE_EINTR enable the ignore of interruptions
  * during the connect() call */
  * during the connect() call */
 #define MINIUPNPC_IGNORE_EINTR
 #define MINIUPNPC_IGNORE_EINTR
-#ifndef USE_GETHOSTBYNAME
 #include <sys/socket.h>
 #include <sys/socket.h>
 #include <sys/select.h>
 #include <sys/select.h>
-#endif /* #ifndef USE_GETHOSTBYNAME */
 #endif /* #else _WIN32 */
 #endif /* #else _WIN32 */
 
 
 /* definition of PRINT_SOCKET_ERROR */
 /* definition of PRINT_SOCKET_ERROR */
 #ifdef _WIN32
 #ifdef _WIN32
-#define PRINT_SOCKET_ERROR(x)    printf("Socket error: %s, %d\n", x, WSAGetLastError());
+#define PRINT_SOCKET_ERROR(x)    fprintf(stderr, "Socket error: %s, %d\n", x, WSAGetLastError());
 #else
 #else
 #define PRINT_SOCKET_ERROR(x) perror(x)
 #define PRINT_SOCKET_ERROR(x) perror(x)
 #endif
 #endif

+ 0 - 4
ext/miniupnpc/external-ip.sh

@@ -1,4 +0,0 @@
-#!/bin/sh
-# $Id: external-ip.sh,v 1.1 2010/08/05 12:57:41 nanard Exp $
-# (c) 2010 Reuben Hawkins
-upnpc -s | grep ExternalIPAddress | sed 's/[^0-9\.]//g'

+ 0 - 659
ext/miniupnpc/minihttptestserver.c

@@ -1,659 +0,0 @@
-/* $Id: minihttptestserver.c,v 1.20 2016/12/16 08:54:55 nanard Exp $ */
-/* Project : miniUPnP
- * Author : Thomas Bernard
- * Copyright (c) 2011-2016 Thomas Bernard
- * This software is subject to the conditions detailed in the
- * LICENCE file provided in this distribution.
- * */
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/wait.h>
-#include <arpa/inet.h>
-#include <netinet/in.h>
-#include <signal.h>
-#include <time.h>
-#include <errno.h>
-
-#ifndef INADDR_LOOPBACK
-#define INADDR_LOOPBACK         0x7f000001
-#endif
-
-#define CRAP_LENGTH (2048)
-
-volatile sig_atomic_t quit = 0;
-volatile sig_atomic_t child_to_wait_for = 0;
-
-/**
- * signal handler for SIGCHLD (child status has changed)
- */
-void handle_signal_chld(int sig)
-{
-	(void)sig;
-	/* printf("handle_signal_chld(%d)\n", sig); */
-	++child_to_wait_for;
-}
-
-/**
- * signal handler for SIGINT (CRTL C)
- */
-void handle_signal_int(int sig)
-{
-	(void)sig;
-	/* printf("handle_signal_int(%d)\n", sig); */
-	quit = 1;
-}
-
-/**
- * build a text/plain content of the specified length
- */
-void build_content(char * p, int n)
-{
-	char line_buffer[80];
-	int k;
-	int i = 0;
-
-	while(n > 0) {
-		k = snprintf(line_buffer, sizeof(line_buffer),
-		             "%04d_ABCDEFGHIJKL_This_line_is_64_bytes_long_ABCDEFGHIJKL_%04d\r\n",
-		             i, i);
-		if(k != 64) {
-			fprintf(stderr, "snprintf() returned %d in build_content()\n", k);
-		}
-		++i;
-		if(n >= 64) {
-			memcpy(p, line_buffer, 64);
-			p += 64;
-			n -= 64;
-		} else {
-			memcpy(p, line_buffer, n);
-			p += n;
-			n = 0;
-		}
-	}
-}
-
-/**
- * build crappy content
- */
-void build_crap(char * p, int n)
-{
-	static const char crap[] = "_CRAP_\r\n";
-	int i;
-
-	while(n > 0) {
-		i = sizeof(crap) - 1;
-		if(i > n)
-			i = n;
-		memcpy(p, crap, i);
-		p += i;
-		n -= i;
-	}
-}
-
-/**
- * build chunked response.
- * return a malloc'ed buffer
- */
-char * build_chunked_response(int content_length, int * response_len)
-{
-	char * response_buffer;
-	char * content_buffer;
-	int buffer_length;
-	int i, n;
-
-	/* allocate to have some margin */
-	buffer_length = 256 + content_length + (content_length >> 4);
-	response_buffer = malloc(buffer_length);
-	if(response_buffer == NULL)
-		return NULL;
-	*response_len = snprintf(response_buffer, buffer_length,
-	                         "HTTP/1.1 200 OK\r\n"
-	                         "Content-Type: text/plain\r\n"
-	                         "Transfer-Encoding: chunked\r\n"
-	                         "\r\n");
-
-	/* build the content */
-	content_buffer = malloc(content_length);
-	if(content_buffer == NULL) {
-		free(response_buffer);
-		return NULL;
-	}
-	build_content(content_buffer, content_length);
-
-	/* chunk it */
-	i = 0;
-	while(i < content_length) {
-		n = (rand() % 199) + 1;
-		if(i + n > content_length) {
-			n = content_length - i;
-		}
-		/* TODO : check buffer size ! */
-		*response_len += snprintf(response_buffer + *response_len,
-		                          buffer_length - *response_len,
-		                          "%x\r\n", n);
-		memcpy(response_buffer + *response_len, content_buffer + i, n);
-		*response_len += n;
-		i += n;
-		response_buffer[(*response_len)++] = '\r';
-		response_buffer[(*response_len)++] = '\n';
-	}
-	/* the last chunk : "0\r\n" a empty body and then
-	 * the final "\r\n" */
-	memcpy(response_buffer + *response_len, "0\r\n\r\n", 5);
-	*response_len += 5;
-	free(content_buffer);
-
-	printf("resp_length=%d buffer_length=%d content_length=%d\n",
-	       *response_len, buffer_length, content_length);
-	return response_buffer;
-}
-
-/* favicon.ico generator */
-#ifdef OLD_HEADER
-#define FAVICON_LENGTH (6 + 16 + 12 + 8 + 32 * 4)
-#else
-#define FAVICON_LENGTH (6 + 16 + 40 + 8 + 32 * 4)
-#endif
-void build_favicon_content(char * p, int n)
-{
-	int i;
-	if(n < FAVICON_LENGTH)
-		return;
-	/* header : 6 bytes */
-	*p++ = 0;
-	*p++ = 0;
-	*p++ = 1;	/* type : ICO */
-	*p++ = 0;
-	*p++ = 1;	/* number of images in file */
-	*p++ = 0;
-	/* image directory (1 entry) : 16 bytes */
-	*p++ = 16;	/* width */
-	*p++ = 16;	/* height */
-	*p++ = 2;	/* number of colors in the palette. 0 = no palette */
-	*p++ = 0;	/* reserved */
-	*p++ = 1;	/* color planes */
-	*p++ = 0;	/* " */
-	*p++ = 1;	/* bpp */
-	*p++ = 0;	/* " */
-#ifdef OLD_HEADER
-	*p++ = 12 + 8 + 32 * 4;	/* bmp size */
-#else
-	*p++ = 40 + 8 + 32 * 4;	/* bmp size */
-#endif
-	*p++ = 0;	/* " */
-	*p++ = 0;	/* " */
-	*p++ = 0;	/* " */
-	*p++ = 6 + 16;	/* bmp offset */
-	*p++ = 0;	/* " */
-	*p++ = 0;	/* " */
-	*p++ = 0;	/* " */
-	/* BMP */
-#ifdef OLD_HEADER
-	/* BITMAPCOREHEADER */
-	*p++ = 12;	/* size of this header */
-	*p++ = 0;	/* " */
-	*p++ = 0;	/* " */
-	*p++ = 0;	/* " */
-	*p++ = 16;	/* width */
-	*p++ = 0;	/* " */
-	*p++ = 16 * 2;	/* height x 2 ! */
-	*p++ = 0;	/* " */
-	*p++ = 1;	/* color planes */
-	*p++ = 0;	/* " */
-	*p++ = 1;	/* bpp */
-	*p++ = 0;	/* " */
-#else
-	/* BITMAPINFOHEADER */
-	*p++ = 40;	/* size of this header */
-	*p++ = 0;	/* " */
-	*p++ = 0;	/* " */
-	*p++ = 0;	/* " */
-	*p++ = 16;	/* width */
-	*p++ = 0;	/* " */
-	*p++ = 0;	/* " */
-	*p++ = 0;	/* " */
-	*p++ = 16 * 2;	/* height x 2 ! */
-	*p++ = 0;	/* " */
-	*p++ = 0;	/* " */
-	*p++ = 0;	/* " */
-	*p++ = 1;	/* color planes */
-	*p++ = 0;	/* " */
-	*p++ = 1;	/* bpp */
-	*p++ = 0;	/* " */
-	/* compression method, image size, ppm x, ppm y */
-	/* colors in the palette ? */
-	/* important colors */
-	for(i = 4 * 6; i > 0; --i)
-		*p++ = 0;
-#endif
-	/* palette */
-	*p++ = 0;	/* b */
-	*p++ = 0;	/* g */
-	*p++ = 0;	/* r */
-	*p++ = 0;	/* reserved */
-	*p++ = 255;	/* b */
-	*p++ = 255;	/* g */
-	*p++ = 255;	/* r */
-	*p++ = 0;	/* reserved */
-	/* pixel data */
-	for(i = 16; i > 0; --i) {
-		if(i & 1) {
-			*p++ = 0125;
-			*p++ = 0125;
-		} else {
-			*p++ = 0252;
-			*p++ = 0252;
-		}
-		*p++ = 0;
-		*p++ = 0;
-	}
-	/* Opacity MASK */
-	for(i = 16 * 4; i > 0; --i) {
-		*p++ = 0;
-	}
-}
-
-enum modes {
-	MODE_INVALID, MODE_CHUNKED, MODE_ADDCRAP, MODE_NORMAL, MODE_FAVICON
-};
-
-const struct {
-	const enum modes mode;
-	const char * text;
-} modes_array[] = {
-	{MODE_CHUNKED, "chunked"},
-	{MODE_ADDCRAP, "addcrap"},
-	{MODE_NORMAL, "normal"},
-	{MODE_FAVICON, "favicon.ico"},
-	{MODE_INVALID, NULL}
-};
-
-/**
- * write the response with random behaviour !
- */
-void send_response(int c, const char * buffer, int len)
-{
-	int n;
-	while(len > 0) {
-		n = (rand() % 99) + 1;
-		if(n > len)
-			n = len;
-		n = write(c, buffer, n);
-		if(n < 0) {
-			if(errno != EINTR) {
-				perror("write");
-				return;
-			}
-			/* if errno == EINTR, try again */
-		} else {
-			len -= n;
-			buffer += n;
-		}
-		usleep(10000); /* 10ms */
-	}
-}
-
-/**
- * handle the HTTP connection
- */
-void handle_http_connection(int c)
-{
-	char request_buffer[2048];
-	int request_len = 0;
-	int headers_found = 0;
-	int n, i;
-	char request_method[16];
-	char request_uri[256];
-	char http_version[16];
-	char * p;
-	char * response_buffer;
-	int response_len;
-	enum modes mode;
-	int content_length = 16*1024;
-
-	/* read the request */
-	while(request_len < (int)sizeof(request_buffer) && !headers_found) {
-		n = read(c,
-		         request_buffer + request_len,
-		         sizeof(request_buffer) - request_len);
-		if(n < 0) {
-			if(errno == EINTR)
-				continue;
-			perror("read");
-			return;
-		} else if(n==0) {
-			/* remote host closed the connection */
-			break;
-		} else {
-			request_len += n;
-			for(i = 0; i < request_len - 3; i++) {
-				if(0 == memcmp(request_buffer + i, "\r\n\r\n", 4)) {
-					/* found the end of headers */
-					headers_found = 1;
-					break;
-				}
-			}
-		}
-	}
-	if(!headers_found) {
-		/* error */
-		printf("no HTTP header found in the request\n");
-		return;
-	}
-	printf("headers :\n%.*s", request_len, request_buffer);
-	/* the request have been received, now parse the request line */
-	p = request_buffer;
-	for(i = 0; i < (int)sizeof(request_method) - 1; i++) {
-		if(*p == ' ' || *p == '\r')
-			break;
-		request_method[i] = *p;
-		++p;
-	}
-	request_method[i] = '\0';
-	while(*p == ' ')
-		p++;
-	for(i = 0; i < (int)sizeof(request_uri) - 1; i++) {
-		if(*p == ' ' || *p == '\r')
-			break;
-		request_uri[i] = *p;
-		++p;
-	}
-	request_uri[i] = '\0';
-	while(*p == ' ')
-		p++;
-	for(i = 0; i < (int)sizeof(http_version) - 1; i++) {
-		if(*p == ' ' || *p == '\r')
-			break;
-		http_version[i] = *p;
-		++p;
-	}
-	http_version[i] = '\0';
-	printf("Method = %s, URI = %s, %s\n",
-	       request_method, request_uri, http_version);
-	/* check if the request method is allowed */
-	if(0 != strcmp(request_method, "GET")) {
-		const char response405[] = "HTTP/1.1 405 Method Not Allowed\r\n"
-		                           "Allow: GET\r\n\r\n";
-		const char * pc;
-		/* 405 Method Not Allowed */
-		/* The response MUST include an Allow header containing a list
-		 * of valid methods for the requested resource. */
-		n = sizeof(response405) - 1;
-		pc = response405;
-		while(n > 0) {
-			i = write(c, pc, n);
-			if(i<0) {
-				if(errno != EINTR) {
-					perror("write");
-					return;
-				}
-			} else {
-				n -= i;
-				pc += i;
-			}
-		}
-		return;
-	}
-
-	mode = MODE_INVALID;
-	/* use the request URI to know what to do */
-	for(i = 0; modes_array[i].mode != MODE_INVALID; i++) {
-		if(strstr(request_uri, modes_array[i].text)) {
-			mode = modes_array[i].mode; /* found */
-			break;
-		}
-	}
-
-	switch(mode) {
-	case MODE_CHUNKED:
-		response_buffer = build_chunked_response(content_length, &response_len);
-		break;
-	case MODE_ADDCRAP:
-		response_len = content_length+256;
-		response_buffer = malloc(response_len);
-		if(!response_buffer)
-			break;
-		n = snprintf(response_buffer, response_len,
-		             "HTTP/1.1 200 OK\r\n"
-		             "Server: minihttptestserver\r\n"
-		             "Content-Type: text/plain\r\n"
-		             "Content-Length: %d\r\n"
-		             "\r\n", content_length);
-		response_len = content_length+n+CRAP_LENGTH;
-		p = realloc(response_buffer, response_len);
-		if(p == NULL) {
-			/* error 500 */
-			free(response_buffer);
-			response_buffer = NULL;
-			break;
-		}
-		response_buffer = p;
-		build_content(response_buffer + n, content_length);
-		build_crap(response_buffer + n + content_length, CRAP_LENGTH);
-		break;
-	case MODE_FAVICON:
-		content_length = FAVICON_LENGTH;
-		response_len = content_length + 256;
-		response_buffer = malloc(response_len);
-		if(!response_buffer)
-			break;
-		n = snprintf(response_buffer, response_len,
-		             "HTTP/1.1 200 OK\r\n"
-		             "Server: minihttptestserver\r\n"
-		             "Content-Type: image/vnd.microsoft.icon\r\n"
-		             "Content-Length: %d\r\n"
-		             "\r\n", content_length);
-		/* image/x-icon */
-		build_favicon_content(response_buffer + n, content_length);
-		response_len = content_length + n;
-		break;
-	default:
-		response_len = content_length+256;
-		response_buffer = malloc(response_len);
-		if(!response_buffer)
-			break;
-		n = snprintf(response_buffer, response_len,
-		             "HTTP/1.1 200 OK\r\n"
-		             "Server: minihttptestserver\r\n"
-		             "Content-Type: text/plain\r\n"
-		             "\r\n");
-		response_len = content_length+n;
-		p = realloc(response_buffer, response_len);
-		if(p == NULL) {
-			/* Error 500 */
-			free(response_buffer);
-			response_buffer = NULL;
-			break;
-		}
-		response_buffer = p;
-		build_content(response_buffer + n, response_len - n);
-	}
-
-	if(response_buffer) {
-		send_response(c, response_buffer, response_len);
-		free(response_buffer);
-	} else {
-		/* Error 500 */
-	}
-}
-
-/**
- */
-int main(int argc, char * * argv) {
-	int ipv6 = 0;
-	int s, c, i;
-	unsigned short port = 0;
-	struct sockaddr_storage server_addr;
-	socklen_t server_addrlen;
-	struct sockaddr_storage client_addr;
-	socklen_t client_addrlen;
-	pid_t pid;
-	int child = 0;
-	int status;
-	const char * expected_file_name = NULL;
-	struct sigaction sa;
-
-	for(i = 1; i < argc; i++) {
-		if(argv[i][0] == '-') {
-			switch(argv[i][1]) {
-			case '6':
-				ipv6 = 1;
-				break;
-			case 'e':
-				/* write expected file ! */
-				expected_file_name = argv[++i];
-				break;
-			case 'p':
-				/* port */
-				if(++i < argc) {
-					port = (unsigned short)atoi(argv[i]);
-				}
-				break;
-			default:
-				fprintf(stderr, "unknown command line switch '%s'\n", argv[i]);
-			}
-		} else {
-			fprintf(stderr, "unkown command line argument '%s'\n", argv[i]);
-		}
-	}
-
-	srand(time(NULL));
-
-	memset(&sa, 0, sizeof(struct sigaction));
-
-	/*signal(SIGCHLD, handle_signal_chld);*/
-	sa.sa_handler = handle_signal_chld;
-	if(sigaction(SIGCHLD, &sa, NULL) < 0) {
-		perror("sigaction");
-		return 1;
-	}
-	/*signal(SIGINT, handle_signal_int);*/
-	sa.sa_handler = handle_signal_int;
-	if(sigaction(SIGINT, &sa, NULL) < 0) {
-		perror("sigaction");
-		return 1;
-	}
-
-	s = socket(ipv6 ? AF_INET6 : AF_INET, SOCK_STREAM, 0);
-	if(s < 0) {
-		perror("socket");
-		return 1;
-	}
-	memset(&server_addr, 0, sizeof(struct sockaddr_storage));
-	memset(&client_addr, 0, sizeof(struct sockaddr_storage));
-	if(ipv6) {
-		struct sockaddr_in6 * addr = (struct sockaddr_in6 *)&server_addr;
-		addr->sin6_family = AF_INET6;
-		addr->sin6_port = htons(port);
-		addr->sin6_addr = in6addr_loopback;
-	} else {
-		struct sockaddr_in * addr = (struct sockaddr_in *)&server_addr;
-		addr->sin_family = AF_INET;
-		addr->sin_port = htons(port);
-		addr->sin_addr.s_addr = htonl(INADDR_LOOPBACK);
-	}
-	if(bind(s, (struct sockaddr *)&server_addr,
-	        ipv6 ? sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in)) < 0) {
-		perror("bind");
-		return 1;
-	}
-	if(listen(s, 5) < 0) {
-		perror("listen");
-	}
-	if(port == 0) {
-		server_addrlen = sizeof(struct sockaddr_storage);
-		if(getsockname(s, (struct sockaddr *)&server_addr, &server_addrlen) < 0) {
-			perror("getsockname");
-			return 1;
-		}
-		if(ipv6) {
-			struct sockaddr_in6 * addr = (struct sockaddr_in6 *)&server_addr;
-			port = ntohs(addr->sin6_port);
-		} else {
-			struct sockaddr_in * addr = (struct sockaddr_in *)&server_addr;
-			port = ntohs(addr->sin_port);
-		}
-		printf("Listening on port %hu\n", port);
-		fflush(stdout);
-	}
-
-	/* write expected file */
-	if(expected_file_name) {
-		FILE * f;
-		f = fopen(expected_file_name, "wb");
-		if(f) {
-			char * buffer;
-			buffer = malloc(16*1024);
-			if(buffer == NULL) {
-				fprintf(stderr, "memory allocation error\n");
-			} else {
-				build_content(buffer, 16*1024);
-				i = fwrite(buffer, 1, 16*1024, f);
-				if(i != 16*1024) {
-					fprintf(stderr, "error writing to file %s : %dbytes written (out of %d)\n", expected_file_name, i, 16*1024);
-				}
-				free(buffer);
-			}
-			fclose(f);
-		} else {
-			fprintf(stderr, "error opening file %s for writing\n", expected_file_name);
-		}
-	}
-
-	/* fork() loop */
-	while(!child && !quit) {
-		while(child_to_wait_for > 0) {
-			pid = wait(&status);
-			if(pid < 0) {
-				perror("wait");
-			} else {
-				printf("child(%d) terminated with status %d\n", (int)pid, status);
-			}
-			--child_to_wait_for;
-		}
-		client_addrlen = sizeof(struct sockaddr_storage);
-		c = accept(s, (struct sockaddr *)&client_addr,
-		           &client_addrlen);
-		if(c < 0) {
-			if(errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR)
-				continue;
-			perror("accept");
-			return 1;
-		}
-		printf("accept...\n");
-		pid = fork();
-		if(pid < 0) {
-			perror("fork");
-			return 1;
-		} else if(pid == 0) {
-			/* child */
-			child = 1;
-			close(s);
-			s = -1;
-			handle_http_connection(c);
-		}
-		close(c);
-	}
-	if(s >= 0) {
-		close(s);
-		s = -1;
-	}
-	if(!child) {
-		while(child_to_wait_for > 0) {
-			pid = wait(&status);
-			if(pid < 0) {
-				perror("wait");
-			} else {
-				printf("child(%d) terminated with status %d\n", (int)pid, status);
-			}
-			--child_to_wait_for;
-		}
-		printf("Bye...\n");
-	}
-	return 0;
-}
-

+ 2 - 2
ext/miniupnpc/minisoap.c

@@ -1,4 +1,4 @@
-/* $Id: minisoap.c,v 1.24 2015/10/26 17:05:07 nanard Exp $ */
+/* $Id: minisoap.c,v 1.25 2017/04/21 10:03:24 nanard Exp $ */
 /* Project : miniupnp
 /* Project : miniupnp
  * Author : Thomas Bernard
  * Author : Thomas Bernard
  * Copyright (c) 2005-2015 Thomas Bernard
  * Copyright (c) 2005-2015 Thomas Bernard
@@ -36,7 +36,7 @@
 #include <stdlib.h>
 #include <stdlib.h>
 
 
 #ifdef _WIN32
 #ifdef _WIN32
-#define PRINT_SOCKET_ERROR(x)    printf("Socket error: %s, %d\n", x, WSAGetLastError());
+#define PRINT_SOCKET_ERROR(x)    fprintf(stderr, "Socket error: %s, %d\n", x, WSAGetLastError());
 #else
 #else
 #define PRINT_SOCKET_ERROR(x) perror(x)
 #define PRINT_SOCKET_ERROR(x) perror(x)
 #endif
 #endif

+ 30 - 12
ext/miniupnpc/minissdpc.c

@@ -1,9 +1,9 @@
-/* $Id: minissdpc.c,v 1.33 2016/12/16 08:57:20 nanard Exp $ */
+/* $Id: minissdpc.c,v 1.35 2017/11/02 15:34:36 nanard Exp $ */
 /* vim: tabstop=4 shiftwidth=4 noexpandtab
 /* vim: tabstop=4 shiftwidth=4 noexpandtab
  * Project : miniupnp
  * Project : miniupnp
  * Web : http://miniupnp.free.fr/
  * Web : http://miniupnp.free.fr/
  * Author : Thomas BERNARD
  * Author : Thomas BERNARD
- * copyright (c) 2005-2016 Thomas Bernard
+ * copyright (c) 2005-2017 Thomas Bernard
  * This software is subjet to the conditions detailed in the
  * This software is subjet to the conditions detailed in the
  * provided LICENCE file. */
  * provided LICENCE file. */
 /*#include <syslog.h>*/
 /*#include <syslog.h>*/
@@ -62,7 +62,7 @@ struct sockaddr_un {
 #endif
 #endif
 
 
 #ifdef _WIN32
 #ifdef _WIN32
-#define PRINT_SOCKET_ERROR(x)    printf("Socket error: %s, %d\n", x, WSAGetLastError());
+#define PRINT_SOCKET_ERROR(x)    fprintf(stderr, "Socket error: %s, %d\n", x, WSAGetLastError());
 #else
 #else
 #define PRINT_SOCKET_ERROR(x) perror(x)
 #define PRINT_SOCKET_ERROR(x) perror(x)
 #endif
 #endif
@@ -201,6 +201,7 @@ connectToMiniSSDPD(const char * socketpath)
 #endif /* #ifdef MINIUPNPC_SET_SOCKET_TIMEOUT */
 #endif /* #ifdef MINIUPNPC_SET_SOCKET_TIMEOUT */
 	if(!socketpath)
 	if(!socketpath)
 		socketpath = "/var/run/minissdpd.sock";
 		socketpath = "/var/run/minissdpd.sock";
+	memset(&addr, 0, sizeof(addr));
 	addr.sun_family = AF_UNIX;
 	addr.sun_family = AF_UNIX;
 	strncpy(addr.sun_path, socketpath, sizeof(addr.sun_path));
 	strncpy(addr.sun_path, socketpath, sizeof(addr.sun_path));
 	/* TODO : check if we need to handle the EINTR */
 	/* TODO : check if we need to handle the EINTR */
@@ -502,6 +503,7 @@ ssdpDiscoverDevices(const char * const deviceTypes[],
 	unsigned long _ttl = (unsigned long)ttl;
 	unsigned long _ttl = (unsigned long)ttl;
 #endif
 #endif
 	int linklocal = 1;
 	int linklocal = 1;
+	int sentok;
 
 
 	if(error)
 	if(error)
 		*error = MINISSDPC_UNKNOWN_ERROR;
 		*error = MINISSDPC_UNKNOWN_ERROR;
@@ -612,14 +614,27 @@ ssdpDiscoverDevices(const char * const deviceTypes[],
 		return NULL;
 		return NULL;
 	}
 	}
 
 
+	if(ipv6) {
 #ifdef _WIN32
 #ifdef _WIN32
-	if(setsockopt(sudp, IPPROTO_IP, IP_MULTICAST_TTL, (const char *)&_ttl, sizeof(_ttl)) < 0)
+		DWORD mcastHops = ttl;
+		if(setsockopt(sudp, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, (const char *)&mcastHops, sizeof(mcastHops)) < 0)
 #else  /* _WIN32 */
 #else  /* _WIN32 */
-	if(setsockopt(sudp, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl)) < 0)
+		int mcastHops = ttl;
+		if(setsockopt(sudp, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &mcastHops, sizeof(mcastHops)) < 0)
 #endif /* _WIN32 */
 #endif /* _WIN32 */
-	{
-		/* not a fatal error */
-		PRINT_SOCKET_ERROR("setsockopt(IP_MULTICAST_TTL,...)");
+		{
+			PRINT_SOCKET_ERROR("setsockopt(IPV6_MULTICAST_HOPS,...)");
+		}
+	} else {
+#ifdef _WIN32
+		if(setsockopt(sudp, IPPROTO_IP, IP_MULTICAST_TTL, (const char *)&_ttl, sizeof(_ttl)) < 0)
+#else  /* _WIN32 */
+		if(setsockopt(sudp, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl)) < 0)
+#endif /* _WIN32 */
+		{
+			/* not a fatal error */
+			PRINT_SOCKET_ERROR("setsockopt(IP_MULTICAST_TTL,...)");
+		}
 	}
 	}
 
 
 	if(multicastif)
 	if(multicastif)
@@ -704,6 +719,7 @@ ssdpDiscoverDevices(const char * const deviceTypes[],
 	}
 	}
 	/* receiving SSDP response packet */
 	/* receiving SSDP response packet */
 	for(deviceIndex = 0; deviceTypes[deviceIndex]; deviceIndex++) {
 	for(deviceIndex = 0; deviceTypes[deviceIndex]; deviceIndex++) {
+		sentok = 0;
 		/* sending the SSDP M-SEARCH packet */
 		/* sending the SSDP M-SEARCH packet */
 		n = snprintf(bufr, sizeof(bufr),
 		n = snprintf(bufr, sizeof(bufr),
 		             MSearchMsgFmt,
 		             MSearchMsgFmt,
@@ -747,7 +763,8 @@ ssdpDiscoverDevices(const char * const deviceTypes[],
 			if(error)
 			if(error)
 				*error = MINISSDPC_SOCKET_ERROR;
 				*error = MINISSDPC_SOCKET_ERROR;
 			PRINT_SOCKET_ERROR("sendto");
 			PRINT_SOCKET_ERROR("sendto");
-			break;
+		} else {
+			sentok = 1;
 		}
 		}
 #else /* #ifdef NO_GETADDRINFO */
 #else /* #ifdef NO_GETADDRINFO */
 		memset(&hints, 0, sizeof(hints));
 		memset(&hints, 0, sizeof(hints));
@@ -779,19 +796,20 @@ ssdpDiscoverDevices(const char * const deviceTypes[],
 #endif
 #endif
 				PRINT_SOCKET_ERROR("sendto");
 				PRINT_SOCKET_ERROR("sendto");
 				continue;
 				continue;
+			} else {
+				sentok = 1;
 			}
 			}
 		}
 		}
 		freeaddrinfo(servinfo);
 		freeaddrinfo(servinfo);
-		if(n < 0) {
+		if(!sentok) {
 			if(error)
 			if(error)
 				*error = MINISSDPC_SOCKET_ERROR;
 				*error = MINISSDPC_SOCKET_ERROR;
-			break;
 		}
 		}
 #endif /* #ifdef NO_GETADDRINFO */
 #endif /* #ifdef NO_GETADDRINFO */
 		/* Waiting for SSDP REPLY packet to M-SEARCH
 		/* Waiting for SSDP REPLY packet to M-SEARCH
 		 * if searchalltypes is set, enter the loop only
 		 * if searchalltypes is set, enter the loop only
 		 * when the last deviceType is reached */
 		 * when the last deviceType is reached */
-		if(!searchalltypes || !deviceTypes[deviceIndex + 1]) do {
+		if((sentok && !searchalltypes) || !deviceTypes[deviceIndex + 1]) do {
 			n = receivedata(sudp, bufr, sizeof(bufr), delay, &scope_id);
 			n = receivedata(sudp, bufr, sizeof(bufr), delay, &scope_id);
 			if (n < 0) {
 			if (n < 0) {
 				/* error */
 				/* error */

+ 1 - 1
ext/miniupnpc/miniupnpc.h

@@ -19,7 +19,7 @@
 #define UPNPDISCOVER_MEMORY_ERROR (-102)
 #define UPNPDISCOVER_MEMORY_ERROR (-102)
 
 
 /* versions : */
 /* versions : */
-#define MINIUPNPC_VERSION	"2.0.20161216"
+#define MINIUPNPC_VERSION	"2.0.20171212"
 #define MINIUPNPC_API_VERSION	16
 #define MINIUPNPC_API_VERSION	16
 
 
 /* Source port:
 /* Source port:

+ 12 - 4
ext/miniupnpc/miniupnpcmodule.c

@@ -1,8 +1,8 @@
-/* $Id: miniupnpcmodule.c,v 1.29 2015/10/26 17:01:30 nanard Exp $*/
+/* $Id: miniupnpcmodule.c,v 1.31 2017/11/02 15:37:28 nanard Exp $*/
 /* Project : miniupnp
 /* Project : miniupnp
  * Author : Thomas BERNARD
  * Author : Thomas BERNARD
  * website : http://miniupnp.tuxfamily.org/
  * website : http://miniupnp.tuxfamily.org/
- * copyright (c) 2007-2014 Thomas Bernard
+ * copyright (c) 2007-2016 Thomas Bernard
  * This software is subjet to the conditions detailed in the
  * This software is subjet to the conditions detailed in the
  * provided LICENCE file. */
  * provided LICENCE file. */
 #include <Python.h>
 #include <Python.h>
@@ -12,6 +12,10 @@
 #include "upnpcommands.h"
 #include "upnpcommands.h"
 #include "upnperrors.h"
 #include "upnperrors.h"
 
 
+#ifdef _WIN32
+#include <winsock2.h>
+#endif
+
 /* for compatibility with Python < 2.4 */
 /* for compatibility with Python < 2.4 */
 #ifndef Py_RETURN_NONE
 #ifndef Py_RETURN_NONE
 #define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
 #define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
@@ -303,7 +307,7 @@ UPnP_addportmapping(UPnPObject *self, PyObject *args)
 	const char * remoteHost;
 	const char * remoteHost;
 	const char * leaseDuration = "0";
 	const char * leaseDuration = "0";
 	int r;
 	int r;
-	if (!PyArg_ParseTuple(args, "HssHss", &ePort, &proto,
+	if (!PyArg_ParseTuple(args, "HssHzz", &ePort, &proto,
 	                                     &host, &iPort, &desc, &remoteHost))
 	                                     &host, &iPort, &desc, &remoteHost))
         return NULL;
         return NULL;
 Py_BEGIN_ALLOW_THREADS
 Py_BEGIN_ALLOW_THREADS
@@ -345,7 +349,7 @@ UPnP_addanyportmapping(UPnPObject *self, PyObject *args)
 	const char * remoteHost;
 	const char * remoteHost;
 	const char * leaseDuration = "0";
 	const char * leaseDuration = "0";
 	int r;
 	int r;
-	if (!PyArg_ParseTuple(args, "HssHss", &ePort, &proto, &host, &iPort, &desc, &remoteHost))
+	if (!PyArg_ParseTuple(args, "HssHzz", &ePort, &proto, &host, &iPort, &desc, &remoteHost))
         return NULL;
         return NULL;
 Py_BEGIN_ALLOW_THREADS
 Py_BEGIN_ALLOW_THREADS
 	sprintf(extPort, "%hu", ePort);
 	sprintf(extPort, "%hu", ePort);
@@ -669,6 +673,10 @@ initminiupnpc(void)
     PyObject* m;
     PyObject* m;
 
 
 #ifdef _WIN32
 #ifdef _WIN32
+    /* initialize Winsock. */
+    WSADATA wsaData;
+    int nResult = WSAStartup(MAKEWORD(2,2), &wsaData);
+
     UPnPType.tp_new = PyType_GenericNew;
     UPnPType.tp_new = PyType_GenericNew;
 #endif
 #endif
     if (PyType_Ready(&UPnPType) < 0)
     if (PyType_Ready(&UPnPType) < 0)

+ 10 - 9
ext/miniupnpc/miniwget.c

@@ -1,8 +1,8 @@
-/* $Id: miniwget.c,v 1.76 2016/12/16 08:54:04 nanard Exp $ */
+/* $Id: miniwget.c,v 1.77 2017/05/09 10:04:57 nanard Exp $ */
 /* Project : miniupnp
 /* Project : miniupnp
  * Website : http://miniupnp.free.fr/
  * Website : http://miniupnp.free.fr/
  * Author : Thomas Bernard
  * Author : Thomas Bernard
- * Copyright (c) 2005-2016 Thomas Bernard
+ * Copyright (c) 2005-2017 Thomas Bernard
  * This software is subject to the conditions detailed in the
  * This software is subject to the conditions detailed in the
  * LICENCE file provided in this distribution. */
  * LICENCE file provided in this distribution. */
 
 
@@ -48,7 +48,6 @@
 #define MIN(x,y) (((x)<(y))?(x):(y))
 #define MIN(x,y) (((x)<(y))?(x):(y))
 #endif /* MIN */
 #endif /* MIN */
 
 
-
 #ifdef _WIN32
 #ifdef _WIN32
 #define OS_STRING "Win32"
 #define OS_STRING "Win32"
 #define MINIUPNPC_VERSION_STRING "2.0"
 #define MINIUPNPC_VERSION_STRING "2.0"
@@ -122,7 +121,7 @@ getHTTPResponse(int s, int * size, int * status_code)
 	chunksize_buf[0] = '\0';
 	chunksize_buf[0] = '\0';
 	chunksize_buf_index = 0;
 	chunksize_buf_index = 0;
 
 
-	while((n = receivedata(s, buf, 2048, 5000, NULL)) > 0)
+	while((n = receivedata(s, buf, sizeof(buf), 5000, NULL)) > 0)
 	{
 	{
 		if(endofheaders == 0)
 		if(endofheaders == 0)
 		{
 		{
@@ -295,11 +294,12 @@ getHTTPResponse(int s, int * size, int * status_code)
 							goto end_of_stream;
 							goto end_of_stream;
 						}
 						}
 					}
 					}
-					bytestocopy = ((int)chunksize < (n - i))?chunksize:(unsigned int)(n - i);
+					/* it is guaranteed that (n >= i) */
+					bytestocopy = (chunksize < (unsigned int)(n - i))?chunksize:(unsigned int)(n - i);
 					if((content_buf_used + bytestocopy) > content_buf_len)
 					if((content_buf_used + bytestocopy) > content_buf_len)
 					{
 					{
 						char * tmp;
 						char * tmp;
-						if(content_length >= (int)(content_buf_used + bytestocopy)) {
+						if((content_length >= 0) && ((unsigned int)content_length >= (content_buf_used + bytestocopy))) {
 							content_buf_len = content_length;
 							content_buf_len = content_length;
 						} else {
 						} else {
 							content_buf_len = content_buf_used + bytestocopy;
 							content_buf_len = content_buf_used + bytestocopy;
@@ -324,14 +324,15 @@ getHTTPResponse(int s, int * size, int * status_code)
 			{
 			{
 				/* not chunked */
 				/* not chunked */
 				if(content_length > 0
 				if(content_length > 0
-				   && (int)(content_buf_used + n) > content_length) {
+				   && (content_buf_used + n) > (unsigned int)content_length) {
 					/* skipping additional bytes */
 					/* skipping additional bytes */
 					n = content_length - content_buf_used;
 					n = content_length - content_buf_used;
 				}
 				}
 				if(content_buf_used + n > content_buf_len)
 				if(content_buf_used + n > content_buf_len)
 				{
 				{
 					char * tmp;
 					char * tmp;
-					if(content_length >= (int)(content_buf_used + n)) {
+					if(content_length >= 0
+					   && (unsigned int)content_length >= (content_buf_used + n)) {
 						content_buf_len = content_length;
 						content_buf_len = content_length;
 					} else {
 					} else {
 						content_buf_len = content_buf_used + n;
 						content_buf_len = content_buf_used + n;
@@ -351,7 +352,7 @@ getHTTPResponse(int s, int * size, int * status_code)
 			}
 			}
 		}
 		}
 		/* use the Content-Length header value if available */
 		/* use the Content-Length header value if available */
-		if(content_length > 0 && (int)content_buf_used >= content_length)
+		if(content_length > 0 && content_buf_used >= (unsigned int)content_length)
 		{
 		{
 #ifdef DEBUG
 #ifdef DEBUG
 			printf("End of HTTP content\n");
 			printf("End of HTTP content\n");

+ 6 - 4
ext/miniupnpc/minixml.c

@@ -1,10 +1,11 @@
-/* $Id: minixml.c,v 1.11 2014/02/03 15:54:12 nanard Exp $ */
-/* minixml.c : the minimum size a xml parser can be ! */
+/* $Id: minixml.c,v 1.12 2017/12/12 11:17:40 nanard Exp $ */
+/* vim: tabstop=4 shiftwidth=4 noexpandtab
+ * minixml.c : the minimum size a xml parser can be ! */
 /* Project : miniupnp
 /* Project : miniupnp
  * webpage: http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
  * webpage: http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
  * Author : Thomas Bernard
  * Author : Thomas Bernard
 
 
-Copyright (c) 2005-2014, Thomas BERNARD
+Copyright (c) 2005-2017, Thomas BERNARD
 All rights reserved.
 All rights reserved.
 
 
 Redistribution and use in source and binary forms, with or without
 Redistribution and use in source and binary forms, with or without
@@ -161,7 +162,8 @@ static void parseelt(struct xmlparser * p)
 						if (p->xml >= p->xmlend)
 						if (p->xml >= p->xmlend)
 							return;
 							return;
 					}
 					}
-					if(memcmp(p->xml, "<![CDATA[", 9) == 0)
+					/* CDATA are at least 9 + 3 characters long : <![CDATA[ ]]> */
+					if((p->xmlend >= (p->xml + (9 + 3))) && (memcmp(p->xml, "<![CDATA[", 9) == 0))
 					{
 					{
 						/* CDATA handling */
 						/* CDATA handling */
 						p->xml += 9;
 						p->xml += 9;

+ 0 - 88
ext/miniupnpc/pymoduletest.py

@@ -1,88 +0,0 @@
-#! /usr/bin/python
-# vim: tabstop=2 shiftwidth=2 expandtab
-# MiniUPnP project
-# Author : Thomas Bernard
-# This Sample code is public domain.
-# website : http://miniupnp.tuxfamily.org/
-
-# import the python miniupnpc module
-import miniupnpc
-import sys
-
-try:
-  import argparse
-  parser = argparse.ArgumentParser()
-  parser.add_argument('-m', '--multicastif')
-  parser.add_argument('-p', '--minissdpdsocket')
-  parser.add_argument('-d', '--discoverdelay', type=int, default=200)
-  parser.add_argument('-z', '--localport', type=int, default=0)
-  # create the object
-  u = miniupnpc.UPnP(**vars(parser.parse_args()))
-except:
-  print 'argparse not available'
-  i = 1
-  multicastif = None
-  minissdpdsocket = None
-  discoverdelay = 200
-  localport = 0
-  while i < len(sys.argv):
-    print sys.argv[i]
-    if sys.argv[i] == '-m' or sys.argv[i] == '--multicastif':
-      multicastif = sys.argv[i+1]
-    elif sys.argv[i] == '-p' or sys.argv[i] == '--minissdpdsocket':
-      minissdpdsocket = sys.argv[i+1]
-    elif sys.argv[i] == '-d' or sys.argv[i] == '--discoverdelay':
-      discoverdelay = int(sys.argv[i+1])
-    elif sys.argv[i] == '-z' or sys.argv[i] == '--localport':
-      localport = int(sys.argv[i+1])
-    else:
-      raise Exception('invalid argument %s' % sys.argv[i])
-    i += 2
-  # create the object
-  u = miniupnpc.UPnP(multicastif, minissdpdsocket, discoverdelay, localport)
-
-print 'inital(default) values :'
-print ' discoverdelay', u.discoverdelay
-print ' lanaddr', u.lanaddr
-print ' multicastif', u.multicastif
-print ' minissdpdsocket', u.minissdpdsocket
-#u.minissdpdsocket = '../minissdpd/minissdpd.sock'
-# discovery process, it usualy takes several seconds (2 seconds or more)
-print 'Discovering... delay=%ums' % u.discoverdelay
-print u.discover(), 'device(s) detected'
-# select an igd
-try:
-  u.selectigd()
-except Exception, e:
-  print 'Exception :', e
-  sys.exit(1)
-# display information about the IGD and the internet connection
-print 'local ip address :', u.lanaddr
-print 'external ip address :', u.externalipaddress()
-print u.statusinfo(), u.connectiontype()
-print 'total bytes : sent', u.totalbytesent(), 'received', u.totalbytereceived()
-print 'total packets : sent', u.totalpacketsent(), 'received', u.totalpacketreceived()
-
-#print u.addportmapping(64000, 'TCP',
-#                       '192.168.1.166', 63000, 'port mapping test', '')
-#print u.deleteportmapping(64000, 'TCP')
-
-port = 0
-proto = 'UDP'
-# list the redirections :
-i = 0
-while True:
-	p = u.getgenericportmapping(i)
-	if p==None:
-		break
-	print i, p
-	(port, proto, (ihost,iport), desc, c, d, e) = p
-	#print port, desc
-	i = i + 1
-
-print u.getspecificportmapping(port, proto)
-try:
-  print u.getportmappingnumberofentries()
-except Exception, e:
-  print 'GetPortMappingNumberOfEntries() is not supported :', e
-

+ 2 - 2
ext/miniupnpc/receivedata.c

@@ -1,4 +1,4 @@
-/* $Id: receivedata.c,v 1.7 2015/11/09 21:51:41 nanard Exp $ */
+/* $Id: receivedata.c,v 1.8 2017/04/21 10:16:45 nanard Exp $ */
 /* Project : miniupnp
 /* Project : miniupnp
  * Website : http://miniupnp.free.fr/
  * Website : http://miniupnp.free.fr/
  * Author : Thomas Bernard
  * Author : Thomas Bernard
@@ -28,7 +28,7 @@
 #endif /* _WIN32 */
 #endif /* _WIN32 */
 
 
 #ifdef _WIN32
 #ifdef _WIN32
-#define PRINT_SOCKET_ERROR(x)    printf("Socket error: %s, %d\n", x, WSAGetLastError());
+#define PRINT_SOCKET_ERROR(x)    fprintf(stderr, "Socket error: %s, %d\n", x, WSAGetLastError());
 #else
 #else
 #define PRINT_SOCKET_ERROR(x) perror(x)
 #define PRINT_SOCKET_ERROR(x) perror(x)
 #endif
 #endif

+ 0 - 14
ext/miniupnpc/testdesc/linksys_WAG200G_desc.values

@@ -1,14 +0,0 @@
-# values for linksys_WAG200G_desc.xml
-
-CIF:
- servicetype = urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1
- controlurl = /upnp/control/WANCommonIFC1
- eventsuburl = /upnp/event/WANCommonIFC1
- scpdurl = /cmnicfg.xml
-
-first:
- servicetype = urn:schemas-upnp-org:service:WANPPPConnection:1
- controlurl = /upnp/control/WANPPPConn1
- eventsuburl = /upnp/event/WANPPPConn1
- scpdurl = /pppcfg.xml
-

+ 0 - 110
ext/miniupnpc/testdesc/linksys_WAG200G_desc.xml

@@ -1,110 +0,0 @@
-<?xml version="1.0"?>
-<root xmlns="urn:schemas-upnp-org:device-1-0">
-<specVersion>
-<major>1</major>
-<minor>0</minor>
-</specVersion>
-<URLBase>http://192.168.1.1:49152</URLBase>
-<device>
-<deviceType>urn:schemas-upnp-org:device:InternetGatewayDevice:1</deviceType>
-<friendlyName>LINKSYS WAG200G Gateway</friendlyName>
-<manufacturer>LINKSYS</manufacturer>
-<manufacturerURL>http://www.linksys.com</manufacturerURL>
-<modelDescription>LINKSYS WAG200G Gateway</modelDescription>
-<modelName>Wireless-G ADSL Home Gateway</modelName>
-<modelNumber>WAG200G</modelNumber>
-<modelURL>http://www.linksys.com</modelURL>
-<serialNumber>123456789</serialNumber>
-<UDN>uuid:8ca2eb37-1dd2-11b2-86f1-001a709b5aa8</UDN>
-<UPC>WAG200G</UPC>
-<serviceList>
-<service>
-<serviceType>urn:schemas-upnp-org:service:Layer3Forwarding:1</serviceType>
-<serviceId>urn:upnp-org:serviceId:L3Forwarding1</serviceId>
-<controlURL>/upnp/control/L3Forwarding1</controlURL>
-<eventSubURL>/upnp/event/L3Forwarding1</eventSubURL>
-<SCPDURL>/l3frwd.xml</SCPDURL>
-</service>
-</serviceList>
-<deviceList>
-<device>
-<deviceType>urn:schemas-upnp-org:device:WANDevice:1</deviceType>
-<friendlyName>WANDevice</friendlyName>
-<manufacturer>LINKSYS</manufacturer>
-<manufacturerURL>http://www.linksys.com/</manufacturerURL>
-<modelDescription>Residential Gateway</modelDescription>
-<modelName>Internet Connection Sharing</modelName>
-<modelNumber>1</modelNumber>
-<modelURL>http://www.linksys.com/</modelURL>
-<serialNumber>0000001</serialNumber>
-<UDN>uuid:8ca2eb36-1dd2-11b2-86f1-001a709b5aa8</UDN>
-<UPC>WAG200G</UPC>
-<serviceList>
-<service>
-<serviceType>urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1</serviceType>
-<serviceId>urn:upnp-org:serviceId:WANCommonIFC1</serviceId>
-<controlURL>/upnp/control/WANCommonIFC1</controlURL>
-<eventSubURL>/upnp/event/WANCommonIFC1</eventSubURL>
-<SCPDURL>/cmnicfg.xml</SCPDURL>
-</service>
-</serviceList>
-<deviceList>
-<device>
-<deviceType>urn:schemas-upnp-org:device:WANConnectionDevice:1</deviceType>
-<friendlyName>WANConnectionDevice</friendlyName>
-<manufacturer>LINKSYS</manufacturer>
-<manufacturerURL>http://www.linksys.com/</manufacturerURL>
-<modelDescription>Residential Gateway</modelDescription>
-<modelName>Internet Connection Sharing</modelName>
-<modelNumber>1</modelNumber>
-<modelURL>http://www.linksys.com/</modelURL>
-<serialNumber>0000001</serialNumber>
-<UDN>uuid:8ca2eb37-1dd2-11b2-86f0-001a709b5aa8</UDN>
-<UPC>WAG200G</UPC>
-<serviceList>
-<service>
-<serviceType>urn:schemas-upnp-org:service:WANEthernetLinkConfig:1</serviceType>
-<serviceId>urn:upnp-org:serviceId:WANEthLinkC1</serviceId>
-<controlURL>/upnp/control/WANEthLinkC1</controlURL>
-<eventSubURL>/upnp/event/WANEthLinkC1</eventSubURL>
-<SCPDURL>/wanelcfg.xml</SCPDURL>
-</service>
-<service>
-<serviceType>urn:schemas-upnp-org:service:WANPPPConnection:1</serviceType>
-<serviceId>urn:upnp-org:serviceId:WANPPPConn1</serviceId>
-<controlURL>/upnp/control/WANPPPConn1</controlURL>
-<eventSubURL>/upnp/event/WANPPPConn1</eventSubURL>
-<SCPDURL>/pppcfg.xml</SCPDURL>
-</service>
-</serviceList>
-</device>
-</deviceList>
-</device>
-<device>
-<deviceType>urn:schemas-upnp-org:device:LANDevice:1</deviceType>
-<friendlyName>LANDevice</friendlyName>
-<manufacturer>LINKSYS</manufacturer>
-<manufacturerURL>http://www.linksys.com/</manufacturerURL>
-<modelDescription>Residential Gateway</modelDescription>
-<modelName>Residential Gateway</modelName>
-<modelNumber>1</modelNumber>
-<modelURL>http://www.linksys.com/</modelURL>
-<serialNumber>0000001</serialNumber>
-<UDN>uuid:8ca2eb36-1dd2-11b2-86f0-001a709b5aa
-8</UDN>
-<UPC>WAG200G</UPC>
-<serviceList>
-<service>
-<serviceType>urn:schemas-upnp-org:service:LANHostConfigManagement:1</serviceType>
-<serviceId>urn:upnp-org:serviceId:LANHostCfg1</serviceId>
-<controlURL>/upnp/control/LANHostCfg1</controlURL>
-<eventSubURL>/upnp/event/LANHostCfg1</eventSubURL>
-<SCPDURL>/lanhostc.xml</SCPDURL>
-</service>
-</serviceList>
-</device>
-</deviceList>
-<presentationURL>http://192.168.1.1/index.htm</presentationURL>
-</device>
-</root>
-

+ 0 - 20
ext/miniupnpc/testdesc/new_LiveBox_desc.values

@@ -1,20 +0,0 @@
-# values for new_LiveBox_desc.xml
-
-CIF:
- servicetype = urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1
- controlurl = /87895a19/upnp/control/WANCommonIFC1
- eventsuburl = /87895a19/upnp/control/WANCommonIFC1
- scpdurl = /87895a19/gateicfgSCPD.xml
-
-first:
- servicetype = urn:schemas-upnp-org:service:WANPPPConnection:2
- controlurl = /87895a19/upnp/control/WANIPConn1
- eventsuburl = /87895a19/upnp/control/WANIPConn1
- scpdurl = /87895a19/gateconnSCPD_PPP.xml
-
-IPv6FC:
- servicetype = urn:schemas-upnp-org:service:WANIPv6FirewallControl:1
- controlurl = /87895a19/upnp/control/WANIPv6FwCtrl1
- eventsuburl = /87895a19/upnp/control/WANIPv6FwCtrl1
- scpdurl = /87895a19/wanipv6fwctrlSCPD.xml
-

+ 0 - 90
ext/miniupnpc/testdesc/new_LiveBox_desc.xml

@@ -1,90 +0,0 @@
-<?xml version="1.0"?>
-<root xmlns="urn:schemas-upnp-org:device-1-0">
-  <specVersion>
-    <major>1</major>
-    <minor>0</minor>
-  </specVersion>
-  <device>
-    <pnpx:X_hardwareId xmlns:pnpx="http://schemas.microsoft.com/windows/pnpx/2005/11">VEN_0129&amp;DEV_0000&amp;SUBSYS_03&amp;REV_250417</pnpx:X_hardwareId>
-    <pnpx:X_compatibleId xmlns:pnpx="http://schemas.microsoft.com/windows/pnpx/2005/11">GenericUmPass</pnpx:X_compatibleId>
-    <pnpx:X_deviceCategory xmlns:pnpx="http://schemas.microsoft.com/windows/pnpx/2005/11">NetworkInfrastructure.Gateway</pnpx:X_deviceCategory>
-    <df:X_deviceCategory xmlns:df="http://schemas.microsoft.com/windows/2008/09/devicefoundation">Network.Gateway</df:X_deviceCategory>
-    <deviceType>urn:schemas-upnp-org:device:InternetGatewayDevice:2</deviceType>
-    <friendlyName>Orange Livebox</friendlyName>
-    <manufacturer>Sagemcom</manufacturer>
-    <manufacturerURL>http://www.sagemcom.com/</manufacturerURL>
-    <modelName>Residential Livebox,(DSL,WAN Ethernet)</modelName>
-    <UDN>uuid:87895a19-50f9-3736-a87f-115c230155f8</UDN>
-    <modelDescription>Sagemcom,fr,SG30_sip-fr-4.28.35.1</modelDescription>
-    <modelNumber>3</modelNumber>
-    <serialNumber>LK14129DP441489</serialNumber>
-    <presentationURL>http://192.168.1.1</presentationURL>
-    <UPC></UPC>
-    <iconList>
-      <icon>
-        <mimetype>image/png</mimetype>
-        <width>16</width>
-        <height>16</height>
-        <depth>8</depth>
-        <url>/87895a19/ligd.png</url>
-      </icon>
-    </iconList>
-    <deviceList>
-      <device>
-        <deviceType>urn:schemas-upnp-org:device:WANDevice:2</deviceType>
-        <friendlyName>WANDevice</friendlyName>
-        <manufacturer>Sagemcom</manufacturer>
-        <manufacturerURL>http://www.sagemcom.com/</manufacturerURL>
-        <modelDescription>WAN Device on Sagemcom,fr,SG30_sip-fr-4.28.35.1</modelDescription>
-        <modelName>Residential Livebox,(DSL,WAN Ethernet)</modelName>
-        <modelNumber>3</modelNumber>
-        <modelURL>http://www.sagemcom.com/</modelURL>
-        <serialNumber>LK14129DP441489</serialNumber>
-        <presentationURL>http://192.168.1.1</presentationURL>
-        <UDN>uuid:e2397374-53d8-3fc6-8306-593ba1a34625</UDN>
-        <UPC></UPC>
-        <serviceList>
-          <service>
-            <serviceType>urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1</serviceType>
-            <serviceId>urn:upnp-org:serviceId:WANCommonIFC1</serviceId>
-            <controlURL>/87895a19/upnp/control/WANCommonIFC1</controlURL>
-            <eventSubURL>/87895a19/upnp/control/WANCommonIFC1</eventSubURL>
-            <SCPDURL>/87895a19/gateicfgSCPD.xml</SCPDURL>
-          </service>
-        </serviceList>
-        <deviceList>
-          <device>
-            <deviceType>urn:schemas-upnp-org:device:WANConnectionDevice:2</deviceType>
-            <friendlyName>WANConnectionDevice</friendlyName>
-            <manufacturer>Sagemcom</manufacturer>
-            <manufacturerURL>http://www.sagemcom.com/</manufacturerURL>
-            <modelDescription>WanConnectionDevice on Sagemcom,fr,SG30_sip-fr-4.28.35.1</modelDescription>
-            <modelName>Residential Livebox,(DSL,WAN Ethernet)</modelName>
-            <modelNumber>3</modelNumber>
-            <modelURL>http://www.sagemcom.com/</modelURL>
-            <serialNumber>LK14129DP441489</serialNumber>
-            <presentationURL>http://192.168.1.1</presentationURL>
-            <UDN>uuid:44598a08-288e-32c9-8a4d-d3c008ede331</UDN>
-            <UPC></UPC>
-            <serviceList>
-              <service>
-                <serviceType>urn:schemas-upnp-org:service:WANPPPConnection:2</serviceType>
-                <serviceId>urn:upnp-org:serviceId:WANIPConn1</serviceId>
-                <controlURL>/87895a19/upnp/control/WANIPConn1</controlURL>
-                <eventSubURL>/87895a19/upnp/control/WANIPConn1</eventSubURL>
-                <SCPDURL>/87895a19/gateconnSCPD_PPP.xml</SCPDURL>
-              </service>
-             <service>
-                <serviceType>urn:schemas-upnp-org:service:WANIPv6FirewallControl:1</serviceType>
-                <serviceId>urn:upnp-org:serviceId:WANIPv6FwCtrl1</serviceId>
-                <controlURL>/87895a19/upnp/control/WANIPv6FwCtrl1</controlURL>
-                <eventSubURL>/87895a19/upnp/control/WANIPv6FwCtrl1</eventSubURL>
-                <SCPDURL>/87895a19/wanipv6fwctrlSCPD.xml</SCPDURL>
-              </service>
-            </serviceList>
-          </device>
-        </deviceList>
-      </device>
-    </deviceList>
-  </device>
-</root>

+ 0 - 187
ext/miniupnpc/testigddescparse.c

@@ -1,187 +0,0 @@
-/* $Id: testigddescparse.c,v 1.10 2015/08/06 09:55:24 nanard Exp $ */
-/* Project : miniupnp
- * http://miniupnp.free.fr/
- * Author : Thomas Bernard
- * Copyright (c) 2008-2015 Thomas Bernard
- * This software is subject to the conditions detailed in the
- * LICENCE file provided in this distribution.
- * */
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include "igd_desc_parse.h"
-#include "minixml.h"
-#include "miniupnpc.h"
-
-/* count number of differences */
-int compare_service(struct IGDdatas_service * s, FILE * f)
-{
-	int n = 0;
-	char line[1024];
-
-	while(fgets(line, sizeof(line), f)) {
-		char * value;
-		char * equal;
-		char * name;
-		char * parsedvalue;
-		int l;
-		l = strlen(line);
-		while((l > 0) && ((line[l-1] == '\r') || (line[l-1] == '\n') || (line[l-1] == ' ')))
-			line[--l] = '\0';
-		if(l == 0)
-			break;	/* end on blank line */
-		if(line[0] == '#')
-			continue;	/* skip comments */
-		equal = strchr(line, '=');
-		if(equal == NULL) {
-			fprintf(stderr, "Warning, line does not contain '=' : %s\n", line);
-			continue;
-		}
-		*equal = '\0';
-		name = line;
-		while(*name == ' ' || *name == '\t')
-			name++;
-		l = strlen(name);
-		while((l > 0) && (name[l-1] == ' ' || name[l-1] == '\t'))
-			name[--l] = '\0';
-		value = equal + 1;
-		while(*value == ' ' || *value == '\t')
-			value++;
-		if(strcmp(name, "controlurl") == 0)
-			parsedvalue = s->controlurl;
-		else if(strcmp(name, "eventsuburl") == 0)
-			parsedvalue = s->eventsuburl;
-		else if(strcmp(name, "scpdurl") == 0)
-			parsedvalue = s->scpdurl;
-		else if(strcmp(name, "servicetype") == 0)
-			parsedvalue = s->servicetype;
-		else {
-			fprintf(stderr, "unknown field '%s'\n", name);
-			continue;
-		}
-		if(0 != strcmp(parsedvalue, value)) {
-			fprintf(stderr, "difference : '%s' != '%s'\n", parsedvalue, value);
-			n++;
-		}
-	}
-	return n;
-}
-
-int compare_igd(struct IGDdatas * p, FILE * f)
-{
-	int n = 0;
-	char line[1024];
-	struct IGDdatas_service * s;
-
-	while(fgets(line, sizeof(line), f)) {
-		char * colon;
-		int l = (int)strlen(line);
-		while((l > 0) && (line[l-1] == '\r' || (line[l-1] == '\n')))
-			line[--l] = '\0';
-		if(l == 0 || line[0] == '#')
-			continue;	/* skip blank lines and comments */
-		colon = strchr(line, ':');
-		if(colon == NULL) {
-			fprintf(stderr, "Warning, no ':' : %s\n", line);
-			continue;
-		}
-		s = NULL;
-		*colon = '\0';
-		if(strcmp(line, "CIF") == 0)
-			s = &p->CIF;
-		else if(strcmp(line, "first") == 0)
-			s = &p->first;
-		else if(strcmp(line, "second") == 0)
-			s = &p->second;
-		else if(strcmp(line, "IPv6FC") == 0)
-			s = &p->IPv6FC;
-		else {
-			s = NULL;
-			fprintf(stderr, "*** unknown service '%s' ***\n", line);
-			n++;
-			continue;
-		}
-		n += compare_service(s, f);
-	}
-	if(n > 0)
-		fprintf(stderr, "*** %d difference%s ***\n", n, (n > 1) ? "s" : "");
-	return n;
-}
-
-int test_igd_desc_parse(char * buffer, int len, FILE * f)
-{
-	int n;
-	struct IGDdatas igd;
-	struct xmlparser parser;
-	struct UPNPUrls urls;
-
-	memset(&igd, 0, sizeof(struct IGDdatas));
-	memset(&parser, 0, sizeof(struct xmlparser));
-	parser.xmlstart = buffer;
-	parser.xmlsize = len;
-	parser.data = &igd;
-	parser.starteltfunc = IGDstartelt;
-	parser.endeltfunc = IGDendelt;
-	parser.datafunc = IGDdata;
-	parsexml(&parser);
-#ifdef DEBUG
-	printIGD(&igd);
-#endif /* DEBUG */
-	GetUPNPUrls(&urls, &igd, "http://fake/desc/url/file.xml", 0);
-	printf("ipcondescURL='%s'\n", urls.ipcondescURL);
-	printf("controlURL='%s'\n", urls.controlURL);
-	printf("controlURL_CIF='%s'\n", urls.controlURL_CIF);
-	n = f ? compare_igd(&igd, f) : 0;
-	FreeUPNPUrls(&urls);
-	return n;
-}
-
-int main(int argc, char * * argv)
-{
-	FILE * f;
-	char * buffer;
-	int len;
-	int r;
-	if(argc<2) {
-		fprintf(stderr, "Usage: %s file.xml [file.values]\n", argv[0]);
-		return 1;
-	}
-	f = fopen(argv[1], "r");
-	if(!f) {
-		fprintf(stderr, "Cannot open %s for reading.\n", argv[1]);
-		return 1;
-	}
-	fseek(f, 0, SEEK_END);
-	len = ftell(f);
-	fseek(f, 0, SEEK_SET);
-	buffer = malloc(len);
-	if(!buffer) {
-		fprintf(stderr, "Memory allocation error.\n");
-		fclose(f);
-		return 1;
-	}
-	r = (int)fread(buffer, 1, len, f);
-	if(r != len) {
-		fprintf(stderr, "Failed to read file %s. %d out of %d bytes.\n",
-		        argv[1], r, len);
-		fclose(f);
-		free(buffer);
-		return 1;
-	}
-	fclose(f);
-	f = NULL;
-	if(argc > 2) {
-		f = fopen(argv[2], "r");
-		if(!f) {
-			fprintf(stderr, "Cannot open %s for reading.\n", argv[2]);
-			free(buffer);
-			return 1;
-		}
-	}
-	r = test_igd_desc_parse(buffer, len, f);
-	free(buffer);
-	if(f)
-		fclose(f);
-	return r;
-}
-

+ 0 - 55
ext/miniupnpc/testminiwget.c

@@ -1,55 +0,0 @@
-/* $Id: testminiwget.c,v 1.5 2016/01/24 17:24:36 nanard Exp $ */
-/* Project : miniupnp
- * Author : Thomas Bernard
- * Copyright (c) 2005-2016 Thomas Bernard
- * This software is subject to the conditions detailed in the
- * LICENCE file provided in this distribution.
- * */
-#include <stdio.h>
-#include <stdlib.h>
-#include "miniwget.h"
-
-/**
- * This program uses the miniwget / miniwget_getaddr function
- * from miniwget.c in order to retreive a web ressource using
- * a GET HTTP method, and store it in a file.
- */
-int main(int argc, char * * argv)
-{
-	void * data;
-	int size, writtensize;
-	FILE *f;
-	char addr[64];
-	int status_code = -1;
-
-	if(argc < 3) {
-		fprintf(stderr, "Usage:\t%s url file\n", argv[0]);
-		fprintf(stderr, "Example:\t%s http://www.google.com/ out.html\n", argv[0]);
-		return 1;
-	}
-	data = miniwget_getaddr(argv[1], &size, addr, sizeof(addr), 0, &status_code);
-	if(!data || (status_code != 200)) {
-		if(data) free(data);
-		fprintf(stderr, "Error %d fetching %s\n", status_code, argv[1]);
-		return 1;
-	}
-	printf("local address : %s\n", addr);
-	printf("got %d bytes\n", size);
-	f = fopen(argv[2], "wb");
-	if(!f) {
-		fprintf(stderr, "Cannot open file %s for writing\n", argv[2]);
-		free(data);
-		return 1;
-	}
-	writtensize = fwrite(data, 1, size, f);
-	if(writtensize != size) {
-		fprintf(stderr, "Could only write %d bytes out of %d to %s\n",
-		        writtensize, size, argv[2]);
-	} else {
-		printf("%d bytes written to %s\n", writtensize, argv[2]);
-	}
-	fclose(f);
-	free(data);
-	return 0;
-}
-

+ 0 - 96
ext/miniupnpc/testminiwget.sh

@@ -1,96 +0,0 @@
-#!/bin/sh
-# $Id: testminiwget.sh,v 1.13 2015/09/03 17:57:44 nanard Exp $
-# project miniupnp : http://miniupnp.free.fr/
-# (c) 2011-2015 Thomas Bernard
-#
-# test program for miniwget.c
-# is usually invoked by "make check"
-#
-# This test program :
-#  1 - launches a local HTTP server (minihttptestserver)
-#  2 - uses testminiwget to retreive data from this server
-#  3 - compares served and received data
-#  4 - kills the local HTTP server and exits
-#
-# The script was tested and works with ksh, bash
-# it should now also run with dash
-
-TMPD=`mktemp -d -t miniwgetXXXXXXXXXX`
-HTTPSERVEROUT="${TMPD}/httpserverout"
-EXPECTEDFILE="${TMPD}/expectedfile"
-DOWNLOADEDFILE="${TMPD}/downloadedfile"
-PORT=
-RET=0
-
-case "$HAVE_IPV6" in
-    n|no|0)
-        ADDR=localhost
-        SERVERARGS=""
-        ;;
-    *)
-        ADDR="[::1]"
-        SERVERARGS="-6"
-        ;;
-
-esac
-
-#make minihttptestserver
-#make testminiwget
-
-# launching the test HTTP server
-./minihttptestserver $SERVERARGS -e $EXPECTEDFILE > $HTTPSERVEROUT &
-SERVERPID=$!
-while [ -z "$PORT" ]; do
-	sleep 1
-	PORT=`cat $HTTPSERVEROUT | sed 's/Listening on port \([0-9]*\)/\1/' `
-done
-echo "Test HTTP server is listening on $PORT"
-
-URL1="http://$ADDR:$PORT/index.html"
-URL2="http://$ADDR:$PORT/chunked"
-URL3="http://$ADDR:$PORT/addcrap"
-
-echo "standard test ..."
-./testminiwget $URL1 "${DOWNLOADEDFILE}.1"
-if cmp $EXPECTEDFILE "${DOWNLOADEDFILE}.1" ; then
-	echo "ok"
-else
-	echo "standard test FAILED"
-	RET=1
-fi
-
-echo "chunked transfert encoding test ..."
-./testminiwget $URL2 "${DOWNLOADEDFILE}.2"
-if cmp $EXPECTEDFILE "${DOWNLOADEDFILE}.2" ; then
-	echo "ok"
-else
-	echo "chunked transfert encoding test FAILED"
-	RET=1
-fi
-
-echo "response too long test ..."
-./testminiwget $URL3 "${DOWNLOADEDFILE}.3"
-if cmp $EXPECTEDFILE "${DOWNLOADEDFILE}.3" ; then
-	echo "ok"
-else
-	echo "response too long test FAILED"
-	RET=1
-fi
-
-# kill the test HTTP server
-kill $SERVERPID
-wait $SERVERPID
-
-# remove temporary files (for success cases)
-if [ $RET -eq 0 ]; then
-	rm -f "${DOWNLOADEDFILE}.1"
-	rm -f "${DOWNLOADEDFILE}.2"
-	rm -f "${DOWNLOADEDFILE}.3"
-	rm -f $EXPECTEDFILE $HTTPSERVEROUT
-	rmdir ${TMPD}
-else
-	echo "at least one of the test FAILED"
-	echo "directory ${TMPD} is left intact"
-fi
-exit $RET
-

+ 0 - 89
ext/miniupnpc/testminixml.c

@@ -1,89 +0,0 @@
-/* $Id: testminixml.c,v 1.10 2014/11/17 17:19:13 nanard Exp $
- * MiniUPnP project
- * Website : http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
- * Author : Thomas Bernard.
- * Copyright (c) 2005-2014 Thomas Bernard
- *
- * testminixml.c
- * test program for the "minixml" functions.
- */
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include "minixml.h"
-#include "igd_desc_parse.h"
-
-/* ---------------------------------------------------------------------- */
-void printeltname1(void * d, const char * name, int l)
-{
-	int i;
-	(void)d;
-	printf("element ");
-	for(i=0;i<l;i++)
-		putchar(name[i]);
-}
-void printeltname2(void * d, const char * name, int l)
-{
-	int i;
-	(void)d;
-	putchar('/');
-	for(i=0;i<l;i++)
-		putchar(name[i]);
-	putchar('\n');
-}
-void printdata(void *d, const char * data, int l)
-{
-	int i;
-	(void)d;
-	printf("data : ");
-	for(i=0;i<l;i++)
-		putchar(data[i]);
-	putchar('\n');
-}
-
-void burptest(const char * buffer, int bufsize)
-{
-	struct IGDdatas data;
-	struct xmlparser parser;
-	/*objet IGDdatas */
-	memset(&data, 0, sizeof(struct IGDdatas));
-	/* objet xmlparser */
-	parser.xmlstart = buffer;
-	parser.xmlsize = bufsize;
-	parser.data = &data;
-	/*parser.starteltfunc = printeltname1;
-	parser.endeltfunc = printeltname2;
-	parser.datafunc = printdata; */
-	parser.starteltfunc = IGDstartelt;
-	parser.endeltfunc = IGDendelt;
-	parser.datafunc = IGDdata;
-	parsexml(&parser);
-#ifdef DEBUG
-	printIGD(&data);
-#endif /* DEBUG */
-}
-
-/* ----- main ---- */
-#define XML_MAX_SIZE (8192)
-int main(int argc, char * * argv)
-{
-	FILE * f;
-	char buffer[XML_MAX_SIZE];
-	int bufsize;
-	if(argc<2)
-	{
-		printf("usage:\t%s file.xml\n", argv[0]);
-		return 1;
-	}
-	f = fopen(argv[1], "r");
-	if(!f)
-	{
-		printf("cannot open file %s\n", argv[1]);
-		return 1;
-	}
-	bufsize = (int)fread(buffer, 1, XML_MAX_SIZE, f);
-	fclose(f);
-	burptest(buffer, bufsize);
-	return 0;
-}
-

+ 0 - 151
ext/miniupnpc/testportlistingparse.c

@@ -1,151 +0,0 @@
-/* $Id: testportlistingparse.c,v 1.2 2014/11/01 10:37:32 nanard Exp $ */
-/* Project : miniupnp
- * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
- * Author : Thomas Bernard
- * Copyright (c) 2014 Thomas Bernard
- * This software is subject to the conditions detailed in the
- * LICENCE file provided in this distribution.
- * */
-
-#include <string.h>
-#include <stdio.h>
-#include "portlistingparse.h"
-
-struct port_mapping {
-	unsigned int leasetime;
-	unsigned short externalport;
-	unsigned short internalport;
-	const char * remotehost;
-	const char * client;
-	const char * proto;
-	const char * desc;
-	unsigned char enabled;
-};
-
-/* return the number of differences */
-int test(const char * portListingXml, int portListingXmlLen,
-         const struct port_mapping * ref, int count)
-{
-	int i;
-	int r = 0;
-	struct PortMappingParserData data;
-	struct PortMapping * pm;
-
-	memset(&data, 0, sizeof(data));
-	ParsePortListing(portListingXml, portListingXmlLen, &data);
-	for(i = 0, pm = data.l_head;
-	    (pm != NULL) && (i < count);
-	    i++, pm = pm->l_next) {
-		printf("%2d %s %5hu->%s:%-5hu '%s' '%s' %u\n",
-		       i, pm->protocol, pm->externalPort, pm->internalClient,
-		       pm->internalPort,
-		       pm->description, pm->remoteHost,
-		       (unsigned)pm->leaseTime);
-		if(0 != strcmp(pm->protocol, ref[i].proto)) {
-			printf("protocol : '%s' != '%s'\n", pm->protocol, ref[i].proto);
-			r++;
-		}
-		if(pm->externalPort != ref[i].externalport) {
-			printf("externalPort : %hu != %hu\n",
-			       pm->externalPort, ref[i].externalport);
-			r++;
-		}
-		if(0 != strcmp(pm->internalClient, ref[i].client)) {
-			printf("client : '%s' != '%s'\n",
-			       pm->internalClient, ref[i].client);
-			r++;
-		}
-		if(pm->internalPort != ref[i].internalport) {
-			printf("internalPort : %hu != %hu\n",
-			       pm->internalPort, ref[i].internalport);
-			r++;
-		}
-		if(0 != strcmp(pm->description, ref[i].desc)) {
-			printf("description : '%s' != '%s'\n",
-			       pm->description, ref[i].desc);
-			r++;
-		}
-		if(0 != strcmp(pm->remoteHost, ref[i].remotehost)) {
-			printf("remoteHost : '%s' != '%s'\n",
-			       pm->remoteHost, ref[i].remotehost);
-			r++;
-		}
-		if((unsigned)pm->leaseTime != ref[i].leasetime) {
-			printf("leaseTime : %u != %u\n",
-			       (unsigned)pm->leaseTime, ref[i].leasetime);
-			r++;
-		}
-		if(pm->enabled != ref[i].enabled) {
-			printf("enabled : %d != %d\n",
-			       (int)pm->enabled, (int)ref[i].enabled);
-			r++;
-		}
-	}
-	if((i != count) || (pm != NULL)) {
-		printf("count mismatch : i=%d count=%d pm=%p\n", i, count, pm);
-		r++;
-	}
-	FreePortListing(&data);
-	return r;
-}
-
-const char test_document[] =
-"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
-"<p:PortMappingList xmlns:p=\"urn:schemas-upnp-org:gw:WANIPConnection\"\n"
-"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" \n"
-"xsi:schemaLocation=\"urn:schemas-upnp-org:gw:WANIPConnection "
-"http://www.upnp.org/schemas/gw/WANIPConnection-v2.xsd\">\n"
-" <p:PortMappingEntry>\n"
-"  <p:NewRemoteHost></p:NewRemoteHost>\n"
-"  <p:NewExternalPort>5002</p:NewExternalPort>\n"
-"  <p:NewProtocol>UDP</p:NewProtocol>\n"
-"  <p:NewInternalPort>4001</p:NewInternalPort>\n"
-"  <p:NewInternalClient>192.168.1.123</p:NewInternalClient>\n"
-"  <p:NewEnabled>1</p:NewEnabled>\n"
-"  <p:NewDescription>xxx</p:NewDescription>\n"
-"  <p:NewLeaseTime>0</p:NewLeaseTime>\n"
-" </p:PortMappingEntry>\n"
-" <p:PortMappingEntry>\n"
-"  <p:NewRemoteHost>202.233.2.1</p:NewRemoteHost>\n"
-"  <p:NewExternalPort>2345</p:NewExternalPort>\n"
-"  <p:NewProtocol>TCP</p:NewProtocol>\n"
-"  <p:NewInternalPort>2349</p:NewInternalPort>\n"
-"  <p:NewInternalClient>192.168.1.137</p:NewInternalClient>\n"
-"  <p:NewEnabled>1</p:NewEnabled>\n"
-"  <p:NewDescription>dooom</p:NewDescription>\n"
-"  <p:NewLeaseTime>346</p:NewLeaseTime>\n"
-" </p:PortMappingEntry>\n"
-" <p:PortMappingEntry>\n"
-"  <p:NewRemoteHost>134.231.2.11</p:NewRemoteHost>\n"
-"  <p:NewExternalPort>12345</p:NewExternalPort>\n"
-"  <p:NewProtocol>TCP</p:NewProtocol>\n"
-"  <p:NewInternalPort>12345</p:NewInternalPort>\n"
-"  <p:NewInternalClient>192.168.1.137</p:NewInternalClient>\n"
-"  <p:NewEnabled>1</p:NewEnabled>\n"
-"  <p:NewDescription>dooom A</p:NewDescription>\n"
-"  <p:NewLeaseTime>347</p:NewLeaseTime>\n"
-" </p:PortMappingEntry>\n"
-"</p:PortMappingList>";
-
-#define PORT_MAPPINGS_COUNT 3
-const struct port_mapping port_mappings[PORT_MAPPINGS_COUNT] = {
-{347, 12345, 12345, "134.231.2.11", "192.168.1.137", "TCP", "dooom A", 1},
-{346, 2345, 2349, "202.233.2.1", "192.168.1.137", "TCP", "dooom", 1},
-{0, 5002, 4001, "", "192.168.1.123", "UDP", "xxx", 1}
-};
-
-/* --- main --- */
-int main(void)
-{
-	int r;
-	r = test(test_document, sizeof(test_document) - 1,
-	         port_mappings, PORT_MAPPINGS_COUNT);
-	if(r == 0) {
-		printf("test of portlistingparse OK\n");
-		return 0;
-	} else {
-		printf("test FAILED (%d differences counted)\n", r);
-		return 1;
-	}
-}
-

+ 0 - 3
ext/miniupnpc/testreplyparse/DeletePortMapping.namevalue

@@ -1,3 +0,0 @@
-NewRemoteHost=
-NewExternalPort=123
-NewProtocol=TCP

+ 0 - 6
ext/miniupnpc/testreplyparse/DeletePortMapping.xml

@@ -1,6 +0,0 @@
-<?xml version="1.0"?>
-<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:DeletePortMapping xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1"><NewRemoteHost></NewRemoteHost><NewExternalPort>123</NewExternalPort>
-<NewProtocol>TCP</NewProtocol></u:DeletePortMapping></s:Body>
- 
-</s:Envelope>
-

+ 0 - 2
ext/miniupnpc/testreplyparse/GetExternalIPAddress.namevalue

@@ -1,2 +0,0 @@
-NewExternalIPAddress=1.2.3.4
-

+ 0 - 2
ext/miniupnpc/testreplyparse/GetExternalIPAddress.xml

@@ -1,2 +0,0 @@
-<?xml version="1.0"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:GetExternalIPAddressResponse xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1"><NewExternalIPAddress>1.2.3.4</NewExternalIPAddress></u:GetExternalIPAddressResponse></s:Body></s:Envelope>
-

+ 0 - 3
ext/miniupnpc/testreplyparse/GetSpecificPortMappingEntryReq.namevalue

@@ -1,3 +0,0 @@
-NewProtocol=UDP
-NewExternalPort=12345
-NewRemoteHost=

+ 0 - 3
ext/miniupnpc/testreplyparse/GetSpecificPortMappingEntryReq.xml

@@ -1,3 +0,0 @@
-<?xml version="1.0"?>
-<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:GetSpecificPortMappingEntry xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1"><NewRemoteHost></NewRemoteHost><NewExternalPort>12345</NewExternalPort><NewProtocol>UDP</NewProtocol></u:GetSpecificPortMappingEntry></s:Body></s:Envelope>
-

+ 0 - 5
ext/miniupnpc/testreplyparse/GetSpecificPortMappingEntryResp.namevalue

@@ -1,5 +0,0 @@
-NewInternalPort=12345
-NewInternalClient=192.168.10.110
-NewEnabled=1
-NewPortMappingDescription=libminiupnpc
-NewLeaseDuration=0

+ 0 - 2
ext/miniupnpc/testreplyparse/GetSpecificPortMappingEntryResp.xml

@@ -1,2 +0,0 @@
-<?xml version="1.0"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:GetSpecificPortMappingEntryResponse xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1"><NewInternalPort>12345</NewInternalPort><NewInternalClient>192.168.10.110</NewInternalClient><NewEnabled>1</NewEnabled><NewPortMappingDescription>libminiupnpc</NewPortMappingDescription><NewLeaseDuration>0</NewLeaseDuration></u:GetSpecificPortMappingEntryResponse></s:Body></s:Envelope>
-

+ 0 - 1
ext/miniupnpc/testreplyparse/SetDefaultConnectionService.namevalue

@@ -1 +0,0 @@
-NewDefaultConnectionService=uuid:c6c05a33-f704-48df-9910-e099b3471d81:WANConnectionDevice:1,INVALID_SERVICE_ID

+ 0 - 1
ext/miniupnpc/testreplyparse/SetDefaultConnectionService.xml

@@ -1 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?><s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><u:SetDefaultConnectionService xmlns:u="urn:schemas-upnp-org:service:Layer3Forwarding:1"><NewDefaultConnectionService>uuid:c6c05a33-f704-48df-9910-e099b3471d81:WANConnectionDevice:1,INVALID_SERVICE_ID</NewDefaultConnectionService></u:SetDefaultConnectionService></s:Body></s:Envelope>

+ 0 - 7
ext/miniupnpc/testreplyparse/readme.txt

@@ -1,7 +0,0 @@
-This directory contains files used for validation of upnpreplyparse.c code.
-
-Each .xml file to parse should give the results which are in the .namevalue
-file.
-
-A .namevalue file contain name=value lines.
-

+ 0 - 84
ext/miniupnpc/testupnpigd.py

@@ -1,84 +0,0 @@
-#! /usr/bin/python
-# $Id: testupnpigd.py,v 1.4 2008/10/11 10:27:20 nanard Exp $
-# MiniUPnP project
-# Author : Thomas Bernard
-# This Sample code is public domain.
-# website : http://miniupnp.tuxfamily.org/
-
-# import the python miniupnpc module
-import miniupnpc
-import socket
-import BaseHTTPServer
-
-# function definition
-def list_redirections():
-	i = 0
-	while True:
-		p = u.getgenericportmapping(i)
-		if p==None:
-			break
-		print i, p
-		i = i + 1
-
-#define the handler class for HTTP connections
-class handler_class(BaseHTTPServer.BaseHTTPRequestHandler):
-	def do_GET(self):
-		self.send_response(200)
-		self.end_headers()
-		self.wfile.write("OK MON GARS")
-
-# create the object
-u = miniupnpc.UPnP()
-#print 'inital(default) values :'
-#print ' discoverdelay', u.discoverdelay
-#print ' lanaddr', u.lanaddr
-#print ' multicastif', u.multicastif
-#print ' minissdpdsocket', u.minissdpdsocket
-u.discoverdelay = 200;
-
-try:
-	print 'Discovering... delay=%ums' % u.discoverdelay
-	ndevices = u.discover()
-	print ndevices, 'device(s) detected'
-
-	# select an igd
-	u.selectigd()
-	# display information about the IGD and the internet connection
-	print 'local ip address :', u.lanaddr
-	externalipaddress = u.externalipaddress()
-	print 'external ip address :', externalipaddress
-	print u.statusinfo(), u.connectiontype()
-
-	#instanciate a HTTPd object. The port is assigned by the system.
-	httpd = BaseHTTPServer.HTTPServer((u.lanaddr, 0), handler_class)
-	eport = httpd.server_port
-
-	# find a free port for the redirection
-	r = u.getspecificportmapping(eport, 'TCP')
-	while r != None and eport < 65536:
-		eport = eport + 1
-		r = u.getspecificportmapping(eport, 'TCP')
-
-	print 'trying to redirect %s port %u TCP => %s port %u TCP' % (externalipaddress, eport, u.lanaddr, httpd.server_port)
-
-	b = u.addportmapping(eport, 'TCP', u.lanaddr, httpd.server_port,
-	                    'UPnP IGD Tester port %u' % eport, '')
-	if b:
-		print 'Success. Now waiting for some HTTP request on http://%s:%u' % (externalipaddress ,eport)
-		try:
-			httpd.handle_request()
-			httpd.server_close()
-		except KeyboardInterrupt, details:
-			print "CTRL-C exception!", details
-		b = u.deleteportmapping(eport, 'TCP')
-		if b:
-			print 'Successfully deleted port mapping'
-		else:
-			print 'Failed to remove port mapping'
-	else:
-		print 'Failed'
-
-	httpd.server_close()
-
-except Exception, e:
-	print 'Exception :', e

+ 0 - 96
ext/miniupnpc/testupnpreplyparse.c

@@ -1,96 +0,0 @@
-/* $Id: testupnpreplyparse.c,v 1.4 2014/01/27 11:45:19 nanard Exp $ */
-/* MiniUPnP project
- * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
- * (c) 2006-2014 Thomas Bernard
- * This software is subject to the conditions detailed
- * in the LICENCE file provided within the distribution */
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include "upnpreplyparse.h"
-
-int
-test_parsing(const char * buf, int len, FILE * f)
-{
-	char line[1024];
-	struct NameValueParserData pdata;
-	int ok = 1;
-	ParseNameValue(buf, len, &pdata);
-	/* check result */
-	if(f != NULL)
-	{
-		while(fgets(line, sizeof(line), f))
-		{
-			char * value;
-			char * equal;
-			char * parsedvalue;
-			int l;
-			l = strlen(line);
-			while((l > 0) && ((line[l-1] == '\r') || (line[l-1] == '\n')))
-				line[--l] = '\0';
-			/* skip empty lines */
-			if(l == 0)
-				continue;
-			equal = strchr(line, '=');
-			if(equal == NULL)
-			{
-				fprintf(stderr, "Warning, line does not contain '=' : %s\n", line);
-				continue;
-			}
-			*equal = '\0';
-			value = equal + 1;
-			parsedvalue = GetValueFromNameValueList(&pdata, line);
-			if((parsedvalue == NULL) || (strcmp(parsedvalue, value) != 0))
-			{
-				fprintf(stderr, "Element <%s> : expecting value '%s', got '%s'\n",
-				        line, value, parsedvalue ? parsedvalue : "<null string>");
-				ok = 0;
-			}
-		}
-	}
-	ClearNameValueList(&pdata);
-	return ok;
-}
-
-int main(int argc, char * * argv)
-{
-	FILE * f;
-	char buffer[4096];
-	int l;
-	int ok;
-
-	if(argc<2)
-	{
-		fprintf(stderr, "Usage: %s file.xml [file.namevalues]\n", argv[0]);
-		return 1;
-	}
-	f = fopen(argv[1], "r");
-	if(!f)
-	{
-		fprintf(stderr, "Error : can not open file %s\n", argv[1]);
-		return 2;
-	}
-	l = fread(buffer, 1, sizeof(buffer)-1, f);
-	fclose(f);
-	f = NULL;
-	buffer[l] = '\0';
-	if(argc > 2)
-	{
-		f = fopen(argv[2], "r");
-		if(!f)
-		{
-			fprintf(stderr, "Error : can not open file %s\n", argv[2]);
-			return 2;
-		}
-	}
-#ifdef DEBUG
-	DisplayNameValueList(buffer, l);
-#endif
-	ok = test_parsing(buffer, l, f);
-	if(f)
-	{
-		fclose(f);
-	}
-	return ok ? 0 : 3;
-}
-

+ 0 - 14
ext/miniupnpc/testupnpreplyparse.sh

@@ -1,14 +0,0 @@
-#!/bin/sh
-
-for f in testreplyparse/*.xml ; do
-	bf="`dirname $f`/`basename $f .xml`"
-	if ./testupnpreplyparse $f $bf.namevalue ; then
-		echo "$f : passed"
-	else
-		echo "$f : FAILED"
-		exit 1
-	fi
-done
-
-exit 0
-

+ 7 - 5
ext/miniupnpc/upnpc.c

@@ -1,7 +1,7 @@
-/* $Id: upnpc.c,v 1.115 2016/10/07 09:04:01 nanard Exp $ */
+/* $Id: upnpc.c,v 1.117 2017/05/26 15:26:55 nanard Exp $ */
 /* Project : miniupnp
 /* Project : miniupnp
  * Author : Thomas Bernard
  * Author : Thomas Bernard
- * Copyright (c) 2005-2016 Thomas Bernard
+ * Copyright (c) 2005-2017 Thomas Bernard
  * This software is subject to the conditions detailed in the
  * This software is subject to the conditions detailed in the
  * LICENCE file provided in this distribution. */
  * LICENCE file provided in this distribution. */
 
 
@@ -292,9 +292,11 @@ static int SetRedirectAndTest(struct UPNPUrls * urls,
 		r = UPNP_AddPortMapping(urls->controlURL, data->first.servicetype,
 		r = UPNP_AddPortMapping(urls->controlURL, data->first.servicetype,
 					eport, iport, iaddr, description,
 					eport, iport, iaddr, description,
 					proto, 0, leaseDuration);
 					proto, 0, leaseDuration);
-		if(r!=UPNPCOMMAND_SUCCESS)
+		if(r!=UPNPCOMMAND_SUCCESS) {
 			printf("AddPortMapping(%s, %s, %s) failed with code %d (%s)\n",
 			printf("AddPortMapping(%s, %s, %s) failed with code %d (%s)\n",
 			       eport, iport, iaddr, r, strupnperror(r));
 			       eport, iport, iaddr, r, strupnperror(r));
+			return -2;
+	}
 	}
 	}
 
 
 	r = UPNP_GetSpecificPortMappingEntry(urls->controlURL,
 	r = UPNP_GetSpecificPortMappingEntry(urls->controlURL,
@@ -576,8 +578,8 @@ int main(int argc, char ** argv)
 	}
 	}
 #endif
 #endif
     printf("upnpc : miniupnpc library test client, version %s.\n", MINIUPNPC_VERSION_STRING);
     printf("upnpc : miniupnpc library test client, version %s.\n", MINIUPNPC_VERSION_STRING);
-	printf(" (c) 2005-2016 Thomas Bernard.\n");
-    printf("Go to http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/\n"
+	printf(" (c) 2005-2017 Thomas Bernard.\n");
+    printf("Go to http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/\n"
 	       "for more information.\n");
 	       "for more information.\n");
 	/* command line processing */
 	/* command line processing */
 	for(i=1; i<argc; i++)
 	for(i=1; i<argc; i++)

+ 47 - 44
ext/miniupnpc/upnpcommands.c

@@ -1,7 +1,8 @@
-/* $Id: upnpcommands.c,v 1.47 2016/03/07 12:26:48 nanard Exp $ */
-/* Project : miniupnp
+/* $Id: upnpcommands.c,v 1.48 2017/04/21 10:22:40 nanard Exp $ */
+/* vim: tabstop=4 shiftwidth=4 noexpandtab
+ * Project : miniupnp
  * Author : Thomas Bernard
  * Author : Thomas Bernard
- * Copyright (c) 2005-2015 Thomas Bernard
+ * Copyright (c) 2005-2017 Thomas Bernard
  * This software is subject to the conditions detailed in the
  * This software is subject to the conditions detailed in the
  * LICENCE file provided in this distribution.
  * LICENCE file provided in this distribution.
  * */
  * */
@@ -372,10 +373,11 @@ UPNP_AddPortMapping(const char * controlURL, const char * servicetype,
 	AddPortMappingArgs[6].val = desc?desc:"libminiupnpc";
 	AddPortMappingArgs[6].val = desc?desc:"libminiupnpc";
 	AddPortMappingArgs[7].elt = "NewLeaseDuration";
 	AddPortMappingArgs[7].elt = "NewLeaseDuration";
 	AddPortMappingArgs[7].val = leaseDuration?leaseDuration:"0";
 	AddPortMappingArgs[7].val = leaseDuration?leaseDuration:"0";
-	if(!(buffer = simpleUPnPcommand(-1, controlURL, servicetype,
-	                                "AddPortMapping", AddPortMappingArgs,
-	                                &bufsize))) {
-		free(AddPortMappingArgs);
+	buffer = simpleUPnPcommand(-1, controlURL, servicetype,
+	                           "AddPortMapping", AddPortMappingArgs,
+	                           &bufsize);
+	free(AddPortMappingArgs);
+	if(!buffer) {
 		return UPNPCOMMAND_HTTP_ERROR;
 		return UPNPCOMMAND_HTTP_ERROR;
 	}
 	}
 	/*DisplayNameValueList(buffer, bufsize);*/
 	/*DisplayNameValueList(buffer, bufsize);*/
@@ -392,7 +394,6 @@ UPNP_AddPortMapping(const char * controlURL, const char * servicetype,
 		ret = UPNPCOMMAND_SUCCESS;
 		ret = UPNPCOMMAND_SUCCESS;
 	}
 	}
 	ClearNameValueList(&pdata);
 	ClearNameValueList(&pdata);
-	free(AddPortMappingArgs);
 	return ret;
 	return ret;
 }
 }
 
 
@@ -436,10 +437,11 @@ UPNP_AddAnyPortMapping(const char * controlURL, const char * servicetype,
 	AddPortMappingArgs[6].val = desc?desc:"libminiupnpc";
 	AddPortMappingArgs[6].val = desc?desc:"libminiupnpc";
 	AddPortMappingArgs[7].elt = "NewLeaseDuration";
 	AddPortMappingArgs[7].elt = "NewLeaseDuration";
 	AddPortMappingArgs[7].val = leaseDuration?leaseDuration:"0";
 	AddPortMappingArgs[7].val = leaseDuration?leaseDuration:"0";
-	if(!(buffer = simpleUPnPcommand(-1, controlURL, servicetype,
-	                                "AddAnyPortMapping", AddPortMappingArgs,
-	                                &bufsize))) {
-		free(AddPortMappingArgs);
+	buffer = simpleUPnPcommand(-1, controlURL, servicetype,
+	                           "AddAnyPortMapping", AddPortMappingArgs,
+	                           &bufsize);
+	free(AddPortMappingArgs);
+	if(!buffer) {
 		return UPNPCOMMAND_HTTP_ERROR;
 		return UPNPCOMMAND_HTTP_ERROR;
 	}
 	}
 	ParseNameValue(buffer, bufsize, &pdata);
 	ParseNameValue(buffer, bufsize, &pdata);
@@ -461,7 +463,6 @@ UPNP_AddAnyPortMapping(const char * controlURL, const char * servicetype,
 		}
 		}
 	}
 	}
 	ClearNameValueList(&pdata);
 	ClearNameValueList(&pdata);
-	free(AddPortMappingArgs);
 	return ret;
 	return ret;
 }
 }
 
 
@@ -490,10 +491,11 @@ UPNP_DeletePortMapping(const char * controlURL, const char * servicetype,
 	DeletePortMappingArgs[1].val = extPort;
 	DeletePortMappingArgs[1].val = extPort;
 	DeletePortMappingArgs[2].elt = "NewProtocol";
 	DeletePortMappingArgs[2].elt = "NewProtocol";
 	DeletePortMappingArgs[2].val = proto;
 	DeletePortMappingArgs[2].val = proto;
-	if(!(buffer = simpleUPnPcommand(-1, controlURL, servicetype,
-	                               "DeletePortMapping",
-	                               DeletePortMappingArgs, &bufsize))) {
-		free(DeletePortMappingArgs);
+	buffer = simpleUPnPcommand(-1, controlURL, servicetype,
+	                          "DeletePortMapping",
+	                          DeletePortMappingArgs, &bufsize);
+	free(DeletePortMappingArgs);
+	if(!buffer) {
 		return UPNPCOMMAND_HTTP_ERROR;
 		return UPNPCOMMAND_HTTP_ERROR;
 	}
 	}
 	/*DisplayNameValueList(buffer, bufsize);*/
 	/*DisplayNameValueList(buffer, bufsize);*/
@@ -507,7 +509,6 @@ UPNP_DeletePortMapping(const char * controlURL, const char * servicetype,
 		ret = UPNPCOMMAND_SUCCESS;
 		ret = UPNPCOMMAND_SUCCESS;
 	}
 	}
 	ClearNameValueList(&pdata);
 	ClearNameValueList(&pdata);
-	free(DeletePortMappingArgs);
 	return ret;
 	return ret;
 }
 }
 
 
@@ -539,10 +540,11 @@ UPNP_DeletePortMappingRange(const char * controlURL, const char * servicetype,
 	DeletePortMappingArgs[3].elt = "NewManage";
 	DeletePortMappingArgs[3].elt = "NewManage";
 	DeletePortMappingArgs[3].val = manage;
 	DeletePortMappingArgs[3].val = manage;
 
 
-	if(!(buffer = simpleUPnPcommand(-1, controlURL, servicetype,
-	                                "DeletePortMappingRange",
-	                                DeletePortMappingArgs, &bufsize))) {
-		free(DeletePortMappingArgs);
+	buffer = simpleUPnPcommand(-1, controlURL, servicetype,
+	                           "DeletePortMappingRange",
+	                           DeletePortMappingArgs, &bufsize);
+	free(DeletePortMappingArgs);
+	if(!buffer) {
 		return UPNPCOMMAND_HTTP_ERROR;
 		return UPNPCOMMAND_HTTP_ERROR;
 	}
 	}
 	ParseNameValue(buffer, bufsize, &pdata);
 	ParseNameValue(buffer, bufsize, &pdata);
@@ -555,7 +557,6 @@ UPNP_DeletePortMappingRange(const char * controlURL, const char * servicetype,
 		ret = UPNPCOMMAND_SUCCESS;
 		ret = UPNPCOMMAND_SUCCESS;
 	}
 	}
 	ClearNameValueList(&pdata);
 	ClearNameValueList(&pdata);
-	free(DeletePortMappingArgs);
 	return ret;
 	return ret;
 }
 }
 
 
@@ -587,10 +588,11 @@ UPNP_GetGenericPortMappingEntry(const char * controlURL,
 		return UPNPCOMMAND_MEM_ALLOC_ERROR;
 		return UPNPCOMMAND_MEM_ALLOC_ERROR;
 	GetPortMappingArgs[0].elt = "NewPortMappingIndex";
 	GetPortMappingArgs[0].elt = "NewPortMappingIndex";
 	GetPortMappingArgs[0].val = index;
 	GetPortMappingArgs[0].val = index;
-	if(!(buffer = simpleUPnPcommand(-1, controlURL, servicetype,
-	                               "GetGenericPortMappingEntry",
-	                               GetPortMappingArgs, &bufsize))) {
-		free(GetPortMappingArgs);
+	buffer = simpleUPnPcommand(-1, controlURL, servicetype,
+	                           "GetGenericPortMappingEntry",
+	                           GetPortMappingArgs, &bufsize);
+	free(GetPortMappingArgs);
+	if(!buffer) {
 		return UPNPCOMMAND_HTTP_ERROR;
 		return UPNPCOMMAND_HTTP_ERROR;
 	}
 	}
 	ParseNameValue(buffer, bufsize, &pdata);
 	ParseNameValue(buffer, bufsize, &pdata);
@@ -652,7 +654,6 @@ UPNP_GetGenericPortMappingEntry(const char * controlURL,
 		sscanf(p, "%d", &r);
 		sscanf(p, "%d", &r);
 	}
 	}
 	ClearNameValueList(&pdata);
 	ClearNameValueList(&pdata);
-	free(GetPortMappingArgs);
 	return r;
 	return r;
 }
 }
 
 
@@ -728,10 +729,11 @@ UPNP_GetSpecificPortMappingEntry(const char * controlURL,
 	GetPortMappingArgs[1].val = extPort;
 	GetPortMappingArgs[1].val = extPort;
 	GetPortMappingArgs[2].elt = "NewProtocol";
 	GetPortMappingArgs[2].elt = "NewProtocol";
 	GetPortMappingArgs[2].val = proto;
 	GetPortMappingArgs[2].val = proto;
-	if(!(buffer = simpleUPnPcommand(-1, controlURL, servicetype,
-	                                "GetSpecificPortMappingEntry",
-	                                GetPortMappingArgs, &bufsize))) {
-		free(GetPortMappingArgs);
+	buffer = simpleUPnPcommand(-1, controlURL, servicetype,
+	                           "GetSpecificPortMappingEntry",
+	                           GetPortMappingArgs, &bufsize);
+	free(GetPortMappingArgs);
+	if(!buffer) {
 		return UPNPCOMMAND_HTTP_ERROR;
 		return UPNPCOMMAND_HTTP_ERROR;
 	}
 	}
 	/*DisplayNameValueList(buffer, bufsize);*/
 	/*DisplayNameValueList(buffer, bufsize);*/
@@ -779,7 +781,6 @@ UPNP_GetSpecificPortMappingEntry(const char * controlURL,
 	}
 	}
 
 
 	ClearNameValueList(&pdata);
 	ClearNameValueList(&pdata);
-	free(GetPortMappingArgs);
 	return ret;
 	return ret;
 }
 }
 
 
@@ -824,13 +825,13 @@ UPNP_GetListOfPortMappings(const char * controlURL,
 	GetListOfPortMappingsArgs[4].elt = "NewNumberOfPorts";
 	GetListOfPortMappingsArgs[4].elt = "NewNumberOfPorts";
 	GetListOfPortMappingsArgs[4].val = numberOfPorts?numberOfPorts:"1000";
 	GetListOfPortMappingsArgs[4].val = numberOfPorts?numberOfPorts:"1000";
 
 
-	if(!(buffer = simpleUPnPcommand(-1, controlURL, servicetype,
-	                                "GetListOfPortMappings",
-	                                GetListOfPortMappingsArgs, &bufsize))) {
-		free(GetListOfPortMappingsArgs);
+	buffer = simpleUPnPcommand(-1, controlURL, servicetype,
+	                           "GetListOfPortMappings",
+	                           GetListOfPortMappingsArgs, &bufsize);
+	free(GetListOfPortMappingsArgs);
+	if(!buffer) {
 		return UPNPCOMMAND_HTTP_ERROR;
 		return UPNPCOMMAND_HTTP_ERROR;
 	}
 	}
-	free(GetListOfPortMappingsArgs);
 
 
 	/*DisplayNameValueList(buffer, bufsize);*/
 	/*DisplayNameValueList(buffer, bufsize);*/
 	ParseNameValue(buffer, bufsize, &pdata);
 	ParseNameValue(buffer, bufsize, &pdata);
@@ -954,6 +955,7 @@ UPNP_GetOutboundPinholeTimeout(const char * controlURL, const char * servicetype
 	GetOutboundPinholeTimeoutArgs[4].val = intClient;
 	GetOutboundPinholeTimeoutArgs[4].val = intClient;
 	buffer = simpleUPnPcommand(-1, controlURL, servicetype,
 	buffer = simpleUPnPcommand(-1, controlURL, servicetype,
 	                           "GetOutboundPinholeTimeout", GetOutboundPinholeTimeoutArgs, &bufsize);
 	                           "GetOutboundPinholeTimeout", GetOutboundPinholeTimeoutArgs, &bufsize);
+	free(GetOutboundPinholeTimeoutArgs);
 	if(!buffer)
 	if(!buffer)
 		return UPNPCOMMAND_HTTP_ERROR;
 		return UPNPCOMMAND_HTTP_ERROR;
 	ParseNameValue(buffer, bufsize, &pdata);
 	ParseNameValue(buffer, bufsize, &pdata);
@@ -972,7 +974,6 @@ UPNP_GetOutboundPinholeTimeout(const char * controlURL, const char * servicetype
 			*opTimeout = my_atoui(p);
 			*opTimeout = my_atoui(p);
 	}
 	}
 	ClearNameValueList(&pdata);
 	ClearNameValueList(&pdata);
-	free(GetOutboundPinholeTimeoutArgs);
 	return ret;
 	return ret;
 }
 }
 
 
@@ -1031,6 +1032,7 @@ UPNP_AddPinhole(const char * controlURL, const char * servicetype,
 	AddPinholeArgs[5].val = leaseTime;
 	AddPinholeArgs[5].val = leaseTime;
 	buffer = simpleUPnPcommand(-1, controlURL, servicetype,
 	buffer = simpleUPnPcommand(-1, controlURL, servicetype,
 	                           "AddPinhole", AddPinholeArgs, &bufsize);
 	                           "AddPinhole", AddPinholeArgs, &bufsize);
+	free(AddPinholeArgs);
 	if(!buffer)
 	if(!buffer)
 		return UPNPCOMMAND_HTTP_ERROR;
 		return UPNPCOMMAND_HTTP_ERROR;
 	ParseNameValue(buffer, bufsize, &pdata);
 	ParseNameValue(buffer, bufsize, &pdata);
@@ -1053,7 +1055,6 @@ UPNP_AddPinhole(const char * controlURL, const char * servicetype,
 		ret = UPNPCOMMAND_SUCCESS;
 		ret = UPNPCOMMAND_SUCCESS;
 	}
 	}
 	ClearNameValueList(&pdata);
 	ClearNameValueList(&pdata);
-	free(AddPinholeArgs);
 	return ret;
 	return ret;
 }
 }
 
 
@@ -1081,6 +1082,7 @@ UPNP_UpdatePinhole(const char * controlURL, const char * servicetype,
 	UpdatePinholeArgs[1].val = leaseTime;
 	UpdatePinholeArgs[1].val = leaseTime;
 	buffer = simpleUPnPcommand(-1, controlURL, servicetype,
 	buffer = simpleUPnPcommand(-1, controlURL, servicetype,
 	                           "UpdatePinhole", UpdatePinholeArgs, &bufsize);
 	                           "UpdatePinhole", UpdatePinholeArgs, &bufsize);
+	free(UpdatePinholeArgs);
 	if(!buffer)
 	if(!buffer)
 		return UPNPCOMMAND_HTTP_ERROR;
 		return UPNPCOMMAND_HTTP_ERROR;
 	ParseNameValue(buffer, bufsize, &pdata);
 	ParseNameValue(buffer, bufsize, &pdata);
@@ -1097,7 +1099,6 @@ UPNP_UpdatePinhole(const char * controlURL, const char * servicetype,
 		ret = UPNPCOMMAND_SUCCESS;
 		ret = UPNPCOMMAND_SUCCESS;
 	}
 	}
 	ClearNameValueList(&pdata);
 	ClearNameValueList(&pdata);
-	free(UpdatePinholeArgs);
 	return ret;
 	return ret;
 }
 }
 
 
@@ -1122,6 +1123,7 @@ UPNP_DeletePinhole(const char * controlURL, const char * servicetype, const char
 	DeletePinholeArgs[0].val = uniqueID;
 	DeletePinholeArgs[0].val = uniqueID;
 	buffer = simpleUPnPcommand(-1, controlURL, servicetype,
 	buffer = simpleUPnPcommand(-1, controlURL, servicetype,
 	                           "DeletePinhole", DeletePinholeArgs, &bufsize);
 	                           "DeletePinhole", DeletePinholeArgs, &bufsize);
+	free(DeletePinholeArgs);
 	if(!buffer)
 	if(!buffer)
 		return UPNPCOMMAND_HTTP_ERROR;
 		return UPNPCOMMAND_HTTP_ERROR;
 	/*DisplayNameValueList(buffer, bufsize);*/
 	/*DisplayNameValueList(buffer, bufsize);*/
@@ -1138,7 +1140,6 @@ UPNP_DeletePinhole(const char * controlURL, const char * servicetype, const char
 		ret = UPNPCOMMAND_SUCCESS;
 		ret = UPNPCOMMAND_SUCCESS;
 	}
 	}
 	ClearNameValueList(&pdata);
 	ClearNameValueList(&pdata);
-	free(DeletePinholeArgs);
 	return ret;
 	return ret;
 }
 }
 
 
@@ -1163,8 +1164,11 @@ UPNP_CheckPinholeWorking(const char * controlURL, const char * servicetype,
 	CheckPinholeWorkingArgs[0].val = uniqueID;
 	CheckPinholeWorkingArgs[0].val = uniqueID;
 	buffer = simpleUPnPcommand(-1, controlURL, servicetype,
 	buffer = simpleUPnPcommand(-1, controlURL, servicetype,
 	                           "CheckPinholeWorking", CheckPinholeWorkingArgs, &bufsize);
 	                           "CheckPinholeWorking", CheckPinholeWorkingArgs, &bufsize);
+	free(CheckPinholeWorkingArgs);
 	if(!buffer)
 	if(!buffer)
+	{
 		return UPNPCOMMAND_HTTP_ERROR;
 		return UPNPCOMMAND_HTTP_ERROR;
+	}
 	ParseNameValue(buffer, bufsize, &pdata);
 	ParseNameValue(buffer, bufsize, &pdata);
 	free(buffer); buffer = NULL;
 	free(buffer); buffer = NULL;
 
 
@@ -1185,7 +1189,6 @@ UPNP_CheckPinholeWorking(const char * controlURL, const char * servicetype,
 	}
 	}
 
 
 	ClearNameValueList(&pdata);
 	ClearNameValueList(&pdata);
-	free(CheckPinholeWorkingArgs);
 	return ret;
 	return ret;
 }
 }
 
 
@@ -1210,6 +1213,7 @@ UPNP_GetPinholePackets(const char * controlURL, const char * servicetype,
 	GetPinholePacketsArgs[0].val = uniqueID;
 	GetPinholePacketsArgs[0].val = uniqueID;
 	buffer = simpleUPnPcommand(-1, controlURL, servicetype,
 	buffer = simpleUPnPcommand(-1, controlURL, servicetype,
 	                           "GetPinholePackets", GetPinholePacketsArgs, &bufsize);
 	                           "GetPinholePackets", GetPinholePacketsArgs, &bufsize);
+	free(GetPinholePacketsArgs);
 	if(!buffer)
 	if(!buffer)
 		return UPNPCOMMAND_HTTP_ERROR;
 		return UPNPCOMMAND_HTTP_ERROR;
 	ParseNameValue(buffer, bufsize, &pdata);
 	ParseNameValue(buffer, bufsize, &pdata);
@@ -1230,7 +1234,6 @@ UPNP_GetPinholePackets(const char * controlURL, const char * servicetype,
 	}
 	}
 
 
 	ClearNameValueList(&pdata);
 	ClearNameValueList(&pdata);
-	free(GetPinholePacketsArgs);
 	return ret;
 	return ret;
 }
 }
 
 

+ 7 - 8
ext/miniupnpc/upnpreplyparse.c

@@ -1,7 +1,8 @@
-/* $Id: upnpreplyparse.c,v 1.19 2015/07/15 10:29:11 nanard Exp $ */
-/* MiniUPnP project
+/* $Id: upnpreplyparse.c,v 1.20 2017/12/12 11:26:25 nanard Exp $ */
+/* vim: tabstop=4 shiftwidth=4 noexpandtab
+ * MiniUPnP project
  * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
  * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
- * (c) 2006-2015 Thomas Bernard
+ * (c) 2006-2017 Thomas Bernard
  * This software is subject to the conditions detailed
  * This software is subject to the conditions detailed
  * in the LICENCE file provided within the distribution */
  * in the LICENCE file provided within the distribution */
 
 
@@ -26,12 +27,12 @@ NameValueParserStartElt(void * d, const char * name, int l)
 }
 }
 
 
 static void
 static void
-NameValueParserEndElt(void * d, const char * name, int l)
+NameValueParserEndElt(void * d, const char * name, int namelen)
 {
 {
     struct NameValueParserData * data = (struct NameValueParserData *)d;
     struct NameValueParserData * data = (struct NameValueParserData *)d;
     struct NameValue * nv;
     struct NameValue * nv;
 	(void)name;
 	(void)name;
-	(void)l;
+	(void)namelen;
 	if(!data->topelt)
 	if(!data->topelt)
 		return;
 		return;
 	if(strcmp(data->curelt, "NewPortListing") != 0)
 	if(strcmp(data->curelt, "NewPortListing") != 0)
@@ -104,9 +105,7 @@ ParseNameValue(const char * buffer, int bufsize,
                struct NameValueParserData * data)
                struct NameValueParserData * data)
 {
 {
 	struct xmlparser parser;
 	struct xmlparser parser;
-	data->l_head = NULL;
-	data->portListing = NULL;
-	data->portListingLength = 0;
+	memset(data, 0, sizeof(struct NameValueParserData));
 	/* init xmlparser object */
 	/* init xmlparser object */
 	parser.xmlstart = buffer;
 	parser.xmlstart = buffer;
 	parser.xmlsize = bufsize;
 	parser.xmlsize = bufsize;