Changeset 74126 in vbox for trunk/include/iprt/cpp/restbinarystring.h
- Timestamp:
- Sep 6, 2018 6:29:40 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/cpp/restbinarystring.h
r74117 r74126 51 51 /** Safe copy assignment method. */ 52 52 int assignCopy(RTCRestBinaryString const &a_rThat); 53 54 /** Frees the data held by the object. 55 * Will set m_pbData to NULL and m_cbData to UINT64_MAX. */ 56 void freeData(); 53 57 54 58 /* Overridden methods: */ … … 66 70 67 71 /** 68 * Gets the data size. 69 * 70 * This can be used from a consumer callback to get the Content-Length field 71 * value if available. Returns UINT64_MAX if not available. 72 */ 73 uint64_t getDataSize() const { return m_cbData; } 72 * Retrieves the callback data. 73 */ 74 void *getCallbackData() const { return m_pvCallbackData; } 75 76 77 /** @name Upload methods 78 * @{ */ 79 80 /** 81 * Sets the content-type for an upload. 82 * 83 * @returns VINF_SUCCESS or VERR_NO_STR_MEMORY. 84 * @param a_pszContentType The content type to set. 85 * If NULL, no content type is set. 86 */ 87 int setContentType(const char *a_pszContentType); 88 89 /** 90 * Gets the content type that was set. 91 */ 92 RTCString const &getContentType() const { return m_strContentType; } 74 93 75 94 /** … … 85 104 * for the entire lifetime of this object (or until 86 105 * setUploadData is called with NULL parameters). 87 * @param a_pszContentType Specifies the content type to set. Pass NULL (default) 88 * to not explictly set the content type. 89 */ 90 int setUploadData(void const *a_pvData, size_t a_cbData, bool a_fCopy, const char *a_pszContentType = NULL); 91 92 /** @name Data callbacks. 93 * @{ */ 106 * 107 * @note This will drop any previously registered producer callback and user data.. 108 */ 109 int setUploadData(void const *a_pvData, size_t a_cbData, bool a_fCopy = true); 110 94 111 /** 95 112 * Callback for producing bytes to upload. … … 109 126 110 127 /** 111 * Callback for consuming downloaded bytes.112 *113 * @returns IPRT status code.114 * @param a_pThis The related string object.115 * @param a_pvSrc Buffer containing the bytes.116 * @param a_cbSrc The number of bytes in the buffer.117 * @remarks Use getCallbackData to get the user data.118 */119 typedef DECLCALLBACK(int) FNCONSUMER(RTCRestBinaryString *a_pThis, const void *a_pvSrc, size_t a_cbSrc);120 /** Pointer to a byte consumer callback. */121 typedef FNCONSUMER *PFNCONSUMER;122 123 /**124 * Retrieves the callback data.125 */126 void *getCallbackData() const { return m_pvCallbackData; }127 128 /**129 * Sets the consumer callback.130 *131 * @returns IPRT status code.132 * @param a_pfnConsumer The callback function for consuming downloaded data.133 * NULL if data should be stored in m_pbData/m_cbData (the default).134 * @param a_pvCallbackData Data the can be retrieved from the callback135 * using getCallbackData().136 */137 int setConsumerCallback(PFNCONSUMER a_pfnConsumer, void *a_pvCallbackData = NULL);138 139 /**140 128 * Sets the producer callback. 141 129 * 142 * @returns IPRT status code.143 130 * @param a_pfnProducer The callback function for producing data. 144 131 * @param a_pvCallbackData Data the can be retrieved from the callback 145 132 * using getCallbackData(). 146 * @param a_cbData The amount of data that will be uploaded, 147 * UINT64_MAX if not unknown. 148 * 149 * @note This will drop any buffer previously registered using 150 * setUploadData(), unless a_pfnProducer is NULL. 151 */ 152 int setProducerCallback(PFNPRODUCER a_pfnProducer, void *a_pvCallbackData = NULL, uint64_t a_cbData = UINT64_MAX); 133 * @param a_cbContentLength The amount of data that will be uploaded and 134 * to be set as the value of the content-length 135 * header field. Pass UINT64_MAX if not known. 136 * 137 * @note This will drop any buffer previously registered using setUploadData(). 138 */ 139 void setProducerCallback(PFNPRODUCER a_pfnProducer, void *a_pvCallbackData = NULL, uint64_t a_cbContentLength = UINT64_MAX); 140 141 /** 142 * Preprares transmission via the @a a_hHttp client instance. 143 * 144 * @returns IPRT status code. 145 * @param a_hHttp The HTTP client instance. 146 * @internal 147 */ 148 virtual int xmitPrepare(RTHTTP a_hHttp) const; 149 150 /** 151 * For completing and/or undoing setup from xmitPrepare. 152 * 153 * @param a_hHttp The HTTP client instance. 154 * @internal 155 */ 156 virtual void xmitComplete(RTHTTP a_hHttp) const; 153 157 /** @} */ 154 158 155 159 156 /** 157 * Preprares transmission via @a a_hHttp. 158 * 159 * @returns IPRT status code. 160 * @param a_hHttp The HTTP client instance. 161 */ 162 virtual int xmitPrepare(RTHTTP a_hHttp) const; 163 164 /** 165 * For completing and/or undoing setup from xmitPrepare. 166 * 167 * @param a_hHttp The HTTP client instance. 168 */ 169 virtual void xmitComplete(RTHTTP a_hHttp) const; 170 171 //virtual int receivePrepare(RTHTTP a_hHttp); 172 //virtual int receiveComplete(int a_rcStatus, RTHTTP a_hHttp); 160 /** @name Download methods 161 * @{ */ 162 163 /** 164 * Sets the max size to download to memory. 165 * 166 * This also indicates the intention to download to a memory buffer, so it 167 * will drop any previously registered consumer callback and its user data. 168 * 169 * @param a_cbMax Maximum number of bytes to download to memory. 170 * If 0, a default is selected (currently 32MiB for 171 * 32-bit hosts and 128MiB for 64-bit). 172 */ 173 void setMaxDownloadSize(size_t a_cbMaxDownload); 174 175 /** 176 * Gets the content-length value (UINT64_MAX if not available). 177 */ 178 uint64_t getContentLength() const { return m_cbContentLength; } 179 180 /** 181 * Gets the number of bytes that has actually been downloaded. 182 */ 183 uint64_t getDownloadSize() const { return m_cbDownloaded; } 184 185 /** 186 * Returns the pointer to the download buffer. 187 * @note returns NULL if setConsumerCallback was used or no data was downloaded. 188 */ 189 uint8_t const *getDownloadData() const { return m_pbData; } 190 191 /** 192 * Callback for consuming downloaded bytes. 193 * 194 * @returns IPRT status code. 195 * @param a_pThis The related string object. 196 * @param a_pvSrc Buffer containing the bytes. 197 * @param a_cbSrc The number of bytes in the buffer. 198 * @param a_uHttpStatus The HTTP status code. 199 * @param a_offContent The byte offset corresponding to the start of @a a_pvSrc. 200 * @param a_cbContent The content length field value, UINT64_MAX if not available. 201 * @remarks Use getCallbackData to get the user data. 202 */ 203 typedef DECLCALLBACK(int) FNCONSUMER(RTCRestBinaryString *a_pThis, const void *a_pvSrc, size_t a_cbSrc, 204 uint32_t a_uHttpStatus, uint64_t a_offContent, uint64_t a_cbContent); 205 /** Pointer to a byte consumer callback. */ 206 typedef FNCONSUMER *PFNCONSUMER; 207 208 /** 209 * Sets the consumer callback. 210 * 211 * @param a_pfnConsumer The callback function for consuming downloaded data. 212 * NULL if data should be stored in m_pbData (the default). 213 * @param a_pvCallbackData Data the can be retrieved from the callback 214 * using getCallbackData(). 215 */ 216 void setConsumerCallback(PFNCONSUMER a_pfnConsumer, void *a_pvCallbackData = NULL); 217 218 /** 219 * Preprares for receiving via the @a a_hHttp client instance. 220 * 221 * @returns IPRT status code. 222 * @param a_hHttp The HTTP client instance. 223 * @param a_fCallbackFlags The HTTP callback flags (status code spec). 224 * @internal 225 */ 226 virtual int receivePrepare(RTHTTP a_hHttp, uint32_t a_fCallbackFlags); 227 228 /** 229 * For completing and/or undoing setup from receivePrepare. 230 * 231 * @param a_hHttp The HTTP client instance. 232 * @internal 233 */ 234 virtual void receiveComplete(RTHTTP a_hHttp); 235 /** @} */ 236 173 237 174 238 protected: 175 /** Pointer to the bytes, if provided directly. */239 /** Pointer to the bytes, if provided directly. (both) */ 176 240 uint8_t *m_pbData; 177 /** Number of bytes. UINT64_MAX if not known. */ 178 uint64_t m_cbData; 179 /** User argument for callbacks. */ 241 /** Number of bytes allocated for the m_pbData buffer (both). */ 242 size_t m_cbAllocated; 243 /** Set if m_pbData must be freed (both). */ 244 bool m_fFreeData; 245 /** Number of bytes corresponding to content-length. 246 * UINT64_MAX if not known. Used both for unploads and downloads. */ 247 uint64_t m_cbContentLength; 248 /** User argument for both callbacks (both). */ 180 249 void *m_pvCallbackData; 181 /** Pointer to user-registered consumer callback function. */ 250 251 /** Pointer to user-registered producer callback function (upload only). */ 252 PFNPRODUCER m_pfnProducer; 253 /** The content type if set (upload only). */ 254 RTCString m_strContentType; 255 256 /** Pointer to user-registered consumer callback function (download only). */ 182 257 PFNCONSUMER m_pfnConsumer; 183 /** Pointer to user-registered producer callback function. */184 PFNPRODUCER m_pfnProducer;185 /** Set if m_pbData must be freed. */186 bool m_fFreeData;187 /** The content type (upload only). */ 188 RTCString m_strContentType;189 190 191 static FNRTHTTP UPLOADCALLBACK xmitHttpCallback;258 /** Number of bytes downloaded thus far. */ 259 uint64_t m_cbDownloaded; 260 /** Maximum data to download to memory (download only). */ 261 size_t m_cbMaxDownload; 262 263 /** Callback for use with RTHttpSetUploadCallback. */ 264 static FNRTHTTPUPLOADCALLBACK xmitHttpCallback; 265 /** Callback for use with RTHttpSetDownloadCallback. */ 266 static FNRTHTTPDOWNLOADCALLBACK receiveHttpCallback; 192 267 193 268 private:
Note:
See TracChangeset
for help on using the changeset viewer.