xref: /aoo41x/main/tools/inc/tools/inetstrm.hxx (revision 8b851043)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef _TOOLS_INETSTRM_HXX
24 #define _TOOLS_INETSTRM_HXX
25 
26 #include "tools/toolsdllapi.h"
27 #include <sal/types.h>
28 #include <tools/string.hxx>
29 
30 class INetMessage;
31 class INetMIMEMessage;
32 class INetHTTPMessage;
33 class SvMemoryStream;
34 class SvStream;
35 
36 /*=========================================================================
37  *
38  * INetStream Interface.
39  *
40  *=======================================================================*/
41 enum INetStreamStatus
42 {
43 	INETSTREAM_STATUS_LOADED     = -4,
44 	INETSTREAM_STATUS_WOULDBLOCK = -3,
45 	INETSTREAM_STATUS_OK         = -2,
46 	INETSTREAM_STATUS_ERROR      = -1
47 };
48 
49 /*
50  * INetIStream.
51  */
52 class TOOLS_DLLPUBLIC INetIStream
53 {
54 	// Not implemented.
55 	INetIStream (const INetIStream& rStrm);
56 	INetIStream& operator= (const INetIStream& rStrm);
57 
58 protected:
59 	virtual int GetData (sal_Char *pData, sal_uIntPtr nSize) = 0;
60 
61 public:
62 	INetIStream ();
63 	virtual ~INetIStream (void);
64 
65 	int Read (sal_Char *pData, sal_uIntPtr nSize);
66 
67 	static void Decode64 (SvStream& rIn, SvStream& rOut);
68 	static void Encode64 (SvStream& rIn, SvStream& rOut);
69 };
70 
71 /*
72  * INetOStream.
73  */
74 class INetOStream
75 {
76 	// Not implemented.
77 	INetOStream (const INetOStream& rStrm);
78 	INetOStream& operator= (const INetOStream& rStrm);
79 
80 protected:
81 	virtual int PutData (
82 		const sal_Char *pData, sal_uIntPtr nSize) = 0;
83 
84 public:
85 	INetOStream ();
86 	virtual ~INetOStream (void);
87 
88 	int Write (const sal_Char *pData, sal_uIntPtr nSize);
89 };
90 
91 /*
92  * INetIOStream.
93  */
94 class INetIOStream : public INetIStream, public INetOStream
95 {
96 	// Not implemented.
97 	INetIOStream (const INetIOStream& rStrm);
98 	INetIOStream& operator= (const INetIOStream& rStrm);
99 
100 public:
101 	INetIOStream (sal_uIntPtr nIBufferSize = 0, sal_uIntPtr nOBufferSize = 0);
102 	virtual ~INetIOStream (void);
103 };
104 
105 /*=========================================================================
106  *
107  * INetMessageStream Interface.
108  *
109  *=======================================================================*/
110 enum INetMessageStreamState
111 {
112 	INETMSG_EOL_BEGIN,
113 	INETMSG_EOL_DONE,
114 	INETMSG_EOL_SCR,
115 	INETMSG_EOL_FCR,
116 	INETMSG_EOL_FLF,
117 	INETMSG_EOL_FSP,
118 	INETMSG_EOL_FESC
119 };
120 
121 /*
122  * INetMessageIStream (Message Generator) Interface.
123  */
124 class INetMessageIStream : public INetIStream
125 {
126 	INetMessage    *pSourceMsg;
127 	sal_Bool            bHeaderGenerated;
128 
129 	sal_uIntPtr           nBufSiz;
130 	sal_Char       *pBuffer;
131 	sal_Char       *pRead;
132 	sal_Char       *pWrite;
133 
134 	SvStream       *pMsgStrm;
135 	SvMemoryStream *pMsgBuffer;
136 	sal_Char       *pMsgRead;
137 	sal_Char       *pMsgWrite;
138 
139 	virtual int GetData (sal_Char *pData, sal_uIntPtr nSize);
140 
141 	// Not implemented.
142 	INetMessageIStream (const INetMessageIStream& rStrm);
143 	INetMessageIStream& operator= (const INetMessageIStream& rStrm);
144 
145 protected:
146 	virtual int GetMsgLine (sal_Char *pData, sal_uIntPtr nSize);
147 
148 public:
149 	INetMessageIStream (sal_uIntPtr nBufferSize = 2048);
150 	virtual ~INetMessageIStream (void);
151 
GetSourceMessage(void) const152 	INetMessage *GetSourceMessage (void) const { return pSourceMsg; }
SetSourceMessage(INetMessage * pMsg)153 	void SetSourceMessage (INetMessage *pMsg) { pSourceMsg = pMsg; }
154 
GenerateHeader(sal_Bool bGen=sal_True)155 	void GenerateHeader (sal_Bool bGen = sal_True) { bHeaderGenerated = !bGen; }
IsHeaderGenerated(void) const156 	sal_Bool IsHeaderGenerated (void) const { return bHeaderGenerated; }
157 };
158 
159 /*
160  * INetMessageOStream (Message Parser) Interface.
161  */
162 class INetMessageOStream : public INetOStream
163 {
164 	INetMessage            *pTargetMsg;
165 	sal_Bool                    bHeaderParsed;
166 
167 	INetMessageStreamState  eOState;
168 
169 	SvMemoryStream         *pMsgBuffer;
170 
171 	virtual int PutData (const sal_Char *pData, sal_uIntPtr nSize);
172 
173 	// Not implemented.
174 	INetMessageOStream (const INetMessageOStream& rStrm);
175 	INetMessageOStream& operator= (const INetMessageOStream& rStrm);
176 
177 protected:
178 	virtual int PutMsgLine (const sal_Char *pData, sal_uIntPtr nSize);
179 
180 public:
181 	INetMessageOStream (void);
182 	virtual ~INetMessageOStream (void);
183 
GetTargetMessage(void) const184 	INetMessage *GetTargetMessage (void) const { return pTargetMsg; }
SetTargetMessage(INetMessage * pMsg)185 	void SetTargetMessage (INetMessage *pMsg) { pTargetMsg = pMsg; }
186 
ParseHeader(sal_Bool bParse=sal_True)187 	void ParseHeader (sal_Bool bParse = sal_True) { bHeaderParsed = !bParse; }
IsHeaderParsed(void) const188 	sal_Bool IsHeaderParsed (void) const { return bHeaderParsed; }
189 };
190 
191 /*
192  * INetMessageIOStream Interface.
193  */
194 class INetMessageIOStream
195 	: public INetMessageIStream,
196 	  public INetMessageOStream
197 {
198 	// Not implemented.
199 	INetMessageIOStream (const INetMessageIOStream& rStrm);
200 	INetMessageIOStream& operator= (const INetMessageIOStream& rStrm);
201 
202 public:
203 	INetMessageIOStream (sal_uIntPtr nBufferSize = 2048);
204 	virtual ~INetMessageIOStream (void);
205 };
206 
207 /*=========================================================================
208  *
209  * INetMIMEMessageStream Interface.
210  *
211  *=======================================================================*/
212 enum INetMessageEncoding
213 {
214 	INETMSG_ENCODING_7BIT,
215 	INETMSG_ENCODING_8BIT,
216 	INETMSG_ENCODING_BINARY,
217 	INETMSG_ENCODING_QUOTED,
218 	INETMSG_ENCODING_BASE64
219 };
220 
221 class TOOLS_DLLPUBLIC INetMIMEMessageStream : public INetMessageIOStream
222 {
223 	int                    eState;
224 
225 	sal_uIntPtr                  nChildIndex;
226 	INetMIMEMessageStream *pChildStrm;
227 
228 	INetMessageEncoding    eEncoding;
229 	INetMessageIStream    *pEncodeStrm;
230 	INetMessageOStream    *pDecodeStrm;
231 
232 	SvMemoryStream        *pMsgBuffer;
233 
234 	static INetMessageEncoding GetMsgEncoding (
235 		const String& rContentType);
236 
237 	// Not implemented.
238 	INetMIMEMessageStream (const INetMIMEMessageStream& rStrm);
239 	INetMIMEMessageStream& operator= (const INetMIMEMessageStream& rStrm);
240 
241 protected:
242 	virtual int GetMsgLine (sal_Char *pData, sal_uIntPtr nSize);
243 	virtual int PutMsgLine (const sal_Char *pData, sal_uIntPtr nSize);
244 
245 public:
246 	INetMIMEMessageStream (sal_uIntPtr nBufferSize = 2048);
247 	virtual ~INetMIMEMessageStream (void);
248 
249     using INetMessageIStream::SetSourceMessage;
SetSourceMessage(INetMIMEMessage * pMsg)250 	void SetSourceMessage (INetMIMEMessage *pMsg)
251 	{
252 		INetMessageIStream::SetSourceMessage ((INetMessage *)pMsg);
253 	}
GetSourceMessage(void) const254 	INetMIMEMessage *GetSourceMessage (void) const
255 	{
256 		return ((INetMIMEMessage *)INetMessageIStream::GetSourceMessage());
257 	}
258 
259     using INetMessageOStream::SetTargetMessage;
SetTargetMessage(INetMIMEMessage * pMsg)260 	void SetTargetMessage (INetMIMEMessage *pMsg)
261 	{
262 		INetMessageOStream::SetTargetMessage ((INetMessage *)pMsg);
263 	}
GetTargetMessage(void) const264 	INetMIMEMessage *GetTargetMessage (void) const
265 	{
266 		return ((INetMIMEMessage *)INetMessageOStream::GetTargetMessage());
267 	}
268 };
269 
270 #endif /* !_TOOLS_INETSTRM_HXX */
271 
272