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