Changeset 8962
- Timestamp:
- Aug 18, 2009, 12:56:12 AM (13 years ago)
- Location:
- trunk/third-party/miniupnp
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/third-party/miniupnp/Changelog.txt
r8862 r8962 1 $Id: Changelog.txt,v 1. 86 2009/07/29 08:44:29nanard Exp $1 $Id: Changelog.txt,v 1.90 2009/08/07 08:42:18 nanard Exp $ 2 2 miniUPnP client Changelog. 3 4 2009/08/07: 5 Set socket timeout for connect() 6 Some cleanup in miniwget.c 7 8 2009/08/04: 9 remove multiple redirections with -d in upnpc.c 10 Print textual error code in upnpc.c 11 Ignore EINTR during the connect() and poll() calls. 3 12 4 13 2009/07/29: -
trunk/third-party/miniupnp/miniupnpc.c
r8862 r8962 1 /* $Id: miniupnpc.c,v 1. 59 2009/07/29 08:44:29nanard Exp $ */1 /* $Id: miniupnpc.c,v 1.63 2009/08/07 14:44:50 nanard Exp $ */ 2 2 /* Project : miniupnp 3 3 * Author : Thomas BERNARD 4 * copyright (c) 2005-200 7Thomas Bernard4 * copyright (c) 2005-2009 Thomas Bernard 5 5 * This software is subjet to the conditions detailed in the 6 6 * provided LICENCE file. */ 7 #define __EXTENSIONS__ 1 8 #ifndef MACOSX 9 #if !defined(_XOPEN_SOURCE) && !defined(__OpenBSD__) && !defined(__NetBSD__) 10 #ifndef __cplusplus 11 #define _XOPEN_SOURCE 600 12 #endif 13 #endif 14 #ifndef __BSD_VISIBLE 15 #define __BSD_VISIBLE 1 16 #endif 17 #endif 18 19 #include <stdlib.h> 7 20 #include <stdio.h> 8 #include <stdlib.h>9 21 #include <string.h> 10 22 #ifdef WIN32 … … 30 42 #include <poll.h> 31 43 #include <netdb.h> 44 #include <strings.h> 45 #include <errno.h> 32 46 #define closesocket close 47 #define MINIUPNPC_IGNORE_EINTR 48 #endif 49 #ifdef MINIUPNPC_SET_SOCKET_TIMEOUT 50 #include <sys/time.h> 33 51 #endif 34 52 #include "miniupnpc.h" … … 150 168 int n; 151 169 int contentlen, headerlen; /* for the response */ 170 #ifdef MINIUPNPC_SET_SOCKET_TIMEOUT 171 struct timeval timeout; 172 #endif 152 173 snprintf(soapact, sizeof(soapact), "%s#%s", service, action); 153 174 if(args==NULL) … … 225 246 return -1; 226 247 } 248 #ifdef MINIUPNPC_SET_SOCKET_TIMEOUT 249 /* setting a 3 seconds timeout for the connect() call */ 250 timeout.tv_sec = 3; 251 timeout.tv_usec = 0; 252 if(setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(struct timeval)) < 0) 253 { 254 PRINT_SOCKET_ERROR("setsockopt"); 255 } 256 timeout.tv_sec = 3; 257 timeout.tv_usec = 0; 258 if(setsockopt(s, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(struct timeval)) < 0) 259 { 260 PRINT_SOCKET_ERROR("setsockopt"); 261 } 262 #endif 227 263 dest.sin_family = AF_INET; 228 264 dest.sin_port = htons(port); 229 265 dest.sin_addr.s_addr = inet_addr(hostname); 230 if(connect(s, (struct sockaddr *)&dest, sizeof(struct sockaddr))<0) 231 { 266 #ifdef MINIUPNPC_IGNORE_EINTR 267 do { 268 #endif 269 n = connect(s, (struct sockaddr *)&dest, sizeof(struct sockaddr)); 270 #ifdef MINIUPNPC_IGNORE_EINTR 271 } while(n < 0 && errno == EINTR); 272 #endif 273 if(n < 0) 274 { 232 275 PRINT_SOCKET_ERROR("connect"); 233 276 closesocket(s); … … 591 634 #ifndef WIN32 592 635 struct pollfd fds[1]; /* for the poll */ 593 fds[0].fd = socket; 594 fds[0].events = POLLIN; 595 n = poll(fds, 1, timeout); 636 #ifdef MINIUPNPC_IGNORE_EINTR 637 do { 638 #endif 639 fds[0].fd = socket; 640 fds[0].events = POLLIN; 641 n = poll(fds, 1, timeout); 642 #ifdef MINIUPNPC_IGNORE_EINTR 643 } while(n < 0 && errno == EINTR); 644 #endif 596 645 if(n < 0) 597 646 { … … 610 659 timeval.tv_sec = timeout / 1000; 611 660 timeval.tv_usec = (timeout % 1000) * 1000; 612 /*n = select(0, &socketSet, NULL, NULL, &timeval);*/613 661 n = select(FD_SETSIZE, &socketSet, NULL, NULL, &timeval); 614 662 if(n < 0) … … 630 678 } 631 679 632 int680 static int 633 681 UPNPIGD_IsConnected(struct UPNPUrls * urls, struct IGDdatas * data) 634 682 { -
trunk/third-party/miniupnp/miniwget.c
r8862 r8962 1 /* $Id: miniwget.c,v 1.2 2 2009/02/28 10:36:35nanard Exp $ */1 /* $Id: miniwget.c,v 1.25 2009/08/07 14:44:51 nanard Exp $ */ 2 2 /* Project : miniupnp 3 3 * Author : Thomas Bernard 4 * Copyright (c) 2005 Thomas Bernard4 * Copyright (c) 2005-2009 Thomas Bernard 5 5 * This software is subject to the conditions detailed in the 6 6 * LICENCE file provided in this distribution. … … 25 25 #include <netinet/in.h> 26 26 #include <arpa/inet.h> 27 #include <errno.h> 27 28 #define closesocket close 29 #define MINIUPNPC_IGNORE_EINTR 28 30 #endif 29 31 #if defined(__sun) || defined(sun) … … 32 34 33 35 #include "miniupnpcstrings.h" 36 #include "miniwget.h" 34 37 35 38 /* miniwget2() : … … 44 47 struct sockaddr_in dest; 45 48 struct hostent *hp; 49 int n; 50 int len; 51 int sent; 52 #ifdef MINIUPNPC_SET_SOCKET_TIMEOUT 53 struct timeval timeout; 54 #endif 46 55 *size = 0; 47 56 hp = gethostbyname(host); … … 60 69 return NULL; 61 70 } 71 #ifdef MINIUPNPC_SET_SOCKET_TIMEOUT 72 /* setting a 3 seconds timeout for the connect() call */ 73 timeout.tv_sec = 3; 74 timeout.tv_usec = 0; 75 if(setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(struct timeval)) < 0) 76 { 77 perror("setsockopt"); 78 } 79 timeout.tv_sec = 3; 80 timeout.tv_usec = 0; 81 if(setsockopt(s, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(struct timeval)) < 0) 82 { 83 perror("setsockopt"); 84 } 85 #endif 62 86 dest.sin_family = AF_INET; 63 87 dest.sin_port = htons(port); 64 if(connect(s, (struct sockaddr *)&dest, sizeof(struct sockaddr_in))<0) 88 #ifdef MINIUPNPC_IGNORE_EINTR 89 do { 90 #endif 91 n = connect(s, (struct sockaddr *)&dest, sizeof(struct sockaddr_in)); 92 #ifdef MINIUPNPC_IGNORE_EINTR 93 } while(n < 0 && errno == EINTR); 94 #endif 95 if(n<0) 65 96 { 66 97 perror("connect"); … … 73 104 { 74 105 struct sockaddr_in saddr; 75 socklen_t len; 76 77 len = sizeof(saddr); 78 getsockname(s, (struct sockaddr *)&saddr, &len); 106 socklen_t saddrlen; 107 108 saddrlen = sizeof(saddr); 109 if(getsockname(s, (struct sockaddr *)&saddr, &saddrlen) < 0) 110 { 111 perror("getsockname"); 112 } 113 else 114 { 79 115 #ifndef WIN32 80 inet_ntop(AF_INET, &saddr.sin_addr, addr_str, addr_str_len);116 inet_ntop(AF_INET, &saddr.sin_addr, addr_str, addr_str_len); 81 117 #else 82 118 /* using INT WINAPI WSAAddressToStringA(LPSOCKADDR, DWORD, LPWSAPROTOCOL_INFOA, LPSTR, LPDWORD); … … 87 123 printf("WSAAddressToStringA() failed : %d\n", WSAGetLastError()); 88 124 }*/ 89 strncpy(addr_str, inet_ntoa(saddr.sin_addr), addr_str_len); 90 #endif 125 strncpy(addr_str, inet_ntoa(saddr.sin_addr), addr_str_len); 126 #endif 127 } 91 128 #ifdef DEBUG 92 129 printf("address miniwget : %s\n", addr_str); … … 94 131 } 95 132 96 snprintf(buf, sizeof(buf),133 len = snprintf(buf, sizeof(buf), 97 134 "GET %s HTTP/1.1\r\n" 98 135 "Host: %s:%d\r\n" … … 102 139 "\r\n", 103 140 path, host, port); 104 /*write(s, buf, strlen(buf));*/ 105 send(s, buf, strlen(buf), 0); 106 { 107 int n, headers=1; 141 sent = 0; 142 /* sending the HTTP request */ 143 while(sent < len) 144 { 145 n = send(s, buf+sent, len-sent, 0); 146 if(n < 0) 147 { 148 perror("send"); 149 closesocket(s); 150 return NULL; 151 } 152 else 153 { 154 sent += n; 155 } 156 } 157 { 158 int headers=1; 108 159 char * respbuffer = NULL; 109 160 int allreadyread = 0; … … 116 167 while(i<n-3) 117 168 { 169 /* searching for the end of the HTTP headers */ 118 170 if(buf[i]=='\r' && buf[i+1]=='\n' 119 171 && buf[i+2]=='\r' && buf[i+3]=='\n') … … 122 174 if(i<n-4) 123 175 { 176 /* Copy the content into respbuffet */ 124 177 respbuffer = (char *)realloc((void *)respbuffer, 125 178 allreadyread+(n-i-4)); -
trunk/third-party/miniupnp/minixml.c
r8862 r8962 36 36 * return 0 (false) in case of success and -1 (true) if the end 37 37 * of the xmlbuffer is reached. */ 38 int parseatt(struct xmlparser * p)38 static int parseatt(struct xmlparser * p) 39 39 { 40 40 const char * attname; … … 107 107 /* parseelt parse the xml stream and 108 108 * call the callback functions when needed... */ 109 void parseelt(struct xmlparser * p)109 static void parseelt(struct xmlparser * p) 110 110 { 111 111 int i;
Note: See TracChangeset
for help on using the changeset viewer.