
/*---------------------------------------------------------------------------*/
/* webserver_mkcol_handler.h                                                 */
/* copyright (c) innovaphone 2016                                            */
/*                                                                           */
/*---------------------------------------------------------------------------*/

class WebserverMkColHandler : public WebserverWebdavMessageHandler, public IWebserverMkCol {
protected:
    UWebserverMkCol * user;

    void SendResult() override { user->WebserverMkColSendResult(this); }

    void CloseComplete() override
    {
        ASSERT(user, "WebserverMkColHandler::CloseComplete() called, but user is NULL. Forgot do call \"delete webserverMkCol\" in WebserverMkColCloseComplete()?");
        UWebserverMkCol * tmp = user;
        user = NULL;
        tmp->WebserverMkColCloseComplete(this);
    }

public:
    WebserverMkColHandler(UWebserverMessageHandler * baseUser,
                          byte * extHeaderBuffer,
                          dword connectionID,
                          ulong64 dataSize,
                          char * resourceName,
                          char * resReqPath,
                          class ExtendedHeader & extHeader,
                          IWebserverMessage * const webserverMessageSend,
                          class IInstanceLog * const log,
                          word protocolVersion);
    virtual ~WebserverMkColHandler();

    void SetUser(UWebserverMkCol * user)
    {
        this->userSet = true;
        this->user = user;
    }

	dword GetConnectionID() override { return WebserverWebdavMessageHandler::GetConnectionID(); }
	const char * GetResourceName() override { return WebserverWebdavMessageHandler::GetResourceName(); }
	const char * GetRegisteredPathForRequest() override { return WebserverWebdavMessageHandler::GetRegisteredPathForRequest(); }
    virtual const char * GetRemoteAddress() { return WebserverMessageHandler::GetRemoteAddress(); }
    virtual word GetRemotePort() { return WebserverMessageHandler::GetRemotePort(); }
    virtual class IDigestAuthenticator * GetAuthenticator() override { return WebserverWebdavMessageHandler::GetAuthenticator(); }

    const char * GetHeaderFieldValue(const char * fieldName) override { return WebserverWebdavMessageHandler::GetHeaderFieldValue(fieldName); }
    void SetLocation(const char * location) override { WebserverWebdavMessageHandler::SetHeaderField("Location", location); }
    void SetResultCode(ws_webdav_result_t result, ulong64 dataSize = 0) override { WebserverWebdavMessageHandler::SetResultCode(result, dataSize); }
    void SetTransferInfo(wsr_type_t resourceType, ulong64 dataSize, wsr_flags_t flags = WSP_FLAG_NONE, const char* etag = nullptr) { WebserverWebdavMessageHandler::SetTransferInfo(resourceType, dataSize, flags, etag); };
    void SetStatusCode(dword code, const char * description = nullptr) override { WebserverWebdavMessageHandler::SetStatusCode(code, description); }
    void SetHeaderField(const char * fname, const char * fvalue) override { WebserverWebdavMessageHandler::SetHeaderField(fname, fvalue); }
    void Cancel(wsr_cancel_type_t reason) override { WebserverWebdavMessageHandler::Cancel(reason); }
    void Send(const void * buffer, size_t len) override { WebserverWebdavMessageHandler::Send(buffer, len); }
    void Close() override { WebserverWebdavMessageHandler::Close(); }
    void AcceptComplete() override { user->WebserverMkColRequestAcceptComplete(this); }
};
