Fix commit 6cbf0ba

Use the "flags" global variable to store the option value
Save a lot of complexity.
This commit is contained in:
Thomas Bernard 2018-02-22 13:47:48 +01:00
parent c6bf0ba6f3
commit 80779ff4f7
5 changed files with 36 additions and 48 deletions

View File

@ -1,7 +1,7 @@
/* $Id: ifacewatcher.c,v 1.7 2012/05/27 22:16:10 nanard Exp $ */
/* $Id: ifacewatcher.c,v 1.9 2018/02/03 22:05:42 nanard Exp $ */
/* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2006-2015 Thomas Bernard
* http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/
* (c) 2006-2018 Thomas Bernard
*
* ifacewatcher.c
*

View File

@ -2,7 +2,7 @@
/* vim: tabstop=4 shiftwidth=4 noexpandtab
* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2006-2017 Thomas Bernard
* (c) 2006-2018 Thomas Bernard
* This software is subject to the conditions detailed
* in the LICENCE file provided within the distribution */
@ -1296,13 +1296,11 @@ init(int argc, char * * argv, struct runtime_vars * v)
break;
#ifdef IGD_V2
case UPNPFORCEIGDDESCV1:
if (strcmp(ary_options[i].value, "yes")!=0 &&
strcmp(ary_options[i].value, "no")!=0 ) {
if (strcmp(ary_options[i].value, "yes") == 0)
SETFLAG(FORCEIGDDESCV1MASK);
else if (strcmp(ary_options[i].value, "no") != 0 ) {
fprintf(stderr, "force_igd_desc_v1 can only be yes or no\n");
}
/* ary_options is processed by genRootDesc() to find
this because there is apperently no way to pass
options to the http server */
break;
#endif
default:

View File

@ -1,7 +1,7 @@
/* $Id: testupnpdescgen.c,v 1.34 2017/05/27 07:47:57 nanard Exp $ */
/* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2006-2017 Thomas Bernard
* (c) 2006-2018 Thomas Bernard
* This software is subject to the conditions detailed
* in the LICENCE file provided within the distribution */
@ -15,6 +15,7 @@
#include "macros.h"
#include "config.h"
#include "upnpglobalvars.h"
#include "upnpdescgen.h"
#include "upnpdescstrings.h"
#include "getifaddr.h"
@ -39,16 +40,11 @@ char random_url[] = "RANDOM";
#endif /* RANDOMIZE_URLS */
unsigned int upnp_configid = 666;
char * use_ext_ip_addr = NULL;
const char * use_ext_ip_addr = NULL;
const char * ext_if_name = "eth0";
int runtime_flags = 0;
#ifdef IGD_V2
struct option * ary_options = NULL;
unsigned int num_options = 0;
#endif
int getifaddr(const char * ifname, char * buf, int len, struct in_addr * addr, struct in_addr * mask)
{
UNUSED(ifname);
@ -144,8 +140,25 @@ main(int argc, char * * argv)
char * s;
int l;
FILE * f;
UNUSED(argc);
UNUSED(argv);
for(l = 1; l < argc; l++) {
if(0 == strcmp(argv[l], "--help") || 0 == strcmp(argv[l], "-h")) {
printf("Usage:\t%s [options]\n", argv[0]);
printf("options:\n");
#ifdef IGD_V2
printf("\t--forceigdv1 Force versions of devices to be 1\n");
#else
printf("\tNone\n");
#endif
return 0;
#ifdef IGD_V2
} else if(0 == strcmp(argv[l], "--forceigdv1")) {
SETFLAG(FORCEIGDDESCV1MASK);
#endif
} else {
fprintf(stderr, "unknown option %s\n", argv[l]);
}
}
if(mkdir("testdescs", 0777) < 0) {
if(errno != EEXIST) {

View File

@ -2,7 +2,7 @@
/* vim: tabstop=4 shiftwidth=4 noexpandtab
* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2006-2017 Thomas Bernard
* (c) 2006-2018 Thomas Bernard
* This software is subject to the conditions detailed
* in the LICENCE file provided within the distribution */
@ -17,7 +17,6 @@
#endif
#include "upnpdescgen.h"
#include "miniupnpdpath.h"
#include "options.h"
#include "upnpglobalvars.h"
#include "upnpdescstrings.h"
#include "upnpurns.h"
@ -879,31 +878,6 @@ strcat_int(char * str, int * len, int * tmplen, int i)
return str;
}
#ifdef IGD_V2
int force_igd_desc_v1(void)
{
/* keep a cache so we only do it once */
static int force=-1;
int i;
if (force!=-1) return force;
force=0;
for(i=0; i<num_options; i++) {
if(ary_options[i].id==UPNPFORCEIGDDESCV1)
{
if (strcmp(ary_options[i].value, "yes")==0)
force=1;
else if (strcmp(ary_options[i].value, "no")==0)
force=0;
}
}
return force;
}
#endif
/* iterative subroutine using a small stack
* This way, the progam stack usage is kept low */
static char *
@ -948,15 +922,15 @@ genXML(char * str, int * len, int * tmplen,
#endif /* RANDOMIZE_URLS */
str = strcat_str(str, len, tmplen, p[i].data);
#ifdef IGD_V2
if (force_igd_desc_v1())
/* checking a single 'u' saves us 4 strcmp() calls most of the time */
if (GETFLAG(FORCEIGDDESCV1MASK) && (p[i].data[0] == 'u'))
{
if ((strcmp(p[i].data, DEVICE_TYPE_IGD) == 0) ||
(strcmp(p[i].data, DEVICE_TYPE_WAN) == 0) ||
(strcmp(p[i].data, DEVICE_TYPE_WANC) == 0) ||
(strcmp(p[i].data, SERVICE_TYPE_WANIPC) == 0) )
{
int pos = strlen(str)-1;
if (pos>0) str[pos] = '1';
str[*len - 1] = '1'; /* Change the version number to 1 */
}
}
#endif

View File

@ -65,6 +65,9 @@ extern int runtime_flags;
#ifdef ENABLE_PCP
#define PCP_ALLOWTHIRDPARTYMASK 0x0400
#endif
#ifdef IGD_V2
#define FORCEIGDDESCV1MASK 0x0800
#endif
#define SETFLAG(mask) runtime_flags |= mask
#define GETFLAG(mask) (runtime_flags & mask)