summaryrefslogtreecommitdiffabout
path: root/lib
Unidiff
Diffstat (limited to 'lib') (more/less context) (ignore whitespace changes)
-rw-r--r--lib/discovery.cc2
1 files changed, 2 insertions, 0 deletions
diff --git a/lib/discovery.cc b/lib/discovery.cc
index a35ce32..1f23ff1 100644
--- a/lib/discovery.cc
+++ b/lib/discovery.cc
@@ -74,59 +74,61 @@ namespace opkele {
74 CURLcode r; 74 CURLcode r;
75 (r=misc_sets()) 75 (r=misc_sets())
76 || (r=set_write()) 76 || (r=set_write())
77 || (r=set_header()) 77 || (r=set_header())
78 ; 78 ;
79 if(r) 79 if(r)
80 throw exception_curl(OPKELE_CP_ "failed to set curly options",r); 80 throw exception_curl(OPKELE_CP_ "failed to set curly options",r);
81 } 81 }
82 ~idigger_t() throw() { } 82 ~idigger_t() throw() { }
83 83
84 void discover(idiscovery_t& result,const string& identity) { 84 void discover(idiscovery_t& result,const string& identity) {
85 result.clear(); 85 result.clear();
86 string::size_type fsc = identity.find_first_not_of(whitespace); 86 string::size_type fsc = identity.find_first_not_of(whitespace);
87 if(fsc==string::npos) 87 if(fsc==string::npos)
88 throw bad_input(OPKELE_CP_ "whtiespace-only identity"); 88 throw bad_input(OPKELE_CP_ "whtiespace-only identity");
89 string::size_type lsc = identity.find_last_not_of(whitespace); 89 string::size_type lsc = identity.find_last_not_of(whitespace);
90 assert(lsc!=string::npos); 90 assert(lsc!=string::npos);
91 if(!strncasecmp(identity.c_str()+fsc,"xri://",sizeof("xri://")-1)) 91 if(!strncasecmp(identity.c_str()+fsc,"xri://",sizeof("xri://")-1))
92 fsc += sizeof("xri://")-1; 92 fsc += sizeof("xri://")-1;
93 if((fsc+1)>=lsc) 93 if((fsc+1)>=lsc)
94 throw bad_input(OPKELE_CP_ "not a character of importance in identity"); 94 throw bad_input(OPKELE_CP_ "not a character of importance in identity");
95 string id(identity,fsc,lsc-fsc+1); 95 string id(identity,fsc,lsc-fsc+1);
96 if(strchr(i_leaders,id[0])) { 96 if(strchr(i_leaders,id[0])) {
97 result.normalized_id = id; 97 result.normalized_id = id;
98 result.xri_identity = true;
98 /* TODO: further canonicalize xri identity? Like folding case or whatever... */ 99 /* TODO: further canonicalize xri identity? Like folding case or whatever... */
99 discover_at( 100 discover_at(
100 result, 101 result,
101 xri_proxy + util::url_encode(id)+ 102 xri_proxy + util::url_encode(id)+
102 "?_xrd_r=application/xrd+xml;sep=false", xmode_xrd); 103 "?_xrd_r=application/xrd+xml;sep=false", xmode_xrd);
103 if(status_code!=100) 104 if(status_code!=100)
104 throw failed_xri_resolution(OPKELE_CP_ 105 throw failed_xri_resolution(OPKELE_CP_
105 "XRI resolution failed with '"+status_string+"' message",status_code); 106 "XRI resolution failed with '"+status_string+"' message",status_code);
106 if(result.xrd.canonical_ids.empty()) 107 if(result.xrd.canonical_ids.empty())
107 throw opkele::failed_discovery(OPKELE_CP_ "No CanonicalID for XRI identity found"); 108 throw opkele::failed_discovery(OPKELE_CP_ "No CanonicalID for XRI identity found");
108 }else{ 109 }else{
110 result.xri_identity = false;
109 if(id.find("://")==string::npos) 111 if(id.find("://")==string::npos)
110 id.insert(0,"http://"); 112 id.insert(0,"http://");
111 string::size_type fp = id.find('#'); 113 string::size_type fp = id.find('#');
112 if(fp!=string::npos) { 114 if(fp!=string::npos) {
113 string::size_type qp = id.find('?'); 115 string::size_type qp = id.find('?');
114 if(qp==string::npos || qp<fp) 116 if(qp==string::npos || qp<fp)
115 id.erase(fp); 117 id.erase(fp);
116 else if(qp>fp) 118 else if(qp>fp)
117 id.erase(fp,qp-fp); 119 id.erase(fp,qp-fp);
118 } 120 }
119 result.normalized_id = util::rfc_3986_normalize_uri(id); 121 result.normalized_id = util::rfc_3986_normalize_uri(id);
120 discover_at(result,id,xmode_html|xmode_xrd); 122 discover_at(result,id,xmode_html|xmode_xrd);
121 const char * eu = 0; 123 const char * eu = 0;
122 CURLcode r = easy_getinfo(CURLINFO_EFFECTIVE_URL,&eu); 124 CURLcode r = easy_getinfo(CURLINFO_EFFECTIVE_URL,&eu);
123 if(r) 125 if(r)
124 throw exception_curl(OPKELE_CP_ "failed to get CURLINFO_EFFECTIVE_URL",r); 126 throw exception_curl(OPKELE_CP_ "failed to get CURLINFO_EFFECTIVE_URL",r);
125 result.canonicalized_id = util::rfc_3986_normalize_uri(eu); /* XXX: strip fragment part? */ 127 result.canonicalized_id = util::rfc_3986_normalize_uri(eu); /* XXX: strip fragment part? */
126 if(xrds_location.empty()) { 128 if(xrds_location.empty()) {
127 html2xrd(result.xrd); 129 html2xrd(result.xrd);
128 }else{ 130 }else{
129 discover_at(result,xrds_location,xmode_xrd); 131 discover_at(result,xrds_location,xmode_xrd);
130 if(result.xrd.empty()) 132 if(result.xrd.empty())
131 html2xrd(result.xrd); 133 html2xrd(result.xrd);
132 } 134 }