|
a/libupnpp/control/cdirectory.cxx |
|
b/libupnpp/control/cdirectory.cxx |
|
... |
|
... |
16 |
*/
|
16 |
*/
|
17 |
#include "config.h"
|
17 |
#include "config.h"
|
18 |
|
18 |
|
19 |
#include "libupnpp/control/cdirectory.hxx"
|
19 |
#include "libupnpp/control/cdirectory.hxx"
|
20 |
|
20 |
|
|
|
21 |
#include <sys/types.h>
|
|
|
22 |
#include <regex.h>
|
|
|
23 |
|
21 |
#include <upnp/upnp.h> // for UPNP_E_SUCCESS, etc
|
24 |
#include <upnp/upnp.h> // for UPNP_E_SUCCESS, etc
|
22 |
#include <upnp/upnptools.h> // for UpnpGetErrorMessage
|
25 |
#include <upnp/upnptools.h> // for UpnpGetErrorMessage
|
23 |
|
26 |
|
24 |
#include <functional> // for _Bind, bind, _1, _2
|
27 |
#include <functional> // for _Bind, bind, _1, _2
|
25 |
#include <iostream> // for operator<<, basic_ostream, etc
|
28 |
#include <iostream> // for operator<<, basic_ostream, etc
|
|
... |
|
... |
39 |
|
42 |
|
40 |
namespace UPnPClient {
|
43 |
namespace UPnPClient {
|
41 |
|
44 |
|
42 |
// The service type string for Content Directories:
|
45 |
// The service type string for Content Directories:
|
43 |
const string ContentDirectory::SType("urn:schemas-upnp-org:service:ContentDirectory:1");
|
46 |
const string ContentDirectory::SType("urn:schemas-upnp-org:service:ContentDirectory:1");
|
|
|
47 |
|
|
|
48 |
class SimpleRegexp {
|
|
|
49 |
public:
|
|
|
50 |
SimpleRegexp(const string& exp, int flags) : m_ok(false) {
|
|
|
51 |
if (regcomp(&m_expr, exp.c_str(), flags) == 0) {
|
|
|
52 |
m_ok = true;
|
|
|
53 |
}
|
|
|
54 |
}
|
|
|
55 |
~SimpleRegexp() {
|
|
|
56 |
regfree(&m_expr);
|
|
|
57 |
}
|
|
|
58 |
bool simpleMatch(const string& val) const {
|
|
|
59 |
if (!ok())
|
|
|
60 |
return false;
|
|
|
61 |
if (regexec(&m_expr, val.c_str(), 0, 0, 0) == 0) {
|
|
|
62 |
return true;
|
|
|
63 |
} else {
|
|
|
64 |
return false;
|
|
|
65 |
}
|
|
|
66 |
}
|
|
|
67 |
bool operator() (const string& val) const {
|
|
|
68 |
return simpleMatch(val);
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
bool ok() const {return m_ok;}
|
|
|
72 |
private:
|
|
|
73 |
bool m_ok;
|
|
|
74 |
regex_t m_expr;
|
|
|
75 |
};
|
|
|
76 |
|
|
|
77 |
/*
|
|
|
78 |
manufacturer: Bubblesoft model BubbleUPnP Media Server
|
|
|
79 |
manufacturer: Justin Maggard model Windows Media Connect compatible (MiniDLNA)
|
|
|
80 |
manufacturer: minimserver.com model MinimServer
|
|
|
81 |
manufacturer: PacketVideo model TwonkyMedia Server
|
|
|
82 |
manufacturer: ? model MediaTomb
|
|
|
83 |
*/
|
|
|
84 |
static const SimpleRegexp bubble_rx("bubble", REG_ICASE|REG_NOSUB);
|
|
|
85 |
static const SimpleRegexp mediatomb_rx("mediatomb", REG_ICASE|REG_NOSUB);
|
|
|
86 |
static const SimpleRegexp minidlna_rx("minidlna", REG_ICASE|REG_NOSUB);
|
|
|
87 |
static const SimpleRegexp minim_rx("minim", REG_ICASE|REG_NOSUB);
|
|
|
88 |
static const SimpleRegexp twonky_rx("twonky", REG_ICASE|REG_NOSUB);
|
|
|
89 |
|
|
|
90 |
ContentDirectory::ContentDirectory(const UPnPDeviceDesc& device,
|
|
|
91 |
const UPnPServiceDesc& service)
|
|
|
92 |
: Service(device, service), m_rdreqcnt(200), m_serviceKind(CDSKIND_UNKNOWN)
|
|
|
93 |
{
|
|
|
94 |
LOGERR("ContentDirectory::ContentDirectory: manufacturer: " <<
|
|
|
95 |
m_manufacturer << " model " << m_modelName << endl);
|
|
|
96 |
|
|
|
97 |
if (bubble_rx(m_modelName)) {
|
|
|
98 |
m_serviceKind = CDSKIND_BUBBLE;
|
|
|
99 |
LOGDEB1("ContentDirectory::ContentDirectory: BUBBLE" << endl);
|
|
|
100 |
} else if (mediatomb_rx(m_modelName)) {
|
|
|
101 |
// Readdir by 200 entries is good for most, but MediaTomb likes
|
|
|
102 |
// them really big. Actually 1000 is better but I don't dare
|
|
|
103 |
m_rdreqcnt = 500;
|
|
|
104 |
m_serviceKind = CDSKIND_MEDIATOMB;
|
|
|
105 |
LOGDEB1("ContentDirectory::ContentDirectory: MEDIATOMB" << endl);
|
|
|
106 |
} else if (minidlna_rx(m_modelName)) {
|
|
|
107 |
m_serviceKind = CDSKIND_MINIDLNA;
|
|
|
108 |
LOGDEB1("ContentDirectory::ContentDirectory: MINIDLNA" << endl);
|
|
|
109 |
} else if (minim_rx(m_modelName)) {
|
|
|
110 |
m_serviceKind = CDSKIND_MINIM;
|
|
|
111 |
LOGDEB1("ContentDirectory::ContentDirectory: MINIM" << endl);
|
|
|
112 |
} else if (twonky_rx(m_modelName)) {
|
|
|
113 |
m_serviceKind = CDSKIND_TWONKY;
|
|
|
114 |
LOGDEB1("ContentDirectory::ContentDirectory: TWONKY" << endl);
|
|
|
115 |
}
|
|
|
116 |
registerCallback();
|
|
|
117 |
}
|
44 |
|
118 |
|
45 |
// We don't include a version in comparisons, as we are satisfied with
|
119 |
// We don't include a version in comparisons, as we are satisfied with
|
46 |
// version 1
|
120 |
// version 1
|
47 |
bool ContentDirectory::isCDService(const string& st)
|
121 |
bool ContentDirectory::isCDService(const string& st)
|
48 |
{
|
122 |
{
|