-rw-r--r-- | include/opkele/consumer.h | 2 | ||||
-rw-r--r-- | include/opkele/util.h | 1 | ||||
-rw-r--r-- | lib/consumer.cc | 29 | ||||
-rw-r--r-- | lib/util.cc | 25 |
4 files changed, 29 insertions, 28 deletions
diff --git a/include/opkele/consumer.h b/include/opkele/consumer.h index b9c29bd..3c0ed5f 100644 --- a/include/opkele/consumer.h +++ b/include/opkele/consumer.h @@ -127,8 +127,10 @@ namespace opkele { * @param p request parameters */ void check_authentication(const string& server,const params_t& p); + static string canonicalize(const string& url); + }; } diff --git a/include/opkele/util.h b/include/opkele/util.h index fbbef93..5372498 100644 --- a/include/opkele/util.h +++ b/include/opkele/util.h @@ -47,9 +47,8 @@ namespace opkele { string time_to_w3c(time_t t); time_t w3c_to_time(const string& w); - string canonicalize_url(const string& url); string url_encode(const string& str); string long_to_string(long l); long string_to_long(const string& s); diff --git a/lib/consumer.cc b/lib/consumer.cc index bd76b61..cbe0769 100644 --- a/lib/consumer.cc +++ b/lib/consumer.cc @@ -136,9 +136,9 @@ namespace opkele { else if(mode==mode_checkid_setup) p["mode"]="checkid_setup"; else throw bad_input(OPKELE_CP_ "unknown checkid_* mode"); - string iurl = util::canonicalize_url(identity); + string iurl = canonicalize(identity); string server, delegate; retrieve_links(iurl,server,delegate); p["identity"] = delegate.empty()?iurl:delegate; if(!trust_root.empty()) @@ -159,9 +159,9 @@ namespace opkele { void consumer_t::id_res(const params_t& pin,const string& identity) { if(pin.has_param("openid.user_setup_url")) throw id_res_setup(OPKELE_CP_ "assertion failed, setup url provided",pin.get_param("openid.user_setup_url")); 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 { assoc_t assoc = retrieve_assoc(server,pin.get_param("openid.assoc_handle")); const string& sigenc = pin.get_param("openid.sig"); mimetic::Base64::Decoder b; @@ -312,5 +312,30 @@ namespace opkele { assoc_t consumer_t::find_assoc(const string& server) { throw failed_lookup(OPKELE_CP_ "no find_assoc() provided"); } + 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; + } + } diff --git a/lib/util.cc b/lib/util.cc index 1e7335c..d78b5e0 100644 --- a/lib/util.cc +++ b/lib/util.cc @@ -82,33 +82,8 @@ namespace opkele { /* * */ - string canonicalize_url(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; - } - string url_encode(const string& str) { char * t = curl_escape(str.c_str(),str.length()); if(!t) throw failed_conversion(OPKELE_CP_ "failed to curl_escape()"); |