author | Michael Krelin <hacker@klever.net> | 2008-03-03 15:57:15 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2008-03-03 15:57:15 (UTC) |
commit | c28479399ef0fedeb6bf14ec665bb4c427654356 (patch) (unidiff) | |
tree | ff1dfe84a54f717772bdb6233a5cbfedb57788d1 | |
parent | 0182b9dee269f1a8f3fc0794bfdf4a143fa1b5be (diff) | |
download | libopkele-c28479399ef0fedeb6bf14ec665bb4c427654356.zip libopkele-c28479399ef0fedeb6bf14ec665bb4c427654356.tar.gz libopkele-c28479399ef0fedeb6bf14ec665bb4c427654356.tar.bz2 |
introduced base_message class as a base for basic_openid_message
Signed-off-by: Michael Krelin <hacker@klever.net>
-rw-r--r-- | include/opkele/types.h | 42 | ||||
-rw-r--r-- | lib/Makefile.am | 2 | ||||
-rw-r--r-- | lib/message.cc (renamed from lib/openid_message.cc) | 94 |
3 files changed, 73 insertions, 65 deletions
diff --git a/include/opkele/types.h b/include/opkele/types.h index ffb9afb..64f165c 100644 --- a/include/opkele/types.h +++ b/include/opkele/types.h | |||
@@ -120,3 +120,3 @@ namespace opkele { | |||
120 | 120 | ||
121 | class basic_openid_message { | 121 | class basic_message { |
122 | public: | 122 | public: |
@@ -127,7 +127,7 @@ namespace opkele { | |||
127 | 127 | ||
128 | basic_openid_message() { } | 128 | basic_message() { } |
129 | virtual ~basic_openid_message() { } | 129 | virtual ~basic_message() { } |
130 | basic_openid_message(const basic_openid_message& x); | 130 | basic_message(const basic_message& x); |
131 | void copy_to(basic_openid_message& x) const; | 131 | void copy_to(basic_message& x) const; |
132 | void append_to(basic_openid_message& x) const; | 132 | void append_to(basic_message& x) const; |
133 | 133 | ||
@@ -136,5 +136,2 @@ namespace opkele { | |||
136 | 136 | ||
137 | virtual bool has_ns(const string& uri) const; | ||
138 | virtual string get_ns(const string& uri) const; | ||
139 | |||
140 | virtual fields_iterator fields_begin() const = 0; | 137 | virtual fields_iterator fields_begin() const = 0; |
@@ -142,5 +139,4 @@ namespace opkele { | |||
142 | 139 | ||
143 | virtual string append_query(const string& url,const char *pfx="openid.") const; | 140 | virtual string append_query(const string& url,const char *pfx=0) const; |
144 | virtual string query_string(const char *pfx="openid.") const; | 141 | virtual string query_string(const char *pfx=0) const; |
145 | |||
146 | 142 | ||
@@ -150,2 +146,22 @@ namespace opkele { | |||
150 | 146 | ||
147 | }; | ||
148 | |||
149 | class basic_openid_message : public basic_message { | ||
150 | public: | ||
151 | typedef list<string> fields_t; | ||
152 | typedef util::forward_iterator_proxy< | ||
153 | string,const string&,const string* | ||
154 | > fields_iterator; | ||
155 | |||
156 | basic_openid_message() { } | ||
157 | basic_openid_message(const basic_openid_message& x); | ||
158 | |||
159 | virtual bool has_ns(const string& uri) const; | ||
160 | virtual string get_ns(const string& uri) const; | ||
161 | |||
162 | virtual string append_query(const string& url,const char *pfx="openid.") const { | ||
163 | return basic_message::append_query(url,pfx); } | ||
164 | virtual string query_string(const char *pfx="openid.") const { | ||
165 | return basic_message::query_string(pfx); } | ||
166 | |||
151 | virtual void from_keyvalues(const string& kv); | 167 | virtual void from_keyvalues(const string& kv); |
@@ -166,4 +182,2 @@ namespace opkele { | |||
166 | 182 | ||
167 | void copy_to(basic_openid_message& x) const; | ||
168 | |||
169 | bool has_field(const string& n) const; | 183 | bool has_field(const string& n) const; |
diff --git a/lib/Makefile.am b/lib/Makefile.am index e8bfbf5..9b25b42 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am | |||
@@ -30,3 +30,3 @@ libopkele_la_SOURCES = \ | |||
30 | basic_rp.cc prequeue_rp.cc \ | 30 | basic_rp.cc prequeue_rp.cc \ |
31 | openid_message.cc \ | 31 | message.cc \ |
32 | basic_op.cc verify_op.cc | 32 | basic_op.cc verify_op.cc |
diff --git a/lib/openid_message.cc b/lib/message.cc index e244f43..78f20f4 100644 --- a/lib/openid_message.cc +++ b/lib/message.cc | |||
@@ -14,6 +14,6 @@ namespace opkele { | |||
14 | public: | 14 | public: |
15 | const basic_openid_message& from; | 15 | const basic_message& from; |
16 | basic_openid_message& to; | 16 | basic_message& to; |
17 | 17 | ||
18 | __om_copier(basic_openid_message& t,const basic_openid_message& f) | 18 | __om_copier(basic_message& t,const basic_message& f) |
19 | : from(f), to(t) { } | 19 | : from(f), to(t) { } |
@@ -24,6 +24,6 @@ namespace opkele { | |||
24 | 24 | ||
25 | basic_openid_message::basic_openid_message(const basic_openid_message& x) { | 25 | basic_message::basic_message(const basic_message& x) { |
26 | x.copy_to(*this); | 26 | x.copy_to(*this); |
27 | } | 27 | } |
28 | void basic_openid_message::copy_to(basic_openid_message& x) const { | 28 | void basic_message::copy_to(basic_message& x) const { |
29 | x.reset_fields(); | 29 | x.reset_fields(); |
@@ -32,3 +32,3 @@ namespace opkele { | |||
32 | } | 32 | } |
33 | void basic_openid_message::append_to(basic_openid_message& x) const { | 33 | void basic_message::append_to(basic_message& x) const { |
34 | for_each(fields_begin(),fields_end(), | 34 | for_each(fields_begin(),fields_end(), |
@@ -37,35 +37,5 @@ namespace opkele { | |||
37 | 37 | ||
38 | struct __om_ns_finder : public unary_function<const string&,bool> { | ||
39 | public: | ||
40 | const basic_openid_message& om; | ||
41 | const string& uri; | ||
42 | |||
43 | __om_ns_finder(const basic_openid_message& m, | ||
44 | const string& u) : om(m), uri(u) { } | ||
45 | |||
46 | result_type operator()(argument_type f) { | ||
47 | return | ||
48 | (!strncmp(f.c_str(),"ns.",sizeof("ns.")-1)) | ||
49 | && om.get_field(f)==uri ; | ||
50 | } | ||
51 | }; | ||
52 | |||
53 | bool basic_openid_message::has_ns(const string& uri) const { | ||
54 | fields_iterator ei = fields_end(); | ||
55 | fields_iterator i = find_if(fields_begin(),fields_end(), | ||
56 | __om_ns_finder(*this,uri)); | ||
57 | return !(i==ei); | ||
58 | } | ||
59 | string basic_openid_message::get_ns(const string& uri) const { | ||
60 | fields_iterator ei = fields_end(); | ||
61 | fields_iterator i = find_if(fields_begin(),fields_end(), | ||
62 | __om_ns_finder(*this,uri)); | ||
63 | if(i==ei) | ||
64 | throw failed_lookup(OPKELE_CP_ string("failed to find namespace ")+uri); | ||
65 | return i->substr(3); | ||
66 | } | ||
67 | |||
68 | struct __om_query_builder : public unary_function<const string&,void> { | 38 | struct __om_query_builder : public unary_function<const string&,void> { |
69 | public: | 39 | public: |
70 | const basic_openid_message& om; | 40 | const basic_message& om; |
71 | bool first; | 41 | bool first; |
@@ -74,3 +44,3 @@ namespace opkele { | |||
74 | 44 | ||
75 | __om_query_builder(const char *p,string& r,const basic_openid_message& m) | 45 | __om_query_builder(const char *p,string& r,const basic_message& m) |
76 | : om(m), first(true), rv(r), pfx(p) { | 46 | : om(m), first(true), rv(r), pfx(p) { |
@@ -78,3 +48,3 @@ namespace opkele { | |||
78 | } | 48 | } |
79 | __om_query_builder(const char *p,string& r,const basic_openid_message& m,const string& u) | 49 | __om_query_builder(const char *p,string& r,const basic_message& m,const string& u) |
80 | : om(m), first(true), rv(r), pfx(p) { | 50 | : om(m), first(true), rv(r), pfx(p) { |
@@ -100,3 +70,3 @@ namespace opkele { | |||
100 | 70 | ||
101 | string basic_openid_message::append_query(const string& url,const char *pfx) const { | 71 | string basic_message::append_query(const string& url,const char *pfx) const { |
102 | string rv; | 72 | string rv; |
@@ -104,3 +74,3 @@ namespace opkele { | |||
104 | } | 74 | } |
105 | string basic_openid_message::query_string(const char *pfx) const { | 75 | string basic_message::query_string(const char *pfx) const { |
106 | string rv; | 76 | string rv; |
@@ -109,9 +79,9 @@ namespace opkele { | |||
109 | 79 | ||
110 | void basic_openid_message::reset_fields() { | 80 | void basic_message::reset_fields() { |
111 | throw not_implemented(OPKELE_CP_ "reset_fields() not implemented"); | 81 | throw not_implemented(OPKELE_CP_ "reset_fields() not implemented"); |
112 | } | 82 | } |
113 | void basic_openid_message::set_field(const string&,const string&) { | 83 | void basic_message::set_field(const string&,const string&) { |
114 | throw not_implemented(OPKELE_CP_ "set_field() not implemented"); | 84 | throw not_implemented(OPKELE_CP_ "set_field() not implemented"); |
115 | } | 85 | } |
116 | void basic_openid_message::reset_field(const string&) { | 86 | void basic_message::reset_field(const string&) { |
117 | throw not_implemented(OPKELE_CP_ "reset_field() not implemented"); | 87 | throw not_implemented(OPKELE_CP_ "reset_field() not implemented"); |
@@ -119,2 +89,32 @@ namespace opkele { | |||
119 | 89 | ||
90 | struct __om_ns_finder : public unary_function<const string&,bool> { | ||
91 | public: | ||
92 | const basic_openid_message& om; | ||
93 | const string& uri; | ||
94 | |||
95 | __om_ns_finder(const basic_openid_message& m, | ||
96 | const string& u) : om(m), uri(u) { } | ||
97 | |||
98 | result_type operator()(argument_type f) { | ||
99 | return | ||
100 | (!strncmp(f.c_str(),"ns.",sizeof("ns.")-1)) | ||
101 | && om.get_field(f)==uri ; | ||
102 | } | ||
103 | }; | ||
104 | |||
105 | bool basic_openid_message::has_ns(const string& uri) const { | ||
106 | fields_iterator ei = fields_end(); | ||
107 | fields_iterator i = find_if(fields_begin(),fields_end(), | ||
108 | __om_ns_finder(*this,uri)); | ||
109 | return !(i==ei); | ||
110 | } | ||
111 | string basic_openid_message::get_ns(const string& uri) const { | ||
112 | fields_iterator ei = fields_end(); | ||
113 | fields_iterator i = find_if(fields_begin(),fields_end(), | ||
114 | __om_ns_finder(*this,uri)); | ||
115 | if(i==ei) | ||
116 | throw failed_lookup(OPKELE_CP_ string("failed to find namespace ")+uri); | ||
117 | return i->substr(3); | ||
118 | } | ||
119 | |||
120 | void basic_openid_message::from_keyvalues(const string& kv) { | 120 | void basic_openid_message::from_keyvalues(const string& kv) { |
@@ -242,8 +242,2 @@ namespace opkele { | |||
242 | 242 | ||
243 | void openid_message_t::copy_to(basic_openid_message& x) const { | ||
244 | x.reset_fields(); | ||
245 | for(const_iterator i=begin();i!=end();++i) | ||
246 | x.set_field(i->first,i->second); | ||
247 | } | ||
248 | |||
249 | bool openid_message_t::has_field(const string& n) const { | 243 | bool openid_message_t::has_field(const string& n) const { |