nhttpd add helper for json,xml outputs

git-svn-id: file:///home/bas/coolstream_public_svn/THIRDPARTY/applications/neutrino-beta@1674 e54a6e83-5905-42d5-8d5c-058d10e6a962
This commit is contained in:
yjogol
2011-09-08 11:58:35 +00:00
parent 65aa929ce7
commit e19eaf7289
4 changed files with 220 additions and 2 deletions

View File

@@ -81,6 +81,17 @@ typedef enum
} THandleStatus;
typedef std::list<Cyhook *> THookList;
//-----------------------------------------------------------------------------
// Output Tyoe.
//-----------------------------------------------------------------------------
typedef enum
{
plain = 0,
html,
xml,
json
} TOutType;
//-----------------------------------------------------------------------------
// An abstract Hook-Class. Custom Hook must be inherited.
//-----------------------------------------------------------------------------
@@ -176,11 +187,23 @@ 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) {(ParamList["response"]=="json") ? Write("{\"success\": \"true\"}") : Write("ok");}
void SendError(void) {(ParamList["response"]=="json") ? Write("{\"success\": \"false\"}") : Write("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;}
int _outIndent;
TOutType outType; // Outputtpe = plain (default)|xml|json
TOutType outStart();
TOutType checkOutput();
std::string outIndent();
std::string outPair(std::string _key, std::string _content, bool _next);
std::string outArray(std::string _key, std::string _content);
std::string outArrayItem(std::string _key, std::string _content, bool _next);
std::string outCollection(std::string _key,std::string _content);
std::string outValue(std::string _content);
std::string outNext();
friend class CyParser;
};