VirtualBox

Changeset 73930 in vbox for trunk/include/iprt/cpp


Ignore:
Timestamp:
Aug 28, 2018 6:09:54 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
124656
Message:

IPRT/rest: Implemented parsing json response bodies. bugref:9167

File:
1 edited

Legend:

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

    r73922 r73930  
    707707    int getHttpStatus() { return m_rcHttp; }
    708708
     709    /**
     710     * Getter for m_pErrInfo.
     711     */
     712    PCRTERRINFO  getErrIfno(void) const { return m_pErrInfo; }
     713
     714    /**
     715     * Getter for m_strContentType.
     716     */
     717    RTCString const &getContentType(void) const { return m_strContentType; }
     718
     719
    709720protected:
    710721    /** Negative numbers are IPRT errors, positive are HTTP status codes. */
    711     int m_rcStatus;
     722    int         m_rcStatus;
    712723    /** The HTTP status code, VERR_NOT_AVAILABLE if not set. */
    713     int m_rcHttp;
     724    int         m_rcHttp;
    714725    /** Error information. */
    715     PRTERRINFO m_pErrInfo;
     726    PRTERRINFO  m_pErrInfo;
    716727    /** The value of the Content-Type header field. */
    717     RTCString m_strContentType;
    718 
    719     PRTERRINFO  allocErrInfo(void);
     728    RTCString   m_strContentType;
     729
     730    PRTERRINFO  getErrInfo(void);
    720731    void        deleteErrInfo(void);
    721732    void        copyErrInfo(PCRTERRINFO pErrInfo);
     733
     734    /**
     735     * Reports an error (or warning if a_rc non-negative).
     736     *
     737     * @returns a_rc
     738     * @param   a_rc        The status code to report and return.  The first
     739     *                      error status is assigned to m_rcStatus, subsequent
     740     *                      ones as well as informational statuses are not
     741     *                      recorded by m_rcStatus.
     742     * @param   a_pszFormat The message format string.
     743     * @param   ...         Message arguments.
     744     */
     745    int         addError(int a_rc, const char *a_pszFormat, ...);
    722746
    723747    /**
     
    735759    int extractHeaderFromBlob(const char *a_pszField, size_t a_cchField, const char *a_pchData, size_t a_cbData,
    736760                              RTCString *a_pStrDst);
     761
     762    /**
     763     * Helper that does the deserializing of the response body.
     764     *
     765     * @param   a_pDst      The destination object for the body content.
     766     * @param   a_pchData   The body blob.
     767     * @param   a_cbData    The size of the body blob.
     768     */
     769    void deserializeBody(RTCRestObjectBase *a_pDst, const char *a_pchData, size_t a_cbData);
     770
     771    /**
     772     * Primary json cursor for parsing bodies.
     773     */
     774    class PrimaryJsonCursorForBody : public RTCRestJsonPrimaryCursor
     775    {
     776    public:
     777        RTCRestClientResponseBase *m_pThat; /**< Pointer to response object. */
     778        PrimaryJsonCursorForBody(RTJSONVAL hValue, const char *pszName, RTCRestClientResponseBase *a_pThat);
     779        virtual int addError(RTCRestJsonCursor const &a_rCursor, int a_rc, const char *a_pszFormat, ...) RT_OVERRIDE;
     780        virtual int unknownField(RTCRestJsonCursor const &a_rCursor) RT_OVERRIDE;
     781    };
    737782};
    738783
     
    821866    virtual void doCall(RTCRestClientRequestBase const &a_rRequest, RTHTTPMETHOD a_enmHttpMethod,
    822867                        RTCRestClientResponseBase *a_pResponse);
     868
    823869};
    824870
Note: See TracChangeset for help on using the changeset viewer.

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