mirror of
https://github.com/monero-project/monero.git
synced 2025-06-23 21:04:14 -04:00
updated miniupnpc
This commit is contained in:
parent
9e45eadb98
commit
7da9905589
45 changed files with 2070 additions and 1472 deletions
139
external/miniupnpc/testigddescparse.c
vendored
139
external/miniupnpc/testigddescparse.c
vendored
|
@ -1,8 +1,8 @@
|
|||
/* $Id: testigddescparse.c,v 1.4 2012/06/28 18:52:12 nanard Exp $ */
|
||||
/* $Id: testigddescparse.c,v 1.8 2015/02/08 08:46:06 nanard Exp $ */
|
||||
/* Project : miniupnp
|
||||
* http://miniupnp.free.fr/
|
||||
* Author : Thomas Bernard
|
||||
* Copyright (c) 2008-2012 Thomas Bernard
|
||||
* Copyright (c) 2008-2015 Thomas Bernard
|
||||
* This software is subject to the conditions detailed in the
|
||||
* LICENCE file provided in this distribution.
|
||||
* */
|
||||
|
@ -13,11 +13,108 @@
|
|||
#include "minixml.h"
|
||||
#include "miniupnpc.h"
|
||||
|
||||
int test_igd_desc_parse(char * buffer, int len)
|
||||
/* count number of differences */
|
||||
int compare_service(struct IGDdatas_service * s, FILE * f)
|
||||
{
|
||||
int n = 0;
|
||||
char line[1024];
|
||||
|
||||
while(fgets(line, sizeof(line), f)) {
|
||||
char * value;
|
||||
char * equal;
|
||||
char * name;
|
||||
char * parsedvalue;
|
||||
int l;
|
||||
l = strlen(line);
|
||||
while((l > 0) && ((line[l-1] == '\r') || (line[l-1] == '\n') || (line[l-1] == ' ')))
|
||||
line[--l] = '\0';
|
||||
if(l == 0)
|
||||
break; /* end on blank line */
|
||||
if(line[0] == '#')
|
||||
continue; /* skip comments */
|
||||
equal = strchr(line, '=');
|
||||
if(equal == NULL) {
|
||||
fprintf(stderr, "Warning, line does not contain '=' : %s\n", line);
|
||||
continue;
|
||||
}
|
||||
*equal = '\0';
|
||||
name = line;
|
||||
while(*name == ' ' || *name == '\t')
|
||||
name++;
|
||||
l = strlen(name);
|
||||
while((l > 0) && (name[l-1] == ' ' || name[l-1] == '\t'))
|
||||
name[--l] = '\0';
|
||||
value = equal + 1;
|
||||
while(*value == ' ' || *value == '\t')
|
||||
value++;
|
||||
if(strcmp(name, "controlurl") == 0)
|
||||
parsedvalue = s->controlurl;
|
||||
else if(strcmp(name, "eventsuburl") == 0)
|
||||
parsedvalue = s->eventsuburl;
|
||||
else if(strcmp(name, "scpdurl") == 0)
|
||||
parsedvalue = s->scpdurl;
|
||||
else if(strcmp(name, "servicetype") == 0)
|
||||
parsedvalue = s->servicetype;
|
||||
else {
|
||||
fprintf(stderr, "unknown field '%s'\n", name);
|
||||
continue;
|
||||
}
|
||||
if(0 != strcmp(parsedvalue, value)) {
|
||||
fprintf(stderr, "difference : '%s' != '%s'\n", parsedvalue, value);
|
||||
n++;
|
||||
}
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
int compare_igd(struct IGDdatas * p, FILE * f)
|
||||
{
|
||||
int n = 0;
|
||||
char line[1024];
|
||||
struct IGDdatas_service * s;
|
||||
|
||||
while(fgets(line, sizeof(line), f)) {
|
||||
char * colon;
|
||||
int l = (int)strlen(line);
|
||||
while((l > 0) && (line[l-1] == '\r' || (line[l-1] == '\n')))
|
||||
line[--l] = '\0';
|
||||
if(l == 0 || line[0] == '#')
|
||||
continue; /* skip blank lines and comments */
|
||||
colon = strchr(line, ':');
|
||||
if(colon == NULL) {
|
||||
fprintf(stderr, "Warning, no ':' : %s\n", line);
|
||||
continue;
|
||||
}
|
||||
s = NULL;
|
||||
*colon = '\0';
|
||||
if(strcmp(line, "CIF") == 0)
|
||||
s = &p->CIF;
|
||||
else if(strcmp(line, "first") == 0)
|
||||
s = &p->first;
|
||||
else if(strcmp(line, "second") == 0)
|
||||
s = &p->second;
|
||||
else if(strcmp(line, "IPv6FC") == 0)
|
||||
s = &p->IPv6FC;
|
||||
else {
|
||||
s = NULL;
|
||||
fprintf(stderr, "*** unknown service '%s' ***\n", line);
|
||||
n++;
|
||||
continue;
|
||||
}
|
||||
n += compare_service(s, f);
|
||||
}
|
||||
if(n > 0)
|
||||
fprintf(stderr, "*** %d difference%s ***\n", n, (n > 1) ? "s" : "");
|
||||
return n;
|
||||
}
|
||||
|
||||
int test_igd_desc_parse(char * buffer, int len, FILE * f)
|
||||
{
|
||||
int n;
|
||||
struct IGDdatas igd;
|
||||
struct xmlparser parser;
|
||||
struct UPNPUrls urls;
|
||||
|
||||
memset(&igd, 0, sizeof(struct IGDdatas));
|
||||
memset(&parser, 0, sizeof(struct xmlparser));
|
||||
parser.xmlstart = buffer;
|
||||
|
@ -27,13 +124,16 @@ int test_igd_desc_parse(char * buffer, int len)
|
|||
parser.endeltfunc = IGDendelt;
|
||||
parser.datafunc = IGDdata;
|
||||
parsexml(&parser);
|
||||
#ifdef DEBUG
|
||||
printIGD(&igd);
|
||||
#endif /* DEBUG */
|
||||
GetUPNPUrls(&urls, &igd, "http://fake/desc/url/file.xml", 0);
|
||||
printf("ipcondescURL='%s'\n", urls.ipcondescURL);
|
||||
printf("controlURL='%s'\n", urls.controlURL);
|
||||
printf("controlURL_CIF='%s'\n", urls.controlURL_CIF);
|
||||
n = f ? compare_igd(&igd, f) : 0;
|
||||
FreeUPNPUrls(&urls);
|
||||
return 0;
|
||||
return n;
|
||||
}
|
||||
|
||||
int main(int argc, char * * argv)
|
||||
|
@ -41,9 +141,9 @@ int main(int argc, char * * argv)
|
|||
FILE * f;
|
||||
char * buffer;
|
||||
int len;
|
||||
int r = 0;
|
||||
int r;
|
||||
if(argc<2) {
|
||||
fprintf(stderr, "Usage: %s file.xml\n", argv[0]);
|
||||
fprintf(stderr, "Usage: %s file.xml [file.values]\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
f = fopen(argv[1], "r");
|
||||
|
@ -55,10 +155,33 @@ int main(int argc, char * * argv)
|
|||
len = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
buffer = malloc(len);
|
||||
fread(buffer, 1, len, f);
|
||||
if(!buffer) {
|
||||
fprintf(stderr, "Memory allocation error.\n");
|
||||
fclose(f);
|
||||
return 1;
|
||||
}
|
||||
r = (int)fread(buffer, 1, len, f);
|
||||
if(r != len) {
|
||||
fprintf(stderr, "Failed to read file %s. %d out of %d bytes.\n",
|
||||
argv[1], r, len);
|
||||
fclose(f);
|
||||
free(buffer);
|
||||
return 1;
|
||||
}
|
||||
fclose(f);
|
||||
r = test_igd_desc_parse(buffer, len);
|
||||
f = NULL;
|
||||
if(argc > 2) {
|
||||
f = fopen(argv[2], "r");
|
||||
if(!f) {
|
||||
fprintf(stderr, "Cannot open %s for reading.\n", argv[2]);
|
||||
free(buffer);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
r = test_igd_desc_parse(buffer, len, f);
|
||||
free(buffer);
|
||||
if(f)
|
||||
fclose(f);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue