From f8ea720ba9557923a961af19cc9d5385eacc125a Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Wed, 22 Dec 2010 16:10:14 +0000 Subject: [PATCH] update miniupnp to 1.4.20101221 --- third-party/miniupnp/Changelog.txt | 9 ++- third-party/miniupnp/connecthostport.c | 6 +- third-party/miniupnp/igd_desc_parse.c | 4 +- third-party/miniupnp/minisoap.c | 8 ++- third-party/miniupnp/miniupnpc.c | 27 +++++---- third-party/miniupnp/miniwget.c | 79 ++++++++++++++------------ 6 files changed, 80 insertions(+), 53 deletions(-) diff --git a/third-party/miniupnp/Changelog.txt b/third-party/miniupnp/Changelog.txt index 78e0dec35..88498314f 100644 --- a/third-party/miniupnp/Changelog.txt +++ b/third-party/miniupnp/Changelog.txt @@ -1,9 +1,16 @@ -$Id: Changelog.txt,v 1.122 2010/12/09 16:11:31 nanard Exp $ +$Id: Changelog.txt,v 1.125 2010/12/21 16:13:13 nanard Exp $ miniUPnP client Changelog. +2010/12/21: + use NO_GETADDRINFO macro to disable the use of getaddrinfo/freeaddrinfo + +2010/12/11: + Improvements on getHTTPResponse() code. + 2010/12/09: new code for miniwget that handle Chunked transfer encoding using getHTTPResponse() in SOAP call code + Adding MANIFEST.in for 'python setup.py bdist_rpm' 2010/11/25: changes to minissdpc.c to compile under Win32. diff --git a/third-party/miniupnp/connecthostport.c b/third-party/miniupnp/connecthostport.c index e52eed09c..5e5da3af7 100644 --- a/third-party/miniupnp/connecthostport.c +++ b/third-party/miniupnp/connecthostport.c @@ -1,4 +1,4 @@ -/* $Id: connecthostport.c,v 1.2 2010/04/05 00:08:15 nanard Exp $ */ +/* $Id: connecthostport.c,v 1.3 2010/12/21 16:13:14 nanard Exp $ */ /* Project : miniupnp * Author : Thomas Bernard * Copyright (c) 2010 Thomas Bernard @@ -7,7 +7,9 @@ /* use getaddrinfo() or gethostbyname() * uncomment the following line in order to use gethostbyname() */ -/* #define USE_GETHOSTBYNAME */ +#ifdef NO_GETADDRINFO +#define USE_GETHOSTBYNAME +#endif #include #include diff --git a/third-party/miniupnp/igd_desc_parse.c b/third-party/miniupnp/igd_desc_parse.c index 7440e9f5b..8df6950e1 100644 --- a/third-party/miniupnp/igd_desc_parse.c +++ b/third-party/miniupnp/igd_desc_parse.c @@ -1,4 +1,4 @@ -/* $Id: igd_desc_parse.c,v 1.10 2010/04/05 20:36:59 nanard Exp $ */ +/* $Id: igd_desc_parse.c,v 1.11 2010/12/11 17:56:51 nanard Exp $ */ /* Project : miniupnp * http://miniupnp.free.fr/ * Author : Thomas Bernard @@ -97,7 +97,7 @@ void printIGD(struct IGDdatas * d) printf(" controlURL = '%s'\n", d->CIF.controlurl); printf(" eventSubURL = '%s'\n", d->CIF.eventsuburl); printf(" SCPDURL = '%s'\n", d->CIF.scpdurl); - printf("WAN Connection Device (IP or PPP Connection):\n"); + printf("primary WAN Connection Device (IP or PPP Connection):\n"); /*printf(" deviceType = '%s'\n", d->first.devicetype);*/ printf(" servicetype = '%s'\n", d->first.servicetype); printf(" controlURL = '%s'\n", d->first.controlurl); diff --git a/third-party/miniupnp/minisoap.c b/third-party/miniupnp/minisoap.c index 9afacb787..a834c5e2a 100644 --- a/third-party/miniupnp/minisoap.c +++ b/third-party/miniupnp/minisoap.c @@ -1,4 +1,4 @@ -/* $Id: minisoap.c,v 1.19 2010/04/12 20:39:41 nanard Exp $ */ +/* $Id: minisoap.c,v 1.20 2010/12/11 17:56:51 nanard Exp $ */ /* Project : miniupnp * Author : Thomas Bernard * Copyright (c) 2005-2009 Thomas Bernard @@ -106,8 +106,12 @@ int soapPostSubmit(int fd, "\r\n", url, httpversion, host, portstr, bodysize, action); #ifdef DEBUG - printf("SOAP request : headersize=%d bodysize=%d\n", + /*printf("SOAP request : headersize=%d bodysize=%d\n", headerssize, bodysize); + */ + printf("SOAP request : POST %s HTTP/%s - Host: %s%s\n", + url, httpversion, host, portstr); + printf("SOAPAction: \"%s\" - Content-Length: %d\n", action, bodysize); /*printf("%s", headerbuf);*/ #endif return httpWrite(fd, body, bodysize, headerbuf, headerssize); diff --git a/third-party/miniupnp/miniupnpc.c b/third-party/miniupnp/miniupnpc.c index 961f390f5..d91591c2c 100644 --- a/third-party/miniupnp/miniupnpc.c +++ b/third-party/miniupnp/miniupnpc.c @@ -1,4 +1,4 @@ -/* $Id: miniupnpc.c,v 1.83 2010/12/09 16:11:32 nanard Exp $ */ +/* $Id: miniupnpc.c,v 1.85 2010/12/21 16:13:14 nanard Exp $ */ /* Project : miniupnp * Author : Thomas BERNARD * copyright (c) 2005-2010 Thomas Bernard @@ -298,6 +298,9 @@ static int simpleUPnPcommand2(int s, const char * url, const char * service, buf = getHTTPResponse(s, &n); if(n > 0 && buf) { +#ifdef DEBUG + printf("SOAP Response :\n%.*s\n", n, buf); +#endif if(*bufsize > n) { memcpy(buffer, buf, n); @@ -438,8 +441,12 @@ LIBSPEC struct UPNPDev * upnpDiscover(int delay, const char * multicastif, int n; struct sockaddr sockudp_r; unsigned int mx; +#ifdef NO_GETADDRINFO + struct sockaddr_in sockudp_w; +#else int rv; struct addrinfo hints, *servinfo, *p; +#endif #ifdef WIN32 MIB_IPFORWARDROW ip_forward; #endif @@ -484,13 +491,6 @@ LIBSPEC struct UPNPDev * upnpDiscover(int delay, const char * multicastif, p->sin_port = htons(PORT); p->sin_addr.s_addr = INADDR_ANY; } -#if 0 - /* emission */ - memset(&sockudp_w, 0, sizeof(struct sockaddr_in)); - sockudp_w.sin_family = AF_INET; - sockudp_w.sin_port = htons(PORT); - sockudp_w.sin_addr.s_addr = inet_addr(UPNP_MCAST_ADDR); -#endif #ifdef WIN32 /* This code could help us to use the right Network interface for * SSDP multicast traffic */ @@ -593,7 +593,13 @@ LIBSPEC struct UPNPDev * upnpDiscover(int delay, const char * multicastif, n = snprintf(bufr, sizeof(bufr), MSearchMsgFmt, deviceList[deviceIndex++], mx); /*printf("Sending %s", bufr);*/ -#if 0 +#ifdef NO_GETADDRINFO + /* the following code is not using getaddrinfo */ + /* emission */ + memset(&sockudp_w, 0, sizeof(struct sockaddr_in)); + sockudp_w.sin_family = AF_INET; + sockudp_w.sin_port = htons(PORT); + sockudp_w.sin_addr.s_addr = inet_addr(UPNP_MCAST_ADDR); n = sendto(sudp, bufr, n, 0, (struct sockaddr *)&sockudp_w, sizeof(struct sockaddr_in)); if (n < 0) { @@ -601,7 +607,7 @@ LIBSPEC struct UPNPDev * upnpDiscover(int delay, const char * multicastif, closesocket(sudp); return devlist; } -#endif +#else /* #ifdef NO_GETADDRINFO */ memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_UNSPEC; // AF_INET6 or AF_INET hints.ai_socktype = SOCK_DGRAM; @@ -626,6 +632,7 @@ LIBSPEC struct UPNPDev * upnpDiscover(int delay, const char * multicastif, closesocket(sudp); return devlist; } +#endif /* #ifdef NO_GETADDRINFO */ } /* Waiting for SSDP REPLY packet to M-SEARCH */ n = ReceiveData(sudp, bufr, sizeof(bufr), delay); diff --git a/third-party/miniupnp/miniwget.c b/third-party/miniupnp/miniwget.c index f436358eb..89afe2e52 100644 --- a/third-party/miniupnp/miniwget.c +++ b/third-party/miniupnp/miniwget.c @@ -1,4 +1,4 @@ -/* $Id: miniwget.c,v 1.38 2010/12/09 15:54:25 nanard Exp $ */ +/* $Id: miniwget.c,v 1.41 2010/12/12 23:52:02 nanard Exp $ */ /* Project : miniupnp * Author : Thomas Bernard * Copyright (c) 2005-2010 Thomas Bernard @@ -18,6 +18,11 @@ #define MIN(x,y) (((x)<(y))?(x):(y)) #define snprintf _snprintf #define socklen_t int +#if defined(_MSC_VER) && (_MSC_VER >= 1400) +#define strncasecmp _memicmp +#else /* defined(_MSC_VER) && (_MSC_VER >= 1400) */ +#define strncasecmp memicmp +#endif /* defined(_MSC_VER) && (_MSC_VER >= 1400) */ #else /* #ifdef WIN32 */ #include #include @@ -55,6 +60,7 @@ getHTTPResponse(int s, int * size) int chunked = 0; int content_length = -1; unsigned int chunksize = 0; + unsigned int bytestocopy = 0; /* buffers : */ char * header_buf; int header_buf_len = 2048; @@ -129,43 +135,44 @@ getHTTPResponse(int s, int * size) { if(chunked) { - while(i= '0' && header_buf[i] <= '9') - chunksize = (chunksize << 4) + (header_buf[i] - '0'); - else - chunksize = (chunksize << 4) + ((header_buf[i] | 32) - 'a' + 10); - i++; - } - /* discarding chunk-extension */ - while(i < header_buf_used && header_buf[i] != '\r') i++; - if(i < header_buf_used && header_buf[i] == '\r') i++; - if(i < header_buf_used && header_buf[i] == '\n') i++; + while(i= '0' && header_buf[i] <= '9') + chunksize = (chunksize << 4) + (header_buf[i] - '0'); + else + chunksize = (chunksize << 4) + ((header_buf[i] | 32) - 'a' + 10); + i++; + } + /* discarding chunk-extension */ + while(i < header_buf_used && header_buf[i] != '\r') i++; + if(i < header_buf_used && header_buf[i] == '\r') i++; + if(i < header_buf_used && header_buf[i] == '\n') i++; #ifdef DEBUG - printf("chunksize = %u (%x)\n", chunksize, chunksize); + printf("chunksize = %u (%x)\n", chunksize, chunksize); #endif - if(chunksize == 0) - { + if(chunksize == 0) + { #ifdef DEBUG - printf("end of stream !\n"); + printf("end of HTTP content !\n"); #endif - goto end_of_stream; - } - if(header_buf_used - i <= chunksize) - { - if(content_buf_len < header_buf_used - i) + goto end_of_stream; + } + bytestocopy = ((int)chunksize < header_buf_used - i)?chunksize:(header_buf_used - i); +#ifdef DEBUG + printf("chunksize=%u bytestocopy=%u (i=%d header_buf_used=%d)\n", + chunksize, bytestocopy, i, header_buf_used); +#endif + if(content_buf_len < (int)(content_buf_used + bytestocopy)) { - content_buf = realloc(content_buf, header_buf_used - i); - content_buf_len = header_buf_used - i; + content_buf = realloc(content_buf, content_buf_used + bytestocopy); + content_buf_len = content_buf_used + bytestocopy; } - memcpy(content_buf, header_buf + i, header_buf_used - i); - content_buf_used = header_buf_used - i; - chunksize -= (header_buf_used - i); - i = header_buf_used; - } - else - { - printf("arg ! chunksize < (header_buf_used - i)\n"); + memcpy(content_buf + content_buf_used, header_buf + i, bytestocopy); + content_buf_used += bytestocopy; + chunksize -= bytestocopy; + i += bytestocopy; } } else @@ -177,6 +184,7 @@ getHTTPResponse(int s, int * size) } memcpy(content_buf, header_buf + i, header_buf_used - i); content_buf_used = header_buf_used - i; + i = header_buf_used; } } } @@ -188,7 +196,6 @@ getHTTPResponse(int s, int * size) if(chunked) { int i = 0; - unsigned bytestocopy; while(i < n) { if(chunksize == 0) @@ -213,14 +220,14 @@ getHTTPResponse(int s, int * size) if(chunksize == 0) { #ifdef DEBUG - printf("end of stream - %d %d\n", i, n); + printf("end of HTTP content - %d %d\n", i, n); /*printf("'%.*s'\n", n-i, buf+i);*/ #endif goto end_of_stream; } } - bytestocopy = (chunksize < n - i)?chunksize:(n - i); - if(content_buf_used + bytestocopy > content_buf_len) + bytestocopy = ((int)chunksize < n - i)?chunksize:(n - i); + if((int)(content_buf_used + bytestocopy) > content_buf_len) { content_buf = (char *)realloc((void *)content_buf, content_buf_used + bytestocopy); @@ -247,7 +254,7 @@ getHTTPResponse(int s, int * size) if(content_length > 0 && content_buf_used >= content_length) { #ifdef DEBUG - printf("termine!\n"); + printf("End of HTTP content\n"); #endif break; } -- 2.40.0