Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : : #ifndef _TOOLS_INETSTRM_HXX
20 : : #define _TOOLS_INETSTRM_HXX
21 : :
22 : : #include "tools/toolsdllapi.h"
23 : : #include <sal/types.h>
24 : : #include <tools/string.hxx>
25 : :
26 : : class INetMessage;
27 : : class INetMIMEMessage;
28 : : class SvMemoryStream;
29 : : class SvStream;
30 : :
31 : : enum INetStreamStatus
32 : : {
33 : : INETSTREAM_STATUS_LOADED = -4,
34 : : INETSTREAM_STATUS_WOULDBLOCK = -3,
35 : : INETSTREAM_STATUS_OK = -2,
36 : : INETSTREAM_STATUS_ERROR = -1
37 : : };
38 : :
39 : : class TOOLS_DLLPUBLIC INetIStream
40 : : {
41 : : // Not implemented.
42 : : INetIStream (const INetIStream& rStrm);
43 : : INetIStream& operator= (const INetIStream& rStrm);
44 : :
45 : : protected:
46 : : virtual int GetData (sal_Char *pData, sal_uIntPtr nSize) = 0;
47 : :
48 : : public:
49 : : INetIStream ();
50 : : virtual ~INetIStream (void);
51 : :
52 : : int Read (sal_Char *pData, sal_uIntPtr nSize);
53 : : };
54 : :
55 : : class INetOStream
56 : : {
57 : : // Not implemented.
58 : : INetOStream (const INetOStream& rStrm);
59 : : INetOStream& operator= (const INetOStream& rStrm);
60 : :
61 : : protected:
62 : : virtual int PutData (
63 : : const sal_Char *pData, sal_uIntPtr nSize) = 0;
64 : :
65 : : public:
66 : : INetOStream ();
67 : : virtual ~INetOStream (void);
68 : :
69 : : int Write (const sal_Char *pData, sal_uIntPtr nSize);
70 : : };
71 : :
72 : : enum INetMessageStreamState
73 : : {
74 : : INETMSG_EOL_BEGIN,
75 : : INETMSG_EOL_DONE,
76 : : INETMSG_EOL_SCR,
77 : : INETMSG_EOL_FCR,
78 : : INETMSG_EOL_FLF,
79 : : INETMSG_EOL_FSP,
80 : : INETMSG_EOL_FESC
81 : : };
82 : :
83 : : /// Message Generator Interface.
84 : : class INetMessageIStream : public INetIStream
85 : : {
86 : : INetMessage *pSourceMsg;
87 : : sal_Bool bHeaderGenerated;
88 : :
89 : : sal_uIntPtr nBufSiz;
90 : : sal_Char *pBuffer;
91 : : sal_Char *pRead;
92 : : sal_Char *pWrite;
93 : :
94 : : SvStream *pMsgStrm;
95 : : SvMemoryStream *pMsgBuffer;
96 : : sal_Char *pMsgRead;
97 : : sal_Char *pMsgWrite;
98 : :
99 : : virtual int GetData (sal_Char *pData, sal_uIntPtr nSize);
100 : :
101 : : // Not implemented.
102 : : INetMessageIStream (const INetMessageIStream& rStrm);
103 : : INetMessageIStream& operator= (const INetMessageIStream& rStrm);
104 : :
105 : : protected:
106 : : virtual int GetMsgLine (sal_Char *pData, sal_uIntPtr nSize);
107 : :
108 : : public:
109 : : INetMessageIStream (sal_uIntPtr nBufferSize = 2048);
110 : : virtual ~INetMessageIStream (void);
111 : :
112 : : INetMessage *GetSourceMessage (void) const { return pSourceMsg; }
113 : 0 : void SetSourceMessage (INetMessage *pMsg) { pSourceMsg = pMsg; }
114 : :
115 : 0 : void GenerateHeader (sal_Bool bGen = sal_True) { bHeaderGenerated = !bGen; }
116 : : sal_Bool IsHeaderGenerated (void) const { return bHeaderGenerated; }
117 : : };
118 : :
119 : : /// Message Parser Interface.
120 : : class INetMessageOStream : public INetOStream
121 : : {
122 : : INetMessage *pTargetMsg;
123 : : sal_Bool bHeaderParsed;
124 : :
125 : : INetMessageStreamState eOState;
126 : :
127 : : SvMemoryStream *pMsgBuffer;
128 : :
129 : : virtual int PutData (const sal_Char *pData, sal_uIntPtr nSize);
130 : :
131 : : // Not implemented.
132 : : INetMessageOStream (const INetMessageOStream& rStrm);
133 : : INetMessageOStream& operator= (const INetMessageOStream& rStrm);
134 : :
135 : : protected:
136 : : virtual int PutMsgLine (const sal_Char *pData, sal_uIntPtr nSize);
137 : :
138 : : public:
139 : : INetMessageOStream (void);
140 : : virtual ~INetMessageOStream (void);
141 : :
142 : : INetMessage *GetTargetMessage (void) const { return pTargetMsg; }
143 : : void SetTargetMessage (INetMessage *pMsg) { pTargetMsg = pMsg; }
144 : :
145 : : void ParseHeader (sal_Bool bParse = sal_True) { bHeaderParsed = !bParse; }
146 : : sal_Bool IsHeaderParsed (void) const { return bHeaderParsed; }
147 : : };
148 : :
149 : : class INetMessageIOStream
150 : : : public INetMessageIStream,
151 : : public INetMessageOStream
152 : : {
153 : : // Not implemented.
154 : : INetMessageIOStream (const INetMessageIOStream& rStrm);
155 : : INetMessageIOStream& operator= (const INetMessageIOStream& rStrm);
156 : :
157 : : public:
158 : : INetMessageIOStream (sal_uIntPtr nBufferSize = 2048);
159 : : virtual ~INetMessageIOStream (void);
160 : : };
161 : :
162 : : enum INetMessageEncoding
163 : : {
164 : : INETMSG_ENCODING_7BIT,
165 : : INETMSG_ENCODING_8BIT,
166 : : INETMSG_ENCODING_BINARY,
167 : : INETMSG_ENCODING_QUOTED,
168 : : INETMSG_ENCODING_BASE64
169 : : };
170 : :
171 : : class TOOLS_DLLPUBLIC INetMIMEMessageStream : public INetMessageIOStream
172 : : {
173 : : int eState;
174 : :
175 : : sal_uIntPtr nChildIndex;
176 : : INetMIMEMessageStream *pChildStrm;
177 : :
178 : : INetMessageEncoding eEncoding;
179 : : INetMessageIStream *pEncodeStrm;
180 : : INetMessageOStream *pDecodeStrm;
181 : :
182 : : SvMemoryStream *pMsgBuffer;
183 : :
184 : : static INetMessageEncoding GetMsgEncoding (
185 : : const String& rContentType);
186 : :
187 : : // Not implemented.
188 : : INetMIMEMessageStream (const INetMIMEMessageStream& rStrm);
189 : : INetMIMEMessageStream& operator= (const INetMIMEMessageStream& rStrm);
190 : :
191 : : protected:
192 : : virtual int GetMsgLine (sal_Char *pData, sal_uIntPtr nSize);
193 : : virtual int PutMsgLine (const sal_Char *pData, sal_uIntPtr nSize);
194 : :
195 : : public:
196 : : INetMIMEMessageStream (sal_uIntPtr nBufferSize = 2048);
197 : : virtual ~INetMIMEMessageStream (void);
198 : :
199 : : using INetMessageIStream::SetSourceMessage;
200 : 0 : void SetSourceMessage (INetMIMEMessage *pMsg)
201 : : {
202 : 0 : INetMessageIStream::SetSourceMessage ((INetMessage *)pMsg);
203 : 0 : }
204 : : INetMIMEMessage *GetSourceMessage (void) const
205 : : {
206 : : return ((INetMIMEMessage *)INetMessageIStream::GetSourceMessage());
207 : : }
208 : :
209 : : using INetMessageOStream::SetTargetMessage;
210 : : void SetTargetMessage (INetMIMEMessage *pMsg)
211 : : {
212 : : INetMessageOStream::SetTargetMessage ((INetMessage *)pMsg);
213 : : }
214 : : INetMIMEMessage *GetTargetMessage (void) const
215 : : {
216 : : return ((INetMIMEMessage *)INetMessageOStream::GetTargetMessage());
217 : : }
218 : : };
219 : :
220 : : #endif
221 : :
222 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|