Coverage Report

Created: 2025-06-13 06:07

/src/poco/Net/include/Poco/Net/MultipartWriter.h
Line
Count
Source
1
//
2
// MultipartWriter.h
3
//
4
// Library: Net
5
// Package: Messages
6
// Module:  MultipartWriter
7
//
8
// Definition of the MultipartWriter class.
9
//
10
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
11
// and Contributors.
12
//
13
// SPDX-License-Identifier: BSL-1.0
14
//
15
16
17
#ifndef Net_MultipartWriter_INCLUDED
18
#define Net_MultipartWriter_INCLUDED
19
20
21
#include "Poco/Net/Net.h"
22
#include <ostream>
23
24
25
namespace Poco {
26
namespace Net {
27
28
29
class MessageHeader;
30
31
32
class Net_API MultipartWriter
33
  /// This class is used to write MIME multipart
34
  /// messages to an output stream.
35
  ///
36
  /// The format of multipart messages is described
37
  /// in section 5.1 of RFC 2046.
38
  ///
39
  /// To create a multipart message, first create
40
  /// a MultipartWriter object.
41
  /// Then, for each part, call nextPart() and
42
  /// write the content to the output stream.
43
  /// Repeat for all parts.
44
  /// After the last part has been written,
45
  /// call close() to finish the multipart message.
46
{
47
public:
48
  explicit MultipartWriter(std::ostream& ostr);
49
    /// Creates the MultipartWriter, using the
50
    /// given output stream.
51
    ///
52
    /// Creates a random boundary string.
53
54
  MultipartWriter(std::ostream& ostr, const std::string& boundary);
55
    /// Creates the MultipartWriter, using the
56
    /// given output stream and boundary string.
57
58
  ~MultipartWriter();
59
    /// Destroys the MultipartWriter.
60
61
  void nextPart(const MessageHeader& header);
62
    /// Opens a new message part and writes
63
    /// the message boundary string, followed
64
    /// by the message header to the stream.
65
66
  void close();
67
    /// Closes the multipart message and writes
68
    /// the terminating boundary string.
69
    ///
70
    /// Does not close the underlying stream.
71
72
  std::ostream& stream();
73
    /// Returns the writer's stream.
74
75
  const std::string& boundary() const;
76
    /// Returns the multipart boundary used by this writer.
77
78
  static std::string createBoundary();
79
    /// Creates a random boundary string.
80
    ///
81
    /// The string always has the form
82
    /// MIME_boundary_XXXXXXXXXXXX, where
83
    /// XXXXXXXXXXXX is a random hexadecimal
84
    /// number.
85
86
private:
87
  MultipartWriter();
88
  MultipartWriter(const MultipartWriter&);
89
  MultipartWriter& operator = (const MultipartWriter&);
90
91
  std::ostream& _ostr;
92
  std::string   _boundary;
93
  bool          _firstPart;
94
};
95
96
97
//
98
// inlines
99
//
100
inline std::ostream& MultipartWriter::stream()
101
174k
{
102
174k
  return _ostr;
103
174k
}
104
105
106
} } // namespace Poco::Net
107
108
109
#endif // Net_MultipartWriter_INCLUDED