summaryrefslogtreecommitdiffabout
path: root/lib
Side-by-side diff
Diffstat (limited to 'lib') (more/less context) (ignore whitespace changes)
-rw-r--r--lib/discovery.cc45
1 files changed, 35 insertions, 10 deletions
diff --git a/lib/discovery.cc b/lib/discovery.cc
index 6e20654..6f58339 100644
--- a/lib/discovery.cc
+++ b/lib/discovery.cc
@@ -27,9 +27,9 @@ namespace opkele {
static const struct service_type_t {
const char *uri;
const char *forceid;
- } service_types[] = {
+ } op_service_types[] = {
{ STURI_OPENID20_OP, IDURI_SELECT20 },
{ STURI_OPENID20, 0 },
{ STURI_OPENID11, 0 },
{ STURI_OPENID10, 0 }
@@ -73,9 +73,10 @@ namespace opkele {
public:
string xri_proxy;
enum {
- xmode_html = 1, xmode_xrd = 2, xmode_cid = 4
+ xmode_html = 1, xmode_xrd = 2, xmode_cid = 4,
+ xmode_noredirs = 8
};
int xmode;
string xrds_location;
@@ -109,8 +110,22 @@ namespace opkele {
throw exception_curl(OPKELE_CP_ "failed to set curly options",r);
}
~idigger_t() throw() { }
+ void yadiscover(endpoint_discovery_iterator oi,const string& yurl,const char **types,bool redirs) {
+ idiscovery_t idis;
+ idis.xri_identity = false;
+ discover_at(idis,yurl,xmode_html|xmode_xrd|(redirs?0:xmode_noredirs));
+ if(!xrds_location.empty()) {
+ idis.clear();
+ discover_at(idis,xrds_location,xmode_xrd);
+ }
+ idis.normalized_id = idis.canonicalized_id = yurl;
+ service_type_t st;
+ for(st.uri=*types;*types;st.uri=*(++types))
+ queue_endpoints(oi,idis,&st);
+ }
+
string discover(endpoint_discovery_iterator& oi,const string& identity) {
string rv;
idiscovery_t idis;
string::size_type fsc = identity.find_first_not_of(whitespace);
@@ -128,10 +143,10 @@ namespace opkele {
/* TODO: further normalize xri identity? Like folding case
* or whatever... */
rv = id;
set<string> cids;
- for(const struct service_type_t *st=service_types;
- st<&service_types[sizeof(service_types)/sizeof(*service_types)];++st) {
+ for(const struct service_type_t *st=op_service_types;
+ st<&op_service_types[sizeof(op_service_types)/sizeof(*op_service_types)];++st) {
idis.clear();
discover_at( idis,
xri_proxy + util::url_encode(id)+
"?_xrd_t="+util::url_encode(st->uri)+
@@ -193,21 +208,23 @@ namespace opkele {
discover_at(idis,xrds_location,xmode_xrd);
if(idis.xrd.empty())
html2xrd(oi,idis);
else{
- for(const service_type_t *st=service_types;
- st<&service_types[sizeof(service_types)/sizeof(*service_types)];++st)
+ for(const service_type_t *st=op_service_types;
+ st<&op_service_types[sizeof(op_service_types)/sizeof(*op_service_types)];++st)
queue_endpoints(oi,idis,st);
}
}
}
return rv;
}
void discover_at(idiscovery_t& idis,const string& url,int xm) {
- CURLcode r = easy_setopt(CURLOPT_URL,url.c_str());
+ CURLcode r = easy_setopt(CURLOPT_MAXREDIRS, (xm&xmode_noredirs)?0:5);
if(r)
- throw exception_curl(OPKELE_CP_ "failed to set culry urlie",r);
+ throw exception_curl(OPKELE_CP_ "failed to set curly maxredirs option");
+ if( (r=easy_setopt(CURLOPT_URL,url.c_str())) )
+ throw exception_curl(OPKELE_CP_ "failed to set curly urlie",r);
http_content_type.clear();
xmode = xm;
prepare_to_parse();
@@ -271,14 +288,14 @@ namespace opkele {
XRD_t& x = id.xrd;
if(!html_openid2.uris.empty()) {
html_openid2.types.insert(STURI_OPENID20);
x.services.add(-1,html_openid2);
- queue_endpoints(oi,id,&service_types[st_index_2]);
+ queue_endpoints(oi,id,&op_service_types[st_index_2]);
}
if(!html_openid1.uris.empty()) {
html_openid1.types.insert(STURI_OPENID11);
x.services.add(-1,html_openid1);
- queue_endpoints(oi,id,&service_types[st_index_1]);
+ queue_endpoints(oi,id,&op_service_types[st_index_1]);
}
}
size_t write(void *p,size_t s,size_t nm) {
@@ -548,5 +565,13 @@ namespace opkele {
idigger_t idigger;
return idigger.discover(oi,identity);
}
+ void yadiscover(endpoint_discovery_iterator oi,const string& yurl,const char **types,bool redirs) try {
+ idigger_t idigger;
+ idigger.yadiscover(oi,yurl,types,redirs);
+ }catch(exception_curl& ec) {
+ if(redirs || ec._error!=CURLE_TOO_MANY_REDIRECTS)
+ throw;
+ }
+
}