summaryrefslogtreecommitdiffabout
path: root/lib
authorMichael Krelin <hacker@klever.net>2005-07-20 23:17:25 (UTC)
committer Michael Krelin <hacker@klever.net>2005-07-20 23:17:25 (UTC)
commit84a0285be7c7a57cfc00cb31a4a1da9902fa1b34 (patch) (side-by-side diff)
tree608822c31cbedeb35c7341b88456dd9c826b4d27 /lib
parent9634a1491130ef24130454e951672301e805351f (diff)
downloadlibopkele-84a0285be7c7a57cfc00cb31a4a1da9902fa1b34.zip
libopkele-84a0285be7c7a57cfc00cb31a4a1da9902fa1b34.tar.gz
libopkele-84a0285be7c7a57cfc00cb31a4a1da9902fa1b34.tar.bz2
moved util::canonicalize_url to consumer class
Diffstat (limited to 'lib') (more/less context) (show whitespace changes)
-rw-r--r--lib/consumer.cc29
-rw-r--r--lib/util.cc25
2 files changed, 27 insertions, 27 deletions
diff --git a/lib/consumer.cc b/lib/consumer.cc
index bd76b61..cbe0769 100644
--- a/lib/consumer.cc
+++ b/lib/consumer.cc
@@ -128,48 +128,48 @@ namespace opkele {
}
string consumer_t::checkid_setup(const string& identity,const string& return_to,const string& trust_root) {
return checkid_(mode_checkid_setup,identity,return_to,trust_root);
}
string consumer_t::checkid_(mode_t mode,const string& identity,const string& return_to,const string& trust_root) {
params_t p;
if(mode==mode_checkid_immediate)
p["mode"]="checkid_immediate";
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())
p["trust_root"] = trust_root;
p["return_to"] = return_to;
try {
try {
string ah = find_assoc(server)->handle();
p["assoc_handle"] = ah;
}catch(failed_lookup& fl) {
string ah = associate(server)->handle();
p["assoc_handle"] = ah;
}
}catch(exception& e) { }
return p.append_query(server);
}
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;
vector<unsigned char> sig;
mimetic::decode(
sigenc.begin(),sigenc.end(), b,
back_insert_iterator<vector<unsigned char> >(sig) );
const string& slist = pin.get_param("openid.signed");
string kv;
string::size_type p = 0;
while(true) {
@@ -304,13 +304,38 @@ namespace opkele {
if(!server.empty())
break;
}
}
if(server.empty())
throw failed_assertion(OPKELE_CP_ "The location has no openid.server declaration");
}
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
@@ -74,49 +74,24 @@ namespace opkele {
tm_t.tm_mon--;
tm_t.tm_year-=1900;
time_t rv = mktime(&tm_t);
if(rv==(time_t)-1)
throw failed_conversion(OPKELE_CP_ "failed to mktime()");
return rv;
}
/*
*
*/
- 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()");
string rv(t);
curl_free(t);
return rv;
}
string long_to_string(long l) {
char rv[32];
int r=snprintf(rv,sizeof(rv),"%ld",l);