summaryrefslogtreecommitdiffabout
path: root/lib
authorMichael Krelin <hacker@klever.net>2008-01-05 19:39:07 (UTC)
committer Michael Krelin <hacker@klever.net>2008-01-05 22:03:51 (UTC)
commit7bde7f66284b47a75bbceadc360e7f03550ace21 (patch) (unidiff)
tree401b24fc8b952fee21ad3dce117d4baf99048c9f /lib
parent8e3f9231383194d94e41032b64d87cc6ef1c2ee8 (diff)
downloadlibopkele-7bde7f66284b47a75bbceadc360e7f03550ace21.zip
libopkele-7bde7f66284b47a75bbceadc360e7f03550ace21.tar.gz
libopkele-7bde7f66284b47a75bbceadc360e7f03550ace21.tar.bz2
discovery: stop parser with XML_StopParser()
Signed-off-by: Michael Krelin <hacker@klever.net>
Diffstat (limited to 'lib') (more/less context) (ignore whitespace changes)
-rw-r--r--lib/discovery.cc18
1 files changed, 12 insertions, 6 deletions
diff --git a/lib/discovery.cc b/lib/discovery.cc
index 81727c0..8729cfb 100644
--- a/lib/discovery.cc
+++ b/lib/discovery.cc
@@ -1,388 +1,394 @@
1#include <list> 1#include <list>
2#include <opkele/curl.h> 2#include <opkele/curl.h>
3#include <opkele/expat.h> 3#include <opkele/expat.h>
4#include <opkele/uris.h> 4#include <opkele/uris.h>
5#include <opkele/discovery.h> 5#include <opkele/discovery.h>
6#include <opkele/exception.h> 6#include <opkele/exception.h>
7#include <opkele/util.h> 7#include <opkele/util.h>
8#include <opkele/debug.h>
8 9
9#include "config.h" 10#include "config.h"
10 11
11#define XRDS_HEADER "X-XRDS-Location" 12#define XRDS_HEADER "X-XRDS-Location"
12#define CT_HEADER "Content-Type" 13#define CT_HEADER "Content-Type"
13 14
14namespace opkele { 15namespace opkele {
15 using std::list; 16 using std::list;
16 using xrd::XRD_t; 17 using xrd::XRD_t;
17 using xrd::service_t; 18 using xrd::service_t;
18 19
19 static const char *whitespace = " \t\r\n"; 20 static const char *whitespace = " \t\r\n";
20 static const char *i_leaders = "=@+$!("; 21 static const char *i_leaders = "=@+$!(";
21 22
22 static inline bool is_qelement(const XML_Char *n,const char *qen) { 23 static inline bool is_qelement(const XML_Char *n,const char *qen) {
23 return !strcasecmp(n,qen); 24 return !strcasecmp(n,qen);
24 } 25 }
25 static inline bool is_element(const XML_Char *n,const char *en) { 26 static inline bool is_element(const XML_Char *n,const char *en) {
26 if(!strcasecmp(n,en)) return true; 27 if(!strcasecmp(n,en)) return true;
27 int nl = strlen(n), enl = strlen(en); 28 int nl = strlen(n), enl = strlen(en);
28 if( (nl>=(enl+1)) && n[nl-enl-1]=='\t' 29 if( (nl>=(enl+1)) && n[nl-enl-1]=='\t'
29 && !strcasecmp(&n[nl-enl],en) ) 30 && !strcasecmp(&n[nl-enl],en) )
30 return true; 31 return true;
31 return false; 32 return false;
32 } 33 }
33 34
34 static long element_priority(const XML_Char **a) { 35 static long element_priority(const XML_Char **a) {
35 for(;*a;++a) 36 for(;*a;++a)
36 if(!strcasecmp(*(a++),"priority")) { 37 if(!strcasecmp(*(a++),"priority")) {
37 long rv; 38 long rv;
38 return (sscanf(*a,"%ld",&rv)==1)?rv:-1; 39 return (sscanf(*a,"%ld",&rv)==1)?rv:-1;
39 } 40 }
40 return -1; 41 return -1;
41 } 42 }
42 43
43 class idigger_t : public util::curl_t, public util::expat_t { 44 class idigger_t : public util::curl_t, public util::expat_t {
44 public: 45 public:
45 string xri_proxy; 46 string xri_proxy;
46 47
47 enum { 48 enum {
48 xmode_html = 1, xmode_xrd = 2 49 xmode_html = 1, xmode_xrd = 2
49 }; 50 };
50 int xmode; 51 int xmode;
51 52
52 string xrds_location; 53 string xrds_location;
53 string http_content_type; 54 string http_content_type;
54 service_t html_openid1; 55 service_t html_openid1;
55 service_t html_openid2; 56 service_t html_openid2;
56 string cdata_buf; 57 string cdata_buf;
57 long status_code; 58 long status_code;
58 string status_string; 59 string status_string;
59 60
60 typedef list<string> pt_stack_t; 61 typedef list<string> pt_stack_t;
61 pt_stack_t pt_stack; 62 pt_stack_t pt_stack;
62 int skipping; 63 int skipping;
63 64
64 XRD_t *xrd; 65 XRD_t *xrd;
65 service_t *xrd_service; 66 service_t *xrd_service;
66 string* cdata; 67 string* cdata;
67 68
68 idigger_t() 69 idigger_t()
69 : util::curl_t(easy_init()), 70 : util::curl_t(easy_init()),
70 util::expat_t(0), 71 util::expat_t(0),
71 xri_proxy(XRI_PROXY_URL) { 72 xri_proxy(XRI_PROXY_URL) {
72 CURLcode r; 73 CURLcode r;
73 (r=misc_sets()) 74 (r=misc_sets())
74 || (r=set_write()) 75 || (r=set_write())
75 || (r=set_header()) 76 || (r=set_header())
76 ; 77 ;
77 if(r) 78 if(r)
78 throw exception_curl(OPKELE_CP_ "failed to set curly options",r); 79 throw exception_curl(OPKELE_CP_ "failed to set curly options",r);
79 } 80 }
80 ~idigger_t() throw() { } 81 ~idigger_t() throw() { }
81 82
82 void discover(idiscovery_t& result,const string& identity) { 83 void discover(idiscovery_t& result,const string& identity) {
83 result.clear(); 84 result.clear();
84 string::size_type fsc = identity.find_first_not_of(whitespace); 85 string::size_type fsc = identity.find_first_not_of(whitespace);
85 if(fsc==string::npos) 86 if(fsc==string::npos)
86 throw bad_input(OPKELE_CP_ "whtiespace-only identity"); 87 throw bad_input(OPKELE_CP_ "whtiespace-only identity");
87 string::size_type lsc = identity.find_last_not_of(whitespace); 88 string::size_type lsc = identity.find_last_not_of(whitespace);
88 assert(lsc!=string::npos); 89 assert(lsc!=string::npos);
89 if(!strncasecmp(identity.c_str()+fsc,"xri://",sizeof("xri://")-1)) 90 if(!strncasecmp(identity.c_str()+fsc,"xri://",sizeof("xri://")-1))
90 fsc += sizeof("xri://")-1; 91 fsc += sizeof("xri://")-1;
91 if((fsc+1)>=lsc) 92 if((fsc+1)>=lsc)
92 throw bad_input(OPKELE_CP_ "not a character of importance in identity"); 93 throw bad_input(OPKELE_CP_ "not a character of importance in identity");
93 string id(identity,fsc,lsc-fsc+1); 94 string id(identity,fsc,lsc-fsc+1);
94 if(strchr(i_leaders,id[0])) { 95 if(strchr(i_leaders,id[0])) {
95 result.normalized_id = id; 96 result.normalized_id = id;
96 result.xri_identity = true; 97 result.xri_identity = true;
97 /* TODO: further canonicalize xri identity? Like folding case or whatever... */ 98 /* TODO: further canonicalize xri identity? Like folding case or whatever... */
98 discover_at( 99 discover_at(
99 result, 100 result,
100 xri_proxy + util::url_encode(id)+ 101 xri_proxy + util::url_encode(id)+
101 "?_xrd_r=application/xrd+xml;sep=false", xmode_xrd); 102 "?_xrd_r=application/xrd+xml;sep=false", xmode_xrd);
102 if(status_code!=100) 103 if(status_code!=100)
103 throw failed_xri_resolution(OPKELE_CP_ 104 throw failed_xri_resolution(OPKELE_CP_
104 "XRI resolution failed with '"+status_string+"' message",status_code); 105 "XRI resolution failed with '"+status_string+"' message",status_code);
105 if(result.xrd.canonical_ids.empty()) 106 if(result.xrd.canonical_ids.empty())
106 throw opkele::failed_discovery(OPKELE_CP_ "No CanonicalID for XRI identity found"); 107 throw opkele::failed_discovery(OPKELE_CP_ "No CanonicalID for XRI identity found");
107 result.canonicalized_id = result.xrd.canonical_ids.begin()->second; 108 result.canonicalized_id = result.xrd.canonical_ids.begin()->second;
108 }else{ 109 }else{
109 result.xri_identity = false; 110 result.xri_identity = false;
110 if(id.find("://")==string::npos) 111 if(id.find("://")==string::npos)
111 id.insert(0,"http://"); 112 id.insert(0,"http://");
112 string::size_type fp = id.find('#'); 113 string::size_type fp = id.find('#');
113 if(fp!=string::npos) { 114 if(fp!=string::npos) {
114 string::size_type qp = id.find('?'); 115 string::size_type qp = id.find('?');
115 if(qp==string::npos || qp<fp) 116 if(qp==string::npos || qp<fp)
116 id.erase(fp); 117 id.erase(fp);
117 else if(qp>fp) 118 else if(qp>fp)
118 id.erase(fp,qp-fp); 119 id.erase(fp,qp-fp);
119 } 120 }
120 result.normalized_id = util::rfc_3986_normalize_uri(id); 121 result.normalized_id = util::rfc_3986_normalize_uri(id);
121 discover_at(result,id,xmode_html|xmode_xrd); 122 discover_at(result,id,xmode_html|xmode_xrd);
122 const char * eu = 0; 123 const char * eu = 0;
123 CURLcode r = easy_getinfo(CURLINFO_EFFECTIVE_URL,&eu); 124 CURLcode r = easy_getinfo(CURLINFO_EFFECTIVE_URL,&eu);
124 if(r) 125 if(r)
125 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);
126 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? */
127 if(xrds_location.empty()) { 128 if(xrds_location.empty()) {
128 html2xrd(result.xrd); 129 html2xrd(result.xrd);
129 }else{ 130 }else{
130 discover_at(result,xrds_location,xmode_xrd); 131 discover_at(result,xrds_location,xmode_xrd);
131 if(result.xrd.empty()) 132 if(result.xrd.empty())
132 html2xrd(result.xrd); 133 html2xrd(result.xrd);
133 } 134 }
134 } 135 }
135 } 136 }
136 137
137 void discover_at(idiscovery_t& result,const string& url,int xm) { 138 void discover_at(idiscovery_t& result,const string& url,int xm) {
138 CURLcode r = easy_setopt(CURLOPT_URL,url.c_str()); 139 CURLcode r = easy_setopt(CURLOPT_URL,url.c_str());
139 if(r) 140 if(r)
140 throw exception_curl(OPKELE_CP_ "failed to set culry urlie",r); 141 throw exception_curl(OPKELE_CP_ "failed to set culry urlie",r);
141 142
142 (*(expat_t*)this) = parser_create_ns(); 143 (*(expat_t*)this) = parser_create_ns();
143 set_user_data(); set_element_handler(); 144 set_user_data(); set_element_handler();
144 set_character_data_handler(); 145 set_character_data_handler();
145 146
146 http_content_type.clear(); 147 http_content_type.clear();
147 xmode = xm; 148 xmode = xm;
148 if(xmode&xmode_html) { 149 if(xmode&xmode_html) {
149 xrds_location.clear(); 150 xrds_location.clear();
150 html_openid1.clear(); html_openid2.clear(); 151 html_openid1.clear(); html_openid2.clear();
151 } 152 }
152 xrd = &result.xrd; 153 xrd = &result.xrd;
153 cdata = 0; xrd_service = 0; skipping = 0; 154 cdata = 0; xrd_service = 0; skipping = 0;
154 status_code = 100; status_string.clear(); 155 status_code = 100; status_string.clear();
155 156
156 r = easy_perform(); 157 r = easy_perform();
157 if(r && r!=CURLE_WRITE_ERROR) 158 if(r && r!=CURLE_WRITE_ERROR)
158 throw exception_curl(OPKELE_CP_ "failed to perform curly request",r); 159 throw exception_curl(OPKELE_CP_ "failed to perform curly request",r);
159 160
160 parse(0,0,true); 161 parse(0,0,true);
161 } 162 }
162 163
163 void html2xrd(XRD_t& x) { 164 void html2xrd(XRD_t& x) {
164 if(!html_openid1.uris.empty()) { 165 if(!html_openid1.uris.empty()) {
165 html_openid1.types.insert(STURI_OPENID11); 166 html_openid1.types.insert(STURI_OPENID11);
166 x.services.add(-1,html_openid1); 167 x.services.add(-1,html_openid1);
167 } 168 }
168 if(!html_openid2.uris.empty()) { 169 if(!html_openid2.uris.empty()) {
169 html_openid2.types.insert(STURI_OPENID20); 170 html_openid2.types.insert(STURI_OPENID20);
170 x.services.add(-1,html_openid2); 171 x.services.add(-1,html_openid2);
171 } 172 }
172 } 173 }
173 174
174 size_t write(void *p,size_t s,size_t nm) { 175 size_t write(void *p,size_t s,size_t nm) {
175 if(skipping<0) return 0; 176 if(skipping<0) return 0;
176 /* TODO: limit total size */ 177 /* TODO: limit total size */
177 size_t bytes = s*nm; 178 size_t bytes = s*nm;
178 parse((const char *)p,bytes,false); 179 bool rp = parse((const char *)p,bytes,false);
180 if(!rp) {
181 skipping = -1;
182 bytes = 0;
183 }
179 return bytes; 184 return bytes;
180 } 185 }
181 size_t header(void *p,size_t s,size_t nm) { 186 size_t header(void *p,size_t s,size_t nm) {
182 size_t bytes = s*nm; 187 size_t bytes = s*nm;
183 const char *h = (const char*)p; 188 const char *h = (const char*)p;
184 const char *colon = (const char*)memchr(p,':',bytes); 189 const char *colon = (const char*)memchr(p,':',bytes);
185 const char *space = (const char*)memchr(p,' ',bytes); 190 const char *space = (const char*)memchr(p,' ',bytes);
186 if(space && ( (!colon) || space<colon ) ) { 191 if(space && ( (!colon) || space<colon ) ) {
187 xrds_location.clear(); http_content_type.clear(); 192 xrds_location.clear(); http_content_type.clear();
188 }else if(colon) { 193 }else if(colon) {
189 const char *hv = ++colon; 194 const char *hv = ++colon;
190 int hnl = colon-h; 195 int hnl = colon-h;
191 int rb; 196 int rb;
192 for(rb = bytes-hnl-1;rb>0 && isspace(*hv);++hv,--rb); 197 for(rb = bytes-hnl-1;rb>0 && isspace(*hv);++hv,--rb);
193 while(rb>0 && isspace(hv[rb-1])) --rb; 198 while(rb>0 && isspace(hv[rb-1])) --rb;
194 if(rb) { 199 if(rb) {
195 if( (hnl>=sizeof(XRDS_HEADER)) 200 if( (hnl>=sizeof(XRDS_HEADER))
196 && !strncasecmp(h,XRDS_HEADER":", 201 && !strncasecmp(h,XRDS_HEADER":",
197 sizeof(XRDS_HEADER)) ) { 202 sizeof(XRDS_HEADER)) ) {
198 xrds_location.assign(hv,rb); 203 xrds_location.assign(hv,rb);
199 }else if( (hnl>=sizeof(CT_HEADER)) 204 }else if( (hnl>=sizeof(CT_HEADER))
200 && !strncasecmp(h,CT_HEADER":", 205 && !strncasecmp(h,CT_HEADER":",
201 sizeof(CT_HEADER)) ) { 206 sizeof(CT_HEADER)) ) {
202 const char *sc = (const char*)memchr( 207 const char *sc = (const char*)memchr(
203 hv,';',rb); 208 hv,';',rb);
204 http_content_type.assign(hv,sc?(sc-hv):rb); 209 http_content_type.assign(hv,sc?(sc-hv):rb);
205 } 210 }
206 } 211 }
207 } 212 }
208 return curl_t::header(p,s,nm); 213 return curl_t::header(p,s,nm);
209 } 214 }
210 215
211 void start_element(const XML_Char *n,const XML_Char **a) { 216 void start_element(const XML_Char *n,const XML_Char **a) {
212 if(skipping<0) return; 217 if(skipping<0) return;
213 if(skipping) { 218 if(skipping) {
214 if(xmode&xmode_html) 219 if(xmode&xmode_html)
215 html_start_element(n,a); 220 html_start_element(n,a);
216 ++skipping; return; 221 ++skipping; return;
217 } 222 }
218 if(pt_stack.empty()) { 223 if(pt_stack.empty()) {
219 if(is_qelement(n,NSURI_XRDS "\tXRDS")) 224 if(is_qelement(n,NSURI_XRDS "\tXRDS"))
220 return; 225 return;
221 if(is_qelement(n,NSURI_XRD "\tXRD")) { 226 if(is_qelement(n,NSURI_XRD "\tXRD")) {
222 assert(xrd); 227 assert(xrd);
223 xrd->clear(); 228 xrd->clear();
224 pt_stack.push_back(n); 229 pt_stack.push_back(n);
225 }else if(xmode&xmode_html) { 230 }else if(xmode&xmode_html) {
226 html_start_element(n,a); 231 html_start_element(n,a);
227 }else{ 232 }else{
228 skipping = -1; 233 skipping = -1; stop_parser();
229 } 234 }
230 }else{ 235 }else{
231 int pt_s = pt_stack.size(); 236 int pt_s = pt_stack.size();
232 if(pt_s==1) { 237 if(pt_s==1) {
233 if(is_qelement(n,NSURI_XRD "\tCanonicalID")) { 238 if(is_qelement(n,NSURI_XRD "\tCanonicalID")) {
234 assert(xrd); 239 assert(xrd);
235 cdata = &(xrd->canonical_ids.add(element_priority(a),string())); 240 cdata = &(xrd->canonical_ids.add(element_priority(a),string()));
236 }else if(is_qelement(n,NSURI_XRD "\tLocalID")) { 241 }else if(is_qelement(n,NSURI_XRD "\tLocalID")) {
237 assert(xrd); 242 assert(xrd);
238 cdata = &(xrd->local_ids.add(element_priority(a),string())); 243 cdata = &(xrd->local_ids.add(element_priority(a),string()));
239 }else if(is_qelement(n,NSURI_XRD "\tProviderID")) { 244 }else if(is_qelement(n,NSURI_XRD "\tProviderID")) {
240 assert(xrd); 245 assert(xrd);
241 cdata = &(xrd->provider_id); 246 cdata = &(xrd->provider_id);
242 }else if(is_qelement(n,NSURI_XRD "\tService")) { 247 }else if(is_qelement(n,NSURI_XRD "\tService")) {
243 assert(xrd); 248 assert(xrd);
244 xrd_service = &(xrd->services.add(element_priority(a), 249 xrd_service = &(xrd->services.add(element_priority(a),
245 service_t())); 250 service_t()));
246 pt_stack.push_back(n); 251 pt_stack.push_back(n);
247 }else if(is_qelement(n,NSURI_XRD "\tStatus")) { 252 }else if(is_qelement(n,NSURI_XRD "\tStatus")) {
248 for(;*a;) { 253 for(;*a;) {
249 if(!strcasecmp(*(a++),"code")) { 254 if(!strcasecmp(*(a++),"code")) {
250 if(sscanf(*(a++),"%ld",&status_code)==1 && status_code!=100) { 255 if(sscanf(*(a++),"%ld",&status_code)==1 && status_code!=100) {
251 cdata = &status_string; 256 cdata = &status_string;
252 pt_stack.push_back(n); 257 pt_stack.push_back(n);
253 break; 258 break;
254 } 259 }
255 } 260 }
256 } 261 }
257 }else if(is_qelement(n,NSURI_XRD "\tExpires")) { 262 }else if(is_qelement(n,NSURI_XRD "\tExpires")) {
258 assert(xrd); 263 assert(xrd);
259 cdata_buf.clear(); 264 cdata_buf.clear();
260 cdata = &cdata_buf; 265 cdata = &cdata_buf;
261 }else if(xmode&xmode_html) { 266 }else if(xmode&xmode_html) {
262 html_start_element(n,a); 267 html_start_element(n,a);
263 }else{ 268 }else{
264 skipping = 1; 269 skipping = 1;
265 } 270 }
266 }else if(pt_s==2) { 271 }else if(pt_s==2) {
267 if(is_qelement(pt_stack.back().c_str(), NSURI_XRD "\tService")) { 272 if(is_qelement(pt_stack.back().c_str(), NSURI_XRD "\tService")) {
268 if(is_qelement(n,NSURI_XRD "\tType")) { 273 if(is_qelement(n,NSURI_XRD "\tType")) {
269 assert(xrd); assert(xrd_service); 274 assert(xrd); assert(xrd_service);
270 cdata_buf.clear(); 275 cdata_buf.clear();
271 cdata = &cdata_buf; 276 cdata = &cdata_buf;
272 }else if(is_qelement(n,NSURI_XRD "\tURI")) { 277 }else if(is_qelement(n,NSURI_XRD "\tURI")) {
273 assert(xrd); assert(xrd_service); 278 assert(xrd); assert(xrd_service);
274 cdata = &(xrd_service->uris.add(element_priority(a),string())); 279 cdata = &(xrd_service->uris.add(element_priority(a),string()));
275 }else if(is_qelement(n,NSURI_XRD "\tLocalID") 280 }else if(is_qelement(n,NSURI_XRD "\tLocalID")
276 || is_qelement(n,NSURI_OPENID10 "\tDelegate") ) { 281 || is_qelement(n,NSURI_OPENID10 "\tDelegate") ) {
277 assert(xrd); assert(xrd_service); 282 assert(xrd); assert(xrd_service);
278 cdata = &(xrd_service->local_ids.add(element_priority(a),string())); 283 cdata = &(xrd_service->local_ids.add(element_priority(a),string()));
279 }else if(is_qelement(n,NSURI_XRD "\tProviderID")) { 284 }else if(is_qelement(n,NSURI_XRD "\tProviderID")) {
280 assert(xrd); assert(xrd_service); 285 assert(xrd); assert(xrd_service);
281 cdata = &(xrd_service->provider_id); 286 cdata = &(xrd_service->provider_id);
282 }else{ 287 }else{
283 skipping = 1; 288 skipping = 1;
284 } 289 }
285 }else 290 }else
286 skipping = 1; 291 skipping = 1;
287 }else if(xmode&xmode_html) { 292 }else if(xmode&xmode_html) {
288 html_start_element(n,a); 293 html_start_element(n,a);
289 }else{ 294 }else{
290 skipping = 1; 295 skipping = 1;
291 } 296 }
292 } 297 }
293 } 298 }
294 void end_element(const XML_Char *n) { 299 void end_element(const XML_Char *n) {
295 if(skipping<0) return; 300 if(skipping<0) return;
296 if(skipping) { 301 if(skipping) {
297 --skipping; return; 302 --skipping; return;
298 } 303 }
299 if(is_qelement(n,NSURI_XRD "\tType")) { 304 if(is_qelement(n,NSURI_XRD "\tType")) {
300 assert(xrd); assert(xrd_service); assert(cdata==&cdata_buf); 305 assert(xrd); assert(xrd_service); assert(cdata==&cdata_buf);
301 xrd_service->types.insert(cdata_buf); 306 xrd_service->types.insert(cdata_buf);
302 }else if(is_qelement(n,NSURI_XRD "\tService")) { 307 }else if(is_qelement(n,NSURI_XRD "\tService")) {
303 assert(xrd); assert(xrd_service); 308 assert(xrd); assert(xrd_service);
304 assert(!pt_stack.empty()); 309 assert(!pt_stack.empty());
305 assert(pt_stack.back()==(NSURI_XRD "\tService")); 310 assert(pt_stack.back()==(NSURI_XRD "\tService"));
306 pt_stack.pop_back(); 311 pt_stack.pop_back();
307 xrd_service = 0; 312 xrd_service = 0;
308 }else if(is_qelement(n,NSURI_XRD "\tStatus")) { 313 }else if(is_qelement(n,NSURI_XRD "\tStatus")) {
309 assert(xrd); 314 assert(xrd);
310 if(is_qelement(pt_stack.back().c_str(),n)) { 315 if(is_qelement(pt_stack.back().c_str(),n)) {
311 assert(cdata==&status_string); 316 assert(cdata==&status_string);
312 pt_stack.pop_back(); 317 pt_stack.pop_back();
313 if(status_code!=100) 318 if(status_code!=100) {
314 skipping = -1; 319 skipping = -1; stop_parser();
320 }
315 } 321 }
316 }else if(is_qelement(n,NSURI_XRD "\tExpires")) { 322 }else if(is_qelement(n,NSURI_XRD "\tExpires")) {
317 assert(xrd); 323 assert(xrd);
318 xrd->expires = util::w3c_to_time(cdata_buf); 324 xrd->expires = util::w3c_to_time(cdata_buf);
319 }else if((xmode&xmode_html) && is_element(n,"head")) { 325 }else if((xmode&xmode_html) && is_element(n,"head")) {
320 skipping = -1; 326 skipping = -1; stop_parser();
321 } 327 }
322 cdata = 0; 328 cdata = 0;
323 } 329 }
324 void character_data(const XML_Char *s,int l) { 330 void character_data(const XML_Char *s,int l) {
325 if(skipping) return; 331 if(skipping) return;
326 if(cdata) cdata->append(s,l); 332 if(cdata) cdata->append(s,l);
327 } 333 }
328 334
329 void html_start_element(const XML_Char *n,const XML_Char **a) { 335 void html_start_element(const XML_Char *n,const XML_Char **a) {
330 if(is_element(n,"meta")) { 336 if(is_element(n,"meta")) {
331 bool heq = false; 337 bool heq = false;
332 string l; 338 string l;
333 for(;*a;a+=2) { 339 for(;*a;a+=2) {
334 if(!( strcasecmp(a[0],"http-equiv") 340 if(!( strcasecmp(a[0],"http-equiv")
335 || strcasecmp(a[1],XRDS_HEADER) )) 341 || strcasecmp(a[1],XRDS_HEADER) ))
336 heq = true; 342 heq = true;
337 else if(!strcasecmp(a[0],"content")) 343 else if(!strcasecmp(a[0],"content"))
338 l.assign(a[1]); 344 l.assign(a[1]);
339 } 345 }
340 if(heq) 346 if(heq)
341 xrds_location = l; 347 xrds_location = l;
342 }else if(is_element(n,"link")) { 348 }else if(is_element(n,"link")) {
343 string rels; 349 string rels;
344 string href; 350 string href;
345 for(;*a;a+=2) { 351 for(;*a;a+=2) {
346 if( !strcasecmp(a[0],"rel") ) { 352 if( !strcasecmp(a[0],"rel") ) {
347 rels.assign(a[1]); 353 rels.assign(a[1]);
348 }else if( !strcasecmp(a[0],"href") ) { 354 }else if( !strcasecmp(a[0],"href") ) {
349 const char *ns = a[1]; 355 const char *ns = a[1];
350 for(;*ns && isspace(*ns);++ns); 356 for(;*ns && isspace(*ns);++ns);
351 href.assign(ns); 357 href.assign(ns);
352 string::size_type lns=href.find_last_not_of(whitespace); 358 string::size_type lns=href.find_last_not_of(whitespace);
353 href.erase(lns+1); 359 href.erase(lns+1);
354 } 360 }
355 } 361 }
356 for(string::size_type ns=rels.find_first_not_of(whitespace); 362 for(string::size_type ns=rels.find_first_not_of(whitespace);
357 ns!=string::npos; ns=rels.find_first_not_of(whitespace,ns)) { 363 ns!=string::npos; ns=rels.find_first_not_of(whitespace,ns)) {
358 string::size_type s = rels.find_first_of(whitespace,ns); 364 string::size_type s = rels.find_first_of(whitespace,ns);
359 string rel; 365 string rel;
360 if(s==string::npos) { 366 if(s==string::npos) {
361 rel.assign(rels,ns,string::npos); 367 rel.assign(rels,ns,string::npos);
362 ns = string::npos; 368 ns = string::npos;
363 }else{ 369 }else{
364 rel.assign(rels,ns,s-ns); 370 rel.assign(rels,ns,s-ns);
365 ns = s; 371 ns = s;
366 } 372 }
367 if(rel=="openid.server") 373 if(rel=="openid.server")
368 html_openid1.uris.add(-1,href); 374 html_openid1.uris.add(-1,href);
369 else if(rel=="openid.delegate") 375 else if(rel=="openid.delegate")
370 html_openid1.local_ids.add(-1,href); 376 html_openid1.local_ids.add(-1,href);
371 else if(rel=="openid2.provider") 377 else if(rel=="openid2.provider")
372 html_openid2.uris.add(-1,href); 378 html_openid2.uris.add(-1,href);
373 else if(rel=="openid2.local_id") 379 else if(rel=="openid2.local_id")
374 html_openid2.local_ids.add(-1,href); 380 html_openid2.local_ids.add(-1,href);
375 } 381 }
376 }else if(is_element(n,"body")) { 382 }else if(is_element(n,"body")) {
377 skipping = -1; 383 skipping = -1; stop_parser();
378 } 384 }
379 } 385 }
380 386
381 }; 387 };
382 388
383 void idiscover(idiscovery_t& result,const string& identity) { 389 void idiscover(idiscovery_t& result,const string& identity) {
384 idigger_t idigger; 390 idigger_t idigger;
385 idigger.discover(result,identity); 391 idigger.discover(result,identity);
386 } 392 }
387 393
388} 394}