Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
miniupnpc: change miniwget to return HTTP status code
increments API_VERSION to 16
  • Loading branch information
miniupnp committed Jan 24, 2016
1 parent d274456 commit c499191
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 33 deletions.
2 changes: 1 addition & 1 deletion miniupnpc/CMakeLists.txt
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required (VERSION 2.6)

project (miniupnpc C)
set (MINIUPNPC_VERSION 1.9)
set (MINIUPNPC_API_VERSION 15)
set (MINIUPNPC_API_VERSION 16)

if (NOT CMAKE_BUILD_TYPE)
if (WIN32)
Expand Down
6 changes: 5 additions & 1 deletion miniupnpc/Changelog.txt
@@ -1,6 +1,10 @@
$Id: Changelog.txt,v 1.221 2016/01/22 15:07:27 nanard Exp $
$Id: Changelog.txt,v 1.222 2016/01/24 17:24:35 nanard Exp $
miniUPnP client Changelog.

2016/01/24:
change miniwget to return HTTP status code
increments API_VERSION to 16

2016/01/22:
Improve UPNPIGD_IsConnected() to check if WAN address is not private.
parse HTTP response status line in miniwget.c
Expand Down
4 changes: 2 additions & 2 deletions miniupnpc/Makefile
@@ -1,4 +1,4 @@
# $Id: Makefile,v 1.126 2015/08/28 12:14:18 nanard Exp $
# $Id: Makefile,v 1.133 2016/01/24 17:24:35 nanard Exp $
# MiniUPnP Project
# http://miniupnp.free.fr/
# http://miniupnp.tuxfamily.org/
Expand Down Expand Up @@ -66,7 +66,7 @@ ifeq (SunOS, $(OS))
endif

# APIVERSION is used to build SONAME
APIVERSION = 15
APIVERSION = 16

SRCS = igd_desc_parse.c miniupnpc.c minixml.c minisoap.c miniwget.c \
upnpc.c upnpcommands.c upnpreplyparse.c testminixml.c \
Expand Down
7 changes: 6 additions & 1 deletion miniupnpc/apiversions.txt
@@ -1,7 +1,12 @@
$Id: apiversions.txt,v 1.7 2015/07/23 20:40:08 nanard Exp $
$Id: apiversions.txt,v 1.9 2016/01/24 17:24:36 nanard Exp $

Differences in API between miniUPnPc versions

API version 16
added "status_code" argument to getHTTPResponse(), miniwget() and miniwget_getaddr()
updated macro :
#define MINIUPNPC_API_VERSION 16

API version 15
changed "sameport" argument of upnpDiscover() upnpDiscoverAll() upnpDiscoverDevice()
to "localport". When 0 or 1, behaviour is not changed, but it can take
Expand Down
9 changes: 6 additions & 3 deletions miniupnpc/miniupnpc.c
@@ -1,4 +1,4 @@
/* $Id: miniupnpc.c,v 1.147 2016/01/24 16:32:24 nanard Exp $ */
/* $Id: miniupnpc.c,v 1.148 2016/01/24 17:24:36 nanard Exp $ */
/* vim: tabstop=4 shiftwidth=4 noexpandtab
* Project : miniupnp
* Web : http://miniupnp.free.fr/
Expand Down Expand Up @@ -571,6 +571,8 @@ UPNP_GetValidIGD(struct UPNPDev * devlist,
int n_igd = 0;
char extIpAddr[16];
char myLanAddr[40];
int status_code = -1;

if(!devlist)
{
#ifdef DEBUG
Expand All @@ -594,7 +596,7 @@ UPNP_GetValidIGD(struct UPNPDev * devlist,
* with st == urn:schemas-upnp-org:device:InternetGatewayDevice:1 */
desc[i].xml = miniwget_getaddr(dev->descURL, &(desc[i].size),
myLanAddr, sizeof(myLanAddr),
dev->scope_id);
dev->scope_id, &status_code);
#ifdef DEBUG
if(!desc[i].xml)
{
Expand Down Expand Up @@ -702,8 +704,9 @@ UPNP_GetIGDFromUrl(const char * rootdescurl,
{
char * descXML;
int descXMLsize = 0;

descXML = miniwget_getaddr(rootdescurl, &descXMLsize,
lanaddr, lanaddrlen, 0);
lanaddr, lanaddrlen, 0, NULL);
if(descXML) {
memset(data, 0, sizeof(struct IGDdatas));
memset(urls, 0, sizeof(struct UPNPUrls));
Expand Down
6 changes: 3 additions & 3 deletions miniupnpc/miniupnpc.h
@@ -1,8 +1,8 @@
/* $Id: miniupnpc.h,v 1.44 2015/07/23 20:40:10 nanard Exp $ */
/* $Id: miniupnpc.h,v 1.49 2016/01/24 17:24:36 nanard Exp $ */
/* Project: miniupnp
* http://miniupnp.free.fr/
* Author: Thomas Bernard
* Copyright (c) 2005-2015 Thomas Bernard
* Copyright (c) 2005-2016 Thomas Bernard
* This software is subjects to the conditions detailed
* in the LICENCE file provided within this distribution */
#ifndef MINIUPNPC_H_INCLUDED
Expand All @@ -20,7 +20,7 @@

/* versions : */
#define MINIUPNPC_VERSION "1.9"
#define MINIUPNPC_API_VERSION 15
#define MINIUPNPC_API_VERSION 16

/* Source port:
Using "1" as an alias for 1900 for backwards compatability
Expand Down
33 changes: 19 additions & 14 deletions miniupnpc/miniwget.c
@@ -1,4 +1,4 @@
/* $Id: miniwget.c,v 1.74 2016/01/22 15:19:43 nanard Exp $ */
/* $Id: miniwget.c,v 1.75 2016/01/24 17:24:36 nanard Exp $ */
/* Project : miniupnp
* Website : http://miniupnp.free.fr/
* Author : Thomas Bernard
Expand Down Expand Up @@ -362,15 +362,15 @@ static void *
miniwget3(const char * host,
unsigned short port, const char * path,
int * size, char * addr_str, int addr_str_len,
const char * httpversion, unsigned int scope_id)
const char * httpversion, unsigned int scope_id,
int * status_code)
{
char buf[2048];
int s;
int n;
int len;
int sent;
void * content;
int status_code;

*size = 0;
s = connecthostport(host, port, scope_id);
Expand Down Expand Up @@ -461,7 +461,7 @@ miniwget3(const char * host,
sent += n;
}
}
content = getHTTPResponse(s, size, &status_code);
content = getHTTPResponse(s, size, status_code);
closesocket(s);
return content;
}
Expand All @@ -470,26 +470,29 @@ miniwget3(const char * host,
* Call miniwget3(); retry with HTTP/1.1 if 1.0 fails. */
static void *
miniwget2(const char * host,
unsigned short port, const char * path,
int * size, char * addr_str, int addr_str_len,
unsigned int scope_id)
unsigned short port, const char * path,
int * size, char * addr_str, int addr_str_len,
unsigned int scope_id, int * status_code)
{
char * respbuffer;

#if 1
respbuffer = miniwget3(host, port, path, size,
addr_str, addr_str_len, "1.1", scope_id);
addr_str, addr_str_len, "1.1",
scope_id, status_code);
#else
respbuffer = miniwget3(host, port, path, size,
addr_str, addr_str_len, "1.0", scope_id);
addr_str, addr_str_len, "1.0",
scope_id, status_code);
if (*size == 0)
{
#ifdef DEBUG
printf("Retrying with HTTP/1.1\n");
#endif
free(respbuffer);
respbuffer = miniwget3(host, port, path, size,
addr_str, addr_str_len, "1.1", scope_id);
addr_str, addr_str_len, "1.1",
scope_id, status_code);
}
#endif
return respbuffer;
Expand Down Expand Up @@ -614,7 +617,8 @@ parseURL(const char * url,
}

void *
miniwget(const char * url, int * size, unsigned int scope_id)
miniwget(const char * url, int * size,
unsigned int scope_id, int * status_code)
{
unsigned short port;
char * path;
Expand All @@ -627,12 +631,13 @@ miniwget(const char * url, int * size, unsigned int scope_id)
printf("parsed url : hostname='%s' port=%hu path='%s' scope_id=%u\n",
hostname, port, path, scope_id);
#endif
return miniwget2(hostname, port, path, size, 0, 0, scope_id);
return miniwget2(hostname, port, path, size, 0, 0, scope_id, status_code);
}

void *
miniwget_getaddr(const char * url, int * size,
char * addr, int addrlen, unsigned int scope_id)
char * addr, int addrlen, unsigned int scope_id,
int * status_code)
{
unsigned short port;
char * path;
Expand All @@ -647,6 +652,6 @@ miniwget_getaddr(const char * url, int * size,
printf("parsed url : hostname='%s' port=%hu path='%s' scope_id=%u\n",
hostname, port, path, scope_id);
#endif
return miniwget2(hostname, port, path, size, addr, addrlen, scope_id);
return miniwget2(hostname, port, path, size, addr, addrlen, scope_id, status_code);
}

6 changes: 3 additions & 3 deletions miniupnpc/miniwget.h
@@ -1,4 +1,4 @@
/* $Id: miniwget.h,v 1.11 2016/01/22 15:19:43 nanard Exp $ */
/* $Id: miniwget.h,v 1.12 2016/01/24 17:24:36 nanard Exp $ */
/* Project : miniupnp
* Author : Thomas Bernard
* Copyright (c) 2005-2016 Thomas Bernard
Expand All @@ -16,9 +16,9 @@ extern "C" {

MINIUPNP_LIBSPEC void * getHTTPResponse(int s, int * size, int * status_code);

MINIUPNP_LIBSPEC void * miniwget(const char *, int *, unsigned int);
MINIUPNP_LIBSPEC void * miniwget(const char *, int *, unsigned int, int *);

MINIUPNP_LIBSPEC void * miniwget_getaddr(const char *, int *, char *, int, unsigned int);
MINIUPNP_LIBSPEC void * miniwget_getaddr(const char *, int *, char *, int, unsigned int, int *);

int parseURL(const char *, char *, unsigned short *, char * *, unsigned int *);

Expand Down
12 changes: 7 additions & 5 deletions miniupnpc/testminiwget.c
@@ -1,7 +1,7 @@
/* $Id: testminiwget.c,v 1.4 2012/06/23 22:35:59 nanard Exp $ */
/* $Id: testminiwget.c,v 1.5 2016/01/24 17:24:36 nanard Exp $ */
/* Project : miniupnp
* Author : Thomas Bernard
* Copyright (c) 2005-2012 Thomas Bernard
* Copyright (c) 2005-2016 Thomas Bernard
* This software is subject to the conditions detailed in the
* LICENCE file provided in this distribution.
* */
Expand All @@ -20,15 +20,17 @@ int main(int argc, char * * argv)
int size, writtensize;
FILE *f;
char addr[64];
int status_code = -1;

if(argc < 3) {
fprintf(stderr, "Usage:\t%s url file\n", argv[0]);
fprintf(stderr, "Example:\t%s http://www.google.com/ out.html\n", argv[0]);
return 1;
}
data = miniwget_getaddr(argv[1], &size, addr, sizeof(addr), 0);
if(!data) {
fprintf(stderr, "Error fetching %s\n", argv[1]);
data = miniwget_getaddr(argv[1], &size, addr, sizeof(addr), 0, &status_code);
if(!data || (status_code != 200)) {
if(data) free(data);
fprintf(stderr, "Error %d fetching %s\n", status_code, argv[1]);
return 1;
}
printf("local address : %s\n", addr);
Expand Down

0 comments on commit c499191

Please sign in to comment.