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 /include/opkele | |
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 |
1 files changed, 28 insertions, 14 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 | |||
@@ -97,96 +97,110 @@ namespace opkele { | |||
97 | */ | 97 | */ |
98 | virtual secret_t secret() const = 0; | 98 | virtual secret_t secret() const = 0; |
99 | /** | 99 | /** |
100 | * retrieve the number of seconds the association expires in. | 100 | * retrieve the number of seconds the association expires in. |
101 | * @return seconds till expiration | 101 | * @return seconds till expiration |
102 | */ | 102 | */ |
103 | virtual int expires_in() const = 0; | 103 | virtual int expires_in() const = 0; |
104 | /** | 104 | /** |
105 | * check whether the association is stateless. | 105 | * check whether the association is stateless. |
106 | * @return true if stateless | 106 | * @return true if stateless |
107 | */ | 107 | */ |
108 | virtual bool stateless() const = 0; | 108 | virtual bool stateless() const = 0; |
109 | /** | 109 | /** |
110 | * check whether the association is expired. | 110 | * check whether the association is expired. |
111 | * @return true if expired | 111 | * @return true if expired |
112 | */ | 112 | */ |
113 | virtual bool is_expired() const = 0; | 113 | virtual bool is_expired() const = 0; |
114 | }; | 114 | }; |
115 | 115 | ||
116 | /** | 116 | /** |
117 | * the shared_ptr<> for association_t object type | 117 | * the shared_ptr<> for association_t object type |
118 | */ | 118 | */ |
119 | typedef tr1mem::shared_ptr<association_t> assoc_t; | 119 | typedef tr1mem::shared_ptr<association_t> assoc_t; |
120 | 120 | ||
121 | class basic_openid_message { | 121 | class basic_message { |
122 | public: | 122 | public: |
123 | typedef list<string> fields_t; | 123 | typedef list<string> fields_t; |
124 | typedef util::forward_iterator_proxy< | 124 | typedef util::forward_iterator_proxy< |
125 | string,const string&,const string* | 125 | string,const string&,const string* |
126 | > fields_iterator; | 126 | > fields_iterator; |
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 | ||
134 | virtual bool has_field(const string& n) const = 0; | 134 | virtual bool has_field(const string& n) const = 0; |
135 | virtual const string& get_field(const string& n) const = 0; | 135 | virtual const string& get_field(const string& n) const = 0; |
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; |
141 | virtual fields_iterator fields_end() const = 0; | 138 | virtual fields_iterator fields_end() const = 0; |
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 | ||
147 | virtual void reset_fields(); | 143 | virtual void reset_fields(); |
148 | virtual void set_field(const string& n,const string& v); | 144 | virtual void set_field(const string& n,const string& v); |
149 | virtual void reset_field(const string& n); | 145 | virtual void reset_field(const string& n); |
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); |
152 | virtual void to_keyvalues(ostream& o) const; | 168 | virtual void to_keyvalues(ostream& o) const; |
153 | 169 | ||
154 | virtual void to_htmlhiddens(ostream& o,const char* pfx=0) const; | 170 | virtual void to_htmlhiddens(ostream& o,const char* pfx=0) const; |
155 | 171 | ||
156 | void add_to_signed(const string& fields); | 172 | void add_to_signed(const string& fields); |
157 | string find_ns(const string& uri,const char *pfx) const; | 173 | string find_ns(const string& uri,const char *pfx) const; |
158 | string allocate_ns(const string& uri,const char *pfx); | 174 | string allocate_ns(const string& uri,const char *pfx); |
159 | }; | 175 | }; |
160 | 176 | ||
161 | class openid_message_t : public basic_openid_message, public map<string,string> { | 177 | class openid_message_t : public basic_openid_message, public map<string,string> { |
162 | public: | 178 | public: |
163 | openid_message_t() { } | 179 | openid_message_t() { } |
164 | openid_message_t(const basic_openid_message& x) | 180 | openid_message_t(const basic_openid_message& x) |
165 | : basic_openid_message(x) { } | 181 | : basic_openid_message(x) { } |
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; |
170 | const string& get_field(const string& n) const; | 184 | const string& get_field(const string& n) const; |
171 | virtual fields_iterator fields_begin() const; | 185 | virtual fields_iterator fields_begin() const; |
172 | virtual fields_iterator fields_end() const; | 186 | virtual fields_iterator fields_end() const; |
173 | 187 | ||
174 | void reset_fields(); | 188 | void reset_fields(); |
175 | void set_field(const string& n,const string& v); | 189 | void set_field(const string& n,const string& v); |
176 | void reset_field(const string& n); | 190 | void reset_field(const string& n); |
177 | }; | 191 | }; |
178 | 192 | ||
179 | /** | 193 | /** |
180 | * request/response parameters map | 194 | * request/response parameters map |
181 | */ | 195 | */ |
182 | class params_t : public openid_message_t { | 196 | class params_t : public openid_message_t { |
183 | public: | 197 | public: |
184 | 198 | ||
185 | /** | 199 | /** |
186 | * check whether the parameter is present. | 200 | * check whether the parameter is present. |
187 | * @param n the parameter name | 201 | * @param n the parameter name |
188 | * @return true if yes | 202 | * @return true if yes |
189 | */ | 203 | */ |
190 | bool has_param(const string& n) const { | 204 | bool has_param(const string& n) const { |
191 | return has_field(n); } | 205 | return has_field(n); } |
192 | /** | 206 | /** |