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