|
a |
|
b/libupnpp/soaphelp.cxx |
|
|
1 |
/* Copyright (C) 2014 J.F.Dockes
|
|
|
2 |
* This program is free software; you can redistribute it and/or modify
|
|
|
3 |
* it under the terms of the GNU General Public License as published by
|
|
|
4 |
* the Free Software Foundation; either version 2 of the License, or
|
|
|
5 |
* (at your option) any later version.
|
|
|
6 |
*
|
|
|
7 |
* This program is distributed in the hope that it will be useful,
|
|
|
8 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
9 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
10 |
* GNU General Public License for more details.
|
|
|
11 |
*
|
|
|
12 |
* You should have received a copy of the GNU General Public License
|
|
|
13 |
* along with this program; if not, write to the
|
|
|
14 |
* Free Software Foundation, Inc.,
|
|
|
15 |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
16 |
*/
|
|
|
17 |
|
|
|
18 |
#include <iostream>
|
|
|
19 |
using namespace std;
|
|
|
20 |
|
|
|
21 |
#include "soaphelp.hxx"
|
|
|
22 |
|
|
|
23 |
|
|
|
24 |
/* Example Soap XML doc passed by libupnp is like:
|
|
|
25 |
<ns0:SetMute>
|
|
|
26 |
<InstanceID>0</InstanceID>
|
|
|
27 |
<Channel>Master</Channel>
|
|
|
28 |
<DesiredMute>False</DesiredMute>
|
|
|
29 |
</ns0:SetMute>
|
|
|
30 |
*/
|
|
|
31 |
bool decodeSoap(const char *callnm, IXML_Document *actReq, SoapCall *res)
|
|
|
32 |
{
|
|
|
33 |
bool ret = false;
|
|
|
34 |
IXML_NodeList* nl = 0;
|
|
|
35 |
IXML_Node* topNode =
|
|
|
36 |
ixmlNode_getFirstChild((IXML_Node *)actReq);
|
|
|
37 |
if (topNode == 0) {
|
|
|
38 |
cerr << "decodeSoap: Empty Action request (no topNode) ??" << endl;
|
|
|
39 |
return false;
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
nl = ixmlNode_getChildNodes(topNode);
|
|
|
43 |
if (nl == 0) {
|
|
|
44 |
cerr << "decodeSoap: empty Action request (no childs) ??" << endl;
|
|
|
45 |
return false;
|
|
|
46 |
}
|
|
|
47 |
for (unsigned long i = 0; i < ixmlNodeList_length(nl); i++) {
|
|
|
48 |
IXML_Node *cld = ixmlNodeList_item(nl, i);
|
|
|
49 |
if (cld == 0) {
|
|
|
50 |
cerr << "decodeSoap: got null node from nodelist??" << endl;
|
|
|
51 |
goto out;
|
|
|
52 |
}
|
|
|
53 |
const char *name = ixmlNode_getNodeName(cld);
|
|
|
54 |
if (cld == 0) {
|
|
|
55 |
cerr << "decodeSoap: got null name ??" << endl;
|
|
|
56 |
goto out;
|
|
|
57 |
}
|
|
|
58 |
IXML_Node *txtnode = ixmlNode_getFirstChild(cld);
|
|
|
59 |
if (txtnode == 0) {
|
|
|
60 |
cerr << "decodeSoap: got null name ??" << endl;
|
|
|
61 |
goto out;
|
|
|
62 |
}
|
|
|
63 |
const char *value = ixmlNode_getNodeValue(txtnode);
|
|
|
64 |
// Can we get an empty value here ?
|
|
|
65 |
if (value == 0)
|
|
|
66 |
value = "";
|
|
|
67 |
res->args[name] = value;
|
|
|
68 |
}
|
|
|
69 |
res->name = callnm;
|
|
|
70 |
ret = true;
|
|
|
71 |
out:
|
|
|
72 |
if (nl)
|
|
|
73 |
ixmlNodeList_free(nl);
|
|
|
74 |
return ret;
|
|
|
75 |
}
|