Switch to unified view

a/src/cdplugins/plgwithslave.cxx b/src/cdplugins/plgwithslave.cxx
...
...
15
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
15
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
16
 */
16
 */
17
17
18
#include "plgwithslave.hxx"
18
#include "plgwithslave.hxx"
19
19
20
#define LOGGER_LOCAL_LOGINC 3
21
22
#include <fcntl.h>
20
#include <fcntl.h>
23
21
24
#include <string>
22
#include <string>
25
#include <vector>
23
#include <vector>
26
#include <sstream>
24
#include <sstream>
27
#include <string.h>
25
#include <string.h>
28
#include <upnp/upnp.h>
26
#include <upnp/upnp.h>
29
#include <microhttpd.h>
27
#include <microhttpd.h>
30
extern "C" {
31
#include <libavformat/avio.h>
32
#include <libavformat/avformat.h>
33
}
34
35
28
36
#include "cmdtalk.h"
29
#include "cmdtalk.h"
37
#include "pathut.h"
30
#include "pathut.h"
38
#include "smallut.h"
31
#include "smallut.h"
39
#include "log.hxx"
32
#include "log.hxx"
40
#include "json.hpp"
33
#include "json/json.h"
41
#include "main.hxx"
34
#include "main.hxx"
42
#include "conftree.h"
35
#include "conftree.h"
43
36
44
using namespace std;
37
using namespace std;
45
using namespace std::placeholders;
38
using namespace std::placeholders;
46
using json = nlohmann::json;
39
//using json = nlohmann::json;
47
using namespace UPnPProvider;
40
using namespace UPnPProvider;
48
41
49
class StreamHandle {
42
class StreamHandle {
50
public:
43
public:
51
    StreamHandle(PlgWithSlave::Internal *plg) {
44
    StreamHandle(PlgWithSlave::Internal *plg) {
...
...
60
        len = 0;
53
        len = 0;
61
        opentime = 0;
54
        opentime = 0;
62
    }
55
    }
63
    
56
    
64
    PlgWithSlave::Internal *plg;
57
    PlgWithSlave::Internal *plg;
65
    AVIOContext *avio;
66
    string path;
58
    string path;
67
    string media_url;
59
    string media_url;
68
    long long len;
60
    long long len;
69
    time_t opentime;
61
    time_t opentime;
70
};
62
};
...
...
290
PlgWithSlave::~PlgWithSlave()
282
PlgWithSlave::~PlgWithSlave()
291
{
283
{
292
    delete m;
284
    delete m;
293
}
285
}
294
286
295
#define JSONTOUPS(fld, nm)                                              \
296
  it1 = decoded[i].find(#nm);                 \
297
  if (it1 != decoded[i].end()) {                  \
298
            if (it1.value() != nullptr)                                 \
299
                song.fld = it1.value();                   \
300
  }
301
302
static int resultToEntries(const string& encoded, int stidx, int cnt,
287
static int resultToEntries(const string& encoded, int stidx, int cnt,
303
               vector<UpSong>& entries)
288
               vector<UpSong>& entries)
304
{
289
{
305
    entries.clear();
290
    entries.clear();
306
    auto decoded = json::parse(encoded);
291
    Json::Value decoded;
292
    istringstream input(encoded);
293
    input >> decoded;
307
    LOGDEB0("PlgWithSlave::results: got " << decoded.size() << " entries\n");
294
    LOGDEB0("PlgWithSlave::results: got " << decoded.size() << " entries \n");
308
    LOGDEB1("PlgWithSlave::results: undecoded: " << decoded.dump() << endl);
295
    LOGDEB1("PlgWithSlave::results: undecoded: " << decoded.dump() << endl);
309
    bool dolimit = cnt > 0;
296
    bool dolimit = cnt > 0;
310
    
297
    
311
    for (unsigned int i = stidx; i < decoded.size(); i++) {
298
    for (unsigned int i = stidx; i < decoded.size(); i++) {
299
#define JSONTOUPS(fld, nm) {song.fld = decoded[i].get(#nm, "").asString();}
312
    if (dolimit && --cnt < 0) {
300
    if (dolimit && --cnt < 0) {
313
        break;
301
        break;
314
    }
302
    }
315
    UpSong song;
303
    UpSong song;
316
    // tp is container ("ct") or item ("it")
304
    // tp is container ("ct") or item ("it")
317
  auto it1 = decoded[i].find("tp");
305
        string stp = decoded[i].get("tp", "").asString();
318
  if (it1 == decoded[i].end()) {
306
        LOGDEB("PlgWithSlave::results: tp is " << stp << endl)
319
      LOGERR("PlgWithSlave::result: no type in entry\n");
320
      continue;
321
  }
322
  string stp = it1.value();
323
  
324
    if (!stp.compare("ct")) {
307
    if (!stp.compare("ct")) {
325
        song.iscontainer = true;
308
        song.iscontainer = true;
326
            it1 = decoded[i].find("searchable");
309
            string ss = decoded[i].get("searchable", "").asString();
327
            if (it1 != decoded[i].end() && it1.value() != nullptr) {
310
            LOGDEB("PlgWithSlave::results: searchable is " << ss << endl)
328
                string ss = it1.value();
311
            if (!ss.empty()) {
329
                song.searchable = stringToBool(ss);
312
                song.searchable = stringToBool(ss);
330
            }
313
            }
331
    } else  if (!stp.compare("it")) {
314
    } else  if (!stp.compare("it")) {
332
        song.iscontainer = false;
315
        song.iscontainer = false;
333
        JSONTOUPS(uri, uri);
316
        JSONTOUPS(uri, uri);
334
        JSONTOUPS(artist, dc:creator);
317
        JSONTOUPS(artist, dc:creator);
335
        JSONTOUPS(genre, upnp:genre);
318
        JSONTOUPS(genre, upnp:genre);
336
        JSONTOUPS(tracknum, upnp:originalTrackNumber);
319
        JSONTOUPS(tracknum, upnp:originalTrackNumber);
337
      JSONTOUPS(duration_secs, duration);
320
            string sdur = decoded[i].get("duration", "").asString();
321
            if (!sdur.empty()) {
322
                song.duration_secs = atoi(sdur.c_str());
323
            }
338
    } else {
324
    } else {
339
        LOGERR("PlgWithSlave::result: bad type in entry: " <<
325
        LOGERR("PlgWithSlave::result: bad type in entry: " << stp << endl);
340
                   it1.value() << endl);
341
        continue;
326
        continue;
342
    }
327
    }
343
    JSONTOUPS(id, id);
328
    JSONTOUPS(id, id);
344
    JSONTOUPS(parentid, pid);
329
    JSONTOUPS(parentid, pid);
345
    JSONTOUPS(title, tt);
330
    JSONTOUPS(title, tt);