Switch to unified view

a/src/cdplugins/plgwithslave.cxx b/src/cdplugins/plgwithslave.cxx
...
...
71
71
72
class PlgWithSlave::Internal {
72
class PlgWithSlave::Internal {
73
public:
73
public:
74
    Internal(PlgWithSlave *_plg, const string& exe, const string& hst,
74
    Internal(PlgWithSlave *_plg, const string& exe, const string& hst,
75
             int prt, const string& pp)
75
             int prt, const string& pp)
76
    : plg(_plg), exepath(exe), host(hst), port(prt), pathprefix(pp), 
76
    : plg(_plg), exepath(exe), upnphost(hst), upnpport(prt), pathprefix(pp), 
77
          laststream(this) {
77
          laststream(this) {
78
    }
78
    }
79
79
80
    bool maybeStartCmd();
80
    bool maybeStartCmd();
81
81
82
    PlgWithSlave *plg;
82
    PlgWithSlave *plg;
83
    CmdTalk cmd;
83
    CmdTalk cmd;
84
    string exepath;
84
    string exepath;
85
    // Host and port for the URLs we generate.
85
    // Upnp Host and port. This would only be used to generate URLsif
86
    // we were using the libupnp miniserver. We currently use
87
    // microhttp because it can do redirects
86
    string host;
88
    string upnphost;
87
    int port;
89
    int upnpport;
88
    // path prefix (this is used by upmpdcli that gets it for us).
90
    // path prefix (this is used by upmpdcli that gets it for us).
89
    string pathprefix;
91
    string pathprefix;
90
    
92
    
91
    // Cached uri translation
93
    // Cached uri translation
92
    StreamHandle laststream;
94
    StreamHandle laststream;
...
...
188
{
190
{
189
    if (cmd.running()) {
191
    if (cmd.running()) {
190
        return true;
192
        return true;
191
    }
193
    }
192
194
195
    ConfSimple *conf = plg->m_services->getconfig(plg);
196
    int port = 49149;
197
    string sport;
198
    if (conf->get("plgmicrohttpport", sport)) {
199
        port = atoi(sport.c_str());
200
    }
193
    if (nullptr == mhd) {
201
    if (nullptr == mhd) {
194
202
195
        // Start the microhttpd daemon. There can be only one, and it
203
        // Start the microhttpd daemon. There can be only one, and it
196
        // is started with a context handle which points to whatever
204
        // is started with a context handle which points to whatever
197
        // plugin got there first. The callback will only use the
205
        // plugin got there first. The callback will only use the
198
        // handle to get to the plugin services, and retrieve the
206
        // handle to get to the plugin services, and retrieve the
199
        // appropriate plugin based on the url path prefix.
207
        // appropriate plugin based on the url path prefix.
200
        LOGDEB("PlgWithSlave: starting httpd on port "<< port << endl);
208
        LOGDEB("PlgWithSlave: starting httpd on port "<< port << endl);
201
        ConfSimple *conf = plg->m_services->getconfig(plg);
202
        port = 49149;
203
        string sport;
204
        if (conf->get("plgmicrohttpport", sport)) {
205
            port = atoi(sport.c_str());
206
        }
207
        mhd = MHD_start_daemon(
209
        mhd = MHD_start_daemon(
208
            MHD_USE_THREAD_PER_CONNECTION,
210
            MHD_USE_THREAD_PER_CONNECTION,
209
            //MHD_USE_SELECT_INTERNALLY, 
211
            //MHD_USE_SELECT_INTERNALLY, 
210
            port, 
212
            port, 
211
            /* Accept policy callback and arg */
213
            /* Accept policy callback and arg */
...
...
223
        path_cat(g_datadir, "cdplugins") + ":" +
225
        path_cat(g_datadir, "cdplugins") + ":" +
224
        path_cat(g_datadir, "cdplugins/pycommon") + ":" +
226
        path_cat(g_datadir, "cdplugins/pycommon") + ":" +
225
        path_cat(g_datadir, "cdplugins/" + plg->m_name);
227
        path_cat(g_datadir, "cdplugins/" + plg->m_name);
226
    string configname = string("UPMPD_CONFIG=") + g_configfilename;
228
    string configname = string("UPMPD_CONFIG=") + g_configfilename;
227
    stringstream ss;
229
    stringstream ss;
228
    ss << host << ":" << port;
230
    ss << upnphost << ":" << port;
229
    string hostport = string("UPMPD_HTTPHOSTPORT=") + ss.str();
231
    string hostport = string("UPMPD_HTTPHOSTPORT=") + ss.str();
230
    string pp = string("UPMPD_PATHPREFIX=") + pathprefix;
232
    string pp = string("UPMPD_PATHPREFIX=") + pathprefix;
231
    if (!cmd.startCmd(exepath, {/*args*/},
233
    if (!cmd.startCmd(exepath, {/*args*/},
232
                      /* env */ {pythonpath, configname, hostport, pp})) {
234
                      /* env */ {pythonpath, configname, hostport, pp})) {
233
        LOGERR("PlgWithSlave::maybeStartCmd: startCmd failed\n");
235
        LOGERR("PlgWithSlave::maybeStartCmd: startCmd failed\n");