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.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
@@ -10,14 +10,16 @@
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
@@ -37,16 +39,16 @@ namespace opkele {
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
@@ -105,9 +107,9 @@ namespace opkele {
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
@@ -158,6 +160,14 @@ namespace opkele {
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 /**
@@ -167,6 +177,70 @@ namespace opkele {
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 */