add json response for yweb 3 calls

git-svn-id: file:///home/bas/coolstream_public_svn/THIRDPARTY/applications/neutrino-experimental@534 e54a6e83-5905-42d5-8d5c-058d10e6a962
This commit is contained in:
yjogol
2010-04-01 14:25:15 +00:00
parent e413dc3ef0
commit aa52b78495

View File

@@ -69,14 +69,14 @@ class Cyhook;
typedef enum typedef enum
{ {
HANDLED_NONE = 0, // Init HANDLED_NONE = 0, // Init
HANDLED_READY, // Handled HANDLED_READY, // Handled
HANDLED_ABORT, // Abort Connection Fatal HANDLED_ABORT, // Abort Connection Fatal
HANDLED_ERROR, // Have Error like missing Parameter HANDLED_ERROR, // Have Error like missing Parameter
HANDLED_NOT_IMPLEMENTED,// URL should be handled but not implemented HANDLED_NOT_IMPLEMENTED,// URL should be handled but not implemented
HANDLED_REDIRECTION, // Set new URL and send HTTPD Object Moved HANDLED_REDIRECTION, // Set new URL and send HTTPD Object Moved
HANDLED_SENDFILE, // Set new URL and Send File HANDLED_SENDFILE, // Set new URL and Send File
HANDLED_REWRITE, // Set new URL and call Hooks again HANDLED_REWRITE, // Set new URL and call Hooks again
HANDLED_CONTINUE, // handled but go on HANDLED_CONTINUE, // handled but go on
} THandleStatus; } THandleStatus;
typedef std::list<Cyhook *> THookList; typedef std::list<Cyhook *> THookList;
@@ -112,23 +112,23 @@ protected:
static THookList HookList; static THookList HookList;
public: public:
// Output // Output
std::string yresult; // content for response output std::string yresult; // content for response output
THandleStatus status; // status of Hook handling THandleStatus status; // status of Hook handling
HttpResponseType httpStatus; // http-status code for response HttpResponseType httpStatus; // http-status code for response
std::string ResponseMimeType; // mime-type for response std::string ResponseMimeType; // mime-type for response
std::string NewURL; // new URL for Redirection std::string NewURL; // new URL for Redirection
long ContentLength; // Length of Response Body long ContentLength; // Length of Response Body
time_t LastModified; // Last Modified Time of Item to send / -1 dynamic content time_t LastModified; // Last Modified Time of Item to send / -1 dynamic content
std::string Sendfile; // Path & Name (local os style) of file to send std::string Sendfile; // Path & Name (local os style) of file to send
bool keep_alive; bool keep_alive;
// Input // Input
CStringList ParamList; // local copy of ParamList (Request) CStringList ParamList; // local copy of ParamList (Request)
CStringList UrlData; // local copy of UrlData (Request) CStringList UrlData; // local copy of UrlData (Request)
CStringList HeaderList; // local copy of HeaderList (Request) CStringList HeaderList; // local copy of HeaderList (Request)
CStringList WebserverConfigList; // Reference (writable) to ConfigList CStringList WebserverConfigList;// Reference (writable) to ConfigList
CStringList HookVarList; // Variables in Hook-Handling passing to other Hooks CStringList HookVarList; // Variables in Hook-Handling passing to other Hooks
THttp_Method Method; // HTTP Method (requested) THttp_Method Method; // HTTP Method (requested)
// constructor & deconstructor // constructor & deconstructor
CyhookHandler(){}; CyhookHandler(){};
virtual ~CyhookHandler(){}; virtual ~CyhookHandler(){};
@@ -146,7 +146,7 @@ public:
// Cyhttpd based hooks // Cyhttpd based hooks
static THandleStatus Hooks_ReadConfig(CConfigFile *Config, CStringList &ConfigList); static THandleStatus Hooks_ReadConfig(CConfigFile *Config, CStringList &ConfigList);
// CWebserverConnection based hooks // CWebserverConnection based hooks
THandleStatus Hooks_PrepareResponse(); // Hook for Response.SendResonse Dispatching THandleStatus Hooks_PrepareResponse();// Hook for Response.SendResonse Dispatching
THandleStatus Hooks_SendResponse(); // Hook for Response.SendResonse Dispatching THandleStatus Hooks_SendResponse(); // Hook for Response.SendResonse Dispatching
THandleStatus Hooks_EndConnection(); THandleStatus Hooks_EndConnection();
THandleStatus Hooks_UploadSetFilename(std::string &Filename); THandleStatus Hooks_UploadSetFilename(std::string &Filename);
@@ -170,17 +170,17 @@ public:
void addResult(const std::string& result, THandleStatus _status) void addResult(const std::string& result, THandleStatus _status)
{yresult += result; status = _status;} {yresult += result; status = _status;}
void printf(const char *fmt, ...); void printf(const char *fmt, ...);
void Write(const std::string& text) { addResult(text); } void Write(const std::string& text) {addResult(text);}
void WriteLn(const std::string& text) { addResult(text+"\r\n"); } void WriteLn(const std::string& text) {addResult(text+"\r\n");}
void Write(char const *text) {Write(std::string(text));} void Write(char const *text) {Write(std::string(text));}
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) {Write("ok");} void SendOk(void) {(ParamList["response"]=="json") ? Write("{\"success\": true}") : Write("ok");}
void SendError(void) {Write("error");} void SendError(void) {(ParamList["response"]=="json") ? Write("{\"success\": false}") : Write("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;}
friend class CyParser; friend class CyParser;
}; };