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);
}
Ejemplo n.º 2
0
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;
}