Download this file

toto.c    190 lines (169 with data), 6.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/* Copyright (C) 2016 J.F.Dockes
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "toto.h"
#include <upnp/upnp.h>
#include <functional>
#include <iostream>
#include <map>
#include <utility>
#include "libupnpp/log.hxx"
#include "libupnpp/soaphelp.hxx"
#include "libupnpp/device/device.hxx"
using namespace std;
using namespace std::placeholders;
static const string sTpservice("urn:XXX");
static const string sIdservice("urn:XXX:1");
service::service(UPnPProvider::UpnpDevice *dev)
: UpnpService(sTpservice, sIdservice, dev)
{
dev->addActionMapping(
this, "GetSearchCapabilities",
bind(&service::actGetSearchCapabilities, this, _1, _2));
dev->addActionMapping(
this, "GetSortCapabilities",
bind(&service::actGetSortCapabilities, this, _1, _2));
dev->addActionMapping(
this, "GetSystemUpdateID",
bind(&service::actGetSystemUpdateID, this, _1, _2));
dev->addActionMapping(
this, "Browse",
bind(&service::actBrowse, this, _1, _2));
dev->addActionMapping(
this, "Search",
bind(&service::actSearch, this, _1, _2));
}
int service::actGetSearchCapabilities(const SoapIncoming& sc, SoapOutgoing& data)
{
LOGDEB("service::actGetSearchCapabilities: " << endl);
std::string out_SearchCaps;
data.addarg("SearchCaps", out_SearchCaps);
return UPNP_E_SUCCESS;
}
int service::actGetSortCapabilities(const SoapIncoming& sc, SoapOutgoing& data)
{
LOGDEB("service::actGetSortCapabilities: " << endl);
std::string out_SortCaps;
data.addarg("SortCaps", out_SortCaps);
return UPNP_E_SUCCESS;
}
int service::actGetSystemUpdateID(const SoapIncoming& sc, SoapOutgoing& data)
{
LOGDEB("service::actGetSystemUpdateID: " << endl);
std::string out_Id;
data.addarg("Id", out_Id);
return UPNP_E_SUCCESS;
}
int service::actBrowse(const SoapIncoming& sc, SoapOutgoing& data)
{
bool ok = false;
std::string in_ObjectID;
ok = sc.get("ObjectID", &in_ObjectID);
if (!ok) {
LOGERR("service::actBrowse: no ObjectID in params\n");
return UPNP_E_INVALID_PARAM;
}
std::string in_BrowseFlag;
ok = sc.get("BrowseFlag", &in_BrowseFlag);
if (!ok) {
LOGERR("service::actBrowse: no BrowseFlag in params\n");
return UPNP_E_INVALID_PARAM;
}
std::string in_Filter;
ok = sc.get("Filter", &in_Filter);
if (!ok) {
LOGERR("service::actBrowse: no Filter in params\n");
return UPNP_E_INVALID_PARAM;
}
int in_StartingIndex;
ok = sc.get("StartingIndex", &in_StartingIndex);
if (!ok) {
LOGERR("service::actBrowse: no StartingIndex in params\n");
return UPNP_E_INVALID_PARAM;
}
int in_RequestedCount;
ok = sc.get("RequestedCount", &in_RequestedCount);
if (!ok) {
LOGERR("service::actBrowse: no RequestedCount in params\n");
return UPNP_E_INVALID_PARAM;
}
std::string in_SortCriteria;
ok = sc.get("SortCriteria", &in_SortCriteria);
if (!ok) {
LOGERR("service::actBrowse: no SortCriteria in params\n");
return UPNP_E_INVALID_PARAM;
}
LOGDEB("service::actBrowse: " << " ObjectID " << ObjectID << " BrowseFlag " << BrowseFlag << " Filter " << Filter << " StartingIndex " << StartingIndex << " RequestedCount " << RequestedCount << " SortCriteria " << SortCriteria << endl);
std::string out_Result;
std::string out_NumberReturned;
std::string out_TotalMatches;
std::string out_UpdateID;
data.addarg("Result", out_Result);
data.addarg("NumberReturned", out_NumberReturned);
data.addarg("TotalMatches", out_TotalMatches);
data.addarg("UpdateID", out_UpdateID);
return UPNP_E_SUCCESS;
}
int service::actSearch(const SoapIncoming& sc, SoapOutgoing& data)
{
bool ok = false;
std::string in_ContainerID;
ok = sc.get("ContainerID", &in_ContainerID);
if (!ok) {
LOGERR("service::actSearch: no ContainerID in params\n");
return UPNP_E_INVALID_PARAM;
}
std::string in_SearchCriteria;
ok = sc.get("SearchCriteria", &in_SearchCriteria);
if (!ok) {
LOGERR("service::actSearch: no SearchCriteria in params\n");
return UPNP_E_INVALID_PARAM;
}
std::string in_Filter;
ok = sc.get("Filter", &in_Filter);
if (!ok) {
LOGERR("service::actSearch: no Filter in params\n");
return UPNP_E_INVALID_PARAM;
}
int in_StartingIndex;
ok = sc.get("StartingIndex", &in_StartingIndex);
if (!ok) {
LOGERR("service::actSearch: no StartingIndex in params\n");
return UPNP_E_INVALID_PARAM;
}
int in_RequestedCount;
ok = sc.get("RequestedCount", &in_RequestedCount);
if (!ok) {
LOGERR("service::actSearch: no RequestedCount in params\n");
return UPNP_E_INVALID_PARAM;
}
std::string in_SortCriteria;
ok = sc.get("SortCriteria", &in_SortCriteria);
if (!ok) {
LOGERR("service::actSearch: no SortCriteria in params\n");
return UPNP_E_INVALID_PARAM;
}
LOGDEB("service::actSearch: " << " ContainerID " << ContainerID << " SearchCriteria " << SearchCriteria << " Filter " << Filter << " StartingIndex " << StartingIndex << " RequestedCount " << RequestedCount << " SortCriteria " << SortCriteria << endl);
std::string out_Result;
std::string out_NumberReturned;
std::string out_TotalMatches;
std::string out_UpdateID;
data.addarg("Result", out_Result);
data.addarg("NumberReturned", out_NumberReturned);
data.addarg("TotalMatches", out_TotalMatches);
data.addarg("UpdateID", out_UpdateID);
return UPNP_E_SUCCESS;
}