a/src/contentdirectory.cxx b/src/contentdirectory.cxx
...
...
22
#include <functional>
22
#include <functional>
23
#include <iostream>
23
#include <iostream>
24
#include <map>
24
#include <map>
25
#include <utility>
25
#include <utility>
26
#include <unordered_map>
26
#include <unordered_map>
27
#include <sstream>
27
28
28
#include "libupnpp/log.hxx"
29
#include "libupnpp/log.hxx"
29
#include "libupnpp/soaphelp.hxx"
30
#include "libupnpp/soaphelp.hxx"
30
#include "libupnpp/device/device.hxx"
31
#include "libupnpp/device/device.hxx"
31
32
32
#include "pathut.h"
33
#include "pathut.h"
33
#include "smallut.h"
34
#include "smallut.h"
34
#include "upmpdutils.hxx"
35
#include "upmpdutils.hxx"
36
#include "main.hxx"
35
#include "cdplugins/cdplugin.hxx"
37
#include "cdplugins/cdplugin.hxx"
36
#include "cdplugins/tidal.hxx"
38
#include "cdplugins/tidal.hxx"
37
39
38
using namespace std;
40
using namespace std;
39
using namespace std::placeholders;
41
using namespace std::placeholders;
40
42
using namespace UPnPProvider;
41
extern string g_datadir;
42
43
43
class ContentDirectory::Internal {
44
class ContentDirectory::Internal {
44
public:
45
public:
46
    Internal (ContentDirectory *sv)
47
  : service(sv) {
48
    }
45
    ~Internal() {
49
    ~Internal() {
46
    for (auto& it : plugins) {
50
    for (auto& it : plugins) {
47
        delete it.second;
51
        delete it.second;
48
    }
52
    }
49
    }
53
    }
50
    CDPlugin *pluginFactory(const string& appname) {
54
    CDPlugin *pluginFactory(const string& appname) {
51
    LOGDEB("ContentDirectory::pluginFactory: for " << appname << endl);
55
    LOGDEB("ContentDirectory::pluginFactory: for " << appname << endl);
56
57
  if (httphp.empty()) {
58
      UpnpDevice *dev;
59
      if (!service || !(dev = service->getDevice())) {
60
      LOGERR("ContentDirectory::Internal: no service or dev ??\n");
61
      return nullptr;
62
      }
63
      string host;
64
      unsigned short port;
65
      if (!dev->ipv4(&host, &port)) {
66
      LOGERR("ContentDirectory::Internal: can't get server IP\n");
67
      return nullptr;
68
      }
69
      ostringstream ss;
70
      ss << host << ":" << port;
71
      httphp = ss.str();
72
      LOGDEB("ContentDirectory: host:port: " << httphp << endl);
73
  }
74
  VirtualDir *dir = VirtualDir::getVirtualDir();
75
  if (dir == nullptr) {
76
      LOGERR("CDPlugin::factory: getVirtualDir() failed\n");
77
      return nullptr;
78
  }
52
    if (!appname.compare("tidal")) {
79
    if (!appname.compare("tidal")) {
53
        string pthcdplugs = path_cat(g_datadir, "cdplugins");
80
        string pthcdplugs = path_cat(g_datadir, "cdplugins");
81
      Tidal *tidal =
54
        return new Tidal({pthcdplugs, path_cat(pthcdplugs, appname)});
82
      new Tidal({pthcdplugs, path_cat(pthcdplugs, appname)},
83
            httphp, "/tidal");
84
      if (tidal) {
85
      dir->addVDir("/tidal", tidal->getFileOps());
86
      }
87
      return tidal;
55
    } else {
88
    } else {
56
        return nullptr;
89
        return nullptr;
57
    }
90
    }
58
    }
91
    }
59
    CDPlugin *pluginForApp(const string& appname) {
92
    CDPlugin *pluginForApp(const string& appname) {
...
...
67
        }
100
        }
68
        return plug;
101
        return plug;
69
    }
102
    }
70
    }
103
    }
71
    unordered_map<string, CDPlugin *> plugins;
104
    unordered_map<string, CDPlugin *> plugins;
105
    ContentDirectory *service;
106
    string httphp;
72
};
107
};
73
108
74
static const string
109
static const string
75
sTpContentDirectory("urn:schemas-upnp-org:service:ContentDirectory:1");
110
sTpContentDirectory("urn:schemas-upnp-org:service:ContentDirectory:1");
76
static const string
111
static const string
77
sIdContentDirectory("urn:upnp-org:serviceId:ContentDirectory");
112
sIdContentDirectory("urn:upnp-org:serviceId:ContentDirectory");
78
113
79
ContentDirectory::ContentDirectory(UPnPProvider::UpnpDevice *dev)
114
ContentDirectory::ContentDirectory(UPnPProvider::UpnpDevice *dev)
80
    : UpnpService(sTpContentDirectory, sIdContentDirectory, dev),
115
    : UpnpService(sTpContentDirectory, sIdContentDirectory, dev),
81
      m(new Internal)
116
      m(new Internal(this))
82
{
117
{
83
    dev->addActionMapping(
118
    dev->addActionMapping(
84
        this, "GetSearchCapabilities",
119
        this, "GetSearchCapabilities",
85
        bind(&ContentDirectory::actGetSearchCapabilities, this, _1, _2));
120
        bind(&ContentDirectory::actGetSearchCapabilities, this, _1, _2));
86
    dev->addActionMapping(
121
    dev->addActionMapping(