summaryrefslogtreecommitdiffabout
path: root/include/opkele/types.h
Unidiff
Diffstat (limited to 'include/opkele/types.h') (more/less context) (show whitespace changes)
-rw-r--r--include/opkele/types.h92
1 files changed, 83 insertions, 9 deletions
diff --git a/include/opkele/types.h b/include/opkele/types.h
index f732a1e..de44a5c 100644
--- a/include/opkele/types.h
+++ b/include/opkele/types.h
@@ -1,172 +1,246 @@
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 <ostream> 9#include <ostream>
10#include <vector> 10#include <vector>
11#include <string> 11#include <string>
12#include <map> 12#include <map>
13#include <memory> 13#include <set>
14#include <opkele/tr1-mem.h>
14 15
15namespace opkele { 16namespace opkele {
16 using std::vector; 17 using std::vector;
17 using std::string; 18 using std::string;
18 using std::map; 19 using std::map;
19 using std::ostream; 20 using std::ostream;
20 using std::auto_ptr; 21 using std::multimap;
22 using std::set;
21 23
22 /** 24 /**
23 * the OpenID operation mode 25 * the OpenID operation mode
24 */ 26 */
25 typedef enum _mode_t { 27 typedef enum _mode_t {
26 mode_associate, 28 mode_associate,
27 mode_checkid_immediate, 29 mode_checkid_immediate,
28 mode_checkid_setup, 30 mode_checkid_setup,
29 mode_check_association 31 mode_check_association
30 } mode_t; 32 } mode_t;
31 33
32 /** 34 /**
33 * the association secret container 35 * the association secret container
34 */ 36 */
35 class secret_t : public vector<unsigned char> { 37 class secret_t : public vector<unsigned char> {
36 public: 38 public:
37 39
38 /** 40 /**
39 * xor the secret and hmac together and encode, using base64 41 * xor the secret and hmac together and encode, using base64
40 * @param key_sha1 pointer to the sha1 digest 42 * @param key_d pointer to the message digest
41 * @param rv reference to the return value 43 * @param rv reference to the return value
42 */ 44 */
43 void enxor_to_base64(const unsigned char *key_sha1,string& rv) const; 45 void enxor_to_base64(const unsigned char *key_d,string& rv) const;
44 /** 46 /**
45 * decode base64-encoded secret and xor it with the sha1 digest 47 * decode base64-encoded secret and xor it with the message digest
46 * @param key_sha1 pointer to the message digest 48 * @param key_d pointer to the message digest
47 * @param b64 base64-encoded secret value 49 * @param b64 base64-encoded secret value
48 */ 50 */
49 void enxor_from_base64(const unsigned char *key_sha1,const string& b64); 51 void enxor_from_base64(const unsigned char *key_d,const string& b64);
50 /** 52 /**
51 * plainly encode to base64 representation 53 * plainly encode to base64 representation
52 * @param rv reference to the return value 54 * @param rv reference to the return value
53 */ 55 */
54 void to_base64(string& rv) const; 56 void to_base64(string& rv) const;
55 /** 57 /**
56 * decode cleartext secret from base64 58 * decode cleartext secret from base64
57 * @param b64 base64-encoded representation of the secret value 59 * @param b64 base64-encoded representation of the secret value
58 */ 60 */
59 void from_base64(const string& b64); 61 void from_base64(const string& b64);
60 }; 62 };
61 63
62 /** 64 /**
63 * Interface to the association. 65 * Interface to the association.
64 */ 66 */
65 class association_t { 67 class association_t {
66 public: 68 public:
67 69
68 virtual ~association_t() { } 70 virtual ~association_t() { }
69 71
70 /** 72 /**
71 * retrieve the server with which association was established. 73 * retrieve the server with which association was established.
72 * @return server name 74 * @return server name
73 */ 75 */
74 virtual string server() const = 0; 76 virtual string server() const = 0;
75 /** 77 /**
76 * retrieve the association handle. 78 * retrieve the association handle.
77 * @return handle 79 * @return handle
78 */ 80 */
79 virtual string handle() const = 0; 81 virtual string handle() const = 0;
80 /** 82 /**
81 * retrieve the association type. 83 * retrieve the association type.
82 * @return association type 84 * @return association type
83 */ 85 */
84 virtual string assoc_type() const = 0; 86 virtual string assoc_type() const = 0;
85 /** 87 /**
86 * retrieve the association secret. 88 * retrieve the association secret.
87 * @return association secret 89 * @return association secret
88 */ 90 */
89 virtual secret_t secret() const = 0; 91 virtual secret_t secret() const = 0;
90 /** 92 /**
91 * retrieve the number of seconds the association expires in. 93 * retrieve the number of seconds the association expires in.
92 * @return seconds till expiration 94 * @return seconds till expiration
93 */ 95 */
94 virtual int expires_in() const = 0; 96 virtual int expires_in() const = 0;
95 /** 97 /**
96 * check whether the association is stateless. 98 * check whether the association is stateless.
97 * @return true if stateless 99 * @return true if stateless
98 */ 100 */
99 virtual bool stateless() const = 0; 101 virtual bool stateless() const = 0;
100 /** 102 /**
101 * check whether the association is expired. 103 * check whether the association is expired.
102 * @return true if expired 104 * @return true if expired
103 */ 105 */
104 virtual bool is_expired() const = 0; 106 virtual bool is_expired() const = 0;
105 }; 107 };
106 108
107 /** 109 /**
108 * the auto_ptr<> for association_t object type 110 * the shared_ptr<> for association_t object type
109 */ 111 */
110 typedef auto_ptr<association_t> assoc_t; 112 typedef tr1mem::shared_ptr<association_t> assoc_t;
111 113
112 /** 114 /**
113 * request/response parameters map 115 * request/response parameters map
114 */ 116 */
115 class params_t : public map<string,string> { 117 class params_t : public map<string,string> {
116 public: 118 public:
117 119
118 /** 120 /**
119 * check whether the parameter is present. 121 * check whether the parameter is present.
120 * @param n the parameter name 122 * @param n the parameter name
121 * @return true if yes 123 * @return true if yes
122 */ 124 */
123 bool has_param(const string& n) const; 125 bool has_param(const string& n) const;
124 /** 126 /**
125 * retrieve the parameter (const version) 127 * retrieve the parameter (const version)
126 * @param n the parameter name 128 * @param n the parameter name
127 * @return the parameter value 129 * @return the parameter value
128 * @throw failed_lookup if there is no such parameter 130 * @throw failed_lookup if there is no such parameter
129 */ 131 */
130 const string& get_param(const string& n) const; 132 const string& get_param(const string& n) const;
131 /** 133 /**
132 * retrieve the parameter. 134 * retrieve the parameter.
133 * @param n the parameter name 135 * @param n the parameter name
134 * @return the parameter value 136 * @return the parameter value
135 * @throw failed_lookup if there is no such parameter 137 * @throw failed_lookup if there is no such parameter
136 */ 138 */
137 string& get_param(const string& n); 139 string& get_param(const string& n);
138 140
139 /** 141 /**
140 * parse the OpenID key/value data. 142 * parse the OpenID key/value data.
141 * @param kv the OpenID key/value data 143 * @param kv the OpenID key/value data
142 */ 144 */
143 void parse_keyvalues(const string& kv); 145 void parse_keyvalues(const string& kv);
144 /** 146 /**
145 * sign the fields. 147 * sign the fields.
146 * @param secret the secret used for signing 148 * @param secret the secret used for signing
147 * @param sig reference to the string, containing base64-encoded 149 * @param sig reference to the string, containing base64-encoded
148 * result 150 * result
149 * @param slist the comma-separated list of fields to sign 151 * @param slist the comma-separated list of fields to sign
150 * @param prefix the string to prepend to parameter names 152 * @param prefix the string to prepend to parameter names
151 */ 153 */
152 void sign(secret_t secret,string& sig,const string& slist,const char *prefix=0) const; 154 void sign(secret_t secret,string& sig,const string& slist,const char *prefix=0) const;
153 155
154 /** 156 /**
155 * append parameters to the URL as a GET-request parameters. 157 * append parameters to the URL as a GET-request parameters.
156 * @param url the base URL 158 * @param url the base URL
157 * @param prefix the string to prepend to parameter names 159 * @param prefix the string to prepend to parameter names
158 * @return the ready-to-use location 160 * @return the ready-to-use location
159 */ 161 */
160 string append_query(const string& url,const char *prefix = "openid.") const; 162 string append_query(const string& url,const char *prefix = "openid.") const;
163
164 /**
165 * make up a query string suitable for use in GET and POST
166 * requests.
167 * @param prefix string to prened to parameter names
168 * @return query string
169 */
170 string query_string(const char *prefix = "openid.") const;
161 }; 171 };
162 172
163 /** 173 /**
164 * dump the key/value pairs for the parameters to the stream. 174 * dump the key/value pairs for the parameters to the stream.
165 * @param o output stream 175 * @param o output stream
166 * @param p the parameters 176 * @param p the parameters
167 */ 177 */
168 ostream& operator << (ostream& o,const params_t& p); 178 ostream& operator << (ostream& o,const params_t& p);
169 179
180 namespace xrd {
181
182 struct priority_compare {
183 inline bool operator()(long a,long b) const {
184 return (a<0) ? false : (b<0) ? true : (a<b);
185 }
186 };
187
188 template <typename _DT>
189 class priority_map : public multimap<long,_DT,priority_compare> {
190 typedef multimap<long,_DT,priority_compare> map_type;
191 public:
192
193 inline _DT& add(long priority,const _DT& d) {
194 return insert(typename map_type::value_type(priority,d))->second;
195 }
196 };
197
198 typedef priority_map<string> canonical_ids_t;
199 typedef priority_map<string> local_ids_t;
200 typedef set<string> types_t;
201 typedef priority_map<string> uris_t;
202
203 class service_t {
204 public:
205 types_t types;
206 uris_t uris;
207 local_ids_t local_ids;
208 string provider_id;
209
210 void clear() {
211 types.clear();
212 uris.clear(); local_ids.clear();
213 provider_id.clear();
214 }
215 };
216 typedef priority_map<service_t> services_t;
217
218 class XRD_t {
219 public:
220 time_t expires;
221
222 canonical_ids_t canonical_ids;
223 local_ids_t local_ids;
224 services_t services;
225 string provider_id;
226
227 void clear() {
228 expires = 0;
229 canonical_ids.clear(); local_ids.clear();
230 services.clear();
231 provider_id.clear();
232 }
233 bool empty() const {
234 return
235 canonical_ids.empty()
236 && local_ids.empty()
237 && services.empty();
238 }
239
240 };
241
242 }
243
170} 244}
171 245
172#endif /* __OPKELE_TYPES_H */ 246#endif /* __OPKELE_TYPES_H */