You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

108 lines
4.4 KiB

  1. #pragma once
  2. #include "request.h"
  3. namespace cppmicrohttpd
  4. {
  5. /**
  6. * @brief Abstract request class to handle uploaded data.
  7. */
  8. struct post_data_request
  9. : public request
  10. {
  11. private:
  12. using post_processor_ptr_u = std::unique_ptr<MHD_PostProcessor, decltype(&MHD_destroy_post_processor)>;
  13. private:
  14. post_processor_ptr_u _post_processor; //!< Post processor to handle uploaded data
  15. size_t _buffer_size; //!< Size of the internal post data buffer
  16. public:
  17. /**
  18. * @brief Constructor.
  19. *
  20. * @param[in] p_connection Connection this request was received at.
  21. * @param[in] p_url The URL requested by the client.
  22. * @param[in] p_method The HTTP method used by the client.
  23. * @param[in] p_version The HTTP version string.
  24. * @param[in] p_buffer_size Size of the internal post data buffer.
  25. * A tiny value e.g. 256 to 1024 should be sufficient, do NOT use a value smaller than 256.
  26. * For good performance, use 32k or 64k.
  27. */
  28. inline post_data_request(
  29. MHD_Connection * const p_connection,
  30. const std::string& p_url,
  31. const std::string& p_method,
  32. const std::string& p_version,
  33. size_t p_buffer_size);
  34. /**
  35. * @brief Handle uploaded data.
  36. *
  37. * @param[in] p_data Received post data.
  38. * @param[in,out] p_size Number of bytes stored in postData.
  39. *
  40. * @retval true If the request is not yet finished.
  41. * @retval false If the request is finished.
  42. */
  43. bool handle_post_pata(
  44. const void * p_data,
  45. size_t& p_size) override;
  46. private:
  47. /**
  48. * @brief Handle procesed post data from the post processor.
  49. *
  50. * @param[in] kind Type of the value.
  51. * @param[in] key Zero-terminated key for the value.
  52. * @param[in] filename Name of the uploaded file, NULL if not known.
  53. * @param[in] content_type Mime-type of the data, NULL if not known.
  54. * @param[in] transfer_encoding Encoding of the data, NULL if not known.
  55. * @param[in] data Pointer to size bytes of data at the specified offset.
  56. * @param[in] off Offset of data in the overall value.
  57. * @param[in] size Number of bytes in data available.
  58. *
  59. * @retval MHD_YES If the processing of the data was successful.
  60. * @retval MHD_NO If the processing of the data has failed.
  61. */
  62. virtual int handle_processed_post_data(
  63. enum MHD_ValueKind kind,
  64. const char * key,
  65. const char * filename,
  66. const char * content_type,
  67. const char * transfer_encoding,
  68. const char * data,
  69. uint64_t off,
  70. size_t size) = 0;
  71. private:
  72. /**
  73. * @brief Callback to handle procesed post data.
  74. *
  75. * @param[in] cls Custom value selected at callback registration time.
  76. * @param[in] kind Type of the value.
  77. * @param[in] key Zero-terminated key for the value.
  78. * @param[in] filename Name of the uploaded file, NULL if not known.
  79. * @param[in] content_type Mime-type of the data, NULL if not known.
  80. * @param[in] transfer_encoding Encoding of the data, NULL if not known.
  81. * @param[in] data Pointer to size bytes of data at the specified offset.
  82. * @param[in] off Offset of data in the overall value.
  83. * @param[in] size Number of bytes in data available.
  84. *
  85. * @retval MHD_YES If the processing of the data was successful.
  86. * @retval MHD_NO If the processing of the data has failed.
  87. */
  88. static int mhd_post_data_iterator_callback(
  89. void * cls,
  90. enum MHD_ValueKind kind,
  91. const char * key,
  92. const char * filename,
  93. const char * content_type,
  94. const char * transfer_encoding,
  95. const char * data,
  96. uint64_t off,
  97. size_t size);
  98. };
  99. }