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