summaryrefslogtreecommitdiffabout
path: root/include/opkele/types.h
Unidiff
Diffstat (limited to 'include/opkele/types.h') (more/less context) (ignore whitespace changes)
-rw-r--r--include/opkele/types.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/include/opkele/types.h b/include/opkele/types.h
index 5d39a5c..6ab51ef 100644
--- a/include/opkele/types.h
+++ b/include/opkele/types.h
@@ -1,56 +1,57 @@
1#ifndef __OPKELE_TYPES_H 1#ifndef __OPKELE_TYPES_H
2#define __OPKELE_TYPES_H 2#define __OPKELE_TYPES_H
3 3
4/** 4/**
5 * @file 5 * @file
6 * @brief various types declarations 6 * @brief various types declarations
7 */ 7 */
8 8
9#include <cstring>
9#include <ostream> 10#include <ostream>
10#include <vector> 11#include <vector>
11#include <string> 12#include <string>
12#include <map> 13#include <map>
13#include <set> 14#include <set>
14#include <list> 15#include <list>
15#include <opkele/iterator.h> 16#include <opkele/iterator.h>
16#include <opkele/tr1-mem.h> 17#include <opkele/tr1-mem.h>
17 18
18namespace opkele { 19namespace opkele {
19 using std::vector; 20 using std::vector;
20 using std::string; 21 using std::string;
21 using std::map; 22 using std::map;
22 using std::ostream; 23 using std::ostream;
23 using std::multimap; 24 using std::multimap;
24 using std::set; 25 using std::set;
25 using std::list; 26 using std::list;
26 using std::iterator; 27 using std::iterator;
27 using std::forward_iterator_tag; 28 using std::forward_iterator_tag;
28 29
29 /** 30 /**
30 * the OpenID operation mode 31 * the OpenID operation mode
31 */ 32 */
32 typedef enum _mode_t { 33 typedef enum _mode_t {
33 mode_unknown = 0, 34 mode_unknown = 0,
34 mode_associate, 35 mode_associate,
35 mode_checkid_immediate, 36 mode_checkid_immediate,
36 mode_checkid_setup, 37 mode_checkid_setup,
37 mode_check_association 38 mode_check_association
38 } mode_t; 39 } mode_t;
39 40
40 /** 41 /**
41 * the association secret container 42 * the association secret container
42 */ 43 */
43 class secret_t : public vector<unsigned char> { 44 class secret_t : public vector<unsigned char> {
44 public: 45 public:
45 46
46 /** 47 /**
47 * xor the secret and hmac together and encode, using base64 48 * xor the secret and hmac together and encode, using base64
48 * @param key_d pointer to the message digest 49 * @param key_d pointer to the message digest
49 * @param rv reference to the return value 50 * @param rv reference to the return value
50 */ 51 */
51 void enxor_to_base64(const unsigned char *key_d,string& rv) const; 52 void enxor_to_base64(const unsigned char *key_d,string& rv) const;
52 /** 53 /**
53 * decode base64-encoded secret and xor it with the message digest 54 * decode base64-encoded secret and xor it with the message digest
54 * @param key_d pointer to the message digest 55 * @param key_d pointer to the message digest
55 * @param b64 base64-encoded secret value 56 * @param b64 base64-encoded secret value
56 */ 57 */
@@ -161,51 +162,68 @@ namespace opkele {
161 openid_message_t(const basic_openid_message& x) 162 openid_message_t(const basic_openid_message& x)
162 : basic_openid_message(x) { } 163 : basic_openid_message(x) { }
163 164
164 void copy_to(basic_openid_message& x) const; 165 void copy_to(basic_openid_message& x) const;
165 166
166 bool has_field(const string& n) const; 167 bool has_field(const string& n) const;
167 const string& get_field(const string& n) const; 168 const string& get_field(const string& n) const;
168 virtual fields_iterator fields_begin() const; 169 virtual fields_iterator fields_begin() const;
169 virtual fields_iterator fields_end() const; 170 virtual fields_iterator fields_end() const;
170 171
171 void reset_fields(); 172 void reset_fields();
172 void set_field(const string& n,const string& v); 173 void set_field(const string& n,const string& v);
173 void reset_field(const string& n); 174 void reset_field(const string& n);
174 }; 175 };
175 176
176 /** 177 /**
177 * request/response parameters map 178 * request/response parameters map
178 */ 179 */
179 class params_t : public openid_message_t { 180 class params_t : public openid_message_t {
180 public: 181 public:
181 182
182 /** 183 /**
183 * check whether the parameter is present. 184 * check whether the parameter is present.
184 * @param n the parameter name 185 * @param n the parameter name
185 * @return true if yes 186 * @return true if yes
186 */ 187 */
187 bool has_param(const string& n) const { 188 bool has_param(const string& n) const {
188 return has_field(n); } 189 return has_field(n); }
189 /** 190 /**
190 * retrieve the parameter (const version) 191 * retrieve the parameter (const version)
191 * @param n the parameter name 192 * @param n the parameter name
192 * @return the parameter value 193 * @return the parameter value
193 * @throw failed_lookup if there is no such parameter 194 * @throw failed_lookup if there is no such parameter
194 */ 195 */
195 const string& get_param(const string& n) const { 196 const string& get_param(const string& n) const {
196 return get_field(n); } 197 return get_field(n); }
197 198
198 /** 199 /**
199 * parse the OpenID key/value data. 200 * parse the OpenID key/value data.
200 * @param kv the OpenID key/value data 201 * @param kv the OpenID key/value data
201 */ 202 */
202 void parse_keyvalues(const string& kv) { 203 void parse_keyvalues(const string& kv) {
203 from_keyvalues(kv); } 204 from_keyvalues(kv); }
204 205
205 string append_query(const string& url,const char *prefix="openid.") const; 206 string append_query(const string& url,const char *prefix="openid.") const;
206 207
207 }; 208 };
208 209
210 struct openid_endpoint_t {
211 string uri;
212 string claimed_id;
213 string local_id;
214
215 openid_endpoint_t() { }
216 openid_endpoint_t(const string& u,const string& cid,const string& lid)
217 : uri(u), claimed_id(cid), local_id(lid) { }
218
219 bool operator==(const openid_endpoint_t& x) const {
220 return uri==x.uri && local_id==x.local_id; }
221 bool operator<(const openid_endpoint_t& x) const {
222 int c;
223 return (c=strcmp(uri.c_str(),x.uri.c_str()))
224 ? (c<0) : (strcmp(local_id.c_str(),x.local_id.c_str())<0); }
225 };
226
209} 227}
210 228
211#endif /* __OPKELE_TYPES_H */ 229#endif /* __OPKELE_TYPES_H */