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 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; } }
void RecordingsResponder::cutRecording(ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply) { QueryHandler q("/recordings/cut", request); const cRecording* recording = getRecordingByRequest(q); if ( recording != NULL ) { #if APIVERSNUM > 20101 if (RecordingsHandler.GetUsage(recording->FileName()) != ruNone) { #else if (cCutter::Active()) { #endif reply.httpReturn(504, "VDR Cutter currently busy."); } else { #if APIVERSNUM > 20101 RecordingsHandler.Add(ruCut, recording->FileName()); #else cCutter::Start(recording->FileName()); #endif } return; } reply.httpReturn(503, "Cutting recordings failed."); } void RecordingsResponder::showCutterStatus(ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply) { QueryHandler q("/recordings/cut", request); StreamExtension s(&out); #if APIVERSNUM > 20101 bool active = RecordingsHandler.Active(); #else bool active = cCutter::Active(); #endif 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 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."); } }
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 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; }
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; }
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::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; }
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 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!"); } }
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"); } }
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); } }
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."); } }
void RecordingsResponder::reply(ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply) { QueryHandler::addHeader(reply); bool found = false; if (request.method() == "OPTIONS") { return; } if ((int)request.url().find("/recordings/play") == 0 ) { if ( request.method() == "GET" ) { playRecording(out, request, reply); reply.addHeader("Content-Type", "text/plain; charset=utf-8"); } else if (request.method() == "POST") { rewindRecording(out, request, reply); reply.addHeader("Content-Type", "text/plain; charset=utf-8"); } else { reply.httpReturn(501, "Only GET and POST method is supported by the /recordings/play service."); } found = true; } else 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 ChannelsResponder::replyChannels(std::ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply) { QueryHandler q("/channels", request); ChannelList* channelList; if ( q.isFormat(".json") ) { reply.addHeader("Content-Type", "application/json; charset=utf-8"); channelList = (ChannelList*)new JsonChannelList(&out); } else if ( q.isFormat(".html") ) { reply.addHeader("Content-Type", "text/html; charset=utf-8"); channelList = (ChannelList*)new HtmlChannelList(&out); } else if ( q.isFormat(".xml") ) { reply.addHeader("Content-Type", "text/xml; charset=utf-8"); channelList = (ChannelList*)new XmlChannelList(&out); } else { reply.httpReturn(403, "Resources are not available for the selected format. (Use: .json, .html or .xml)"); return; } std::string channel_details = q.getParamAsString(0); int start_filter = q.getOptionAsInt("start"); int limit_filter = q.getOptionAsInt("limit"); std::string group_filter = q.getOptionAsString("group"); if (channel_details.length() > 0) { cChannel* channel = VdrExtension::getChannel(channel_details); if (channel == NULL || channel->GroupSep()) { reply.httpReturn(403, "The requested channel is not available."); delete channelList; return; } else { channelList->init(); std::string group = ""; int total = 0; for (cChannel *channelIt = Channels.First(); channelIt; channelIt = Channels.Next(channelIt)) { if (!channelIt->GroupSep()) total++; else if ( total < channel->Number()) group = channelIt->Name(); } channelList->setTotal(total); std::string image = FileCaches::get()->searchChannelLogo(channel); channelList->addChannel(channel, group, image.length() == 0); } } else { if ( start_filter >= 0 && limit_filter >= 1 ) { channelList->activateLimit(start_filter, limit_filter); } channelList->init(); int total = 0; std::string group = ""; for (cChannel *channel = Channels.First(); channel; channel = Channels.Next(channel)) { if (!channel->GroupSep()) { if ( group_filter.length() == 0 || group == group_filter ) { std::string image = FileCaches::get()->searchChannelLogo(channel); channelList->addChannel(channel, group, image.length() != 0); total++; } } else { group = channel->Name(); } } channelList->setTotal(total); } channelList->finish(); delete channelList; }
void EventsResponder::replySearchResult(ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply) { QueryHandler q("/events/search", request); if ( request.method() != "POST") { reply.httpReturn(403, "To search for information use the POST method!"); return; } StreamExtension se(&out); string query = q.getBodyAsString("query"); string search = q.getBodyAsString("search"); if ( query.length() == 0 && search.length() == 0 ) { reply.httpReturn(402, "Query required"); return; } 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 or .html)"); return; } eventList->init(); int start_filter = q.getOptionAsInt("start"); int limit_filter = q.getOptionAsInt("limit"); int date_filter = q.getOptionAsInt("date_limit"); if ( start_filter >= 0 && limit_filter >= 1 ) { eventList->activateLimit(start_filter, limit_filter); } if ( date_filter >= 0 ) { eventList->activateDateLimit(date_filter); } int total = 0; if ( search.length() > 0 ) { vdrlive::SearchTimer* searchtimer = new vdrlive::SearchTimer; searchtimer->SetId(0); string result = searchtimer->LoadCommonFromQuery(q); if (result.length() > 0) { reply.httpReturn(406, result.c_str()); return; } string query = searchtimer->ToText(); vdrlive::SearchResults* results = new vdrlive::SearchResults; results->GetByQuery(query); for (vdrlive::SearchResults::iterator result = results->begin(); result != results->end(); ++result) { eventList->addEvent(((cEvent*)result->GetEvent())); total++; } delete searchtimer; delete results; } else { int mode = q.getBodyAsInt("mode");// search mode (0=phrase, 1=and, 2=or, 3=exact, 4=regular expression, 5=fuzzy) string channelid = q.getBodyAsString("channelid"); //id !! bool use_title = q.getBodyAsString("use_title") == "true"; bool use_subtitle = q.getBodyAsString("use_subtitle") == "true"; bool use_description = q.getBodyAsString("use_description") == "true"; int channel = 0; const cChannel* channelInstance = VdrExtension::getChannel(channelid); if (channelInstance != NULL) { channel = channelInstance->Number(); } #if APIVERSNUM > 20300 LOCK_CHANNELS_READ; const cChannels& channels = *Channels; #else cChannels& channels = Channels; #endif if (!use_title && !use_subtitle && !use_description) use_title = true; if (mode < 0 || mode > 5) mode = 0; if (channel < 0 || channel > channels.Count()) channel = 0; if (query.length() > 100) query = query.substr(0,100); //don't allow more than 100 characters, NOTE: maybe I should add a limitation to the Responderclass? struct Epgsearch_searchresults_v1_0* epgquery = new struct Epgsearch_searchresults_v1_0; epgquery->query = (char*)query.c_str(); epgquery->mode = mode; epgquery->channelNr = channel; epgquery->useTitle = use_title; epgquery->useSubTitle = use_subtitle; epgquery->useDescription = use_description; cPlugin *Plugin = cPluginManager::GetPlugin("epgsearch"); if (Plugin) { if (Plugin->Service("Epgsearch-searchresults-v1.0", NULL)) { if (Plugin->Service("Epgsearch-searchresults-v1.0", epgquery)) { cList< Epgsearch_searchresults_v1_0::cServiceSearchResult>* result = epgquery->pResultList; Epgsearch_searchresults_v1_0::cServiceSearchResult* item = NULL; if (result != NULL) { for(int i=0;i<result->Count();i++) { item = result->Get(i); eventList->addEvent(((cEvent*)item->event)); total++; } } } else { reply.httpReturn(406, "Internal (epgsearch) error, check parameters."); } } else { reply.httpReturn(405, "Plugin-service not available."); } } else { reply.httpReturn(404, "Plugin not installed!"); } delete epgquery; } eventList->setTotal(total); eventList->finish(); delete eventList; }
void TimersResponder::replyBulkdelete(std::ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply) { QueryHandler q("/timers/bulkdelete", request); #if APIVERSNUM > 20300 LOCK_TIMERS_WRITE; cTimers& timers = *Timers; #else cTimers& timers = Timers; if ( timers.BeingEdited() ) { reply.httpReturn(502, "Timers are being edited - try again later"); return; } #endif TimerDeletedList* list; if ( q.isFormat(".json") ) { reply.addHeader("Content-Type", "application/json; charset=utf-8"); list = (TimerDeletedList*)new JsonTimerDeletedList(&out); } else if ( q.isFormat(".html") ) { reply.addHeader("Content-Type", "text/html; charset=utf-8"); list = (TimerDeletedList*)new HtmlTimerDeletedList(&out); } else if ( q.isFormat(".xml") ) { reply.addHeader("Content-Type", "text/xml; charset=utf-8"); list = (TimerDeletedList*)new XmlTimerDeletedList(&out); } else { reply.httpReturn(404, "Resources are not available for the selected format. (Use: .json, .html or .xml)"); return; } TimerValues v; cTimer* timer; vector< string > deleteTimers = q.getBodyAsStringArray("timers"); vector< SerBulkDeleted > results; SerBulkDeleted result; size_t i; list->init(); for ( i = 0; i < deleteTimers.size(); i++ ) { timer = v.ConvertTimer(deleteTimers[i]); result.id = deleteTimers[i]; if ( timer == NULL ) { result.deleted = false; } else { if ( timer->Recording() ) { timer->Skip(); #if APIVERSNUM > 20300 cRecordControls::Process(Timers, time(NULL)); #else cRecordControls::Process(time(NULL)); #endif } timers.Del(timer); timers.SetModified(); result.deleted = true; } list->addDeleted(result); } list->setTotal((int)deleteTimers.size()); list->finish(); delete list; };
void EventsResponder::replyEvents(ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply) { QueryHandler q("/events", request); if ( request.method() != "GET") { reply.httpReturn(403, "To retrieve information use the GET method!"); return; } 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 or .html)"); return; } string channel_id = q.getParamAsString(0); int timespan = q.getOptionAsInt("timespan");//q.getParamAsInt(1); int from = q.getOptionAsInt("from");//q.getParamAsInt(2); int start_filter = q.getOptionAsInt("start"); int limit_filter = q.getOptionAsInt("limit"); int event_id = q.getParamAsInt(1);//q.getOptionAsInt("eventid"); string onlyCount = q.getOptionAsString("only_count"); #if APIVERSNUM > 20300 LOCK_CHANNELS_READ; const cChannels& channels = *Channels; #else cChannels& channels = Channels; #endif const cChannel* channel = VdrExtension::getChannel(channel_id); if ( channel == NULL ) { /*reply.addHeader("Content-Type", "application/octet-stream"); string error_message = (string)"Could not find channel with id: " + channel_id + (string)"!"; reply.httpReturn(404, error_message); return;*/ } int channel_limit = q.getOptionAsInt("chevents"); if ( channel_limit <= -1 ) channel_limit = 0; // default channel events is 0 -> all int channel_from = q.getOptionAsInt("chfrom"); if ( channel_from <= -1 || channel != NULL ) channel_from = 0; // default channel number is 0 int channel_to = q.getOptionAsInt("chto"); if ( channel_to <= 0 || channel != NULL ) channel_to = channels.Count(); if ( from <= -1 ) from = time(NULL); // default time is now if ( timespan <= -1 ) timespan = 0; // default timespan is 0, which means all entries will be returned int to = from + timespan; #if APIVERSNUM > 20300 LOCK_SCHEDULES_READ; #else cSchedulesLock MutexLock; const cSchedules *Schedules = cSchedules::Schedules(MutexLock); #endif if( !Schedules ) { reply.httpReturn(404, "Could not find schedules!"); return; } if ( start_filter >= 0 && limit_filter >= 1 ) { eventList->activateLimit(start_filter, limit_filter); } bool initialized = false; int total = 0; for(int i=0; i<channels.Count(); i++) { const cSchedule *Schedule = Schedules->GetSchedule(channels.Get(i)->GetChannelID()); if ((channel == NULL || strcmp(channel->GetChannelID().ToString(), channels.Get(i)->GetChannelID().ToString()) == 0) && (i >= channel_from && i <= channel_to)) { if (!Schedule) { if (channel != NULL) { reply.httpReturn(404, "Could not find schedule!"); return; } } else { if (!initialized) { eventList->init(); initialized = true; } int old = 0; int channel_events = 0; for(const cEvent* event = Schedule->Events()->First(); event; event = Schedule->Events()->Next(event)) { int ts = event->StartTime(); int te = ts + event->Duration(); if ((ts <= to && te > from) || (te > from && timespan == 0)) { if (channel_limit == 0 || channel_limit > channel_events) { if ((event_id < 0 || event_id == (int)event->EventID()) && onlyCount != "true") { eventList->addEvent(event); channel_events++; } } } else { if (ts > to) break; if (te <= from) old++; } } total += (Schedule->Events()->Count() - old); } } } eventList->setTotal(total); eventList->finish(); delete eventList; }
void EventsResponder::replyContentDescriptors(std::ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply) { QueryHandler q("/events/contentdescriptors", request); if ( request.method() != "GET") { reply.httpReturn(403, "To retrieve content descriptors use the POST method!"); return; } StreamExtension se(&out); ContentDescriptorList* list; if ( q.isFormat(".json") ) { reply.addHeader("Content-Type", "application/json; charset=utf-8"); list = (ContentDescriptorList*)new JsonContentDescriptorList(&out); } else if ( q.isFormat(".html") ) { reply.addHeader("Content-Type", "text/html; charset=utf-8"); list = (ContentDescriptorList*)new HtmlContentDescriptorList(&out); } else if ( q.isFormat(".xml") ) { reply.addHeader("Content-Type", "text/xml; charset=utf-8"); list = (ContentDescriptorList*)new XmlContentDescriptorList(&out); } else { reply.httpReturn(403, "Resources are not available for the selected format. (Use: .json, .xml or .html)"); return; } list->init(); int total = 0; std::set<std::string> contentStrings; for(unsigned int i=0; i<CONTENT_DESCRIPTOR_MAX;i++) { const string contentDescr = cEvent::ContentToString(i); SerContentDescriptor cDescr; if (!contentDescr.empty() && contentStrings.find(contentDescr) == contentStrings.end()) { contentStrings.insert(contentDescr); cDescr.name = StringExtension::UTF8Decode(contentDescr); std::stringstream stream; stream << std::hex << i; std::string result( stream.str() ); switch (i) { case ecgArtsCulture: case ecgChildrenYouth: case ecgEducationalScience: case ecgLeisureHobbies: case ecgMovieDrama: case ecgMusicBalletDance: case ecgNewsCurrentAffairs: case ecgShow: case ecgSocialPoliticalEconomics: case ecgSpecial: case ecgSports: case ecgUserDefined: cDescr.isGroup = true; break; default: cDescr.isGroup = false; } cDescr.id = result; list->addDescr(cDescr); total++; } } list->setTotal(total); list->finish(); delete list; };