Robustified stream/protocol related API calls
This commit is contained in:
parent
04e0dfeab0
commit
0e0da824f7
4 changed files with 30 additions and 0 deletions
14
lib/json.cpp
14
lib/json.cpp
|
@ -1294,6 +1294,20 @@ void JSON::Value::removeMember(const std::map<std::string, Value*>::iterator & i
|
||||||
objVal.erase(it);
|
objVal.erase(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void JSON::Value::removeNullMembers(){
|
||||||
|
bool again = true;
|
||||||
|
while (again){
|
||||||
|
again = false;
|
||||||
|
jsonForEach(*this, m){
|
||||||
|
if (m.key().size() && m->isNull()){
|
||||||
|
removeMember(m.key());
|
||||||
|
again = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// For object JSON::Value objects, returns true if the
|
/// For object JSON::Value objects, returns true if the
|
||||||
/// given name is a member. Returns false otherwise.
|
/// given name is a member. Returns false otherwise.
|
||||||
bool JSON::Value::isMember(const std::string & name) const {
|
bool JSON::Value::isMember(const std::string & name) const {
|
||||||
|
|
|
@ -84,6 +84,7 @@ namespace JSON {
|
||||||
void removeMember(const std::string & name);
|
void removeMember(const std::string & name);
|
||||||
void removeMember(const std::deque<Value*>::iterator & it);
|
void removeMember(const std::deque<Value*>::iterator & it);
|
||||||
void removeMember(const std::map<std::string, Value*>::iterator & it);
|
void removeMember(const std::map<std::string, Value*>::iterator & it);
|
||||||
|
void removeNullMembers();
|
||||||
bool isMember(const std::string & name) const;
|
bool isMember(const std::string & name) const;
|
||||||
bool isInt() const;
|
bool isInt() const;
|
||||||
bool isString() const;
|
bool isString() const;
|
||||||
|
|
|
@ -167,6 +167,9 @@ int Controller::handleAPIConnection(Socket::Connection & conn){
|
||||||
/// Local-only helper function that checks for duplicate protocols and removes them
|
/// Local-only helper function that checks for duplicate protocols and removes them
|
||||||
static void removeDuplicateProtocols(){
|
static void removeDuplicateProtocols(){
|
||||||
JSON::Value & P = Controller::Storage["config"]["protocols"];
|
JSON::Value & P = Controller::Storage["config"]["protocols"];
|
||||||
|
jsonForEach(P, it){
|
||||||
|
it->removeNullMembers();
|
||||||
|
}
|
||||||
std::set<std::string> ignores;
|
std::set<std::string> ignores;
|
||||||
ignores.insert("online");
|
ignores.insert("online");
|
||||||
bool reloop = true;
|
bool reloop = true;
|
||||||
|
|
|
@ -132,11 +132,23 @@ namespace Controller {
|
||||||
if (out.isMember(jit.key())){
|
if (out.isMember(jit.key())){
|
||||||
if ( !streamsEqual((*jit), out[jit.key()])){
|
if ( !streamsEqual((*jit), out[jit.key()])){
|
||||||
out[jit.key()] = (*jit);
|
out[jit.key()] = (*jit);
|
||||||
|
out[jit.key()].removeNullMembers();
|
||||||
out[jit.key()]["name"] = jit.key();
|
out[jit.key()]["name"] = jit.key();
|
||||||
Log("STRM", std::string("Updated stream ") + jit.key());
|
Log("STRM", std::string("Updated stream ") + jit.key());
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
|
std::string checked = jit.key();
|
||||||
|
Util::sanitizeName(checked);
|
||||||
|
if (checked != jit.key() || !checked.size()){
|
||||||
|
if (!checked.size()){
|
||||||
|
FAIL_MSG("Invalid stream name '%s'", jit.key().c_str());
|
||||||
|
}else{
|
||||||
|
FAIL_MSG("Invalid stream name '%s'. Suggested alternative: '%s'", jit.key().c_str(), checked.c_str());
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
out[jit.key()] = (*jit);
|
out[jit.key()] = (*jit);
|
||||||
|
out[jit.key()].removeNullMembers();
|
||||||
out[jit.key()]["name"] = jit.key();
|
out[jit.key()]["name"] = jit.key();
|
||||||
Log("STRM", std::string("New stream ") + jit.key());
|
Log("STRM", std::string("New stream ") + jit.key());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue