Exemplo n.º 1
0
void RecordingsResponder::showRecordings(ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply)
{
  QueryHandler q("/recordings", request);
  bool read_marks = q.getOptionAsString("marks") == "true";
  string sync_id = q.getOptionAsString("syncId");

  RecordingList* recordingList = getRecordingList(out, q, reply, read_marks);
  if (recordingList == NULL) {
     return;
  }
    
  SyncMap* sync_map = new SyncMap(q);

  int start_filter = q.getOptionAsInt("start");
  int limit_filter = q.getOptionAsInt("limit");
  
  const cRecording* recording = getRecordingByRequest(q);

  if ( start_filter >= 0 && limit_filter >= 1 ) {
     recordingList->activateLimit(start_filter, limit_filter);
  }

  recordingList->init();

#if APIVERSNUM > 20300
    LOCK_RECORDINGS_READ;
    const cRecordings& recordings = *Recordings;
#else
    cRecordings& recordings = Recordings;
#endif

  if ( recording == NULL ) {
     for (int i = 0; i < recordings.Count(); i++) {
        recordingList->addRecording(recordings.Get(i), i, sync_map, "");
     }
  } else {
     recordingList->addRecording(recording, recording->Index(), sync_map, "");
  }
  recordingList->setTotal(recordings.Count());

  recordingList->finish();
  delete recordingList;

  if (sync_map->active()) {
      sync_map->write();
  }
  delete sync_map;
}
void RecordingsResponder::showRecordings(ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply)
{
  QueryHandler q("/recordings", request);
  RecordingList* recordingList;
  bool read_marks = q.getOptionAsString("marks") == "true";

  if ( q.isFormat(".json") ) {
     reply.addHeader("Content-Type", "application/json; charset=utf-8");
     recordingList = (RecordingList*)new JsonRecordingList(&out, read_marks);
  } else if ( q.isFormat(".html") ) {
     reply.addHeader("Content-Type", "text/html; charset=utf-8");
     recordingList = (RecordingList*)new HtmlRecordingList(&out, read_marks);
  } else if ( q.isFormat(".xml") )  {
     reply.addHeader("Content-Type", "text/xml; charset=utf-8");
     recordingList = (RecordingList*)new XmlRecordingList(&out, read_marks);
  } else {
     reply.httpReturn(404, "Resources are not available for the selected format. (Use: .json or .html)");
     return;
  }

  int start_filter = q.getOptionAsInt("start");
  int limit_filter = q.getOptionAsInt("limit");
  
  int requested_item = q.getParamAsInt(0);

  if ( start_filter >= 0 && limit_filter >= 1 ) {
     recordingList->activateLimit(start_filter, limit_filter);
  }

  recordingList->init();
  
  cRecording* recording = NULL;
  for (int i = 0; i < Recordings.Count();i++) {
     if ( requested_item == i || requested_item < 0 ) {
        recording = Recordings.Get(i);
        recordingList->addRecording(recording, i); 
     }
  }
  recordingList->setTotal(Recordings.Count());

  recordingList->finish();
  delete recordingList;
}