-rw-r--r-- | lib/discovery.cc | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/discovery.cc b/lib/discovery.cc index d1989ec..984e308 100644 --- a/lib/discovery.cc +++ b/lib/discovery.cc | |||
@@ -294,97 +294,97 @@ namespace opkele { | |||
294 | void html2xrd(endpoint_discovery_iterator& oi,idiscovery_t& id) { | 294 | void html2xrd(endpoint_discovery_iterator& oi,idiscovery_t& id) { |
295 | XRD_t& x = id.xrd; | 295 | XRD_t& x = id.xrd; |
296 | if(!html_openid2.uris.empty()) { | 296 | if(!html_openid2.uris.empty()) { |
297 | html_openid2.types.insert(STURI_OPENID20); | 297 | html_openid2.types.insert(STURI_OPENID20); |
298 | x.services.add(-1,html_openid2); | 298 | x.services.add(-1,html_openid2); |
299 | queue_endpoints(oi,id,&op_service_types[st_index_2]); | 299 | queue_endpoints(oi,id,&op_service_types[st_index_2]); |
300 | } | 300 | } |
301 | if(!html_openid1.uris.empty()) { | 301 | if(!html_openid1.uris.empty()) { |
302 | html_openid1.types.insert(STURI_OPENID11); | 302 | html_openid1.types.insert(STURI_OPENID11); |
303 | x.services.add(-1,html_openid1); | 303 | x.services.add(-1,html_openid1); |
304 | queue_endpoints(oi,id,&op_service_types[st_index_1]); | 304 | queue_endpoints(oi,id,&op_service_types[st_index_1]); |
305 | } | 305 | } |
306 | } | 306 | } |
307 | 307 | ||
308 | size_t write(void *p,size_t s,size_t nm) { | 308 | size_t write(void *p,size_t s,size_t nm) { |
309 | /* TODO: limit total size */ | 309 | /* TODO: limit total size */ |
310 | size_t bytes = s*nm; | 310 | size_t bytes = s*nm; |
311 | const char *inbuf = (const char*)p; | 311 | const char *inbuf = (const char*)p; |
312 | if(xmode&xmode_html) { | 312 | if(xmode&xmode_html) { |
313 | size_t mbts = save_html.capacity()-save_html.size(); | 313 | size_t mbts = save_html.capacity()-save_html.size(); |
314 | size_t bts = 0; | 314 | size_t bts = 0; |
315 | if(mbts>0) { | 315 | if(mbts>0) { |
316 | bts = (bytes>mbts)?mbts:bytes; | 316 | bts = (bytes>mbts)?mbts:bytes; |
317 | save_html.append(inbuf,bts); | 317 | save_html.append(inbuf,bts); |
318 | } | 318 | } |
319 | if(skipping<0) return bts; | 319 | if(skipping<0) return bts; |
320 | } | 320 | } |
321 | if(skipping<0) return 0; | 321 | if(skipping<0) return 0; |
322 | bool rp = parse(inbuf,bytes,false); | 322 | bool rp = parse(inbuf,bytes,false); |
323 | if(!rp) { | 323 | if(!rp) { |
324 | parser_choked = true; | 324 | parser_choked = true; |
325 | skipping = -1; | 325 | skipping = -1; |
326 | if(!(xmode&xmode_html)) | 326 | if(!(xmode&xmode_html)) |
327 | bytes = 0; | 327 | bytes = 0; |
328 | } | 328 | } |
329 | return bytes; | 329 | return bytes; |
330 | } | 330 | } |
331 | size_t header(void *p,size_t s,size_t nm) { | 331 | size_t header(void *p,size_t s,size_t nm) { |
332 | size_t bytes = s*nm; | 332 | size_t bytes = s*nm; |
333 | const char *h = (const char*)p; | 333 | const char *h = (const char*)p; |
334 | const char *colon = (const char*)memchr(p,':',bytes); | 334 | const char *colon = (const char*)memchr(p,':',bytes); |
335 | const char *space = (const char*)memchr(p,' ',bytes); | 335 | const char *space = (const char*)memchr(p,' ',bytes); |
336 | if(space && ( (!colon) || space<colon ) ) { | 336 | if(space && ( (!colon) || space<colon ) ) { |
337 | xrds_location.clear(); http_content_type.clear(); | 337 | xrds_location.clear(); http_content_type.clear(); |
338 | }else if(colon) { | 338 | }else if(colon) { |
339 | const char *hv = ++colon; | 339 | const char *hv = ++colon; |
340 | size_t hnl = colon-h; | 340 | size_t hnl = colon-h; |
341 | int rb; | 341 | int rb; |
342 | for(rb = bytes-hnl-1;rb>0 && isspace(*hv);++hv,--rb); | 342 | for(rb = bytes-hnl-1;rb>0 && isspace(*hv);++hv,--rb) ; |
343 | while(rb>0 && isspace(hv[rb-1])) --rb; | 343 | while(rb>0 && isspace(hv[rb-1])) --rb; |
344 | if(rb) { | 344 | if(rb) { |
345 | if( (hnl>=sizeof(XRDS_HEADER)) | 345 | if( (hnl>=sizeof(XRDS_HEADER)) |
346 | && !strncasecmp(h,XRDS_HEADER":", | 346 | && !strncasecmp(h,XRDS_HEADER":", |
347 | sizeof(XRDS_HEADER)) ) { | 347 | sizeof(XRDS_HEADER)) ) { |
348 | xrds_location.assign(hv,rb); | 348 | xrds_location.assign(hv,rb); |
349 | }else if( (hnl>=sizeof(CT_HEADER)) | 349 | }else if( (hnl>=sizeof(CT_HEADER)) |
350 | && !strncasecmp(h,CT_HEADER":", | 350 | && !strncasecmp(h,CT_HEADER":", |
351 | sizeof(CT_HEADER)) ) { | 351 | sizeof(CT_HEADER)) ) { |
352 | const char *sc = (const char*)memchr( | 352 | const char *sc = (const char*)memchr( |
353 | hv,';',rb); | 353 | hv,';',rb); |
354 | http_content_type.assign(hv,sc?(sc-hv):rb); | 354 | http_content_type.assign(hv,sc?(sc-hv):rb); |
355 | } | 355 | } |
356 | } | 356 | } |
357 | } | 357 | } |
358 | return curl_t::header(p,s,nm); | 358 | return curl_t::header(p,s,nm); |
359 | } | 359 | } |
360 | 360 | ||
361 | void start_element(const XML_Char *n,const XML_Char **a) { | 361 | void start_element(const XML_Char *n,const XML_Char **a) { |
362 | if(skipping<0) return; | 362 | if(skipping<0) return; |
363 | if(skipping) { | 363 | if(skipping) { |
364 | if(xmode&xmode_html) | 364 | if(xmode&xmode_html) |
365 | html_start_element(n,a); | 365 | html_start_element(n,a); |
366 | ++skipping; return; | 366 | ++skipping; return; |
367 | } | 367 | } |
368 | if(pt_stack.empty()) { | 368 | if(pt_stack.empty()) { |
369 | if(is_qelement(n,NSURI_XRDS "\tXRDS")) | 369 | if(is_qelement(n,NSURI_XRDS "\tXRDS")) |
370 | return; | 370 | return; |
371 | if(is_qelement(n,NSURI_XRD "\tXRD")) { | 371 | if(is_qelement(n,NSURI_XRD "\tXRD")) { |
372 | assert(xrd); | 372 | assert(xrd); |
373 | xrd->clear(); | 373 | xrd->clear(); |
374 | pt_stack.push_back(n); | 374 | pt_stack.push_back(n); |
375 | }else if(xmode&xmode_html) { | 375 | }else if(xmode&xmode_html) { |
376 | html_start_element(n,a); | 376 | html_start_element(n,a); |
377 | }else{ | 377 | }else{ |
378 | skipping = -1; | 378 | skipping = -1; |
379 | } | 379 | } |
380 | }else{ | 380 | }else{ |
381 | int pt_s = pt_stack.size(); | 381 | int pt_s = pt_stack.size(); |
382 | if(pt_s==1) { | 382 | if(pt_s==1) { |
383 | if(is_qelement(n,NSURI_XRD "\tCanonicalID")) { | 383 | if(is_qelement(n,NSURI_XRD "\tCanonicalID")) { |
384 | assert(xrd); | 384 | assert(xrd); |
385 | cdata = &(xrd->canonical_ids.add(element_priority(a),string())); | 385 | cdata = &(xrd->canonical_ids.add(element_priority(a),string())); |
386 | }else if(is_qelement(n,NSURI_XRD "\tLocalID")) { | 386 | }else if(is_qelement(n,NSURI_XRD "\tLocalID")) { |
387 | assert(xrd); | 387 | assert(xrd); |
388 | cdata = &(xrd->local_ids.add(element_priority(a),string())); | 388 | cdata = &(xrd->local_ids.add(element_priority(a),string())); |
389 | }else if(is_qelement(n,NSURI_XRD "\tProviderID")) { | 389 | }else if(is_qelement(n,NSURI_XRD "\tProviderID")) { |
390 | assert(xrd); | 390 | assert(xrd); |
@@ -455,97 +455,97 @@ namespace opkele { | |||
455 | }else if(is_qelement(n,NSURI_XRD "\tService")) { | 455 | }else if(is_qelement(n,NSURI_XRD "\tService")) { |
456 | assert(xrd); assert(xrd_service); | 456 | assert(xrd); assert(xrd_service); |
457 | assert(!pt_stack.empty()); | 457 | assert(!pt_stack.empty()); |
458 | assert(pt_stack.back()==(NSURI_XRD "\tService")); | 458 | assert(pt_stack.back()==(NSURI_XRD "\tService")); |
459 | pt_stack.pop_back(); | 459 | pt_stack.pop_back(); |
460 | xrd_service = 0; | 460 | xrd_service = 0; |
461 | }else if(is_qelement(n,NSURI_XRD "\tStatus")) { | 461 | }else if(is_qelement(n,NSURI_XRD "\tStatus")) { |
462 | assert(xrd); | 462 | assert(xrd); |
463 | if(is_qelement(pt_stack.back().c_str(),n)) { | 463 | if(is_qelement(pt_stack.back().c_str(),n)) { |
464 | assert(cdata==&status_string); | 464 | assert(cdata==&status_string); |
465 | pt_stack.pop_back(); | 465 | pt_stack.pop_back(); |
466 | if(status_code!=100) | 466 | if(status_code!=100) |
467 | skipping = -1; | 467 | skipping = -1; |
468 | } | 468 | } |
469 | }else if(is_qelement(n,NSURI_XRD "\tExpires")) { | 469 | }else if(is_qelement(n,NSURI_XRD "\tExpires")) { |
470 | assert(xrd); | 470 | assert(xrd); |
471 | xrd->expires = util::w3c_to_time(cdata_buf); | 471 | xrd->expires = util::w3c_to_time(cdata_buf); |
472 | }else if((xmode&xmode_html) && is_element(n,"head")) { | 472 | }else if((xmode&xmode_html) && is_element(n,"head")) { |
473 | skipping = -1; | 473 | skipping = -1; |
474 | } | 474 | } |
475 | cdata = 0; | 475 | cdata = 0; |
476 | } | 476 | } |
477 | void character_data(const XML_Char *s,int l) { | 477 | void character_data(const XML_Char *s,int l) { |
478 | if(skipping) return; | 478 | if(skipping) return; |
479 | if(cdata) cdata->append(s,l); | 479 | if(cdata) cdata->append(s,l); |
480 | } | 480 | } |
481 | 481 | ||
482 | void html_start_element(const XML_Char *n,const XML_Char **a) { | 482 | void html_start_element(const XML_Char *n,const XML_Char **a) { |
483 | if(is_element(n,"meta")) { | 483 | if(is_element(n,"meta")) { |
484 | bool heq = false; | 484 | bool heq = false; |
485 | string l; | 485 | string l; |
486 | for(;*a;a+=2) { | 486 | for(;*a;a+=2) { |
487 | if(!( strcasecmp(a[0],"http-equiv") | 487 | if(!( strcasecmp(a[0],"http-equiv") |
488 | || strcasecmp(a[1],XRDS_HEADER) )) | 488 | || strcasecmp(a[1],XRDS_HEADER) )) |
489 | heq = true; | 489 | heq = true; |
490 | else if(!strcasecmp(a[0],"content")) | 490 | else if(!strcasecmp(a[0],"content")) |
491 | l.assign(a[1]); | 491 | l.assign(a[1]); |
492 | } | 492 | } |
493 | if(heq) | 493 | if(heq) |
494 | xrds_location = l; | 494 | xrds_location = l; |
495 | }else if(is_element(n,"link")) { | 495 | }else if(is_element(n,"link")) { |
496 | string rels; | 496 | string rels; |
497 | string href; | 497 | string href; |
498 | for(;*a;a+=2) { | 498 | for(;*a;a+=2) { |
499 | if( !strcasecmp(a[0],"rel") ) { | 499 | if( !strcasecmp(a[0],"rel") ) { |
500 | rels.assign(a[1]); | 500 | rels.assign(a[1]); |
501 | }else if( !strcasecmp(a[0],"href") ) { | 501 | }else if( !strcasecmp(a[0],"href") ) { |
502 | const char *ns = a[1]; | 502 | const char *ns = a[1]; |
503 | for(;*ns && isspace(*ns);++ns); | 503 | for(;*ns && isspace(*ns);++ns) ; |
504 | href.assign(ns); | 504 | href.assign(ns); |
505 | string::size_type lns=href.find_last_not_of(data::_whitespace_chars); | 505 | string::size_type lns=href.find_last_not_of(data::_whitespace_chars); |
506 | href.erase(lns+1); | 506 | href.erase(lns+1); |
507 | } | 507 | } |
508 | } | 508 | } |
509 | for(string::size_type ns=rels.find_first_not_of(data::_whitespace_chars); | 509 | for(string::size_type ns=rels.find_first_not_of(data::_whitespace_chars); |
510 | ns!=string::npos; ns=rels.find_first_not_of(data::_whitespace_chars,ns)) { | 510 | ns!=string::npos; ns=rels.find_first_not_of(data::_whitespace_chars,ns)) { |
511 | string::size_type s = rels.find_first_of(data::_whitespace_chars,ns); | 511 | string::size_type s = rels.find_first_of(data::_whitespace_chars,ns); |
512 | string rel; | 512 | string rel; |
513 | if(s==string::npos) { | 513 | if(s==string::npos) { |
514 | rel.assign(rels,ns,string::npos); | 514 | rel.assign(rels,ns,string::npos); |
515 | ns = string::npos; | 515 | ns = string::npos; |
516 | }else{ | 516 | }else{ |
517 | rel.assign(rels,ns,s-ns); | 517 | rel.assign(rels,ns,s-ns); |
518 | ns = s; | 518 | ns = s; |
519 | } | 519 | } |
520 | if(rel=="openid.server") | 520 | if(rel=="openid.server") |
521 | html_openid1.uris.add(-1,xrd::uri_t(href)); | 521 | html_openid1.uris.add(-1,xrd::uri_t(href)); |
522 | else if(rel=="openid.delegate") | 522 | else if(rel=="openid.delegate") |
523 | html_openid1.local_ids.add(-1,href); | 523 | html_openid1.local_ids.add(-1,href); |
524 | else if(rel=="openid2.provider") | 524 | else if(rel=="openid2.provider") |
525 | html_openid2.uris.add(-1,xrd::uri_t(href)); | 525 | html_openid2.uris.add(-1,xrd::uri_t(href)); |
526 | else if(rel=="openid2.local_id") | 526 | else if(rel=="openid2.local_id") |
527 | html_openid2.local_ids.add(-1,href); | 527 | html_openid2.local_ids.add(-1,href); |
528 | } | 528 | } |
529 | }else if(is_element(n,"body")) { | 529 | }else if(is_element(n,"body")) { |
530 | skipping = -1; | 530 | skipping = -1; |
531 | } | 531 | } |
532 | } | 532 | } |
533 | 533 | ||
534 | void queue_endpoints(endpoint_discovery_iterator& oi, | 534 | void queue_endpoints(endpoint_discovery_iterator& oi, |
535 | const idiscovery_t &id, | 535 | const idiscovery_t &id, |
536 | const service_type_t *st) { | 536 | const service_type_t *st) { |
537 | openid_endpoint_t ep; | 537 | openid_endpoint_t ep; |
538 | ep.claimed_id = id.canonicalized_id; | 538 | ep.claimed_id = id.canonicalized_id; |
539 | for(xrd::services_t::const_iterator isvc=id.xrd.services.begin(); | 539 | for(xrd::services_t::const_iterator isvc=id.xrd.services.begin(); |
540 | isvc!=id.xrd.services.end(); ++isvc) { | 540 | isvc!=id.xrd.services.end(); ++isvc) { |
541 | const xrd::service_t svc = isvc->second; | 541 | const xrd::service_t svc = isvc->second; |
542 | if(svc.types.find(st->uri)==svc.types.end()) continue; | 542 | if(svc.types.find(st->uri)==svc.types.end()) continue; |
543 | for(xrd::uris_t::const_iterator iu=svc.uris.begin();iu!=svc.uris.end();++iu) { | 543 | for(xrd::uris_t::const_iterator iu=svc.uris.begin();iu!=svc.uris.end();++iu) { |
544 | ep.uri = iu->second.uri; | 544 | ep.uri = iu->second.uri; |
545 | if(id.xri_identity) { | 545 | if(id.xri_identity) { |
546 | if(iu->second.append=="qxri") { | 546 | if(iu->second.append=="qxri") { |
547 | ep.uri += id.normalized_id; | 547 | ep.uri += id.normalized_id; |
548 | } /* TODO: else handle other append attribute values */ | 548 | } /* TODO: else handle other append attribute values */ |
549 | } | 549 | } |
550 | if(st->forceid) { | 550 | if(st->forceid) { |
551 | ep.local_id = ep.claimed_id = st->forceid; | 551 | ep.local_id = ep.claimed_id = st->forceid; |