summaryrefslogtreecommitdiffabout
path: root/include
Side-by-side diff
Diffstat (limited to 'include') (more/less context) (ignore whitespace changes)
-rw-r--r--include/Makefile.am8
-rw-r--r--include/opkele/discovery.h33
-rw-r--r--include/opkele/exception.h19
-rw-r--r--include/opkele/expat.h91
-rw-r--r--include/opkele/types.h63
-rw-r--r--include/opkele/uris.h15
6 files changed, 226 insertions, 3 deletions
diff --git a/include/Makefile.am b/include/Makefile.am
index b31786d..0c2928d 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -1,17 +1,19 @@
nobase_include_HEADERS = \
opkele/acconfig.h \
opkele/opkele-config.h \
opkele/types.h \
opkele/association.h \
opkele/exception.h \
opkele/server.h \
opkele/consumer.h \
opkele/extension.h \
opkele/sreg.h \
opkele/extension_chain.h \
opkele/xconsumer.h \
- opkele/xserver.h
+ opkele/xserver.h \
+ opkele/curl.h opkele/expat.h \
+ opkele/discovery.h \
+ opkele/uris.h
EXTRA_DIST = \
opkele/data.h \
- opkele/util.h \
- opkele/curl.h
+ opkele/util.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 @@
+#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 2ff44b7..8913665 100644
--- a/include/opkele/exception.h
+++ b/include/opkele/exception.h
@@ -191,45 +191,64 @@ namespace opkele {
/**
* network operation related error occured
*/
class exception_network : public exception {
public:
exception_network(OPKELE_E_PARS)
: exception(OPKELE_E_CONS) { }
};
/**
* network operation related error occured, specifically, related to
* libcurl
*/
class exception_curl : public exception_network {
public:
CURLcode _error;
string _curl_string;
exception_curl(OPKELE_E_PARS);
exception_curl(OPKELE_E_PARS,CURLcode e);
~exception_curl() throw() { }
};
/**
+ * 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
*/
class not_implemented : public exception {
public:
not_implemented(OPKELE_E_PARS)
: exception(OPKELE_E_CONS) { }
};
/**
* internal error, indicates internal libopkele problem
*/
class internal_error : public exception {
public:
internal_error(OPKELE_E_PARS)
: exception(OPKELE_E_CONS) { }
};
}
#endif /* __OPKELE_EXCEPTION_H */
diff --git a/include/opkele/expat.h b/include/opkele/expat.h
new file mode 100644
index 0000000..60c41ac
--- a/dev/null
+++ b/include/opkele/expat.h
@@ -0,0 +1,91 @@
+#ifndef __OPKELE_EXPAT_H
+#define __OPKELE_EXPAT_H
+
+#include <cassert>
+#include <expat.h>
+
+namespace opkele {
+
+ namespace util {
+
+ class expat_t {
+ public:
+ XML_Parser _x;
+
+ expat_t() : _x(0) { }
+ expat_t(XML_Parser x) : _x(x) { }
+ virtual ~expat_t() throw();
+
+ expat_t& operator=(XML_Parser x);
+
+ operator const XML_Parser(void) const { return _x; }
+ operator XML_Parser(void) { return _x; }
+
+ inline bool parse(const char *s,int len,bool final=false) {
+ assert(_x);
+ return XML_Parse(_x,s,len,final);
+ }
+
+ virtual void start_element(const XML_Char *n,const XML_Char **a) { }
+ virtual void end_element(const XML_Char *n) { }
+ void set_element_handler();
+
+ virtual void character_data(const XML_Char *s,int l) { }
+ void set_character_data_handler();
+
+ virtual void processing_instruction(const XML_Char *t,const XML_Char *d) { }
+ void set_processing_instruction_handler();
+
+ virtual void comment(const XML_Char *d) { }
+ void set_comment_handler();
+
+ virtual void start_cdata_section() { }
+ virtual void end_cdata_section() { }
+ void set_cdata_section_handler();
+
+ virtual void default_handler(const XML_Char *s,int l) { }
+ void set_default_handler();
+ void set_default_handler_expand();
+
+ virtual void start_namespace_decl(const XML_Char *p,const XML_Char *u) { }
+ virtual void end_namespace_decl(const XML_Char *p) { }
+ void set_namespace_decl_handler();
+
+ inline enum XML_Error get_error_code() {
+ assert(_x); return XML_GetErrorCode(_x); }
+ static inline const XML_LChar *error_string(XML_Error c) {
+ return XML_ErrorString(c); }
+
+ inline long get_current_byte_index() {
+ assert(_x); return XML_GetCurrentByteIndex(_x); }
+ inline int get_current_line_number() {
+ assert(_x); return XML_GetCurrentLineNumber(_x); }
+ inline int get_current_column_number() {
+ assert(_x); return XML_GetCurrentColumnNumber(_x); }
+
+ inline void set_user_data() {
+ assert(_x); XML_SetUserData(_x,this); }
+
+ inline bool set_base(const XML_Char *b) {
+ assert(_x); return XML_SetBase(_x,b); }
+ inline const XML_Char *get_base() {
+ assert(_x); return XML_GetBase(_x); }
+
+ inline int get_specified_attribute_count() {
+ assert(_x); return XML_GetSpecifiedAttributeCount(_x); }
+
+ inline bool set_param_entity_parsing(enum XML_ParamEntityParsing c) {
+ assert(_x); return XML_SetParamEntityParsing(_x,c); }
+
+ inline static XML_Parser parser_create(const XML_Char *e=0) {
+ return XML_ParserCreate(e); }
+ inline static XML_Parser parser_create_ns(const XML_Char *e=0,XML_Char s='\t') {
+ return XML_ParserCreateNS(e,s); }
+
+ };
+
+ }
+
+}
+
+#endif /* __OPKELE_EXPAT_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
@@ -1,44 +1,47 @@
#ifndef __OPKELE_TYPES_H
#define __OPKELE_TYPES_H
/**
* @file
* @brief various types declarations
*/
#include <ostream>
#include <vector>
#include <string>
#include <map>
#include <memory>
+#include <set>
namespace opkele {
using std::vector;
using std::string;
using std::map;
using std::ostream;
using std::auto_ptr;
+ using std::multimap;
+ using std::set;
/**
* the OpenID operation mode
*/
typedef enum _mode_t {
mode_associate,
mode_checkid_immediate,
mode_checkid_setup,
mode_check_association
} mode_t;
/**
* the association secret container
*/
class secret_t : public vector<unsigned char> {
public:
/**
* xor the secret and hmac together and encode, using base64
* @param key_sha1 pointer to the sha1 digest
* @param rv reference to the return value
*/
void enxor_to_base64(const unsigned char *key_sha1,string& rv) const;
/**
@@ -146,27 +149,87 @@ namespace opkele {
* @param secret the secret used for signing
* @param sig reference to the string, containing base64-encoded
* result
* @param slist the comma-separated list of fields to sign
* @param prefix the string to prepend to parameter names
*/
void sign(secret_t secret,string& sig,const string& slist,const char *prefix=0) const;
/**
* append parameters to the URL as a GET-request parameters.
* @param url the base URL
* @param prefix the string to prepend to parameter names
* @return the ready-to-use location
*/
string append_query(const string& url,const char *prefix = "openid.") const;
};
/**
* dump the key/value pairs for the parameters to the stream.
* @param o output stream
* @param p the parameters
*/
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();
+ }
+
+ };
+
+ }
+
}
#endif /* __OPKELE_TYPES_H */
diff --git a/include/opkele/uris.h b/include/opkele/uris.h
new file mode 100644
index 0000000..a432b13
--- a/dev/null
+++ b/include/opkele/uris.h
@@ -0,0 +1,15 @@
+#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"
+#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 */