From 22277c6ffe91189cbb5d7a7d8572bf829e3a2610 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 24 Feb 2009 01:31:48 +0000 Subject: Just committing some in-progress code. It may report some warnings, but it doesn't inhibit building. These'll be in good working shape in no time. --- src/buffer.cpp | 17 ++++++++++ src/buffer.h | 33 ++++++++++++++++++ src/httpget.cpp | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/httpget.h | 54 +++++++++++++++++++++++++++++ 4 files changed, 207 insertions(+) create mode 100644 src/buffer.cpp create mode 100644 src/buffer.h create mode 100644 src/httpget.cpp create mode 100644 src/httpget.h diff --git a/src/buffer.cpp b/src/buffer.cpp new file mode 100644 index 0000000..abb4fed --- /dev/null +++ b/src/buffer.cpp @@ -0,0 +1,17 @@ +#include "bu/buffer.h" + +Bu::Buffer::Buffer( Bu::Stream &rNext, int iBufsize ) : + Bu::Filter( rNext ), + sSoFar( 0 ), + iBufSize( iBufSize ), + sReadBuf( NULL ), + sWriteBuf( NULL ), + iReadBufFill( 0 ), + iWriteBufFill( 0 ) +{ +} + +Bu::Buffer::~Buffer() +{ +} + diff --git a/src/buffer.h b/src/buffer.h new file mode 100644 index 0000000..beb4b08 --- /dev/null +++ b/src/buffer.h @@ -0,0 +1,33 @@ +#ifndef BU_BUFFER_H +#define BU_BUFFER_H + +#include "bu/filter.h" + +namespace Bu +{ + class Buffer : public Bu::Filter + { + public: + Buffer( Bu::Stream &rNext, int iBufSize=4096 ); + virtual ~Buffer(); + + virtual void start(); + virtual size_t stop(); + + virtual size_t read( void *pBuf, size_t nBytes ); + virtual size_t write( const void *pBuf, size_t nBytes ); + using Stream::write; + + virtual void flush(); + + private: + size_t sSoFar; + int iBufSize; + char *sReadBuf; + char *sWriteBuf; + int iReadBufFill; + int iWriteBufFill; + }; +}; + +#endif diff --git a/src/httpget.cpp b/src/httpget.cpp new file mode 100644 index 0000000..c5aa16d --- /dev/null +++ b/src/httpget.cpp @@ -0,0 +1,103 @@ +#include "bu/httpget.h" + +Bu::HttpGet::HttpGet( const Bu::Url &uSrc, const Bu::FString &sMethod ) : + uSrc( uSrc ), + sMethod( sMethod ), + sSrv( uSrc.getHost(), uSrc.getPort() ) +{ + sSrv.write( sMethod + " " + uSrc.getFullPath() + " HTTP/1.1\r\n" ); +} + +Bu::HttpGet::~HttpGet() +{ +} + +void Bu::HttpGet::close() +{ +} + +void Bu::HttpGet::get() +{ + for( MimeHash::iterator i = hMimeOut.begin(); i; i++ ) + { + sSrv.write( i.getKey() + ": " + i.getValue() + "\r\n" ); + } + sSrv.write("\r\n", 2 ); + +// sSrv.read( +} + +size_t Bu::HttpGet::read( void *pBuf, size_t nBytes ) +{ +} + +size_t Bu::HttpGet::write( const void *pBuf, size_t nBytes ) +{ + return 0; +} + +long Bu::HttpGet::tell() +{ + return 0; +} + +void Bu::HttpGet::seek( long ) +{ +} + +void Bu::HttpGet::setPos( long ) +{ +} + +void Bu::HttpGet::setPosEnd( long ) +{ +} + +bool Bu::HttpGet::isEOS() +{ + return false; +} + +bool Bu::HttpGet::isOpen() +{ + return true; +} + +void Bu::HttpGet::flush() +{ +} + +bool Bu::HttpGet::canRead() +{ + return true; +} + +bool Bu::HttpGet::canWrite() +{ + return false; +} + +bool Bu::HttpGet::isReadable() +{ + return true; +} + +bool Bu::HttpGet::isWritable() +{ + return false; +} + +bool Bu::HttpGet::isSeekable() +{ + return false; +} + +bool Bu::HttpGet::isBlocking() +{ + return true; +} + +void Bu::HttpGet::setBlocking( bool /*bBlocking*/ ) +{ +} + diff --git a/src/httpget.h b/src/httpget.h new file mode 100644 index 0000000..25f5ab1 --- /dev/null +++ b/src/httpget.h @@ -0,0 +1,54 @@ +#ifndef BU_HTTP_GET_H +#define BU_HTTP_GET_H + +#include "bu/stream.h" +#include "bu/fstring.h" +#include "bu/url.h" +#include "bu/socket.h" + +namespace Bu +{ + class HttpGet : public Bu::Stream + { + public: + HttpGet( const Bu::Url &uSrc, const Bu::FString &sMethod="GET" ); + virtual ~HttpGet(); + + void get(); + + // From Bu::Stream + virtual void close(); + virtual size_t read( void *pBuf, size_t nBytes ); + virtual size_t write( const void *pBuf, size_t nBytes ); + using Stream::write; + + virtual long tell(); + virtual void seek( long offset ); + virtual void setPos( long pos ); + virtual void setPosEnd( long pos ); + virtual bool isEOS(); + virtual bool isOpen(); + + virtual void flush(); + + virtual bool canRead(); + virtual bool canWrite(); + + virtual bool isReadable(); + virtual bool isWritable(); + virtual bool isSeekable(); + + virtual bool isBlocking(); + virtual void setBlocking( bool bBlocking=true ); + + private: + Bu::Url uSrc; + Bu::FString sMethod; + Bu::Socket sSrv; + typedef Bu::Hash MimeHash; + MimeHash hMimeIn; + MimeHash hMimeOut; + }; +}; + +#endif -- cgit v1.2.3