From fd56cdd21a7c9c944ad189cf91ff24d3c2b0f975 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 20 Apr 2022 14:04:47 -0700 Subject: Gradually moving to better archive structure. It's dragging other new API changes along with it, including use of Blob and Text. --- src/stable/archive.cpp | 84 ++++++++++++------- src/stable/archive.h | 46 ++++++++++- src/stable/archivebinary.cpp | 190 ++++++++++++++++++++++++++++++++++++++++++- src/stable/archivebinary.h | 40 ++++++++- src/stable/crypt.cpp | 4 +- src/stable/membuf.cpp | 5 ++ src/stable/membuf.h | 2 + src/stable/string.cpp | 12 ++- 8 files changed, 339 insertions(+), 44 deletions(-) (limited to 'src/stable') diff --git a/src/stable/archive.cpp b/src/stable/archive.cpp index df9b1ff..829e7eb 100644 --- a/src/stable/archive.cpp +++ b/src/stable/archive.cpp @@ -17,181 +17,205 @@ Bu::Archive::~Archive() Bu::Archive &Bu::operator<<( Bu::Archive &ar, bool p) { - ar.write( &p, sizeof(p) ); + ar.write( p ); return ar; } Bu::Archive &Bu::operator<<( Bu::Archive &ar, char p) { - ar.write( &p, sizeof(p) ); + ar.write( p ); return ar; } Bu::Archive &Bu::operator<<( Bu::Archive &ar, signed char p) { - ar.write( &p, sizeof(p) ); + ar.write( p ); return ar; } Bu::Archive &Bu::operator<<( Bu::Archive &ar, unsigned char p) { - ar.write( &p, sizeof(p) ); + ar.write( p ); return ar; } Bu::Archive &Bu::operator<<( Bu::Archive &ar, signed short p) { - ar.write( &p, sizeof(p) ); + ar.write( p ); return ar; } Bu::Archive &Bu::operator<<( Bu::Archive &ar, unsigned short p) { - ar.write( &p, sizeof(p) ); + ar.write( p ); return ar; } Bu::Archive &Bu::operator<<( Bu::Archive &ar, signed int p) { - ar.write( &p, sizeof(p) ); + ar.write( p ); return ar; } Bu::Archive &Bu::operator<<( Bu::Archive &ar, unsigned int p) { - ar.write( &p, sizeof(p) ); + ar.write( p ); return ar; } Bu::Archive &Bu::operator<<( Bu::Archive &ar, signed long p) { - ar.write( &p, sizeof(p) ); + ar.write( p ); return ar; } Bu::Archive &Bu::operator<<( Bu::Archive &ar, unsigned long p) { - ar.write( &p, sizeof(p) ); + ar.write( p ); return ar; } Bu::Archive &Bu::operator<<( Bu::Archive &ar, signed long long p) { - ar.write( &p, sizeof(p) ); + ar.write( p ); return ar; } Bu::Archive &Bu::operator<<( Bu::Archive &ar, unsigned long long p) { - ar.write( &p, sizeof(p) ); + ar.write( p ); return ar; } Bu::Archive &Bu::operator<<( Bu::Archive &ar, float p) { - ar.write( &p, sizeof(p) ); + ar.write( p ); return ar; } Bu::Archive &Bu::operator<<( Bu::Archive &ar, double p) { - ar.write( &p, sizeof(p) ); + ar.write( p ); return ar; } Bu::Archive &Bu::operator<<( Bu::Archive &ar, long double p) { - ar.write( &p, sizeof(p) ); + ar.write( p ); + return ar; +} + +Bu::Archive &Bu::operator<<( Bu::Archive &ar, const Bu::Blob &p) +{ + ar.write( p ); + return ar; +} + +Bu::Archive &Bu::operator<<( Bu::Archive &ar, const Bu::Text &p) +{ + ar.write( p ); return ar; } Bu::Archive &Bu::operator>>( Bu::Archive &ar, bool &p) { - ar.read( &p, sizeof(p) ); + ar.read( p ); return ar; } Bu::Archive &Bu::operator>>( Bu::Archive &ar, char &p) { - ar.read( &p, sizeof(p) ); + ar.read( p ); return ar; } Bu::Archive &Bu::operator>>( Bu::Archive &ar, signed char &p) { - ar.read( &p, sizeof(p) ); + ar.read( p ); return ar; } Bu::Archive &Bu::operator>>( Bu::Archive &ar, unsigned char &p) { - ar.read( &p, sizeof(p) ); + ar.read( p ); return ar; } Bu::Archive &Bu::operator>>( Bu::Archive &ar, signed short &p) { - ar.read( &p, sizeof(p) ); + ar.read( p ); return ar; } Bu::Archive &Bu::operator>>( Bu::Archive &ar, unsigned short &p) { - ar.read( &p, sizeof(p) ); + ar.read( p ); return ar; } Bu::Archive &Bu::operator>>( Bu::Archive &ar, signed int &p) { - ar.read( &p, sizeof(p) ); + ar.read( p ); return ar; } Bu::Archive &Bu::operator>>( Bu::Archive &ar, unsigned int &p) { - ar.read( &p, sizeof(p) ); + ar.read( p ); return ar; } Bu::Archive &Bu::operator>>( Bu::Archive &ar, signed long &p) { - ar.read( &p, sizeof(p) ); + ar.read( p ); return ar; } Bu::Archive &Bu::operator>>( Bu::Archive &ar, unsigned long &p) { - ar.read( &p, sizeof(p) ); + ar.read( p ); return ar; } Bu::Archive &Bu::operator>>( Bu::Archive &ar, signed long long &p) { - ar.read( &p, sizeof(p) ); + ar.read( p ); return ar; } Bu::Archive &Bu::operator>>( Bu::Archive &ar, unsigned long long &p) { - ar.read( &p, sizeof(p) ); + ar.read( p ); return ar; } Bu::Archive &Bu::operator>>( Bu::Archive &ar, float &p) { - ar.read( &p, sizeof(p) ); + ar.read( p ); return ar; } Bu::Archive &Bu::operator>>( Bu::Archive &ar, double &p) { - ar.read( &p, sizeof(p) ); + ar.read( p ); return ar; } Bu::Archive &Bu::operator>>( Bu::Archive &ar, long double &p) { - ar.read( &p, sizeof(p) ); + ar.read( p ); + return ar; +} + +Bu::Archive &Bu::operator>>( Bu::Archive &ar, Bu::Blob &p) +{ + ar.read( p ); + return ar; +} + +Bu::Archive &Bu::operator>>( Bu::Archive &ar, Bu::Text &p) +{ + ar.read( p ); return ar; } diff --git a/src/stable/archive.h b/src/stable/archive.h index 45d9af6..2cd340c 100644 --- a/src/stable/archive.h +++ b/src/stable/archive.h @@ -16,6 +16,8 @@ namespace Bu { + class Text; + class Archive { public: @@ -29,10 +31,46 @@ namespace Bu }; virtual void close()=0; - virtual void write( const void *pData, size_t iLength )=0; - virtual void read( void *pData, size_t iLength )=0; +// virtual void write( const void *pData, size_t iLength )=0; +// virtual void read( void *pData, size_t iLength )=0; virtual bool isLoading()=0; + virtual void write( bool rData )=0; + virtual void write( unsigned char rData )=0; + virtual void write( char rData )=0; + virtual void write( signed char rData )=0; + virtual void write( unsigned short rData )=0; + virtual void write( signed short rData )=0; + virtual void write( unsigned int rData )=0; + virtual void write( signed int rData )=0; + virtual void write( unsigned long rData )=0; + virtual void write( signed long rData )=0; + virtual void write( unsigned long long rData )=0; + virtual void write( signed long long rData )=0; + virtual void write( float rData )=0; + virtual void write( double rData )=0; + virtual void write( long double rData )=0; + virtual void write( const Bu::Blob &rData )=0; + virtual void write( const Bu::Text &rData )=0; + + virtual void read( bool &rData )=0; + virtual void read( unsigned char &rData )=0; + virtual void read( char &rData )=0; + virtual void read( signed char &rData )=0; + virtual void read( unsigned short &rData )=0; + virtual void read( signed short &rData )=0; + virtual void read( unsigned int &rData )=0; + virtual void read( signed int &rData )=0; + virtual void read( unsigned long &rData )=0; + virtual void read( signed long &rData )=0; + virtual void read( unsigned long long &rData )=0; + virtual void read( signed long long &rData )=0; + virtual void read( float &rData )=0; + virtual void read( double &rData )=0; + virtual void read( long double &rData )=0; + virtual void read( Bu::Blob &rData )=0; + virtual void read( Bu::Text &rData )=0; + virtual void setProperty( const Bu::Blob &rKey, const Bu::Variant &rValue )=0; virtual Bu::Variant getProperty( const Bu::Blob &rKey ) const=0; @@ -65,6 +103,8 @@ namespace Bu Archive &operator<<( Archive &ar, float p ); Archive &operator<<( Archive &ar, double p ); Archive &operator<<( Archive &ar, long double p ); + Archive &operator<<( Archive &ar, const Bu::Blob &p ); + Archive &operator<<( Archive &ar, const Bu::Text &p ); Archive &operator>>( Archive &ar, bool &p ); Archive &operator>>( Archive &ar, char &p ); @@ -81,6 +121,8 @@ namespace Bu Archive &operator>>( Archive &ar, float &p ); Archive &operator>>( Archive &ar, double &p ); Archive &operator>>( Archive &ar, long double &p ); + Archive &operator>>( Archive &ar, Bu::Blob &p ); + Archive &operator>>( Archive &ar, Bu::Text &p ); }; #endif diff --git a/src/stable/archivebinary.cpp b/src/stable/archivebinary.cpp index 3f05947..04e80d2 100644 --- a/src/stable/archivebinary.cpp +++ b/src/stable/archivebinary.cpp @@ -9,6 +9,7 @@ #include "bu/stream.h" #include "bu/sio.h" +#include "bu/text.h" Bu::ArchiveBinary::ArchiveBinary( Stream &rStream, bool bLoading ) : bLoading( bLoading ), @@ -20,7 +21,7 @@ Bu::ArchiveBinary::ArchiveBinary( Stream &rStream, bool bLoading ) : Bu::ArchiveBinary::~ArchiveBinary() { } - +/* void Bu::ArchiveBinary::write( const void *pData, size_t nSize ) { if( nSize == 0 || pData == NULL ) @@ -36,6 +37,193 @@ void Bu::ArchiveBinary::read( void *pData, size_t nSize ) if( (size_t)rStream.read( (char *)pData, nSize ) < nSize ) throw Bu::ExceptionBase("Insufficient data to unarchive object."); +}*/ + +void Bu::ArchiveBinary::write( bool rData ) +{ + rStream.write( &rData, sizeof(rData) ); +} + +void Bu::ArchiveBinary::write( const unsigned char rData ) +{ + rStream.write( &rData, sizeof(rData) ); +} + +void Bu::ArchiveBinary::write( char rData ) +{ + rStream.write( &rData, sizeof(rData) ); +} + +void Bu::ArchiveBinary::write( signed char rData ) +{ + rStream.write( &rData, sizeof(rData) ); +} + +void Bu::ArchiveBinary::write( unsigned short rData ) +{ + rStream.write( &rData, sizeof(rData) ); +} + +void Bu::ArchiveBinary::write( signed short rData ) +{ + rStream.write( &rData, sizeof(rData) ); +} + +void Bu::ArchiveBinary::write( unsigned int rData ) +{ + rStream.write( &rData, sizeof(rData) ); +} + +void Bu::ArchiveBinary::write( signed int rData ) +{ + rStream.write( &rData, sizeof(rData) ); +} + +void Bu::ArchiveBinary::write( unsigned long rData ) +{ + rStream.write( &rData, sizeof(rData) ); +} + +void Bu::ArchiveBinary::write( signed long rData ) +{ + rStream.write( &rData, sizeof(rData) ); +} + +void Bu::ArchiveBinary::write( unsigned long long rData ) +{ + rStream.write( &rData, sizeof(rData) ); +} + +void Bu::ArchiveBinary::write( signed long long rData ) +{ + rStream.write( &rData, sizeof(rData) ); +} + +void Bu::ArchiveBinary::write( float rData ) +{ + rStream.write( &rData, sizeof(rData) ); +} + +void Bu::ArchiveBinary::write( double rData ) +{ + rStream.write( &rData, sizeof(rData) ); +} + +void Bu::ArchiveBinary::write( long double rData ) +{ + rStream.write( &rData, sizeof(rData) ); +} + +void Bu::ArchiveBinary::write( const Bu::Blob &rData ) +{ + int32_t iSize = rData.getSize(); + write( iSize ); + rStream.write( rData.getData(), iSize ); +} + +void Bu::ArchiveBinary::write( const Bu::Text &rData ) +{ + int32_t iSize = rData.getSize(); + write( iSize ); + rStream.write( rData.getData(), iSize ); +} + +void Bu::ArchiveBinary::read( bool &rData ) +{ + rStream.read( &rData, sizeof(rData) ); +} + +void Bu::ArchiveBinary::read( unsigned char &rData ) +{ + rStream.read( &rData, sizeof(rData) ); +} + +void Bu::ArchiveBinary::read( char &rData ) +{ + rStream.read( &rData, sizeof(rData) ); +} + +void Bu::ArchiveBinary::read( signed char &rData ) +{ + rStream.read( &rData, sizeof(rData) ); +} + +void Bu::ArchiveBinary::read( unsigned short &rData ) +{ + rStream.read( &rData, sizeof(rData) ); +} + +void Bu::ArchiveBinary::read( signed short &rData ) +{ + rStream.read( &rData, sizeof(rData) ); +} + +void Bu::ArchiveBinary::read( unsigned int &rData ) +{ + rStream.read( &rData, sizeof(rData) ); +} + +void Bu::ArchiveBinary::read( signed int &rData ) +{ + rStream.read( &rData, sizeof(rData) ); +} + +void Bu::ArchiveBinary::read( unsigned long &rData ) +{ + rStream.read( &rData, sizeof(rData) ); +} + +void Bu::ArchiveBinary::read( signed long &rData ) +{ + rStream.read( &rData, sizeof(rData) ); +} + +void Bu::ArchiveBinary::read( unsigned long long &rData ) +{ + rStream.read( &rData, sizeof(rData) ); +} + +void Bu::ArchiveBinary::read( signed long long &rData ) +{ + rStream.read( &rData, sizeof(rData) ); +} + +void Bu::ArchiveBinary::read( float &rData ) +{ + rStream.read( &rData, sizeof(rData) ); +} + +void Bu::ArchiveBinary::read( double &rData ) +{ + rStream.read( &rData, sizeof(rData) ); +} + +void Bu::ArchiveBinary::read( long double &rData ) +{ + rStream.read( &rData, sizeof(rData) ); +} + +void Bu::ArchiveBinary::read( Bu::Blob &rData ) +{ + int32_t iSize; + read( iSize ); + char *pBuf = new char[iSize]; + rStream.read( pBuf, iSize ); + rData.set( pBuf, iSize ); + delete[] pBuf; +} + +void Bu::ArchiveBinary::read( Bu::Text &rData ) +{ + /* + int32_t iSize; + read( iSize ); + char *pBuf = new char[iSize]; + rStream.read( pBuf, iSize ); + rData.set( pBuf, iSize ); + delete[] pBuf; + */ + throw Bu::ExceptionBase("Cannot read Bu::Text objects yet."); } void Bu::ArchiveBinary::close() diff --git a/src/stable/archivebinary.h b/src/stable/archivebinary.h index 4c12e02..d28e5e7 100644 --- a/src/stable/archivebinary.h +++ b/src/stable/archivebinary.h @@ -77,8 +77,44 @@ namespace Bu virtual ~ArchiveBinary(); virtual void close(); - virtual void write( const void *pData, size_t iSize ); - virtual void read( void *pData, size_t iSize ); + //virtual void write( const void *pData, size_t iSize ); + //virtual void read( void *pData, size_t iSize ); + + virtual void write( bool rData ); + virtual void write( unsigned char rData ); + virtual void write( char rData ); + virtual void write( signed char rData ); + virtual void write( unsigned short rData ); + virtual void write( signed short rData ); + virtual void write( unsigned int rData ); + virtual void write( signed int rData ); + virtual void write( unsigned long rData ); + virtual void write( signed long rData ); + virtual void write( unsigned long long rData ); + virtual void write( signed long long rData ); + virtual void write( float rData ); + virtual void write( double rData ); + virtual void write( long double rData ); + virtual void write( const Bu::Blob &rData ); + virtual void write( const Bu::Text &rData ); + + virtual void read( bool &rData ); + virtual void read( unsigned char &rData ); + virtual void read( char &rData ); + virtual void read( signed char &rData ); + virtual void read( unsigned short &rData ); + virtual void read( signed short &rData ); + virtual void read( unsigned int &rData ); + virtual void read( signed int &rData ); + virtual void read( unsigned long &rData ); + virtual void read( signed long &rData ); + virtual void read( unsigned long long &rData ); + virtual void read( signed long long &rData ); + virtual void read( float &rData ); + virtual void read( double &rData ); + virtual void read( long double &rData ); + virtual void read( Bu::Blob &rData ); + virtual void read( Bu::Text &rData ); /** * For storage, get an ID for the pointer to the object you're going to diff --git a/src/stable/crypt.cpp b/src/stable/crypt.cpp index 085d460..0dbe2d5 100644 --- a/src/stable/crypt.cpp +++ b/src/stable/crypt.cpp @@ -26,7 +26,7 @@ Bu::String Bu::cryptPass( const Bu::String &sPass, const Bu::String &sSalt ) b64Out.stop(); - return sSaltSml + "$" + mbOut.getString(); + return sSaltSml + "$" + mbOut.getBlob(); } Bu::String Bu::cryptPass( const Bu::String &sPass ) @@ -42,6 +42,6 @@ Bu::String Bu::cryptPass( const Bu::String &sPass ) b64Salt.stop(); - return cryptPass( sPass, mbSalt.getString() ); + return cryptPass( sPass, mbSalt.getBlob() ); } diff --git a/src/stable/membuf.cpp b/src/stable/membuf.cpp index 040c0c6..fff3027 100644 --- a/src/stable/membuf.cpp +++ b/src/stable/membuf.cpp @@ -169,6 +169,11 @@ Bu::String &Bu::MemBuf::getString() return sBuf; } +Bu::Blob Bu::MemBuf::getBlob() +{ + return Bu::Blob( sBuf.getStr(), sBuf.getSize() ); +} + void Bu::MemBuf::setString( const Bu::String &sNewData ) { sBuf = sNewData; diff --git a/src/stable/membuf.h b/src/stable/membuf.h index fc9be1f..f42cc2d 100644 --- a/src/stable/membuf.h +++ b/src/stable/membuf.h @@ -13,6 +13,7 @@ #include "bu/config.h" #include "bu/stream.h" #include "bu/string.h" +#include "bu/blob.h" namespace Bu { @@ -57,6 +58,7 @@ namespace Bu virtual Bu::String getLocation() const; Bu::String &getString(); + Bu::Blob getBlob(); void setString( const Bu::String &sNewData ); private: diff --git a/src/stable/string.cpp b/src/stable/string.cpp index c36b768..81f2c7f 100644 --- a/src/stable/string.cpp +++ b/src/stable/string.cpp @@ -1520,20 +1520,18 @@ Bu::String &Bu::operator<<( Bu::String &dst, const Bu::String &sIn ) return dst; } +#include "bu/blob.h" + Bu::Archive &Bu::operator<<( Bu::Archive &ar, const Bu::String &s ) { - long n = s.getSize(); - ar << n; - ar.write( s.getConstStr(), n ); + ar << Bu::Blob( s.getStr(), s.getSize() ); return ar; } Bu::Archive &Bu::operator>>( Bu::Archive &ar, Bu::String &s ) { - long n; - ar >> n; - s.setSize( n ); - ar.read( s.getStr(), n ); + Bu::Blob b; + ar >> b; return ar; } -- cgit v1.2.3