diff --git a/src/nhttpd/yhttpd_core/yhook.cpp b/src/nhttpd/yhttpd_core/yhook.cpp index c159416d5..c9fd94a08 100644 --- a/src/nhttpd/yhttpd_core/yhook.cpp +++ b/src/nhttpd/yhttpd_core/yhook.cpp @@ -538,3 +538,44 @@ std::string CyhookHandler::outNext() { return ""; } +//----------------------------------------------------------------------------- +void CyhookHandler::SendOk() { + std::string result = ""; + switch (outType) { + case xml: + result = "true"; + break; + case json: + result = "{\"success\": \"true\"}"; + break; + default: + result = "ok"; + break; + } + Write(result); +} +//----------------------------------------------------------------------------- +void CyhookHandler::SendError(std::string error) { + std::string result = ""; + switch (outType) { + case xml: + if (error.empty()) + result = "false"; + else + result = "false" + error + ""; + break; + case json: + if (error.empty()) + result = "{\"success\": \"false\"}"; + else + result = "{\"success\": \"false\", \"error\":{\"text\": \"" + error + "\"}}"; + break; + default: + if (error.empty()) + result = "error"; + else + result = "error=" + error; + break; + } + Write(result); +} diff --git a/src/nhttpd/yhttpd_core/yhook.h b/src/nhttpd/yhttpd_core/yhook.h index 781d8dc9f..03147a8da 100644 --- a/src/nhttpd/yhttpd_core/yhook.h +++ b/src/nhttpd/yhttpd_core/yhook.h @@ -192,8 +192,8 @@ public: void WriteLn(char const *text) {WriteLn(std::string(text));} void SendHTMLHeader(const std::string& Titel); void SendHTMLFooter(void); - void SendOk(void) {(ParamList["response"]=="json") ? Write("{\"success\": \"true\"}") : Write("ok");} - void SendError(void) {(ParamList["response"]=="json") ? Write("{\"success\": \"false\"}") : Write("error");} + void SendOk(void); + void SendError(std::string error = ""); void SendFile(const std::string& url) {NewURL = url; status = HANDLED_SENDFILE;} void SendRedirect(const std::string& url) {httpStatus=HTTP_MOVED_TEMPORARILY; NewURL = url; status = HANDLED_REDIRECTION;} void SendRewrite(const std::string& url) {NewURL = url; status = HANDLED_REWRITE;}