|
a |
|
b/scripts/toto.c |
|
|
1 |
/* Copyright (C) 2016 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 "toto.h"
|
|
|
19 |
|
|
|
20 |
#include <upnp/upnp.h>
|
|
|
21 |
|
|
|
22 |
#include <functional>
|
|
|
23 |
#include <iostream>
|
|
|
24 |
#include <map>
|
|
|
25 |
#include <utility>
|
|
|
26 |
|
|
|
27 |
#include "libupnpp/log.hxx"
|
|
|
28 |
#include "libupnpp/soaphelp.hxx"
|
|
|
29 |
#include "libupnpp/device/device.hxx"
|
|
|
30 |
|
|
|
31 |
using namespace std;
|
|
|
32 |
using namespace std::placeholders;
|
|
|
33 |
|
|
|
34 |
static const string sTpservice("urn:XXX");
|
|
|
35 |
static const string sIdservice("urn:XXX:1");
|
|
|
36 |
|
|
|
37 |
service::service(UPnPProvider::UpnpDevice *dev)
|
|
|
38 |
: UpnpService(sTpservice, sIdservice, dev)
|
|
|
39 |
{
|
|
|
40 |
dev->addActionMapping(
|
|
|
41 |
this, "GetSearchCapabilities",
|
|
|
42 |
bind(&service::actGetSearchCapabilities, this, _1, _2));
|
|
|
43 |
dev->addActionMapping(
|
|
|
44 |
this, "GetSortCapabilities",
|
|
|
45 |
bind(&service::actGetSortCapabilities, this, _1, _2));
|
|
|
46 |
dev->addActionMapping(
|
|
|
47 |
this, "GetSystemUpdateID",
|
|
|
48 |
bind(&service::actGetSystemUpdateID, this, _1, _2));
|
|
|
49 |
dev->addActionMapping(
|
|
|
50 |
this, "Browse",
|
|
|
51 |
bind(&service::actBrowse, this, _1, _2));
|
|
|
52 |
dev->addActionMapping(
|
|
|
53 |
this, "Search",
|
|
|
54 |
bind(&service::actSearch, this, _1, _2));
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
|
|
|
58 |
int service::actGetSearchCapabilities(const SoapIncoming& sc, SoapOutgoing& data)
|
|
|
59 |
{
|
|
|
60 |
|
|
|
61 |
LOGDEB("service::actGetSearchCapabilities: " << endl);
|
|
|
62 |
std::string out_SearchCaps;
|
|
|
63 |
data.addarg("SearchCaps", out_SearchCaps);
|
|
|
64 |
return UPNP_E_SUCCESS;
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
int service::actGetSortCapabilities(const SoapIncoming& sc, SoapOutgoing& data)
|
|
|
68 |
{
|
|
|
69 |
|
|
|
70 |
LOGDEB("service::actGetSortCapabilities: " << endl);
|
|
|
71 |
std::string out_SortCaps;
|
|
|
72 |
data.addarg("SortCaps", out_SortCaps);
|
|
|
73 |
return UPNP_E_SUCCESS;
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
int service::actGetSystemUpdateID(const SoapIncoming& sc, SoapOutgoing& data)
|
|
|
77 |
{
|
|
|
78 |
|
|
|
79 |
LOGDEB("service::actGetSystemUpdateID: " << endl);
|
|
|
80 |
std::string out_Id;
|
|
|
81 |
data.addarg("Id", out_Id);
|
|
|
82 |
return UPNP_E_SUCCESS;
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
int service::actBrowse(const SoapIncoming& sc, SoapOutgoing& data)
|
|
|
86 |
{
|
|
|
87 |
bool ok = false;
|
|
|
88 |
std::string in_ObjectID;
|
|
|
89 |
ok = sc.get("ObjectID", &in_ObjectID);
|
|
|
90 |
if (!ok) {
|
|
|
91 |
LOGERR("service::actBrowse: no ObjectID in params\n");
|
|
|
92 |
return UPNP_E_INVALID_PARAM;
|
|
|
93 |
}
|
|
|
94 |
std::string in_BrowseFlag;
|
|
|
95 |
ok = sc.get("BrowseFlag", &in_BrowseFlag);
|
|
|
96 |
if (!ok) {
|
|
|
97 |
LOGERR("service::actBrowse: no BrowseFlag in params\n");
|
|
|
98 |
return UPNP_E_INVALID_PARAM;
|
|
|
99 |
}
|
|
|
100 |
std::string in_Filter;
|
|
|
101 |
ok = sc.get("Filter", &in_Filter);
|
|
|
102 |
if (!ok) {
|
|
|
103 |
LOGERR("service::actBrowse: no Filter in params\n");
|
|
|
104 |
return UPNP_E_INVALID_PARAM;
|
|
|
105 |
}
|
|
|
106 |
int in_StartingIndex;
|
|
|
107 |
ok = sc.get("StartingIndex", &in_StartingIndex);
|
|
|
108 |
if (!ok) {
|
|
|
109 |
LOGERR("service::actBrowse: no StartingIndex in params\n");
|
|
|
110 |
return UPNP_E_INVALID_PARAM;
|
|
|
111 |
}
|
|
|
112 |
int in_RequestedCount;
|
|
|
113 |
ok = sc.get("RequestedCount", &in_RequestedCount);
|
|
|
114 |
if (!ok) {
|
|
|
115 |
LOGERR("service::actBrowse: no RequestedCount in params\n");
|
|
|
116 |
return UPNP_E_INVALID_PARAM;
|
|
|
117 |
}
|
|
|
118 |
std::string in_SortCriteria;
|
|
|
119 |
ok = sc.get("SortCriteria", &in_SortCriteria);
|
|
|
120 |
if (!ok) {
|
|
|
121 |
LOGERR("service::actBrowse: no SortCriteria in params\n");
|
|
|
122 |
return UPNP_E_INVALID_PARAM;
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
LOGDEB("service::actBrowse: " << " ObjectID " << ObjectID << " BrowseFlag " << BrowseFlag << " Filter " << Filter << " StartingIndex " << StartingIndex << " RequestedCount " << RequestedCount << " SortCriteria " << SortCriteria << endl);
|
|
|
126 |
std::string out_Result;
|
|
|
127 |
std::string out_NumberReturned;
|
|
|
128 |
std::string out_TotalMatches;
|
|
|
129 |
std::string out_UpdateID;
|
|
|
130 |
data.addarg("Result", out_Result);
|
|
|
131 |
data.addarg("NumberReturned", out_NumberReturned);
|
|
|
132 |
data.addarg("TotalMatches", out_TotalMatches);
|
|
|
133 |
data.addarg("UpdateID", out_UpdateID);
|
|
|
134 |
return UPNP_E_SUCCESS;
|
|
|
135 |
}
|
|
|
136 |
|
|
|
137 |
int service::actSearch(const SoapIncoming& sc, SoapOutgoing& data)
|
|
|
138 |
{
|
|
|
139 |
bool ok = false;
|
|
|
140 |
std::string in_ContainerID;
|
|
|
141 |
ok = sc.get("ContainerID", &in_ContainerID);
|
|
|
142 |
if (!ok) {
|
|
|
143 |
LOGERR("service::actSearch: no ContainerID in params\n");
|
|
|
144 |
return UPNP_E_INVALID_PARAM;
|
|
|
145 |
}
|
|
|
146 |
std::string in_SearchCriteria;
|
|
|
147 |
ok = sc.get("SearchCriteria", &in_SearchCriteria);
|
|
|
148 |
if (!ok) {
|
|
|
149 |
LOGERR("service::actSearch: no SearchCriteria in params\n");
|
|
|
150 |
return UPNP_E_INVALID_PARAM;
|
|
|
151 |
}
|
|
|
152 |
std::string in_Filter;
|
|
|
153 |
ok = sc.get("Filter", &in_Filter);
|
|
|
154 |
if (!ok) {
|
|
|
155 |
LOGERR("service::actSearch: no Filter in params\n");
|
|
|
156 |
return UPNP_E_INVALID_PARAM;
|
|
|
157 |
}
|
|
|
158 |
int in_StartingIndex;
|
|
|
159 |
ok = sc.get("StartingIndex", &in_StartingIndex);
|
|
|
160 |
if (!ok) {
|
|
|
161 |
LOGERR("service::actSearch: no StartingIndex in params\n");
|
|
|
162 |
return UPNP_E_INVALID_PARAM;
|
|
|
163 |
}
|
|
|
164 |
int in_RequestedCount;
|
|
|
165 |
ok = sc.get("RequestedCount", &in_RequestedCount);
|
|
|
166 |
if (!ok) {
|
|
|
167 |
LOGERR("service::actSearch: no RequestedCount in params\n");
|
|
|
168 |
return UPNP_E_INVALID_PARAM;
|
|
|
169 |
}
|
|
|
170 |
std::string in_SortCriteria;
|
|
|
171 |
ok = sc.get("SortCriteria", &in_SortCriteria);
|
|
|
172 |
if (!ok) {
|
|
|
173 |
LOGERR("service::actSearch: no SortCriteria in params\n");
|
|
|
174 |
return UPNP_E_INVALID_PARAM;
|
|
|
175 |
}
|
|
|
176 |
|
|
|
177 |
LOGDEB("service::actSearch: " << " ContainerID " << ContainerID << " SearchCriteria " << SearchCriteria << " Filter " << Filter << " StartingIndex " << StartingIndex << " RequestedCount " << RequestedCount << " SortCriteria " << SortCriteria << endl);
|
|
|
178 |
std::string out_Result;
|
|
|
179 |
std::string out_NumberReturned;
|
|
|
180 |
std::string out_TotalMatches;
|
|
|
181 |
std::string out_UpdateID;
|
|
|
182 |
data.addarg("Result", out_Result);
|
|
|
183 |
data.addarg("NumberReturned", out_NumberReturned);
|
|
|
184 |
data.addarg("TotalMatches", out_TotalMatches);
|
|
|
185 |
data.addarg("UpdateID", out_UpdateID);
|
|
|
186 |
return UPNP_E_SUCCESS;
|
|
|
187 |
}
|
|
|
188 |
|
|
|
189 |
|