-$Id: Changelog.txt,v 1.111 2010/04/05 20:36:59 nanard Exp $
+$Id: Changelog.txt,v 1.113 2010/04/12 20:39:40 nanard Exp $
miniUPnP client Changelog.
+2010/04/12:
+ Retrying with HTTP/1.1 if HTTP/1.0 failed. see
+ http://miniupnp.tuxfamily.org/forum/viewtopic.php?p=1703
+
+2010/04/07:
+ avoid returning duplicates in upnpDiscover()
+
2010/04/05:
Create a connecthostport.h/.c with connecthostport() function
and use it in miniwget and miniupnpc.
-/* $Id: minisoap.c,v 1.18 2009/12/04 11:29:18 nanard Exp $ */
+/* $Id: minisoap.c,v 1.19 2010/04/12 20:39:41 nanard Exp $ */
/* Project : miniupnp
* Author : Thomas Bernard
* Copyright (c) 2005-2009 Thomas Bernard
const char * host,
unsigned short port,
const char * action,
- const char * body)
+ const char * body,
+ const char * httpversion)
{
int bodysize;
char headerbuf[512];
if(port != 80)
snprintf(portstr, sizeof(portstr), ":%hu", port);
headerssize = snprintf(headerbuf, sizeof(headerbuf),
-/* "POST %s HTTP/1.1\r\n" */
- "POST %s HTTP/1.0\r\n"
+ "POST %s HTTP/%s\r\n"
"Host: %s%s\r\n"
"User-Agent: " OS_STRING ", UPnP/1.0, MiniUPnPc/" MINIUPNPC_VERSION_STRING "\r\n"
"Content-Length: %d\r\n"
"Cache-Control: no-cache\r\n" /* ??? */
"Pragma: no-cache\r\n"
"\r\n",
- url, host, portstr, bodysize, action);
+ url, httpversion, host, portstr, bodysize, action);
#ifdef DEBUG
printf("SOAP request : headersize=%d bodysize=%d\n",
headerssize, bodysize);
-/* $Id: minisoap.h,v 1.3 2006/11/19 22:32:34 nanard Exp $ */
+/* $Id: minisoap.h,v 1.4 2010/04/12 20:39:41 nanard Exp $ */
/* Project : miniupnp
* Author : Thomas Bernard
* Copyright (c) 2005 Thomas Bernard
/*int httpWrite(int, const char *, int, const char *);*/
int soapPostSubmit(int, const char *, const char *, unsigned short,
- const char *, const char *);
+ const char *, const char *, const char *);
#endif
-/* $Id: miniupnpc.c,v 1.78 2010/04/05 20:36:59 nanard Exp $ */
+/* $Id: miniupnpc.c,v 1.80 2010/04/12 20:39:41 nanard Exp $ */
/* Project : miniupnp
* Author : Thomas BERNARD
* copyright (c) 2005-2010 Thomas Bernard
#endif
#endif
-#ifdef __APPLE__
-#define _DARWIN_C_SOURCE
-#endif
-
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
}
}
-/* simpleUPnPcommand :
+/* simpleUPnPcommand2 :
* not so simple !
* return values :
* 0 - OK
* -1 - error */
-int simpleUPnPcommand(int s, const char * url, const char * service,
- const char * action, struct UPNParg * args,
- char * buffer, int * bufsize)
+static int simpleUPnPcommand2(int s, const char * url, const char * service,
+ const char * action, struct UPNParg * args,
+ char * buffer, int * bufsize, const char * httpversion)
{
char hostname[MAXHOSTNAMELEN+1];
unsigned short port = 0;
}
}
- n = soapPostSubmit(s, path, hostname, port, soapact, soapbody);
+ n = soapPostSubmit(s, path, hostname, port, soapact, soapbody, httpversion);
if(n<=0) {
#ifdef DEBUG
printf("Error sending SOAP request\n");
return 0;
}
+/* simpleUPnPcommand :
+ * not so simple !
+ * return values :
+ * 0 - OK
+ * -1 - error */
+int simpleUPnPcommand(int s, const char * url, const char * service,
+ const char * action, struct UPNParg * args,
+ char * buffer, int * bufsize)
+{
+ int result;
+ int origbufsize = *bufsize;
+
+ result = simpleUPnPcommand2(s, url, service, action, args, buffer, bufsize, "1.0");
+ if (result < 0 || *bufsize == 0)
+ {
+#if DEBUG
+ printf("Error or no result from SOAP request; retrying with HTTP/1.1\n");
+#endif
+ *bufsize = origbufsize;
+ result = simpleUPnPcommand2(s, url, service, action, args, buffer, bufsize, "1.1");
+ }
+ return result;
+}
+
/* parseMSEARCHReply()
* the last 4 arguments are filled during the parsing :
* - location/locationsize : "location:" field of the SSDP reply packet
parseMSEARCHReply(bufr, n, &descURL, &urlsize, &st, &stsize);
if(st&&descURL)
{
- /*printf("M-SEARCH Reply:\nST: %.*s\nLocation: %.*s\n",
- stsize, st, urlsize, descURL); */
+#ifdef DEBUG
+ printf("M-SEARCH Reply:\nST: %.*s\nLocation: %.*s\n",
+ stsize, st, urlsize, descURL);
+#endif
+ for(tmp=devlist; tmp; tmp = tmp->pNext) {
+ if(memcmp(tmp->descURL, descURL, urlsize) == 0 &&
+ tmp->descURL[urlsize] == '\0' &&
+ memcmp(tmp->st, st, stsize) == 0 &&
+ tmp->st[stsize] == '\0')
+ break;
+ }
+ /* at the exit of the loop above, tmp is null if
+ * no duplicate device was found */
+ if(tmp)
+ continue;
tmp = (struct UPNPDev *)malloc(sizeof(struct UPNPDev)+urlsize+stsize);
tmp->pNext = devlist;
tmp->descURL = tmp->buffer;
-/* $Id: miniwget.c,v 1.36 2010/04/05 12:34:05 nanard Exp $ */
+/* $Id: miniwget.c,v 1.37 2010/04/12 20:39:42 nanard Exp $ */
/* Project : miniupnp
* Author : Thomas Bernard
* Copyright (c) 2005-2010 Thomas Bernard
#include "miniwget.h"
#include "connecthostport.h"
-/* miniwget2() :
+/* miniwget3() :
* do all the work.
* Return NULL if something failed. */
static void *
-miniwget2(const char * url, const char * host,
+miniwget3(const char * url, const char * host,
unsigned short port, const char * path,
- int * size, char * addr_str, int addr_str_len)
+ int * size, char * addr_str, int addr_str_len, const char * httpversion)
{
char buf[2048];
int s;
}
len = snprintf(buf, sizeof(buf),
- "GET %s HTTP/1.0\r\n"
+ "GET %s HTTP/%s\r\n"
"Host: %s:%d\r\n"
"Connection: Close\r\n"
"User-Agent: " OS_STRING ", UPnP/1.0, MiniUPnPc/" MINIUPNPC_VERSION_STRING "\r\n"
"\r\n",
- path, host, port);
+ path, httpversion, host, port);
sent = 0;
/* sending the HTTP request */
while(sent < len)
}
}
+/* miniwget2() :
+ * Call miniwget3(); retry with HTTP/1.1 if 1.0 fails. */
+static void *
+miniwget2(const char * url, const char * host,
+ unsigned short port, const char * path,
+ int * size, char * addr_str, int addr_str_len)
+{
+ char * respbuffer;
+
+ respbuffer = miniwget3(url, host, port, path, size, addr_str, addr_str_len, "1.0");
+ if (*size == 0)
+ {
+#ifdef DEBUG
+ printf("Retrying with HTTP/1.1\n");
+#endif
+ free(respbuffer);
+ respbuffer = miniwget3(url, host, port, path, size, addr_str, addr_str_len, "1.1");
+ }
+ return respbuffer;
+}
+
+
+
+
/* parseURL()
* arguments :
* url : source string not modified