author | Michael Krelin <hacker@klever.net> | 2005-07-20 23:17:25 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2005-07-20 23:17:25 (UTC) |
commit | 84a0285be7c7a57cfc00cb31a4a1da9902fa1b34 (patch) (side-by-side diff) | |
tree | 608822c31cbedeb35c7341b88456dd9c826b4d27 /lib/consumer.cc | |
parent | 9634a1491130ef24130454e951672301e805351f (diff) | |
download | libopkele-84a0285be7c7a57cfc00cb31a4a1da9902fa1b34.zip libopkele-84a0285be7c7a57cfc00cb31a4a1da9902fa1b34.tar.gz libopkele-84a0285be7c7a57cfc00cb31a4a1da9902fa1b34.tar.bz2 |
moved util::canonicalize_url to consumer class
-rw-r--r-- | lib/consumer.cc | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/lib/consumer.cc b/lib/consumer.cc index bd76b61..cbe0769 100644 --- a/lib/consumer.cc +++ b/lib/consumer.cc @@ -139,3 +139,3 @@ namespace opkele { throw bad_input(OPKELE_CP_ "unknown checkid_* mode"); - string iurl = util::canonicalize_url(identity); + string iurl = canonicalize(identity); string server, delegate; @@ -162,3 +162,3 @@ namespace opkele { string server,delegate; - retrieve_links(identity.empty()?pin.get_param("openid.identity"):util::canonicalize_url(identity),server,delegate); + retrieve_links(identity.empty()?pin.get_param("openid.identity"):canonicalize(identity),server,delegate); try { @@ -315,2 +315,27 @@ namespace opkele { + string consumer_t::canonicalize(const string& url) { + string rv = url; + // strip leading and trailing spaces + string::size_type i = rv.find_first_not_of(" \t\r\n"); + if(i==string::npos) + throw bad_input(OPKELE_CP_ "empty URL"); + if(i) + rv.erase(0,i); + i = rv.find_last_not_of(" \t\r\n"); + assert(i!=string::npos); + if(i<(rv.length()-1)) + rv.erase(i+1); + // add missing http:// + i = rv.find("://"); + if(i==string::npos) { // primitive. but do we need more? + rv.insert(0,"http://"); + i = sizeof("http://")-1; + }else{ + i += sizeof("://")-1; + } + if(rv.find('/',i)==string::npos) + rv += '/'; + return rv; + } + } |