summaryrefslogtreecommitdiffabout
path: root/include
authorMichael Krelin <hacker@klever.net>2007-12-09 17:22:06 (UTC)
committer Michael Krelin <hacker@klever.net>2007-12-09 22:08:24 (UTC)
commitc34adc6e274c3dbb63af99ca566000e7d218244c (patch) (unidiff)
tree705624c208deb4eaf8d07c119a883e6f4f35236e /include
parent60fdaff7888b455b4d07eadc905cefd20f1ddd3c (diff)
downloadlibopkele-c34adc6e274c3dbb63af99ca566000e7d218244c.zip
libopkele-c34adc6e274c3dbb63af99ca566000e7d218244c.tar.gz
libopkele-c34adc6e274c3dbb63af99ca566000e7d218244c.tar.bz2
reworked identity resolution and service discovery
The discovery, which does both XRDS-based (Yadis, XRI, for XRI, using proxy) and HTML-based search, now returns results in opkele:idiscovery_t structure. It uses expat-based parser idigger_t, which itself is not exposed via any header files, but hidden in lib/discovery.cc, the discovery testing program is renamed from openid_resolve to idiscover. Signed-off-by: Michael Krelin <hacker@klever.net>
Diffstat (limited to 'include') (more/less context) (ignore whitespace changes)
-rw-r--r--include/Makefile.am2
-rw-r--r--include/opkele/discovery.h33
-rw-r--r--include/opkele/exception.h19
-rw-r--r--include/opkele/openid_service_resolver.h118
-rw-r--r--include/opkele/types.h63
-rw-r--r--include/opkele/uris.h13
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
@@ -12,7 +12,7 @@ nobase_include_HEADERS = \
12 opkele/xconsumer.h \ 12 opkele/xconsumer.h \
13 opkele/xserver.h \ 13 opkele/xserver.h \
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
17EXTRA_DIST = \ 17EXTRA_DIST = \
18 opkele/data.h \ 18 opkele/data.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
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 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
@@ -203,6 +203,25 @@ namespace opkele {
203 }; 203 };
204 204
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
207 * programmer error 226 * programmer error
208 */ 227 */
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
12namespace 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
@@ -11,6 +11,7 @@
11#include <string> 11#include <string>
12#include <map> 12#include <map>
13#include <memory> 13#include <memory>
14#include <set>
14 15
15namespace opkele { 16namespace opkele {
16 using std::vector; 17 using std::vector;
@@ -18,6 +19,8 @@ namespace opkele {
18 using std::map; 19 using std::map;
19 using std::ostream; 20 using std::ostream;
20 using std::auto_ptr; 21 using std::auto_ptr;
22 using std::multimap;
23 using std::set;
21 24
22 /** 25 /**
23 * the OpenID operation mode 26 * the OpenID operation mode
@@ -167,6 +170,66 @@ namespace opkele {
167 */ 170 */
168 ostream& operator << (ostream& o,const params_t& p); 171 ostream& operator << (ostream& o,const params_t& p);
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}
171 234
172#endif /* __OPKELE_TYPES_H */ 235#endif /* __OPKELE_TYPES_H */
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
@@ -1,10 +1,15 @@
1#ifndef __OPKELE_URIS_H 1#ifndef __OPKELE_URIS_H
2#define __OPKELE_URIS_H 2#define __OPKELE_URIS_H
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
10#endif /* __OPKELE_URIS_H */ 15#endif /* __OPKELE_URIS_H */