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 | |||
@@ -433,67 +433,78 @@ namespace opkele { | |||
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")) { |