summaryrefslogtreecommitdiffabout
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) (unidiff)
tree142bad9602519b9b92200fc7ee6e4f09ad7099bd
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 (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
@@ -22,4 +22,5 @@ using namespace opkele;
22 22
23#include "sqlite.h" 23#include "sqlite.h"
24#include "kingate_openid_message.h"
24 25
25#undef DUMB_RP 26#undef DUMB_RP
@@ -31,113 +32,4 @@ using namespace opkele;
31#endif 32#endif
32 33
33template<typename IT>
34class join_iterator : public iterator<
35 input_iterator_tag,typename IT::value_type,
36 void,typename IT::pointer,typename IT::reference> {
37 public:
38 typedef pair<IT,IT> range_t;
39 typedef list<range_t> ranges_t;
40 ranges_t ranges;
41
42 join_iterator() { }
43
44 bool cleanup() {
45 bool rv = false;
46 while(!(ranges.empty() || ranges.front().first!=ranges.front().second)) {
47 ranges.pop_front(); rv = true;
48 }
49 return rv;
50 }
51
52 join_iterator<IT>& add_range(const IT& b,const IT& e) {
53 ranges.push_back(typename ranges_t::value_type(b,e));
54 cleanup();
55 return *this;
56 }
57
58 bool operator==(const join_iterator<IT>& x) const {
59 return ranges==x.ranges; }
60 bool operator!=(const join_iterator<IT>& x) const {
61 return ranges!=x.ranges; }
62
63 typename IT::reference operator*() const {
64 assert(!ranges.empty());
65 assert(ranges.front().first!=ranges.front().second);
66 return *ranges.front().first; }
67 typename IT::pointer operator->() const {
68 assert(!ranges.empty());
69 assert(ranges.front().first!=ranges.front().second);
70 return ranges.front().first.operator->(); }
71
72 join_iterator<IT>& operator++() {
73 cleanup();
74 if(ranges.empty()) return *this;
75 do {
76 ++ranges.front().first;
77 }while(cleanup() && !ranges.empty());
78 return *this;
79 }
80 join_iterator<IT> operator++(int) {
81 join_iterator<IT> rv(*this);
82 ++(*this); return rv; }
83};
84
85template<typename IT>
86class cut_prefix_filterator : public opkele::util::basic_filterator<IT> {
87 public:
88 string pfx;
89 mutable string tmp;
90
91 cut_prefix_filterator() { }
92 cut_prefix_filterator(const IT& bi,const IT&ei,const string& pfx)
93 : opkele::util::basic_filterator<IT>(bi,ei), pfx(pfx) {
94 this->prepare();
95 }
96
97 bool is_interesting() const {
98 return pfx.length()==0 || !strncmp(this->it->c_str(),pfx.c_str(),pfx.length());
99 }
100
101 typename IT::reference operator*() const {
102 assert(!this->empty);
103 tmp = *this->it; tmp.erase(0,pfx.length());
104 return tmp; }
105 typename IT::pointer operator->() const {
106 assert(!this->empty);
107 return &this->operator*(); }
108};
109
110class kingate_openid_message_t : public opkele::basic_openid_message {
111 typedef join_iterator<kingate::cgi_gateway::params_t::const_iterator> jitterator;
112 typedef opkele::util::map_keys_iterator<
113 jitterator,
114 fields_iterator::value_type,
115 fields_iterator::reference,
116 fields_iterator::pointer> keys_iterator;
117 typedef cut_prefix_filterator<keys_iterator> pfilterator;
118 public:
119 const kingate::cgi_gateway& gw;
120
121 kingate_openid_message_t(const kingate::cgi_gateway& g) : gw(g) { }
122
123 bool has_field(const string& n) const {
124 return gw.has_param("openid."+n); }
125 const string& get_field(const string& n) const {
126 return gw.get_param("openid."+n); }
127
128 fields_iterator fields_begin() const {
129 return
130 pfilterator( keys_iterator(
131 jitterator()
132 .add_range( gw.get.begin(), gw.get.end() )
133 .add_range( gw.post.begin(), gw.post.end() ),
134 jitterator()
135 ), keys_iterator(), "openid." );
136 }
137 fields_iterator fields_end() const {
138 return pfilterator();
139 }
140};
141
142class rpdb_t : public sqlite3_t { 34class rpdb_t : public sqlite3_t {
143 public: 35 public:
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 @@
1template<typename IT>
2class join_iterator : public iterator<
3 input_iterator_tag,typename IT::value_type,
4 void,typename IT::pointer,typename IT::reference> {
5 public:
6 typedef pair<IT,IT> range_t;
7 typedef list<range_t> ranges_t;
8 ranges_t ranges;
9
10 join_iterator() { }
11
12 bool cleanup() {
13 bool rv = false;
14 while(!(ranges.empty() || ranges.front().first!=ranges.front().second)) {
15 ranges.pop_front(); rv = true;
16 }
17 return rv;
18 }
19
20 join_iterator<IT>& add_range(const IT& b,const IT& e) {
21 ranges.push_back(typename ranges_t::value_type(b,e));
22 cleanup();
23 return *this;
24 }
25
26 bool operator==(const join_iterator<IT>& x) const {
27 return ranges==x.ranges; }
28 bool operator!=(const join_iterator<IT>& x) const {
29 return ranges!=x.ranges; }
30
31 typename IT::reference operator*() const {
32 assert(!ranges.empty());
33 assert(ranges.front().first!=ranges.front().second);
34 return *ranges.front().first; }
35 typename IT::pointer operator->() const {
36 assert(!ranges.empty());
37 assert(ranges.front().first!=ranges.front().second);
38 return ranges.front().first.operator->(); }
39
40 join_iterator<IT>& operator++() {
41 cleanup();
42 if(ranges.empty()) return *this;
43 do {
44 ++ranges.front().first;
45 }while(cleanup() && !ranges.empty());
46 return *this;
47 }
48 join_iterator<IT> operator++(int) {
49 join_iterator<IT> rv(*this);
50 ++(*this); return rv; }
51};
52
53template<typename IT>
54class cut_prefix_filterator : public opkele::util::basic_filterator<IT> {
55 public:
56 string pfx;
57 mutable string tmp;
58
59 cut_prefix_filterator() { }
60 cut_prefix_filterator(const IT& bi,const IT&ei,const string& pfx)
61 : opkele::util::basic_filterator<IT>(bi,ei), pfx(pfx) {
62 this->prepare();
63 }
64
65 bool is_interesting() const {
66 return pfx.length()==0 || !strncmp(this->it->c_str(),pfx.c_str(),pfx.length());
67 }
68
69 typename IT::reference operator*() const {
70 assert(!this->empty);
71 tmp = *this->it; tmp.erase(0,pfx.length());
72 return tmp; }
73 typename IT::pointer operator->() const {
74 assert(!this->empty);
75 return &this->operator*(); }
76};
77
78class kingate_openid_message_t : public opkele::basic_openid_message {
79 typedef join_iterator<kingate::cgi_gateway::params_t::const_iterator> jitterator;
80 typedef opkele::util::map_keys_iterator<
81 jitterator,
82 fields_iterator::value_type,
83 fields_iterator::reference,
84 fields_iterator::pointer> keys_iterator;
85 typedef cut_prefix_filterator<keys_iterator> pfilterator;
86 public:
87 const kingate::cgi_gateway& gw;
88
89 kingate_openid_message_t(const kingate::cgi_gateway& g) : gw(g) { }
90
91 bool has_field(const string& n) const {
92 return gw.has_param("openid."+n); }
93 const string& get_field(const string& n) const {
94 return gw.get_param("openid."+n); }
95
96 fields_iterator fields_begin() const {
97 return
98 pfilterator( keys_iterator(
99 jitterator()
100 .add_range( gw.get.begin(), gw.get.end() )
101 .add_range( gw.post.begin(), gw.post.end() ),
102 jitterator()
103 ), keys_iterator(), "openid." );
104 }
105 fields_iterator fields_end() const {
106 return pfilterator();
107 }
108};