Switch to unified view

a/src/contentdirectory.cxx b/src/contentdirectory.cxx
...
...
34
34
35
#include "pathut.h"
35
#include "pathut.h"
36
#include "smallut.h"
36
#include "smallut.h"
37
#include "upmpdutils.hxx"
37
#include "upmpdutils.hxx"
38
#include "main.hxx"
38
#include "main.hxx"
39
#include "cdplugins/cdplugin.hxx"
40
#include "cdplugins/tidal.hxx"
39
#include "cdplugins/tidal.hxx"
41
40
42
using namespace std;
41
using namespace std;
43
using namespace std::placeholders;
42
using namespace std::placeholders;
44
using namespace UPnPProvider;
43
using namespace UPnPProvider;
...
...
54
    }
53
    }
55
    }
54
    }
56
    CDPlugin *pluginFactory(const string& appname) {
55
    CDPlugin *pluginFactory(const string& appname) {
57
    LOGDEB("ContentDirectory::pluginFactory: for " << appname << endl);
56
    LOGDEB("ContentDirectory::pluginFactory: for " << appname << endl);
58
57
59
    if (httphp.empty()) {
58
    if (host.empty()) {
60
        UpnpDevice *dev;
59
        UpnpDevice *dev;
61
        if (!service || !(dev = service->getDevice())) {
60
        if (!service || !(dev = service->getDevice())) {
62
        LOGERR("ContentDirectory::Internal: no service or dev ??\n");
61
        LOGERR("ContentDirectory::Internal: no service or dev ??\n");
63
        return nullptr;
62
        return nullptr;
64
        }
63
        }
65
      string host;
66
        unsigned short port;
64
        unsigned short usport;
67
        if (!dev->ipv4(&host, &port)) {
65
        if (!dev->ipv4(&host, &usport)) {
68
        LOGERR("ContentDirectory::Internal: can't get server IP\n");
66
        LOGERR("ContentDirectory::Internal: can't get server IP\n");
69
        return nullptr;
67
        return nullptr;
70
        }
68
        }
71
      ostringstream ss;
69
            port = usport;
72
      ss << host << ":" << port;
73
      httphp = ss.str();
74
        LOGDEB("ContentDirectory: host:port: " << httphp << endl);
70
        LOGDEB("ContentDirectory: host "<< host<< " port " << port << endl);
75
  }
76
  VirtualDir *dir = VirtualDir::getVirtualDir();
77
  if (dir == nullptr) {
78
      LOGERR("CDPlugin::factory: getVirtualDir() failed\n");
79
      return nullptr;
80
    }
71
    }
81
    if (!appname.compare("tidal")) {
72
    if (!appname.compare("tidal")) {
82
      string pthcdplugs = path_cat(g_datadir, "cdplugins");
73
      Tidal *tidal = new Tidal("tidal", service);
83
      Tidal *tidal =
84
      new Tidal({pthcdplugs, path_cat(pthcdplugs, appname)},
85
            httphp, "/tidal");
86
      if (tidal) {
87
      dir->addVDir("/tidal", tidal->getFileOps());
88
      }
89
        return tidal;
74
        return tidal;
90
    } else {
75
    } else {
91
        return nullptr;
76
        return nullptr;
92
    }
77
    }
93
    }
78
    }
...
...
103
        return plug;
88
        return plug;
104
    }
89
    }
105
    }
90
    }
106
    unordered_map<string, CDPlugin *> plugins;
91
    unordered_map<string, CDPlugin *> plugins;
107
    ContentDirectory *service;
92
    ContentDirectory *service;
108
    string httphp;
93
    string host;
94
    int port;
109
    string updateID;
95
    string updateID;
110
};
96
};
111
97
112
static const string
98
static const string
113
sTpContentDirectory("urn:schemas-upnp-org:service:ContentDirectory:1");
99
sTpContentDirectory("urn:schemas-upnp-org:service:ContentDirectory:1");
...
...
404
    data.addarg("NumberReturned", out_NumberReturned);
390
    data.addarg("NumberReturned", out_NumberReturned);
405
    data.addarg("TotalMatches", out_TotalMatches);
391
    data.addarg("TotalMatches", out_TotalMatches);
406
    data.addarg("UpdateID", out_UpdateID);
392
    data.addarg("UpdateID", out_UpdateID);
407
    return UPNP_E_SUCCESS;
393
    return UPNP_E_SUCCESS;
408
}
394
}
395
396
std::string ContentDirectory::getpathprefix(CDPlugin *plg)
397
{
398
    return string("/") + plg->getname();
399
}
400
401
402
std::string ContentDirectory::getupnpaddr(CDPlugin *)
403
{
404
    return m->host;
405
}
406
407
408
int ContentDirectory::getupnpport(CDPlugin *)
409
{
410
    return m->port;
411
}
412
413
414
bool ContentDirectory::setfileops(CDPlugin *plg, const std::string& path,
415
                                  UPnPProvider::VirtualDir::FileOps ops)
416
{
417
    VirtualDir *dir = VirtualDir::getVirtualDir();
418
    if (dir == nullptr) {
419
        LOGERR("ContentDirectory::setfileops: getVirtualDir() failed\n");
420
        return false;
421
    }
422
    string prefix = getpathprefix(plg);
423
    if (path.find(prefix) != 0) {
424
        LOGERR("ContentDirectory::setfileops: dir path should begin with: " <<
425
               prefix);
426
        return false;
427
    }
428
        
429
    dir->addVDir(path, ops);
430
    return true;
431
}
432
433
434
ConfSimple *ContentDirectory::getconfig(CDPlugin *)
435
{
436
    return g_config;
437
}
438
439
440
const std::vector<std::string> ContentDirectory::getexecpath(CDPlugin *plg)
441
{
442
    string pthcdplugs = path_cat(g_datadir, "cdplugins");
443
    return {pthcdplugs, path_cat(pthcdplugs, plg->getname())};
444
}