summaryrefslogtreecommitdiffabout
path: root/include/opkele
Side-by-side diff
Diffstat (limited to 'include/opkele') (more/less context) (ignore whitespace changes)
-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
5 files changed, 124 insertions, 122 deletions
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 @@
+#ifndef __OPKELE_DISCOVERY_H
+#define __OPKELE_DISCOVERY_H
+
+#include <string>
+#include <opkele/types.h>
+
+namespace opkele {
+ using std::string;
+
+ struct idiscovery_t;
+
+ void idiscover(idiscovery_t& result,const string& identity);
+
+ struct idiscovery_t {
+ string normalized_id;
+ string canonicalized_id;
+ xrd::XRD_t xrd;
+
+ idiscovery_t(const string& i) {
+ idiscover(*this,i);
+ }
+ idiscovery_t(const char *i) {
+ idiscover(*this,i);
+ }
+
+ void clear() {
+ normalized_id.clear(); canonicalized_id.clear();
+ xrd.clear();
+ }
+ };
+}
+
+#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
@@ -204,4 +204,23 @@ namespace opkele {
/**
+ * exception thrown in case of failed discovery
+ */
+ class failed_discovery : public exception {
+ public:
+ failed_discovery(OPKELE_E_PARS)
+ : exception(OPKELE_E_CONS) { }
+ };
+
+ /**
+ * unsuccessfull xri resolution
+ */
+ class failed_xri_resolution : public failed_discovery {
+ public:
+ long _code;
+ failed_xri_resolution(OPKELE_E_PARS,long _c=-1)
+ : failed_discovery(OPKELE_E_CONS), _code(_c) { }
+ };
+
+ /**
* not implemented (think pure virtual) member function executed, signfies
* programmer error
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 @@
-#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/types.h b/include/opkele/types.h
index f732a1e..520618d 100644
--- a/include/opkele/types.h
+++ b/include/opkele/types.h
@@ -12,4 +12,5 @@
#include <map>
#include <memory>
+#include <set>
namespace opkele {
@@ -19,4 +20,6 @@ namespace opkele {
using std::ostream;
using std::auto_ptr;
+ using std::multimap;
+ using std::set;
/**
@@ -168,4 +171,64 @@ namespace opkele {
ostream& operator << (ostream& o,const params_t& p);
+ namespace xrd {
+
+ struct priority_compare {
+ inline bool operator()(long a,long b) const {
+ return (a<0) ? false : (b<0) ? false : (a<b);
+ }
+ };
+
+ template <typename _DT>
+ class priority_map : public multimap<long,_DT,priority_compare> {
+ typedef multimap<long,_DT,priority_compare> map_type;
+ public:
+
+ inline _DT& add(long priority,const _DT& d) {
+ return insert(typename map_type::value_type(priority,d))->second;
+ }
+ };
+
+ typedef priority_map<string> canonical_ids_t;
+ typedef priority_map<string> local_ids_t;
+ typedef set<string> types_t;
+ typedef priority_map<string> uris_t;
+
+ class service_t {
+ public:
+ types_t types;
+ uris_t uris;
+ local_ids_t local_ids;
+
+ void clear() {
+ types.clear();
+ uris.clear(); local_ids.clear();
+ }
+ };
+ typedef priority_map<service_t> services_t;
+
+ class XRD_t {
+ public:
+ time_t expires;
+
+ canonical_ids_t canonical_ids;
+ local_ids_t local_ids;
+ services_t services;
+
+ void clear() {
+ expires = 0;
+ canonical_ids.clear(); local_ids.clear();
+ services.clear();
+ }
+ bool empty() const {
+ return
+ canonical_ids.empty()
+ && local_ids.empty()
+ && services.empty();
+ }
+
+ };
+
+ }
+
}
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
@@ -2,9 +2,14 @@
#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 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"
+#define STURI_OPENID10 "http://openid.net/signon/1.0"
+#define STURI_OPENID11 "http://openid.net/signon/1.1"
+#define STURI_OPENID20 "http://specs.openid.net/auth/2.0/signon"
+#define STURI_OPENID20_OP "http://specs.openid.net/auth/2.0/server"
+
+#define IDURI_SELECT20 "http://specs.openid.net/auth/2.0/identifier_select"
#endif /* __OPKELE_URIS_H */