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 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)
86 void Pipe::destruct(
Filter* to_kill)
88 if(!to_kill || dynamic_cast<SecureQueue*>(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))
185 void 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]);
201 void 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");
221 if(dynamic_cast<SecureQueue*>(filter))
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");
241 if(dynamic_cast<SecureQueue*>(filter))
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];
void append(Filter *filt)
void write(const byte in[], size_t length)
std::invalid_argument Invalid_Argument
size_t remaining(message_id msg=DEFAULT_MESSAGE) const
static const message_id DEFAULT_MESSAGE
static const message_id LAST_MESSAGE
Pipe(Filter *=0, Filter *=0, Filter *=0, Filter *=0)
void add(class SecureQueue *)
void set_default_msg(message_id msg)
message_id message_count() const
void process_msg(const byte in[], size_t length)
void prepend(Filter *filt)
Pipe::message_id message_count() const