1: /* $Id: testupnpdescgen.c,v 1.1.1.3 2013/07/22 00:32:35 misho Exp $ */
2: /* MiniUPnP project
3: * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
4: * (c) 2006-2012 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: /* for mkdir */
12: #include <sys/stat.h>
13: #include <sys/types.h>
14: #include <errno.h>
15:
16: #include "macros.h"
17: #include "config.h"
18: #include "upnpdescgen.h"
19:
20: char uuidvalue[] = "uuid:12345678-0000-0000-0000-00000000abcd";
21: char serialnumber[] = "12345678";
22: char modelnumber[] = "1";
23: char presentationurl[] = "http://192.168.0.1:8080/";
24: /*char presentationurl[] = "";*/
25: char friendly_name[] = OS_NAME " router";
26:
27: char * use_ext_ip_addr = NULL;
28: const char * ext_if_name = "eth0";
29:
30: #ifdef ENABLE_6FC_SERVICE
31: int ipv6fc_firewall_enabled = 1;
32: int ipv6fc_inbound_pinhole_allowed = 1;
33: #endif
34:
35: int getifaddr(const char * ifname, char * buf, int len)
36: {
37: UNUSED(ifname);
38: strncpy(buf, "1.2.3.4", len);
39: return 0;
40: }
41:
42: int upnp_get_portmapping_number_of_entries(void)
43: {
44: return 42;
45: }
46:
47: int get_wan_connection_status(const char * ifname)
48: {
49: UNUSED(ifname);
50: return 2;
51: }
52:
53: /* To be improved */
54: int
55: xml_pretty_print(const char * s, int len, FILE * f)
56: {
57: int n = 0, i;
58: int elt_close = 0;
59: int c, indent = 0;
60:
61: if(!s)
62: return n;
63: while(len > 0)
64: {
65: c = *(s++); len--;
66: switch(c)
67: {
68: case '<':
69: if(len>0 && *s == '/')
70: elt_close++;
71: else if(len>0 && *s == '?')
72: elt_close = 1;
73: else
74: elt_close = 0;
75: if(elt_close!=1)
76: {
77: if(elt_close > 1)
78: indent--;
79: fputc('\n', f); n++;
80: for(i=indent; i>0; i--)
81: fputc(' ', f);
82: n += indent;
83: }
84: fputc(c, f); n++;
85: break;
86: case '>':
87: fputc(c, f); n++;
88: if(elt_close==1)
89: {
90: /*fputc('\n', f); n++; */
91: /* elt_close = 0; */
92: if(indent > 0)
93: indent--;
94: }
95: else if(elt_close == 0)
96: indent++;
97: break;
98: case '\n':
99: /* remove existing LF */
100: break;
101: default:
102: fputc(c, f); n++;
103: }
104: }
105: return n;
106: }
107:
108: /* stupid test */
109: const char * str1 = "Prefix123String";
110: const char * str2 = "123String";
111:
112: void stupid_test(void)
113: {
114: printf("str1:'%s' str2:'%s'\n", str1, str2);
115: printf("str1:%p str2:%p str2-str1:%ld\n", str1, str2, (long)(str2-str1));
116: }
117:
118: /* main */
119:
120: int
121: main(int argc, char * * argv)
122: {
123: char * rootDesc;
124: int rootDescLen;
125: char * s;
126: int l;
127: FILE * f;
128: UNUSED(argc);
129: UNUSED(argv);
130:
131: if(mkdir("testdescs", 0777) < 0) {
132: if(errno != EEXIST) {
133: perror("mkdir");
134: }
135: }
136: printf("Root Description :\n");
137: rootDesc = genRootDesc(&rootDescLen);
138: xml_pretty_print(rootDesc, rootDescLen, stdout);
139: f = fopen("testdescs/rootdesc.xml", "w");
140: if(f) {
141: xml_pretty_print(rootDesc, rootDescLen, f);
142: fclose(f);
143: }
144: free(rootDesc);
145: printf("\n-------------\n");
146: printf("WANIPConnection Description :\n");
147: s = genWANIPCn(&l);
148: xml_pretty_print(s, l, stdout);
149: f = fopen("testdescs/wanipc_scpd.xml", "w");
150: if(f) {
151: xml_pretty_print(s, l, f);
152: fclose(f);
153: }
154: free(s);
155: printf("\n-------------\n");
156: printf("WANConfig Description :\n");
157: s = genWANCfg(&l);
158: xml_pretty_print(s, l, stdout);
159: f = fopen("testdescs/wanconfig_scpd.xml", "w");
160: if(f) {
161: xml_pretty_print(s, l, f);
162: fclose(f);
163: }
164: free(s);
165: printf("\n-------------\n");
166: #ifdef ENABLE_L3F_SERVICE
167: printf("Layer3Forwarding service :\n");
168: s = genL3F(&l);
169: xml_pretty_print(s, l, stdout);
170: f = fopen("testdescs/l3f_scpd.xml", "w");
171: if(f) {
172: xml_pretty_print(s, l, f);
173: fclose(f);
174: }
175: free(s);
176: printf("\n-------------\n");
177: #endif
178: #ifdef ENABLE_6FC_SERVICE
179: printf("WANIPv6FirewallControl service :\n");
180: s = gen6FC(&l);
181: xml_pretty_print(s, l, stdout);
182: f = fopen("testdescs/wanipv6fc_scpd.xml", "w");
183: if(f) {
184: xml_pretty_print(s, l, f);
185: fclose(f);
186: }
187: free(s);
188: printf("\n-------------\n");
189: #endif
190: #ifdef ENABLE_DP_SERVICE
191: printf("DeviceProtection service :\n");
192: s = genDP(&l);
193: xml_pretty_print(s, l, stdout);
194: f = fopen("testdescs/dp_scpd.xml", "w");
195: if(f) {
196: xml_pretty_print(s, l, f);
197: fclose(f);
198: }
199: free(s);
200: printf("\n-------------\n");
201: #endif
202: #ifdef ENABLE_EVENTS
203: s = getVarsWANIPCn(&l);
204: xml_pretty_print(s, l, stdout);
205: free(s);
206: printf("\n-------------\n");
207: s = getVarsWANCfg(&l);
208: xml_pretty_print(s, l, stdout);
209: free(s);
210: printf("\n-------------\n");
211: #ifdef ENABLE_L3F_SERVICE
212: s = getVarsL3F(&l);
213: xml_pretty_print(s, l, stdout);
214: free(s);
215: printf("\n-------------\n");
216: #ifdef ENABLE_6FC_SERVICE
217: s = getVars6FC(&l);
218: xml_pretty_print(s, l, stdout);
219: free(s);
220: printf("\n-------------\n");
221: #endif
222: #ifdef ENABLE_DP_SERVICE
223: s = getVarsDP(&l);
224: xml_pretty_print(s, l, stdout);
225: free(s);
226: printf("\n-------------\n");
227: #endif
228: #endif
229: #endif
230: /*
231: stupid_test();
232: */
233: return 0;
234: }
235:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>