9#include <botan/internal/out_buf.h>
10#include <botan/secqueue.h>
11#include <botan/parsing.h>
20class Null_Filter :
public Filter
23 void write(
const byte input[],
size_t length)
24 { send(input, length); }
26 std::string name()
const {
return "Null"; }
49 for(
size_t j = 0; j != count; ++j)
86void Pipe::destruct(
Filter* to_kill)
90 for(
size_t j = 0; j != to_kill->total_ports(); ++j)
91 destruct(to_kill->next[j]);
119 write(input, length);
136 process_msg(
reinterpret_cast<const byte*
>(input.data()), input.length());
155 throw Invalid_State(
"Pipe::start_msg: Message was already started");
157 pipe =
new Null_Filter;
158 find_endpoints(pipe);
169 throw Invalid_State(
"Pipe::end_msg: Message was already ended");
171 clear_endpoints(pipe);
172 if(
dynamic_cast<Null_Filter*
>(pipe))
185void Pipe::find_endpoints(
Filter* f)
187 for(
size_t j = 0; j != f->total_ports(); ++j)
188 if(f->next[j] && !
dynamic_cast<SecureQueue*
>(f->next[j]))
189 find_endpoints(f->next[j]);
201void Pipe::clear_endpoints(
Filter* f)
204 for(
size_t j = 0; j != f->total_ports(); ++j)
206 if(f->next[j] &&
dynamic_cast<SecureQueue*
>(f->next[j]))
208 clear_endpoints(f->next[j]);
218 throw Invalid_State(
"Cannot append to a Pipe while it is processing");
226 filter->owned =
true;
228 if(!pipe) pipe = filter;
229 else pipe->attach(filter);
238 throw Invalid_State(
"Cannot prepend to a Pipe while it is processing");
246 filter->owned =
true;
248 if(pipe) filter->attach(pipe);
258 throw Invalid_State(
"Cannot pop off a Pipe while it is processing");
263 if(pipe->total_ports() > 1)
264 throw Invalid_State(
"Cannot pop off a Filter with multiple ports");
267 size_t owns = f->owns();
268 pipe = pipe->next[0];
274 pipe = pipe->next[0];
284 return outputs->message_count();
void add(class SecureQueue *)
static const message_id LAST_MESSAGE
Pipe(Filter *=0, Filter *=0, Filter *=0, Filter *=0)
static const message_id DEFAULT_MESSAGE
void write(const byte in[], size_t length)
size_t remaining(message_id msg=DEFAULT_MESSAGE) const
void process_msg(const byte in[], size_t length)
void append(Filter *filt)
message_id message_count() const
void prepend(Filter *filt)
void set_default_msg(message_id msg)
std::invalid_argument Invalid_Argument
Invalid_State(const std::string &err)