author | Michael Krelin <hacker@klever.net> | 2007-11-28 16:17:00 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2007-11-28 16:17:00 (UTC) |
commit | 17aeb70fafc306ba5e06d2321196bc913f3c0fe1 (patch) (unidiff) | |
tree | 606aa63bdb310b25bec0846e30cdeec4bb26b18a /lib | |
parent | b71de8d6a2b2d8b57e229ac7887c5b74590f58b8 (diff) | |
download | libopkele-17aeb70fafc306ba5e06d2321196bc913f3c0fe1.zip libopkele-17aeb70fafc306ba5e06d2321196bc913f3c0fe1.tar.gz libopkele-17aeb70fafc306ba5e06d2321196bc913f3c0fe1.tar.bz2 |
removed meaningless condition
Signed-off-by: Michael Krelin <hacker@klever.net>
-rw-r--r-- | lib/consumer.cc | 1 |
1 files changed, 0 insertions, 1 deletions
diff --git a/lib/consumer.cc b/lib/consumer.cc index 62bec71..66db7dd 100644 --- a/lib/consumer.cc +++ b/lib/consumer.cc | |||
@@ -299,97 +299,96 @@ namespace opkele { | |||
299 | if(r && r!=CURLE_WRITE_ERROR) | 299 | if(r && r!=CURLE_WRITE_ERROR) |
300 | throw exception_curl(OPKELE_CP_ "failed to perform curly request",r); | 300 | throw exception_curl(OPKELE_CP_ "failed to perform curly request",r); |
301 | static const char *re_bre = "<\\s*body\\b", *re_hdre = "<\\s*head[^>]*>", | 301 | static const char *re_bre = "<\\s*body\\b", *re_hdre = "<\\s*head[^>]*>", |
302 | *re_lre = "<\\s*link\\b([^>]+)>", | 302 | *re_lre = "<\\s*link\\b([^>]+)>", |
303 | *re_rre = "\\brel\\s*=\\s*['\"]([^'\"]+)['\"]", | 303 | *re_rre = "\\brel\\s*=\\s*['\"]([^'\"]+)['\"]", |
304 | *re_hre = "\\bhref\\s*=\\s*['\"]\\s*([^'\"\\s]+)\\s*['\"]"; | 304 | *re_hre = "\\bhref\\s*=\\s*['\"]\\s*([^'\"\\s]+)\\s*['\"]"; |
305 | pcre_matches_t m1(3), m2(3); | 305 | pcre_matches_t m1(3), m2(3); |
306 | pcre_t bre(re_bre,PCRE_CASELESS); | 306 | pcre_t bre(re_bre,PCRE_CASELESS); |
307 | if(bre.exec(html,m1)>0) | 307 | if(bre.exec(html,m1)>0) |
308 | html.erase(m1.begin(0)); | 308 | html.erase(m1.begin(0)); |
309 | pcre_t hdre(re_hdre,PCRE_CASELESS); | 309 | pcre_t hdre(re_hdre,PCRE_CASELESS); |
310 | if(hdre.exec(html,m1)<=0) | 310 | if(hdre.exec(html,m1)<=0) |
311 | throw bad_input(OPKELE_CP_ "failed to find <head>"); | 311 | throw bad_input(OPKELE_CP_ "failed to find <head>"); |
312 | html.erase(0,m1.end(0)+1); | 312 | html.erase(0,m1.end(0)+1); |
313 | pcre_t lre(re_lre,PCRE_CASELESS), rre(re_rre,PCRE_CASELESS), hre(re_hre,PCRE_CASELESS); | 313 | pcre_t lre(re_lre,PCRE_CASELESS), rre(re_rre,PCRE_CASELESS), hre(re_hre,PCRE_CASELESS); |
314 | bool gotit = false; | 314 | bool gotit = false; |
315 | while( (!gotit) && lre.exec(html,m1)>=2 ) { | 315 | while( (!gotit) && lre.exec(html,m1)>=2 ) { |
316 | static const char *whitespace = " \t"; | 316 | static const char *whitespace = " \t"; |
317 | string attrs(html,m1.begin(1),m1.length(1)); | 317 | string attrs(html,m1.begin(1),m1.length(1)); |
318 | html.erase(0,m1.end(0)+1); | 318 | html.erase(0,m1.end(0)+1); |
319 | if(!( rre.exec(attrs,m1)>=2 && hre.exec(attrs,m2)>=2 )) | 319 | if(!( rre.exec(attrs,m1)>=2 && hre.exec(attrs,m2)>=2 )) |
320 | continue; | 320 | continue; |
321 | string rels(attrs,m1.begin(1),m1.length(1)); | 321 | string rels(attrs,m1.begin(1),m1.length(1)); |
322 | for(string::size_type ns = rels.find_first_not_of(whitespace); | 322 | for(string::size_type ns = rels.find_first_not_of(whitespace); |
323 | ns!=string::npos; | 323 | ns!=string::npos; |
324 | ns=rels.find_first_not_of(whitespace,ns)) { | 324 | ns=rels.find_first_not_of(whitespace,ns)) { |
325 | string::size_type s = rels.find_first_of(whitespace,ns); | 325 | string::size_type s = rels.find_first_of(whitespace,ns); |
326 | string rel; | 326 | string rel; |
327 | if(s==string::npos) { | 327 | if(s==string::npos) { |
328 | rel.assign(rels,ns,string::npos); | 328 | rel.assign(rels,ns,string::npos); |
329 | ns=string::npos; | 329 | ns=string::npos; |
330 | }else{ | 330 | }else{ |
331 | rel.assign(rels,ns,s-ns); | 331 | rel.assign(rels,ns,s-ns); |
332 | ns=s; | 332 | ns=s; |
333 | } | 333 | } |
334 | if(rel=="openid.server") { | 334 | if(rel=="openid.server") { |
335 | server.assign(attrs,m2.begin(1),m2.length(1)); | 335 | server.assign(attrs,m2.begin(1),m2.length(1)); |
336 | if(!delegate.empty()) { | 336 | if(!delegate.empty()) { |
337 | gotit = true; | 337 | gotit = true; |
338 | break; | 338 | break; |
339 | } | 339 | } |
340 | }else if(rel=="openid.delegate") { | 340 | }else if(rel=="openid.delegate") { |
341 | delegate.assign(attrs,m2.begin(1),m2.length(1)); | 341 | delegate.assign(attrs,m2.begin(1),m2.length(1)); |
342 | if(!server.empty()) { | 342 | if(!server.empty()) { |
343 | gotit = true; | 343 | gotit = true; |
344 | break; | 344 | break; |
345 | } | 345 | } |
346 | } | 346 | } |
347 | if(ns==string::npos) break; | ||
348 | } | 347 | } |
349 | } | 348 | } |
350 | if(server.empty()) | 349 | if(server.empty()) |
351 | throw failed_assertion(OPKELE_CP_ "The location has no openid.server declaration"); | 350 | throw failed_assertion(OPKELE_CP_ "The location has no openid.server declaration"); |
352 | } | 351 | } |
353 | 352 | ||
354 | assoc_t consumer_t::find_assoc(const string& /* server */) { | 353 | assoc_t consumer_t::find_assoc(const string& /* server */) { |
355 | throw failed_lookup(OPKELE_CP_ "no find_assoc() provided"); | 354 | throw failed_lookup(OPKELE_CP_ "no find_assoc() provided"); |
356 | } | 355 | } |
357 | 356 | ||
358 | string consumer_t::normalize(const string& url) { | 357 | string consumer_t::normalize(const string& url) { |
359 | string rv = url; | 358 | string rv = url; |
360 | // strip leading and trailing spaces | 359 | // strip leading and trailing spaces |
361 | string::size_type i = rv.find_first_not_of(" \t\r\n"); | 360 | string::size_type i = rv.find_first_not_of(" \t\r\n"); |
362 | if(i==string::npos) | 361 | if(i==string::npos) |
363 | throw bad_input(OPKELE_CP_ "empty URL"); | 362 | throw bad_input(OPKELE_CP_ "empty URL"); |
364 | if(i) | 363 | if(i) |
365 | rv.erase(0,i); | 364 | rv.erase(0,i); |
366 | i = rv.find_last_not_of(" \t\r\n"); | 365 | i = rv.find_last_not_of(" \t\r\n"); |
367 | assert(i!=string::npos); | 366 | assert(i!=string::npos); |
368 | if(i<(rv.length()-1)) | 367 | if(i<(rv.length()-1)) |
369 | rv.erase(i+1); | 368 | rv.erase(i+1); |
370 | // add missing http:// | 369 | // add missing http:// |
371 | i = rv.find("://"); | 370 | i = rv.find("://"); |
372 | if(i==string::npos) { // primitive. but do we need more? | 371 | if(i==string::npos) { // primitive. but do we need more? |
373 | rv.insert(0,"http://"); | 372 | rv.insert(0,"http://"); |
374 | i = sizeof("http://")-1; | 373 | i = sizeof("http://")-1; |
375 | }else{ | 374 | }else{ |
376 | i += sizeof("://")-1; | 375 | i += sizeof("://")-1; |
377 | } | 376 | } |
378 | string::size_type qm = rv.find('?',i); | 377 | string::size_type qm = rv.find('?',i); |
379 | string::size_type sl = rv.find('/',i); | 378 | string::size_type sl = rv.find('/',i); |
380 | if(qm!=string::npos) { | 379 | if(qm!=string::npos) { |
381 | if(sl==string::npos || sl>qm) | 380 | if(sl==string::npos || sl>qm) |
382 | rv.insert(qm,1,'/'); | 381 | rv.insert(qm,1,'/'); |
383 | }else{ | 382 | }else{ |
384 | if(sl==string::npos) | 383 | if(sl==string::npos) |
385 | rv += '/'; | 384 | rv += '/'; |
386 | } | 385 | } |
387 | return rv; | 386 | return rv; |
388 | } | 387 | } |
389 | 388 | ||
390 | string consumer_t::canonicalize(const string& url) { | 389 | string consumer_t::canonicalize(const string& url) { |
391 | string rv = normalize(url); | 390 | string rv = normalize(url); |
392 | curl_t curl = curl_t::easy_init(); | 391 | curl_t curl = curl_t::easy_init(); |
393 | if(!curl) | 392 | if(!curl) |
394 | throw exception_curl(OPKELE_CP_ "failed to initialize curl()"); | 393 | throw exception_curl(OPKELE_CP_ "failed to initialize curl()"); |
395 | string html; | 394 | string html; |