Merge remote branch 'remotes/origin/Teaman-IPTraffic' into Teaman-ND
[tomato.git] / release / src / router / minidlna / testupnpdescgen.c
blobdb8b4e27336a318dc40bb6ed7f4bb500e3f47298
1 /* $Id: testupnpdescgen.c,v 1.8 2010/11/11 23:48:13 jmaggard Exp $ */
2 /* MiniUPnP project
3 * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
5 * Copyright (c) 2006-2008, Thomas Bernard
6 * All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * * The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <string.h>
34 #include "config.h"
35 #include "upnpdescgen.h"
37 char uuidvalue[] = "uuid:12345678-0000-0000-0000-00000000abcd";
38 char friendly_name[] = "localhost: system_type";
39 char serialnumber[] = "12345678";
40 char modelnumber[] = "1";
41 char presentationurl[] = "http://192.168.0.1:8080/";
42 unsigned int updateID = 0;
44 int getifaddr(const char * ifname, char * buf, int len)
46 strncpy(buf, "1.2.3.4", len);
47 return 0;
50 int upnp_get_portmapping_number_of_entries()
52 return 42;
55 /* To be improved */
56 int
57 xml_pretty_print(const char * s, int len, FILE * f)
59 int n = 0, i;
60 int elt_close = 0;
61 int c, indent = 0;
62 while(len > 0)
64 c = *(s++); len--;
65 switch(c)
67 case '<':
68 if(len>0 && *s == '/')
69 elt_close++;
70 else if(len>0 && *s == '?')
71 elt_close = 1;
72 else
73 elt_close = 0;
74 if(elt_close!=1)
76 if(elt_close > 1)
77 indent--;
78 fputc('\n', f); n++;
79 for(i=indent; i>0; i--)
80 fputc(' ', f);
81 n += indent;
83 fputc(c, f); n++;
84 break;
85 case '>':
86 fputc(c, f); n++;
87 if(elt_close==1)
89 /*fputc('\n', f); n++; */
90 //elt_close = 0;
91 if(indent > 0)
92 indent--;
94 else if(elt_close == 0)
95 indent++;
96 break;
97 default:
98 fputc(c, f); n++;
101 return n;
104 /* stupid test */
105 const char * str1 = "Prefix123String";
106 const char * str2 = "123String";
108 void stupid_test()
110 printf("str1:'%s' str2:'%s'\n", str1, str2);
111 printf("str1:%p str2:%p str2-str1:%ld\n", str1, str2, (long)(str2-str1));
114 /* main */
117 main(int argc, char * * argv)
119 char * rootDesc;
120 int rootDescLen;
121 char * s;
122 int l;
123 rootDesc = genRootDesc(&rootDescLen);
124 xml_pretty_print(rootDesc, rootDescLen, stdout);
125 free(rootDesc);
126 printf("\n----------------\n");
127 printf("ContentDirectory\n");
128 printf("----------------\n");
129 s = genContentDirectory(&l);
130 xml_pretty_print(s, l, stdout);
131 free(s);
132 printf("\n----------------\n");
133 printf("ConnectionManager\n");
134 printf("----------------\n");
135 s = genConnectionManager(&l);
136 xml_pretty_print(s, l, stdout);
137 free(s);
138 printf("\n----------------\n");
139 printf("X_MS_MRR\n");
140 printf("----------------\n");
141 s = genX_MS_MediaReceiverRegistrar(&l);
142 xml_pretty_print(s, l, stdout);
143 free(s);
144 printf("\n-------------\n");
146 stupid_test();
148 return 0;