summaryrefslogtreecommitdiffabout
path: root/include
authorMichael Krelin <hacker@klever.net>2007-12-02 21:48:18 (UTC)
committer Michael Krelin <hacker@klever.net>2007-12-02 21:51:08 (UTC)
commit262f1579f0a9138a01f06afea06d00155cefd4b5 (patch) (unidiff)
treefb4db0ee7b679a1957c63abbe6f6af1d2fa82531 /include
parent73d98f3652b498b9a74b183bef395714c7d73fda (diff)
downloadlibopkele-262f1579f0a9138a01f06afea06d00155cefd4b5.zip
libopkele-262f1579f0a9138a01f06afea06d00155cefd4b5.tar.gz
libopkele-262f1579f0a9138a01f06afea06d00155cefd4b5.tar.bz2
first cut on XRI resolver
This commit adds openid service resolver that does discovery using XRI (proxy only), Yadis protocol and html-based discovery. It uses expat as xml parsing engine, which makes it a bit more strict about html it receives, but I think failing to discover links in *severely* broken html is better than misdetecting links, hidden in comments or such. This is highly experimental code and needs more thoughts and testing. Thanks everyone pushing me towards this development. Namely Joseph, John, Gen. Signed-off-by: Michael Krelin <hacker@klever.net>
Diffstat (limited to 'include') (more/less context) (ignore whitespace changes)
-rw-r--r--include/Makefile.am8
-rw-r--r--include/opkele/openid_service_resolver.h118
-rw-r--r--include/opkele/uris.h10
3 files changed, 133 insertions, 3 deletions
diff --git a/include/Makefile.am b/include/Makefile.am
index 0385cfb..23c7e0d 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -5,13 +5,15 @@ nobase_include_HEADERS = \
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 opkele/extension.h \
10 opkele/sreg.h \ 10 opkele/sreg.h \
11 opkele/extension_chain.h \ 11 opkele/extension_chain.h \
12 opkele/xconsumer.h \ 12 opkele/xconsumer.h \
13 opkele/xserver.h 13 opkele/xserver.h \
14 opkele/curl.h opkele/expat.h \
15 opkele/openid_service_resolver.h \
16 opkele/uris.h
14EXTRA_DIST = \ 17EXTRA_DIST = \
15 opkele/data.h \ 18 opkele/data.h \
16 opkele/util.h \ 19 opkele/util.h
17 opkele/curl.h opkele/expat.h
diff --git a/include/opkele/openid_service_resolver.h b/include/opkele/openid_service_resolver.h
new file mode 100644
index 0000000..64edd28
--- a/dev/null
+++ b/include/opkele/openid_service_resolver.h
@@ -0,0 +1,118 @@
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/uris.h b/include/opkele/uris.h
new file mode 100644
index 0000000..9a6a3cd
--- a/dev/null
+++ b/include/opkele/uris.h
@@ -0,0 +1,10 @@
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 STURI_OPENID10 "http://openid.net/signon/1.0"
9
10#endif /* __OPKELE_URIS_H */