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 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.");
  }
}
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.");
     }
  }
}
示例#4
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");
  }
}
示例#5
0
void ChannelsResponder::reply(std::ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply)
{
  QueryHandler::addHeader(reply);

  if ( request.method() != "GET") {
     reply.httpReturn(403, "To retrieve information use the GET method!");
     return;
  }
  static cxxtools::Regex imageRegex("/channels/image/*");
  static cxxtools::Regex groupsRegex("/channels/groups/*");

  if ( imageRegex.match(request.url()) ) {
     replyImage(out, request, reply);
  } else if (groupsRegex.match(request.url()) ){
     replyGroups(out, request, reply);
  } else {
     replyChannels(out, request, reply);
  }
}
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);
  }
}
示例#7
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.");
  }
}
bool KeyPairList::hitKey(cxxtools::http::Request& request, cxxtools::http::Reply& reply)
{ 
  
  if ( (int)request.url().find("/remote/kbd") != -1) {
    QueryHandler q("/remote/kbd", request);
    cxxtools::String kbd = StringExtension::UTF8Decode(q.getBodyAsString("kbd"));
    if ( kbd == StringExtension::UTF8Decode("") ) {
	reply.httpReturn(400, "Key is empty.");
    }
    std::size_t n = 0;
    while (kbd[n]) {
      cRemote::Put(KBDKEY(kbd[n]));
      ++n;
    }
    return true;

  } else if ( (int)request.url().find("/remote/seq") != -1) {
    QueryHandler q("/remote/seq", request);
    JsonArray* seq = q.getBodyAsArray("seq");

    if ( seq == NULL ) {
	reply.httpReturn(400, "Sequence is empty.");
        return false;
    }

    for (int i = 0; i < seq->CountItem(); i++) {
      JsonBase* jsonBase = seq->GetItem(i);
      if (jsonBase->IsBasicValue()) {
	JsonBasicValue* jsonBasicValue = (JsonBasicValue*)jsonBase;
	if (jsonBasicValue->IsString()) {
          string key = jsonBasicValue->ValueAsString();
          for (int n=0;n<(int)key.length();n++ ) {
            key[n] = tolower(key[n]);
          }
	  for (int x=0;x<(int)keys.size();x++) {
	    if (string(keys[x].str) == key) {
		cRemote::Put(keys[x].key);
	    }
	  }
	}
      }
    }

    return true;

  } else {
    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 false;
    }

    for (int i=0;i<(int)key.length();i++) {
      key[i] = tolower(key[i]);
    }

    for (int i=0;i<(int)keys.size();i++)
    {
      if (string(keys[i].str) == key) {
        cRemote::Put(keys[i].key);
        return true;
      }
    }
  }



  return false;
}
void RecordingsResponder::reply(ostream& out, cxxtools::http::Request& request, cxxtools::http::Reply& reply)
{
  QueryHandler::addHeader(reply);

  bool found = false;

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


  if ((int)request.url().find("/recordings/play") == 0 ) {
     if (request.method() == "POST") {
        playRecording(out, request, reply);
        reply.addHeader("Content-Type", "text/plain; charset=utf-8");
     } else {
        reply.httpReturn(501, "Only POST method is supported by the /recordings/play service.");
     }
     found = true;
  }
    
  else if ((int)request.url().find("/recordings/rewind") == 0 ) {
     if (request.method() == "POST") {
        rewindRecording(out, request, reply);
        reply.addHeader("Content-Type", "text/plain; charset=utf-8");
     } else {
        reply.httpReturn(501, "Only POST method is supported by the /recordings/rewind 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/editedfile") == 0 ) {
     if (request.method() == "GET") {
	 replyEditedFileName(out, request, reply);
     } else {
        reply.httpReturn(501, "Only GET method are supported by the /recordings/lastedited 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;
  }

  else if ((int)request.url().find("/recordings/move") == 0 ) {
     if (request.method() == "POST") {
        moveRecording(out, request, reply);
     } else {
        reply.httpReturn(501, "Only POST method is supported by the /recordings/move service.");
     }
     found = true;
  }

  else if ((int) request.url().find("/recordings/updates") == 0 ) {
     if (request.method() == "GET") {
        replyUpdates(out, request, reply);
     } else {
        reply.httpReturn(501, "Only GET method is supported by the /recordings/updates service.");
     }
     found = true;
  }

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

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

  if (!found) {
     reply.httpReturn(403, "Service not found");
  }
}