summaryrefslogtreecommitdiffabout
path: root/test
authorMichael Krelin <hacker@klever.net>2008-01-31 22:12:24 (UTC)
committer Michael Krelin <hacker@klever.net>2008-01-31 22:12:24 (UTC)
commit0a90a7791bd329afd8955df78b8ae358adc897a8 (patch) (side-by-side diff)
tree142bad9602519b9b92200fc7ee6e4f09ad7099bd /test
parent67133db1f33b142561575cdf99fedca8fb6ad79b (diff)
downloadlibopkele-0a90a7791bd329afd8955df78b8ae358adc897a8.zip
libopkele-0a90a7791bd329afd8955df78b8ae358adc897a8.tar.gz
libopkele-0a90a7791bd329afd8955df78b8ae358adc897a8.tar.bz2
test: moved kingate_openid_message wrapper into a separate .h
again, to be used in sample OP Signed-off-by: Michael Krelin <hacker@klever.net>
Diffstat (limited to 'test') (more/less context) (ignore whitespace changes)
-rw-r--r--test/RP.cc110
-rw-r--r--test/kingate_openid_message.h108
2 files changed, 109 insertions, 109 deletions
diff --git a/test/RP.cc b/test/RP.cc
index f2f8851..e9744a4 100644
--- a/test/RP.cc
+++ b/test/RP.cc
@@ -16,134 +16,26 @@ using namespace std;
#include <opkele/discovery.h>
#include <opkele/association.h>
#include <opkele/sreg.h>
using namespace opkele;
#include <opkele/prequeue_rp.h>
#include <opkele/debug.h>
#include "sqlite.h"
+#include "kingate_openid_message.h"
#undef DUMB_RP
#ifdef DUMB_RP
# define DUMBTHROW throw opkele::dumb_RP(OPKELE_CP_ "This RP is dumb")
#else
# define DUMBTHROW (void)0
#endif
-template<typename IT>
-class join_iterator : public iterator<
- input_iterator_tag,typename IT::value_type,
- void,typename IT::pointer,typename IT::reference> {
- public:
- typedef pair<IT,IT> range_t;
- typedef list<range_t> ranges_t;
- ranges_t ranges;
-
- join_iterator() { }
-
- bool cleanup() {
- bool rv = false;
- while(!(ranges.empty() || ranges.front().first!=ranges.front().second)) {
- ranges.pop_front(); rv = true;
- }
- return rv;
- }
-
- join_iterator<IT>& add_range(const IT& b,const IT& e) {
- ranges.push_back(typename ranges_t::value_type(b,e));
- cleanup();
- return *this;
- }
-
- bool operator==(const join_iterator<IT>& x) const {
- return ranges==x.ranges; }
- bool operator!=(const join_iterator<IT>& x) const {
- return ranges!=x.ranges; }
-
- typename IT::reference operator*() const {
- assert(!ranges.empty());
- assert(ranges.front().first!=ranges.front().second);
- return *ranges.front().first; }
- typename IT::pointer operator->() const {
- assert(!ranges.empty());
- assert(ranges.front().first!=ranges.front().second);
- return ranges.front().first.operator->(); }
-
- join_iterator<IT>& operator++() {
- cleanup();
- if(ranges.empty()) return *this;
- do {
- ++ranges.front().first;
- }while(cleanup() && !ranges.empty());
- return *this;
- }
- join_iterator<IT> operator++(int) {
- join_iterator<IT> rv(*this);
- ++(*this); return rv; }
-};
-
-template<typename IT>
-class cut_prefix_filterator : public opkele::util::basic_filterator<IT> {
- public:
- string pfx;
- mutable string tmp;
-
- cut_prefix_filterator() { }
- cut_prefix_filterator(const IT& bi,const IT&ei,const string& pfx)
- : opkele::util::basic_filterator<IT>(bi,ei), pfx(pfx) {
- this->prepare();
- }
-
- bool is_interesting() const {
- return pfx.length()==0 || !strncmp(this->it->c_str(),pfx.c_str(),pfx.length());
- }
-
- typename IT::reference operator*() const {
- assert(!this->empty);
- tmp = *this->it; tmp.erase(0,pfx.length());
- return tmp; }
- typename IT::pointer operator->() const {
- assert(!this->empty);
- return &this->operator*(); }
-};
-
-class kingate_openid_message_t : public opkele::basic_openid_message {
- typedef join_iterator<kingate::cgi_gateway::params_t::const_iterator> jitterator;
- typedef opkele::util::map_keys_iterator<
- jitterator,
- fields_iterator::value_type,
- fields_iterator::reference,
- fields_iterator::pointer> keys_iterator;
- typedef cut_prefix_filterator<keys_iterator> pfilterator;
- public:
- const kingate::cgi_gateway& gw;
-
- kingate_openid_message_t(const kingate::cgi_gateway& g) : gw(g) { }
-
- bool has_field(const string& n) const {
- return gw.has_param("openid."+n); }
- const string& get_field(const string& n) const {
- return gw.get_param("openid."+n); }
-
- fields_iterator fields_begin() const {
- return
- pfilterator( keys_iterator(
- jitterator()
- .add_range( gw.get.begin(), gw.get.end() )
- .add_range( gw.post.begin(), gw.post.end() ),
- jitterator()
- ), keys_iterator(), "openid." );
- }
- fields_iterator fields_end() const {
- return pfilterator();
- }
-};
-
class rpdb_t : public sqlite3_t {
public:
rpdb_t()
: sqlite3_t("/tmp/RP.db") {
assert(_D);
char **resp; int nrow,ncol; char *errm;
if(sqlite3_get_table(
_D,"SELECT a_op FROM assoc LIMIT 0",
diff --git a/test/kingate_openid_message.h b/test/kingate_openid_message.h
new file mode 100644
index 0000000..b3a2c9d
--- a/dev/null
+++ b/test/kingate_openid_message.h
@@ -0,0 +1,108 @@
+template<typename IT>
+class join_iterator : public iterator<
+ input_iterator_tag,typename IT::value_type,
+ void,typename IT::pointer,typename IT::reference> {
+ public:
+ typedef pair<IT,IT> range_t;
+ typedef list<range_t> ranges_t;
+ ranges_t ranges;
+
+ join_iterator() { }
+
+ bool cleanup() {
+ bool rv = false;
+ while(!(ranges.empty() || ranges.front().first!=ranges.front().second)) {
+ ranges.pop_front(); rv = true;
+ }
+ return rv;
+ }
+
+ join_iterator<IT>& add_range(const IT& b,const IT& e) {
+ ranges.push_back(typename ranges_t::value_type(b,e));
+ cleanup();
+ return *this;
+ }
+
+ bool operator==(const join_iterator<IT>& x) const {
+ return ranges==x.ranges; }
+ bool operator!=(const join_iterator<IT>& x) const {
+ return ranges!=x.ranges; }
+
+ typename IT::reference operator*() const {
+ assert(!ranges.empty());
+ assert(ranges.front().first!=ranges.front().second);
+ return *ranges.front().first; }
+ typename IT::pointer operator->() const {
+ assert(!ranges.empty());
+ assert(ranges.front().first!=ranges.front().second);
+ return ranges.front().first.operator->(); }
+
+ join_iterator<IT>& operator++() {
+ cleanup();
+ if(ranges.empty()) return *this;
+ do {
+ ++ranges.front().first;
+ }while(cleanup() && !ranges.empty());
+ return *this;
+ }
+ join_iterator<IT> operator++(int) {
+ join_iterator<IT> rv(*this);
+ ++(*this); return rv; }
+};
+
+template<typename IT>
+class cut_prefix_filterator : public opkele::util::basic_filterator<IT> {
+ public:
+ string pfx;
+ mutable string tmp;
+
+ cut_prefix_filterator() { }
+ cut_prefix_filterator(const IT& bi,const IT&ei,const string& pfx)
+ : opkele::util::basic_filterator<IT>(bi,ei), pfx(pfx) {
+ this->prepare();
+ }
+
+ bool is_interesting() const {
+ return pfx.length()==0 || !strncmp(this->it->c_str(),pfx.c_str(),pfx.length());
+ }
+
+ typename IT::reference operator*() const {
+ assert(!this->empty);
+ tmp = *this->it; tmp.erase(0,pfx.length());
+ return tmp; }
+ typename IT::pointer operator->() const {
+ assert(!this->empty);
+ return &this->operator*(); }
+};
+
+class kingate_openid_message_t : public opkele::basic_openid_message {
+ typedef join_iterator<kingate::cgi_gateway::params_t::const_iterator> jitterator;
+ typedef opkele::util::map_keys_iterator<
+ jitterator,
+ fields_iterator::value_type,
+ fields_iterator::reference,
+ fields_iterator::pointer> keys_iterator;
+ typedef cut_prefix_filterator<keys_iterator> pfilterator;
+ public:
+ const kingate::cgi_gateway& gw;
+
+ kingate_openid_message_t(const kingate::cgi_gateway& g) : gw(g) { }
+
+ bool has_field(const string& n) const {
+ return gw.has_param("openid."+n); }
+ const string& get_field(const string& n) const {
+ return gw.get_param("openid."+n); }
+
+ fields_iterator fields_begin() const {
+ return
+ pfilterator( keys_iterator(
+ jitterator()
+ .add_range( gw.get.begin(), gw.get.end() )
+ .add_range( gw.post.begin(), gw.post.end() ),
+ jitterator()
+ ), keys_iterator(), "openid." );
+ }
+ fields_iterator fields_end() const {
+ return pfilterator();
+ }
+};