WvStreams
|
An encoder chain owns a list of encoders that are used in sequence to transform data from a source buffer to a target buffer. More...
#include <wvencoder.h>
Public Member Functions | |
WvEncoderChain () | |
Creates an initially empty chain of encoders. | |
virtual | ~WvEncoderChain () |
Destroys the encoder chain. More... | |
void | append (WvEncoder *enc, bool autofree) |
Appends an encoder to the tail of the chain. More... | |
void | prepend (WvEncoder *enc, bool autofree) |
Prepends an encoder to the head of the chain. More... | |
bool | get_autofree (WvEncoder *enc) const |
Gets the autofree state of a particular encoder in the chain. More... | |
void | set_autofree (WvEncoder *enc, bool autofree) |
Sets the autofree state of a particular encoder in the chain. More... | |
void | unlink (WvEncoder *enc) |
Unlinks the encoder from the chain. More... | |
void | zap () |
Clears the encoder chain. More... | |
bool | continue_encode (WvBuf &inbuf, WvBuf &outbuf) |
"Continues" encoding a buffer. More... | |
size_t | buffered () |
Returns true if there is data in an internal buffer. | |
bool | isok () const |
Returns true if the encoder has not encountered an error. More... | |
bool | isfinished () const |
Returns true if the encoder can no longer encode data. More... | |
WvString | geterror () const |
Returns an error message if any is available. More... | |
bool | encode (WvBuf &inbuf, WvBuf &outbuf, bool flush=false, bool finish=false) |
Reads data from the input buffer, encodes it, and writes the result to the output buffer. More... | |
bool | flush (WvBuf &inbuf, WvBuf &outbuf, bool finish=false) |
Flushes the encoder and optionally finishes it. More... | |
bool | finish (WvBuf &outbuf) |
Tells the encoder that NO MORE DATA will ever be encoded. More... | |
bool | reset () |
Asks an encoder to reset itself to its initial state at creation time, if supported. More... | |
bool | flushstrbuf (WvStringParm instr, WvBuf &outbuf, bool finish=false) |
Flushes data through the encoder from a string to a buffer. More... | |
bool | flushstrstr (WvStringParm instr, WvString &outstr, bool finish=false) |
Flushes data through the encoder from a string to a string. More... | |
bool | encodebufstr (WvBuf &inbuf, WvString &outstr, bool flush=false, bool finish=false) |
Encodes data from a buffer to a string. More... | |
bool | flushbufstr (WvBuf &inbuf, WvString &outstr, bool finish=false) |
Flushes data through the encoder from a buffer to a string. More... | |
WvString | strflushstr (WvStringParm instr, bool finish=false) |
Flushes data through the encoder from a string to a string. More... | |
WvString | strflushbuf (WvBuf &inbuf, bool finish=false) |
Flushes data through the encoder from a buffer to a string. More... | |
bool | flushmembuf (const void *inmem, size_t inlen, WvBuf &outbuf, bool finish=false) |
Flushes data through the encoder from memory to a buffer. More... | |
bool | flushmemmem (const void *inmem, size_t inlen, void *outmem, size_t *outlen, bool finish=false) |
Flushes data through the encoder from memory to memory. More... | |
bool | encodebufmem (WvBuf &inbuf, void *outmem, size_t *outlen, bool flush=false, bool finish=false) |
Encodes data from a buffer to memory. More... | |
bool | flushbufmem (WvBuf &inbuf, void *outmem, size_t *outlen, bool finish=false) |
Flushes data through the encoder from a buffer to memory. More... | |
bool | flushstrmem (WvStringParm instr, void *outmem, size_t *outlen, bool finish=false) |
Flushes data through the encoder from a string to memory. More... | |
WvString | strflushmem (const void *inmem, size_t inlen, bool finish=false) |
Flushes data through the encoder from memory to a string. More... | |
Protected Member Functions | |
virtual bool | _isok () const |
Returns true if the encoder has not encountered an error. More... | |
virtual bool | _isfinished () const |
Returns true if the encoder can no longer encode data. More... | |
virtual WvString | _geterror () const |
Returns the error message, if any. More... | |
virtual bool | _encode (WvBuf &in, WvBuf &out, bool flush) |
Passes the data through the entire chain of encoders. More... | |
virtual bool | _finish (WvBuf &out) |
Finishes the chain of encoders. More... | |
virtual bool | _reset () |
Resets the chain of encoders. More... | |
void | setnotok () |
Sets 'okay' to false explicitly. | |
void | seterror (WvStringParm message) |
Sets an error condition, then setnotok(). | |
void | seterror (WVSTRING_FORMAT_DECL) |
Sets an error condition, then setnotok(). | |
void | setfinished () |
Sets 'finished' to true explicitly. | |
Protected Attributes | |
bool | okay |
bool | finished |
WvString | errstr |
An encoder chain owns a list of encoders that are used in sequence to transform data from a source buffer to a target buffer.
Supports reset() if all the encoders it contains also support reset().
Definition at line 549 of file wvencoder.h.
|
virtual |
void WvEncoderChain::append | ( | WvEncoder * | enc, |
bool | autofree | ||
) |
Appends an encoder to the tail of the chain.
if "autofree" is true, takes ownership of the encoder
Definition at line 312 of file wvencoder.cc.
void WvEncoderChain::prepend | ( | WvEncoder * | enc, |
bool | autofree | ||
) |
Prepends an encoder to the head of the chain.
if "autofree" is true, takes ownership of the encoder
Definition at line 318 of file wvencoder.cc.
bool WvEncoderChain::get_autofree | ( | WvEncoder * | enc | ) | const |
Gets the autofree state of a particular encoder in the chain.
If an encoder is in the chain multiple times, this will return true if at least one instance is set to autofree.
Definition at line 324 of file wvencoder.cc.
void WvEncoderChain::set_autofree | ( | WvEncoder * | enc, |
bool | autofree | ||
) |
Sets the autofree state of a particular encoder in the chain.
if "autofree" is true, takes ownership of the encoder, by ensuring only one of the encoders has autofree set. If it is false, then all encoders have their autofree cleared.
Definition at line 334 of file wvencoder.cc.
void WvEncoderChain::unlink | ( | WvEncoder * | enc | ) |
Unlinks the encoder from the chain.
Deletes the encoder if it was added with autofree == true.
Definition at line 365 of file wvencoder.cc.
void WvEncoderChain::zap | ( | ) |
Clears the encoder chain.
Deletes any encoders that were added with autofree == true.
Definition at line 374 of file wvencoder.cc.
"Continues" encoding a buffer.
Runs all data in the buffer through any encoders that have been added to the chain since the last encode.
This is only useful once, immediately after you add one or more new encoders to the chain. However, you can call it whenever you want, and if no new encoders have been added, the given data will simply be (perhaps) copied unchanged into outbuf. Note that this call never does flush() or finish(), so outbuf may or may not be used.
The supplied inbuf is guaranteed to be empty when this function returns.
Definition at line 290 of file wvencoder.cc.
|
protectedvirtual |
Returns true if the encoder has not encountered an error.
WvEncoderChain is special in that it may transition from isok() == false to isok() == true if the offending encoders are removed from the list.
Returns: true iff all encoders return isok() == true
Reimplemented from WvEncoder.
Definition at line 218 of file wvencoder.cc.
|
protectedvirtual |
Returns true if the encoder can no longer encode data.
WvEncoderChain is special in that it may transition from isfinished() == true to isfinished() == false if the offending encoders are removed from the list, but not if finish() is called.
Returns: false iff all encoders return isfinished() == false
Reimplemented from WvEncoder.
Definition at line 228 of file wvencoder.cc.
|
protectedvirtual |
Returns the error message, if any.
WvEncoderChain is special in that it may transition from !geterror() = false to !geterror() = true if the offending encoders are removed from the list.
Returns: the first non-null error message in the chain
Reimplemented from WvEncoder.
Definition at line 238 of file wvencoder.cc.
Passes the data through the entire chain of encoders.
Returns true iff all encoders return true.
Implements WvEncoder.
Definition at line 277 of file wvencoder.cc.
References WvEncoder::flush().
|
protectedvirtual |
Finishes the chain of encoders.
Invokes finish() on the first encoder in the chain, then flush() on the second encoder if new data was generated, then finish() on the second encoder, and so on until all encoders have been flushed and finished (assuming the first encoder had already been flushed).
Returns true iff all encoders return true.
Reimplemented from WvEncoder.
Definition at line 283 of file wvencoder.cc.
|
protectedvirtual |
Resets the chain of encoders.
Resets all of the encoders in the chain and discards any pending buffered input. Preserves the list of encoders.
Returns: true iff all encoders return true.
Reimplemented from WvEncoder.
Definition at line 298 of file wvencoder.cc.
|
inlineinherited |
Returns true if the encoder has not encountered an error.
This should only be used to record permanent failures. Transient errors (eg. bad block, but recoverable) should be detected in a different fashion.
Returns: true if the encoder is ok
Definition at line 90 of file wvencoder.h.
References WvEncoder::_isok(), and WvEncoder::okay.
Referenced by WvEncoder::geterror().
|
inlineinherited |
Returns true if the encoder can no longer encode data.
This will be set when the encoder detects and end-of-data mark in its input, or when finish() is called.
Returns: true if the encoder is finished
Definition at line 101 of file wvencoder.h.
References WvEncoder::_isfinished(), and WvEncoder::finished.
|
inherited |
Returns an error message if any is available.
Returns: the error message, or the null string is isok() == true
Definition at line 23 of file wvencoder.cc.
References WvEncoder::_geterror(), WvEncoder::errstr, and WvEncoder::isok().
|
inherited |
Reads data from the input buffer, encodes it, and writes the result to the output buffer.
If flush == true, the input buffer will be drained and the output buffer will contain all of the encoded data including any that might have been buffered internally from previous calls. Thus it is possible that new data will be written to the output buffer even though the input buffer was empty when encode() was called. If the buffer could not be fully drained because there was insufficient data, this function returns false and leaves the remaining unflushed data in the buffer.
If flush == false, the encoder will read and encode as much data as possible (or as is convenient) from the input buffer and store the results in the output buffer. Partial results may be buffered internally by the encoder to be written to the output buffer later when the encoder is flushed.
If finish = true, the encode() will be followed up by a call to finish(). The return values will be ANDed together to yield the final result. Most useful when flush is also true.
If a permanent error occurs, then isok() will return false, this function will return false and the input buffer will be left in an undefined state.
If a recoverable error occurs, the encoder should discard the problematic data from the input buffer and return false from this function, but isok() will remain true.
A stream might become isfinished() == true if an encoder- specific end-of-data marker was detected in the input.
"inbuf" is the input buffer "outbuf" is the output buffer "flush" is if true, flushes the encoder "finish" is if true, calls finish() on success Returns: true on success
Definition at line 36 of file wvencoder.cc.
References WvEncoder::_encode(), WvEncoder::_finish(), WvEncoder::finish(), WvEncoder::finished, WvEncoder::flush(), WvEncoder::okay, and WvBufBaseCommonImpl< T >::used().
Referenced by WvCounterModeEncoder::_encode(), WvEncoder::encodebufmem(), WvEncoder::encodebufstr(), WvEncoder::flush(), WvEncoder::flushmembuf(), WvEncoder::flushstrbuf(), and WvEncoder::flushstrstr().
Flushes the encoder and optionally finishes it.
"inbuf" is the input buffer "outbuf" is the output buffer "finish" is if true, calls finish() on success Returns: true on success
Definition at line 163 of file wvencoder.h.
References WvEncoder::encode(), and WvEncoder::finish().
Referenced by WvBase64Encoder::_encode(), WvWordWrapEncoder::_encode(), WvBackslashEncoder::_encode(), WvCounterModeEncoder::_encode(), WvBase64Decoder::_encode(), WvBlowfishEncoder::_encode(), WvHexDecoder::_encode(), WvTripleDESEncoder::_encode(), WvGzipEncoder::_encode(), WvBackslashDecoder::_encode(), WvRSAEncoder::_encode(), _encode(), WvEncoder::encode(), WvEncoder::encodebufstr(), WvEncoderStream::finish_read(), and WvEncoderStream::flush_read().
|
inherited |
Tells the encoder that NO MORE DATA will ever be encoded.
The encoder will flush out any internally buffered data and write out whatever end-of-data marking it needs to the supplied output buffer before returning.
Clients should invoke flush() on the input buffer before finish() if the input buffer was not yet empty.
It is safe to call this function multiple times. The implementation will simply return isok() and do nothing else.
"outbuf" is the output buffer Returns: true on success
Definition at line 49 of file wvencoder.cc.
References WvEncoder::_finish(), WvEncoder::finished, WvEncoder::okay, and WvEncoder::setfinished().
Referenced by WvEncoder::encode(), WvEncoder::encodebufmem(), WvEncoder::encodebufstr(), WvEncoderStream::finish_read(), WvEncoder::flush(), WvEncoder::flushbufmem(), WvEncoder::flushbufstr(), WvEncoder::flushmembuf(), WvEncoder::flushmemmem(), WvEncoder::flushstrbuf(), WvEncoder::flushstrmem(), WvEncoder::flushstrstr(), WvEncoder::strflushbuf(), WvEncoder::strflushmem(), and WvEncoder::strflushstr().
|
inherited |
Asks an encoder to reset itself to its initial state at creation time, if supported.
This function may be called at any time, even if isok() == false, or isfinished() == true.
If the behaviour is not supported or an error occurs, then false is returned and afterwards isok() == false.
Returns: true on success
Definition at line 60 of file wvencoder.cc.
References WvEncoder::_reset(), WvEncoder::errstr, WvEncoder::finished, WvEncoder::okay, and WvEncoder::seterror().
|
inherited |
Flushes data through the encoder from a string to a buffer.
"instr" is the input string "outbuf" is the output buffer "finish" is if true, calls finish() on success Returns: true on success
Definition at line 77 of file wvencoder.cc.
References WvEncoder::encode(), and WvEncoder::finish().
|
inherited |
Flushes data through the encoder from a string to a string.
The output data is appended to the target string.
"instr" is the input string "outstr" is the output string "finish" is if true, calls finish() on success Returns: true on success
Definition at line 86 of file wvencoder.cc.
References WvEncoder::encode(), WvEncoder::finish(), and WvBufBase< unsigned char >::getstr().
Referenced by WvEncoder::strflushstr().
|
inherited |
Encodes data from a buffer to a string.
The output data is appended to the target string.
"inbuf" is the input buffer "outstr" is the output string "flush" is if true, flushes the encoder "finish" is if true, calls finish() on success Returns: true on success
Definition at line 97 of file wvencoder.cc.
References WvEncoder::encode(), WvEncoder::finish(), WvEncoder::flush(), and WvBufBase< unsigned char >::getstr().
Referenced by WvEncoder::flushbufstr().
|
inlineinherited |
Flushes data through the encoder from a buffer to a string.
The output data is appended to the target string.
"inbuf" is the input buffer "outstr" is the output string "finish" is if true, calls finish() on success Returns: true on success
Definition at line 249 of file wvencoder.h.
References WvEncoder::encodebufstr(), and WvEncoder::finish().
Referenced by WvEncoder::strflushbuf().
|
inherited |
Flushes data through the encoder from a string to a string.
"inbuf" is the input buffer "finish" is if true, calls finish() on success Returns: the resulting encoded string, does not signal errors
Definition at line 107 of file wvencoder.cc.
References WvEncoder::finish(), and WvEncoder::flushstrstr().
Referenced by WvDBusServerAuth::authorize().
Flushes data through the encoder from a buffer to a string.
"inbuf" is the input buffer "finish" is if true, calls finish() on success Returns: the resulting encoded string, does not signal errors
Definition at line 115 of file wvencoder.cc.
References WvEncoder::finish(), and WvEncoder::flushbufstr().
Referenced by WvX509Mgr::sign(), and WvEncoder::strflushmem().
|
inherited |
Flushes data through the encoder from memory to a buffer.
"inmem" is the input data pointer "inlen" is the input data length "outbuf" is the output buffer "finish" is if true, calls finish() on success Returns: true on success
Definition at line 123 of file wvencoder.cc.
References WvEncoder::encode(), and WvEncoder::finish().
|
inherited |
Flushes data through the encoder from memory to memory.
The outlen parameter specifies by reference the length of the output buffer. It is updated in place to reflect the number of bytes copied to the output buffer. If the buffer was too small to hold the data, the overflow bytes will be discarded and false will be returned.
"inmem" is the input data pointer "inlen" is the input data length "outmem" is the output data pointer "outlen" is the output data length, by reference "finish" is if true, calls finish() on success Returns: true on success
Definition at line 132 of file wvencoder.cc.
References WvEncoder::encodebufmem(), and WvEncoder::finish().
Referenced by unhexify().
|
inherited |
Encodes data from a buffer to memory.
The outlen parameter specifies by reference the length of the output buffer. It is updated in place to reflect the number of bytes copied to the output buffer. If the buffer was too small to hold the data, the overflow bytes will be discarded and false will be returned.
"inmem" is the input data pointer "inlen" is the input data length "outmem" is the output data pointer "outlen" is the output data length, by reference "flush" is if true, flushes the encoder "finish" is if true, calls finish() on success Returns: true on success
Definition at line 140 of file wvencoder.cc.
References WvEncoder::encode(), WvEncoder::finish(), and WvBufBaseCommonImpl< T >::used().
Referenced by WvEncoder::flushbufmem(), and WvEncoder::flushmemmem().
|
inlineinherited |
Flushes data through the encoder from a buffer to memory.
The outlen parameter specifies by reference the length of the output buffer. It is updated in place to reflect the number of bytes copied to the output buffer. If the buffer was too small to hold the data, the overflow bytes will be discarded and false will be returned.
"inbuf" is the input buffer "outmem" is the output data pointer "outlen" is the output data length, by reference "finish" is if true, calls finish() on success Returns: true on success
Definition at line 337 of file wvencoder.h.
References WvEncoder::encodebufmem(), and WvEncoder::finish().
Referenced by WvEncoder::flushstrmem().
|
inherited |
Flushes data through the encoder from a string to memory.
The outlen parameter specifies by reference the length of the output buffer. It is updated in place to reflect the number of bytes copied to the output buffer. If the buffer was too small to hold the data, the overflow bytes will be discarded and false will be returned.
"instr" is the input string "outmem" is the output data pointer "outlen" is the output data length, by reference "finish" is if true, calls finish() on success Returns: true on success
Definition at line 150 of file wvencoder.cc.
References WvEncoder::finish(), and WvEncoder::flushbufmem().
Referenced by WvX509::verify().
|
inherited |
Flushes data through the encoder from memory to a string.
"inmem" is the input data pointer "inlen" is the input data length "finish" is if true, calls finish() on success Returns: the resulting encoded string, does not signal errors
Definition at line 158 of file wvencoder.cc.
References WvEncoder::finish(), and WvEncoder::strflushbuf().
|
protectedinherited |
false iff setnotok() was called
Definition at line 70 of file wvencoder.h.
Referenced by WvEncoder::encode(), WvEncoder::finish(), WvEncoder::isok(), WvEncoder::reset(), WvEncoder::setnotok(), and WvEncoder::WvEncoder().
|
protectedinherited |
true iff setfinished()/finish() was called
Definition at line 71 of file wvencoder.h.
Referenced by WvEncoder::encode(), WvEncoder::finish(), WvEncoder::isfinished(), WvEncoder::reset(), WvEncoder::setfinished(), and WvEncoder::WvEncoder().
|
protectedinherited |
the error message
Definition at line 72 of file wvencoder.h.
Referenced by WvEncoder::geterror(), WvEncoder::reset(), and WvEncoder::seterror().