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) (unidiff) | |
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 | |||
@@ -137,7 +137,7 @@ namespace opkele { | |||
137 | p["mode"]="checkid_setup"; | 137 | p["mode"]="checkid_setup"; |
138 | else | 138 | else |
139 | throw bad_input(OPKELE_CP_ "unknown checkid_* mode"); | 139 | throw bad_input(OPKELE_CP_ "unknown checkid_* mode"); |
140 | string iurl = util::canonicalize_url(identity); | 140 | string iurl = canonicalize(identity); |
141 | string server, delegate; | 141 | string server, delegate; |
142 | retrieve_links(iurl,server,delegate); | 142 | retrieve_links(iurl,server,delegate); |
143 | p["identity"] = delegate.empty()?iurl:delegate; | 143 | p["identity"] = delegate.empty()?iurl:delegate; |
@@ -160,7 +160,7 @@ namespace opkele { | |||
160 | if(pin.has_param("openid.user_setup_url")) | 160 | if(pin.has_param("openid.user_setup_url")) |
161 | throw id_res_setup(OPKELE_CP_ "assertion failed, setup url provided",pin.get_param("openid.user_setup_url")); | 161 | throw id_res_setup(OPKELE_CP_ "assertion failed, setup url provided",pin.get_param("openid.user_setup_url")); |
162 | string server,delegate; | 162 | string server,delegate; |
163 | retrieve_links(identity.empty()?pin.get_param("openid.identity"):util::canonicalize_url(identity),server,delegate); | 163 | retrieve_links(identity.empty()?pin.get_param("openid.identity"):canonicalize(identity),server,delegate); |
164 | try { | 164 | try { |
165 | assoc_t assoc = retrieve_assoc(server,pin.get_param("openid.assoc_handle")); | 165 | assoc_t assoc = retrieve_assoc(server,pin.get_param("openid.assoc_handle")); |
166 | const string& sigenc = pin.get_param("openid.sig"); | 166 | const string& sigenc = pin.get_param("openid.sig"); |
@@ -313,4 +313,29 @@ namespace opkele { | |||
313 | throw failed_lookup(OPKELE_CP_ "no find_assoc() provided"); | 313 | throw failed_lookup(OPKELE_CP_ "no find_assoc() provided"); |
314 | } | 314 | } |
315 | 315 | ||
316 | string consumer_t::canonicalize(const string& url) { | ||
317 | string rv = url; | ||
318 | // strip leading and trailing spaces | ||
319 | string::size_type i = rv.find_first_not_of(" \t\r\n"); | ||
320 | if(i==string::npos) | ||
321 | throw bad_input(OPKELE_CP_ "empty URL"); | ||
322 | if(i) | ||
323 | rv.erase(0,i); | ||
324 | i = rv.find_last_not_of(" \t\r\n"); | ||
325 | assert(i!=string::npos); | ||
326 | if(i<(rv.length()-1)) | ||
327 | rv.erase(i+1); | ||
328 | // add missing http:// | ||
329 | i = rv.find("://"); | ||
330 | if(i==string::npos) { // primitive. but do we need more? | ||
331 | rv.insert(0,"http://"); | ||
332 | i = sizeof("http://")-1; | ||
333 | }else{ | ||
334 | i += sizeof("://")-1; | ||
335 | } | ||
336 | if(rv.find('/',i)==string::npos) | ||
337 | rv += '/'; | ||
338 | return rv; | ||
339 | } | ||
340 | |||
316 | } | 341 | } |