From 77ec5c12f29e1d21cf5d1cdbfa17905717c24a42 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 18 Aug 2009 00:56:12 +0000 Subject: [PATCH] (trunk third-party) update miniupnpc to the Aug 7 2009 snapshot --- third-party/miniupnp/Changelog.txt | 11 ++++- third-party/miniupnp/miniupnpc.c | 68 ++++++++++++++++++++++---- third-party/miniupnp/miniwget.c | 77 +++++++++++++++++++++++++----- third-party/miniupnp/minixml.c | 4 +- 4 files changed, 135 insertions(+), 25 deletions(-) diff --git a/third-party/miniupnp/Changelog.txt b/third-party/miniupnp/Changelog.txt index f5dab35c1..ce1280e20 100644 --- a/third-party/miniupnp/Changelog.txt +++ b/third-party/miniupnp/Changelog.txt @@ -1,6 +1,15 @@ -$Id: Changelog.txt,v 1.86 2009/07/29 08:44:29 nanard Exp $ +$Id: Changelog.txt,v 1.90 2009/08/07 08:42:18 nanard Exp $ miniUPnP client Changelog. +2009/08/07: + Set socket timeout for connect() + Some cleanup in miniwget.c + +2009/08/04: + remove multiple redirections with -d in upnpc.c + Print textual error code in upnpc.c + Ignore EINTR during the connect() and poll() calls. + 2009/07/29: fix in updateminiupnpcstrings.sh if OS name contains "/" Sending a correct value for MX: field in SSDP request diff --git a/third-party/miniupnp/miniupnpc.c b/third-party/miniupnp/miniupnpc.c index d5d8fa860..689bf01fb 100644 --- a/third-party/miniupnp/miniupnpc.c +++ b/third-party/miniupnp/miniupnpc.c @@ -1,11 +1,23 @@ -/* $Id: miniupnpc.c,v 1.59 2009/07/29 08:44:29 nanard Exp $ */ +/* $Id: miniupnpc.c,v 1.63 2009/08/07 14:44:50 nanard Exp $ */ /* Project : miniupnp * Author : Thomas BERNARD - * copyright (c) 2005-2007 Thomas Bernard + * copyright (c) 2005-2009 Thomas Bernard * This software is subjet to the conditions detailed in the * provided LICENCE file. */ -#include +#define __EXTENSIONS__ 1 +#ifndef MACOSX +#if !defined(_XOPEN_SOURCE) && !defined(__OpenBSD__) && !defined(__NetBSD__) +#ifndef __cplusplus +#define _XOPEN_SOURCE 600 +#endif +#endif +#ifndef __BSD_VISIBLE +#define __BSD_VISIBLE 1 +#endif +#endif + #include +#include #include #ifdef WIN32 /* Win32 Specific includes and defines */ @@ -29,7 +41,13 @@ #include #include #include +#include +#include #define closesocket close +#define MINIUPNPC_IGNORE_EINTR +#endif +#ifdef MINIUPNPC_SET_SOCKET_TIMEOUT +#include #endif #include "miniupnpc.h" #include "minissdpc.h" @@ -149,6 +167,9 @@ int simpleUPnPcommand(int s, const char * url, const char * service, int buffree; int n; int contentlen, headerlen; /* for the response */ +#ifdef MINIUPNPC_SET_SOCKET_TIMEOUT + struct timeval timeout; +#endif snprintf(soapact, sizeof(soapact), "%s#%s", service, action); if(args==NULL) { @@ -224,11 +245,33 @@ int simpleUPnPcommand(int s, const char * url, const char * service, *bufsize = 0; return -1; } +#ifdef MINIUPNPC_SET_SOCKET_TIMEOUT + /* setting a 3 seconds timeout for the connect() call */ + timeout.tv_sec = 3; + timeout.tv_usec = 0; + if(setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(struct timeval)) < 0) + { + PRINT_SOCKET_ERROR("setsockopt"); + } + timeout.tv_sec = 3; + timeout.tv_usec = 0; + if(setsockopt(s, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(struct timeval)) < 0) + { + PRINT_SOCKET_ERROR("setsockopt"); + } +#endif dest.sin_family = AF_INET; dest.sin_port = htons(port); dest.sin_addr.s_addr = inet_addr(hostname); - if(connect(s, (struct sockaddr *)&dest, sizeof(struct sockaddr))<0) - { +#ifdef MINIUPNPC_IGNORE_EINTR + do { +#endif + n = connect(s, (struct sockaddr *)&dest, sizeof(struct sockaddr)); +#ifdef MINIUPNPC_IGNORE_EINTR + } while(n < 0 && errno == EINTR); +#endif + if(n < 0) + { PRINT_SOCKET_ERROR("connect"); closesocket(s); *bufsize = 0; @@ -590,9 +633,15 @@ int ReceiveData(int socket, char * data, int length, int timeout) int n; #ifndef WIN32 struct pollfd fds[1]; /* for the poll */ - fds[0].fd = socket; - fds[0].events = POLLIN; - n = poll(fds, 1, timeout); +#ifdef MINIUPNPC_IGNORE_EINTR + do { +#endif + fds[0].fd = socket; + fds[0].events = POLLIN; + n = poll(fds, 1, timeout); +#ifdef MINIUPNPC_IGNORE_EINTR + } while(n < 0 && errno == EINTR); +#endif if(n < 0) { PRINT_SOCKET_ERROR("poll"); @@ -609,7 +658,6 @@ int ReceiveData(int socket, char * data, int length, int timeout) FD_SET(socket, &socketSet); timeval.tv_sec = timeout / 1000; timeval.tv_usec = (timeout % 1000) * 1000; - /*n = select(0, &socketSet, NULL, NULL, &timeval);*/ n = select(FD_SETSIZE, &socketSet, NULL, NULL, &timeval); if(n < 0) { @@ -629,7 +677,7 @@ int ReceiveData(int socket, char * data, int length, int timeout) return n; } -int +static int UPNPIGD_IsConnected(struct UPNPUrls * urls, struct IGDdatas * data) { char status[64]; diff --git a/third-party/miniupnp/miniwget.c b/third-party/miniupnp/miniwget.c index 0a026cbb1..7d24c135e 100644 --- a/third-party/miniupnp/miniwget.c +++ b/third-party/miniupnp/miniwget.c @@ -1,7 +1,7 @@ -/* $Id: miniwget.c,v 1.22 2009/02/28 10:36:35 nanard Exp $ */ +/* $Id: miniwget.c,v 1.25 2009/08/07 14:44:51 nanard Exp $ */ /* Project : miniupnp * Author : Thomas Bernard - * Copyright (c) 2005 Thomas Bernard + * Copyright (c) 2005-2009 Thomas Bernard * This software is subject to the conditions detailed in the * LICENCE file provided in this distribution. * */ @@ -24,13 +24,16 @@ #include #include #include +#include #define closesocket close +#define MINIUPNPC_IGNORE_EINTR #endif #if defined(__sun) || defined(sun) #define MIN(x,y) (((x)<(y))?(x):(y)) #endif #include "miniupnpcstrings.h" +#include "miniwget.h" /* miniwget2() : * */ @@ -43,6 +46,12 @@ miniwget2(const char * url, const char * host, int s; struct sockaddr_in dest; struct hostent *hp; + int n; + int len; + int sent; +#ifdef MINIUPNPC_SET_SOCKET_TIMEOUT + struct timeval timeout; +#endif *size = 0; hp = gethostbyname(host); if(hp==NULL) @@ -59,9 +68,31 @@ miniwget2(const char * url, const char * host, perror("socket"); return NULL; } +#ifdef MINIUPNPC_SET_SOCKET_TIMEOUT + /* setting a 3 seconds timeout for the connect() call */ + timeout.tv_sec = 3; + timeout.tv_usec = 0; + if(setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(struct timeval)) < 0) + { + perror("setsockopt"); + } + timeout.tv_sec = 3; + timeout.tv_usec = 0; + if(setsockopt(s, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(struct timeval)) < 0) + { + perror("setsockopt"); + } +#endif dest.sin_family = AF_INET; dest.sin_port = htons(port); - if(connect(s, (struct sockaddr *)&dest, sizeof(struct sockaddr_in))<0) +#ifdef MINIUPNPC_IGNORE_EINTR + do { +#endif + n = connect(s, (struct sockaddr *)&dest, sizeof(struct sockaddr_in)); +#ifdef MINIUPNPC_IGNORE_EINTR + } while(n < 0 && errno == EINTR); +#endif + if(n<0) { perror("connect"); closesocket(s); @@ -72,12 +103,17 @@ miniwget2(const char * url, const char * host, if(addr_str) { struct sockaddr_in saddr; - socklen_t len; + socklen_t saddrlen; - len = sizeof(saddr); - getsockname(s, (struct sockaddr *)&saddr, &len); + saddrlen = sizeof(saddr); + if(getsockname(s, (struct sockaddr *)&saddr, &saddrlen) < 0) + { + perror("getsockname"); + } + else + { #ifndef WIN32 - inet_ntop(AF_INET, &saddr.sin_addr, addr_str, addr_str_len); + inet_ntop(AF_INET, &saddr.sin_addr, addr_str, addr_str_len); #else /* using INT WINAPI WSAAddressToStringA(LPSOCKADDR, DWORD, LPWSAPROTOCOL_INFOA, LPSTR, LPDWORD); * But his function make a string with the port : nn.nn.nn.nn:port */ @@ -86,14 +122,15 @@ miniwget2(const char * url, const char * host, { printf("WSAAddressToStringA() failed : %d\n", WSAGetLastError()); }*/ - strncpy(addr_str, inet_ntoa(saddr.sin_addr), addr_str_len); + strncpy(addr_str, inet_ntoa(saddr.sin_addr), addr_str_len); #endif + } #ifdef DEBUG printf("address miniwget : %s\n", addr_str); #endif } - snprintf(buf, sizeof(buf), + len = snprintf(buf, sizeof(buf), "GET %s HTTP/1.1\r\n" "Host: %s:%d\r\n" "Connection: Close\r\n" @@ -101,10 +138,24 @@ miniwget2(const char * url, const char * host, "\r\n", path, host, port); - /*write(s, buf, strlen(buf));*/ - send(s, buf, strlen(buf), 0); + sent = 0; + /* sending the HTTP request */ + while(sent < len) { - int n, headers=1; + n = send(s, buf+sent, len-sent, 0); + if(n < 0) + { + perror("send"); + closesocket(s); + return NULL; + } + else + { + sent += n; + } + } + { + int headers=1; char * respbuffer = NULL; int allreadyread = 0; /*while((n = recv(s, buf, 2048, 0)) > 0)*/ @@ -115,12 +166,14 @@ miniwget2(const char * url, const char * host, int i=0; while(i