mirror of
				https://github.com/Telecominfraproject/wlan-cloud-lib-poco.git
				synced 2025-11-04 04:28:10 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			126 lines
		
	
	
		
			3.7 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			126 lines
		
	
	
		
			3.7 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
//
 | 
						|
// ApacheStream.h
 | 
						|
//
 | 
						|
// $Id: //poco/1.4/ApacheConnector/include/ApacheStream.h#2 $
 | 
						|
//
 | 
						|
// Copyright (c) 2006-2011, Applied Informatics Software Engineering GmbH.
 | 
						|
// and Contributors.
 | 
						|
//
 | 
						|
// Permission is hereby granted, free of charge, to any person or organization
 | 
						|
// obtaining a copy of the software and accompanying documentation covered by
 | 
						|
// this license (the "Software") to use, reproduce, display, distribute,
 | 
						|
// execute, and transmit the Software, and to prepare derivative works of the
 | 
						|
// Software, and to permit third-parties to whom the Software is furnished to
 | 
						|
// do so, all subject to the following:
 | 
						|
// 
 | 
						|
// The copyright notices in the Software and this entire statement, including
 | 
						|
// the above license grant, this restriction and the following disclaimer,
 | 
						|
// must be included in all copies of the Software, in whole or in part, and
 | 
						|
// all derivative works of the Software, unless such copies or derivative
 | 
						|
// works are solely in the form of machine-executable object code generated by
 | 
						|
// a source language processor.
 | 
						|
// 
 | 
						|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
						|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
						|
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
 | 
						|
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
 | 
						|
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
 | 
						|
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 | 
						|
// DEALINGS IN THE SOFTWARE.
 | 
						|
//
 | 
						|
 | 
						|
 | 
						|
#ifndef ApacheConnector_ApacheStream_INCLUDED
 | 
						|
#define ApacheConnector_ApacheStream_INCLUDED
 | 
						|
 | 
						|
 | 
						|
#include "ApacheConnector.h"
 | 
						|
#include "Poco/BufferedStreamBuf.h"
 | 
						|
#include <istream>
 | 
						|
#include <ostream>
 | 
						|
 | 
						|
 | 
						|
class ApacheStreamBuf: public Poco::BufferedStreamBuf
 | 
						|
	/// This is the streambuf class used for reading from and writing to a socket.
 | 
						|
{
 | 
						|
public:
 | 
						|
	ApacheStreamBuf(ApacheRequestRec* pApacheRequest, bool haveData = false);
 | 
						|
		/// Creates a ApacheStreamBuf with the given socket.
 | 
						|
 | 
						|
	~ApacheStreamBuf();
 | 
						|
		/// Destroys the SocketStreamBuf.
 | 
						|
 | 
						|
protected:
 | 
						|
	int readFromDevice(char* buffer, std::streamsize length);
 | 
						|
	int writeToDevice(const char* buffer, std::streamsize length);
 | 
						|
 | 
						|
private:
 | 
						|
	enum 
 | 
						|
	{
 | 
						|
		STREAM_BUFFER_SIZE = 1024
 | 
						|
	};
 | 
						|
 | 
						|
	ApacheRequestRec* _pApacheRequest;
 | 
						|
	bool  _haveData;
 | 
						|
};
 | 
						|
 | 
						|
 | 
						|
class ApacheIOS: public virtual std::ios
 | 
						|
	/// The base class for ApacheStream, ApacheInputStream and
 | 
						|
	/// ApacheOutputStream.
 | 
						|
	///
 | 
						|
	/// This class is needed to ensure the correct initialization
 | 
						|
	/// order of the stream buffer and base classes.
 | 
						|
{
 | 
						|
public:
 | 
						|
	ApacheIOS(ApacheRequestRec* pApacheRequest, bool haveData = false);
 | 
						|
		/// Creates the ApacheIOS with the given socket.
 | 
						|
		
 | 
						|
	~ApacheIOS();
 | 
						|
		/// Destroys the ApacheIOS.
 | 
						|
		///
 | 
						|
		/// Flushes the buffer, but does not close the socket.
 | 
						|
		
 | 
						|
	ApacheStreamBuf* rdbuf();
 | 
						|
		/// Returns a pointer to the internal ApacheStreamBuf.
 | 
						|
		
 | 
						|
	void close();
 | 
						|
		/// Flushes the stream.
 | 
						|
 | 
						|
protected:
 | 
						|
	ApacheStreamBuf _buf;
 | 
						|
};
 | 
						|
 | 
						|
 | 
						|
class ApacheOutputStream: public ApacheIOS, public std::ostream
 | 
						|
	/// An output stream for writing to an Apache response.
 | 
						|
{
 | 
						|
public:
 | 
						|
	ApacheOutputStream(ApacheRequestRec* pApacheRequest);
 | 
						|
		/// Creates the ApacheOutputStream with the given socket.
 | 
						|
 | 
						|
	~ApacheOutputStream();
 | 
						|
		/// Destroys the ApacheOutputStream.
 | 
						|
		///
 | 
						|
		/// Flushes the buffer.
 | 
						|
};
 | 
						|
 | 
						|
 | 
						|
class ApacheInputStream: public ApacheIOS, public std::istream
 | 
						|
	/// An input stream for reading from an Apache request.
 | 
						|
	///
 | 
						|
	/// Using formatted input from a ApacheInputStream
 | 
						|
	/// is not recommended, due to the read-ahead behavior of
 | 
						|
	/// istream with formatted reads.
 | 
						|
{
 | 
						|
public:
 | 
						|
	ApacheInputStream(ApacheRequestRec* pApacheRequest);
 | 
						|
		/// Creates the ApacheInputStream with the given socket.
 | 
						|
 | 
						|
	~ApacheInputStream();
 | 
						|
		/// Destroys the ApacheInputStream.
 | 
						|
};
 | 
						|
 | 
						|
 | 
						|
#endif // ApacheConnector_ApacheStream_INCLUDED
 |