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