author | Michael Krelin <hacker@klever.net> | 2009-01-21 19:48:17 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2009-01-21 19:48:17 (UTC) |
commit | 485a0816b78fcf53a717e8e7cbeabee0b83091e7 (patch) (unidiff) | |
tree | 1100501fe3590a63ac615ac23747d6d30ed8a2ae | |
parent | a2a524f744849e81ec91a7afbaf641d1b57e14b1 (diff) | |
download | libopkele-485a0816b78fcf53a717e8e7cbeabee0b83091e7.zip libopkele-485a0816b78fcf53a717e8e7cbeabee0b83091e7.tar.gz libopkele-485a0816b78fcf53a717e8e7cbeabee0b83091e7.tar.bz2 |
Do not bomb out on unusual xml
In particular, properly handle directy Type child of XRD element.
As usually, thanks to Joseph Smarr of Plaxo for spotting it ;-)
Signed-off-by: Michael Krelin <hacker@klever.net>
-rw-r--r-- | lib/discovery.cc | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/lib/discovery.cc b/lib/discovery.cc index cbdceb3..f8a3988 100644 --- a/lib/discovery.cc +++ b/lib/discovery.cc | |||
@@ -265,331 +265,342 @@ namespace opkele { | |||
265 | td.opt_set(TidyDoctypeMode,TidyDoctypeOmit); | 265 | td.opt_set(TidyDoctypeMode,TidyDoctypeOmit); |
266 | td.opt_set(TidyMark,false); | 266 | td.opt_set(TidyMark,false); |
267 | td.opt_set(TidyNumEntities,true); | 267 | td.opt_set(TidyNumEntities,true); |
268 | if(td.parse_string(save_html)<=0) | 268 | if(td.parse_string(save_html)<=0) |
269 | throw exception_tidy(OPKELE_CP_ "tidy failed to parse document"); | 269 | throw exception_tidy(OPKELE_CP_ "tidy failed to parse document"); |
270 | if(td.clean_and_repair()<=0) | 270 | if(td.clean_and_repair()<=0) |
271 | throw exception_tidy(OPKELE_CP_ "tidy failed to clean and repair"); | 271 | throw exception_tidy(OPKELE_CP_ "tidy failed to clean and repair"); |
272 | util::tidy_buf_t tide; | 272 | util::tidy_buf_t tide; |
273 | if(td.save_buffer(tide)<=0) | 273 | if(td.save_buffer(tide)<=0) |
274 | throw exception_tidy(OPKELE_CP_ "tidy failed to save buffer"); | 274 | throw exception_tidy(OPKELE_CP_ "tidy failed to save buffer"); |
275 | prepare_to_parse(); | 275 | prepare_to_parse(); |
276 | parse(tide.c_str(),tide.size(),true); | 276 | parse(tide.c_str(),tide.size(),true); |
277 | }catch(exception_tidy& et) { } | 277 | }catch(exception_tidy& et) { } |
278 | } | 278 | } |
279 | save_html.clear(); | 279 | save_html.clear(); |
280 | } | 280 | } |
281 | 281 | ||
282 | void prepare_to_parse() { | 282 | void prepare_to_parse() { |
283 | (*(expat_t*)this) = parser_create_ns(); | 283 | (*(expat_t*)this) = parser_create_ns(); |
284 | set_user_data(); set_element_handler(); | 284 | set_user_data(); set_element_handler(); |
285 | set_character_data_handler(); | 285 | set_character_data_handler(); |
286 | set_unknown_encoding_handler(); | 286 | set_unknown_encoding_handler(); |
287 | 287 | ||
288 | if(xmode&xmode_html) { | 288 | if(xmode&xmode_html) { |
289 | html_openid1.clear(); html_openid2.clear(); | 289 | html_openid1.clear(); html_openid2.clear(); |
290 | parser_choked = false; | 290 | parser_choked = false; |
291 | } | 291 | } |
292 | 292 | ||
293 | cdata = 0; xrd_service = 0; skipping = 0; | 293 | cdata = 0; xrd_service = 0; skipping = 0; |
294 | pt_stack.clear(); | 294 | pt_stack.clear(); |
295 | status_code = 100; status_string.clear(); | 295 | status_code = 100; status_string.clear(); |
296 | } | 296 | } |
297 | 297 | ||
298 | void html2xrd(endpoint_discovery_iterator& oi,idiscovery_t& id) { | 298 | void html2xrd(endpoint_discovery_iterator& oi,idiscovery_t& id) { |
299 | XRD_t& x = id.xrd; | 299 | XRD_t& x = id.xrd; |
300 | if(!html_openid2.uris.empty()) { | 300 | if(!html_openid2.uris.empty()) { |
301 | html_openid2.types.insert(STURI_OPENID20); | 301 | html_openid2.types.insert(STURI_OPENID20); |
302 | x.services.add(-1,html_openid2); | 302 | x.services.add(-1,html_openid2); |
303 | queue_endpoints(oi,id,&op_service_types[st_index_2]); | 303 | queue_endpoints(oi,id,&op_service_types[st_index_2]); |
304 | } | 304 | } |
305 | if(!html_openid1.uris.empty()) { | 305 | if(!html_openid1.uris.empty()) { |
306 | html_openid1.types.insert(STURI_OPENID11); | 306 | html_openid1.types.insert(STURI_OPENID11); |
307 | x.services.add(-1,html_openid1); | 307 | x.services.add(-1,html_openid1); |
308 | queue_endpoints(oi,id,&op_service_types[st_index_1]); | 308 | queue_endpoints(oi,id,&op_service_types[st_index_1]); |
309 | } | 309 | } |
310 | } | 310 | } |
311 | 311 | ||
312 | size_t write(void *p,size_t s,size_t nm) { | 312 | size_t write(void *p,size_t s,size_t nm) { |
313 | /* TODO: limit total size */ | 313 | /* TODO: limit total size */ |
314 | size_t bytes = s*nm; | 314 | size_t bytes = s*nm; |
315 | const char *inbuf = (const char*)p; | 315 | const char *inbuf = (const char*)p; |
316 | if(xmode&xmode_html) { | 316 | if(xmode&xmode_html) { |
317 | size_t mbts = save_html.capacity()-save_html.size(); | 317 | size_t mbts = save_html.capacity()-save_html.size(); |
318 | size_t bts = 0; | 318 | size_t bts = 0; |
319 | if(mbts>0) { | 319 | if(mbts>0) { |
320 | bts = (bytes>mbts)?mbts:bytes; | 320 | bts = (bytes>mbts)?mbts:bytes; |
321 | save_html.append(inbuf,bts); | 321 | save_html.append(inbuf,bts); |
322 | } | 322 | } |
323 | if(skipping<0) return bts; | 323 | if(skipping<0) return bts; |
324 | } | 324 | } |
325 | if(skipping<0) return 0; | 325 | if(skipping<0) return 0; |
326 | bool rp = parse(inbuf,bytes,false); | 326 | bool rp = parse(inbuf,bytes,false); |
327 | if(!rp) { | 327 | if(!rp) { |
328 | parser_choked = true; | 328 | parser_choked = true; |
329 | skipping = -1; | 329 | skipping = -1; |
330 | if(!(xmode&xmode_html)) | 330 | if(!(xmode&xmode_html)) |
331 | bytes = 0; | 331 | bytes = 0; |
332 | } | 332 | } |
333 | return bytes; | 333 | return bytes; |
334 | } | 334 | } |
335 | size_t header(void *p,size_t s,size_t nm) { | 335 | size_t header(void *p,size_t s,size_t nm) { |
336 | size_t bytes = s*nm; | 336 | size_t bytes = s*nm; |
337 | const char *h = (const char*)p; | 337 | const char *h = (const char*)p; |
338 | const char *colon = (const char*)memchr(p,':',bytes); | 338 | const char *colon = (const char*)memchr(p,':',bytes); |
339 | const char *space = (const char*)memchr(p,' ',bytes); | 339 | const char *space = (const char*)memchr(p,' ',bytes); |
340 | if(space && ( (!colon) || space<colon ) ) { | 340 | if(space && ( (!colon) || space<colon ) ) { |
341 | xrds_location.clear(); http_content_type.clear(); | 341 | xrds_location.clear(); http_content_type.clear(); |
342 | }else if(colon) { | 342 | }else if(colon) { |
343 | const char *hv = ++colon; | 343 | const char *hv = ++colon; |
344 | size_t hnl = colon-h; | 344 | size_t hnl = colon-h; |
345 | int rb; | 345 | int rb; |
346 | for(rb = bytes-hnl-1;rb>0 && isspace(*hv);++hv,--rb) ; | 346 | for(rb = bytes-hnl-1;rb>0 && isspace(*hv);++hv,--rb) ; |
347 | while(rb>0 && isspace(hv[rb-1])) --rb; | 347 | while(rb>0 && isspace(hv[rb-1])) --rb; |
348 | if(rb) { | 348 | if(rb) { |
349 | if( (hnl>=sizeof(XRDS_HEADER)) | 349 | if( (hnl>=sizeof(XRDS_HEADER)) |
350 | && !strncasecmp(h,XRDS_HEADER":", | 350 | && !strncasecmp(h,XRDS_HEADER":", |
351 | sizeof(XRDS_HEADER)) ) { | 351 | sizeof(XRDS_HEADER)) ) { |
352 | xrds_location.assign(hv,rb); | 352 | xrds_location.assign(hv,rb); |
353 | }else if( (hnl>=sizeof(CT_HEADER)) | 353 | }else if( (hnl>=sizeof(CT_HEADER)) |
354 | && !strncasecmp(h,CT_HEADER":", | 354 | && !strncasecmp(h,CT_HEADER":", |
355 | sizeof(CT_HEADER)) ) { | 355 | sizeof(CT_HEADER)) ) { |
356 | const char *sc = (const char*)memchr( | 356 | const char *sc = (const char*)memchr( |
357 | hv,';',rb); | 357 | hv,';',rb); |
358 | http_content_type.assign(hv,sc?(sc-hv):rb); | 358 | http_content_type.assign(hv,sc?(sc-hv):rb); |
359 | } | 359 | } |
360 | } | 360 | } |
361 | } | 361 | } |
362 | return curl_t::header(p,s,nm); | 362 | return curl_t::header(p,s,nm); |
363 | } | 363 | } |
364 | 364 | ||
365 | void start_element(const XML_Char *n,const XML_Char **a) { | 365 | void start_element(const XML_Char *n,const XML_Char **a) { |
366 | if(skipping<0) return; | 366 | if(skipping<0) return; |
367 | if(skipping) { | 367 | if(skipping) { |
368 | if(xmode&xmode_html) | 368 | if(xmode&xmode_html) |
369 | html_start_element(n,a); | 369 | html_start_element(n,a); |
370 | ++skipping; return; | 370 | ++skipping; return; |
371 | } | 371 | } |
372 | if(pt_stack.empty()) { | 372 | if(pt_stack.empty()) { |
373 | if(is_qelement(n,NSURI_XRDS "\tXRDS")) | 373 | if(is_qelement(n,NSURI_XRDS "\tXRDS")) |
374 | return; | 374 | return; |
375 | if(is_qelement(n,NSURI_XRD "\tXRD")) { | 375 | if(is_qelement(n,NSURI_XRD "\tXRD")) { |
376 | assert(xrd); | 376 | assert(xrd); |
377 | xrd->clear(); | 377 | xrd->clear(); |
378 | pt_stack.push_back(n); | 378 | pt_stack.push_back(n); |
379 | }else if(xmode&xmode_html) { | 379 | }else if(xmode&xmode_html) { |
380 | html_start_element(n,a); | 380 | html_start_element(n,a); |
381 | }else{ | 381 | }else{ |
382 | skipping = -1; | 382 | skipping = -1; |
383 | } | 383 | } |
384 | }else{ | 384 | }else{ |
385 | int pt_s = pt_stack.size(); | 385 | int pt_s = pt_stack.size(); |
386 | if(pt_s==1) { | 386 | if(pt_s==1) { |
387 | if(is_qelement(n,NSURI_XRD "\tCanonicalID")) { | 387 | if(is_qelement(n,NSURI_XRD "\tCanonicalID")) { |
388 | assert(xrd); | 388 | assert(xrd); |
389 | cdata = &(xrd->canonical_ids.add(element_priority(a),string())); | 389 | cdata = &(xrd->canonical_ids.add(element_priority(a),string())); |
390 | }else if(is_qelement(n,NSURI_XRD "\tLocalID")) { | 390 | }else if(is_qelement(n,NSURI_XRD "\tLocalID")) { |
391 | assert(xrd); | 391 | assert(xrd); |
392 | cdata = &(xrd->local_ids.add(element_priority(a),string())); | 392 | cdata = &(xrd->local_ids.add(element_priority(a),string())); |
393 | }else if(is_qelement(n,NSURI_XRD "\tProviderID")) { | 393 | }else if(is_qelement(n,NSURI_XRD "\tProviderID")) { |
394 | assert(xrd); | 394 | assert(xrd); |
395 | cdata = &(xrd->provider_id); | 395 | cdata = &(xrd->provider_id); |
396 | }else if(is_qelement(n,NSURI_XRD "\tService")) { | 396 | }else if(is_qelement(n,NSURI_XRD "\tService")) { |
397 | assert(xrd); | 397 | assert(xrd); |
398 | xrd_service = &(xrd->services.add(element_priority(a), | 398 | xrd_service = &(xrd->services.add(element_priority(a), |
399 | service_t())); | 399 | service_t())); |
400 | pt_stack.push_back(n); | 400 | pt_stack.push_back(n); |
401 | }else if(is_qelement(n,NSURI_XRD "\tStatus")) { | 401 | }else if(is_qelement(n,NSURI_XRD "\tStatus")) { |
402 | for(;*a;) { | 402 | for(;*a;) { |
403 | if(!strcasecmp(*(a++),"code")) { | 403 | if(!strcasecmp(*(a++),"code")) { |
404 | if(sscanf(*(a++),"%ld",&status_code)==1 && status_code!=100) { | 404 | if(sscanf(*(a++),"%ld",&status_code)==1 && status_code!=100) { |
405 | cdata = &status_string; | 405 | cdata = &status_string; |
406 | pt_stack.push_back(n); | 406 | pt_stack.push_back(n); |
407 | break; | 407 | break; |
408 | } | 408 | } |
409 | }else | 409 | }else |
410 | ++a; | 410 | ++a; |
411 | } | 411 | } |
412 | }else if(is_qelement(n,NSURI_XRD "\tExpires")) { | 412 | }else if(is_qelement(n,NSURI_XRD "\tExpires")) { |
413 | assert(xrd); | 413 | assert(xrd); |
414 | cdata_buf.clear(); | 414 | cdata_buf.clear(); |
415 | cdata = &cdata_buf; | 415 | cdata = &cdata_buf; |
416 | }else if(xmode&xmode_html) { | 416 | }else if(xmode&xmode_html) { |
417 | html_start_element(n,a); | 417 | html_start_element(n,a); |
418 | }else{ | 418 | }else{ |
419 | skipping = 1; | 419 | skipping = 1; |
420 | } | 420 | } |
421 | }else if(pt_s==2) { | 421 | }else if(pt_s==2) { |
422 | if(is_qelement(pt_stack.back().c_str(), NSURI_XRD "\tService")) { | 422 | if(is_qelement(pt_stack.back().c_str(), NSURI_XRD "\tService")) { |
423 | if(is_qelement(n,NSURI_XRD "\tType")) { | 423 | if(is_qelement(n,NSURI_XRD "\tType")) { |
424 | assert(xrd); assert(xrd_service); | 424 | assert(xrd); assert(xrd_service); |
425 | cdata_buf.clear(); | 425 | cdata_buf.clear(); |
426 | cdata = &cdata_buf; | 426 | cdata = &cdata_buf; |
427 | }else if(is_qelement(n,NSURI_XRD "\tURI")) { | 427 | }else if(is_qelement(n,NSURI_XRD "\tURI")) { |
428 | assert(xrd); assert(xrd_service); | 428 | assert(xrd); assert(xrd_service); |
429 | const char *append = element_attr(a,"append"); | 429 | const char *append = element_attr(a,"append"); |
430 | xrd::uri_t& uri = xrd_service->uris.add(element_priority(a),xrd::uri_t("",append?append:"")); | 430 | xrd::uri_t& uri = xrd_service->uris.add(element_priority(a),xrd::uri_t("",append?append:"")); |
431 | cdata = &uri.uri; | 431 | cdata = &uri.uri; |
432 | }else if(is_qelement(n,NSURI_XRD "\tLocalID") | 432 | }else if(is_qelement(n,NSURI_XRD "\tLocalID") |
433 | || is_qelement(n,NSURI_OPENID10 "\tDelegate") ) { | 433 | || is_qelement(n,NSURI_OPENID10 "\tDelegate") ) { |
434 | assert(xrd); assert(xrd_service); | 434 | assert(xrd); assert(xrd_service); |
435 | cdata = &(xrd_service->local_ids.add(element_priority(a),string())); | 435 | cdata = &(xrd_service->local_ids.add(element_priority(a),string())); |
436 | }else if(is_qelement(n,NSURI_XRD "\tProviderID")) { | 436 | }else if(is_qelement(n,NSURI_XRD "\tProviderID")) { |
437 | assert(xrd); assert(xrd_service); | 437 | assert(xrd); assert(xrd_service); |
438 | cdata = &(xrd_service->provider_id); | 438 | cdata = &(xrd_service->provider_id); |
439 | }else{ | 439 | }else{ |
440 | skipping = 1; | 440 | skipping = 1; |
441 | } | 441 | } |
442 | }else | 442 | }else |
443 | skipping = 1; | 443 | skipping = 1; |
444 | }else if(xmode&xmode_html) { | 444 | }else if(xmode&xmode_html) { |
445 | html_start_element(n,a); | 445 | html_start_element(n,a); |
446 | }else{ | 446 | }else{ |
447 | skipping = 1; | 447 | skipping = 1; |
448 | } | 448 | } |
449 | } | 449 | } |
450 | } | 450 | } |
451 | void end_element(const XML_Char *n) { | 451 | void end_element(const XML_Char *n) { |
452 | if(skipping<0) return; | 452 | if(skipping<0) return; |
453 | if(skipping) { | 453 | if(skipping) { |
454 | --skipping; return; | 454 | --skipping; return; |
455 | } | 455 | } |
456 | if(is_qelement(n,NSURI_XRD "\tType")) { | 456 | if(is_qelement(n,NSURI_XRD "\tType")) { |
457 | assert(xrd); assert(xrd_service); assert(cdata==&cdata_buf); | 457 | if(xrd && xrd_service) { |
458 | xrd_service->types.insert(cdata_buf); | 458 | assert(cdata==&cdata_buf); |
459 | xrd_service->types.insert(cdata_buf); | ||
460 | } | ||
459 | }else if(is_qelement(n,NSURI_XRD "\tService")) { | 461 | }else if(is_qelement(n,NSURI_XRD "\tService")) { |
460 | assert(xrd); assert(xrd_service); | 462 | if(!(xrd && xrd_service)) { |
461 | assert(!pt_stack.empty()); | 463 | skipping = -1; |
462 | assert(pt_stack.back()==(NSURI_XRD "\tService")); | 464 | }else{ |
463 | pt_stack.pop_back(); | 465 | assert(!pt_stack.empty()); |
464 | xrd_service = 0; | 466 | assert(pt_stack.back()==(NSURI_XRD "\tService")); |
465 | }else if(is_qelement(n,NSURI_XRD "\tStatus")) { | ||
466 | assert(xrd); | ||
467 | if(is_qelement(pt_stack.back().c_str(),n)) { | ||
468 | assert(cdata==&status_string); | ||
469 | pt_stack.pop_back(); | 467 | pt_stack.pop_back(); |
470 | if(status_code!=100) | 468 | xrd_service = 0; |
471 | skipping = -1; | 469 | } |
470 | }else if(is_qelement(n,NSURI_XRD "\tStatus")) { | ||
471 | if(!xrd) { | ||
472 | skipping=-1; | ||
473 | }else{ | ||
474 | if(is_qelement(pt_stack.back().c_str(),n)) { | ||
475 | assert(cdata==&status_string); | ||
476 | pt_stack.pop_back(); | ||
477 | if(status_code!=100) | ||
478 | skipping = -1; | ||
479 | } | ||
472 | } | 480 | } |
473 | }else if(is_qelement(n,NSURI_XRD "\tExpires")) { | 481 | }else if(is_qelement(n,NSURI_XRD "\tExpires")) { |
474 | assert(xrd); | 482 | if(!xrd) { |
475 | xrd->expires = util::w3c_to_time(cdata_buf); | 483 | skipping=-1; |
484 | }else{ | ||
485 | xrd->expires = util::w3c_to_time(cdata_buf); | ||
486 | } | ||
476 | }else if((xmode&xmode_html) && is_element(n,"head")) { | 487 | }else if((xmode&xmode_html) && is_element(n,"head")) { |
477 | skipping = -1; | 488 | skipping = -1; |
478 | } | 489 | } |
479 | cdata = 0; | 490 | cdata = 0; |
480 | } | 491 | } |
481 | void character_data(const XML_Char *s,int l) { | 492 | void character_data(const XML_Char *s,int l) { |
482 | if(skipping) return; | 493 | if(skipping) return; |
483 | if(cdata) cdata->append(s,l); | 494 | if(cdata) cdata->append(s,l); |
484 | } | 495 | } |
485 | 496 | ||
486 | void html_start_element(const XML_Char *n,const XML_Char **a) { | 497 | void html_start_element(const XML_Char *n,const XML_Char **a) { |
487 | if(is_element(n,"meta")) { | 498 | if(is_element(n,"meta")) { |
488 | bool heq = false; | 499 | bool heq = false; |
489 | string l; | 500 | string l; |
490 | for(;*a;a+=2) { | 501 | for(;*a;a+=2) { |
491 | if(!( strcasecmp(a[0],"http-equiv") | 502 | if(!( strcasecmp(a[0],"http-equiv") |
492 | || strcasecmp(a[1],XRDS_HEADER) )) | 503 | || strcasecmp(a[1],XRDS_HEADER) )) |
493 | heq = true; | 504 | heq = true; |
494 | else if(!strcasecmp(a[0],"content")) | 505 | else if(!strcasecmp(a[0],"content")) |
495 | l.assign(a[1]); | 506 | l.assign(a[1]); |
496 | } | 507 | } |
497 | if(heq) | 508 | if(heq) |
498 | xrds_location = l; | 509 | xrds_location = l; |
499 | }else if(is_element(n,"link")) { | 510 | }else if(is_element(n,"link")) { |
500 | string rels; | 511 | string rels; |
501 | string href; | 512 | string href; |
502 | for(;*a;a+=2) { | 513 | for(;*a;a+=2) { |
503 | if( !strcasecmp(a[0],"rel") ) { | 514 | if( !strcasecmp(a[0],"rel") ) { |
504 | rels.assign(a[1]); | 515 | rels.assign(a[1]); |
505 | }else if( !strcasecmp(a[0],"href") ) { | 516 | }else if( !strcasecmp(a[0],"href") ) { |
506 | const char *ns = a[1]; | 517 | const char *ns = a[1]; |
507 | for(;*ns && isspace(*ns);++ns) ; | 518 | for(;*ns && isspace(*ns);++ns) ; |
508 | href.assign(ns); | 519 | href.assign(ns); |
509 | string::size_type lns=href.find_last_not_of(data::_whitespace_chars); | 520 | string::size_type lns=href.find_last_not_of(data::_whitespace_chars); |
510 | href.erase(lns+1); | 521 | href.erase(lns+1); |
511 | } | 522 | } |
512 | } | 523 | } |
513 | for(string::size_type ns=rels.find_first_not_of(data::_whitespace_chars); | 524 | for(string::size_type ns=rels.find_first_not_of(data::_whitespace_chars); |
514 | ns!=string::npos; ns=rels.find_first_not_of(data::_whitespace_chars,ns)) { | 525 | ns!=string::npos; ns=rels.find_first_not_of(data::_whitespace_chars,ns)) { |
515 | string::size_type s = rels.find_first_of(data::_whitespace_chars,ns); | 526 | string::size_type s = rels.find_first_of(data::_whitespace_chars,ns); |
516 | string rel; | 527 | string rel; |
517 | if(s==string::npos) { | 528 | if(s==string::npos) { |
518 | rel.assign(rels,ns,string::npos); | 529 | rel.assign(rels,ns,string::npos); |
519 | ns = string::npos; | 530 | ns = string::npos; |
520 | }else{ | 531 | }else{ |
521 | rel.assign(rels,ns,s-ns); | 532 | rel.assign(rels,ns,s-ns); |
522 | ns = s; | 533 | ns = s; |
523 | } | 534 | } |
524 | if(rel=="openid.server") | 535 | if(rel=="openid.server") |
525 | html_openid1.uris.add(-1,xrd::uri_t(href)); | 536 | html_openid1.uris.add(-1,xrd::uri_t(href)); |
526 | else if(rel=="openid.delegate") | 537 | else if(rel=="openid.delegate") |
527 | html_openid1.local_ids.add(-1,href); | 538 | html_openid1.local_ids.add(-1,href); |
528 | else if(rel=="openid2.provider") | 539 | else if(rel=="openid2.provider") |
529 | html_openid2.uris.add(-1,xrd::uri_t(href)); | 540 | html_openid2.uris.add(-1,xrd::uri_t(href)); |
530 | else if(rel=="openid2.local_id") | 541 | else if(rel=="openid2.local_id") |
531 | html_openid2.local_ids.add(-1,href); | 542 | html_openid2.local_ids.add(-1,href); |
532 | } | 543 | } |
533 | }else if(is_element(n,"body")) { | 544 | }else if(is_element(n,"body")) { |
534 | skipping = -1; | 545 | skipping = -1; |
535 | } | 546 | } |
536 | } | 547 | } |
537 | 548 | ||
538 | void queue_endpoints(endpoint_discovery_iterator& oi, | 549 | void queue_endpoints(endpoint_discovery_iterator& oi, |
539 | const idiscovery_t &id, | 550 | const idiscovery_t &id, |
540 | const service_type_t *st) { | 551 | const service_type_t *st) { |
541 | openid_endpoint_t ep; | 552 | openid_endpoint_t ep; |
542 | ep.claimed_id = id.canonicalized_id; | 553 | ep.claimed_id = id.canonicalized_id; |
543 | for(xrd::services_t::const_iterator isvc=id.xrd.services.begin(); | 554 | for(xrd::services_t::const_iterator isvc=id.xrd.services.begin(); |
544 | isvc!=id.xrd.services.end(); ++isvc) { | 555 | isvc!=id.xrd.services.end(); ++isvc) { |
545 | const xrd::service_t svc = isvc->second; | 556 | const xrd::service_t svc = isvc->second; |
546 | if(svc.types.find(st->uri)==svc.types.end()) continue; | 557 | if(svc.types.find(st->uri)==svc.types.end()) continue; |
547 | for(xrd::uris_t::const_iterator iu=svc.uris.begin();iu!=svc.uris.end();++iu) { | 558 | for(xrd::uris_t::const_iterator iu=svc.uris.begin();iu!=svc.uris.end();++iu) { |
548 | ep.uri = iu->second.uri; | 559 | ep.uri = iu->second.uri; |
549 | if(id.xri_identity) { | 560 | if(id.xri_identity) { |
550 | if(iu->second.append=="qxri") { | 561 | if(iu->second.append=="qxri") { |
551 | ep.uri += id.normalized_id; | 562 | ep.uri += id.normalized_id; |
552 | } /* TODO: else handle other append attribute values */ | 563 | } /* TODO: else handle other append attribute values */ |
553 | } | 564 | } |
554 | if(st->forceid) { | 565 | if(st->forceid) { |
555 | ep.local_id = ep.claimed_id = st->forceid; | 566 | ep.local_id = ep.claimed_id = st->forceid; |
556 | *(oi++) = ep; | 567 | *(oi++) = ep; |
557 | }else{ | 568 | }else{ |
558 | if(svc.local_ids.empty()) { | 569 | if(svc.local_ids.empty()) { |
559 | ep.local_id = ep.claimed_id; | 570 | ep.local_id = ep.claimed_id; |
560 | *(oi++) = ep; | 571 | *(oi++) = ep; |
561 | }else{ | 572 | }else{ |
562 | for(xrd::local_ids_t::const_iterator ilid=svc.local_ids.begin(); | 573 | for(xrd::local_ids_t::const_iterator ilid=svc.local_ids.begin(); |
563 | ilid!=svc.local_ids.end(); ++ilid) { | 574 | ilid!=svc.local_ids.end(); ++ilid) { |
564 | ep.local_id = ilid->second; | 575 | ep.local_id = ilid->second; |
565 | *(oi++) = ep; | 576 | *(oi++) = ep; |
566 | } | 577 | } |
567 | } | 578 | } |
568 | } | 579 | } |
569 | } | 580 | } |
570 | } | 581 | } |
571 | } | 582 | } |
572 | 583 | ||
573 | int unknown_encoding(const XML_Char *n,XML_Encoding *i) { | 584 | int unknown_encoding(const XML_Char *n,XML_Encoding *i) { |
574 | for(int ii=0;ii < sizeof(i->map)/sizeof(i->map[0]);++ii) | 585 | for(int ii=0;ii < sizeof(i->map)/sizeof(i->map[0]);++ii) |
575 | i->map[ii] = ii; | 586 | i->map[ii] = ii; |
576 | i->convert = 0; i->release = 0; | 587 | i->convert = 0; i->release = 0; |
577 | return XML_STATUS_OK; | 588 | return XML_STATUS_OK; |
578 | } | 589 | } |
579 | 590 | ||
580 | }; | 591 | }; |
581 | 592 | ||
582 | string idiscover(endpoint_discovery_iterator oi,const string& identity) { | 593 | string idiscover(endpoint_discovery_iterator oi,const string& identity) { |
583 | idigger_t idigger; | 594 | idigger_t idigger; |
584 | return idigger.discover(oi,identity); | 595 | return idigger.discover(oi,identity); |
585 | } | 596 | } |
586 | 597 | ||
587 | void yadiscover(endpoint_discovery_iterator oi,const string& yurl,const char **types,bool redirs) try { | 598 | void yadiscover(endpoint_discovery_iterator oi,const string& yurl,const char **types,bool redirs) try { |
588 | idigger_t idigger; | 599 | idigger_t idigger; |
589 | idigger.yadiscover(oi,yurl,types,redirs); | 600 | idigger.yadiscover(oi,yurl,types,redirs); |
590 | }catch(exception_curl& ec) { | 601 | }catch(exception_curl& ec) { |
591 | if(redirs || ec._error!=CURLE_TOO_MANY_REDIRECTS) | 602 | if(redirs || ec._error!=CURLE_TOO_MANY_REDIRECTS) |
592 | throw; | 603 | throw; |
593 | } | 604 | } |
594 | 605 | ||
595 | } | 606 | } |