summaryrefslogtreecommitdiffabout
path: root/include/opkele
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) (side-by-side diff)
treefb4db0ee7b679a1957c63abbe6f6af1d2fa82531 /include/opkele
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/opkele') (more/less context) (show whitespace changes)
-rw-r--r--include/opkele/openid_service_resolver.h118
-rw-r--r--include/opkele/uris.h10
2 files changed, 128 insertions, 0 deletions
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 @@
+#ifndef __OPKELE_OPENID_SERVICE_RESOLVER_H
+#define __OPKELE_OPENID_SERVICE_RESOLVER_H
+
+#include <climits>
+#include <string>
+#include <list>
+#include <set>
+#include <map>
+#include <opkele/curl.h>
+#include <opkele/expat.h>
+
+namespace opkele {
+ using std::list;
+ using std::string;
+ using std::set;
+ using std::map;
+
+ struct openid_auth_SEP_t {
+ long priority;
+ set<string> xrd_Type;
+ string xrd_URI;
+ string openid_Delegate;
+
+ openid_auth_SEP_t() : priority(LONG_MAX) { }
+ };
+
+ struct openid_auth_info_t {
+ string canonical_id;
+ openid_auth_SEP_t auth_SEP;
+ };
+
+
+ class openid_service_resolver_t : public util::curl_t, public util::expat_t {
+ public:
+ string xri_proxy;
+
+ openid_service_resolver_t(const string& xp="");
+ ~openid_service_resolver_t() throw() { }
+
+ const openid_auth_info_t& resolve(const string& id);
+
+ enum state_t {
+ state_parse = 0,
+ state_stopping_head, state_stopping_body,
+ state_stopping_size
+ };
+ state_t state;
+
+ struct parser_node_t {
+ string element;
+ string content;
+ typedef map<string,string> attrs_t;
+ attrs_t attrs;
+ bool skip_text, skip_tags;
+ openid_auth_info_t auth_info;
+
+ parser_node_t(const XML_Char *n,const XML_Char **a)
+ : skip_text(true), skip_tags(true)
+ {
+ element = n;
+ for(;*a;a+=2)
+ attrs[a[0]] = a[1];
+ }
+
+ };
+
+ class parser_tree_t : public list<parser_node_t> {
+ public:
+ const_reference top() const { return back(); }
+ reference top() { return back(); }
+
+ const_reference parent() const {
+ const_reverse_iterator rv = rbegin();
+ return *(++rv); }
+ reference parent() {
+ reverse_iterator rv = rbegin();
+ return *(++rv); }
+
+ inline void pop() { pop_back(); }
+ inline void push(const_reference e) { push_back(e); }
+
+ void push(const XML_Char *n,const XML_Char **a) {
+ parser_node_t nn(n,a);
+ if(empty())
+ nn.skip_text = nn.skip_tags = true;
+ else{
+ const_reference t = top();
+ nn.skip_text = t.skip_text; nn.skip_tags = t.skip_tags;
+ }
+ push(nn);
+ }
+ };
+ parser_tree_t tree;
+
+ void start_element(const XML_Char *n,const XML_Char **a);
+ void end_element(const XML_Char *n);
+ void character_data(const XML_Char *s,int l);
+
+ string xrds_location;
+ openid_auth_SEP_t html_SEP;
+ openid_auth_info_t auth_info;
+
+ void pop_tag();
+
+ size_t write(void *p,size_t s,size_t nm);
+
+ string http_content_type;
+
+ size_t header(void *p,size_t s,size_t nm);
+
+ bool xri_mode;
+
+ void discover_service(const string& url,bool xri=false);
+ };
+
+}
+
+#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 @@
+#ifndef __OPKELE_URIS_H
+#define __OPKELE_URIS_H
+
+#define NSURI_XRDS "xri://$xrds"
+#define NSURI_XRD "xri://$xrd*($v*2.0)"
+#define NSURI_OPENID10 "http://openid.net/xmlns/1.0"
+
+#define STURI_OPENID10 "http://openid.net/signon/1.0"
+
+#endif /* __OPKELE_URIS_H */