
/*---------------------------------------------------------------------------*/
/* webserver_set_certificate_handler.h                                       */
/* copyright (c) innovaphone 2017                                            */
/*                                                                           */
/*---------------------------------------------------------------------------*/

class CertData : public istd::listElement<CertData> {
public:
    UWebserverPlugin * user;
    char * password;
    char * hostName;
    byte * certBuffer;
    size_t certSize;
        
    CertData()
    {
    }

    virtual ~CertData()
    {
        free(this->hostName);
        free(this->password);
    }
};


class WebserverSetCertificateHandler : public WebserverMessageHandler {
protected:
    IWebserverPlugin * plugIn;
    istd::list<CertData> certStack;
    CertData * curCert;
    byte * curBufPos;
    
    virtual void SendNextCert();

    virtual void SendResult();
    virtual void * RecvBuffer(size_t size) { return nullptr; } // Unused
    virtual void RecvResult(byte * buffer, size_t len) { } // Unused
    virtual void CloseComplete() { delete this; }
public:
    WebserverSetCertificateHandler(UWebserverMessageHandler * baseUser,
                                   IWebserverMessage * const webserverMessageSend,
                                   IInstanceLog * const log,
                                   class ExtendedHeader & extHeader,
                                   word protocolVersion);

    virtual ~WebserverSetCertificateHandler();

    void SendCert(const char * password, const char * hostName, const byte * certBuffer, size_t certSize, UWebserverPlugin * user);

    virtual void AcceptComplete() {} // Unused

};