-rw-r--r-- | include/Makefile.am | 8 | ||||
-rw-r--r-- | include/opkele/discovery.h | 33 | ||||
-rw-r--r-- | include/opkele/exception.h | 19 | ||||
-rw-r--r-- | include/opkele/expat.h | 91 | ||||
-rw-r--r-- | include/opkele/types.h | 63 | ||||
-rw-r--r-- | include/opkele/uris.h | 15 |
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 | |||
@@ -10,8 +10,10 @@ nobase_include_HEADERS = \ | |||
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/discovery.h \ | ||
16 | opkele/uris.h | ||
14 | EXTRA_DIST = \ | 17 | EXTRA_DIST = \ |
15 | opkele/data.h \ | 18 | opkele/data.h \ |
16 | opkele/util.h \ | 19 | opkele/util.h |
17 | opkele/curl.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 | |||
7 | namespace 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 2ff44b7..8913665 100644 --- a/include/opkele/exception.h +++ b/include/opkele/exception.h | |||
@@ -212,6 +212,25 @@ namespace opkele { | |||
212 | }; | 212 | }; |
213 | 213 | ||
214 | /** | 214 | /** |
215 | * exception thrown in case of failed discovery | ||
216 | */ | ||
217 | class failed_discovery : public exception { | ||
218 | public: | ||
219 | failed_discovery(OPKELE_E_PARS) | ||
220 | : exception(OPKELE_E_CONS) { } | ||
221 | }; | ||
222 | |||
223 | /** | ||
224 | * unsuccessfull xri resolution | ||
225 | */ | ||
226 | class failed_xri_resolution : public failed_discovery { | ||
227 | public: | ||
228 | long _code; | ||
229 | failed_xri_resolution(OPKELE_E_PARS,long _c=-1) | ||
230 | : failed_discovery(OPKELE_E_CONS), _code(_c) { } | ||
231 | }; | ||
232 | |||
233 | /** | ||
215 | * not implemented (think pure virtual) member function executed, signfies | 234 | * not implemented (think pure virtual) member function executed, signfies |
216 | * programmer error | 235 | * programmer error |
217 | */ | 236 | */ |
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 @@ | |||
1 | #ifndef __OPKELE_EXPAT_H | ||
2 | #define __OPKELE_EXPAT_H | ||
3 | |||
4 | #include <cassert> | ||
5 | #include <expat.h> | ||
6 | |||
7 | namespace opkele { | ||
8 | |||
9 | namespace util { | ||
10 | |||
11 | class expat_t { | ||
12 | public: | ||
13 | XML_Parser _x; | ||
14 | |||
15 | expat_t() : _x(0) { } | ||
16 | expat_t(XML_Parser x) : _x(x) { } | ||
17 | virtual ~expat_t() throw(); | ||
18 | |||
19 | expat_t& operator=(XML_Parser x); | ||
20 | |||
21 | operator const XML_Parser(void) const { return _x; } | ||
22 | operator XML_Parser(void) { return _x; } | ||
23 | |||
24 | inline bool parse(const char *s,int len,bool final=false) { | ||
25 | assert(_x); | ||
26 | return XML_Parse(_x,s,len,final); | ||
27 | } | ||
28 | |||
29 | virtual void start_element(const XML_Char *n,const XML_Char **a) { } | ||
30 | virtual void end_element(const XML_Char *n) { } | ||
31 | void set_element_handler(); | ||
32 | |||
33 | virtual void character_data(const XML_Char *s,int l) { } | ||
34 | void set_character_data_handler(); | ||
35 | |||
36 | virtual void processing_instruction(const XML_Char *t,const XML_Char *d) { } | ||
37 | void set_processing_instruction_handler(); | ||
38 | |||
39 | virtual void comment(const XML_Char *d) { } | ||
40 | void set_comment_handler(); | ||
41 | |||
42 | virtual void start_cdata_section() { } | ||
43 | virtual void end_cdata_section() { } | ||
44 | void set_cdata_section_handler(); | ||
45 | |||
46 | virtual void default_handler(const XML_Char *s,int l) { } | ||
47 | void set_default_handler(); | ||
48 | void set_default_handler_expand(); | ||
49 | |||
50 | virtual void start_namespace_decl(const XML_Char *p,const XML_Char *u) { } | ||
51 | virtual void end_namespace_decl(const XML_Char *p) { } | ||
52 | void set_namespace_decl_handler(); | ||
53 | |||
54 | inline enum XML_Error get_error_code() { | ||
55 | assert(_x); return XML_GetErrorCode(_x); } | ||
56 | static inline const XML_LChar *error_string(XML_Error c) { | ||
57 | return XML_ErrorString(c); } | ||
58 | |||
59 | inline long get_current_byte_index() { | ||
60 | assert(_x); return XML_GetCurrentByteIndex(_x); } | ||
61 | inline int get_current_line_number() { | ||
62 | assert(_x); return XML_GetCurrentLineNumber(_x); } | ||
63 | inline int get_current_column_number() { | ||
64 | assert(_x); return XML_GetCurrentColumnNumber(_x); } | ||
65 | |||
66 | inline void set_user_data() { | ||
67 | assert(_x); XML_SetUserData(_x,this); } | ||
68 | |||
69 | inline bool set_base(const XML_Char *b) { | ||
70 | assert(_x); return XML_SetBase(_x,b); } | ||
71 | inline const XML_Char *get_base() { | ||
72 | assert(_x); return XML_GetBase(_x); } | ||
73 | |||
74 | inline int get_specified_attribute_count() { | ||
75 | assert(_x); return XML_GetSpecifiedAttributeCount(_x); } | ||
76 | |||
77 | inline bool set_param_entity_parsing(enum XML_ParamEntityParsing c) { | ||
78 | assert(_x); return XML_SetParamEntityParsing(_x,c); } | ||
79 | |||
80 | inline static XML_Parser parser_create(const XML_Char *e=0) { | ||
81 | return XML_ParserCreate(e); } | ||
82 | inline static XML_Parser parser_create_ns(const XML_Char *e=0,XML_Char s='\t') { | ||
83 | return XML_ParserCreateNS(e,s); } | ||
84 | |||
85 | }; | ||
86 | |||
87 | } | ||
88 | |||
89 | } | ||
90 | |||
91 | #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 | |||
@@ -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 | ||
15 | namespace opkele { | 16 | namespace 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 new file mode 100644 index 0000000..a432b13 --- a/dev/null +++ b/include/opkele/uris.h | |||
@@ -0,0 +1,15 @@ | |||
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 | #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" | ||
14 | |||
15 | #endif /* __OPKELE_URIS_H */ | ||