libupnpp 0.16.0
A C++ wrapper for the Portable UPnP reference library
upnpp_p.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 _UPNPP_H_X_INCLUDED_
19#define _UPNPP_H_X_INCLUDED_
20
21/* Private shared defs for the library. Clients need not and should
22 not include this */
23#include <sys/types.h>
24
25#include <upnp.h>
26
27#include <time.h>
28
29#include <string>
30#include <mutex>
31#include <unordered_map>
32#include <vector>
33#include <utility>
34
35#include "config.h"
36#include "libupnpp/upnpplib.hxx"
37#include "libupnpp/soaphelp.hxx"
38
39// define this for testing setting the description document as memory
40// buffer Note: this does not work well for embedded devices (npupnp
41// issue?), did not try to debug. Also does not work for multiple
42// roots (would need a way to specify a different doc name).
43#undef SETUP_DESCRIPTION_BY_BUFFER
44
45namespace UPnPP {
46
48public:
49 std::string name;
50 std::unordered_map<std::string, std::string> args;
51};
52
54public:
55 Internal() = default;
56 Internal(const std::string& st, const std::string& nm)
57 : serviceType(st), name(nm) {}
58 std::string serviceType;
59 std::string name;
60 std::vector<std::pair<std::string, std::string> > data;
61};
62
63// Concatenate paths. Caller should make sure it makes sense.
64extern std::string caturl(const std::string& s1, const std::string& s2);
65// Return the scheme://host:port[/] part of input, or input if it is weird
66extern std::string baseurl(const std::string& url);
67extern std::string path_getfather(const std::string &s);
68extern std::string path_getsimple(const std::string &s);
69template <class T> bool csvToStrings(const std::string& s, T &tokens);
70
71// @return false if s does not look like a bool at all (does not begin
72// with [FfNnYyTt01]
73extern bool stringToBool(const std::string& s, bool *v);
74
76std::string reSanitizeURL(const std::string& in);
77
79extern std::string evTypeAsString(Upnp_EventType);
80
82public:
83
84 int getSubsTimeout();
85 bool reSanitizeURLs();
86
90 void registerHandler(Upnp_EventType et, Upnp_FunPtr handler, void *cookie);
91
92 // A Handler object records the data from registerHandler.
93 class Handler {
94 public:
95 Handler()
96 : handler(0), cookie(0) {}
97 Handler(Upnp_FunPtr h, void *c)
98 : handler(h), cookie(c) {}
99 Upnp_FunPtr handler;
100 void *cookie;
101 };
102
103 int setupWebServer(const std::string& description, UpnpDevice_Handle *dvh);
104 UpnpClient_Handle getclh();
105
106 bool ok;
107 static int init_error;
108 UpnpClient_Handle clh;
109 std::mutex mutex;
110 std::map<Upnp_EventType, Handler> handlers;
111};
112
113} // namespace
114
115#endif /* _UPNPP_H_X_INCLUDED_ */
Definition upnpp_p.hxx:93
Definition upnpp_p.hxx:81
void registerHandler(Upnp_EventType et, Upnp_FunPtr handler, void *cookie)
Specify function to be called on given UPnP event.
Definition upnpplib.cxx:374
Definition upnpp_p.hxx:47
Definition upnpp_p.hxx:53
Deal with data for the SOAP action protocol.
Definition base64.cxx:26
std::string evTypeAsString(Upnp_EventType)
Translate libupnp event type to string.
Definition upnpplib.cxx:425
std::string reSanitizeURL(const std::string &in)
Sanitize URL which is supposedly already encoded but maybe not fully.
Definition upnpplib.cxx:630