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/"; 20unsigned int updateID = 0; 21 22int getifaddr(const char * ifname, char * buf, int len) 23{ 24 strncpy(buf, "1.2.3.4", len); 25 return 0; 26} 27 28int upnp_get_portmapping_number_of_entries() 29{ 30 return 42; 31} 32 33/* To be improved */ 34int 35xml_pretty_print(const char * s, int len, FILE * f) 36{ 37 int n = 0, i; 38 int elt_close = 0; 39 int c, indent = 0; 40 while(len > 0) 41 { 42 c = *(s++); len--; 43 switch(c) 44 { 45 case '<': 46 if(len>0 && *s == '/') 47 elt_close++; 48 else if(len>0 && *s == '?') 49 elt_close = 1; 50 else 51 elt_close = 0; 52 if(elt_close!=1) 53 { 54 if(elt_close > 1) 55 indent--; 56 fputc('\n', f); n++; 57 for(i=indent; i>0; i--) 58 fputc(' ', f); 59 n += indent; 60 } 61 fputc(c, f); n++; 62 break; 63 case '>': 64 fputc(c, f); n++; 65 if(elt_close==1) 66 { 67 /*fputc('\n', f); n++; */ 68 //elt_close = 0; 69 if(indent > 0) 70 indent--; 71 } 72 else if(elt_close == 0) 73 indent++; 74 break; 75 default: 76 fputc(c, f); n++; 77 } 78 } 79 return n; 80} 81 82/* stupid test */ 83const char * str1 = "Prefix123String"; 84const char * str2 = "123String"; 85 86void stupid_test() 87{ 88 printf("str1:'%s' str2:'%s'\n", str1, str2); 89 printf("str1:%p str2:%p str2-str1:%ld\n", str1, str2, (long)(str2-str1)); 90} 91 92/* main */ 93 94int 95main(int argc, char * * argv) 96{ 97 char * rootDesc; 98 int rootDescLen; 99 char * s; 100 int l; 101 rootDesc = genRootDesc(&rootDescLen); 102 xml_pretty_print(rootDesc, rootDescLen, stdout); 103 free(rootDesc); 104 printf("\n----------------\n"); 105 printf("ContentDirectory\n"); 106 printf("----------------\n"); 107 s = genContentDirectory(&l); 108 xml_pretty_print(s, l, stdout); 109 free(s); 110 printf("\n----------------\n"); 111 printf("ConnectionManager\n"); 112 printf("----------------\n"); 113 s = genConnectionManager(&l); 114 xml_pretty_print(s, l, stdout); 115 free(s); 116 printf("\n----------------\n"); 117 printf("X_MS_MRR\n"); 118 printf("----------------\n"); 119 s = genX_MS_MediaReceiverRegistrar(&l); 120 xml_pretty_print(s, l, stdout); 121 free(s); 122 printf("\n-------------\n"); 123/* 124 stupid_test(); 125*/ 126 return 0; 127} 128 129