1/* $Id: testupnpdescgen.c,v 1.7 2009/05/21 01:20:31 jmaggard Exp $ */
2/* MiniUPnP project
3 * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
4 * (c) 2006-2008 Thomas Bernard
5 * This software is subject to the conditions detailed
6 * in the LICENCE file provided within the distribution */
7
8#include <stdlib.h>
9#include <stdio.h>
10#include <string.h>
11
12#include "config.h"
13#include "upnpdescgen.h"
14
15char uuidvalue[] = "uuid:12345678-0000-0000-0000-00000000abcd";
16char friendly_name[] = "localhost: system_type";
17char serialnumber[] = "12345678";
18char modelnumber[] = "1";
19char presentationurl[] = "http://192.168.0.1:8080/";
20char device_url[] = "http://192.168.0.1:8080/";
21unsigned int updateID = 0;
22
23int getifaddr(const char * ifname, char * buf, int len)
24{
25	strncpy(buf, "1.2.3.4", len);
26	return 0;
27}
28
29int upnp_get_portmapping_number_of_entries()
30{
31	return 42;
32}
33
34/* To be improved */
35int
36xml_pretty_print(const char * s, int len, FILE * f)
37{
38	int n = 0, i;
39	int elt_close = 0;
40	int c, indent = 0;
41	while(len > 0)
42	{
43		c = *(s++);	len--;
44		switch(c)
45		{
46		case '<':
47			if(len>0 && *s == '/')
48				elt_close++;
49			else if(len>0 && *s == '?')
50				elt_close = 1;
51			else
52				elt_close = 0;
53			if(elt_close!=1)
54			{
55				if(elt_close > 1)
56					indent--;
57				fputc('\n', f); n++;
58				for(i=indent; i>0; i--)
59					fputc(' ', f);
60				n += indent;
61			}
62			fputc(c, f); n++;
63			break;
64		case '>':
65			fputc(c, f); n++;
66			if(elt_close==1)
67			{
68				/*fputc('\n', f); n++; */
69				//elt_close = 0;
70				if(indent > 0)
71					indent--;
72			}
73			else if(elt_close == 0)
74				indent++;
75			break;
76		default:
77			fputc(c, f); n++;
78		}
79	}
80	return n;
81}
82
83/* stupid test */
84const char * str1 = "Prefix123String";
85const char * str2 = "123String";
86
87void stupid_test()
88{
89	printf("str1:'%s' str2:'%s'\n", str1, str2);
90	printf("str1:%p str2:%p str2-str1:%ld\n", str1, str2, (long)(str2-str1));
91}
92
93/* main */
94
95int
96main(int argc, char * * argv)
97{
98	char * rootDesc;
99	int rootDescLen;
100	char * s;
101	int l;
102	rootDesc = genRootDesc(&rootDescLen);
103	xml_pretty_print(rootDesc, rootDescLen, stdout);
104	free(rootDesc);
105	printf("\n----------------\n");
106	printf("ContentDirectory\n");
107	printf("----------------\n");
108	s = genContentDirectory(&l);
109	xml_pretty_print(s, l, stdout);
110	free(s);
111	printf("\n----------------\n");
112	printf("ConnectionManager\n");
113	printf("----------------\n");
114	s = genConnectionManager(&l);
115	xml_pretty_print(s, l, stdout);
116	free(s);
117	printf("\n----------------\n");
118	printf("X_MS_MRR\n");
119	printf("----------------\n");
120	s = genX_MS_MediaReceiverRegistrar(&l);
121	xml_pretty_print(s, l, stdout);
122	free(s);
123	printf("\n-------------\n");
124/*
125	stupid_test();
126*/
127	return 0;
128}
129
130