|
|
@@ -27,14 +27,25 @@ WebAPI::~WebAPI()
|
|
|
{
|
|
|
}
|
|
|
|
|
|
-std::string WebAPI::ProcessQuery(ctpl::thread_pool* pThreadPool, Http::HttpClient* pHttpClient, const std::string& path, const std::string& ffmpeg, const std::string& uri, const std::vector<Http::HttpPostData>& postData)
|
|
|
+Http::HttpServer::HttpReply WebAPI::ProcessQuery(ctpl::thread_pool* pThreadPool, Http::HttpClient* pHttpClient, const std::string& path, const std::string& ffmpeg, const std::string& uri, const std::vector<Http::HttpPostData>& postData)
|
|
|
{
|
|
|
- std::string output;
|
|
|
+ if (!StringAlgorithm::iequals(uri, "/api") && !StringAlgorithm::istarts_with(uri, "/api/"))
|
|
|
+ {
|
|
|
+ Http::HttpServer::HttpReply reply;
|
|
|
+ reply.status = Http::HttpServer::HttpReply::Status::Unauthorized;
|
|
|
+ return reply;
|
|
|
+ }
|
|
|
+
|
|
|
+ Http::HttpServer::HttpReply reply;
|
|
|
+ reply.status = Http::HttpServer::HttpReply::Status::InternalServerError;
|
|
|
+ reply.content = "{\"result\": \"error\"}\r\n";
|
|
|
+
|
|
|
+ std::string apiURI = uri.substr(4);
|
|
|
|
|
|
- std::vector<std::string> uriTokens = StringAlgorithm::split(uri, '/');
|
|
|
+ std::vector<std::string> uriTokens = StringAlgorithm::split(apiURI, '/');
|
|
|
|
|
|
if (uriTokens.size() < 7)
|
|
|
- return std::string();
|
|
|
+ return reply;
|
|
|
|
|
|
std::string action = uriTokens[1];
|
|
|
std::string brand = uriTokens[2];
|
|
|
@@ -50,58 +61,59 @@ std::string WebAPI::ProcessQuery(ctpl::thread_pool* pThreadPool, Http::HttpClien
|
|
|
if (uriTokens.size() > 7)
|
|
|
numberOfImages = stoi(uriTokens[7]);
|
|
|
|
|
|
+ reply.status = Http::HttpServer::HttpReply::Status::Ok;
|
|
|
if (StringAlgorithm::iequals("Digoo", brand))
|
|
|
{
|
|
|
auto recorder = Recorder::DigooRecorder(pHttpClient, settings);
|
|
|
if (StringAlgorithm::iequals("Snapshot", action))
|
|
|
- output = recorder.Snapshot(pThreadPool);
|
|
|
+ reply.content = recorder.Snapshot(pThreadPool);
|
|
|
else if (StringAlgorithm::iequals("MultiSnapshot", action))
|
|
|
- output = recorder.MultiSnapshot(pThreadPool, numberOfImages);
|
|
|
+ reply.content = recorder.MultiSnapshot(pThreadPool, numberOfImages);
|
|
|
else if (StringAlgorithm::iequals("Video", action))
|
|
|
- output = recorder.Video(pThreadPool, ffmpeg);
|
|
|
+ reply.content = recorder.Video(pThreadPool, ffmpeg);
|
|
|
}
|
|
|
else if (StringAlgorithm::iequals("Foscam", brand))
|
|
|
{
|
|
|
auto recorder = Recorder::FoscamRecorder(pHttpClient, settings);
|
|
|
if (StringAlgorithm::iequals("Snapshot", action))
|
|
|
- output = recorder.Snapshot(pThreadPool);
|
|
|
+ reply.content = recorder.Snapshot(pThreadPool);
|
|
|
else if (StringAlgorithm::iequals("MultiSnapshot", action))
|
|
|
- output = recorder.MultiSnapshot(pThreadPool, numberOfImages);
|
|
|
+ reply.content = recorder.MultiSnapshot(pThreadPool, numberOfImages);
|
|
|
else if (StringAlgorithm::iequals("Video", action))
|
|
|
- output = recorder.Video(pThreadPool, ffmpeg);
|
|
|
+ reply.content = recorder.Video(pThreadPool, ffmpeg);
|
|
|
}
|
|
|
else if (StringAlgorithm::iequals("VStarCam", brand))
|
|
|
{
|
|
|
auto recorder = Recorder::VStarCamRecorder(pHttpClient, settings);
|
|
|
if (StringAlgorithm::iequals("Snapshot", action))
|
|
|
- output = recorder.Snapshot(pThreadPool);
|
|
|
+ reply.content = recorder.Snapshot(pThreadPool);
|
|
|
else if (StringAlgorithm::iequals("MultiSnapshot", action))
|
|
|
- output = recorder.MultiSnapshot(pThreadPool, numberOfImages);
|
|
|
+ reply.content = recorder.MultiSnapshot(pThreadPool, numberOfImages);
|
|
|
else if (StringAlgorithm::iequals("Video", action))
|
|
|
- output = recorder.Video(pThreadPool, ffmpeg);
|
|
|
+ reply.content = recorder.Video(pThreadPool, ffmpeg);
|
|
|
}
|
|
|
else if (StringAlgorithm::iequals("WatchBot", brand))
|
|
|
{
|
|
|
auto recorder = Recorder::WatchBotRecorder(pHttpClient, settings);
|
|
|
if (StringAlgorithm::iequals("Snapshot", action))
|
|
|
- output = recorder.Snapshot(pThreadPool);
|
|
|
+ reply.content = recorder.Snapshot(pThreadPool);
|
|
|
else if (StringAlgorithm::iequals("MultiSnapshot", action))
|
|
|
- output = recorder.MultiSnapshot(pThreadPool, numberOfImages);
|
|
|
+ reply.content = recorder.MultiSnapshot(pThreadPool, numberOfImages);
|
|
|
else if (StringAlgorithm::iequals("Video", action))
|
|
|
- output = recorder.Video(pThreadPool, ffmpeg);
|
|
|
+ reply.content = recorder.Video(pThreadPool, ffmpeg);
|
|
|
}
|
|
|
else if (StringAlgorithm::iequals("ZModo", brand))
|
|
|
{
|
|
|
auto recorder = Recorder::ZModoRecorder(pHttpClient, settings);
|
|
|
if (StringAlgorithm::iequals("Snapshot", action))
|
|
|
- output = recorder.Snapshot(pThreadPool);
|
|
|
+ reply.content = recorder.Snapshot(pThreadPool);
|
|
|
else if (StringAlgorithm::iequals("MultiSnapshot", action))
|
|
|
- output = recorder.MultiSnapshot(pThreadPool, numberOfImages);
|
|
|
+ reply.content = recorder.MultiSnapshot(pThreadPool, numberOfImages);
|
|
|
else if (StringAlgorithm::iequals("Video", action))
|
|
|
- output = recorder.Video(pThreadPool, ffmpeg);
|
|
|
+ reply.content = recorder.Video(pThreadPool, ffmpeg);
|
|
|
}
|
|
|
|
|
|
- return output;
|
|
|
+ return reply;
|
|
|
}
|
|
|
|
|
|
} // namespace API
|