aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2017-09-22 20:23:36 -0400
committerJack Lloyd <[email protected]>2017-09-22 20:23:36 -0400
commit08e47c5e550c1135535011f178a84d54613fb976 (patch)
treeb1fc7e469ca5699cda21f3dbc119bfc120ef2627 /src/lib
parent3464804dbad8fdc44500082b224c54704cf2fcf6 (diff)
Deprecate modification of Pipe objects
This is a feature that is hairy to implement and really makes application code confusing.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/filters/filter.h2
-rw-r--r--src/lib/filters/pipe.cpp32
-rw-r--r--src/lib/filters/pipe.h5
3 files changed, 21 insertions, 18 deletions
diff --git a/src/lib/filters/filter.h b/src/lib/filters/filter.h
index 8cd045f6e..773552b77 100644
--- a/src/lib/filters/filter.h
+++ b/src/lib/filters/filter.h
@@ -139,7 +139,7 @@ class BOTAN_PUBLIC_API(2,0) Filter
Filter* get_next() const;
secure_vector<uint8_t> m_write_queue;
- std::vector<Filter*> m_next;
+ std::vector<Filter*> m_next; // not owned
size_t m_port_num, m_filter_owns;
// true if filter belongs to a pipe --> prohibit filter sharing!
diff --git a/src/lib/filters/pipe.cpp b/src/lib/filters/pipe.cpp
index 09ebd2165..51f2cace5 100644
--- a/src/lib/filters/pipe.cpp
+++ b/src/lib/filters/pipe.cpp
@@ -30,13 +30,9 @@ class Null_Filter final : public Filter
/*
* Pipe Constructor
*/
-Pipe::Pipe(Filter* f1, Filter* f2, Filter* f3, Filter* f4)
+Pipe::Pipe(Filter* f1, Filter* f2, Filter* f3, Filter* f4) :
+ Pipe({f1,f2,f3,f4})
{
- init();
- append(f1);
- append(f2);
- append(f3);
- append(f4);
}
/*
@@ -47,7 +43,7 @@ Pipe::Pipe(std::initializer_list<Filter*> args)
init();
for(auto i = args.begin(); i != args.end(); ++i)
- append(*i);
+ do_append(*i);
}
/*
@@ -213,13 +209,16 @@ void Pipe::clear_endpoints(Filter* f)
}
}
+void Pipe::append(Filter* filter)
+ {
+ do_append(filter);
+ }
+
/*
* Append a Filter to the Pipe
*/
-void Pipe::append(Filter* filter)
+void Pipe::do_append(Filter* filter)
{
- if(m_inside_msg)
- throw Invalid_State("Cannot append to a Pipe while it is processing");
if(!filter)
return;
if(dynamic_cast<SecureQueue*>(filter))
@@ -227,6 +226,9 @@ void Pipe::append(Filter* filter)
if(filter->m_owned)
throw Invalid_Argument("Filters cannot be shared among multiple Pipes");
+ if(m_inside_msg)
+ throw Invalid_State("Cannot append to a Pipe while it is processing");
+
filter->m_owned = true;
if(!m_pipe) m_pipe = filter;
@@ -267,16 +269,12 @@ void Pipe::pop()
if(m_pipe->total_ports() > 1)
throw Invalid_State("Cannot pop off a Filter with multiple ports");
- Filter* f = m_pipe;
- size_t owns = f->owns();
- m_pipe = m_pipe->m_next[0];
- delete f;
+ size_t to_remove = m_pipe->owns() + 1;
- while(owns--)
+ while(to_remove--)
{
- f = m_pipe;
+ std::unique_ptr<Filter> to_destroy(m_pipe);
m_pipe = m_pipe->m_next[0];
- delete f;
}
}
diff --git a/src/lib/filters/pipe.h b/src/lib/filters/pipe.h
index 8dcb1e95c..060b5c1ca 100644
--- a/src/lib/filters/pipe.h
+++ b/src/lib/filters/pipe.h
@@ -271,22 +271,26 @@ class BOTAN_PUBLIC_API(2,0) Pipe final : public DataSource
* Insert a new filter at the front of the pipe
* @param filt the new filter to insert
*/
+ BOTAN_DEPRECATED("Runtime modification of Pipe deprecated")
void prepend(Filter* filt);
/**
* Insert a new filter at the back of the pipe
* @param filt the new filter to insert
*/
+ BOTAN_DEPRECATED("Runtime modification of Pipe deprecated")
void append(Filter* filt);
/**
* Remove the first filter at the front of the pipe.
*/
+ BOTAN_DEPRECATED("Runtime modification of Pipe deprecated")
void pop();
/**
* Reset this pipe to an empty pipe.
*/
+ BOTAN_DEPRECATED("Runtime modification of Pipe deprecated")
void reset();
/**
@@ -309,6 +313,7 @@ class BOTAN_PUBLIC_API(2,0) Pipe final : public DataSource
private:
void init();
void destruct(Filter*);
+ void do_append(Filter* filt);
void find_endpoints(Filter*);
void clear_endpoints(Filter*);