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