HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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_IStream.h"
17 #include "UT_OStream.h"
18 #include "UT_String.h"
19 #include "UT_StringArray.h"
20 #include "UT_StringMap.h"
21 #include "UT_WorkBuffer.h"
22 
23 class UT_IStream;
24 class UT_OStringStream;
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 
39 class UT_API UT_MIME {
40 public:
41  UT_MIME();
42  virtual ~UT_MIME();
43 
44 
45  // --------------------------------------------------------
46  // Reading
47 
49 
50  /// Read the next part of the MIME file.
51  /// 'external_src' is optionally the directory the external files are
52  /// stored in. If this is not specified then UT_MIME_EXTERNAL_OK is
53  /// returned for parts that are stored externally. If the external can
54  /// be read its contents will be placed in 'data'.
55  UT_MIME_Status readPart(UT_IStream &is,
56  UT_String &path,
58  exint *modtime = nullptr,
59  const char *ext_src = nullptr);
60  void close(UT_IStream &is) {};
61 
62  // --------------------------------------------------------
63  // Writing
64 
65  void open(std::ostream &os,
66  const char *boundaryText = nullptr);
67 
68  /// Create a new MIME part in the file with the data specified.
69  void writePart(std::ostream &os,
70  const UT_StringHolder &path,
71  const UT_WorkBuffer &data,
72  const exint modtime = -1);
73 
74  /// Create a new MIME part in the file to indicate externally stored data.
75  void writeExternalReference(std::ostream &os,
76  const UT_StringHolder &path,
77  const exint modtime = -1);
78  void close(std::ostream &os);
79 
80  // --------------------------------------------------------
81  // Filtering
82  typedef bool(*TextFilterFunc)(const UT_WorkBuffer &in_data,
83  UT_WorkBuffer &out_data,
84  void *filter_data);
85 
86  struct TextFilter
87  {
88  TextFilterFunc myFilter;
89  void *myFilterData;
90 
91  TextFilter(TextFilterFunc filter, void *filterData)
92  : myFilter(filter),
93  myFilterData(filterData)
94  {}
95  };
97 
98  static bool filter(UT_IStream &is,
99  std::ostream &os,
100  const char * inclusions,
101  const char * exclusions,
102  const TextFilterList * filters = nullptr);
103 
104 
105  // --------------------------------------------------------
106  // Info
107 
108  /// Returns true for any non-error status.
109  static bool StatusOK(UT_MIME_Status status);
110 
111  const UT_WorkBuffer &getBoundaryText() const { return myBoundaryText; }
112 
113  /// Return a list of all the files stored externally from this MIME file.
114  /// 'external_src' is optionally the directory the files are stored in.
115  static UT_MIME_Status getAllExternalRefs(UT_IStream &is,
116  UT_StringArray &external_files,
117  const char *ext_src = nullptr);
118  /// Return a list of all the files stored externally from this MIME file.
119  /// 'external_src' is optionally the directory the files are stored in.
120  static UT_MIME_Status getAllExternalRefs(const UT_StringHolder &filename,
121  UT_StringArray &external_files,
122  const char *ext_src = nullptr);
123 
124  static const char * const theDefaultBoundaryString;
125 
126 
127 private:
128  UT_WorkBuffer myBoundaryText;
129 
130 
131 
132 };
133 
134 #endif
const UT_WorkBuffer & getBoundaryText() const
Definition: UT_MIME.h:111
TextFilterFunc myFilter
Definition: UT_MIME.h:88
GLsizei const GLchar *const * path
Definition: glcorearb.h:3340
An output stream object that owns its own string buffer storage.
#define UT_API
Definition: UT_API.h:12
UT_StringMap< TextFilter > TextFilterList
Definition: UT_MIME.h:96
void * myFilterData
Definition: UT_MIME.h:89
void close(UT_IStream &is)
Definition: UT_MIME.h:60
UT_MIME_Status
Definition: UT_MIME.h:26
TextFilter(TextFilterFunc filter, void *filterData)
Definition: UT_MIME.h:91
int64 exint
Definition: SYS_Types.h:109
int int filters
Definition: png.h:1924
GLboolean * data
Definition: glcorearb.h:130
virtual int open(float queuesize)
virtual void close()
static const char *const theDefaultBoundaryString
Definition: UT_MIME.h:124
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glcorearb.h:1296