libupnpp  0.16.0
A C++ wrapper for the Portable UPnP reference library
soaphelp.hxx
1 /* Copyright (C) 2006-2016 J.F.Dockes
2  *
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public
5  * License as published by the Free Software Foundation; either
6  * version 2.1 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  * Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with this library; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16  * 02110-1301 USA
17  */
18 #ifndef _SOAPHELP_H_X_INCLUDED_
19 #define _SOAPHELP_H_X_INCLUDED_
20 
21 // This module used to be necessary to decode/encode XML DOM trees
22 // from/to the libupnp interface. The npupnp interface uses C++
23 // objects instead, so there is not much left in here, but it has
24 // successfully isolated the client code from the change.
25 
26 #include <unordered_map>
27 #include <memory>
28 #include <string>
29 
30 #include "upnppexports.hxx"
31 
32 namespace UPnPP {
33 
35 class UPNPP_API SoapIncoming {
36 public:
37  SoapIncoming();
38  ~SoapIncoming();
39 
41  const std::string& getName() const;
42 
44  bool get(const char *nm, bool *value) const;
46  bool get(const char *nm, int *value) const;
48  bool get(const char *nm, std::string *value) const;
49 
50  void getMap(std::unordered_map<std::string, std::string>& out);
51 
52  class UPNPP_LOCAL Internal;
53  Internal *m;
54 };
55 
56 namespace SoapHelp {
57 std::string UPNPP_API xmlQuote(const std::string& in);
58 std::string UPNPP_API xmlUnquote(const std::string& in);
59 std::string UPNPP_API i2s(int val);
60 inline std::string val2s(const std::string& val)
61 {
62  return val;
63 }
64 inline std::string val2s(int val)
65 {
66  return i2s(val);
67 }
68 inline std::string val2s(bool val)
69 {
70  return i2s(int(val));
71 }
72 template <class InputIterator>
73 std::string UPNPP_API argsToStr(InputIterator first, InputIterator last)
74 {
75  std::string out;
76  for (auto it = first; it != last; it++) {
77  out += it->first + " = " + it->second + "\n";
78  }
79  return out;
80 }
81 }
82 
90 class UPNPP_API SoapOutgoing {
91 public:
92  SoapOutgoing();
93  SoapOutgoing(const std::string& st, const std::string& nm);
94  ~SoapOutgoing();
95 
96  SoapOutgoing& addarg(const std::string& k, const std::string& v);
97 
98  SoapOutgoing& operator()(const std::string& k, const std::string& v);
99 
100  const std::string& getName() const;
101 
102  class UPNPP_LOCAL Internal;
103  Internal *m;
104 };
105 
106 
107 } // namespace UPnPP
108 
109 #endif /* _SOAPHELP_H_X_INCLUDED_ */
Store the values to be encoded in a SOAP response.
Definition: soaphelp.hxx:90
Decode incoming Soap call data.
Definition: soaphelp.hxx:35
Definition: base64.cxx:26