1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
/* $Id: testminixml.c,v 1.9 2013/05/14 19:50:49 nanard Exp $
* MiniUPnP project
* Website : http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* Author : Thomas Bernard.
* Copyright (c) 2005-2013 Thomas Bernard
*
* testminixml.c
* test program for the "minixml" functions.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "minixml.h"
#include "igd_desc_parse.h"
/* ---------------------------------------------------------------------- */
void printeltname1(void * d, const char * name, int l)
{
int i;
(void)d;
printf("element ");
for(i=0;i<l;i++)
putchar(name[i]);
}
void printeltname2(void * d, const char * name, int l)
{
int i;
(void)d;
putchar('/');
for(i=0;i<l;i++)
putchar(name[i]);
putchar('\n');
}
void printdata(void *d, const char * data, int l)
{
int i;
(void)d;
printf("data : ");
for(i=0;i<l;i++)
putchar(data[i]);
putchar('\n');
}
void burptest(const char * buffer, int bufsize)
{
struct IGDdatas data;
struct xmlparser parser;
/*objet IGDdatas */
memset(&data, 0, sizeof(struct IGDdatas));
/* objet xmlparser */
parser.xmlstart = buffer;
parser.xmlsize = bufsize;
parser.data = &data;
/*parser.starteltfunc = printeltname1;
parser.endeltfunc = printeltname2;
parser.datafunc = printdata; */
parser.starteltfunc = IGDstartelt;
parser.endeltfunc = IGDendelt;
parser.datafunc = IGDdata;
parsexml(&parser);
printIGD(&data);
}
/* ----- main ---- */
#define XML_MAX_SIZE (8192)
int main(int argc, char * * argv)
{
FILE * f;
char buffer[XML_MAX_SIZE];
int bufsize;
if(argc<2)
{
printf("usage:\t%s file.xml\n", argv[0]);
return 1;
}
f = fopen(argv[1], "r");
if(!f)
{
printf("cannot open file %s\n", argv[1]);
return 1;
}
bufsize = (int)fread(buffer, 1, XML_MAX_SIZE, f);
fclose(f);
burptest(buffer, bufsize);
return 0;
}
|