update to miniupnp-20080217

This commit is contained in:
Charles Kerr 2008-02-21 14:38:01 +00:00
parent 58b655338a
commit d30101ac13
2 changed files with 48 additions and 29 deletions

View File

@ -1,4 +1,4 @@
/* $Id: minisoap.c,v 1.12 2007/12/13 17:09:03 nanard Exp $ */
/* $Id: minisoap.c,v 1.14 2008/02/16 23:46:11 nanard Exp $ */
/* Project : miniupnp
* Author : Thomas Bernard
* Copyright (c) 2005 Thomas Bernard
@ -23,6 +23,12 @@
/* only for malloc */
#include <stdlib.h>
#ifdef WIN32
#define PRINT_SOCKET_ERROR(x) printf("Socket error: %s, %d\n", x, WSAGetLastError());
#else
#define PRINT_SOCKET_ERROR(x) perror(x)
#endif
/* httpWrite sends the headers and the body to the socket
* and returns the number of bytes sent */
static int
@ -36,15 +42,25 @@ httpWrite(int fd, const char * body, int bodysize,
/* Note : my old linksys router only took into account
* soap request that are sent into only one packet */
char * p;
/* TODO: AVOID MALLOC */
p = malloc(headerssize+bodysize);
memcpy(p, headers, headerssize);
memcpy(p+headerssize, body, bodysize);
/*n = write(fd, p, headerssize+bodysize);*/
n = send(fd, p, headerssize+bodysize, 0);
if(n<0) {
PRINT_SOCKET_ERROR("send");
}
/* disable send on the socket */
/* draytek routers dont seems to like that... */
#if 0
#ifdef WIN32
shutdown(fd, SD_SEND);
if(shutdown(fd, SD_SEND)<0) {
#else
shutdown(fd, SHUT_WR); /*SD_SEND*/
if(shutdown(fd, SHUT_WR)<0) { /*SD_SEND*/
#endif
PRINT_SOCKET_ERROR("shutdown");
}
#endif
free(p);
return n;
@ -65,6 +81,7 @@ int soapPostSubmit(int fd,
/* We are not using keep-alive HTTP connections.
* HTTP/1.1 needs the header Connection: close to do that.
* This is the default with HTTP/1.0 */
/* Connection: Close is normally there only in HTTP/1.1 but who knows */
headerssize = snprintf(headerbuf, sizeof(headerbuf),
/* "POST %s HTTP/1.1\r\n"*/
"POST %s HTTP/1.0\r\n"
@ -73,7 +90,7 @@ int soapPostSubmit(int fd,
"Content-Length: %d\r\n"
"Content-Type: text/xml\r\n"
"SOAPAction: \"%s\"\r\n"
/* "Connection: Close\r\n" */
"Connection: Close\r\n"
"\r\n",
url, host, port, bodysize, action);
return httpWrite(fd, body, bodysize, headerbuf, headerssize);

View File

@ -1,4 +1,4 @@
/* $Id: miniupnpc.c,v 1.49 2007/12/19 14:58:54 nanard Exp $ */
/* $Id: miniupnpc.c,v 1.50 2008/02/03 22:19:45 nanard Exp $ */
/* Project : miniupnp
* Author : Thomas BERNARD
* copyright (c) 2005-2007 Thomas Bernard
@ -665,37 +665,39 @@ UPNP_GetValidIGD(struct UPNPDev * devlist,
{
/* we should choose an internet gateway device.
* with st == urn:schemas-upnp-org:device:InternetGatewayDevice:1 */
if((state >= 3) || strstr(dev->st, "InternetGatewayDevice"))
{
descXML = miniwget_getaddr(dev->descURL, &descXMLsize,
descXML = miniwget_getaddr(dev->descURL, &descXMLsize,
lanaddr, lanaddrlen);
if(descXML)
if(descXML)
{
ndev++;
memset(data, 0, sizeof(struct IGDdatas));
memset(urls, 0, sizeof(struct UPNPUrls));
parserootdesc(descXML, descXMLsize, data);
free(descXML);
descXML = NULL;
if(0==strcmp(data->servicetype_CIF,
"urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1")
|| state >= 3 )
{
ndev++;
memset(data, 0, sizeof(struct IGDdatas));
memset(urls, 0, sizeof(struct UPNPUrls));
parserootdesc(descXML, descXMLsize, data);
free(descXML);
descXML = NULL;
GetUPNPUrls(urls, data, dev->descURL);
GetUPNPUrls(urls, data, dev->descURL);
#ifdef DEBUG
printf("UPNPIGD_IsConnected(%s) = %d\n",
urls->controlURL,
UPNPIGD_IsConnected(urls, data));
printf("UPNPIGD_IsConnected(%s) = %d\n",
urls->controlURL,
UPNPIGD_IsConnected(urls, data));
#endif
if((state >= 2) || UPNPIGD_IsConnected(urls, data))
return state;
FreeUPNPUrls(urls);
memset(data, 0, sizeof(struct IGDdatas));
if((state >= 2) || UPNPIGD_IsConnected(urls, data))
return state;
FreeUPNPUrls(urls);
}
#ifdef DEBUG
else
{
printf("error getting XML description %s\n", dev->descURL);
}
#endif
memset(data, 0, sizeof(struct IGDdatas));
}
#ifdef DEBUG
else
{
printf("error getting XML description %s\n", dev->descURL);
}
#endif
}
}
return 0;