|
- #pragma once
-
- #include "request.h"
-
- namespace cppmicrohttpd
- {
-
- /**
- * @brief Abstract request class to handle uploaded data.
- */
- struct post_data_request
- : public request
- {
- private:
- using post_processor_ptr_u = std::unique_ptr<MHD_PostProcessor, decltype(&MHD_destroy_post_processor)>;
-
- private:
- post_processor_ptr_u _post_processor; //!< Post processor to handle uploaded data
- size_t _buffer_size; //!< Size of the internal post data buffer
-
- public:
- /**
- * @brief Constructor.
- *
- * @param[in] p_connection Connection this request was received at.
- * @param[in] p_url The URL requested by the client.
- * @param[in] p_method The HTTP method used by the client.
- * @param[in] p_version The HTTP version string.
- * @param[in] p_buffer_size Size of the internal post data buffer.
- * A tiny value e.g. 256 to 1024 should be sufficient, do NOT use a value smaller than 256.
- * For good performance, use 32k or 64k.
- */
- inline post_data_request(
- MHD_Connection * const p_connection,
- const std::string& p_url,
- const std::string& p_method,
- const std::string& p_version,
- size_t p_buffer_size);
-
- /**
- * @brief Handle uploaded data.
- *
- * @param[in] p_data Received post data.
- * @param[in,out] p_size Number of bytes stored in postData.
- *
- * @retval true If the request is not yet finished.
- * @retval false If the request is finished.
- */
- bool handle_post_pata(
- const void * p_data,
- size_t& p_size) override;
-
- private:
- /**
- * @brief Handle procesed post data from the post processor.
- *
- * @param[in] kind Type of the value.
- * @param[in] key Zero-terminated key for the value.
- * @param[in] filename Name of the uploaded file, NULL if not known.
- * @param[in] content_type Mime-type of the data, NULL if not known.
- * @param[in] transfer_encoding Encoding of the data, NULL if not known.
- * @param[in] data Pointer to size bytes of data at the specified offset.
- * @param[in] off Offset of data in the overall value.
- * @param[in] size Number of bytes in data available.
- *
- * @retval MHD_YES If the processing of the data was successful.
- * @retval MHD_NO If the processing of the data has failed.
- */
- virtual int handle_processed_post_data(
- enum MHD_ValueKind kind,
- const char * key,
- const char * filename,
- const char * content_type,
- const char * transfer_encoding,
- const char * data,
- uint64_t off,
- size_t size) = 0;
-
- private:
- /**
- * @brief Callback to handle procesed post data.
- *
- * @param[in] cls Custom value selected at callback registration time.
- * @param[in] kind Type of the value.
- * @param[in] key Zero-terminated key for the value.
- * @param[in] filename Name of the uploaded file, NULL if not known.
- * @param[in] content_type Mime-type of the data, NULL if not known.
- * @param[in] transfer_encoding Encoding of the data, NULL if not known.
- * @param[in] data Pointer to size bytes of data at the specified offset.
- * @param[in] off Offset of data in the overall value.
- * @param[in] size Number of bytes in data available.
- *
- * @retval MHD_YES If the processing of the data was successful.
- * @retval MHD_NO If the processing of the data has failed.
- */
- static int mhd_post_data_iterator_callback(
- void * cls,
- enum MHD_ValueKind kind,
- const char * key,
- const char * filename,
- const char * content_type,
- const char * transfer_encoding,
- const char * data,
- uint64_t off,
- size_t size);
- };
- }
|