Request: Add ValidateInput()

This commit is contained in:
tt2468 2021-06-16 02:22:13 -07:00
parent 1116af128e
commit 3400bfdc9a
2 changed files with 25 additions and 0 deletions

View File

@ -139,3 +139,26 @@ const bool Request::ValidateArray(const std::string keyName, RequestStatus::Requ
return true;
}
obs_source_t *Request::ValidateInput(const std::string keyName, RequestStatus::RequestStatus &statusCode, std::string &comment) const
{
if (!ValidateString(keyName, statusCode, comment))
return nullptr;
std::string inputName = RequestData[keyName];
obs_source_t *ret = obs_get_source_by_name(inputName.c_str());
if (!ret) {
statusCode = RequestStatus::InputNotFound;
comment = std::string("No input was found by the name of `") + inputName + "`.";
return nullptr;
}
if (obs_source_get_type(ret) != OBS_SOURCE_TYPE_INPUT) {
statusCode = RequestStatus::InvalidSourceType;
comment = "The specified source is not an input.";
return nullptr;
}
return ret;
}

View File

@ -21,6 +21,8 @@ struct Request
const bool ValidateObject(const std::string keyName, RequestStatus::RequestStatus &statusCode, std::string &comment, const bool allowEmpty = false) const;
const bool ValidateArray(const std::string keyName, RequestStatus::RequestStatus &statusCode, std::string &comment, const bool allowEmpty = false) const;
obs_source_t *ValidateInput(const std::string keyName, RequestStatus::RequestStatus &statusCode, std::string &comment) const;
const uint8_t RpcVersion;
const bool IgnoreNonFatalRequestChecks;
const std::string RequestType;