summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--include/opkele/consumer.h2
-rw-r--r--include/opkele/util.h1
-rw-r--r--lib/consumer.cc29
-rw-r--r--lib/util.cc25
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
@@ -128,6 +128,8 @@ namespace opkele {
128 */ 128 */
129 void check_authentication(const string& server,const params_t& p); 129 void check_authentication(const string& server,const params_t& p);
130 130
131 static string canonicalize(const string& url);
132
131 }; 133 };
132 134
133} 135}
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
@@ -48,7 +48,6 @@ namespace opkele {
48 string time_to_w3c(time_t t); 48 string time_to_w3c(time_t t);
49 time_t w3c_to_time(const string& w); 49 time_t w3c_to_time(const string& w);
50 50
51 string canonicalize_url(const string& url);
52 string url_encode(const string& str); 51 string url_encode(const string& str);
53 52
54 string long_to_string(long l); 53 string long_to_string(long l);
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}
diff --git a/lib/util.cc b/lib/util.cc
index 1e7335c..d78b5e0 100644
--- a/lib/util.cc
+++ b/lib/util.cc
@@ -83,31 +83,6 @@ namespace opkele {
83 * 83 *
84 */ 84 */
85 85
86 string canonicalize_url(const string& url) {
87 string rv = url;
88 // strip leading and trailing spaces
89 string::size_type i = rv.find_first_not_of(" \t\r\n");
90 if(i==string::npos)
91 throw bad_input(OPKELE_CP_ "empty URL");
92 if(i)
93 rv.erase(0,i);
94 i = rv.find_last_not_of(" \t\r\n");
95 assert(i!=string::npos);
96 if(i<(rv.length()-1))
97 rv.erase(i+1);
98 // add missing http://
99 i = rv.find("://");
100 if(i==string::npos) { // primitive. but do we need more?
101 rv.insert(0,"http://");
102 i = sizeof("http://")-1;
103 }else{
104 i += sizeof("://")-1;
105 }
106 if(rv.find('/',i)==string::npos)
107 rv += '/';
108 return rv;
109 }
110
111 string url_encode(const string& str) { 86 string url_encode(const string& str) {
112 char * t = curl_escape(str.c_str(),str.length()); 87 char * t = curl_escape(str.c_str(),str.length());
113 if(!t) 88 if(!t)