PartList.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /***************************************************************************
  2. *
  3. * Project _____ __ ____ _ _
  4. * ( _ ) /__\ (_ _)_| |_ _| |_
  5. * )(_)( /(__)\ )( (_ _)(_ _)
  6. * (_____)(__)(__)(__) |_| |_|
  7. *
  8. *
  9. * Copyright 2018-present, Leonid Stryzhevskyi <lganzzzo@gmail.com>,
  10. * Matthias Haselmaier <mhaselmaier@gmail.com>
  11. *
  12. * Licensed under the Apache License, Version 2.0 (the "License");
  13. * you may not use this file except in compliance with the License.
  14. * You may obtain a copy of the License at
  15. *
  16. * http://www.apache.org/licenses/LICENSE-2.0
  17. *
  18. * Unless required by applicable law or agreed to in writing, software
  19. * distributed under the License is distributed on an "AS IS" BASIS,
  20. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  21. * See the License for the specific language governing permissions and
  22. * limitations under the License.
  23. *
  24. ***************************************************************************/
  25. #ifndef oatpp_web_mime_multipart_PartList_hpp
  26. #define oatpp_web_mime_multipart_PartList_hpp
  27. #include "Multipart.hpp"
  28. namespace oatpp { namespace web { namespace mime { namespace multipart {
  29. /**
  30. * Structure that holds Multipart parts in the `std::list`.
  31. */
  32. class PartList : public Multipart {
  33. private:
  34. std::unordered_map<oatpp::String, std::list<std::shared_ptr<Part>>> m_namedParts;
  35. bool m_readIteratorInitialized;
  36. std::list<std::shared_ptr<Part>> m_parts;
  37. std::list<std::shared_ptr<Part>>::const_iterator m_iterator;
  38. public:
  39. /**
  40. * Constructor.
  41. * @param boundary - multipart boundary value.
  42. */
  43. PartList(const oatpp::String& boundary);
  44. /**
  45. * Constructor.
  46. * @param requestHeaders - request headers. Headers must contain "Content-Type" header.
  47. */
  48. PartList(const Headers& requestHeaders);
  49. /**
  50. * Create Multipart object with random boundary. <br>
  51. * It will generate random vector of size `boundarySize` in bytes encoded in base64.
  52. * @param boundarySize - size of the random vecrot in bytes.
  53. * @return - `std::shared_ptr` to Multipart.
  54. */
  55. static std::shared_ptr<PartList> createSharedWithRandomBoundary(v_int32 boundarySize = 15);
  56. /**
  57. * Read part-by-part from Multipart.
  58. * @return
  59. */
  60. std::shared_ptr<Part> readNextPart(async::Action& action) override;
  61. /**
  62. * Write part-by-part to Multipart.
  63. * @param part
  64. */
  65. void writeNextPart(const std::shared_ptr<Part>& part, async::Action& action) override;
  66. /**
  67. * Get part by name <br>
  68. * Returns the first part if multiple parts with same name exist.
  69. * Applicable to named parts only.
  70. * @param name - &id:oatpp::String;.
  71. * @return - `std::shared_ptr` to &id:oatpp::web::mime::multipart::Part;.
  72. */
  73. std::shared_ptr<Part> getNamedPart(const oatpp::String& name);
  74. /**
  75. * Get all parts by name <br>
  76. * Applicable to named parts only.
  77. * @param name - &id:oatpp::String;.
  78. * @return - `std::list` of `std::shared_ptr` to &id:oatpp::web::mime::multipart::Part;.
  79. */
  80. std::list<std::shared_ptr<Part>> getNamedParts(const oatpp::String& name);
  81. /**
  82. * Get list of all parts.
  83. * @return - `std::list` of `std::shared_ptr` to &id:oatpp::web::mime::multipart::Part;.
  84. */
  85. const std::list<std::shared_ptr<Part>>& getAllParts();
  86. /**
  87. * Get parts count.
  88. * @return - parts count.
  89. */
  90. v_int64 count();
  91. };
  92. }}}}
  93. #endif //oatpp_web_mime_multipart_PartList_hpp