-rw-r--r-- | include/Makefile.am | 2 | ||||
-rw-r--r-- | include/opkele/discovery.h | 33 | ||||
-rw-r--r-- | include/opkele/exception.h | 19 | ||||
-rw-r--r-- | include/opkele/openid_service_resolver.h | 118 | ||||
-rw-r--r-- | include/opkele/types.h | 63 | ||||
-rw-r--r-- | include/opkele/uris.h | 13 |
6 files changed, 125 insertions, 123 deletions
diff --git a/include/Makefile.am b/include/Makefile.am index 23c7e0d..0c2928d 100644 --- a/include/Makefile.am +++ b/include/Makefile.am | |||
@@ -14,3 +14,3 @@ nobase_include_HEADERS = \ | |||
14 | opkele/curl.h opkele/expat.h \ | 14 | opkele/curl.h opkele/expat.h \ |
15 | opkele/openid_service_resolver.h \ | 15 | opkele/discovery.h \ |
16 | opkele/uris.h | 16 | opkele/uris.h |
diff --git a/include/opkele/discovery.h b/include/opkele/discovery.h new file mode 100644 index 0000000..5d7129b --- a/dev/null +++ b/include/opkele/discovery.h | |||
@@ -0,0 +1,33 @@ | |||
1 | #ifndef __OPKELE_DISCOVERY_H | ||
2 | #define __OPKELE_DISCOVERY_H | ||
3 | |||
4 | #include <string> | ||
5 | #include <opkele/types.h> | ||
6 | |||
7 | namespace 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 | string normalized_id; | ||
16 | string canonicalized_id; | ||
17 | xrd::XRD_t xrd; | ||
18 | |||
19 | idiscovery_t(const string& i) { | ||
20 | idiscover(*this,i); | ||
21 | } | ||
22 | idiscovery_t(const char *i) { | ||
23 | idiscover(*this,i); | ||
24 | } | ||
25 | |||
26 | void clear() { | ||
27 | normalized_id.clear(); canonicalized_id.clear(); | ||
28 | xrd.clear(); | ||
29 | } | ||
30 | }; | ||
31 | } | ||
32 | |||
33 | #endif /* __OPKELE_DISCOVERY_H */ | ||
diff --git a/include/opkele/exception.h b/include/opkele/exception.h index 753a818..a654d59 100644 --- a/include/opkele/exception.h +++ b/include/opkele/exception.h | |||
@@ -205,2 +205,21 @@ namespace opkele { | |||
205 | /** | 205 | /** |
206 | * exception thrown in case of failed discovery | ||
207 | */ | ||
208 | class failed_discovery : public exception { | ||
209 | public: | ||
210 | failed_discovery(OPKELE_E_PARS) | ||
211 | : exception(OPKELE_E_CONS) { } | ||
212 | }; | ||
213 | |||
214 | /** | ||
215 | * unsuccessfull xri resolution | ||
216 | */ | ||
217 | class failed_xri_resolution : public failed_discovery { | ||
218 | public: | ||
219 | long _code; | ||
220 | failed_xri_resolution(OPKELE_E_PARS,long _c=-1) | ||
221 | : failed_discovery(OPKELE_E_CONS), _code(_c) { } | ||
222 | }; | ||
223 | |||
224 | /** | ||
206 | * not implemented (think pure virtual) member function executed, signfies | 225 | * not implemented (think pure virtual) member function executed, signfies |
diff --git a/include/opkele/openid_service_resolver.h b/include/opkele/openid_service_resolver.h deleted file mode 100644 index 64edd28..0000000 --- a/include/opkele/openid_service_resolver.h +++ b/dev/null | |||
@@ -1,118 +0,0 @@ | |||
1 | #ifndef __OPKELE_OPENID_SERVICE_RESOLVER_H | ||
2 | #define __OPKELE_OPENID_SERVICE_RESOLVER_H | ||
3 | |||
4 | #include <climits> | ||
5 | #include <string> | ||
6 | #include <list> | ||
7 | #include <set> | ||
8 | #include <map> | ||
9 | #include <opkele/curl.h> | ||
10 | #include <opkele/expat.h> | ||
11 | |||
12 | namespace opkele { | ||
13 | using std::list; | ||
14 | using std::string; | ||
15 | using std::set; | ||
16 | using std::map; | ||
17 | |||
18 | struct openid_auth_SEP_t { | ||
19 | long priority; | ||
20 | set<string> xrd_Type; | ||
21 | string xrd_URI; | ||
22 | string openid_Delegate; | ||
23 | |||
24 | openid_auth_SEP_t() : priority(LONG_MAX) { } | ||
25 | }; | ||
26 | |||
27 | struct openid_auth_info_t { | ||
28 | string canonical_id; | ||
29 | openid_auth_SEP_t auth_SEP; | ||
30 | }; | ||
31 | |||
32 | |||
33 | class openid_service_resolver_t : public util::curl_t, public util::expat_t { | ||
34 | public: | ||
35 | string xri_proxy; | ||
36 | |||
37 | openid_service_resolver_t(const string& xp=""); | ||
38 | ~openid_service_resolver_t() throw() { } | ||
39 | |||
40 | const openid_auth_info_t& resolve(const string& id); | ||
41 | |||
42 | enum state_t { | ||
43 | state_parse = 0, | ||
44 | state_stopping_head, state_stopping_body, | ||
45 | state_stopping_size | ||
46 | }; | ||
47 | state_t state; | ||
48 | |||
49 | struct parser_node_t { | ||
50 | string element; | ||
51 | string content; | ||
52 | typedef map<string,string> attrs_t; | ||
53 | attrs_t attrs; | ||
54 | bool skip_text, skip_tags; | ||
55 | openid_auth_info_t auth_info; | ||
56 | |||
57 | parser_node_t(const XML_Char *n,const XML_Char **a) | ||
58 | : skip_text(true), skip_tags(true) | ||
59 | { | ||
60 | element = n; | ||
61 | for(;*a;a+=2) | ||
62 | attrs[a[0]] = a[1]; | ||
63 | } | ||
64 | |||
65 | }; | ||
66 | |||
67 | class parser_tree_t : public list<parser_node_t> { | ||
68 | public: | ||
69 | const_reference top() const { return back(); } | ||
70 | reference top() { return back(); } | ||
71 | |||
72 | const_reference parent() const { | ||
73 | const_reverse_iterator rv = rbegin(); | ||
74 | return *(++rv); } | ||
75 | reference parent() { | ||
76 | reverse_iterator rv = rbegin(); | ||
77 | return *(++rv); } | ||
78 | |||
79 | inline void pop() { pop_back(); } | ||
80 | inline void push(const_reference e) { push_back(e); } | ||
81 | |||
82 | void push(const XML_Char *n,const XML_Char **a) { | ||
83 | parser_node_t nn(n,a); | ||
84 | if(empty()) | ||
85 | nn.skip_text = nn.skip_tags = true; | ||
86 | else{ | ||
87 | const_reference t = top(); | ||
88 | nn.skip_text = t.skip_text; nn.skip_tags = t.skip_tags; | ||
89 | } | ||
90 | push(nn); | ||
91 | } | ||
92 | }; | ||
93 | parser_tree_t tree; | ||
94 | |||
95 | void start_element(const XML_Char *n,const XML_Char **a); | ||
96 | void end_element(const XML_Char *n); | ||
97 | void character_data(const XML_Char *s,int l); | ||
98 | |||
99 | string xrds_location; | ||
100 | openid_auth_SEP_t html_SEP; | ||
101 | openid_auth_info_t auth_info; | ||
102 | |||
103 | void pop_tag(); | ||
104 | |||
105 | size_t write(void *p,size_t s,size_t nm); | ||
106 | |||
107 | string http_content_type; | ||
108 | |||
109 | size_t header(void *p,size_t s,size_t nm); | ||
110 | |||
111 | bool xri_mode; | ||
112 | |||
113 | void discover_service(const string& url,bool xri=false); | ||
114 | }; | ||
115 | |||
116 | } | ||
117 | |||
118 | #endif /* __OPKELE_OPENID_SERVICE_RESOLVER_H */ | ||
diff --git a/include/opkele/types.h b/include/opkele/types.h index f732a1e..520618d 100644 --- a/include/opkele/types.h +++ b/include/opkele/types.h | |||
@@ -13,2 +13,3 @@ | |||
13 | #include <memory> | 13 | #include <memory> |
14 | #include <set> | ||
14 | 15 | ||
@@ -20,2 +21,4 @@ namespace opkele { | |||
20 | using std::auto_ptr; | 21 | using std::auto_ptr; |
22 | using std::multimap; | ||
23 | using std::set; | ||
21 | 24 | ||
@@ -169,2 +172,62 @@ namespace opkele { | |||
169 | 172 | ||
173 | namespace xrd { | ||
174 | |||
175 | struct priority_compare { | ||
176 | inline bool operator()(long a,long b) const { | ||
177 | return (a<0) ? false : (b<0) ? false : (a<b); | ||
178 | } | ||
179 | }; | ||
180 | |||
181 | template <typename _DT> | ||
182 | class priority_map : public multimap<long,_DT,priority_compare> { | ||
183 | typedef multimap<long,_DT,priority_compare> map_type; | ||
184 | public: | ||
185 | |||
186 | inline _DT& add(long priority,const _DT& d) { | ||
187 | return insert(typename map_type::value_type(priority,d))->second; | ||
188 | } | ||
189 | }; | ||
190 | |||
191 | typedef priority_map<string> canonical_ids_t; | ||
192 | typedef priority_map<string> local_ids_t; | ||
193 | typedef set<string> types_t; | ||
194 | typedef priority_map<string> uris_t; | ||
195 | |||
196 | class service_t { | ||
197 | public: | ||
198 | types_t types; | ||
199 | uris_t uris; | ||
200 | local_ids_t local_ids; | ||
201 | |||
202 | void clear() { | ||
203 | types.clear(); | ||
204 | uris.clear(); local_ids.clear(); | ||
205 | } | ||
206 | }; | ||
207 | typedef priority_map<service_t> services_t; | ||
208 | |||
209 | class XRD_t { | ||
210 | public: | ||
211 | time_t expires; | ||
212 | |||
213 | canonical_ids_t canonical_ids; | ||
214 | local_ids_t local_ids; | ||
215 | services_t services; | ||
216 | |||
217 | void clear() { | ||
218 | expires = 0; | ||
219 | canonical_ids.clear(); local_ids.clear(); | ||
220 | services.clear(); | ||
221 | } | ||
222 | bool empty() const { | ||
223 | return | ||
224 | canonical_ids.empty() | ||
225 | && local_ids.empty() | ||
226 | && services.empty(); | ||
227 | } | ||
228 | |||
229 | }; | ||
230 | |||
231 | } | ||
232 | |||
170 | } | 233 | } |
diff --git a/include/opkele/uris.h b/include/opkele/uris.h index 9a6a3cd..a432b13 100644 --- a/include/opkele/uris.h +++ b/include/opkele/uris.h | |||
@@ -3,7 +3,12 @@ | |||
3 | 3 | ||
4 | #define NSURI_XRDS "xri://$xrds" | 4 | #define NSURI_XRDS "xri://$xrds" |
5 | #define NSURI_XRD "xri://$xrd*($v*2.0)" | 5 | #define NSURI_XRD "xri://$xrd*($v*2.0)" |
6 | #define NSURI_OPENID10 "http://openid.net/xmlns/1.0" | 6 | #define NSURI_OPENID10 "http://openid.net/xmlns/1.0" |
7 | 7 | ||
8 | #define STURI_OPENID10 "http://openid.net/signon/1.0" | 8 | #define STURI_OPENID10 "http://openid.net/signon/1.0" |
9 | #define STURI_OPENID11 "http://openid.net/signon/1.1" | ||
10 | #define STURI_OPENID20 "http://specs.openid.net/auth/2.0/signon" | ||
11 | #define STURI_OPENID20_OP"http://specs.openid.net/auth/2.0/server" | ||
12 | |||
13 | #define IDURI_SELECT20 "http://specs.openid.net/auth/2.0/identifier_select" | ||
9 | 14 | ||