summaryrefslogtreecommitdiffabout
path: root/lib/discovery.cc
Unidiff
Diffstat (limited to 'lib/discovery.cc') (more/less context) (ignore whitespace changes)
-rw-r--r--lib/discovery.cc41
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
@@ -393,147 +393,158 @@ namespace opkele {
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,