summaryrefslogtreecommitdiffstats
path: root/botan/src/filters/filter.cpp
diff options
context:
space:
mode:
authorKeith Isdale <keith.isdale@nokia.com>2010-07-26 14:56:53 +1000
committerKeith Isdale <keith.isdale@nokia.com>2010-07-26 14:56:53 +1000
commit9f034793bcfc51c2b7c1dd14db806f7258f9a9eb (patch)
tree63bd0f50ce5b77828ad8205eafd7b9412810499e /botan/src/filters/filter.cpp
parent619d92cfef29e653bfdf852e83888e50cfc4348f (diff)
parent65271649dbc90f3af1184ad1b23bdb64c0c07d07 (diff)
Merge branch 'master' of git://git-nokia.trolltech.com.au/qtsoftware/research/qtuitest
Diffstat (limited to 'botan/src/filters/filter.cpp')
-rw-r--r--botan/src/filters/filter.cpp127
1 files changed, 127 insertions, 0 deletions
diff --git a/botan/src/filters/filter.cpp b/botan/src/filters/filter.cpp
new file mode 100644
index 0000000..4bf0ef9
--- /dev/null
+++ b/botan/src/filters/filter.cpp
@@ -0,0 +1,127 @@
+/*
+* Filter
+* (C) 1999-2007 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*/
+
+#include <botan/filter.h>
+#include <botan/secqueue.h>
+#include <botan/exceptn.h>
+
+namespace Botan {
+
+/*
+* Filter Constructor
+*/
+Filter::Filter()
+ {
+ next.resize(1);
+ port_num = 0;
+ filter_owns = 0;
+ owned = false;
+ }
+
+/*
+* Send data to all ports
+*/
+void Filter::send(const byte input[], u32bit length)
+ {
+ bool nothing_attached = true;
+ for(u32bit j = 0; j != total_ports(); ++j)
+ if(next[j])
+ {
+ if(write_queue.has_items())
+ next[j]->write(write_queue, write_queue.size());
+ next[j]->write(input, length);
+ nothing_attached = false;
+ }
+ if(nothing_attached)
+ write_queue.append(input, length);
+ else if(write_queue.has_items())
+ write_queue.destroy();
+ }
+
+/*
+* Start a new message
+*/
+void Filter::new_msg()
+ {
+ start_msg();
+ for(u32bit j = 0; j != total_ports(); ++j)
+ if(next[j])
+ next[j]->new_msg();
+ }
+
+/*
+* End the current message
+*/
+void Filter::finish_msg()
+ {
+ end_msg();
+ for(u32bit j = 0; j != total_ports(); ++j)
+ if(next[j])
+ next[j]->finish_msg();
+ }
+
+/*
+* Attach a filter to the current port
+*/
+void Filter::attach(Filter* new_filter)
+ {
+ if(new_filter)
+ {
+ Filter* last = this;
+ while(last->get_next())
+ last = last->get_next();
+ last->next[last->current_port()] = new_filter;
+ }
+ }
+
+/*
+* Set the active port on a filter
+*/
+void Filter::set_port(u32bit new_port)
+ {
+ if(new_port >= total_ports())
+ throw Invalid_Argument("Filter: Invalid port number");
+ port_num = new_port;
+ }
+
+/*
+* Return the next Filter in the logical chain
+*/
+Filter* Filter::get_next() const
+ {
+ if(port_num < next.size())
+ return next[port_num];
+ return 0;
+ }
+
+/*
+* Set the next Filters
+*/
+void Filter::set_next(Filter* filters[], u32bit size)
+ {
+ while(size && filters && filters[size-1] == 0)
+ --size;
+
+ next.clear();
+ next.resize(size);
+
+ port_num = 0;
+ filter_owns = 0;
+
+ for(u32bit j = 0; j != size; ++j)
+ next[j] = filters[j];
+ }
+
+/*
+* Return the total number of ports
+*/
+u32bit Filter::total_ports() const
+ {
+ return next.size();
+ }
+
+}