File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / miniupnpc / testigddescparse.c
Revision 1.1: download - view: text, annotated - select for diffs - revision graph
Tue Feb 21 23:16:22 2012 UTC (12 years, 4 months ago) by misho
CVS tags: MAIN, HEAD
Initial revision

    1: /* $Id: testigddescparse.c,v 1.1 2012/02/21 23:16:22 misho Exp $ */
    2: /* Project : miniupnp
    3:  * http://miniupnp.free.fr/
    4:  * Author : Thomas Bernard
    5:  * Copyright (c) 2008-2009 Thomas Bernard
    6:  * This software is subject to the conditions detailed in the
    7:  * LICENCE file provided in this distribution.
    8:  * */
    9: #include <stdio.h>
   10: #include <stdlib.h>
   11: #include <string.h>
   12: #include "igd_desc_parse.h"
   13: #include "minixml.h"
   14: #include "miniupnpc.h"
   15: 
   16: int test_igd_desc_parse(char * buffer, int len)
   17: {
   18: 	struct IGDdatas igd;
   19: 	struct xmlparser parser;
   20: 	struct UPNPUrls urls;
   21: 	memset(&igd, 0, sizeof(struct IGDdatas));
   22: 	memset(&parser, 0, sizeof(struct xmlparser));
   23: 	parser.xmlstart = buffer;
   24: 	parser.xmlsize = len;
   25: 	parser.data = &igd;
   26: 	parser.starteltfunc = IGDstartelt;
   27: 	parser.endeltfunc = IGDendelt;
   28: 	parser.datafunc = IGDdata; 
   29: 	parsexml(&parser);
   30: 	printIGD(&igd);
   31: 	GetUPNPUrls(&urls, &igd, "http://fake/desc/url/file.xml");
   32: 	printf("ipcondescURL='%s'\n", urls.ipcondescURL);
   33: 	printf("controlURL='%s'\n", urls.controlURL);
   34: 	printf("controlURL_CIF='%s'\n", urls.controlURL_CIF);
   35: 	FreeUPNPUrls(&urls);
   36: 	return 0;
   37: }
   38: 
   39: int main(int argc, char * * argv)
   40: {
   41: 	FILE * f;
   42: 	char * buffer;
   43: 	int len;
   44: 	int r = 0;
   45: 	if(argc<2) {
   46: 		fprintf(stderr, "Usage: %s file.xml\n", argv[0]);
   47: 		return 1;
   48: 	}
   49: 	f = fopen(argv[1], "r");
   50: 	if(!f) {
   51: 		fprintf(stderr, "Cannot open %s for reading.\n", argv[1]);
   52: 		return 1;
   53: 	}
   54: 	fseek(f, 0, SEEK_END);
   55: 	len = ftell(f);
   56: 	fseek(f, 0, SEEK_SET);
   57: 	buffer = malloc(len);
   58: 	fread(buffer, 1, len, f);
   59: 	fclose(f);
   60: 	r = test_igd_desc_parse(buffer, len);
   61: 	free(buffer);
   62: 	return r;
   63: }
   64: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>