summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--lib/consumer.cc32
1 files changed, 27 insertions, 5 deletions
diff --git a/lib/consumer.cc b/lib/consumer.cc
index 7f31d52..f72ae08 100644
--- a/lib/consumer.cc
+++ b/lib/consumer.cc
@@ -325,7 +325,7 @@ namespace opkele {
325 throw exception_curl(OPKELE_CP_ "failed to curl_easy_perform()",r); 325 throw exception_curl(OPKELE_CP_ "failed to curl_easy_perform()",r);
326 static const char *re_bre = "<\\s*body\\b", *re_hdre = "<\\s*head[^>]*>", 326 static const char *re_bre = "<\\s*body\\b", *re_hdre = "<\\s*head[^>]*>",
327 *re_lre = "<\\s*link\\b([^>]+)>", 327 *re_lre = "<\\s*link\\b([^>]+)>",
328 *re_rre = "\\brel\\s*=\\s*['\"]\\s*([^'\"\\s]+)\\s*['\"]", 328 *re_rre = "\\brel\\s*=\\s*['\"]([^'\"]+)['\"]",
329 *re_hre = "\\bhref\\s*=\\s*['\"]\\s*([^'\"\\s]+)\\s*['\"]"; 329 *re_hre = "\\bhref\\s*=\\s*['\"]\\s*([^'\"\\s]+)\\s*['\"]";
330 pcre_matches_t m1(3), m2(3); 330 pcre_matches_t m1(3), m2(3);
331 pcre_t bre(re_bre,PCRE_CASELESS); 331 pcre_t bre(re_bre,PCRE_CASELESS);
@@ -336,18 +336,40 @@ namespace opkele {
336 throw bad_input(OPKELE_CP_ "failed to find <head>"); 336 throw bad_input(OPKELE_CP_ "failed to find <head>");
337 html.erase(0,m1.end(0)+1); 337 html.erase(0,m1.end(0)+1);
338 pcre_t lre(re_lre,PCRE_CASELESS), rre(re_rre,PCRE_CASELESS), hre(re_hre,PCRE_CASELESS); 338 pcre_t lre(re_lre,PCRE_CASELESS), rre(re_rre,PCRE_CASELESS), hre(re_hre,PCRE_CASELESS);
339 while(lre.exec(html,m1)>=2) { 339 bool gotit = false;
340 while( (!gotit) && lre.exec(html,m1)>=2 ) {
341 static const char *whitespace = " \t";
340 string attrs(html,m1.begin(1),m1.length(1)); 342 string attrs(html,m1.begin(1),m1.length(1));
341 html.erase(0,m1.end(0)+1); 343 html.erase(0,m1.end(0)+1);
342 if(!( rre.exec(attrs,m1)>=2 && hre.exec(attrs,m2)>=2 )) 344 if(!( rre.exec(attrs,m1)>=2 && hre.exec(attrs,m2)>=2 ))
343 continue; 345 continue;
344 string rel(attrs,m1.begin(1),m1.length(1)); 346 string rels(attrs,m1.begin(1),m1.length(1));
347 for(string::size_type ns = rels.find_first_not_of(whitespace);
348 ns!=string::npos;
349 ns=rels.find_first_not_of(whitespace,ns)) {
350 string::size_type s = rels.find_first_of(whitespace,ns);
351 string rel;
352 if(s==string::npos) {
353 rel.assign(rels,ns,string::npos);
354 ns=string::npos;
355 }else{
356 rel.assign(rels,ns,s-ns);
357 ns=s;
358 }
345 if(rel=="openid.server") { 359 if(rel=="openid.server") {
346 server.assign(attrs,m2.begin(1),m2.length(1)); 360 server.assign(attrs,m2.begin(1),m2.length(1));
347 if(!delegate.empty()) break; 361 if(!delegate.empty()) {
362 gotit = true;
363 break;
364 }
348 }else if(rel=="openid.delegate") { 365 }else if(rel=="openid.delegate") {
349 delegate.assign(attrs,m2.begin(1),m2.length(1)); 366 delegate.assign(attrs,m2.begin(1),m2.length(1));
350 if(!server.empty()) break; 367 if(!server.empty()) {
368 gotit = true;
369 break;
370 }
371 }
372 if(ns==string::npos) break;
351 } 373 }
352 } 374 }
353 if(server.empty()) 375 if(server.empty())