summaryrefslogtreecommitdiffabout
path: root/include/opkele
Unidiff
Diffstat (limited to 'include/opkele') (more/less context) (ignore whitespace changes)
-rw-r--r--include/opkele/.gitignore1
-rw-r--r--include/opkele/consumer.h6
-rw-r--r--include/opkele/curl.h24
-rw-r--r--include/opkele/debug.h17
-rw-r--r--include/opkele/discovery.h40
-rw-r--r--include/opkele/exception.h95
-rw-r--r--include/opkele/expat.h91
-rw-r--r--include/opkele/server.h4
-rw-r--r--include/opkele/tidy.h73
-rw-r--r--include/opkele/tr1-mem.h.in10
-rw-r--r--include/opkele/types.h92
-rw-r--r--include/opkele/uris.h18
12 files changed, 450 insertions, 21 deletions
diff --git a/include/opkele/.gitignore b/include/opkele/.gitignore
index ffa24dc..dfc2d2c 100644
--- a/include/opkele/.gitignore
+++ b/include/opkele/.gitignore
@@ -1,2 +1,3 @@
1acconfig.h 1acconfig.h
2tr1-mem.h
2stamp-h2 3stamp-h2
diff --git a/include/opkele/consumer.h b/include/opkele/consumer.h
index c463787..3c1d318 100644
--- a/include/opkele/consumer.h
+++ b/include/opkele/consumer.h
@@ -22,25 +22,25 @@ namespace opkele {
22 class consumer_t { 22 class consumer_t {
23 public: 23 public:
24 24
25 virtual ~consumer_t() { } 25 virtual ~consumer_t() { }
26 26
27 /** 27 /**
28 * store association. The function should be overridden in the real 28 * store association. The function should be overridden in the real
29 * implementation to provide persistent associations store. 29 * implementation to provide persistent associations store.
30 * @param server the OpenID server 30 * @param server the OpenID server
31 * @param handle association handle 31 * @param handle association handle
32 * @param secret the secret associated with the server and handle 32 * @param secret the secret associated with the server and handle
33 * @param expires_in the number of seconds until the handle is expired 33 * @param expires_in the number of seconds until the handle is expired
34 * @return the auto_ptr<> for the newly allocated association_t object 34 * @return the assoc_t for the newly allocated association_t object
35 */ 35 */
36 virtual assoc_t store_assoc(const string& server,const string& handle,const secret_t& secret,int expires_in) = 0; 36 virtual assoc_t store_assoc(const string& server,const string& handle,const secret_t& secret,int expires_in) = 0;
37 /** 37 /**
38 * retrieve stored association. The function should be overridden 38 * retrieve stored association. The function should be overridden
39 * in the real implementation to provide persistent assocations 39 * in the real implementation to provide persistent assocations
40 * store. 40 * store.
41 * 41 *
42 * @note 42 * @note
43 * The user is responsible for handling associations expiry and 43 * The user is responsible for handling associations expiry and
44 * this function should never return an expired or invalidated 44 * this function should never return an expired or invalidated
45 * association. 45 * association.
46 * 46 *
@@ -64,45 +64,45 @@ namespace opkele {
64 * 64 *
65 * @note 65 * @note
66 * The user is responsible for handling associations and this 66 * The user is responsible for handling associations and this
67 * function should never return an expired or invalidated 67 * function should never return an expired or invalidated
68 * association. 68 * association.
69 * 69 *
70 * @note 70 * @note
71 * It may be a good idea to pre-expire associations shortly before 71 * It may be a good idea to pre-expire associations shortly before
72 * their time is really up to avoid association expiry in the 72 * their time is really up to avoid association expiry in the
73 * middle of negotiations. 73 * middle of negotiations.
74 * 74 *
75 * @param server the OpenID server 75 * @param server the OpenID server
76 * @return the auto_ptr<> for the newly allocated association_t object 76 * @return the assoc_t for the newly allocated association_t object
77 * @throw failed_lookup in case of absence of the handle 77 * @throw failed_lookup in case of absence of the handle
78 */ 78 */
79 virtual assoc_t find_assoc(const string& server); 79 virtual assoc_t find_assoc(const string& server);
80 80
81 /** 81 /**
82 * retrieve the metainformation contained in link tags from the 82 * retrieve the metainformation contained in link tags from the
83 * page pointed by url. the function may implement caching of the 83 * page pointed by url. the function may implement caching of the
84 * information. 84 * information.
85 * @param url url to harvest for link tags 85 * @param url url to harvest for link tags
86 * @param server reference to the string object where to put 86 * @param server reference to the string object where to put
87 * openid.server value 87 * openid.server value
88 * @param delegate reference to the string object where to put the 88 * @param delegate reference to the string object where to put the
89 * openid.delegate value (if any) 89 * openid.delegate value (if any)
90 */ 90 */
91 virtual void retrieve_links(const string& url,string& server,string& delegate); 91 virtual void retrieve_links(const string& url,string& server,string& delegate);
92 92
93 /** 93 /**
94 * perform the associate request to OpenID server. 94 * perform the associate request to OpenID server.
95 * @param server the OpenID server 95 * @param server the OpenID server
96 * @return the auto_ptr<> for the newly allocated association_t 96 * @return the assoc_t for the newly allocated association_t
97 * object, representing established association 97 * object, representing established association
98 * @throw exception in case of error 98 * @throw exception in case of error
99 */ 99 */
100 assoc_t associate(const string& server); 100 assoc_t associate(const string& server);
101 /** 101 /**
102 * prepare the parameters for the checkid_immediate 102 * prepare the parameters for the checkid_immediate
103 * request. 103 * request.
104 * @param identity the identity to verify 104 * @param identity the identity to verify
105 * @param return_to the return_to url to pass with the request 105 * @param return_to the return_to url to pass with the request
106 * @param trust_root the trust root to advertise with the request 106 * @param trust_root the trust root to advertise with the request
107 * @param ext pointer to an extension(s) hooks object 107 * @param ext pointer to an extension(s) hooks object
108 * @return the location string 108 * @return the location string
diff --git a/include/opkele/curl.h b/include/opkele/curl.h
index 8020b63..5cf8e48 100644
--- a/include/opkele/curl.h
+++ b/include/opkele/curl.h
@@ -1,19 +1,23 @@
1#ifndef __OPKELE_CURL_H 1#ifndef __OPKELE_CURL_H
2#define __OPKELE_CURL_H 2#define __OPKELE_CURL_H
3 3
4#include <cassert> 4#include <cassert>
5#include <string>
6#include <algorithm>
5#include <curl/curl.h> 7#include <curl/curl.h>
6 8
7namespace opkele { 9namespace opkele {
10 using std::min;
11 using std::string;
8 12
9 namespace util { 13 namespace util {
10 14
11 class curl_t { 15 class curl_t {
12 public: 16 public:
13 CURL *_c; 17 CURL *_c;
14 18
15 curl_t() : _c(0) { } 19 curl_t() : _c(0) { }
16 curl_t(CURL *c) : _c(c) { } 20 curl_t(CURL *c) : _c(c) { }
17 virtual ~curl_t() throw(); 21 virtual ~curl_t() throw();
18 22
19 curl_t& operator=(CURL *c); 23 curl_t& operator=(CURL *c);
@@ -32,17 +36,37 @@ namespace opkele {
32 static inline CURL *easy_init() { return curl_easy_init(); } 36 static inline CURL *easy_init() { return curl_easy_init(); }
33 37
34 virtual size_t write(void* /* p */,size_t /* s */,size_t /* nm */) { return 0; } 38 virtual size_t write(void* /* p */,size_t /* s */,size_t /* nm */) { return 0; }
35 CURLcode set_write(); 39 CURLcode set_write();
36 40
37 virtual int progress(double /* dlt */,double /* dln*/ ,double /* ult */,double /* uln */) { return 0; } 41 virtual int progress(double /* dlt */,double /* dln*/ ,double /* ult */,double /* uln */) { return 0; }
38 CURLcode set_progress(); 42 CURLcode set_progress();
39 43
40 virtual size_t header(void* /* p */,size_t s,size_t nm) { return s*nm; } 44 virtual size_t header(void* /* p */,size_t s,size_t nm) { return s*nm; }
41 CURLcode set_header(); 45 CURLcode set_header();
42 }; 46 };
43 47
48 template<int lim>
49 class curl_fetch_string_t : public curl_t {
50 public:
51 curl_fetch_string_t(CURL *c)
52 : curl_t(c) { }
53 ~curl_fetch_string_t() throw() { }
54
55 string response;
56
57 size_t write(void *p,size_t size,size_t nmemb) {
58 size_t bytes = size*nmemb;
59 size_t get = min(lim-response.length(),bytes);
60 response.append((const char *)p,get);
61 return get;
62 }
63 };
64
65 typedef curl_fetch_string_t<16384> curl_pick_t;
66
67
44 } 68 }
45 69
46} 70}
47 71
48#endif /* __OPKELE_CURL_H */ 72#endif /* __OPKELE_CURL_H */
diff --git a/include/opkele/debug.h b/include/opkele/debug.h
new file mode 100644
index 0000000..a02f8d4
--- a/dev/null
+++ b/include/opkele/debug.h
@@ -0,0 +1,17 @@
1#ifndef __OPKELE_DEBUG_H
2#define __OPKELE_DEBUG_H
3
4#ifdef NDEBUG
5
6 #define D_(x) ((void)0)
7 #define DOUT_(x)((void)0)
8
9#else /* NDEBUG */
10
11 #define D_(x) x
12#include <iostream>
13 #define DOUT_(x)std::clog << x << std::endl
14
15#endif /* NDEBUG */
16
17#endif /* __OPKELE_DEBUG_H */
diff --git a/include/opkele/discovery.h b/include/opkele/discovery.h
new file mode 100644
index 0000000..af4aa29
--- a/dev/null
+++ b/include/opkele/discovery.h
@@ -0,0 +1,40 @@
1#ifndef __OPKELE_DISCOVERY_H
2#define __OPKELE_DISCOVERY_H
3
4#include <string>
5#include <opkele/types.h>
6
7namespace opkele {
8 using std::string;
9
10 struct idiscovery_t;
11
12 void idiscover(idiscovery_t& result,const string& identity);
13
14 struct idiscovery_t {
15 bool xri_identity;
16 string normalized_id;
17 string canonicalized_id;
18 xrd::XRD_t xrd;
19
20 idiscovery_t() { }
21 idiscovery_t(const string& i) {
22 idiscover(*this,i);
23 }
24 idiscovery_t(const char *i) {
25 idiscover(*this,i);
26 }
27
28 void clear() {
29 normalized_id.clear(); canonicalized_id.clear();
30 xrd.clear();
31 }
32
33 idiscovery_t& operator=(const string& i) {
34 idiscover(*this,i); return *this; }
35 idiscovery_t& operator=(const char *i) {
36 idiscover(*this,i); return *this; }
37 };
38}
39
40#endif /* __OPKELE_DISCOVERY_H */
diff --git a/include/opkele/exception.h b/include/opkele/exception.h
index 2ff44b7..a8c3339 100644
--- a/include/opkele/exception.h
+++ b/include/opkele/exception.h
@@ -15,44 +15,52 @@
15 * the exception parameters declaration 15 * the exception parameters declaration
16 */ 16 */
17# define OPKELE_E_PARS const string& fi,const string&fu,int l,const string& w 17# define OPKELE_E_PARS const string& fi,const string&fu,int l,const string& w
18/** 18/**
19 * the exception parameters list to pass to constructor 19 * the exception parameters list to pass to constructor
20 */ 20 */
21# define OPKELE_E_CONS_ fi,fu,l, 21# define OPKELE_E_CONS_ fi,fu,l,
22/** 22/**
23 * the exception codepoint specification 23 * the exception codepoint specification
24 */ 24 */
25# define OPKELE_CP_ CODEPOINT, 25# define OPKELE_CP_ CODEPOINT,
26/** 26/**
27 * open function-try-block
28 */
29# define OPKELE_FUNC_TRY try
30/**
27 * the simple rethrow of konforka-based exception 31 * the simple rethrow of konforka-based exception
28 */ 32 */
29# define OPKELE_RETHROW catch(konforka::exception& e) { e.see(CODEPOINT); throw } 33# define OPKELE_RETHROW catch(konforka::exception& e) { e.see(CODEPOINT); throw; }
30#else /* OPKELE_HAVE_KONFORKA */ 34#else /* OPKELE_HAVE_KONFORKA */
31# include <exception> 35# include <exception>
32# include <string> 36# include <string>
33/** 37/**
34 * the exception parameter declaration 38 * the exception parameter declaration
35 */ 39 */
36# define OPKELE_E_PARS const string& w 40# define OPKELE_E_PARS const string& w
37/** 41/**
38 * the dummy prefix for exception parameters list to prepend in the absence of 42 * the dummy prefix for exception parameters list to prepend in the absence of
39 * konforka library 43 * konforka library
40 */ 44 */
41# define OPKELE_E_CONS_ 45# define OPKELE_E_CONS_
42/** 46/**
43 * the dummy placeholder for konforka exception codepoint specification 47 * the dummy placeholder for konforka exception codepoint specification
44 */ 48 */
45# define OPKELE_CP_ 49# define OPKELE_CP_
46/** 50/**
51 * the dummy define for the opening function-try-block
52 */
53# define OPKELE_FUNC_TRY
54/**
47 * the dummy define for the konforka-based rethrow of exception 55 * the dummy define for the konforka-based rethrow of exception
48 */ 56 */
49# define OPKELE_RETHROW 57# define OPKELE_RETHROW
50#endif /* OPKELE_HAVE_KONFORKA */ 58#endif /* OPKELE_HAVE_KONFORKA */
51/** 59/**
52 * the exception parameters list to pass to constructor 60 * the exception parameters list to pass to constructor
53 */ 61 */
54# define OPKELE_E_CONS OPKELE_E_CONS_ w 62# define OPKELE_E_CONS OPKELE_E_CONS_ w
55 63
56namespace opkele { 64namespace opkele {
57 using std::string; 65 using std::string;
58 66
@@ -60,31 +68,28 @@ namespace opkele {
60 * the base opkele exception class 68 * the base opkele exception class
61 */ 69 */
62 class exception : public 70 class exception : public
63# ifdef OPKELE_HAVE_KONFORKA 71# ifdef OPKELE_HAVE_KONFORKA
64 konforka::exception 72 konforka::exception
65# else 73# else
66 std::exception 74 std::exception
67# endif 75# endif
68 { 76 {
69 public: 77 public:
70# ifdef OPKELE_HAVE_KONFORKA 78# ifdef OPKELE_HAVE_KONFORKA
71 explicit 79 explicit
72 exception(const string& fi,const string& fu,int l,const string& w) 80 exception(const string& fi,const string& fu,int l,const string& w);
73 : konforka::exception(fi,fu,l,w) { }
74# else /* OPKELE_HAVE_KONFORKA */ 81# else /* OPKELE_HAVE_KONFORKA */
75 string _what; 82 string _what;
76 explicit 83 explicit exception(const string& w);
77 exception(const string& w)
78 : _what(w) { }
79 virtual ~exception() throw(); 84 virtual ~exception() throw();
80 virtual const char * what() const throw(); 85 virtual const char * what() const throw();
81# endif /* OPKELE_HAVE_KONFORKA */ 86# endif /* OPKELE_HAVE_KONFORKA */
82 }; 87 };
83 88
84 /** 89 /**
85 * thrown in case of failed conversion 90 * thrown in case of failed conversion
86 */ 91 */
87 class failed_conversion : public exception { 92 class failed_conversion : public exception {
88 public: 93 public:
89 failed_conversion(OPKELE_E_PARS) 94 failed_conversion(OPKELE_E_PARS)
90 : exception(OPKELE_E_CONS) { } 95 : exception(OPKELE_E_CONS) { }
@@ -147,47 +152,83 @@ namespace opkele {
147 */ 152 */
148 class id_res_failed : public exception { 153 class id_res_failed : public exception {
149 public: 154 public:
150 id_res_failed(OPKELE_E_PARS) 155 id_res_failed(OPKELE_E_PARS)
151 : exception(OPKELE_E_CONS) { } 156 : exception(OPKELE_E_CONS) { }
152 }; 157 };
153 /** 158 /**
154 * thrown if the user_setup_url is provided with negative response 159 * thrown if the user_setup_url is provided with negative response
155 */ 160 */
156 class id_res_setup : public id_res_failed { 161 class id_res_setup : public id_res_failed {
157 public: 162 public:
158 string setup_url; 163 string setup_url;
159 id_res_setup(OPKELE_E_PARS,const string& su) 164 id_res_setup(OPKELE_E_PARS,const string& su="")
160 : id_res_failed(OPKELE_E_CONS), setup_url(su) { } 165 : id_res_failed(OPKELE_E_CONS), setup_url(su) { }
161 ~id_res_setup() throw() { } 166 ~id_res_setup() throw() { }
162 }; 167 };
163 /** 168 /**
164 * thrown in case of signature mismatch 169 * thrown in case of signature mismatch
165 */ 170 */
166 class id_res_mismatch : public id_res_failed { 171 class id_res_mismatch : public id_res_failed {
167 public: 172 public:
168 id_res_mismatch(OPKELE_E_PARS) 173 id_res_mismatch(OPKELE_E_PARS)
169 : id_res_failed(OPKELE_E_CONS) { } 174 : id_res_failed(OPKELE_E_CONS) { }
170 }; 175 };
171 176
172 /** 177 /**
173 * thrown if the association has expired before it could've been verified. 178 * thrown if the association has expired before it could've been verified.
174 */ 179 */
175 class id_res_expired_on_delivery : public id_res_failed { 180 class id_res_expired_on_delivery : public id_res_failed {
176 public: 181 public:
177 id_res_expired_on_delivery(OPKELE_E_PARS) 182 id_res_expired_on_delivery(OPKELE_E_PARS)
178 : id_res_failed(OPKELE_E_CONS) { } 183 : id_res_failed(OPKELE_E_CONS) { }
179 }; 184 };
180 185
181 /** 186 /**
187 * thown when the user cancelled authentication process.
188 */
189 class id_res_cancel : public id_res_failed {
190 public:
191 id_res_cancel(OPKELE_E_PARS)
192 : id_res_failed(OPKELE_E_CONS) { }
193 };
194
195 /**
196 * thrown in case of nonce reuse or otherwise imperfect nonce.
197 */
198 class id_res_bad_nonce : public id_res_failed {
199 public:
200 id_res_bad_nonce(OPKELE_E_PARS)
201 : id_res_failed(OPKELE_E_CONS) { }
202 };
203
204 /**
205 * thrown if return_to didn't pass verification
206 */
207 class id_res_bad_return_to : public id_res_failed {
208 public:
209 id_res_bad_return_to(OPKELE_E_PARS)
210 : id_res_failed(OPKELE_E_CONS) { }
211 };
212
213 /**
214 * thrown if OP isn't authorized to make an assertion
215 */
216 class id_res_unauthorized : public id_res_failed {
217 public:
218 id_res_unauthorized(OPKELE_E_PARS)
219 : id_res_failed(OPKELE_E_CONS) { }
220 };
221
222 /**
182 * openssl malfunction occured 223 * openssl malfunction occured
183 */ 224 */
184 class exception_openssl : public exception { 225 class exception_openssl : public exception {
185 public: 226 public:
186 unsigned long _error; 227 unsigned long _error;
187 string _ssl_string; 228 string _ssl_string;
188 exception_openssl(OPKELE_E_PARS); 229 exception_openssl(OPKELE_E_PARS);
189 ~exception_openssl() throw() { } 230 ~exception_openssl() throw() { }
190 }; 231 };
191 232
192 /** 233 /**
193 * network operation related error occured 234 * network operation related error occured
@@ -203,33 +244,73 @@ namespace opkele {
203 * libcurl 244 * libcurl
204 */ 245 */
205 class exception_curl : public exception_network { 246 class exception_curl : public exception_network {
206 public: 247 public:
207 CURLcode _error; 248 CURLcode _error;
208 string _curl_string; 249 string _curl_string;
209 exception_curl(OPKELE_E_PARS); 250 exception_curl(OPKELE_E_PARS);
210 exception_curl(OPKELE_E_PARS,CURLcode e); 251 exception_curl(OPKELE_E_PARS,CURLcode e);
211 ~exception_curl() throw() { } 252 ~exception_curl() throw() { }
212 }; 253 };
213 254
214 /** 255 /**
256 * htmltidy related error occured
257 */
258 class exception_tidy : public exception {
259 public:
260 int _rc;
261 exception_tidy(OPKELE_E_PARS);
262 exception_tidy(OPKELE_E_PARS,int r);
263 ~exception_tidy() throw() { }
264 };
265
266 /**
267 * exception thrown in case of failed discovery
268 */
269 class failed_discovery : public exception {
270 public:
271 failed_discovery(OPKELE_E_PARS)
272 : exception(OPKELE_E_CONS) { }
273 };
274
275 /**
276 * unsuccessfull xri resolution
277 */
278 class failed_xri_resolution : public failed_discovery {
279 public:
280 long _code;
281 failed_xri_resolution(OPKELE_E_PARS,long _c=-1)
282 : failed_discovery(OPKELE_E_CONS), _code(_c) { }
283 };
284
285 /**
215 * not implemented (think pure virtual) member function executed, signfies 286 * not implemented (think pure virtual) member function executed, signfies
216 * programmer error 287 * programmer error
217 */ 288 */
218 class not_implemented : public exception { 289 class not_implemented : public exception {
219 public: 290 public:
220 not_implemented(OPKELE_E_PARS) 291 not_implemented(OPKELE_E_PARS)
221 : exception(OPKELE_E_CONS) { } 292 : exception(OPKELE_E_CONS) { }
222 }; 293 };
223 294
224 /** 295 /**
225 * internal error, indicates internal libopkele problem 296 * internal error, indicates internal libopkele problem
226 */ 297 */
227 class internal_error : public exception { 298 class internal_error : public exception {
228 public: 299 public:
229 internal_error(OPKELE_E_PARS) 300 internal_error(OPKELE_E_PARS)
230 : exception(OPKELE_E_CONS) { } 301 : exception(OPKELE_E_CONS) { }
231 }; 302 };
232 303
304 /**
305 * thrown in case of unsupported parameter encountered (e.g. unsupported
306 * association type).
307 */
308 class unsupported : public exception {
309 public:
310 unsupported(OPKELE_E_PARS)
311 : exception(OPKELE_E_CONS) { }
312 };
313
233} 314}
234 315
235#endif /* __OPKELE_EXCEPTION_H */ 316#endif /* __OPKELE_EXCEPTION_H */
diff --git a/include/opkele/expat.h b/include/opkele/expat.h
new file mode 100644
index 0000000..60c41ac
--- a/dev/null
+++ b/include/opkele/expat.h
@@ -0,0 +1,91 @@
1#ifndef __OPKELE_EXPAT_H
2#define __OPKELE_EXPAT_H
3
4#include <cassert>
5#include <expat.h>
6
7namespace opkele {
8
9 namespace util {
10
11 class expat_t {
12 public:
13 XML_Parser _x;
14
15 expat_t() : _x(0) { }
16 expat_t(XML_Parser x) : _x(x) { }
17 virtual ~expat_t() throw();
18
19 expat_t& operator=(XML_Parser x);
20
21 operator const XML_Parser(void) const { return _x; }
22 operator XML_Parser(void) { return _x; }
23
24 inline bool parse(const char *s,int len,bool final=false) {
25 assert(_x);
26 return XML_Parse(_x,s,len,final);
27 }
28
29 virtual void start_element(const XML_Char *n,const XML_Char **a) { }
30 virtual void end_element(const XML_Char *n) { }
31 void set_element_handler();
32
33 virtual void character_data(const XML_Char *s,int l) { }
34 void set_character_data_handler();
35
36 virtual void processing_instruction(const XML_Char *t,const XML_Char *d) { }
37 void set_processing_instruction_handler();
38
39 virtual void comment(const XML_Char *d) { }
40 void set_comment_handler();
41
42 virtual void start_cdata_section() { }
43 virtual void end_cdata_section() { }
44 void set_cdata_section_handler();
45
46 virtual void default_handler(const XML_Char *s,int l) { }
47 void set_default_handler();
48 void set_default_handler_expand();
49
50 virtual void start_namespace_decl(const XML_Char *p,const XML_Char *u) { }
51 virtual void end_namespace_decl(const XML_Char *p) { }
52 void set_namespace_decl_handler();
53
54 inline enum XML_Error get_error_code() {
55 assert(_x); return XML_GetErrorCode(_x); }
56 static inline const XML_LChar *error_string(XML_Error c) {
57 return XML_ErrorString(c); }
58
59 inline long get_current_byte_index() {
60 assert(_x); return XML_GetCurrentByteIndex(_x); }
61 inline int get_current_line_number() {
62 assert(_x); return XML_GetCurrentLineNumber(_x); }
63 inline int get_current_column_number() {
64 assert(_x); return XML_GetCurrentColumnNumber(_x); }
65
66 inline void set_user_data() {
67 assert(_x); XML_SetUserData(_x,this); }
68
69 inline bool set_base(const XML_Char *b) {
70 assert(_x); return XML_SetBase(_x,b); }
71 inline const XML_Char *get_base() {
72 assert(_x); return XML_GetBase(_x); }
73
74 inline int get_specified_attribute_count() {
75 assert(_x); return XML_GetSpecifiedAttributeCount(_x); }
76
77 inline bool set_param_entity_parsing(enum XML_ParamEntityParsing c) {
78 assert(_x); return XML_SetParamEntityParsing(_x,c); }
79
80 inline static XML_Parser parser_create(const XML_Char *e=0) {
81 return XML_ParserCreate(e); }
82 inline static XML_Parser parser_create_ns(const XML_Char *e=0,XML_Char s='\t') {
83 return XML_ParserCreateNS(e,s); }
84
85 };
86
87 }
88
89}
90
91#endif /* __OPKELE_EXPAT_H */
diff --git a/include/opkele/server.h b/include/opkele/server.h
index dd7fc41..3c25646 100644
--- a/include/opkele/server.h
+++ b/include/opkele/server.h
@@ -16,33 +16,33 @@ namespace opkele {
16 */ 16 */
17 class server_t { 17 class server_t {
18 public: 18 public:
19 19
20 virtual ~server_t() { } 20 virtual ~server_t() { }
21 21
22 /** 22 /**
23 * allocate the new association. The function should be overridden 23 * allocate the new association. The function should be overridden
24 * in the real implementation to provide persistent assocations 24 * in the real implementation to provide persistent assocations
25 * store. 25 * store.
26 * @param mode the mode of request being processed to base the 26 * @param mode the mode of request being processed to base the
27 * statelessness of the association upon 27 * statelessness of the association upon
28 * @return the auto_ptr<> for the newly allocated association_t object 28 * @return the assoc_t for the newly allocated association_t object
29 */ 29 */
30 virtual assoc_t alloc_assoc(mode_t mode) = 0; 30 virtual assoc_t alloc_assoc(mode_t mode) = 0;
31 /** 31 /**
32 * retrieve the association. The function should be overridden in 32 * retrieve the association. The function should be overridden in
33 * the reqal implementation to provide persistent assocations 33 * the reqal implementation to provide persistent assocations
34 * store. 34 * store.
35 * @param h association handle 35 * @param h association handle
36 * @return the auto_ptr<> for the newly allocated association_t object 36 * @return the assoc_t for the newly allocated association_t object
37 * @throw failed_lookup in case of failure 37 * @throw failed_lookup in case of failure
38 */ 38 */
39 virtual assoc_t retrieve_assoc(const string& h) = 0; 39 virtual assoc_t retrieve_assoc(const string& h) = 0;
40 40
41 /** 41 /**
42 * validate the identity. 42 * validate the identity.
43 * @param assoc association object 43 * @param assoc association object
44 * @param pin incoming request parameters 44 * @param pin incoming request parameters
45 * @param identity being verified 45 * @param identity being verified
46 * @param trust_root presented in the request 46 * @param trust_root presented in the request
47 * @throw exception if identity can not be confirmed 47 * @throw exception if identity can not be confirmed
48 */ 48 */
diff --git a/include/opkele/tidy.h b/include/opkele/tidy.h
new file mode 100644
index 0000000..888e7d4
--- a/dev/null
+++ b/include/opkele/tidy.h
@@ -0,0 +1,73 @@
1#ifndef __OPKELE_TIDY_H
2#define __OPKELE_TIDY_H
3
4#include <cassert>
5#include <tidy.h>
6#include <buffio.h>
7
8namespace opkele {
9 namespace util {
10
11 class tidy_buf_t {
12 public:
13 TidyBuffer _x;
14
15 tidy_buf_t() { tidyBufInit(&_x); }
16 virtual ~tidy_buf_t() throw() {
17 tidyBufFree(&_x); }
18
19 inline operator const TidyBuffer&(void) const { return _x; }
20 inline operator TidyBuffer&(void) { return _x; }
21
22 inline operator const char*(void) const { return (const char*)_x.bp; }
23 inline operator char*(void) { return (char*)_x.bp; }
24
25 inline const char *c_str() const {
26 return (const char*)_x.bp; }
27 inline size_t size() const {
28 return _x.size; }
29 };
30
31 class tidy_doc_t {
32 public:
33 TidyDoc _x;
34
35 tidy_doc_t() : _x(0) { }
36 tidy_doc_t(TidyDoc x) : _x(x) { }
37 virtual ~tidy_doc_t() throw() {
38 if(_x) tidyRelease(_x); }
39
40 tidy_doc_t& operator=(TidyDoc x) {
41 if(_x) tidyRelease(_x);
42 _x = x;
43 return *this;
44 }
45
46 operator const TidyDoc(void) const { return _x; }
47 operator TidyDoc(void) { return _x; }
48
49 inline bool opt_set(TidyOptionId o,bool v) {
50 assert(_x);
51 return tidyOptSetBool(_x,o,v?yes:no); }
52 inline bool opt_set(TidyOptionId o,int v) {
53 assert(_x);
54 return tidyOptSetInt(_x,o,v); }
55
56 inline int parse_string(const string& s) {
57 assert(_x);
58 return tidyParseString(_x,s.c_str()); }
59 inline int clean_and_repair() {
60 assert(_x);
61 return tidyCleanAndRepair(_x); }
62 inline int save_buffer(TidyBuffer& ob) {
63 assert(_x);
64 return tidySaveBuffer(_x,&ob); }
65
66 static inline TidyDoc create() {
67 return tidyCreate(); }
68 };
69
70 }
71}
72
73#endif /* __OPKELE_TIDY_H */
diff --git a/include/opkele/tr1-mem.h.in b/include/opkele/tr1-mem.h.in
new file mode 100644
index 0000000..e9ccf0b
--- a/dev/null
+++ b/include/opkele/tr1-mem.h.in
@@ -0,0 +1,10 @@
1#ifndef __OPKELE_TR1_MEM_H
2#define __OPKELE_TR1_MEM_H
3
4#include <@OPKELE_TR1_MEM_HEADER@>
5
6namespace opkele {
7 namespace tr1mem = @OPKELE_TR1_MEM_NS@;
8}
9
10#endif /* __OPKELE_TR1_MEM_H */
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,61 +1,63 @@
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
@@ -96,27 +98,27 @@ namespace opkele {
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 */
@@ -149,24 +151,96 @@ namespace opkele {
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 */
diff --git a/include/opkele/uris.h b/include/opkele/uris.h
new file mode 100644
index 0000000..56c2d6d
--- a/dev/null
+++ b/include/opkele/uris.h
@@ -0,0 +1,18 @@
1#ifndef __OPKELE_URIS_H
2#define __OPKELE_URIS_H
3
4 #define NSURI_XRDS "xri://$xrds"
5 #define NSURI_XRD "xri://$xrd*($v*2.0)"
6 #define NSURI_OPENID10 "http://openid.net/xmlns/1.0"
7
8 #define OIURI_OPENID20 "http://specs.openid.net/auth/2.0"
9 #define OIURI_SREG11 "http://openid.net/extensions/sreg/1.1"
10
11 #define STURI_OPENID10 "http://openid.net/signon/1.0"
12 #define STURI_OPENID11 "http://openid.net/signon/1.1"
13 #define STURI_OPENID20 "http://specs.openid.net/auth/2.0/signon"
14 #define STURI_OPENID20_OP"http://specs.openid.net/auth/2.0/server"
15
16 #define IDURI_SELECT20 "http://specs.openid.net/auth/2.0/identifier_select"
17
18#endif /* __OPKELE_URIS_H */