diff options
author | lloyd <[email protected]> | 2012-07-09 22:50:00 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2012-07-09 22:50:00 +0000 |
commit | 84913296d62f59fce5db5c87802c8a026d39c54a (patch) | |
tree | c17589913e95cdd467375e5aaf954e4bfd7edbbd /src | |
parent | 18a0c6d0b77985d85a22fed8afa3df14de590ca5 (diff) |
Add a patch from Markus Wanner that extends DataSource (including
Pipe) with get_bytes_read() which returns the number of bytes read so
far from that source.
Diffstat (limited to 'src')
-rw-r--r-- | src/entropy/unix_procs/unix_cmd.cpp | 7 | ||||
-rw-r--r-- | src/entropy/unix_procs/unix_cmd.h | 3 | ||||
-rw-r--r-- | src/filters/data_src.h | 10 | ||||
-rw-r--r-- | src/filters/out_buf.cpp | 12 | ||||
-rw-r--r-- | src/filters/out_buf.h | 2 | ||||
-rw-r--r-- | src/filters/pipe.h | 11 | ||||
-rw-r--r-- | src/filters/pipe_rw.cpp | 11 | ||||
-rw-r--r-- | src/filters/secqueue.cpp | 12 | ||||
-rw-r--r-- | src/filters/secqueue.h | 3 |
9 files changed, 71 insertions, 0 deletions
diff --git a/src/entropy/unix_procs/unix_cmd.cpp b/src/entropy/unix_procs/unix_cmd.cpp index 823da2717..07386dbc5 100644 --- a/src/entropy/unix_procs/unix_cmd.cpp +++ b/src/entropy/unix_procs/unix_cmd.cpp @@ -1,6 +1,7 @@ /* * Unix Command Execution * (C) 1999-2007 Jack Lloyd +* 2012 Markus Wanner * * Distributed under the terms of the Botan license */ @@ -86,6 +87,7 @@ size_t DataSource_Command::read(byte buf[], size_t length) return 0; } + bytes_read += got; return static_cast<size_t>(got); } @@ -107,6 +109,11 @@ bool DataSource_Command::end_of_data() const return (pipe) ? false : true; } +size_t DataSource_Command::get_bytes_read() const + { + return bytes_read; + } + /** * Return the Unix file descriptor of the pipe */ diff --git a/src/entropy/unix_procs/unix_cmd.h b/src/entropy/unix_procs/unix_cmd.h index 5185c1c8f..7c2483c10 100644 --- a/src/entropy/unix_procs/unix_cmd.h +++ b/src/entropy/unix_procs/unix_cmd.h @@ -1,6 +1,7 @@ /* * Unix Command Execution * (C) 1999-2007 Jack Lloyd +* 2012 Markus Wanner * * Distributed under the terms of the Botan license */ @@ -53,6 +54,7 @@ class DataSource_Command : public DataSource size_t peek(byte[], size_t, size_t) const; bool end_of_data() const; std::string id() const; + size_t get_bytes_read() const; int fd() const; @@ -67,6 +69,7 @@ class DataSource_Command : public DataSource std::vector<std::string> arg_list; struct pipe_wrapper* pipe; + size_t bytes_read; }; } diff --git a/src/filters/data_src.h b/src/filters/data_src.h index 62bdacd33..775d17cda 100644 --- a/src/filters/data_src.h +++ b/src/filters/data_src.h @@ -1,6 +1,7 @@ /* * DataSource * (C) 1999-2007 Jack Lloyd +* 2012 Markus Wanner * * Distributed under the terms of the Botan license */ @@ -79,6 +80,11 @@ class BOTAN_DLL DataSource */ size_t discard_next(size_t N); + /** + * @return number of bytes read so far. + */ + virtual size_t get_bytes_read() const = 0; + DataSource() {} virtual ~DataSource() {} DataSource& operator=(const DataSource&) = delete; @@ -122,6 +128,8 @@ class BOTAN_DLL DataSource_Memory : public DataSource */ DataSource_Memory(const std::vector<byte>& in) : source(&in[0], &in[in.size()]), offset(0) {} + + virtual size_t get_bytes_read() const { return offset; } private: secure_vector<byte> source; size_t offset; @@ -149,6 +157,8 @@ class BOTAN_DLL DataSource_Stream : public DataSource DataSource_Stream(const std::string& file, bool use_binary = false); ~DataSource_Stream(); + + virtual size_t get_bytes_read() const { return total_read; } private: const std::string identifier; diff --git a/src/filters/out_buf.cpp b/src/filters/out_buf.cpp index 134f6a308..fa94e92e3 100644 --- a/src/filters/out_buf.cpp +++ b/src/filters/out_buf.cpp @@ -1,6 +1,7 @@ /* * Pipe Output Buffer * (C) 1999-2007,2011 Jack Lloyd +* 2012 Markus Wanner * * Distributed under the terms of the Botan license */ @@ -48,6 +49,17 @@ size_t Output_Buffers::remaining(Pipe::message_id msg) const } /* +* Return the total bytes of a message that have already been read. +*/ +size_t Output_Buffers::get_bytes_read(Pipe::message_id msg) const + { + SecureQueue* q = get(msg); + if (q) + return q->get_bytes_read(); + return 0; + } + +/* * Add a new output queue */ void Output_Buffers::add(SecureQueue* queue) diff --git a/src/filters/out_buf.h b/src/filters/out_buf.h index d4244ca5e..2d17ac8d3 100644 --- a/src/filters/out_buf.h +++ b/src/filters/out_buf.h @@ -1,6 +1,7 @@ /* * Output Buffer * (C) 1999-2007 Jack Lloyd +* 2012 Markus Wanner * * Distributed under the terms of the Botan license */ @@ -22,6 +23,7 @@ class Output_Buffers public: size_t read(byte[], size_t, Pipe::message_id); size_t peek(byte[], size_t, size_t, Pipe::message_id) const; + size_t get_bytes_read(Pipe::message_id) const; size_t remaining(Pipe::message_id) const; void add(class SecureQueue*); diff --git a/src/filters/pipe.h b/src/filters/pipe.h index 3236e7c36..ec56d4503 100644 --- a/src/filters/pipe.h +++ b/src/filters/pipe.h @@ -1,6 +1,7 @@ /* * Pipe * (C) 1999-2007 Jack Lloyd +* 2012 Markus Wanner * * Distributed under the terms of the Botan license */ @@ -216,6 +217,16 @@ class BOTAN_DLL Pipe : public DataSource message_id msg = DEFAULT_MESSAGE) const; /** + * @return the number of bytes read from the default message. + */ + size_t get_bytes_read() const; + + /** + * @return the number of bytes read from the specified message. + */ + size_t get_bytes_read(message_id msg = DEFAULT_MESSAGE) const; + + /** * @return currently set default message */ size_t default_msg() const { return default_read; } diff --git a/src/filters/pipe_rw.cpp b/src/filters/pipe_rw.cpp index 8a713ea8d..06b87406e 100644 --- a/src/filters/pipe_rw.cpp +++ b/src/filters/pipe_rw.cpp @@ -1,6 +1,7 @@ /* * Pipe Reading/Writing * (C) 1999-2007 Jack Lloyd +* 2012 Markus Wanner * * Distributed under the terms of the Botan license */ @@ -157,4 +158,14 @@ size_t Pipe::peek(byte& out, size_t offset, message_id msg) const return peek(&out, 1, offset, msg); } +size_t Pipe::get_bytes_read() const + { + return outputs->get_bytes_read(DEFAULT_MESSAGE); + } + +size_t Pipe::get_bytes_read(message_id msg) const + { + return outputs->get_bytes_read(msg); + } + } diff --git a/src/filters/secqueue.cpp b/src/filters/secqueue.cpp index 811a7ef57..9908a2a8c 100644 --- a/src/filters/secqueue.cpp +++ b/src/filters/secqueue.cpp @@ -1,6 +1,7 @@ /* * SecureQueue * (C) 1999-2007 Jack Lloyd +* 2012 Markus Wanner * * Distributed under the terms of the Botan license */ @@ -59,6 +60,7 @@ class SecureQueueNode */ SecureQueue::SecureQueue() { + bytes_read = 0; set_next(nullptr, 0); head = tail = new SecureQueueNode; } @@ -69,6 +71,7 @@ SecureQueue::SecureQueue() SecureQueue::SecureQueue(const SecureQueue& input) : Fanout_Filter(), DataSource() { + bytes_read = 0; set_next(nullptr, 0); head = tail = new SecureQueueNode; @@ -150,6 +153,7 @@ size_t SecureQueue::read(byte output[], size_t length) head = holder; } } + bytes_read += got; return got; } @@ -184,6 +188,14 @@ size_t SecureQueue::peek(byte output[], size_t length, size_t offset) const return got; } +/** +* Return how many bytes have been read so far. +*/ +size_t SecureQueue::get_bytes_read() const + { + return bytes_read; + } + /* * Return how many bytes the queue holds */ diff --git a/src/filters/secqueue.h b/src/filters/secqueue.h index e773b69bc..05c2e3db1 100644 --- a/src/filters/secqueue.h +++ b/src/filters/secqueue.h @@ -1,6 +1,7 @@ /* * SecureQueue * (C) 1999-2007 Jack Lloyd +* 2012 Markus Wanner * * Distributed under the terms of the Botan license */ @@ -25,6 +26,7 @@ class BOTAN_DLL SecureQueue : public Fanout_Filter, public DataSource size_t read(byte[], size_t); size_t peek(byte[], size_t, size_t = 0) const; + size_t get_bytes_read() const; bool end_of_data() const; @@ -56,6 +58,7 @@ class BOTAN_DLL SecureQueue : public Fanout_Filter, public DataSource ~SecureQueue() { destroy(); } private: + size_t bytes_read; void destroy(); class SecureQueueNode* head; class SecureQueueNode* tail; |