xref: /aoo41x/main/tools/inc/tools/inetstrm.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef _TOOLS_INETSTRM_HXX
28 #define _TOOLS_INETSTRM_HXX
29 
30 #include "tools/toolsdllapi.h"
31 #include <sal/types.h>
32 #include <tools/string.hxx>
33 
34 class INetMessage;
35 class INetMIMEMessage;
36 class INetHTTPMessage;
37 class SvMemoryStream;
38 class SvStream;
39 
40 /*=========================================================================
41  *
42  * INetStream Interface.
43  *
44  *=======================================================================*/
45 enum INetStreamStatus
46 {
47 	INETSTREAM_STATUS_LOADED     = -4,
48 	INETSTREAM_STATUS_WOULDBLOCK = -3,
49 	INETSTREAM_STATUS_OK         = -2,
50 	INETSTREAM_STATUS_ERROR      = -1
51 };
52 
53 /*
54  * INetIStream.
55  */
56 class TOOLS_DLLPUBLIC INetIStream
57 {
58 	// Not implemented.
59 	INetIStream (const INetIStream& rStrm);
60 	INetIStream& operator= (const INetIStream& rStrm);
61 
62 protected:
63 	virtual int GetData (sal_Char *pData, sal_uIntPtr nSize) = 0;
64 
65 public:
66 	INetIStream ();
67 	virtual ~INetIStream (void);
68 
69 	int Read (sal_Char *pData, sal_uIntPtr nSize);
70 
71 	static void Decode64 (SvStream& rIn, SvStream& rOut);
72 	static void Encode64 (SvStream& rIn, SvStream& rOut);
73 };
74 
75 /*
76  * INetOStream.
77  */
78 class INetOStream
79 {
80 	// Not implemented.
81 	INetOStream (const INetOStream& rStrm);
82 	INetOStream& operator= (const INetOStream& rStrm);
83 
84 protected:
85 	virtual int PutData (
86 		const sal_Char *pData, sal_uIntPtr nSize) = 0;
87 
88 public:
89 	INetOStream ();
90 	virtual ~INetOStream (void);
91 
92 	int Write (const sal_Char *pData, sal_uIntPtr nSize);
93 };
94 
95 /*
96  * INetIOStream.
97  */
98 class INetIOStream : public INetIStream, public INetOStream
99 {
100 	// Not implemented.
101 	INetIOStream (const INetIOStream& rStrm);
102 	INetIOStream& operator= (const INetIOStream& rStrm);
103 
104 public:
105 	INetIOStream (sal_uIntPtr nIBufferSize = 0, sal_uIntPtr nOBufferSize = 0);
106 	virtual ~INetIOStream (void);
107 };
108 
109 /*=========================================================================
110  *
111  * INetMessageStream Interface.
112  *
113  *=======================================================================*/
114 enum INetMessageStreamState
115 {
116 	INETMSG_EOL_BEGIN,
117 	INETMSG_EOL_DONE,
118 	INETMSG_EOL_SCR,
119 	INETMSG_EOL_FCR,
120 	INETMSG_EOL_FLF,
121 	INETMSG_EOL_FSP,
122 	INETMSG_EOL_FESC
123 };
124 
125 /*
126  * INetMessageIStream (Message Generator) Interface.
127  */
128 class INetMessageIStream : public INetIStream
129 {
130 	INetMessage    *pSourceMsg;
131 	sal_Bool            bHeaderGenerated;
132 
133 	sal_uIntPtr           nBufSiz;
134 	sal_Char       *pBuffer;
135 	sal_Char       *pRead;
136 	sal_Char       *pWrite;
137 
138 	SvStream       *pMsgStrm;
139 	SvMemoryStream *pMsgBuffer;
140 	sal_Char       *pMsgRead;
141 	sal_Char       *pMsgWrite;
142 
143 	virtual int GetData (sal_Char *pData, sal_uIntPtr nSize);
144 
145 	// Not implemented.
146 	INetMessageIStream (const INetMessageIStream& rStrm);
147 	INetMessageIStream& operator= (const INetMessageIStream& rStrm);
148 
149 protected:
150 	virtual int GetMsgLine (sal_Char *pData, sal_uIntPtr nSize);
151 
152 public:
153 	INetMessageIStream (sal_uIntPtr nBufferSize = 2048);
154 	virtual ~INetMessageIStream (void);
155 
156 	INetMessage *GetSourceMessage (void) const { return pSourceMsg; }
157 	void SetSourceMessage (INetMessage *pMsg) { pSourceMsg = pMsg; }
158 
159 	void GenerateHeader (sal_Bool bGen = sal_True) { bHeaderGenerated = !bGen; }
160 	sal_Bool IsHeaderGenerated (void) const { return bHeaderGenerated; }
161 };
162 
163 /*
164  * INetMessageOStream (Message Parser) Interface.
165  */
166 class INetMessageOStream : public INetOStream
167 {
168 	INetMessage            *pTargetMsg;
169 	sal_Bool                    bHeaderParsed;
170 
171 	INetMessageStreamState  eOState;
172 
173 	SvMemoryStream         *pMsgBuffer;
174 
175 	virtual int PutData (const sal_Char *pData, sal_uIntPtr nSize);
176 
177 	// Not implemented.
178 	INetMessageOStream (const INetMessageOStream& rStrm);
179 	INetMessageOStream& operator= (const INetMessageOStream& rStrm);
180 
181 protected:
182 	virtual int PutMsgLine (const sal_Char *pData, sal_uIntPtr nSize);
183 
184 public:
185 	INetMessageOStream (void);
186 	virtual ~INetMessageOStream (void);
187 
188 	INetMessage *GetTargetMessage (void) const { return pTargetMsg; }
189 	void SetTargetMessage (INetMessage *pMsg) { pTargetMsg = pMsg; }
190 
191 	void ParseHeader (sal_Bool bParse = sal_True) { bHeaderParsed = !bParse; }
192 	sal_Bool IsHeaderParsed (void) const { return bHeaderParsed; }
193 };
194 
195 /*
196  * INetMessageIOStream Interface.
197  */
198 class INetMessageIOStream
199 	: public INetMessageIStream,
200 	  public INetMessageOStream
201 {
202 	// Not implemented.
203 	INetMessageIOStream (const INetMessageIOStream& rStrm);
204 	INetMessageIOStream& operator= (const INetMessageIOStream& rStrm);
205 
206 public:
207 	INetMessageIOStream (sal_uIntPtr nBufferSize = 2048);
208 	virtual ~INetMessageIOStream (void);
209 };
210 
211 /*=========================================================================
212  *
213  * INetMIMEMessageStream Interface.
214  *
215  *=======================================================================*/
216 enum INetMessageEncoding
217 {
218 	INETMSG_ENCODING_7BIT,
219 	INETMSG_ENCODING_8BIT,
220 	INETMSG_ENCODING_BINARY,
221 	INETMSG_ENCODING_QUOTED,
222 	INETMSG_ENCODING_BASE64
223 };
224 
225 class TOOLS_DLLPUBLIC INetMIMEMessageStream : public INetMessageIOStream
226 {
227 	int                    eState;
228 
229 	sal_uIntPtr                  nChildIndex;
230 	INetMIMEMessageStream *pChildStrm;
231 
232 	INetMessageEncoding    eEncoding;
233 	INetMessageIStream    *pEncodeStrm;
234 	INetMessageOStream    *pDecodeStrm;
235 
236 	SvMemoryStream        *pMsgBuffer;
237 
238 	static INetMessageEncoding GetMsgEncoding (
239 		const String& rContentType);
240 
241 	// Not implemented.
242 	INetMIMEMessageStream (const INetMIMEMessageStream& rStrm);
243 	INetMIMEMessageStream& operator= (const INetMIMEMessageStream& rStrm);
244 
245 protected:
246 	virtual int GetMsgLine (sal_Char *pData, sal_uIntPtr nSize);
247 	virtual int PutMsgLine (const sal_Char *pData, sal_uIntPtr nSize);
248 
249 public:
250 	INetMIMEMessageStream (sal_uIntPtr nBufferSize = 2048);
251 	virtual ~INetMIMEMessageStream (void);
252 
253     using INetMessageIStream::SetSourceMessage;
254 	void SetSourceMessage (INetMIMEMessage *pMsg)
255 	{
256 		INetMessageIStream::SetSourceMessage ((INetMessage *)pMsg);
257 	}
258 	INetMIMEMessage *GetSourceMessage (void) const
259 	{
260 		return ((INetMIMEMessage *)INetMessageIStream::GetSourceMessage());
261 	}
262 
263     using INetMessageOStream::SetTargetMessage;
264 	void SetTargetMessage (INetMIMEMessage *pMsg)
265 	{
266 		INetMessageOStream::SetTargetMessage ((INetMessage *)pMsg);
267 	}
268 	INetMIMEMessage *GetTargetMessage (void) const
269 	{
270 		return ((INetMIMEMessage *)INetMessageOStream::GetTargetMessage());
271 	}
272 };
273 
274 #endif /* !_TOOLS_INETSTRM_HXX */
275 
276