source: trunk/third-party/miniupnp/igd_desc_parse.c @ 11577

Last change on this file since 11577 was 11577, checked in by livings124, 11 years ago

update miniupnp to 1.4.20101221

File size: 3.9 KB
Line 
1/* $Id: igd_desc_parse.c,v 1.11 2010/12/11 17:56:51 nanard Exp $ */
2/* Project : miniupnp
3 * http://miniupnp.free.fr/
4 * Author : Thomas Bernard
5 * Copyright (c) 2005-2010 Thomas Bernard
6 * This software is subject to the conditions detailed in the
7 * LICENCE file provided in this distribution. */
8
9#include "igd_desc_parse.h"
10#include <stdio.h>
11#include <string.h>
12
13/* Start element handler :
14 * update nesting level counter and copy element name */
15void IGDstartelt(void * d, const char * name, int l)
16{
17        struct IGDdatas * datas = (struct IGDdatas *)d;
18        memcpy( datas->cureltname, name, l);
19        datas->cureltname[l] = '\0';
20        datas->level++;
21        if( (l==7) && !memcmp(name, "service", l) ) {
22                datas->tmp.controlurl[0] = '\0';
23                datas->tmp.eventsuburl[0] = '\0';
24                datas->tmp.scpdurl[0] = '\0';
25                datas->tmp.servicetype[0] = '\0';
26        }
27}
28
29/* End element handler :
30 * update nesting level counter and update parser state if
31 * service element is parsed */
32void IGDendelt(void * d, const char * name, int l)
33{
34        struct IGDdatas * datas = (struct IGDdatas *)d;
35        datas->level--;
36        /*printf("endelt %2d %.*s\n", datas->level, l, name);*/
37        if( (l==7) && !memcmp(name, "service", l) )
38        {
39                /*
40                if( datas->state < 1
41                        && !strcmp(datas->servicetype,
42                                //      "urn:schemas-upnp-org:service:WANIPConnection:1") )
43                                "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1"))
44                        datas->state ++;
45                */
46                if(0==strcmp(datas->tmp.servicetype,
47                                "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1")) {
48                        memcpy(&datas->CIF, &datas->tmp, sizeof(struct IGDdatas_service));
49                } else if(0==strcmp(datas->tmp.servicetype,
50                                "urn:schemas-upnp-org:service:WANIPConnection:1")
51                                 || 0==strcmp(datas->tmp.servicetype,
52                                "urn:schemas-upnp-org:service:WANPPPConnection:1") ) {
53                        if(datas->first.servicetype[0] == '\0') {
54                                memcpy(&datas->first, &datas->tmp, sizeof(struct IGDdatas_service));
55                        } else {
56                                memcpy(&datas->second, &datas->tmp, sizeof(struct IGDdatas_service));
57                        }
58                }
59        }
60}
61
62/* Data handler :
63 * copy data depending on the current element name and state */
64void IGDdata(void * d, const char * data, int l)
65{
66        struct IGDdatas * datas = (struct IGDdatas *)d;
67        char * dstmember = 0;
68        /*printf("%2d %s : %.*s\n",
69           datas->level, datas->cureltname, l, data);   */
70        if( !strcmp(datas->cureltname, "URLBase") )
71                dstmember = datas->urlbase;
72        else if( !strcmp(datas->cureltname, "serviceType") )
73                dstmember = datas->tmp.servicetype;
74        else if( !strcmp(datas->cureltname, "controlURL") )
75                dstmember = datas->tmp.controlurl;
76        else if( !strcmp(datas->cureltname, "eventSubURL") )
77                dstmember = datas->tmp.eventsuburl;
78        else if( !strcmp(datas->cureltname, "SCPDURL") )
79                dstmember = datas->tmp.scpdurl;
80/*      else if( !strcmp(datas->cureltname, "deviceType") )
81                dstmember = datas->devicetype_tmp;*/
82        if(dstmember)
83        {
84                if(l>=MINIUPNPC_URL_MAXSIZE)
85                        l = MINIUPNPC_URL_MAXSIZE-1;
86                memcpy(dstmember, data, l);
87                dstmember[l] = '\0';
88        }
89}
90
91void printIGD(struct IGDdatas * d)
92{
93        printf("urlbase = '%s'\n", d->urlbase);
94        printf("WAN Device (Common interface config) :\n");
95        /*printf(" deviceType = '%s'\n", d->CIF.devicetype);*/
96        printf(" serviceType = '%s'\n", d->CIF.servicetype);
97        printf(" controlURL = '%s'\n", d->CIF.controlurl);
98        printf(" eventSubURL = '%s'\n", d->CIF.eventsuburl);
99        printf(" SCPDURL = '%s'\n", d->CIF.scpdurl);
100        printf("primary WAN Connection Device (IP or PPP Connection):\n");
101        /*printf(" deviceType = '%s'\n", d->first.devicetype);*/
102        printf(" servicetype = '%s'\n", d->first.servicetype);
103        printf(" controlURL = '%s'\n", d->first.controlurl);
104        printf(" eventSubURL = '%s'\n", d->first.eventsuburl);
105        printf(" SCPDURL = '%s'\n", d->first.scpdurl);
106        printf("secondary WAN Connection Device (IP or PPP Connection):\n");
107        /*printf(" deviceType = '%s'\n", d->second.devicetype);*/
108        printf(" servicetype = '%s'\n", d->second.servicetype);
109        printf(" controlURL = '%s'\n", d->second.controlurl);
110        printf(" eventSubURL = '%s'\n", d->second.eventsuburl);
111        printf(" SCPDURL = '%s'\n", d->second.scpdurl);
112}
113
114
Note: See TracBrowser for help on using the repository browser.