author | Michael Krelin <hacker@klever.net> | 2008-02-03 15:29:07 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2008-02-03 15:29:07 (UTC) |
commit | 23a6d48436e24d3d145b742984ef68ec3bae2bfd (patch) (side-by-side diff) | |
tree | 9cd085f583f4235e4f21e640cfc1b1ab1fb04b06 /lib/discovery.cc | |
parent | d1c45af16b3bd31f65d03eec0fcd1c61b4d69fb0 (diff) | |
download | libopkele-23a6d48436e24d3d145b742984ef68ec3bae2bfd.zip libopkele-23a6d48436e24d3d145b742984ef68ec3bae2bfd.tar.gz libopkele-23a6d48436e24d3d145b742984ef68ec3bae2bfd.tar.bz2 |
added provisions for discovery on RP
Signed-off-by: Michael Krelin <hacker@klever.net>
-rw-r--r-- | lib/discovery.cc | 45 |
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 @@ -29,5 +29,5 @@ namespace opkele { const char *uri; const char *forceid; - } service_types[] = { + } op_service_types[] = { { STURI_OPENID20_OP, IDURI_SELECT20 }, { STURI_OPENID20, 0 }, @@ -75,5 +75,6 @@ namespace opkele { enum { - xmode_html = 1, xmode_xrd = 2, xmode_cid = 4 + xmode_html = 1, xmode_xrd = 2, xmode_cid = 4, + xmode_noredirs = 8 }; int xmode; @@ -111,4 +112,18 @@ namespace opkele { ~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; @@ -130,6 +145,6 @@ namespace opkele { 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, @@ -195,6 +210,6 @@ namespace opkele { 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); } @@ -205,7 +220,9 @@ namespace opkele { 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(); @@ -273,10 +290,10 @@ namespace opkele { 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]); } } @@ -550,3 +567,11 @@ namespace opkele { } + 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; + } + } |