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