VirtualBox

Changeset 73930 in vbox for trunk/include/iprt


Ignore:
Timestamp:
Aug 28, 2018 6:09:54 PM (6 years ago)
Author:
vboxsync
Message:

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

Location:
trunk/include/iprt
Files:
3 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
  • trunk/include/iprt/err.h

    r73929 r73930  
    31943194/** Internal processing error \#5.  */
    31953195#define VERR_ISOFS_IPE_5                                (-25395)
    3196 
    31973196/** @} */
    31983197
     
    32043203/** The chosen baudrate is invalid or not supported by the given serial port. */
    32053204#define VERR_SERIALPORT_INVALID_BAUDRATE                (-25501)
    3206 
     3205/** @} */
     3206
     3207
     3208/** @name RTCRest status codes
     3209 * @{ */
     3210/** Do not know how to handle the content type in the server response. */
     3211#define VERR_REST_RESPONSE_CONTENT_TYPE_NOT_SUPPORTED   (-25700)
     3212/** Invalid UTF-8 encoding in the response. */
     3213#define VERR_REST_RESPONSE_INVALID_UTF8_ENCODING        (-25701)
     3214/** Server response contains embedded zero character(s). */
     3215#define VERR_REST_RESPONSE_EMBEDDED_ZERO_CHAR           (-25702)
    32073216/** @} */
    32083217
  • trunk/include/iprt/json.h

    r73874 r73930  
    8888 * @param   cbBuf           Size of the buffer.
    8989 * @param   pErrInfo        Where to store extended error info. Optional.
     90 *
     91 * @todo    r=bird: The use of uint8_t makes no sense here since the parser
     92 *          expects ASCII / UTF-8.  What's more, if this is a real buffer the
     93 *          type should be 'const void *' rather than 'const uint8_t *'.
     94 *          This function should be modified to reflect that it's really for
     95 *          handling unterminated strings.
    9096 */
    9197RTDECL(int) RTJsonParseFromBuf(PRTJSONVAL phJsonVal, const uint8_t *pbBuf, size_t cbBuf, PRTERRINFO pErrInfo);
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