~ubuntu-branches/ubuntu/hardy/transmission/hardy-updates

« back to all changes in this revision

Viewing changes to third-party/miniupnp/igd_desc_parse.c

  • Committer: Bazaar Package Importer
  • Author(s): Philipp Benner
  • Date: 2008-01-05 09:16:52 UTC
  • mto: This revision was merged to the branch mainline in revision 11.
  • Revision ID: james.westby@ubuntu.com-20080105091652-8cf0z4rb3pu8d6jt
Tags: upstream-1.00
ImportĀ upstreamĀ versionĀ 1.00

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: igd_desc_parse.c,v 1.7 2006/11/19 22:32:33 nanard Exp $ */
 
2
/* Project : miniupnp
 
3
 * http://miniupnp.free.fr/
 
4
 * Author : Thomas Bernard
 
5
 * Copyright (c) 2005 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 */
 
15
void 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
}
 
22
 
 
23
/* End element handler :
 
24
 * update nesting level counter and update parser state if
 
25
 * service element is parsed */
 
26
void IGDendelt(void * d, const char * name, int l)
 
27
{
 
28
        struct IGDdatas * datas = (struct IGDdatas *)d;
 
29
        datas->level--;
 
30
        /*printf("endelt %2d %.*s\n", datas->level, l, name);*/
 
31
        if( (l==7) && !memcmp(name, "service", l) )
 
32
        {
 
33
                /*datas->state++; */
 
34
                /*
 
35
                if( datas->state < 1
 
36
                        && !strcmp(datas->servicetype,
 
37
                                //      "urn:schemas-upnp-org:service:WANIPConnection:1") )
 
38
                                "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1"))
 
39
                        datas->state ++;
 
40
                */
 
41
                if(0==strcmp(datas->servicetype_CIF,
 
42
                                "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1"))
 
43
                        datas->state = 2;
 
44
                if(0==strcmp(datas->servicetype,
 
45
                                "urn:schemas-upnp-org:service:WANIPConnection:1") )
 
46
                        datas->state = 3;
 
47
/*              if(0==strcmp(datas->servicetype,
 
48
                                "urn:schemas-upnp-org:service:WANPPPConnection:1") )
 
49
                        datas->state = 4; */
 
50
        }
 
51
}
 
52
 
 
53
/* Data handler :
 
54
 * copy data depending on the current element name and state */
 
55
void IGDdata(void * d, const char * data, int l)
 
56
{
 
57
        struct IGDdatas * datas = (struct IGDdatas *)d;
 
58
        char * dstmember = 0;
 
59
        /*printf("%2d %s : %.*s\n",
 
60
           datas->level, datas->cureltname, l, data);   */
 
61
        if( !strcmp(datas->cureltname, "URLBase") )
 
62
                dstmember = datas->urlbase;
 
63
        else if(datas->state<=1)
 
64
        {
 
65
                if( !strcmp(datas->cureltname, "serviceType") )
 
66
                        dstmember = datas->servicetype_CIF;
 
67
                else if( !strcmp(datas->cureltname, "controlURL") )
 
68
                        dstmember = datas->controlurl_CIF;
 
69
                else if( !strcmp(datas->cureltname, "eventSubURL") )
 
70
                        dstmember = datas->eventsuburl_CIF;
 
71
                else if( !strcmp(datas->cureltname, "SCPDURL") )
 
72
                        dstmember = datas->scpdurl_CIF;
 
73
                else if( !strcmp(datas->cureltname, "deviceType") )
 
74
                        dstmember = datas->devicetype_CIF;
 
75
        }
 
76
        else if(datas->state==2)
 
77
        {
 
78
                if( !strcmp(datas->cureltname, "serviceType") )
 
79
                        dstmember = datas->servicetype;
 
80
                else if( !strcmp(datas->cureltname, "controlURL") )
 
81
                        dstmember = datas->controlurl;
 
82
                else if( !strcmp(datas->cureltname, "eventSubURL") )
 
83
                        dstmember = datas->eventsuburl;
 
84
                else if( !strcmp(datas->cureltname, "SCPDURL") )
 
85
                        dstmember = datas->scpdurl;
 
86
                else if( !strcmp(datas->cureltname, "deviceType") )
 
87
                        dstmember = datas->devicetype;
 
88
        }
 
89
        if(dstmember)
 
90
        {
 
91
                if(l>=MINIUPNPC_URL_MAXSIZE)
 
92
                        l = MINIUPNPC_URL_MAXSIZE-1;
 
93
                memcpy(dstmember, data, l);
 
94
                dstmember[l] = '\0';
 
95
        }
 
96
}
 
97
 
 
98
void printIGD(struct IGDdatas * d)
 
99
{
 
100
        printf("urlbase = %s\n", d->urlbase);
 
101
        printf("WAN Device (Common interface config) :\n");
 
102
        printf(" deviceType = %s\n", d->devicetype_CIF);
 
103
        printf(" serviceType = %s\n", d->servicetype_CIF);
 
104
        printf(" controlURL = %s\n", d->controlurl_CIF);
 
105
        printf(" eventSubURL = %s\n", d->eventsuburl_CIF);
 
106
        printf(" SCPDURL = %s\n", d->scpdurl_CIF);
 
107
        printf("WAN Connection Device :\n");
 
108
        printf(" deviceType = %s\n", d->devicetype);
 
109
        printf(" servicetype = %s\n", d->servicetype);
 
110
        printf(" controlURL = %s\n", d->controlurl);
 
111
        printf(" eventSubURL = %s\n", d->eventsuburl);
 
112
        printf(" SCPDURL = %s\n", d->scpdurl);
 
113
}
 
114
 
 
115