VirtualBox

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


Ignore:
Timestamp:
Sep 13, 2018 4:33:17 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
125044
Message:

IRPT/rest,http: Use header callbacks for capturing header values in responses. Removed [P]FNCREATEINSTANCE as it isn't needed any more (and it didn't work like expected for RTCRestString). Some HTTP header callback updates. bugref:9167

Location:
trunk/include/iprt/cpp
Files:
2 edited

Legend:

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

    r74181 r74250  
    386386     */
    387387    virtual const char *typeName(void) const = 0;
    388 
    389     /**
    390      * Factory method.
    391      * @returns Pointer to new object on success, NULL if out of memory.
    392      */
    393     typedef DECLCALLBACK(RTCRestObjectBase *) FNCREATEINSTANCE(void);
    394     /** Pointer to factory method. */
    395     typedef FNCREATEINSTANCE *PFNCREATEINSTANCE;
    396388
    397389protected:
  • trunk/include/iprt/cpp/restclient.h

    r74232 r74250  
    2929#include <iprt/http.h>
    3030#include <iprt/cpp/restbase.h>
     31#include <iprt/cpp/reststringmap.h>
    3132
    3233
     
    463464     * This may install callbacks and such like.
    464465     *
     466     * When overridden, the parent class must always be called.
     467     *
    465468     * @returns IPRT status code.
    466469     * @param   a_hHttp     The HTTP handle to prepare for receiving.
    467      * @param   a_pppvHdr   If a header callback handler is installed, set the value pointed to to NULL.
    468      * @param   a_pppvBody  If a body callback handler is installed, set the value pointed to to NULL.
    469      */
    470     virtual int receivePrepare(RTHTTP a_hHttp, void ***a_pppvHdr, void ***a_pppvBody);
     470     */
     471    virtual int receivePrepare(RTHTTP a_hHttp);
    471472
    472473    /**
     
    478479     *                      which case it is possible receivePrepare() wasn't called.
    479480     *
    480      * @note    Called before consumeHeaders() and consumeBody().
     481     * @note    Called before consumeBody() but after consumeHeader().
    481482     */
    482483    virtual void receiveComplete(int a_rcStatus, RTHTTP a_hHttp);
    483484
    484485    /**
    485      * Callback that consumes HTTP header data from the server.
     486     * Callback that consumes HTTP body data from the server.
    486487     *
    487488     * @param   a_pchData  Body data.
    488489     * @param   a_cbData   Amount of body data.
    489490     *
    490      * @note    Called after receiveComplete()..
    491      */
    492     virtual void consumeHeaders(const char *a_pchData, size_t a_cbData);
    493 
    494     /**
    495      * Callback that consumes HTTP body data from the server.
    496      *
    497      * @param   a_pchData  Body data.
    498      * @param   a_cbData   Amount of body data.
    499      *
    500      * @note    Called after consumeHeaders().
     491     * @note    Called after consumeHeader().
    501492     */
    502493    virtual void consumeBody(const char *a_pchData, size_t a_cbData);
     
    559550    int addError(int a_rc, const char *a_pszFormat, ...);
    560551
    561     /** Field flags. */
    562     enum
    563     {
    564         /** Collection map, name is a prefix followed by '*'. */
    565         kHdrField_MapCollection   = RT_BIT_32(24)
    566     };
    567 
    568     /** Header field descriptor. */
    569     typedef struct
    570     {
    571         /** The header field name. */
    572         const char *pszName;
    573         /** The length of the field name.*/
    574         uint32_t    cchName;
    575         /** Flags, TBD. */
    576         uint32_t    fFlags;
    577         /** Object factory. */
    578         RTCRestObjectBase::PFNCREATEINSTANCE pfnCreateInstance;
    579     } HEADERFIELDDESC;
    580 
    581     /**
    582      * Helper that extracts fields from the HTTP headers.
    583      *
    584      * @param   a_paFieldDescs      Pointer to an array of field descriptors.
    585      * @param   a_pappFieldValues   Pointer to a parallel array of value pointer pointers.
    586      * @param   a_cFields           Number of field descriptors..
    587      * @param   a_pchData           The header blob to search.
    588      * @param   a_cbData            The size of the header blob to search.
    589      */
    590     void extractHeaderFieldsFromBlob(HEADERFIELDDESC const *a_paFieldDescs, RTCRestObjectBase ***a_pappFieldValues,
    591                                      size_t a_cFields, const char *a_pchData, size_t a_cbData);
    592 
    593     /**
    594      * Helper that extracts a header field.
    595      *
    596      * @retval  VINF_SUCCESS
    597      * @retval  VERR_NOT_FOUND if not found.
    598      * @retval  VERR_NO_STR_MEMORY
    599      * @param   a_pszField  The header field header name.
    600      * @param   a_cchField  The length of the header field name.
    601      * @param   a_pchData   The header blob to search.
    602      * @param   a_cbData    The size of the header blob to search.
    603      * @param   a_pStrDst   Where to store the header value on successs.
    604      */
    605     int extractHeaderFromBlob(const char *a_pszField, size_t a_cchField, const char *a_pchData, size_t a_cbData,
    606                               RTCString *a_pStrDst);
     552    /**
     553     * Deserializes a header field value.
     554     *
     555     * @returns IPRT status code.
     556     * @param   a_pObj              The object to deserialize into.
     557     * @param   a_pchValue          Pointer to the value (not zero terminated).
     558     *                              Not necessarily valid UTF-8!
     559     * @param   a_cchValue          The value length.
     560     * @param   a_fFlags            Flags to pass to fromString().
     561     * @param   a_pszErrorTag       The error tag (field name).
     562     */
     563    int deserializeHeader(RTCRestObjectBase *a_pObj, const char *a_pchValue, size_t a_cchValue,
     564                          uint32_t a_fFlags, const char *a_pszErrorTag);
     565
     566    /**
     567     * Deserializes a header field value.
     568     *
     569     * @returns IPRT status code.
     570     * @param   a_pMap              The string map object to deserialize into.
     571     * @param   a_pchField          Pointer to the map field name.  (Caller dropped the prefix.)
     572     *                              Not necessarily valid UTF-8!
     573     * @param   a_cchField          Length of field name.
     574     * @param   a_pchValue          Pointer to the value (not zero terminated).
     575     *                              Not necessarily valid UTF-8!
     576     * @param   a_cchValue          The value length.
     577     * @param   a_fFlags            Flags to pass to fromString().
     578     * @param   a_pszErrorTag       The error tag (field name).
     579     */
     580    int deserializeHeaderIntoMap(RTCRestStringMapBase *a_pMap, const char *a_pchField, size_t a_cchField,
     581                                 const char *a_pchValue, size_t a_cchValue, uint32_t a_fFlags, const char *a_pszErrorTag);
    607582
    608583    /**
     
    626601        virtual int unknownField(RTCRestJsonCursor const &a_rCursor) RT_OVERRIDE;
    627602    };
     603
     604
     605    /**
     606     * Consumes a header.
     607     *
     608     * Child classes can override this to pick up their header fields, but must
     609     * always call the parent class.
     610     *
     611     * @returns IPRT status code.
     612     * @param   a_uMatchWord    Match word constructed by RTHTTP_MAKE_HDR_MATCH_WORD
     613     * @param   a_pchField      The field name (not zero terminated).
     614     *                          Not necessarily valid UTF-8!
     615     * @param   a_cchField      The length of the field.
     616     * @param   a_pchValue      The field value (not zero terminated).
     617     * @param   a_cchValue      The length of the value.
     618     */
     619    virtual int consumeHeader(uint32_t a_uMatchWord, const char *a_pchField, size_t a_cchField,
     620                              const char *a_pchValue, size_t a_cchValue);
     621
     622private:
     623    /** Callback for use with RTHttpSetHeaderCallback. */
     624    static FNRTHTTPHEADERCALLBACK receiveHttpHeaderCallback;
    628625};
    629626
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