Exemplo n.º 1
0
void RecordingsResponder::deleteRecording(ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply)
{
  QueryHandler q("/recordings", request);
  cRecording* delRecording = getRecordingByRequestWrite(q);
  string syncId = q.getOptionAsString("syncId");

  if ( delRecording == NULL ) {
      reply.httpReturn(404, "Recording not found!");
      return;
  }

  esyslog("restfulapi: delete recording %s", delRecording->FileName());
  if ( delRecording->Delete() ) {

    if (syncId != "") {
      SyncMap* syncMap = new SyncMap(q, true);
      syncMap->erase(StringExtension::toString(delRecording->FileName()));
    }

#if APIVERSNUM > 20300
    LOCK_RECORDINGS_WRITE;
    cRecordings& recordings = *Recordings;
#else
    cRecordings& recordings = Recordings;
#endif
    recordings.DelByName(delRecording->FileName());
    reply.httpReturn(200, "Recording deleted!");
    return;
  }
  reply.httpReturn(500, "Recording could not be deleted!");
}
Exemplo n.º 2
0
void RemoteResponder::reply(ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply)
{
  QueryHandler::addHeader(reply);
  if (request.method() != "POST") {
     reply.httpReturn(403, "Only POST method is support by the remote control");
     return;
  }

  if ( (int)request.url().find("/remote/switch") != -1 ) {
     QueryHandler q("/remote/switch", request);
     cChannel* channel = VdrExtension::getChannel(q.getParamAsString(0));
     if ( channel == NULL ) {
        reply.httpReturn(404, "Channel-Id is not valid.");
     /*} else if ( !Channels.SwitchTo( channel->Number() ) ) {
        reply.httpReturn(404, "Couldn't switch to channel.");
     }*/
     } else {
        TaskScheduler::get()->SwitchableChannel(channel->GetChannelID());
     }

     return;
  } 

  QueryHandler q("/remote", request);
  string key = q.getParamAsString(0);

  if (key.length() == 0) {
     reply.httpReturn(404, "Please add a key to the parameter list, see API-file for more details.");
     return;
  }

  if (!keyPairList->hitKey(key.c_str())) {
     reply.httpReturn(404, "Remote Control does not support the requested key.");
  }
}
Exemplo n.º 3
0
void RecordingsResponder::rewindRecording(std::ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply)
{
  QueryHandler q("/recordings/rewind", request);
#if APIVERSNUM > 20300
  LOCK_RECORDINGS_READ;
  const cRecordings& recordings = *Recordings;
#else
  cThreadLock RecordingsLock(&Recordings);
  cRecordings& recordings = Recordings;
#endif
  const cRecording* recording = NULL;
    
  string recording_file = q.getBodyAsString("file");
  if (recording_file.length() > 0)
     recording = recordings.GetByName(recording_file.c_str());
  else {
     int recording_number = q.getParamAsInt(0);
     if (recording_number < 0 || recording_number >= recordings.Count())
        reply.httpReturn(404, "Wrong recording number!");
    else
        recording = recordings.Get(recording_number);
  }
    
  if (recording != NULL) {
     TaskScheduler::get()->SetRewind(true);
     TaskScheduler::get()->SwitchableRecording(recording);
  } else {
     reply.httpReturn(404, "Wrong recording name or number!");
  }
}
void RecordingsResponder::showCutterStatus(ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply)
{
  QueryHandler q("/recordings/cut", request);
  StreamExtension s(&out);

  bool active = cCutter::Active();

  if (q.isFormat(".html")) {
     reply.addHeader("Content-Type", "text/html; charset=utf-8");
     s.writeHtmlHeader("HtmlCutterStatus");
     s.write((active ? "True" : "False"));
     s.write("</body></html>");
  } else if (q.isFormat(".json")) {
     reply.addHeader("Content-Type", "application/json; charset=utf-8");
     cxxtools::JsonSerializer serializer(out);
     serializer.serialize(active, "active");
     serializer.finish();     
  } else if (q.isFormat(".xml")) {
     reply.addHeader("Content-Type", "text/xml; charset=utf-8");
     s.write("<cutter xmlns=\"http://www.domain.org/restfulapi/2011/cutter-xml\">\n");
     s.write(cString::sprintf(" <param name=\"active\">%s</param>\n", (active ? "true" : "false")));
     s.write("</cutter>");
  } else {
     reply.httpReturn(502, "Only the following formats are supported: .xml, .json and .html");
  } 
}
void RecordingsResponder::saveMarks(ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply)
{
  QueryHandler q("/recordings/marks", request);
  int recording = q.getParamAsInt(0);
  JsonArray* jsonArray = q.getBodyAsArray("marks");

  if (jsonArray == NULL) {
     reply.httpReturn(503, "Marks in HTTP-Body are missing.");
  }

  if (recording < 0 && recording >= Recordings.Count()) {
     reply.httpReturn(504, "Recording number missing or invalid.");
  }

  vector< string > marks;

  for(int i=0;i<jsonArray->CountItem();i++) {
     JsonBase* jsonBase = jsonArray->GetItem(i);
     if (jsonBase->IsBasicValue()) {
        JsonBasicValue* jsonBasicValue = (JsonBasicValue*)jsonBase;
        if (jsonBasicValue->IsString()) {
           marks.push_back(jsonBasicValue->ValueAsString());
        }
     }
  }

  VdrMarks::get()->saveMarks(Recordings.Get(recording), marks);
}
Exemplo n.º 6
0
void RecordingsResponder::replyEditedFileName(ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply) {

   QueryHandler q("/recordings/editedfile", request);
   
   const cRecording* recording	= getRecordingByRequest(q);
   if (recording == NULL) {
      reply.httpReturn(404, "Requested recording not found!");
      return;
   }
   
   RecordingList* recordingList	= getRecordingList(out, q, reply);
   if (recordingList == NULL) {
      return;
   }

#if APIVERSNUM > 20300
   LOCK_RECORDINGS_READ;
   const cRecordings& recordings = *Recordings;
#else
   cRecordings& recordings = Recordings;
#endif
    
   const cRecording* editedFile = recordings.GetByName(cCutter::EditedFileName(recording->FileName()));
   if (editedFile == NULL) {
      reply.httpReturn(404, "Requested edited file not found!");
      return;
   }

   recordingList->init();
   recordingList->addRecording(editedFile, editedFile->Index(), NULL, "");
   recordingList->setTotal(recordings.Count());
   recordingList->finish();
   delete recordingList;
};
Exemplo n.º 7
0
void TimersResponder::deleteTimer(ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply)
{
  QueryHandler q("/timers", request);

  if ( Timers.BeingEdited() ) {
     reply.httpReturn(502, "Timers are being edited - try again later");
     return;
  }

  TimerValues v;

  cTimer* timer = v.ConvertTimer(q.getParamAsString(0));
 
  if ( timer == NULL) {
     reply.httpReturn(404, "Timer id invalid!");
  } else {
     if ( timer->Recording() ) {
        timer->Skip();
        cRecordControls::Process(time(NULL));
     }
     Timers.Del(timer);
     Timers.SetModified();
     reply.httpReturn(200, "Timer deleted."); 
  }
}
void SearchTimersResponder::reply(ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply)
{
  QueryHandler::addHeader(reply);
  cPlugin* plugin = cPluginManager::GetPlugin("epgsearch");
  if (plugin == NULL) {
     reply.httpReturn(403, "Epgsearch isn't installed!");
     return; 
  }

  if ((int)request.url().find("/searchtimers/search/") == 0 ) {
     replySearch(out, request, reply);
  } else { 
     if (request.method() == "GET") {
        replyShow(out, request, reply);
     } else if (request.method() == "POST") {
        replyCreate(out, request, reply);
     } else if (request.method() == "DELETE") {
        replyDelete(out, request, reply);
     } else if (request.method() == "OPTIONS") {
        return;	
     } else {
        reply.httpReturn(404, "The searchtimer-service does only support the following methods: GET, POST and DELETE.");
     }
  }
}
Exemplo n.º 9
0
void RemoteResponder::reply(ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply)
{
  QueryHandler::addHeader(reply);

  if ( request.method() == "OPTIONS" ) {
      reply.addHeader("Allow", "POST");
      reply.httpReturn(200, "OK");
      return;
  }

  if (request.method() != "POST") {
     reply.httpReturn(403, "Only POST method is support by the remote control");
     return;
  }

  if ( (int)request.url().find("/remote/switch") != -1 ) {
     QueryHandler q("/remote/switch", request);
     const cChannel* channel = VdrExtension::getChannel(q.getParamAsString(0));
     if ( channel == NULL ) {
        reply.httpReturn(404, "Channel-Id is not valid.");
     } else {
        TaskScheduler::get()->SwitchableChannel(channel->GetChannelID());
     }

     return;
  } 

  if (!keyPairList->hitKey(request, reply)) {
     reply.httpReturn(404, "Remote Control does not support the requested key.");
  }
}
Exemplo n.º 10
0
void ChannelsResponder::replyImage(std::ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply)
{
  StreamExtension se(&out);
  QueryHandler q("/channels/image/", request);
  
  std::string channelid = q.getParamAsString(0);
  cChannel* channel = VdrExtension::getChannel(channelid);
  std::string imageFolder = Settings::get()->ChannelLogoDirectory() + (std::string)"/";
  
  if (channel == NULL) {
     reply.httpReturn(502, "Channel not found!");
     return;
  }

  std::string imageName = FileCaches::get()->searchChannelLogo(channel);

  if (imageName.length() == 0 ) {
     reply.httpReturn(502, "No image found!");
     return;
  }
  
  std::string absolute_path = imageFolder + imageName;
  std::string contenttype = (std::string)"image/" + imageName.substr( imageName.find_last_of('.') + 1 );
  if ( se.writeBinary(absolute_path) ) {
     reply.addHeader("Content-Type", contenttype.c_str());
  } else {
    reply.httpReturn(502, "Binary Output failed");
  }
}
void SearchTimersResponder::replyDelete(ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply)
{
  QueryHandler q("/searchtimers", request);
  vdrlive::SearchTimers searchTimers;
  string id = q.getParamAsString(0);
  bool result = searchTimers.Delete(id);

  if (!result)
     reply.httpReturn(408, "Deleting searchtimer failed!");
  else
     reply.httpReturn(200, "Searchtimer deleted.");  
}
void RecordingsResponder::cutRecording(ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply)
{
  QueryHandler q("/recordings/cut", request);
  int rec_number = q.getParamAsInt(0);
  if (rec_number >= 0 && rec_number < Recordings.Count()) {
     cRecording* recording = Recordings.Get(rec_number);
     if (cCutter::Active()) {
        reply.httpReturn(504, "VDR Cutter currently busy.");
     } else {
        cCutter::Start(recording->FileName());
     }
     return;
  }
  reply.httpReturn(503, "Cutting recordings failed.");
}
void RecordingsResponder::playRecording(std::ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply)
{
  QueryHandler q("/recordings/play", request);
  int recording_number = q.getParamAsInt(0);
  if ( recording_number < 0 || recording_number >= Recordings.Count() ) {
     reply.httpReturn(404, "Wrong recording number!");
  } else {
     cRecording* recording = Recordings.Get(recording_number);
     if ( recording != NULL ) {
        TaskScheduler::get()->SwitchableRecording(recording);
     } else {
        reply.httpReturn(404, "Wrong recording number!");
     }
  }
}
Exemplo n.º 14
0
void RecordingsResponder::reply(std::ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply)
{
  QueryHandler::addHeader(reply);
  bool found = false;

  if ((int)request.url().find("/recordings/cut") == 0 ) {
     if ( request.method() == "GET" ) {
	showCutterStatus(out, request, reply);
     } else if (request.method() == "POST") {
        cutRecording(out, request, reply); 
     } else {
        reply.httpReturn(501, "Only GET and POST methods are supported by the /recordings/cut service.");
     }
     found = true;
  }

  else if ((int)request.url().find("/recordings/marks") == 0 ) {
     if ( request.method() == "DELETE" ) {
        deleteMarks(out, request, reply);
     } else if (request.method() == "POST" ) {
        saveMarks(out, request, reply);
     } else {
        reply.httpReturn(501, "Only DELETE and POST methods are supported by the /recordings/marks service.");
     }
     found = true;
  }

  // original /recordings service
  else if ((int) request.url().find("/recordings") == 0 ) {
        if ( request.method() == "GET" ) {
        showRecordings(out, request, reply);
        found = true;
     } else if (request.method() == "DELETE" ) {
        deleteRecording(out, request,reply);
        found = true;
     } else {
        reply.httpReturn(501, "Only GET and DELETE methods are supported by the /recordings service.");
     }
     found = true;
  }

  if (!found) {
     reply.httpReturn(403, "Service not found");
  }
}
void RecordingsResponder::rewindRecording(std::ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply)
{
  QueryHandler q("/recordings/play", request);
  int recording_number = q.getParamAsInt(0);
  if ( recording_number < 0 || recording_number >= Recordings.Count() ) {
     reply.httpReturn(404, "Wrong recording number!");
  } else {
     cRecording* recording = Recordings.Get(recording_number);
     if ( recording != NULL ) {
        cDevice::PrimaryDevice()->StopReplay(); // must do this first to be able to rewind the currently replayed recording
        cResumeFile ResumeFile(recording->FileName(), recording->IsPesRecording());
        ResumeFile.Delete();
        TaskScheduler::get()->SwitchableRecording(recording);
     } else {
        reply.httpReturn(404, "Wrong recording number!");
     }
  }
}
Exemplo n.º 16
0
void TimersResponder::showTimers(ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply)
{
  QueryHandler q("/timers", request);
  TimerList* timerList;
 
  Timers.SetModified();

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

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

  string timer_id = q.getParamAsString(0);

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

  timerList->init();

  vector< cTimer* > timers = VdrExtension::SortedTimers();
  for (int i=0;i<(int)timers.size();i++)
  {
     if ( VdrExtension::getTimerID(timers[i]) == timer_id || timer_id.length() == 0 ) {
        timerList->addTimer(timers[i]);   
     }
  }
  timerList->setTotal((int)timers.size());

  timerList->finish();
  delete timerList;   
}
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;
}
Exemplo n.º 18
0
void EventsResponder::replyImage(ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply)
{
  QueryHandler q("/events/image", request);
  if ( request.method() != "GET") {
     reply.httpReturn(403, "To retrieve information use the GET method!");
     return;
  }

  StreamExtension se(&out);
  int eventid = q.getParamAsInt(0);
  int number = q.getParamAsInt(1);
  double timediff = -1;
  
  vector< string > images;
  
  FileCaches::get()->searchEventImages(eventid, images);

  if (number < 0 || number >= (int)images.size()) {
     reply.httpReturn(404, "Could not find image because of invalid image number!");
     return;
  }

  string image = images[number];
  string type = image.substr(image.find_last_of(".")+1);
  string contenttype = (string)"image/" + type;
  string path = Settings::get()->EpgImageDirectory() + (string)"/" + image;

  if (request.hasHeader("If-Modified-Since")) {
      timediff = difftime(FileExtension::get()->getModifiedTime(path), FileExtension::get()->getModifiedSinceTime(request));
  }

  if (timediff > 0.0 || timediff < 0.0) {
    if ( se.writeBinary(path) ) {
       reply.addHeader("Content-Type", contenttype.c_str());
       FileExtension::get()->addModifiedHeader(path, reply);
    } else {
       reply.httpReturn(404, "Could not find image!");
    }
  } else {
      reply.httpReturn(304, "Not-Modified");
  }
}
Exemplo n.º 19
0
void RecordingsResponder::deleteMarks(ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply)
{
  QueryHandler q("/recordings/marks", request);
  const cRecording* recording = getRecordingByRequest(q);
  if ( recording != NULL ) {
     if (VdrMarks::get()->deleteMarks(recording)) {
        return;
     }
  }
  reply.httpReturn(503, "Deleting marks failed.");
}
void SearchTimersResponder::replySearch(ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply)
{
  QueryHandler q("/searchtimers/search", request);
  vdrlive::SearchResults searchResults;
  int id = q.getParamAsInt(0);

  EventList* eventList;

  if ( q.isFormat(".json") ) {
     reply.addHeader("Content-Type", "application/json; charset=utf-8");
     eventList = (EventList*)new JsonEventList(&out);
  } else if ( q.isFormat(".html") ) {
     reply.addHeader("Content-Type", "text/html; charset=utf-8");
     eventList = (EventList*)new HtmlEventList(&out);
  } else if ( q.isFormat(".xml") ) {
     reply.addHeader("Content-Type", "text/xml; charset=utf-8");
     eventList = (EventList*)new XmlEventList(&out);
  } else {
     reply.httpReturn(403, "Resources are not available for the selected format. (Use: .json, .xml or .html)");
     return;
  }
  
  searchResults.GetByID(id);

  int start_filter = q.getOptionAsInt("start");
  int limit_filter = q.getOptionAsInt("limit");
  if ( start_filter >= 0 && limit_filter >= 1 )
     eventList->activateLimit(start_filter, limit_filter);
  
  eventList->init();
  int total = 0;
  
  for (vdrlive::SearchResults::iterator item = searchResults.begin(); item != searchResults.end(); ++item) {
    eventList->addEvent((cEvent*)item->GetEvent());
    total++;
  }

  eventList->setTotal(total);
  eventList->finish();
  delete eventList;
}
Exemplo n.º 21
0
void ChannelsResponder::replyGroups(std::ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply)
{ 
  QueryHandler q("/channels/groups", request);
  ChannelGroupList* channelGroupList;
  
  if ( q.isFormat(".json") ) {
    reply.addHeader("Content-Type", "application/json; charset=utf-8");
    channelGroupList = (ChannelGroupList*)new JsonChannelGroupList(&out);
  } else if ( q.isFormat(".html") ) {
    reply.addHeader("Content-Type", "text/html; charset=utf-8");
    channelGroupList = (ChannelGroupList*)new HtmlChannelGroupList(&out);
  } else if ( q.isFormat(".xml") ) {
    reply.addHeader("Content-Type", "text/xml; charset=utf-8");
    channelGroupList = (ChannelGroupList*)new XmlChannelGroupList(&out);
  } else {
    reply.httpReturn(403, "Resources are not available for the selected format. (Use: .json, .html or .xml)");
    return;
  }

  int start_filter = q.getOptionAsInt("start");
  int limit_filter = q.getOptionAsInt("limit");
  if ( start_filter >= 0 && limit_filter >= 1 ) {
     channelGroupList->activateLimit(start_filter, limit_filter);
  }

  channelGroupList->init();
  int total = 0;
  
  for (cChannel *channel = Channels.First(); channel; channel = Channels.Next(channel))
  {
      if (channel->GroupSep()) {
         channelGroupList->addGroup((std::string)channel->Name());
         total++;
      }
  }

  channelGroupList->setTotal(total);
  channelGroupList->finish();

  delete channelGroupList;
}
void SearchTimersResponder::replyCreate(ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply)
{
  QueryHandler q("/searchtimers", request);
  vdrlive::SearchTimer* searchTimer = new vdrlive::SearchTimer();
  vdrlive::SearchTimers searchTimers;
  string result = searchTimer->LoadFromQuery(q);

  if (result.length() > 0)
  { 
     reply.httpReturn(406, result.c_str());
  } else {
     bool succeeded = searchTimers.Save(searchTimer);
     if(succeeded) {
        reply.httpReturn(200, (const char*)cString::sprintf("OK, Id:%i", searchTimer->Id()));
     } else {
        reply.httpReturn(407, "Creating searchtimer failed.");
     }
  }

  delete searchTimer;
}
void RecordingsResponder::deleteMarks(ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply)
{
  QueryHandler q("/recordings/marks", request);
  int rec_number = q.getParamAsInt(0);
  if (rec_number >= 0 && rec_number < Recordings.Count()) {
     cRecording* recording = Recordings.Get(rec_number);
     if (VdrMarks::get()->deleteMarks(recording)) {
        return;
     }
  }
  reply.httpReturn(503, "Deleting marks failed.");
}
void SearchTimersResponder::replyShow(ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply)
{
  QueryHandler q("/searchtimers", request);
  vdrlive::SearchTimers service;
  SearchTimerList* stList;

  if (q.isFormat(".json")) {
     reply.addHeader("Content-Type", "application/json; charset=utf-8");
     stList = (SearchTimerList*)new JsonSearchTimerList(&out);
  } else if ( q.isFormat(".html")) {
     reply.addHeader("Content-Type", "text/html; charset=utf-8");
     stList = (SearchTimerList*)new HtmlSearchTimerList(&out);
  } else if ( q.isFormat(".xml")) {
     reply.addHeader("Content-Type", "text/xml; charset=utf-8");
     stList = (SearchTimerList*)new XmlSearchTimerList(&out);
  } else {
     reply.httpReturn(405, "Resources are not available for the selected format. (Use: .json, .html or .xml)");
     return;
  }

  int start_filter = q.getOptionAsInt("start");
  int limit_filter = q.getOptionAsInt("limit");
  if ( start_filter >= 0 && limit_filter >= 1 ) stList->activateLimit(start_filter, limit_filter);

  stList->init();
  int counter = 0;

  for(vdrlive::SearchTimers::iterator timer = service.begin(); timer != service.end(); ++timer)
  { 
    SerSearchTimerContainer container;
    container.timer = &(*timer);
    stList->addSearchTimer(container);
    counter++;
  }

  stList->setTotal(counter);
  stList->finish();
  
  delete stList;
}
Exemplo n.º 25
0
void OsdResponder::reply(ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply)
{
  QueryHandler q("/osd", request);

  if ( request.method() != "GET" ) {
     reply.httpReturn(403, "Only GET-method is supported!");
     return;
  }

  BasicOsd* osd = StatusMonitor::get()->getOsd();

  if ( osd == NULL ) {
     if ( q.isFormat(".html") ) {
        reply.addHeader("Content-Type", "text /html; charset=utf-8");
        printEmptyHtml(out);
        return;
     } else {
        reply.httpReturn(404, "No OSD opened!");
        return;
     }
  }

  string format = "";
  if ( q.isFormat(".json") ) {
     reply.addHeader("Content-Type", "application/json; charset=utf-8");
     format = ".json";
  } else if ( q.isFormat(".html") ) {
     format = ".html";
     reply.addHeader("Content-Type", "text/html; charset=utf-8");
  } else if ( q.isFormat(".xml") ) {
     reply.addHeader("Content-Type", "text/xml; charset=utf-8");
     format = ".xml";
  } else {
     reply.httpReturn(403, "Resources are not available for the selected format. (Use: .json, .html or .xml)");
     return;
  }

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

  switch(osd->Type())
  {
     case 0x01: printTextOsd(out, (TextOsd*)osd, format, start_filter, limit_filter);
                break;
     case 0x02: { ChannelOsdWrapper* w = new ChannelOsdWrapper(&out);
                  w->print((ChannelOsd*)osd, format);
                  delete w; }
                break;
     case 0x03: { ProgrammeOsdWrapper* w = new ProgrammeOsdWrapper(&out);
                  w->print((ProgrammeOsd*)osd, format);
                  delete w; }
                break;
  }
}
Exemplo n.º 26
0
void TimersResponder::replyCreatedId(cTimer* timer, cxxtools::http::Request& request, cxxtools::http::Reply& reply, ostream& out)
{
  QueryHandler q("/timers", request);
  TimerList* timerList;

  if ( q.isFormat(".html") ) {
     reply.addHeader("Content-Type", "text/html; charset=utf-8");
     timerList = (TimerList*)new HtmlTimerList(&out);
  } else if ( q.isFormat(".xml") ) {
     reply.addHeader("Content-Type", "text/xml; charset=utf-8");
     timerList = (TimerList*)new XmlTimerList(&out);
  } else {
     reply.addHeader("Content-Type", "application/json; charset=utf-8");
     timerList = (TimerList*)new JsonTimerList(&out);
  }

  timerList->init();
  timerList->addTimer(timer);
  timerList->setTotal(1);
  timerList->finish();
  delete timerList;
}
void RecordingsResponder::deleteRecording(ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply)
{
  QueryHandler q("/recordings", request);
  int recording_number = q.getParamAsInt(0);
  if ( recording_number < 0 || recording_number >= Recordings.Count() ) { 
     reply.httpReturn(404, "Wrong recording number!");
  } else {
     cRecording* delRecording = Recordings.Get(recording_number);
     if ( delRecording->Delete() ) {
        Recordings.DelByName(delRecording->FileName());
     }
  }
}
Exemplo n.º 28
0
void EventsResponder::reply(ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply)
{
  if ( request.method() == "OPTIONS" ) {
      reply.addHeader("Allow", "GET, POST");
      reply.httpReturn(200, "OK");
      return;
  }

  QueryHandler::addHeader(reply);
  if ( (int)request.url().find("/events/image/") == 0 ) {
     replyImage(out, request, reply);
  } else if ( (int)request.url().find("/events/search") == 0 ){
     replySearchResult(out, request, reply);
  }

  else if ( (int)request.url().find("/events/contentdescriptors") == 0 ){
      replyContentDescriptors(out, request, reply);
  }

  else {
     replyEvents(out, request, reply);
  }
}
Exemplo n.º 29
0
void TimersResponder::reply(ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply)
{
  QueryHandler::addHeader(reply);

  if ( request.method() == "OPTIONS" ) {
      reply.addHeader("Allow", "GET, POST, DELETE, PUT");
      reply.httpReturn(200, "OK");
      return;
  }

  if ( request.method() == "GET" ) {
      showTimers(out, request, reply);
  } else if ( request.method() == "DELETE" && (int)request.url().find("/timers/bulkdelete") == 0 ) {
      replyBulkdelete(out, request, reply);
  } else if (request.method() == "DELETE") {
      deleteTimer(out, request, reply);
  } else if ( request.method() == "POST" ) {
      createOrUpdateTimer(out, request, reply, false);
  } else if ( request.method() == "PUT" ) {
      createOrUpdateTimer(out, request, reply, true);
  } else {
      reply.httpReturn(501, "Only GET, DELETE, POST and PUT methods are supported.");
  }
}
Exemplo n.º 30
0
void InfoResponder::reply(ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply)
{
  QueryHandler::addHeader(reply);
  QueryHandler q("/info", request);

  if (request.method() != "GET") {
     reply.httpReturn(403, "Only GET method is support by the remote control");
     return;
  }
  StreamExtension se(&out);

  if (q.isFormat(".xml")) {
    reply.addHeader("Content-Type", "text/xml; charset=utf-8");
    replyXml(se);
  } else if (q.isFormat(".json")) {
    reply.addHeader("Content-Type", "application/json; charset=utf-8");
    replyJson(se);
  } else if (q.isFormat(".html")) { 
    reply.addHeader("Content-Type", "text/html; charset=utf-8");
    replyHtml(se);
  }else {
    reply.httpReturn(403, "Support formats: xml, json and html!");
  }
}