Switch to unified view

a/src/mediaserver/cdplugins/plgwithslave.cxx b/src/mediaserver/cdplugins/plgwithslave.cxx
...
...
24
#include <functional>
24
#include <functional>
25
25
26
#include <string.h>
26
#include <string.h>
27
#include <fcntl.h>
27
#include <fcntl.h>
28
#include <upnp/upnp.h>
28
#include <upnp/upnp.h>
29
#include <microhttpd.h>
30
#include <json/json.h>
29
#include <json/json.h>
31
#include <libupnpp/log.hxx>
30
#include <libupnpp/log.hxx>
32
31
33
#include "cmdtalk.h"
32
#include "cmdtalk.h"
34
#include "pathut.h"
33
#include "pathut.h"
...
...
73
class PlgWithSlave::Internal {
72
class PlgWithSlave::Internal {
74
public:
73
public:
75
    Internal(PlgWithSlave *_plg, const string& hst,
74
    Internal(PlgWithSlave *_plg, const string& hst,
76
             int prt, const string& pp)
75
             int prt, const string& pp)
77
        : plg(_plg), cmd(read_timeout), upnphost(hst),
76
        : plg(_plg), cmd(read_timeout), upnphost(hst),
78
          upnpport(prt), pathprefix(pp), laststream(this) { }
77
          upnpport(prt), pathprefix(pp), laststream(this) {
79
78
79
        string val;
80
        if (g_config->get("plgproxymethod", val) && !val.compare("proxy")) {
81
            doingproxy = true;
82
        }
83
    }
84
85
    bool doproxy() {
86
        return doingproxy;
87
    }
80
    bool maybeStartCmd();
88
    bool maybeStartCmd();
81
89
82
    PlgWithSlave *plg;
90
    PlgWithSlave *plg;
83
    CmdTalk cmd;
91
    CmdTalk cmd;
84
    // Upnp Host and port. This would only be used to generate URLs *if*
92
    // Upnp Host and port. This would only be used to generate URLs
85
    // we were using the libupnp miniserver. We currently use
93
    // *if* we were using the libupnp miniserver. We currently use
86
    // microhttp because it can do redirects
94
    // microhttp because it can do redirects
87
    string upnphost;
95
    string upnphost;
88
    int upnpport;
96
    int upnpport;
89
    // path prefix (this is used by upmpdcli that gets it for us).
97
    // path prefix (this is used by upmpdcli that gets it for us).
90
    string pathprefix;
98
    string pathprefix;
99
    bool doingproxy{false};
91
    
100
    
92
    // Cached uri translation
101
    // Cached uri translation
93
    StreamHandle laststream;
102
    StreamHandle laststream;
94
};
103
};
95
104
...
...
107
        dynamic_cast<PlgWithSlave*>(cdsrv->getpluginforpath(url));
116
        dynamic_cast<PlgWithSlave*>(cdsrv->getpluginforpath(url));
108
    if (nullptr == realplg) {
117
    if (nullptr == realplg) {
109
        LOGERR("PlgWithSlave::translateurl: no plugin for path ["<<url<< endl);
118
        LOGERR("PlgWithSlave::translateurl: no plugin for path ["<<url<< endl);
110
        return StreamProxy::Error;
119
        return StreamProxy::Error;
111
    }
120
    }
112
113
    // We may need one day to subclass PlgWithSlave to implement a
114
    // plugin-specific method. For now, existing plugins have
115
    // compatible python code, and we can keep one c++ method.
116
    // get_media_url() would also need changing because it is in
117
    // Internal: either make it generic or move to subclass.
118
    //return realplg->answer_to_connection(connection, url, method, version,
119
    //                               upload_data, upload_data_size, con_cls);
120
121
121
    string path(url);
122
    string path(url);
122
123
123
    // The streaming services plugins set a trackId parameter in the
124
    // The streaming services plugins set a trackId parameter in the
124
    // URIs. This gets parsed out by mhttpd. We rebuild a full url
125
    // URIs. This gets parsed out by mhttpd. We rebuild a full url
...
...
134
    url = realplg->get_media_url(path);
135
    url = realplg->get_media_url(path);
135
    if (url.empty()) {
136
    if (url.empty()) {
136
        LOGERR("answer_to_connection: no media_uri for: " << url << endl);
137
        LOGERR("answer_to_connection: no media_uri for: " << url << endl);
137
        return StreamProxy::Error;
138
        return StreamProxy::Error;
138
    }
139
    }
139
    return StreamProxy::Proxy;
140
    return realplg->doproxy() ? StreamProxy::Proxy : StreamProxy::Redirect;
140
}
141
}
141
142
142
// Static
143
// Static
143
bool PlgWithSlave::startPluginCmd(CmdTalk& cmd, const string& appname,
144
bool PlgWithSlave::startPluginCmd(CmdTalk& cmd, const string& appname,
144
                                  const string& host, unsigned int port,
145
                                  const string& host, unsigned int port,
...
...
278
}
279
}
279
280
280
PlgWithSlave::~PlgWithSlave()
281
PlgWithSlave::~PlgWithSlave()
281
{
282
{
282
    delete m;
283
    delete m;
284
}
285
286
bool PlgWithSlave::doproxy()
287
{
288
    return m->doproxy();
283
}
289
}
284
290
285
static void catstring(string& dest, const string& s2)
291
static void catstring(string& dest, const string& s2)
286
{
292
{
287
    if (s2.empty()) {
293
    if (s2.empty()) {