author | Michael Krelin <hacker@klever.net> | 2008-01-21 19:51:23 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2008-01-21 19:51:23 (UTC) |
commit | 2a116bce75236e46946bb9564790c26c6a59b9a4 (patch) (side-by-side diff) | |
tree | 27b047f773ea2f37d080c8c9c8f583d345649856 | |
parent | eee78b62ac9c4aed629fc47eb2af6615ca17d2e2 (diff) | |
download | libopkele-2a116bce75236e46946bb9564790c26c6a59b9a4.zip libopkele-2a116bce75236e46946bb9564790c26c6a59b9a4.tar.gz libopkele-2a116bce75236e46946bb9564790c26c6a59b9a4.tar.bz2 |
Implement URI construction handling append='qxri' xrd:URI attribute.
This is the right thing to do and may come in handy assisting OPs in improving
UI.
Signed-off-by: Michael Krelin <hacker@klever.net>
-rw-r--r-- | include/opkele/discovery.h | 10 | ||||
-rw-r--r-- | lib/discovery.cc | 29 |
2 files changed, 31 insertions, 8 deletions
diff --git a/include/opkele/discovery.h b/include/opkele/discovery.h index ab4b9d9..677d7bb 100644 --- a/include/opkele/discovery.h +++ b/include/opkele/discovery.h @@ -30,17 +30,25 @@ namespace opkele { if(i->second==d) return true; return false; } }; 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; + struct uri_t { + string uri; + string append; + + uri_t() { } + uri_t(const string& u) : uri(u) { } + uri_t(const string& u,const string& a) : uri(u), append(a) { } + }; + typedef priority_map<uri_t> uris_t; class service_t { public: types_t types; uris_t uris; local_ids_t local_ids; string provider_id; diff --git a/lib/discovery.cc b/lib/discovery.cc index 93409f4..6e20654 100644 --- a/lib/discovery.cc +++ b/lib/discovery.cc @@ -54,16 +54,25 @@ namespace opkele { static long element_priority(const XML_Char **a) { for(;*a;++a) if(!strcasecmp(*(a++),"priority")) { long rv; return (sscanf(*a,"%ld",&rv)==1)?rv:-1; } return -1; } + /* TODO: ideally all attributes should be + * retrieved in one run */ + static const char *element_attr(const XML_Char **a, const char *at) { + for(;*a;++a) + if(!strcasecmp(*(a++),at)) { + return *a; + } + return 0; + } class idigger_t : public util::curl_t, public util::expat_t { public: string xri_proxy; enum { xmode_html = 1, xmode_xrd = 2, xmode_cid = 4 }; @@ -113,18 +122,17 @@ namespace opkele { fsc += sizeof("xri://")-1; if((fsc+1)>=lsc) throw bad_input(OPKELE_CP_ "not a character of importance in identity"); string id(identity,fsc,lsc-fsc+1); idis.clear(); if(strchr(i_leaders,id[0])) { /* TODO: further normalize xri identity? Like folding case * or whatever... */ - rv = idis.normalized_id = id; - idis.xri_identity = true; + rv = id; set<string> cids; for(const struct service_type_t *st=service_types; st<&service_types[sizeof(service_types)/sizeof(*service_types)];++st) { idis.clear(); discover_at( idis, xri_proxy + util::url_encode(id)+ "?_xrd_t="+util::url_encode(st->uri)+ "&_xrd_r=application/xrd%2Bxml" @@ -150,16 +158,17 @@ namespace opkele { if(status_code==241) continue; if(status_code!=100) throw failed_xri_resolution(OPKELE_CP_ "XRI resolution failed with '"+status_string+"' message" ", while looking for SEP with type '"+st->uri+"'" " on canonical id", status_code); } idis.canonicalized_id = cid; + idis.normalized_id = rv; idis.xri_identity = true; queue_endpoints(oi,idis,st); } }else{ idis.xri_identity = false; if(id.find("://")==string::npos) id.insert(0,"http://"); string::size_type fp = id.find('#'); if(fp!=string::npos) { @@ -190,17 +199,16 @@ namespace opkele { queue_endpoints(oi,idis,st); } } } return rv; } void discover_at(idiscovery_t& idis,const string& url,int xm) { - DOUT_("Doing discovery at " << url); CURLcode r = easy_setopt(CURLOPT_URL,url.c_str()); if(r) throw exception_curl(OPKELE_CP_ "failed to set culry urlie",r); http_content_type.clear(); xmode = xm; prepare_to_parse(); if(xmode&xmode_html) { @@ -385,17 +393,19 @@ namespace opkele { }else if(pt_s==2) { if(is_qelement(pt_stack.back().c_str(), NSURI_XRD "\tService")) { if(is_qelement(n,NSURI_XRD "\tType")) { assert(xrd); assert(xrd_service); cdata_buf.clear(); cdata = &cdata_buf; }else if(is_qelement(n,NSURI_XRD "\tURI")) { assert(xrd); assert(xrd_service); - cdata = &(xrd_service->uris.add(element_priority(a),string())); + const char *append = element_attr(a,"append"); + xrd::uri_t& uri = xrd_service->uris.add(element_priority(a),xrd::uri_t("",append?append:"")); + cdata = &uri.uri; }else if(is_qelement(n,NSURI_XRD "\tLocalID") || is_qelement(n,NSURI_OPENID10 "\tDelegate") ) { assert(xrd); assert(xrd_service); cdata = &(xrd_service->local_ids.add(element_priority(a),string())); }else if(is_qelement(n,NSURI_XRD "\tProviderID")) { assert(xrd); assert(xrd_service); cdata = &(xrd_service->provider_id); }else{ @@ -479,21 +489,21 @@ namespace opkele { if(s==string::npos) { rel.assign(rels,ns,string::npos); ns = string::npos; }else{ rel.assign(rels,ns,s-ns); ns = s; } if(rel=="openid.server") - html_openid1.uris.add(-1,href); + html_openid1.uris.add(-1,xrd::uri_t(href)); else if(rel=="openid.delegate") html_openid1.local_ids.add(-1,href); else if(rel=="openid2.provider") - html_openid2.uris.add(-1,href); + html_openid2.uris.add(-1,xrd::uri_t(href)); else if(rel=="openid2.local_id") html_openid2.local_ids.add(-1,href); } }else if(is_element(n,"body")) { skipping = -1; } } @@ -502,17 +512,22 @@ namespace opkele { const service_type_t *st) { openid_endpoint_t ep; ep.claimed_id = id.canonicalized_id; for(xrd::services_t::const_iterator isvc=id.xrd.services.begin(); isvc!=id.xrd.services.end(); ++isvc) { const xrd::service_t svc = isvc->second; if(svc.types.find(st->uri)==svc.types.end()) continue; for(xrd::uris_t::const_iterator iu=svc.uris.begin();iu!=svc.uris.end();++iu) { - ep.uri = iu->second; + ep.uri = iu->second.uri; + if(id.xri_identity) { + if(iu->second.append=="qxri") { + ep.uri += id.normalized_id; + } /* TODO: else handle other append attribute values */ + } if(st->forceid) { ep.local_id = ep.claimed_id = st->forceid; *(oi++) = ep; }else{ if(svc.local_ids.empty()) { ep.local_id = ep.claimed_id; *(oi++) = ep; }else{ |