yhook: send valide error/ok responses; allow error message

Origin commit data
------------------
Commit: 57cc01978b
Author: vanhofen <vanhofen@gmx.de>
Date: 2016-02-20 (Sat, 20 Feb 2016)

Origin message was:
------------------
- yhook: send valide error/ok responses; allow error message
This commit is contained in:
vanhofen
2016-02-20 23:06:46 +01:00
parent bd6cd82ef8
commit dede2bc1eb
2 changed files with 43 additions and 2 deletions

View File

@@ -538,3 +538,44 @@ std::string CyhookHandler::outNext() {
return ""; return "";
} }
//-----------------------------------------------------------------------------
void CyhookHandler::SendOk() {
std::string result = "";
switch (outType) {
case xml:
result = "<success>true</success>";
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 = "<success>false</success>";
else
result = "<success>false<error>" + error + "</error></success>";
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);
}

View File

@@ -192,8 +192,8 @@ public:
void WriteLn(char const *text) {WriteLn(std::string(text));} void WriteLn(char const *text) {WriteLn(std::string(text));}
void SendHTMLHeader(const std::string& Titel); void SendHTMLHeader(const std::string& Titel);
void SendHTMLFooter(void); void SendHTMLFooter(void);
void SendOk(void) {(ParamList["response"]=="json") ? Write("{\"success\": \"true\"}") : Write("ok");} void SendOk(void);
void SendError(void) {(ParamList["response"]=="json") ? Write("{\"success\": \"false\"}") : Write("error");} void SendError(std::string error = "");
void SendFile(const std::string& url) {NewURL = url; status = HANDLED_SENDFILE;} 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 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;} void SendRewrite(const std::string& url) {NewURL = url; status = HANDLED_REWRITE;}