summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--lib/discovery.cc1
1 files changed, 1 insertions, 0 deletions
diff --git a/lib/discovery.cc b/lib/discovery.cc
index 3b184ee..bc7d6fb 100644
--- a/lib/discovery.cc
+++ b/lib/discovery.cc
@@ -59,96 +59,97 @@ namespace opkele {
59 59
60 typedef list<string> pt_stack_t; 60 typedef list<string> pt_stack_t;
61 pt_stack_t pt_stack; 61 pt_stack_t pt_stack;
62 int skipping; 62 int skipping;
63 63
64 XRD_t *xrd; 64 XRD_t *xrd;
65 service_t *xrd_service; 65 service_t *xrd_service;
66 string* cdata; 66 string* cdata;
67 67
68 idigger_t() 68 idigger_t()
69 : util::curl_t(easy_init()), 69 : util::curl_t(easy_init()),
70 util::expat_t(0), 70 util::expat_t(0),
71 xri_proxy(XRI_PROXY_URL) { 71 xri_proxy(XRI_PROXY_URL) {
72 CURLcode r; 72 CURLcode r;
73 (r=misc_sets()) 73 (r=misc_sets())
74 || (r=set_write()) 74 || (r=set_write())
75 || (r=set_header()) 75 || (r=set_header())
76 ; 76 ;
77 if(r) 77 if(r)
78 throw exception_curl(OPKELE_CP_ "failed to set curly options",r); 78 throw exception_curl(OPKELE_CP_ "failed to set curly options",r);
79 } 79 }
80 ~idigger_t() throw() { } 80 ~idigger_t() throw() { }
81 81
82 void discover(idiscovery_t& result,const string& identity) { 82 void discover(idiscovery_t& result,const string& identity) {
83 result.clear(); 83 result.clear();
84 string::size_type fsc = identity.find_first_not_of(whitespace); 84 string::size_type fsc = identity.find_first_not_of(whitespace);
85 if(fsc==string::npos) 85 if(fsc==string::npos)
86 throw bad_input(OPKELE_CP_ "whtiespace-only identity"); 86 throw bad_input(OPKELE_CP_ "whtiespace-only identity");
87 string::size_type lsc = identity.find_last_not_of(whitespace); 87 string::size_type lsc = identity.find_last_not_of(whitespace);
88 assert(lsc!=string::npos); 88 assert(lsc!=string::npos);
89 if(!strncasecmp(identity.c_str()+fsc,"xri://",sizeof("xri://")-1)) 89 if(!strncasecmp(identity.c_str()+fsc,"xri://",sizeof("xri://")-1))
90 fsc += sizeof("xri://")-1; 90 fsc += sizeof("xri://")-1;
91 if((fsc+1)>=lsc) 91 if((fsc+1)>=lsc)
92 throw bad_input(OPKELE_CP_ "not a character of importance in identity"); 92 throw bad_input(OPKELE_CP_ "not a character of importance in identity");
93 string id(identity,fsc,lsc-fsc+1); 93 string id(identity,fsc,lsc-fsc+1);
94 if(strchr(i_leaders,id[0])) { 94 if(strchr(i_leaders,id[0])) {
95 result.normalized_id = id; 95 result.normalized_id = id;
96 result.xri_identity = true; 96 result.xri_identity = true;
97 /* TODO: further canonicalize xri identity? Like folding case or whatever... */ 97 /* TODO: further canonicalize xri identity? Like folding case or whatever... */
98 discover_at( 98 discover_at(
99 result, 99 result,
100 xri_proxy + util::url_encode(id)+ 100 xri_proxy + util::url_encode(id)+
101 "?_xrd_r=application/xrd+xml;sep=false", xmode_xrd); 101 "?_xrd_r=application/xrd+xml;sep=false", xmode_xrd);
102 if(status_code!=100) 102 if(status_code!=100)
103 throw failed_xri_resolution(OPKELE_CP_ 103 throw failed_xri_resolution(OPKELE_CP_
104 "XRI resolution failed with '"+status_string+"' message",status_code); 104 "XRI resolution failed with '"+status_string+"' message",status_code);
105 if(result.xrd.canonical_ids.empty()) 105 if(result.xrd.canonical_ids.empty())
106 throw opkele::failed_discovery(OPKELE_CP_ "No CanonicalID for XRI identity found"); 106 throw opkele::failed_discovery(OPKELE_CP_ "No CanonicalID for XRI identity found");
107 result.canonicalized_id = result.xrd.canonical_ids.begin()->second;
107 }else{ 108 }else{
108 result.xri_identity = false; 109 result.xri_identity = false;
109 if(id.find("://")==string::npos) 110 if(id.find("://")==string::npos)
110 id.insert(0,"http://"); 111 id.insert(0,"http://");
111 string::size_type fp = id.find('#'); 112 string::size_type fp = id.find('#');
112 if(fp!=string::npos) { 113 if(fp!=string::npos) {
113 string::size_type qp = id.find('?'); 114 string::size_type qp = id.find('?');
114 if(qp==string::npos || qp<fp) 115 if(qp==string::npos || qp<fp)
115 id.erase(fp); 116 id.erase(fp);
116 else if(qp>fp) 117 else if(qp>fp)
117 id.erase(fp,qp-fp); 118 id.erase(fp,qp-fp);
118 } 119 }
119 result.normalized_id = util::rfc_3986_normalize_uri(id); 120 result.normalized_id = util::rfc_3986_normalize_uri(id);
120 discover_at(result,id,xmode_html|xmode_xrd); 121 discover_at(result,id,xmode_html|xmode_xrd);
121 const char * eu = 0; 122 const char * eu = 0;
122 CURLcode r = easy_getinfo(CURLINFO_EFFECTIVE_URL,&eu); 123 CURLcode r = easy_getinfo(CURLINFO_EFFECTIVE_URL,&eu);
123 if(r) 124 if(r)
124 throw exception_curl(OPKELE_CP_ "failed to get CURLINFO_EFFECTIVE_URL",r); 125 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? */ 126 result.canonicalized_id = util::rfc_3986_normalize_uri(eu); /* XXX: strip fragment part? */
126 if(xrds_location.empty()) { 127 if(xrds_location.empty()) {
127 html2xrd(result.xrd); 128 html2xrd(result.xrd);
128 }else{ 129 }else{
129 discover_at(result,xrds_location,xmode_xrd); 130 discover_at(result,xrds_location,xmode_xrd);
130 if(result.xrd.empty()) 131 if(result.xrd.empty())
131 html2xrd(result.xrd); 132 html2xrd(result.xrd);
132 } 133 }
133 } 134 }
134 } 135 }
135 136
136 void discover_at(idiscovery_t& result,const string& url,int xm) { 137 void discover_at(idiscovery_t& result,const string& url,int xm) {
137 CURLcode r = easy_setopt(CURLOPT_URL,url.c_str()); 138 CURLcode r = easy_setopt(CURLOPT_URL,url.c_str());
138 if(r) 139 if(r)
139 throw exception_curl(OPKELE_CP_ "failed to set culry urlie",r); 140 throw exception_curl(OPKELE_CP_ "failed to set culry urlie",r);
140 141
141 (*(expat_t*)this) = parser_create_ns(); 142 (*(expat_t*)this) = parser_create_ns();
142 set_user_data(); set_element_handler(); 143 set_user_data(); set_element_handler();
143 set_character_data_handler(); 144 set_character_data_handler();
144 145
145 http_content_type.clear(); 146 http_content_type.clear();
146 xmode = xm; 147 xmode = xm;
147 if(xmode&xmode_html) { 148 if(xmode&xmode_html) {
148 xrds_location.clear(); 149 xrds_location.clear();
149 html_openid1.clear(); html_openid2.clear(); 150 html_openid1.clear(); html_openid2.clear();
150 } 151 }
151 xrd = &result.xrd; 152 xrd = &result.xrd;
152 cdata = 0; xrd_service = 0; skipping = 0; 153 cdata = 0; xrd_service = 0; skipping = 0;
153 status_code = 100; status_string.clear(); 154 status_code = 100; status_string.clear();
154 155