VirtualBox

Changeset 73922 in vbox for trunk


Ignore:
Timestamp:
Aug 28, 2018 7:30:28 AM (6 years ago)
Author:
vboxsync
Message:

iprt/rest: Added error info, copy of http status, and content type to RTCRestClientResponseBase. bugref:9167

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/cpp/restbase.h

    r73920 r73922  
    701701    int getStatus() { return m_rcStatus; }
    702702
     703    /**
     704     * Getter for m_rcHttp.
     705     * @returns HTTP status code or VERR_NOT_AVAILABLE.
     706     */
     707    int getHttpStatus() { return m_rcHttp; }
     708
    703709protected:
    704710    /** Negative numbers are IPRT errors, positive are HTTP status codes. */
    705711    int m_rcStatus;
     712    /** The HTTP status code, VERR_NOT_AVAILABLE if not set. */
     713    int m_rcHttp;
     714    /** Error information. */
     715    PRTERRINFO m_pErrInfo;
     716    /** The value of the Content-Type header field. */
     717    RTCString m_strContentType;
     718
     719    PRTERRINFO  allocErrInfo(void);
     720    void        deleteErrInfo(void);
     721    void        copyErrInfo(PCRTERRINFO pErrInfo);
    706722
    707723    /**
  • trunk/src/VBox/Runtime/common/rest/RTCRestClientResponseBase.cpp

    r73921 r73922  
    4040RTCRestClientResponseBase::RTCRestClientResponseBase()
    4141    : m_rcStatus(VERR_WRONG_ORDER)
     42    , m_rcHttp(VERR_NOT_AVAILABLE)
     43    , m_pErrInfo(NULL)
    4244{
    4345}
     
    4951RTCRestClientResponseBase::~RTCRestClientResponseBase()
    5052{
    51     /* nothing to do here */
     53    deleteErrInfo();
    5254}
    5355
     
    5860RTCRestClientResponseBase::RTCRestClientResponseBase(RTCRestClientResponseBase const &a_rThat)
    5961    : m_rcStatus(a_rThat.m_rcStatus)
    60 {
     62    , m_rcHttp(a_rThat.m_rcHttp)
     63    , m_strContentType(a_rThat.m_strContentType)
     64    , m_pErrInfo(NULL)
     65{
     66    if (m_pErrInfo)
     67        copyErrInfo(m_pErrInfo);
    6168}
    6269
     
    6774RTCRestClientResponseBase &RTCRestClientResponseBase::operator=(RTCRestClientResponseBase const &a_rThat)
    6875{
    69     m_rcStatus = a_rThat.m_rcStatus;
     76    m_rcStatus       = a_rThat.m_rcStatus;
     77    m_rcHttp         = a_rThat.m_rcHttp;
     78    m_strContentType = a_rThat.m_strContentType;
     79    if (a_rThat.m_pErrInfo)
     80        copyErrInfo(a_rThat.m_pErrInfo);
     81    else if (m_pErrInfo)
     82        deleteErrInfo();
     83
    7084    return *this;
    7185}
     
    8397    RT_NOREF_PV(a_hHttp);
    8498    m_rcStatus = a_rcStatus;
     99    if (a_rcStatus >= 0)
     100        m_rcHttp = a_rcStatus;
    85101}
    86102
     
    88104void RTCRestClientResponseBase::consumeHeaders(const char *a_pchData, size_t a_cbData)
    89105{
     106    /*
     107     * Get the the content type.
     108     */
     109    int rc = extractHeaderFromBlob(RT_STR_TUPLE("Content-Type"), a_pchData, a_cbData, &m_strContentType);
     110    if (rc == VERR_NOT_FOUND)
     111        rc = VINF_SUCCESS;
     112    AssertRCReturnVoidStmt(rc, m_rcStatus = rc);
     113}
     114
     115
     116void RTCRestClientResponseBase::consumeBody(const char *a_pchData, size_t a_cbData)
     117{
    90118    RT_NOREF(a_pchData, a_cbData);
    91119}
    92120
    93121
    94 void RTCRestClientResponseBase::consumeBody(const char *a_pchData, size_t a_cbData)
    95 {
    96     RT_NOREF(a_pchData, a_cbData);
    97 }
    98 
    99 
    100122void RTCRestClientResponseBase::receiveFinal()
    101123{
     124}
     125
     126
     127PRTERRINFO RTCRestClientResponseBase::allocErrInfo(void)
     128{
     129    size_t cbMsg = _4K;
     130    m_pErrInfo = (PRTERRINFO)RTMemAllocZ(sizeof(*m_pErrInfo) + cbMsg);
     131    if (m_pErrInfo)
     132        return RTErrInfoInit(m_pErrInfo, (char *)(m_pErrInfo + 1), cbMsg);
     133    return NULL;
     134}
     135
     136
     137void RTCRestClientResponseBase::deleteErrInfo(void)
     138{
     139    if (m_pErrInfo)
     140    {
     141        RTMemFree(m_pErrInfo);
     142        m_pErrInfo = NULL;
     143    }
     144}
     145
     146
     147void RTCRestClientResponseBase::copyErrInfo(PCRTERRINFO pErrInfo)
     148{
     149    deleteErrInfo();
     150    m_pErrInfo = (PRTERRINFO)RTMemDup(pErrInfo, pErrInfo->cbMsg + sizeof(*pErrInfo));
     151    if (m_pErrInfo)
     152    {
     153        m_pErrInfo->pszMsg = (char *)(m_pErrInfo + 1);
     154        m_pErrInfo->apvReserved[0] = NULL;
     155        m_pErrInfo->apvReserved[1] = NULL;
     156    }
    102157}
    103158
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette