summaryrefslogtreecommitdiffabout
authorMichael Krelin <hacker@klever.net>2007-10-31 13:34:27 (UTC)
committer Michael Krelin <hacker@klever.net>2007-10-31 16:50:17 (UTC)
commit6a228d2b1cb39007c6a7b91dae578a30e26b37fd (patch) (unidiff)
tree9cca336ffc422a2dcf81eaf43367453c767a465a
parente1af6ae7242a280c486c84c9d8015911613cd159 (diff)
downloadlibopkele-6a228d2b1cb39007c6a7b91dae578a30e26b37fd.zip
libopkele-6a228d2b1cb39007c6a7b91dae578a30e26b37fd.tar.gz
libopkele-6a228d2b1cb39007c6a7b91dae578a30e26b37fd.tar.bz2
allow whitespace separated list in @rel when doing links discovery.
Thanks to Joseph Smarr and Chris Messina for bringing it to my attention! Signed-off-by: Michael Krelin <hacker@klever.net>
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--lib/consumer.cc40
1 files changed, 31 insertions, 9 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));
345 if(rel=="openid.server") { 347 for(string::size_type ns = rels.find_first_not_of(whitespace);
346 server.assign(attrs,m2.begin(1),m2.length(1)); 348 ns!=string::npos;
347 if(!delegate.empty()) break; 349 ns=rels.find_first_not_of(whitespace,ns)) {
348 }else if(rel=="openid.delegate") { 350 string::size_type s = rels.find_first_of(whitespace,ns);
349 delegate.assign(attrs,m2.begin(1),m2.length(1)); 351 string rel;
350 if(!server.empty()) break; 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 }
359 if(rel=="openid.server") {
360 server.assign(attrs,m2.begin(1),m2.length(1));
361 if(!delegate.empty()) {
362 gotit = true;
363 break;
364 }
365 }else if(rel=="openid.delegate") {
366 delegate.assign(attrs,m2.begin(1),m2.length(1));
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())