Switch to unified view

a/libupnpp/soaphelp.cxx b/libupnpp/soaphelp.cxx
...
...
28
28
29
using namespace std;
29
using namespace std;
30
30
31
namespace UPnPP {
31
namespace UPnPP {
32
32
33
class SoapIncoming::Internal {
34
public:
35
    std::string name;
36
    std::map<std::string, std::string> args;
37
};
38
39
SoapIncoming::SoapIncoming() 
40
{
41
    if ((m = new Internal()) == 0) {
42
        LOGERR("SoapIncoming::SoapIncoming: out of memory" << endl);
43
        return;
44
    }
45
}
46
SoapIncoming::~SoapIncoming() 
47
{
48
    delete m;
49
    m = 0;
50
}
51
33
/* Example Soap XML doc passed by libupnp is like: 
52
/* Example Soap XML doc passed by libupnp is like: 
34
   <ns0:SetMute>
53
   <ns0:SetMute>
35
     <InstanceID>0</InstanceID>
54
     <InstanceID>0</InstanceID>
36
     <Channel>Master</Channel>
55
     <Channel>Master</Channel>
37
     <DesiredMute>False</DesiredMute>
56
     <DesiredMute>False</DesiredMute>
...
...
43
   This is used both for decoding action requests in the device and responses
62
   This is used both for decoding action requests in the device and responses
44
   in the control point side
63
   in the control point side
45
*/
64
*/
46
bool SoapIncoming::decode(const char *callnm, IXML_Document *actReq)
65
bool SoapIncoming::decode(const char *callnm, IXML_Document *actReq)
47
{
66
{
48
    m_ok = false;
49
    m_name = callnm;
67
    m->name = callnm;
50
68
51
    IXML_NodeList* nl = 0;
69
    IXML_NodeList* nl = 0;
52
    IXML_Node* topNode = ixmlNode_getFirstChild((IXML_Node *)actReq);
70
    IXML_Node* topNode = ixmlNode_getFirstChild((IXML_Node *)actReq);
53
    if (topNode == 0) {
71
    if (topNode == 0) {
54
        LOGERR("SoapIncoming: Empty Action request (no topNode) ??" << endl);
72
        LOGERR("SoapIncoming: Empty Action request (no topNode) ??" << endl);
55
        return m_ok;
73
        return false;
56
    }
74
    }
57
    //LOGDEB("SoapIncoming: top node name: " << ixmlNode_getNodeName(topNode) 
75
    //LOGDEB("SoapIncoming: top node name: " << ixmlNode_getNodeName(topNode) 
58
    //       << endl);
76
    //       << endl);
59
77
60
    nl = ixmlNode_getChildNodes(topNode);
78
    nl = ixmlNode_getChildNodes(topNode);
61
    if (nl == 0) {
79
    if (nl == 0) {
62
        // Ok actually, there are no args
80
        // Ok actually, there are no args
63
        return m_ok = true;
81
        return true;
64
    }
82
    }
65
    //LOGDEB("SoapIncoming: childnodes list length: " << ixmlNodeList_length(nl)
83
    //LOGDEB("SoapIncoming: childnodes list length: " << ixmlNodeList_length(nl)
66
    // << endl);
84
    // << endl);
67
85
    bool ret = false;
68
    for (unsigned long i = 0; i <  ixmlNodeList_length(nl); i++) {
86
    for (unsigned long i = 0; i <  ixmlNodeList_length(nl); i++) {
69
        IXML_Node *cld = ixmlNodeList_item(nl, i);
87
        IXML_Node *cld = ixmlNodeList_item(nl, i);
70
        if (cld == 0) {
88
        if (cld == 0) {
71
            //LOGDEB1("SoapIncoming: got null node  from nodelist at index " <<
89
            //LOGDEB1("SoapIncoming: got null node  from nodelist at index " <<
72
            // i << " ??" << endl);
90
            // i << " ??" << endl);
73
            // Seems to happen with empty arg list?? This looks like a bug, 
91
            // Seems to happen with empty arg list?? This looks like a bug, 
74
            // should we not get an empty node instead?
92
            // should we not get an empty node instead?
75
            if (i == 0) {
93
            if (i == 0) {
76
                m_ok = true;
94
                ret = true;
77
            }
95
            }
78
            goto out;
96
            goto out;
79
        }
97
        }
80
        const char *name = ixmlNode_getNodeName(cld);
98
        const char *name = ixmlNode_getNodeName(cld);
81
        if (name == 0) {
99
        if (name == 0) {
...
...
90
            value = ixmlNode_getNodeValue(txtnode);
108
            value = ixmlNode_getNodeValue(txtnode);
91
        }
109
        }
92
        // Can we get an empty value here ?
110
        // Can we get an empty value here ?
93
        if (value == 0)
111
        if (value == 0)
94
            value = "";
112
            value = "";
95
        m_args[name] = value;
113
        m->args[name] = value;
96
    }
114
    }
97
    m_name = callnm;
115
    m->name = callnm;
98
    m_ok = true;
116
    ret = true;
99
117
100
out:
118
out:
101
    if (nl)
119
    if (nl)
102
        ixmlNodeList_free(nl);
120
        ixmlNodeList_free(nl);
103
    return m_ok;
121
    return ret;
104
}
122
}
105
123
124
const std::string& SoapIncoming::getName() const 
125
{
126
    return m->name;
127
}
128
106
bool SoapIncoming::getBool(const char *nm, bool *value) const
129
bool SoapIncoming::get(const char *nm, bool *value) const
107
{
130
{
108
    map<string, string>::const_iterator it = m_args.find(nm);
131
    map<string, string>::const_iterator it = m->args.find(nm);
109
    if (it == m_args.end() || it->second.empty()) {
132
    if (it == m->args.end() || it->second.empty()) {
110
        return false;
133
        return false;
111
    }
134
    }
112
    return stringToBool(it->second, value);
135
    return stringToBool(it->second, value);
113
}
136
}
114
137
115
bool SoapIncoming::getInt(const char *nm, int *value) const
138
bool SoapIncoming::get(const char *nm, int *value) const
116
{
139
{
117
    map<string, string>::const_iterator it = m_args.find(nm);
140
    map<string, string>::const_iterator it = m->args.find(nm);
118
    if (it == m_args.end() || it->second.empty()) {
141
    if (it == m->args.end() || it->second.empty()) {
119
        return false;
142
        return false;
120
    }
143
    }
121
    *value = atoi(it->second.c_str());
144
    *value = atoi(it->second.c_str());
122
    return true;
145
    return true;
123
}
146
}
124
147
125
bool SoapIncoming::getString(const char *nm, string *value) const
148
bool SoapIncoming::get(const char *nm, string *value) const
126
{
149
{
127
    map<string, string>::const_iterator it = m_args.find(nm);
150
    map<string, string>::const_iterator it = m->args.find(nm);
128
    if (it == m_args.end()) {
151
    if (it == m->args.end()) {
129
        return false;
152
        return false;
130
    }
153
    }
131
    *value = it->second;
154
    *value = it->second;
132
    return true;
155
    return true;
133
}
156
}
134
135
157
136
string SoapHelp::xmlQuote(const string& in)
158
string SoapHelp::xmlQuote(const string& in)
137
{
159
{
138
    string out;
160
    string out;
139
    for (unsigned int i = 0; i < in.size(); i++) {
161
    for (unsigned int i = 0; i < in.size(); i++) {
...
...
192
    char cbuf[30];
214
    char cbuf[30];
193
    sprintf(cbuf, "%d", val);
215
    sprintf(cbuf, "%d", val);
194
    return string(cbuf);
216
    return string(cbuf);
195
}
217
}
196
218
219
class SoapOutgoing::Internal {
220
public:
221
    std::string serviceType;
222
    std::string name;
223
    std::vector<std::pair<std::string, std::string> > data;
224
};
225
226
SoapOutgoing::SoapOutgoing() 
227
{
228
    if ((m = new Internal()) == 0) {
229
        LOGERR("SoapOutgoing::SoapOutgoing: out of memory" << endl);
230
        return;
231
    }
232
}
233
234
SoapOutgoing::SoapOutgoing(const std::string& st, const std::string& nm)
235
{
236
    if ((m = new Internal()) == 0) {
237
        LOGERR("SoapOutgoing::SoapOutgoing: out of memory" << endl);
238
        return;
239
    }
240
    m->serviceType = st;
241
    m->name = nm;
242
}
243
244
SoapOutgoing::~SoapOutgoing()
245
{
246
    delete m;
247
    m = 0;
248
}
249
250
const string& SoapOutgoing::getName() const 
251
{
252
    return m->name;
253
}
254
255
SoapOutgoing& SoapOutgoing::addarg(const string& k, const string& v) 
256
{
257
    m->data.push_back(pair<string, string>(k, v));
258
    return *this;
259
}
260
261
SoapOutgoing& SoapOutgoing::operator() (const string& k, const string& v) 
262
{
263
    m->data.push_back(pair<string, string>(k, v));
264
    return *this;
265
}
266
197
IXML_Document *SoapOutgoing::buildSoapBody(bool isResponse) const
267
IXML_Document *SoapOutgoing::buildSoapBody(bool isResponse) const
198
{
268
{
199
    IXML_Document *doc = ixmlDocument_createDocument();
269
    IXML_Document *doc = ixmlDocument_createDocument();
200
    if (doc == 0) {
270
    if (doc == 0) {
201
        cerr << "buildSoapBody: out of memory" << endl;
271
        cerr << "buildSoapBody: out of memory" << endl;
202
        return 0;
272
        return 0;
203
    }
273
    }
204
    string topname = string("u:") + m_name;
274
    string topname = string("u:") + m->name;
205
    if (isResponse)
275
    if (isResponse)
206
        topname += "Response";
276
        topname += "Response";
207
277
208
    IXML_Element *top =  
278
    IXML_Element *top =  
209
        ixmlDocument_createElementNS(doc, m_serviceType.c_str(), 
279
        ixmlDocument_createElementNS(doc, m->serviceType.c_str(), 
210
                                     topname.c_str());
280
                                     topname.c_str());
211
    ixmlElement_setAttribute(top, "xmlns:u", m_serviceType.c_str());
281
    ixmlElement_setAttribute(top, "xmlns:u", m->serviceType.c_str());
212
282
213
    for (unsigned i = 0; i < m_data.size(); i++) {
283
    for (unsigned i = 0; i < m->data.size(); i++) {
214
        IXML_Element *elt = 
284
        IXML_Element *elt = 
215
            ixmlDocument_createElement(doc, m_data[i].first.c_str());
285
            ixmlDocument_createElement(doc, m->data[i].first.c_str());
216
        IXML_Node* textnode = 
286
        IXML_Node* textnode = 
217
            ixmlDocument_createTextNode(doc, m_data[i].second.c_str());
287
            ixmlDocument_createTextNode(doc, m->data[i].second.c_str());
218
        ixmlNode_appendChild((IXML_Node*)elt,(IXML_Node*)textnode);
288
        ixmlNode_appendChild((IXML_Node*)elt,(IXML_Node*)textnode);
219
        ixmlNode_appendChild((IXML_Node*)top,(IXML_Node*)elt);
289
        ixmlNode_appendChild((IXML_Node*)top,(IXML_Node*)elt);
220
    }
290
    }
221
291
222
    ixmlNode_appendChild((IXML_Node*)doc,(IXML_Node*)top);
292
    ixmlNode_appendChild((IXML_Node*)doc,(IXML_Node*)top);