]> granicus.if.org Git - transmission/commitdiff
update miniupnp to 20100412
authorMitchell Livingston <livings124@transmissionbt.com>
Tue, 13 Apr 2010 00:11:34 +0000 (00:11 +0000)
committerMitchell Livingston <livings124@transmissionbt.com>
Tue, 13 Apr 2010 00:11:34 +0000 (00:11 +0000)
third-party/miniupnp/Changelog.txt
third-party/miniupnp/minisoap.c
third-party/miniupnp/minisoap.h
third-party/miniupnp/miniupnpc.c
third-party/miniupnp/miniwget.c

index 9d1b124d5f312b22266d397ee3e832bfdc1d7b5b..d785889020bb4442e14da33bb361ee97dd3e54cd 100644 (file)
@@ -1,6 +1,13 @@
-$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.
index 26022ad0650b3243ff62c858dc13c7382088b1ca..9afacb787d8e31d88961f3144e9f148b9c99309f 100644 (file)
@@ -1,4 +1,4 @@
-/* $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
@@ -75,7 +75,8 @@ int soapPostSubmit(int fd,
                                   const char * host,
                                   unsigned short port,
                                   const char * action,
-                                  const char * body)
+                                  const char * body,
+                                  const char * httpversion)
 {
        int bodysize;
        char headerbuf[512];
@@ -93,8 +94,7 @@ int soapPostSubmit(int fd,
        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"
@@ -104,7 +104,7 @@ int soapPostSubmit(int fd,
                                           "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);
index 9fa297fd33dad4d5a95909064a4bbec2b989d81a..696725f625ea7e4ed7e04281875977b352d054b6 100644 (file)
@@ -1,4 +1,4 @@
-/* $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
@@ -9,7 +9,7 @@
 
 /*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
 
index 69fb3a359a4a593a1c771ba3a51d2b981a3d1398..5195bd3a5f55d6336ac1968add81e9c29b1d4358 100644 (file)
@@ -1,4 +1,4 @@
-/* $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>
@@ -172,14 +168,14 @@ getContentLengthAndHeaderLength(char * p, int n,
        }
 }
 
-/* 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;
@@ -267,7 +263,7 @@ int simpleUPnPcommand(int s, const char * url, const char * service,
                }
        }
 
-       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");
@@ -300,6 +296,30 @@ int simpleUPnPcommand(int s, const char * url, const char * service,
        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
@@ -589,8 +609,21 @@ LIBSPEC struct UPNPDev * upnpDiscover(int delay, const char * multicastif,
                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;
index 55719e971ddf36126c55be2bf6e8eb4c4a9b6b51..aa5ee26ec6351a9d56623f257d7fff069817ce5d 100644 (file)
@@ -1,4 +1,4 @@
-/* $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;
@@ -103,13 +103,13 @@ miniwget2(const char * url, const char * host,
        }
 
        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)
@@ -176,6 +176,30 @@ miniwget2(const char * url, const char * host,
        }
 }
 
+/* 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