8 #include <botan/pipe.h>
9 #include <botan/internal/out_buf.h>
10 #include <botan/secqueue.h>
11 #include <botan/parsing.h>
20 class Null_Filter :
public Filter
23 void write(
const uint8_t input[],
size_t length)
override
24 { send(input, length); }
26 std::string name()
const override {
return "Null"; }
50 for(
auto i = args.begin(); i != args.end(); ++i)
87 void Pipe::destruct(
Filter* to_kill)
89 if(!to_kill || dynamic_cast<SecureQueue*>(to_kill))
91 for(
size_t j = 0; j != to_kill->total_ports(); ++j)
92 destruct(to_kill->m_next[j]);
111 m_default_read = msg;
120 write(input, length);
142 process_msg(reinterpret_cast<const uint8_t*>(input.data()), input.length());
161 throw Invalid_State(
"Pipe::start_msg: Message was already started");
162 if(m_pipe ==
nullptr)
163 m_pipe =
new Null_Filter;
164 find_endpoints(m_pipe);
175 throw Invalid_State(
"Pipe::end_msg: Message was already ended");
176 m_pipe->finish_msg();
177 clear_endpoints(m_pipe);
178 if(dynamic_cast<Null_Filter*>(m_pipe))
183 m_inside_msg =
false;
191 void Pipe::find_endpoints(
Filter* f)
193 for(
size_t j = 0; j != f->total_ports(); ++j)
194 if(f->m_next[j] && !dynamic_cast<SecureQueue*>(f->m_next[j]))
195 find_endpoints(f->m_next[j]);
207 void Pipe::clear_endpoints(Filter* f)
210 for(
size_t j = 0; j != f->total_ports(); ++j)
212 if(f->m_next[j] && dynamic_cast<SecureQueue*>(f->m_next[j]))
213 f->m_next[j] =
nullptr;
214 clear_endpoints(f->m_next[j]);
224 throw Invalid_State(
"Cannot append to a Pipe while it is processing");
227 if(dynamic_cast<SecureQueue*>(filter))
232 filter->m_owned =
true;
234 if(!m_pipe) m_pipe = filter;
235 else m_pipe->attach(filter);
244 throw Invalid_State(
"Cannot prepend to a Pipe while it is processing");
247 if(dynamic_cast<SecureQueue*>(filter))
252 filter->m_owned =
true;
254 if(m_pipe) filter->attach(m_pipe);
264 throw Invalid_State(
"Cannot pop off a Pipe while it is processing");
269 if(m_pipe->total_ports() > 1)
270 throw Invalid_State(
"Cannot pop off a Filter with multiple ports");
273 size_t owns = f->owns();
274 m_pipe = m_pipe->m_next[0];
280 m_pipe = m_pipe->m_next[0];
void append(Filter *filt)
size_t remaining(message_id msg=DEFAULT_MESSAGE) const BOTAN_WARN_UNUSED_RESULT
static const message_id DEFAULT_MESSAGE
std::vector< T, secure_allocator< T >> secure_vector
static const message_id LAST_MESSAGE
Pipe(Filter *=nullptr, Filter *=nullptr, Filter *=nullptr, Filter *=nullptr)
void process_msg(const uint8_t in[], size_t length)
void add(class SecureQueue *)
void set_default_msg(message_id msg)
message_id message_count() const
bool end_of_data() const override
void prepend(Filter *filt)
Pipe::message_id message_count() const
void write(const uint8_t in[], size_t length)