|
a/upexplo/upexplo.cxx |
|
b/upexplo/upexplo.cxx |
|
... |
|
... |
23 |
#include <string>
|
23 |
#include <string>
|
24 |
#include <iostream>
|
24 |
#include <iostream>
|
25 |
#include <vector>
|
25 |
#include <vector>
|
26 |
using namespace std;
|
26 |
using namespace std;
|
27 |
|
27 |
|
|
|
28 |
#include "libupnpp/log.hxx"
|
28 |
#include "libupnpp/upnpplib.hxx"
|
29 |
#include "libupnpp/upnpplib.hxx"
|
29 |
#include "libupnpp/discovery.hxx"
|
30 |
#include "libupnpp/discovery.hxx"
|
30 |
#include "libupnpp/cdirectory.hxx"
|
|
|
31 |
#include "libupnpp/description.hxx"
|
31 |
#include "libupnpp/description.hxx"
|
|
|
32 |
#include "libupnpp/control/cdirectory.hxx"
|
|
|
33 |
#include "libupnpp/control/mediarenderer.hxx"
|
32 |
|
34 |
|
33 |
using namespace UPnPClient;
|
35 |
using namespace UPnPClient;
|
34 |
|
36 |
|
35 |
void listServers(LibUPnP *lib)
|
37 |
void listServers()
|
36 |
{
|
38 |
{
|
37 |
cerr << "Servers:" << endl;
|
39 |
cout << "Content Directories:" << endl;
|
38 |
vector<ContentDirectoryService> dirservices;
|
40 |
vector<ContentDirectoryService> dirservices;
|
39 |
if (!ContentDirectoryService::getServices(dirservices)) {
|
41 |
if (!ContentDirectoryService::getServices(dirservices)) {
|
40 |
cerr << "listDirServices failed" << endl;
|
42 |
cerr << "listDirServices failed" << endl;
|
41 |
return;
|
43 |
return;
|
42 |
}
|
44 |
}
|
43 |
for (vector<ContentDirectoryService>::iterator it = dirservices.begin();
|
45 |
for (vector<ContentDirectoryService>::iterator it = dirservices.begin();
|
44 |
it != dirservices.end(); it++) {
|
46 |
it != dirservices.end(); it++) {
|
45 |
cerr << it->getFriendlyName() << endl;
|
47 |
cout << it->getFriendlyName() << endl;
|
|
|
48 |
}
|
|
|
49 |
cout << endl;
|
46 |
}
|
50 |
}
|
|
|
51 |
|
|
|
52 |
void listPlayers()
|
|
|
53 |
{
|
|
|
54 |
cout << "Media Renderers:" << endl;
|
|
|
55 |
vector<UPnPDeviceDesc> vdds;
|
|
|
56 |
if (!MediaRenderer::getDeviceDescs(vdds)) {
|
|
|
57 |
cerr << "MediaRenderer::getDeviceDescs" << endl;
|
|
|
58 |
return;
|
|
|
59 |
}
|
|
|
60 |
for (auto& entry : vdds) {
|
|
|
61 |
cout << entry.friendlyName << endl;
|
|
|
62 |
}
|
|
|
63 |
cout << endl;
|
47 |
}
|
64 |
}
|
48 |
|
65 |
|
49 |
void readdir(LibUPnP *lib, const string& friendlyName, const string& cid)
|
66 |
void readdir(LibUPnP *lib, const string& friendlyName, const string& cid)
|
50 |
{
|
67 |
{
|
51 |
cerr << "readdir: [" << friendlyName << "] [" << cid << "]" << endl;
|
68 |
cout << "readdir: [" << friendlyName << "] [" << cid << "]" << endl;
|
52 |
ContentDirectoryService server;
|
69 |
ContentDirectoryService server;
|
53 |
if (!ContentDirectoryService::getServerByName(friendlyName, server)) {
|
70 |
if (!ContentDirectoryService::getServerByName(friendlyName, server)) {
|
54 |
cerr << "Server not found" << endl;
|
71 |
cerr << "Server not found" << endl;
|
55 |
return;
|
72 |
return;
|
56 |
}
|
73 |
}
|
57 |
UPnPDirContent dirbuf;
|
74 |
UPnPDirContent dirbuf;
|
58 |
int code = server.readDir(cid, dirbuf);
|
75 |
int code = server.readDir(cid, dirbuf);
|
59 |
if (code) {
|
76 |
if (code) {
|
60 |
cerr << LibUPnP::errAsString("readdir", code) << endl;
|
77 |
cerr << LibUPnP::errAsString("readdir", code) << endl;
|
61 |
return;
|
78 |
return;
|
62 |
}
|
79 |
}
|
63 |
cerr << "Browse: got " << dirbuf.m_containers.size() <<
|
80 |
cout << "Browse: got " << dirbuf.m_containers.size() <<
|
64 |
" containers and " << dirbuf.m_items.size() << " items " << endl;
|
81 |
" containers and " << dirbuf.m_items.size() << " items " << endl;
|
65 |
for (unsigned int i = 0; i < dirbuf.m_containers.size(); i++) {
|
82 |
for (unsigned int i = 0; i < dirbuf.m_containers.size(); i++) {
|
66 |
cerr << dirbuf.m_containers[i].dump();
|
83 |
cout << dirbuf.m_containers[i].dump();
|
67 |
}
|
84 |
}
|
68 |
for (unsigned int i = 0; i < dirbuf.m_items.size(); i++) {
|
85 |
for (unsigned int i = 0; i < dirbuf.m_items.size(); i++) {
|
69 |
cerr << dirbuf.m_items[i].dump();
|
86 |
cout << dirbuf.m_items[i].dump();
|
70 |
}
|
87 |
}
|
71 |
}
|
88 |
}
|
72 |
|
89 |
|
73 |
void getMetadata(LibUPnP *lib, const string& friendlyName, const string& cid)
|
90 |
void getMetadata(LibUPnP *lib, const string& friendlyName, const string& cid)
|
74 |
{
|
91 |
{
|
75 |
cerr << "getMeta: [" << friendlyName << "] [" << cid << "]" << endl;
|
92 |
cout << "getMeta: [" << friendlyName << "] [" << cid << "]" << endl;
|
76 |
ContentDirectoryService server;
|
93 |
ContentDirectoryService server;
|
77 |
if (!ContentDirectoryService::getServerByName(friendlyName, server)) {
|
94 |
if (!ContentDirectoryService::getServerByName(friendlyName, server)) {
|
78 |
cerr << "Server not found" << endl;
|
95 |
cerr << "Server not found" << endl;
|
79 |
return;
|
96 |
return;
|
80 |
}
|
97 |
}
|
81 |
UPnPDirContent dirbuf;
|
98 |
UPnPDirContent dirbuf;
|
82 |
int code = server.getMetadata(cid, dirbuf);
|
99 |
int code = server.getMetadata(cid, dirbuf);
|
83 |
if (code) {
|
100 |
if (code) {
|
84 |
cerr << LibUPnP::errAsString("readdir", code) << endl;
|
101 |
cerr << LibUPnP::errAsString("readdir", code) << endl;
|
85 |
return;
|
102 |
return;
|
86 |
}
|
103 |
}
|
87 |
cerr << "getMeta: got " << dirbuf.m_containers.size() <<
|
104 |
cout << "getMeta: got " << dirbuf.m_containers.size() <<
|
88 |
" containers and " << dirbuf.m_items.size() << " items " << endl;
|
105 |
" containers and " << dirbuf.m_items.size() << " items " << endl;
|
89 |
for (unsigned int i = 0; i < dirbuf.m_containers.size(); i++) {
|
106 |
for (unsigned int i = 0; i < dirbuf.m_containers.size(); i++) {
|
90 |
cerr << dirbuf.m_containers[i].dump();
|
107 |
cout << dirbuf.m_containers[i].dump();
|
91 |
}
|
108 |
}
|
92 |
for (unsigned int i = 0; i < dirbuf.m_items.size(); i++) {
|
109 |
for (unsigned int i = 0; i < dirbuf.m_items.size(); i++) {
|
93 |
cerr << dirbuf.m_items[i].dump();
|
110 |
cout << dirbuf.m_items[i].dump();
|
94 |
}
|
111 |
}
|
95 |
}
|
112 |
}
|
96 |
|
113 |
|
97 |
void search(LibUPnP *lib, const string& friendlyName, const string& ss)
|
114 |
void search(LibUPnP *lib, const string& friendlyName, const string& ss)
|
98 |
{
|
115 |
{
|
99 |
cerr << "search: [" << friendlyName << "] [" << ss << "]" << endl;
|
116 |
cout << "search: [" << friendlyName << "] [" << ss << "]" << endl;
|
100 |
ContentDirectoryService server;
|
117 |
ContentDirectoryService server;
|
101 |
if (!ContentDirectoryService::getServerByName(friendlyName, server)) {
|
118 |
if (!ContentDirectoryService::getServerByName(friendlyName, server)) {
|
102 |
cerr << "Server not found" << endl;
|
119 |
cerr << "Server not found" << endl;
|
103 |
return;
|
120 |
return;
|
104 |
}
|
121 |
}
|
105 |
UPnPDirContent dirbuf;
|
122 |
UPnPDirContent dirbuf;
|
106 |
string cid("0");
|
123 |
string cid("0");
|
107 |
int code = server.search(cid, ss, dirbuf);
|
124 |
int code = server.search(cid, ss, dirbuf);
|
108 |
if (code) {
|
125 |
if (code) {
|
109 |
cerr << LibUPnP::errAsString("search", code) << endl;
|
126 |
cerr << LibUPnP::errAsString("search", code) << endl;
|
110 |
return;
|
127 |
return;
|
111 |
}
|
128 |
}
|
112 |
cerr << "Search: got " << dirbuf.m_containers.size() <<
|
129 |
cout << "Search: got " << dirbuf.m_containers.size() <<
|
113 |
" containers and " << dirbuf.m_items.size() << " items " << endl;
|
130 |
" containers and " << dirbuf.m_items.size() << " items " << endl;
|
114 |
for (unsigned int i = 0; i < dirbuf.m_containers.size(); i++) {
|
131 |
for (unsigned int i = 0; i < dirbuf.m_containers.size(); i++) {
|
115 |
cerr << dirbuf.m_containers[i].dump();
|
132 |
cout << dirbuf.m_containers[i].dump();
|
116 |
}
|
133 |
}
|
117 |
for (unsigned int i = 0; i < dirbuf.m_items.size(); i++) {
|
134 |
for (unsigned int i = 0; i < dirbuf.m_items.size(); i++) {
|
118 |
cerr << dirbuf.m_items[i].dump();
|
135 |
cout << dirbuf.m_items[i].dump();
|
119 |
}
|
136 |
}
|
120 |
}
|
137 |
}
|
121 |
|
138 |
|
122 |
void getSearchCaps(LibUPnP *lib, const string& friendlyName)
|
139 |
void getSearchCaps(LibUPnP *lib, const string& friendlyName)
|
123 |
{
|
140 |
{
|
124 |
cerr << "getSearchCaps: [" << friendlyName << "]" << endl;
|
141 |
cout << "getSearchCaps: [" << friendlyName << "]" << endl;
|
125 |
ContentDirectoryService server;
|
142 |
ContentDirectoryService server;
|
126 |
if (!ContentDirectoryService::getServerByName(friendlyName, server)) {
|
143 |
if (!ContentDirectoryService::getServerByName(friendlyName, server)) {
|
127 |
cerr << "Server not found" << endl;
|
144 |
cerr << "Server not found" << endl;
|
128 |
return;
|
145 |
return;
|
129 |
}
|
146 |
}
|
130 |
set<string> capa;
|
147 |
set<string> capa;
|
131 |
int code = server.getSearchCapabilities(capa);
|
148 |
int code = server.getSearchCapabilities(capa);
|
132 |
if (code) {
|
149 |
if (code) {
|
133 |
cerr << LibUPnP::errAsString("readdir", code) << endl;
|
150 |
cerr << LibUPnP::errAsString("readdir", code) << endl;
|
134 |
return;
|
151 |
return;
|
135 |
}
|
152 |
}
|
136 |
if (capa.empty()) {
|
153 |
if (capa.empty()) {
|
137 |
cerr << "No search capabilities";
|
154 |
cout << "No search capabilities";
|
138 |
} else {
|
155 |
} else {
|
139 |
for (set<string>::const_iterator it = capa.begin();
|
156 |
for (set<string>::const_iterator it = capa.begin();
|
140 |
it != capa.end(); it++) {
|
157 |
it != capa.end(); it++) {
|
141 |
cerr << "[" << *it << "]";
|
158 |
cout << "[" << *it << "]";
|
142 |
}
|
159 |
}
|
143 |
}
|
160 |
}
|
144 |
cerr << endl;
|
161 |
cout << endl;
|
145 |
}
|
162 |
}
|
146 |
|
163 |
|
147 |
static char *thisprog;
|
164 |
static char *thisprog;
|
148 |
static char usage [] =
|
165 |
static char usage [] =
|
149 |
" -l : list servers\n"
|
166 |
" -l : list servers\n"
|
150 |
" -r <server> <objid> list object id (root is '0')\n"
|
167 |
" -r <server> <objid> list object id (root is '0')\n"
|
151 |
" -s <server> <searchstring> search for string\n"
|
168 |
" -s <server> <searchstring> search for string\n"
|
152 |
" -m <server> <objid> : list object metadata\n"
|
169 |
" -m <server> <objid> : list object metadata\n"
|
153 |
" -c <server> get search capabilities\n"
|
170 |
" -c <server> get search capabilities\n"
|
154 |
" \n\n"
|
171 |
" \n\n"
|
155 |
;
|
172 |
;
|
156 |
static void
|
173 |
static void
|
157 |
Usage(void)
|
174 |
Usage(void)
|
158 |
{
|
175 |
{
|
159 |
fprintf(stderr, "%s: usage:\n%s", thisprog, usage);
|
176 |
fprintf(stderr, "%s: usage:\n%s", thisprog, usage);
|
160 |
exit(1);
|
177 |
exit(1);
|
161 |
}
|
178 |
}
|
162 |
static int op_flags;
|
179 |
static int op_flags;
|
163 |
#define OPT_MOINS 0x1
|
180 |
#define OPT_MOINS 0x1
|
164 |
#define OPT_l 0x2
|
181 |
#define OPT_l 0x2
|
165 |
#define OPT_r 0x4
|
182 |
#define OPT_r 0x4
|
|
... |
|
... |
167 |
#define OPT_s 0x10
|
184 |
#define OPT_s 0x10
|
168 |
#define OPT_m 0x20
|
185 |
#define OPT_m 0x20
|
169 |
|
186 |
|
170 |
int main(int argc, char *argv[])
|
187 |
int main(int argc, char *argv[])
|
171 |
{
|
188 |
{
|
172 |
string fname;
|
189 |
string fname;
|
173 |
string arg;
|
190 |
string arg;
|
174 |
|
191 |
|
175 |
thisprog = argv[0];
|
192 |
thisprog = argv[0];
|
176 |
argc--; argv++;
|
193 |
argc--; argv++;
|
177 |
|
194 |
|
178 |
while (argc > 0 && **argv == '-') {
|
195 |
while (argc > 0 && **argv == '-') {
|
179 |
(*argv)++;
|
196 |
(*argv)++;
|
180 |
if (!(**argv))
|
197 |
if (!(**argv))
|
181 |
/* Cas du "adb - core" */
|
198 |
/* Cas du "adb - core" */
|
182 |
Usage();
|
199 |
Usage();
|
183 |
while (**argv)
|
200 |
while (**argv)
|
184 |
switch (*(*argv)++) {
|
201 |
switch (*(*argv)++) {
|
185 |
case 'c': op_flags |= OPT_c; if (argc < 2) Usage();
|
202 |
case 'c': op_flags |= OPT_c; if (argc < 2) Usage();
|
186 |
fname = *(++argv);argc--;
|
203 |
fname = *(++argv);argc--;
|
187 |
goto b1;
|
204 |
goto b1;
|
188 |
case 'l': op_flags |= OPT_l; break;
|
205 |
case 'l': op_flags |= OPT_l; break;
|
189 |
case 'm': op_flags |= OPT_m; if (argc < 3) Usage();
|
206 |
case 'm': op_flags |= OPT_m; if (argc < 3) Usage();
|
190 |
fname = *(++argv);argc--;
|
207 |
fname = *(++argv);argc--;
|
191 |
arg = *(++argv);argc--;
|
208 |
arg = *(++argv);argc--;
|
192 |
goto b1;
|
209 |
goto b1;
|
193 |
case 'r': op_flags |= OPT_r; if (argc < 3) Usage();
|
210 |
case 'r': op_flags |= OPT_r; if (argc < 3) Usage();
|
194 |
fname = *(++argv);argc--;
|
211 |
fname = *(++argv);argc--;
|
195 |
arg = *(++argv);argc--;
|
212 |
arg = *(++argv);argc--;
|
196 |
goto b1;
|
213 |
goto b1;
|
197 |
case 's': op_flags |= OPT_s; if (argc < 3) Usage();
|
214 |
case 's': op_flags |= OPT_s; if (argc < 3) Usage();
|
198 |
fname = *(++argv);argc--;
|
215 |
fname = *(++argv);argc--;
|
199 |
arg = *(++argv);argc--;
|
216 |
arg = *(++argv);argc--;
|
200 |
goto b1;
|
217 |
goto b1;
|
201 |
default: Usage(); break;
|
218 |
default: Usage(); break;
|
202 |
}
|
219 |
}
|
203 |
b1: argc--; argv++;
|
220 |
b1: argc--; argv++;
|
204 |
}
|
221 |
}
|
205 |
|
222 |
|
206 |
if (argc != 0)
|
223 |
if (argc != 0)
|
207 |
Usage();
|
224 |
Usage();
|
208 |
|
225 |
|
|
|
226 |
if (upnppdebug::Logger::getTheLog("/tmp/upexplo.log") == 0) {
|
|
|
227 |
cerr << "Can't initialize log" << endl;
|
|
|
228 |
return 1;
|
|
|
229 |
}
|
|
|
230 |
|
209 |
LibUPnP *mylib = LibUPnP::getLibUPnP();
|
231 |
LibUPnP *mylib = LibUPnP::getLibUPnP();
|
210 |
if (!mylib) {
|
232 |
if (!mylib) {
|
211 |
cerr << "Can't get LibUPnP" << endl;
|
233 |
cerr << "Can't get LibUPnP" << endl;
|
212 |
return 1;
|
234 |
return 1;
|
213 |
}
|
235 |
}
|
214 |
if (!mylib->ok()) {
|
236 |
if (!mylib->ok()) {
|
215 |
cerr << "Lib init failed: " <<
|
237 |
cerr << "Lib init failed: " <<
|
216 |
mylib->errAsString("main", mylib->getInitError()) << endl;
|
238 |
mylib->errAsString("main", mylib->getInitError()) << endl;
|
217 |
return 1;
|
239 |
return 1;
|
218 |
}
|
240 |
}
|
219 |
mylib->setLogFileName("/tmp/libupnp.log");
|
241 |
mylib->setLogFileName("/tmp/libupnp.log");
|
220 |
UPnPDeviceDirectory *superdir = UPnPDeviceDirectory::getTheDir();
|
242 |
UPnPDeviceDirectory *superdir = UPnPDeviceDirectory::getTheDir();
|
221 |
if (!superdir || !superdir->ok()) {
|
243 |
if (!superdir || !superdir->ok()) {
|
222 |
cerr << "Discovery services startup failed" << endl;
|
244 |
cerr << "Discovery services startup failed" << endl;
|
223 |
return 1;
|
245 |
return 1;
|
224 |
}
|
246 |
}
|
225 |
|
247 |
|
226 |
if ((op_flags & OPT_l)) {
|
248 |
if ((op_flags & OPT_l)) {
|
227 |
while (true) {
|
249 |
while (true) {
|
228 |
listServers(mylib);
|
250 |
listServers();
|
229 |
sleep(5);
|
251 |
listPlayers();
|
230 |
}
|
252 |
sleep(5);
|
|
|
253 |
}
|
231 |
} else if ((op_flags & OPT_m)) {
|
254 |
} else if ((op_flags & OPT_m)) {
|
232 |
getMetadata(mylib, fname, arg);
|
255 |
getMetadata(mylib, fname, arg);
|
233 |
} else if ((op_flags & OPT_r)) {
|
256 |
} else if ((op_flags & OPT_r)) {
|
234 |
readdir(mylib, fname, arg);
|
257 |
readdir(mylib, fname, arg);
|
235 |
} else if ((op_flags & OPT_s)) {
|
258 |
} else if ((op_flags & OPT_s)) {
|
236 |
search(mylib, fname, arg);
|
259 |
search(mylib, fname, arg);
|
237 |
} else if ((op_flags & OPT_c)) {
|
260 |
} else if ((op_flags & OPT_c)) {
|
238 |
getSearchCaps(mylib, fname);
|
261 |
getSearchCaps(mylib, fname);
|
239 |
} else {
|
262 |
} else {
|
240 |
Usage();
|
263 |
Usage();
|
241 |
}
|
264 |
}
|
242 |
superdir->terminate();
|
265 |
superdir->terminate();
|
243 |
return 0;
|
266 |
return 0;
|
244 |
}
|
267 |
}
|
245 |
|
|
|
246 |
/* Local Variables: */
|
|
|
247 |
/* mode: c++ */
|
|
|
248 |
/* c-basic-offset: 4 */
|
|
|
249 |
/* tab-width: 4 */
|
|
|
250 |
/* indent-tabs-mode: t */
|
|
|
251 |
/* End: */
|
|
|