Annotation of embedaddon/miniupnpd/testupnpdescgen.c, revision 1.1.1.1

1.1       misho       1: /* $Id: testupnpdescgen.c,v 1.18 2008/07/10 09:18:34 nanard 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: 
                     15: char uuidvalue[] = "uuid:12345678-0000-0000-0000-00000000abcd";
                     16: char serialnumber[] = "12345678";
                     17: char modelnumber[] = "1";
                     18: char presentationurl[] = "http://192.168.0.1:8080/";
                     19: 
                     20: char * use_ext_ip_addr = NULL;
                     21: const char * ext_if_name = "eth0";
                     22: 
                     23: int getifaddr(const char * ifname, char * buf, int len)
                     24: {
                     25:        strncpy(buf, "1.2.3.4", len);
                     26:        return 0;
                     27: }
                     28: 
                     29: int upnp_get_portmapping_number_of_entries()
                     30: {
                     31:        return 42;
                     32: }
                     33: 
                     34: /* To be improved */
                     35: int
                     36: xml_pretty_print(const char * s, int len, FILE * f)
                     37: {
                     38:        int n = 0, i;
                     39:        int elt_close = 0;
                     40:        int c, indent = 0;
                     41:        while(len > 0)
                     42:        {
                     43:                c = *(s++);     len--;
                     44:                switch(c)
                     45:                {
                     46:                case '<':
                     47:                        if(len>0 && *s == '/')
                     48:                                elt_close++;
                     49:                        else if(len>0 && *s == '?')
                     50:                                elt_close = 1;
                     51:                        else
                     52:                                elt_close = 0;
                     53:                        if(elt_close!=1)
                     54:                        {
                     55:                                if(elt_close > 1)
                     56:                                        indent--;
                     57:                                fputc('\n', f); n++;
                     58:                                for(i=indent; i>0; i--)
                     59:                                        fputc(' ', f);
                     60:                                n += indent;
                     61:                        }
                     62:                        fputc(c, f); n++;
                     63:                        break;
                     64:                case '>':
                     65:                        fputc(c, f); n++;
                     66:                        if(elt_close==1)
                     67:                        {
                     68:                                /*fputc('\n', f); n++; */
                     69:                                //elt_close = 0;
                     70:                                if(indent > 0)
                     71:                                        indent--;
                     72:                        }
                     73:                        else if(elt_close == 0)
                     74:                                indent++;
                     75:                        break;
                     76:                default:
                     77:                        fputc(c, f); n++;
                     78:                }
                     79:        }
                     80:        return n;
                     81: }
                     82: 
                     83: /* stupid test */
                     84: const char * str1 = "Prefix123String";
                     85: const char * str2 = "123String";
                     86: 
                     87: void stupid_test()
                     88: {
                     89:        printf("str1:'%s' str2:'%s'\n", str1, str2);
                     90:        printf("str1:%p str2:%p str2-str1:%ld\n", str1, str2, (long)(str2-str1));
                     91: }
                     92: 
                     93: /* main */
                     94: 
                     95: int
                     96: main(int argc, char * * argv)
                     97: {
                     98:        char * rootDesc;
                     99:        int rootDescLen;
                    100:        char * s;
                    101:        int l;
                    102:        rootDesc = genRootDesc(&rootDescLen);
                    103:        xml_pretty_print(rootDesc, rootDescLen, stdout);
                    104:        free(rootDesc);
                    105:        printf("\n-------------\n");
                    106:        s = genWANIPCn(&l);
                    107:        xml_pretty_print(s, l, stdout);
                    108:        free(s);
                    109:        printf("\n-------------\n");
                    110:        s = genWANCfg(&l);
                    111:        xml_pretty_print(s, l, stdout);
                    112:        free(s);
                    113:        printf("\n-------------\n");
                    114: #ifdef ENABLE_L3F_SERVICE
                    115:        s = genL3F(&l);
                    116:        xml_pretty_print(s, l, stdout);
                    117:        free(s);
                    118:        printf("\n-------------\n");
                    119: #endif
                    120: #ifdef ENABLE_EVENTS
                    121:        s = getVarsWANIPCn(&l);
                    122:        xml_pretty_print(s, l, stdout);
                    123:        free(s);
                    124:        printf("\n-------------\n");
                    125:        s = getVarsWANCfg(&l);
                    126:        xml_pretty_print(s, l, stdout);
                    127:        free(s);
                    128:        printf("\n-------------\n");
                    129: #ifdef ENABLE_L3F_SERVICE
                    130:        s = getVarsL3F(&l);
                    131:        xml_pretty_print(s, l, stdout);
                    132:        free(s);
                    133:        printf("\n-------------\n");
                    134: #endif
                    135: #endif
                    136: /*
                    137:        stupid_test();
                    138: */
                    139:        return 0;
                    140: }
                    141: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>