author | Michael Krelin <hacker@klever.net> | 2007-01-11 00:57:06 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2007-01-11 00:57:06 (UTC) |
commit | 06eaf00c48fc563245b85c2be4b8b5a03ef2cfe9 (patch) (unidiff) | |
tree | ef978c5d86188d2fc4c7e98a921804d7bfeb5557 /include | |
parent | 100199abfdf7a353f9ba2aa9618e0711213290d3 (diff) | |
download | libopkele-06eaf00c48fc563245b85c2be4b8b5a03ef2cfe9.zip libopkele-06eaf00c48fc563245b85c2be4b8b5a03ef2cfe9.tar.gz libopkele-06eaf00c48fc563245b85c2be4b8b5a03ef2cfe9.tar.bz2 |
introduced extension hooks framework
-rw-r--r-- | include/Makefile.am | 3 | ||||
-rw-r--r-- | include/opkele/consumer.h | 25 | ||||
-rw-r--r-- | include/opkele/exception.h | 10 | ||||
-rw-r--r-- | include/opkele/extension.h | 59 | ||||
-rw-r--r-- | include/opkele/server.h | 10 |
5 files changed, 92 insertions, 15 deletions
diff --git a/include/Makefile.am b/include/Makefile.am index b014752..72931eb 100644 --- a/include/Makefile.am +++ b/include/Makefile.am | |||
@@ -1,11 +1,12 @@ | |||
1 | nobase_include_HEADERS = \ | 1 | nobase_include_HEADERS = \ |
2 | opkele/acconfig.h \ | 2 | opkele/acconfig.h \ |
3 | opkele/opkele-config.h \ | 3 | opkele/opkele-config.h \ |
4 | opkele/types.h \ | 4 | opkele/types.h \ |
5 | opkele/association.h \ | 5 | opkele/association.h \ |
6 | opkele/exception.h \ | 6 | opkele/exception.h \ |
7 | opkele/server.h \ | 7 | opkele/server.h \ |
8 | opkele/consumer.h | 8 | opkele/consumer.h \ |
9 | opkele/extension.h | ||
9 | EXTRA_DIST = \ | 10 | EXTRA_DIST = \ |
10 | opkele/data.h \ | 11 | opkele/data.h \ |
11 | opkele/util.h | 12 | opkele/util.h |
diff --git a/include/opkele/consumer.h b/include/opkele/consumer.h index 9932315..f9939cf 100644 --- a/include/opkele/consumer.h +++ b/include/opkele/consumer.h | |||
@@ -1,142 +1,145 @@ | |||
1 | #ifndef __OPKELE_CONSUMER_H | 1 | #ifndef __OPKELE_CONSUMER_H |
2 | #define __OPKELE_CONSUMER_H | 2 | #define __OPKELE_CONSUMER_H |
3 | 3 | ||
4 | #include <opkele/types.h> | 4 | #include <opkele/types.h> |
5 | #include <opkele/extension.h> | ||
5 | 6 | ||
6 | /** | 7 | /** |
7 | * @file | 8 | * @file |
8 | * @brief OpenID consumer-side functionality | 9 | * @brief OpenID consumer-side functionality |
9 | */ | 10 | */ |
10 | 11 | ||
11 | /** | 12 | /** |
12 | * @brief the main opkele namespace | 13 | * @brief the main opkele namespace |
13 | */ | 14 | */ |
14 | namespace opkele { | 15 | namespace opkele { |
15 | 16 | ||
16 | /** | 17 | /** |
17 | * implementation of basic consumer functionality | 18 | * implementation of basic consumer functionality |
18 | */ | 19 | */ |
19 | class consumer_t { | 20 | class consumer_t { |
20 | public: | 21 | public: |
21 | 22 | ||
22 | /** | 23 | /** |
23 | * store association. The function should be overridden in the real | 24 | * store association. The function should be overridden in the real |
24 | * implementation to provide persistent associations store. | 25 | * implementation to provide persistent associations store. |
25 | * @param server the OpenID server | 26 | * @param server the OpenID server |
26 | * @param handle association handle | 27 | * @param handle association handle |
27 | * @param secret the secret associated with the server and handle | 28 | * @param secret the secret associated with the server and handle |
28 | * @param expires_in the number of seconds until the handle is expired | 29 | * @param expires_in the number of seconds until the handle is expired |
29 | * @return the auto_ptr<> for the newly allocated association_t object | 30 | * @return the auto_ptr<> for the newly allocated association_t object |
30 | */ | 31 | */ |
31 | virtual assoc_t store_assoc(const string& server,const string& handle,const secret_t& secret,int expires_in) = 0; | 32 | virtual assoc_t store_assoc(const string& server,const string& handle,const secret_t& secret,int expires_in) = 0; |
32 | /** | 33 | /** |
33 | * retrieve stored association. The function should be overridden | 34 | * retrieve stored association. The function should be overridden |
34 | * in the real implementation to provide persistent assocations | 35 | * in the real implementation to provide persistent assocations |
35 | * store. | 36 | * store. |
36 | * @param server the OpenID server | 37 | * @param server the OpenID server |
37 | * @param handle association handle | 38 | * @param handle association handle |
38 | * @return the autho_ptr<> for the newly allocated association_t object | 39 | * @return the autho_ptr<> for the newly allocated association_t object |
39 | * @throw failed_lookup in case of error | 40 | * @throw failed_lookup in case of error |
40 | */ | 41 | */ |
41 | virtual assoc_t retrieve_assoc(const string& server,const string& handle) = 0; | 42 | virtual assoc_t retrieve_assoc(const string& server,const string& handle) = 0; |
42 | /** | 43 | /** |
43 | * invalidate stored association. The function should be overridden | 44 | * invalidate stored association. The function should be overridden |
44 | * in the real implementation of the consumer. | 45 | * in the real implementation of the consumer. |
45 | * @param server the OpenID server | 46 | * @param server the OpenID server |
46 | * @param handle association handle | 47 | * @param handle association handle |
47 | */ | 48 | */ |
48 | virtual void invalidate_assoc(const string& server,const string& handle) = 0; | 49 | virtual void invalidate_assoc(const string& server,const string& handle) = 0; |
49 | /** | 50 | /** |
50 | * retrieve any unexpired association for the server. If the | 51 | * retrieve any unexpired association for the server. If the |
51 | * function is not overridden in the real implementation, the new | 52 | * function is not overridden in the real implementation, the new |
52 | * association will be established for each request. | 53 | * association will be established for each request. |
53 | * @param server the OpenID server | 54 | * @param server the OpenID server |
54 | * @return the auto_ptr<> for the newly allocated association_t object | 55 | * @return the auto_ptr<> for the newly allocated association_t object |
55 | * @throw failed_lookup in case of absence of the handle | 56 | * @throw failed_lookup in case of absence of the handle |
56 | */ | 57 | */ |
57 | virtual assoc_t find_assoc(const string& server); | 58 | virtual assoc_t find_assoc(const string& server); |
58 | 59 | ||
59 | /** | 60 | /** |
60 | * retrieve the metainformation contained in link tags from the | 61 | * retrieve the metainformation contained in link tags from the |
61 | * page pointed by url. the function may implement caching of the | 62 | * page pointed by url. the function may implement caching of the |
62 | * information. | 63 | * information. |
63 | * @param url url to harvest for link tags | 64 | * @param url url to harvest for link tags |
64 | * @param server reference to the string object where to put | 65 | * @param server reference to the string object where to put |
65 | * openid.server value | 66 | * openid.server value |
66 | * @param delegate reference to the string object where to put the | 67 | * @param delegate reference to the string object where to put the |
67 | * openid.delegate value (if any) | 68 | * openid.delegate value (if any) |
68 | */ | 69 | */ |
69 | virtual void retrieve_links(const string& url,string& server,string& delegate); | 70 | virtual void retrieve_links(const string& url,string& server,string& delegate); |
70 | 71 | ||
71 | /** | 72 | /** |
72 | * perform the associate request to OpenID server. | 73 | * perform the associate request to OpenID server. |
73 | * @param server the OpenID server | 74 | * @param server the OpenID server |
74 | * @return the auto_ptr<> for the newly allocated association_t | 75 | * @return the auto_ptr<> for the newly allocated association_t |
75 | * object, representing established association | 76 | * object, representing established association |
76 | * @throw exception in case of error | 77 | * @throw exception in case of error |
77 | */ | 78 | */ |
78 | assoc_t associate(const string& server); | 79 | assoc_t associate(const string& server); |
79 | /** | 80 | /** |
80 | * prepare the parameters for the checkid_immediate | 81 | * prepare the parameters for the checkid_immediate |
81 | * request. | 82 | * request. |
82 | * @param identity the identity to verify | 83 | * @param identity the identity to verify |
83 | * @param return_to the return_to url to pass with the request | 84 | * @param return_to the return_to url to pass with the request |
84 | * @param trust_root the trust root to advertise with the request | 85 | * @param trust_root the trust root to advertise with the request |
86 | * @param ext pointer to an extension(s) hooks object | ||
85 | * @return the location string | 87 | * @return the location string |
86 | * @throw exception in case of error | 88 | * @throw exception in case of error |
87 | */ | 89 | */ |
88 | string checkid_immediate(const string& identity,const string& return_to,const string& trust_root=""); | 90 | string checkid_immediate(const string& identity,const string& return_to,const string& trust_root="",extension_t *ext=0); |
89 | /** | 91 | /** |
90 | * prepare the parameters for the checkid_setup | 92 | * prepare the parameters for the checkid_setup |
91 | * request. | 93 | * request. |
92 | * @param identity the identity to verify | 94 | * @param identity the identity to verify |
93 | * @param return_to the return_to url to pass with the request | 95 | * @param return_to the return_to url to pass with the request |
94 | * @param trust_root the trust root to advertise with the request | 96 | * @param trust_root the trust root to advertise with the request |
97 | * @param ext pointer to an extension(s) hooks object | ||
95 | * @return the location string | 98 | * @return the location string |
96 | * @throw exception in case of error | 99 | * @throw exception in case of error |
97 | */ | 100 | */ |
98 | string checkid_setup(const string& identity,const string& return_to,const string& trust_root=""); | 101 | string checkid_setup(const string& identity,const string& return_to,const string& trust_root="",extension_t *ext=0); |
99 | /** | 102 | /** |
100 | * the actual implementation behind checkid_immediate() and | 103 | * the actual implementation behind checkid_immediate() and |
101 | * checkid_setup() functions. | 104 | * checkid_setup() functions. |
102 | * @param mode checkid_* mode - either mode_checkid_immediate or mode_checkid_setup | 105 | * @param mode checkid_* mode - either mode_checkid_immediate or mode_checkid_setup |
103 | * @param identity the identity to verify | 106 | * @param identity the identity to verify |
104 | * @param return_to the return_to url to pass with the request | 107 | * @param return_to the return_to url to pass with the request |
105 | * @param trust_root the trust root to advertise with the request | 108 | * @param trust_root the trust root to advertise with the request |
109 | * @param ext pointer to an extension(s) hooks object | ||
106 | * @return the location string | 110 | * @return the location string |
107 | * @throw exception in case of error | 111 | * @throw exception in case of error |
108 | */ | 112 | */ |
109 | string checkid_(mode_t mode,const string& identity,const string& return_to,const string& trust_root=""); | 113 | string checkid_(mode_t mode,const string& identity,const string& return_to,const string& trust_root="",extension_t *ext=0); |
110 | /** | 114 | /** |
111 | * verify the id_res response | 115 | * verify the id_res response |
112 | * @param pin the response parameters | 116 | * @param pin the response parameters |
113 | * @param identity the identity being checked (if not specified, extracted | 117 | * @param identity the identity being checked (if not specified, |
114 | * from the openid.identity parameter | 118 | * @param ext pointer to an extension(s) hooks object |
115 | * @throw id_res_mismatch in case of signature | 119 | * extracted from the openid.identity parameter |
116 | * mismatch | 120 | * @throw id_res_mismatch in case of signature mismatch |
117 | * @throw id_res_setup in case of | 121 | * @throw id_res_setup in case of openid.user_setup_url failure |
118 | * openid.user_setup_url failure (supposedly | 122 | * (supposedly checkid_immediate only) |
119 | * checkid_immediate only) | ||
120 | * @throw id_res_failed in case of failure | 123 | * @throw id_res_failed in case of failure |
121 | * @throw exception in case of other failures | 124 | * @throw exception in case of other failures |
122 | */ | 125 | */ |
123 | void id_res(const params_t& pin,const string& identity=""); | 126 | void id_res(const params_t& pin,const string& identity="",extension_t *ext=0); |
124 | /** | 127 | /** |
125 | * perform a check_authentication request. | 128 | * perform a check_authentication request. |
126 | * @param server the OpenID server | 129 | * @param server the OpenID server |
127 | * @param p request parameters | 130 | * @param p request parameters |
128 | */ | 131 | */ |
129 | void check_authentication(const string& server,const params_t& p); | 132 | void check_authentication(const string& server,const params_t& p); |
130 | 133 | ||
131 | /** | 134 | /** |
132 | * make URL canonical, by adding http:// and trailing slash, if needed. | 135 | * make URL canonical, by adding http:// and trailing slash, if needed. |
133 | * @param url | 136 | * @param url |
134 | * @return canonicalized url | 137 | * @return canonicalized url |
135 | */ | 138 | */ |
136 | static string canonicalize(const string& url); | 139 | static string canonicalize(const string& url); |
137 | 140 | ||
138 | }; | 141 | }; |
139 | 142 | ||
140 | } | 143 | } |
141 | 144 | ||
142 | #endif /* __OPKELE_CONSUMER_H */ | 145 | #endif /* __OPKELE_CONSUMER_H */ |
diff --git a/include/opkele/exception.h b/include/opkele/exception.h index c5f5811..9fc9bd3 100644 --- a/include/opkele/exception.h +++ b/include/opkele/exception.h | |||
@@ -1,210 +1,220 @@ | |||
1 | #ifndef __OPKELE_EXCEPTION_H | 1 | #ifndef __OPKELE_EXCEPTION_H |
2 | #define __OPKELE_EXCEPTION_H | 2 | #define __OPKELE_EXCEPTION_H |
3 | 3 | ||
4 | /** | 4 | /** |
5 | * @file | 5 | * @file |
6 | * @brief opkele exceptions | 6 | * @brief opkele exceptions |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include <curl/curl.h> | 9 | #include <curl/curl.h> |
10 | 10 | ||
11 | #include <opkele/opkele-config.h> | 11 | #include <opkele/opkele-config.h> |
12 | #ifdef OPKELE_HAVE_KONFORKA | 12 | #ifdef OPKELE_HAVE_KONFORKA |
13 | # include <konforka/exception.h> | 13 | # include <konforka/exception.h> |
14 | /** | 14 | /** |
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 | * the simple rethrow of konforka-based exception | 27 | * the simple rethrow of konforka-based exception |
28 | */ | 28 | */ |
29 | # define OPKELE_RETHROW catch(konforka::exception& e) { e.see(CODEPOINT); throw } | 29 | # define OPKELE_RETHROW catch(konforka::exception& e) { e.see(CODEPOINT); throw } |
30 | #else /* OPKELE_HAVE_KONFORKA */ | 30 | #else /* OPKELE_HAVE_KONFORKA */ |
31 | # include <exception> | 31 | # include <exception> |
32 | # include <string> | 32 | # include <string> |
33 | /** | 33 | /** |
34 | * the exception parameter declaration | 34 | * the exception parameter declaration |
35 | */ | 35 | */ |
36 | # define OPKELE_E_PARS const string& w | 36 | # define OPKELE_E_PARS const string& w |
37 | /** | 37 | /** |
38 | * the dummy prefix for exception parameters list to prepend in the absence of | 38 | * the dummy prefix for exception parameters list to prepend in the absence of |
39 | * konforka library | 39 | * konforka library |
40 | */ | 40 | */ |
41 | # define OPKELE_E_CONS_ | 41 | # define OPKELE_E_CONS_ |
42 | /** | 42 | /** |
43 | * the dummy placeholder for konforka exception codepoint specification | 43 | * the dummy placeholder for konforka exception codepoint specification |
44 | */ | 44 | */ |
45 | # define OPKELE_CP_ | 45 | # define OPKELE_CP_ |
46 | /** | 46 | /** |
47 | * the dummy define for the konforka-based rethrow of exception | 47 | * the dummy define for the konforka-based rethrow of exception |
48 | */ | 48 | */ |
49 | # define OPKELE_RETHROW | 49 | # define OPKELE_RETHROW |
50 | #endif /* OPKELE_HAVE_KONFORKA */ | 50 | #endif /* OPKELE_HAVE_KONFORKA */ |
51 | /** | 51 | /** |
52 | * the exception parameters list to pass to constructor | 52 | * the exception parameters list to pass to constructor |
53 | */ | 53 | */ |
54 | # define OPKELE_E_CONS OPKELE_E_CONS_ w | 54 | # define OPKELE_E_CONS OPKELE_E_CONS_ w |
55 | 55 | ||
56 | /* | 56 | /* |
57 | * @brief the main opkele namespace | 57 | * @brief the main opkele namespace |
58 | */ | 58 | */ |
59 | namespace opkele { | 59 | namespace opkele { |
60 | using std::string; | 60 | using std::string; |
61 | 61 | ||
62 | /** | 62 | /** |
63 | * the base opkele exception class | 63 | * the base opkele exception class |
64 | */ | 64 | */ |
65 | class exception : public | 65 | class exception : public |
66 | # ifdef OPKELE_HAVE_KONFORKA | 66 | # ifdef OPKELE_HAVE_KONFORKA |
67 | konforka::exception | 67 | konforka::exception |
68 | # else | 68 | # else |
69 | std::exception | 69 | std::exception |
70 | # endif | 70 | # endif |
71 | { | 71 | { |
72 | public: | 72 | public: |
73 | # ifdef OPKELE_HAVE_KONFORKA | 73 | # ifdef OPKELE_HAVE_KONFORKA |
74 | explicit | 74 | explicit |
75 | exception(const string& fi,const string& fu,int l,const string& w) | 75 | exception(const string& fi,const string& fu,int l,const string& w) |
76 | : konforka::exception(fi,fu,l,w) { } | 76 | : konforka::exception(fi,fu,l,w) { } |
77 | # else /* OPKELE_HAVE_KONFORKA */ | 77 | # else /* OPKELE_HAVE_KONFORKA */ |
78 | string _what; | 78 | string _what; |
79 | explicit | 79 | explicit |
80 | exception(const string& w) | 80 | exception(const string& w) |
81 | : _what(w) { } | 81 | : _what(w) { } |
82 | virtual ~exception() throw(); | 82 | virtual ~exception() throw(); |
83 | virtual const char * what() const throw(); | 83 | virtual const char * what() const throw(); |
84 | # endif /* OPKELE_HAVE_KONFORKA */ | 84 | # endif /* OPKELE_HAVE_KONFORKA */ |
85 | }; | 85 | }; |
86 | 86 | ||
87 | /** | 87 | /** |
88 | * thrown in case of failed conversion | 88 | * thrown in case of failed conversion |
89 | */ | 89 | */ |
90 | class failed_conversion : public exception { | 90 | class failed_conversion : public exception { |
91 | public: | 91 | public: |
92 | failed_conversion(OPKELE_E_PARS) | 92 | failed_conversion(OPKELE_E_PARS) |
93 | : exception(OPKELE_E_CONS) { } | 93 | : exception(OPKELE_E_CONS) { } |
94 | }; | 94 | }; |
95 | /** | 95 | /** |
96 | * thrown in case of failed lookup (either parameter or persistent store) | 96 | * thrown in case of failed lookup (either parameter or persistent store) |
97 | */ | 97 | */ |
98 | class failed_lookup : public exception { | 98 | class failed_lookup : public exception { |
99 | public: | 99 | public: |
100 | failed_lookup(OPKELE_E_PARS) | 100 | failed_lookup(OPKELE_E_PARS) |
101 | : exception(OPKELE_E_CONS) { } | 101 | : exception(OPKELE_E_CONS) { } |
102 | }; | 102 | }; |
103 | /** | 103 | /** |
104 | * thrown in case of bad input (either local or network) | 104 | * thrown in case of bad input (either local or network) |
105 | */ | 105 | */ |
106 | class bad_input : public exception { | 106 | class bad_input : public exception { |
107 | public: | 107 | public: |
108 | bad_input(OPKELE_E_PARS) | 108 | bad_input(OPKELE_E_PARS) |
109 | : exception(OPKELE_E_CONS) { } | 109 | : exception(OPKELE_E_CONS) { } |
110 | }; | 110 | }; |
111 | 111 | ||
112 | /** | 112 | /** |
113 | * thrown on failed assertion | 113 | * thrown on failed assertion |
114 | */ | 114 | */ |
115 | class failed_assertion : public exception { | 115 | class failed_assertion : public exception { |
116 | public: | 116 | public: |
117 | failed_assertion(OPKELE_E_PARS) | 117 | failed_assertion(OPKELE_E_PARS) |
118 | : exception(OPKELE_E_CONS) { } | 118 | : exception(OPKELE_E_CONS) { } |
119 | }; | 119 | }; |
120 | 120 | ||
121 | /** | 121 | /** |
122 | * thrown if the handle being retrieved is invalid | 122 | * thrown if the handle being retrieved is invalid |
123 | */ | 123 | */ |
124 | class invalid_handle : public exception { | 124 | class invalid_handle : public exception { |
125 | public: | 125 | public: |
126 | invalid_handle(OPKELE_E_PARS) | 126 | invalid_handle(OPKELE_E_PARS) |
127 | : exception(OPKELE_E_CONS) { } | 127 | : exception(OPKELE_E_CONS) { } |
128 | }; | 128 | }; |
129 | /** | 129 | /** |
130 | * thrown if the handle passed to check_authentication request is not | 130 | * thrown if the handle passed to check_authentication request is not |
131 | * stateless | 131 | * stateless |
132 | */ | 132 | */ |
133 | class stateful_handle : public exception { | 133 | class stateful_handle : public exception { |
134 | public: | 134 | public: |
135 | stateful_handle(OPKELE_E_PARS) | 135 | stateful_handle(OPKELE_E_PARS) |
136 | : exception(OPKELE_E_CONS) { } | 136 | : exception(OPKELE_E_CONS) { } |
137 | }; | 137 | }; |
138 | 138 | ||
139 | /** | 139 | /** |
140 | * thrown if check_authentication request fails | 140 | * thrown if check_authentication request fails |
141 | */ | 141 | */ |
142 | class failed_check_authentication : public exception { | 142 | class failed_check_authentication : public exception { |
143 | public: | 143 | public: |
144 | failed_check_authentication(OPKELE_E_PARS) | 144 | failed_check_authentication(OPKELE_E_PARS) |
145 | : exception(OPKELE_E_CONS) { } | 145 | : exception(OPKELE_E_CONS) { } |
146 | }; | 146 | }; |
147 | 147 | ||
148 | /** | 148 | /** |
149 | * thrown if the id_res request result is negative | 149 | * thrown if the id_res request result is negative |
150 | */ | 150 | */ |
151 | class id_res_failed : public exception { | 151 | class id_res_failed : public exception { |
152 | public: | 152 | public: |
153 | id_res_failed(OPKELE_E_PARS) | 153 | id_res_failed(OPKELE_E_PARS) |
154 | : exception(OPKELE_E_CONS) { } | 154 | : exception(OPKELE_E_CONS) { } |
155 | }; | 155 | }; |
156 | /** | 156 | /** |
157 | * thrown if the user_setup_url is provided with negative response | 157 | * thrown if the user_setup_url is provided with negative response |
158 | */ | 158 | */ |
159 | class id_res_setup : public id_res_failed { | 159 | class id_res_setup : public id_res_failed { |
160 | public: | 160 | public: |
161 | string setup_url; | 161 | string setup_url; |
162 | id_res_setup(OPKELE_E_PARS,const string& su) | 162 | id_res_setup(OPKELE_E_PARS,const string& su) |
163 | : id_res_failed(OPKELE_E_CONS), setup_url(su) { } | 163 | : id_res_failed(OPKELE_E_CONS), setup_url(su) { } |
164 | ~id_res_setup() throw() { } | 164 | ~id_res_setup() throw() { } |
165 | }; | 165 | }; |
166 | /** | 166 | /** |
167 | * thrown in case of signature mismatch | 167 | * thrown in case of signature mismatch |
168 | */ | 168 | */ |
169 | class id_res_mismatch : public id_res_failed { | 169 | class id_res_mismatch : public id_res_failed { |
170 | public: | 170 | public: |
171 | id_res_mismatch(OPKELE_E_PARS) | 171 | id_res_mismatch(OPKELE_E_PARS) |
172 | : id_res_failed(OPKELE_E_CONS) { } | 172 | : id_res_failed(OPKELE_E_CONS) { } |
173 | }; | 173 | }; |
174 | 174 | ||
175 | /** | 175 | /** |
176 | * openssl malfunction occured | 176 | * openssl malfunction occured |
177 | */ | 177 | */ |
178 | class exception_openssl : public exception { | 178 | class exception_openssl : public exception { |
179 | public: | 179 | public: |
180 | unsigned long _error; | 180 | unsigned long _error; |
181 | string _ssl_string; | 181 | string _ssl_string; |
182 | exception_openssl(OPKELE_E_PARS); | 182 | exception_openssl(OPKELE_E_PARS); |
183 | ~exception_openssl() throw() { } | 183 | ~exception_openssl() throw() { } |
184 | }; | 184 | }; |
185 | 185 | ||
186 | /** | 186 | /** |
187 | * network operation related error occured | 187 | * network operation related error occured |
188 | */ | 188 | */ |
189 | class exception_network : public exception { | 189 | class exception_network : public exception { |
190 | public: | 190 | public: |
191 | exception_network(OPKELE_E_PARS) | 191 | exception_network(OPKELE_E_PARS) |
192 | : exception(OPKELE_E_CONS) { } | 192 | : exception(OPKELE_E_CONS) { } |
193 | }; | 193 | }; |
194 | 194 | ||
195 | /** | 195 | /** |
196 | * network operation related error occured, specifically, related to | 196 | * network operation related error occured, specifically, related to |
197 | * libcurl | 197 | * libcurl |
198 | */ | 198 | */ |
199 | class exception_curl : public exception_network { | 199 | class exception_curl : public exception_network { |
200 | public: | 200 | public: |
201 | CURLcode _error; | 201 | CURLcode _error; |
202 | string _curl_string; | 202 | string _curl_string; |
203 | exception_curl(OPKELE_E_PARS); | 203 | exception_curl(OPKELE_E_PARS); |
204 | exception_curl(OPKELE_E_PARS,CURLcode e); | 204 | exception_curl(OPKELE_E_PARS,CURLcode e); |
205 | ~exception_curl() throw() { } | 205 | ~exception_curl() throw() { } |
206 | }; | 206 | }; |
207 | 207 | ||
208 | /** | ||
209 | * not implemented (think pure virtual) member function executed, signfies | ||
210 | * programmer error | ||
211 | */ | ||
212 | class not_implemented : public exception { | ||
213 | public: | ||
214 | not_implemented(OPKELE_E_PARS) | ||
215 | : exception(OPKELE_E_CONS) { } | ||
216 | }; | ||
217 | |||
208 | } | 218 | } |
209 | 219 | ||
210 | #endif /* __OPKELE_EXCEPTION_H */ | 220 | #endif /* __OPKELE_EXCEPTION_H */ |
diff --git a/include/opkele/extension.h b/include/opkele/extension.h new file mode 100644 index 0000000..3fb5f6e --- a/dev/null +++ b/include/opkele/extension.h | |||
@@ -0,0 +1,59 @@ | |||
1 | #ifndef __OPKELE_EXTENSIONS_H | ||
2 | #define __OPKELE_EXTENSIONS_H | ||
3 | |||
4 | /** | ||
5 | * @file | ||
6 | * @brief extensions framework basics | ||
7 | */ | ||
8 | |||
9 | #include <opkele/types.h> | ||
10 | |||
11 | /** | ||
12 | * @brief the main opkele namespace | ||
13 | */ | ||
14 | namespace opkele { | ||
15 | |||
16 | /** | ||
17 | * OpenID consumer extension hooks base class | ||
18 | */ | ||
19 | class extension_t { | ||
20 | public: | ||
21 | /** | ||
22 | * hook called by consumer before submitting data to OpenID server. | ||
23 | * It is supposed to manipulate parameters list. | ||
24 | * @param p parameters about to be submitted to server | ||
25 | * @param identity identity being verified. It may differ from the | ||
26 | * one available in parameters list in case of delegation | ||
27 | */ | ||
28 | virtual void checkid_hook(params_t& p,const string& identity); | ||
29 | /** | ||
30 | * hook called by consumer after identity information received from | ||
31 | * OpenID server is verified. | ||
32 | * @param p parameters received from server | ||
33 | * @param sp signed parameters received from server with 'openid.' | ||
34 | * leader stripped | ||
35 | * @param identity identity confirmed. May differ from the one | ||
36 | * available in parameters list in case of delegation. May also be | ||
37 | * empty which means - extract one from parameters | ||
38 | */ | ||
39 | virtual void id_res_hook(const params_t& p,const params_t& sp,const string& identity); | ||
40 | |||
41 | /** | ||
42 | * hook called by server before returning information to consumer. | ||
43 | * The hook may manipulate output parameters. It is important to | ||
44 | * note that modified pout["signed"] is used for signing response. | ||
45 | * @param pin request parameters list | ||
46 | * @param put response parameters list | ||
47 | */ | ||
48 | virtual void checkid_hook(const params_t& pin,params_t& pout); | ||
49 | |||
50 | /** | ||
51 | * Casts the object to pointer to itself. For convenient passing | ||
52 | * of pointer. | ||
53 | */ | ||
54 | operator extension_t*(void) { return this; } | ||
55 | }; | ||
56 | |||
57 | } | ||
58 | |||
59 | #endif /* __OPKELE_EXTENSIONS_H */ | ||
diff --git a/include/opkele/server.h b/include/opkele/server.h index fe07448..bf131d8 100644 --- a/include/opkele/server.h +++ b/include/opkele/server.h | |||
@@ -1,95 +1,99 @@ | |||
1 | #ifndef __OPKELE_SERVER_H | 1 | #ifndef __OPKELE_SERVER_H |
2 | #define __OPKELE_SERVER_H | 2 | #define __OPKELE_SERVER_H |
3 | 3 | ||
4 | /** | 4 | /** |
5 | * @file | 5 | * @file |
6 | * @brief OpenID server-side functionality | 6 | * @brief OpenID server-side functionality |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include <opkele/types.h> | 9 | #include <opkele/types.h> |
10 | #include <opkele/extension.h> | ||
10 | 11 | ||
11 | /** | 12 | /** |
12 | * @brief the main opkele namespace | 13 | * @brief the main opkele namespace |
13 | */ | 14 | */ |
14 | namespace opkele { | 15 | namespace opkele { |
15 | 16 | ||
16 | /** | 17 | /** |
17 | * implementation of basic server functionality | 18 | * implementation of basic server functionality |
18 | */ | 19 | */ |
19 | class server_t { | 20 | class server_t { |
20 | public: | 21 | public: |
21 | 22 | ||
22 | /** | 23 | /** |
23 | * allocate the new association. The function should be overridden | 24 | * allocate the new association. The function should be overridden |
24 | * in the real implementation to provide persistent assocations | 25 | * in the real implementation to provide persistent assocations |
25 | * store. | 26 | * store. |
26 | * @param mode the mode of request being processed to base the | 27 | * @param mode the mode of request being processed to base the |
27 | * statelessness of the association upon | 28 | * statelessness of the association upon |
28 | * @return the auto_ptr<> for the newly allocated association_t object | 29 | * @return the auto_ptr<> for the newly allocated association_t object |
29 | */ | 30 | */ |
30 | virtual assoc_t alloc_assoc(mode_t mode) = 0; | 31 | virtual assoc_t alloc_assoc(mode_t mode) = 0; |
31 | /** | 32 | /** |
32 | * retrieve the association. The function should be overridden in | 33 | * retrieve the association. The function should be overridden in |
33 | * the reqal implementation to provide persistent assocations | 34 | * the reqal implementation to provide persistent assocations |
34 | * store. | 35 | * store. |
35 | * @param h association handle | 36 | * @param h association handle |
36 | * @return the auto_ptr<> for the newly allocated association_t object | 37 | * @return the auto_ptr<> for the newly allocated association_t object |
37 | * @throw failed_lookup in case of failure | 38 | * @throw failed_lookup in case of failure |
38 | */ | 39 | */ |
39 | virtual assoc_t retrieve_assoc(const string& h) = 0; | 40 | virtual assoc_t retrieve_assoc(const string& h) = 0; |
40 | 41 | ||
41 | /** | 42 | /** |
42 | * validate the identity. | 43 | * validate the identity. |
43 | * @param assoc association object | 44 | * @param assoc association object |
44 | * @param pin incoming request parameters | 45 | * @param pin incoming request parameters |
45 | * @param identity being verified | 46 | * @param identity being verified |
46 | * @param trust_root presented in the request | 47 | * @param trust_root presented in the request |
47 | * @throw exception if identity can not be confirmed | 48 | * @throw exception if identity can not be confirmed |
48 | */ | 49 | */ |
49 | virtual void validate(const association_t& assoc,const params_t& pin,const string& identity,const string& trust_root) = 0; | 50 | virtual void validate(const association_t& assoc,const params_t& pin,const string& identity,const string& trust_root) = 0; |
50 | 51 | ||
51 | 52 | ||
52 | /** | 53 | /** |
53 | * process the associate request. | 54 | * process the associate request. |
54 | * @param pin the incoming request parameters | 55 | * @param pin the incoming request parameters |
55 | * @param pout the store for the response parameters | 56 | * @param pout the store for the response parameters |
56 | */ | 57 | */ |
57 | void associate(const params_t& pin,params_t& pout); | 58 | void associate(const params_t& pin,params_t& pout); |
58 | /** | 59 | /** |
59 | * process the checkid_immediate request. | 60 | * process the checkid_immediate request. |
60 | * @param pin the incoming request parameters | 61 | * @param pin the incoming request parameters |
61 | * @param return_to reference to the object to store return_to url to | 62 | * @param return_to reference to the object to store return_to url to |
62 | * @param pout the response parameters | 63 | * @param pout the response parameters |
64 | * @param ext pointer to the extension hooks object | ||
63 | * @throw exception in case of errors or negative reply | 65 | * @throw exception in case of errors or negative reply |
64 | */ | 66 | */ |
65 | void checkid_immediate(const params_t& pin,string& return_to,params_t& pout); | 67 | void checkid_immediate(const params_t& pin,string& return_to,params_t& pout,extension_t *ext=0); |
66 | /** | 68 | /** |
67 | * process the checkid_setup request. | 69 | * process the checkid_setup request. |
68 | * @param pin the incoming request parameters | 70 | * @param pin the incoming request parameters |
69 | * @param return_to reference to the object to store return_to url to | 71 | * @param return_to reference to the object to store return_to url to |
70 | * @param pout the response parameters | 72 | * @param pout the response parameters |
73 | * @param ext pointer to the extension hooks object | ||
71 | * @throw exception in case of errors or negative reply | 74 | * @throw exception in case of errors or negative reply |
72 | */ | 75 | */ |
73 | void checkid_setup(const params_t& pin,string& return_to,params_t& pout); | 76 | void checkid_setup(const params_t& pin,string& return_to,params_t& pout,extension_t *ext=0); |
74 | /** | 77 | /** |
75 | * the actual functionality behind checkid_immediate() and | 78 | * the actual functionality behind checkid_immediate() and |
76 | * checkid_setup() | 79 | * checkid_setup() |
77 | * @param mode the request being processed (either | 80 | * @param mode the request being processed (either |
78 | * mode_checkid_immediate or mode_checkid_setup) | 81 | * mode_checkid_immediate or mode_checkid_setup) |
79 | * @param pin the incoming request parameters | 82 | * @param pin the incoming request parameters |
80 | * @param return_to reference to the object to store return_to url to | 83 | * @param return_to reference to the object to store return_to url to |
81 | * @param pout the response parameters | 84 | * @param pout the response parameters |
85 | * @param ext pointer to the extension hooks object | ||
82 | * @throw exception in case of errors or negative reply | 86 | * @throw exception in case of errors or negative reply |
83 | */ | 87 | */ |
84 | void checkid_(mode_t mode,const params_t& pin,string& return_to,params_t& pout); | 88 | void checkid_(mode_t mode,const params_t& pin,string& return_to,params_t& pout,extension_t *ext=0); |
85 | /** | 89 | /** |
86 | * process the check_authentication request. | 90 | * process the check_authentication request. |
87 | * @param pin incoming request parameters | 91 | * @param pin incoming request parameters |
88 | * @param pout response parameters | 92 | * @param pout response parameters |
89 | */ | 93 | */ |
90 | void check_authentication(const params_t& pin,params_t& pout); | 94 | void check_authentication(const params_t& pin,params_t& pout); |
91 | }; | 95 | }; |
92 | 96 | ||
93 | } | 97 | } |
94 | 98 | ||
95 | #endif /* __OPKELE_SERVER_H */ | 99 | #endif /* __OPKELE_SERVER_H */ |