HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_MIME.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT library (C++)
7  *
8  * COMMENTS: MIME packetting for I/O
9  *
10  */
11 
12 #ifndef __UT_MIME_h__
13 #define __UT_MIME_h__
14 
15 #include "UT_API.h"
16 #include "UT_StringHolder.h"
17 #include "UT_StringMap.h"
18 #include "UT_WorkBuffer.h"
19 #include <SYS/SYS_Types.h>
20 #include <iosfwd>
21 
22 class UT_IStream;
23 class UT_String;
24 class UT_StringArray;
25 
29  UT_MIME_EOF_OK, // End of file reached
31  UT_MIME_BINARY, // Binary MIME format not supported yet
32  UT_MIME_BAD_EOF, // Unexpected EOF
33  UT_MIME_BAD_HEADER, // Bad header
34  UT_MIME_BAD_CONTENTS, // Bad contents in MIME packet
35  UT_MIME_BAD_STREAM, // Bad stream (i.e. bad calling sequence)
36  UT_MIME_USER_ABORT // User cancelled reading the stream
37 };
38 
40 {
41 public:
42 
43  // --------------------------------------------------------
44  // Reading
45 
47 
48  /// Read the next part of the MIME file.
49  /// 'external_src' is optionally the directory the external files are
50  /// stored in. If this is not specified then UT_MIME_EXTERNAL_OK is
51  /// returned for parts that are stored externally. If the external can
52  /// be read its contents will be placed in 'data'.
53  UT_MIME_Status readPart(UT_IStream &is,
54  UT_String &path,
56  exint *modtime = nullptr,
57  const char *ext_src = nullptr);
58  void close(UT_IStream &is) {};
59 
60  // --------------------------------------------------------
61  // Writing
62 
63  void open(std::ostream &os,
64  const char *boundaryText = nullptr);
65 
66  /// Create a new MIME part in the file with the data specified.
67  void writePart(std::ostream &os,
68  const UT_StringHolder &path,
69  const UT_WorkBuffer &data,
70  const exint modtime = -1);
71 
72  /// Create a new MIME part in the file to indicate externally stored data.
73  void writeExternalReference(std::ostream &os,
74  const UT_StringHolder &path,
75  const exint modtime = -1);
76  void close(std::ostream &os);
77 
78  // --------------------------------------------------------
79  // Filtering
80 
81  /// Function signature for functions used to process MIME sections. This
82  /// does all processing in-memory.
83  /// @param in_data Arbitrary input data.
84  /// @param out_data Post processed data output stream which will be MIME data.
85  /// @param filter_data opaque pointer to data used by the filter func.
86  /// @returns False if there was a problem with the filtering.
87  typedef bool(*TextFilterFunc)(const UT_WorkBuffer &in_data,
88  UT_WorkBuffer &out_data,
89  void *filter_data);
90 
91  struct TextFilter
92  {
93  TextFilterFunc myFilter;
94  void *myFilterData;
95 
96  TextFilter(TextFilterFunc filter, void *filterData)
97  : myFilter(filter),
98  myFilterData(filterData)
99  {}
100  };
101  /// Map of section name pattern to a text filter.
103 
104  /// Runs through a MIME archive and apply the TextFilterList filters to the
105  /// sections as appropriate. The complete input mime file `is` is read.
106  /// Packets matching `inclusions` but not matching `exclusions` are written
107  /// to the output stream `os` as MIME data.
108  ///
109  /// All patterns follow UT_String::multiMatch() except as noted.
110  ///
111  /// @param is input text stream of MIME data.
112  /// @param os output stream which will be MIME data.
113  /// @param inclusions Only include these sections. `nullptr` to include all sections.
114  /// @param exclusions Exclude these sections from sections that pass `inclusions`.
115  /// @param filters Filters to apply.
116  /// @returns False if there was a problem with the stream or parameters.
117  static bool filter(UT_IStream &is,
118  std::ostream &os,
119  const char * inclusions,
120  const char * exclusions,
121  const TextFilterList * filters = nullptr);
122 
123 
124  // --------------------------------------------------------
125  // Info
126 
127  /// Given a UT_MIME_Status, return 'true' if the status is not an error
128  /// condition.
129  static bool StatusOK(UT_MIME_Status status);
130 
131  const UT_WorkBuffer &getBoundaryText() const { return myBoundaryText; }
132 
133  /// Return a list of all the files stored externally from this MIME file.
134  /// 'external_src' is optionally the directory the files are stored in.
135  static UT_MIME_Status getAllExternalRefs(UT_IStream &is,
136  UT_StringArray &external_files,
137  const char *ext_src = nullptr);
138  /// Return a list of all the files stored externally from this MIME file.
139  /// 'external_src' is optionally the directory the files are stored in.
140  static UT_MIME_Status getAllExternalRefs(const UT_StringHolder &filename,
141  UT_StringArray &external_files,
142  const char *ext_src = nullptr);
143 
144  static const char * const theDefaultBoundaryString;
145 
146 
147 private:
148  UT_WorkBuffer myBoundaryText;
149 };
150 
151 #endif
GT_API const UT_StringHolder filename
const UT_WorkBuffer & getBoundaryText() const
Definition: UT_MIME.h:131
TextFilterFunc myFilter
Definition: UT_MIME.h:93
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
int64 exint
Definition: SYS_Types.h:125
#define UT_API
Definition: UT_API.h:14
UT_StringMap< TextFilter > TextFilterList
Map of section name pattern to a text filter.
Definition: UT_MIME.h:102
void close() override
void * myFilterData
Definition: UT_MIME.h:94
void close(UT_IStream &is)
Definition: UT_MIME.h:58
UT_MIME_Status
Definition: UT_MIME.h:26
TextFilter(TextFilterFunc filter, void *filterData)
Definition: UT_MIME.h:96
int open(float queuesize) override
static const char *const theDefaultBoundaryString
Definition: UT_MIME.h:144
Definition: format.h:895
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glcorearb.h:1297