summaryrefslogtreecommitdiffabout
authorMichael Krelin <hacker@klever.net>2007-01-12 14:21:03 (UTC)
committer Michael Krelin <hacker@klever.net>2007-01-12 14:21:03 (UTC)
commit83516ff76d24142cdc5193875ee7b684652f2eaf (patch) (side-by-side diff)
treeee0eedac2f6bb63beaa25291fab47fe40d1e8662
parent782d7a9e2c07ff6621b754595642aa3fec377bd2 (diff)
downloadlibopkele-83516ff76d24142cdc5193875ee7b684652f2eaf.zip
libopkele-83516ff76d24142cdc5193875ee7b684652f2eaf.tar.gz
libopkele-83516ff76d24142cdc5193875ee7b684652f2eaf.tar.bz2
Be a bit more liberal in what we accept as key-value pairs
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--NEWS.xml1
-rw-r--r--lib/params.cc3
2 files changed, 3 insertions, 1 deletions
diff --git a/NEWS.xml b/NEWS.xml
index d8b93f2..210cf13 100644
--- a/NEWS.xml
+++ b/NEWS.xml
@@ -1,11 +1,12 @@
<?xml version="1.0" encoding="us-ascii"?>
<news>
<version version="0.1" date="January 12th, 2007">
<ni>OpenID simple registration extension implementation</ni>
<ni>OpenID extensions framework</ni>
<ni>Canonicalization bugfix</ni>
+ <ni>Slightly improved interoperability with buggy implementations</ni>
</version>
<version version="0.0" date="July 25th, 2005">
<ni>Initial release</ni>
</version>
</news>
diff --git a/lib/params.cc b/lib/params.cc
index 03867d5..b181811 100644
--- a/lib/params.cc
+++ b/lib/params.cc
@@ -1,84 +1,85 @@
#include <opkele/types.h>
#include <opkele/exception.h>
#include <opkele/util.h>
#include <openssl/sha.h>
#include <openssl/hmac.h>
namespace opkele {
using namespace std;
bool params_t::has_param(const string& n) const {
return find(n)!=end();
}
const string& params_t::get_param(const string& n) const {
const_iterator i = find(n);
if(i==end())
throw failed_lookup(OPKELE_CP_ n+": no such parameter");
return i->second;
}
string& params_t::get_param(const string& n) {
iterator i = find(n);
if(i==end())
throw failed_lookup(OPKELE_CP_ n+": no such parameter");
return i->second;
}
void params_t::parse_keyvalues(const string& kv) {
clear();
string::size_type p = 0;
while(true) {
string::size_type co = kv.find(':',p);
if(co==string::npos)
break;
string::size_type nl = kv.find('\n',co+1);
if(nl==string::npos)
throw bad_input(OPKELE_CP_ "malformed input");
- insert(value_type(kv.substr(p,co-p),kv.substr(co+1,nl-co-1)));
+ if(nl>co)
+ insert(value_type(kv.substr(p,co-p),kv.substr(co+1,nl-co-1)));
p = nl+1;
}
}
void params_t::sign(secret_t secret,string& sig,const string& slist,const char *prefix) const {
string kv;
string::size_type p = 0;
while(true) {
string::size_type co = slist.find(',',p);
string f = (co==string::npos)?slist.substr(p):slist.substr(p,co-p);
kv += f;
kv += ':';
if(prefix) f.insert(0,prefix);
kv += get_param(f);
kv += '\n';
if(co==string::npos)
break;
p = co+1;
}
unsigned int md_len = 0;
unsigned char *md = HMAC(
EVP_sha1(),
&(secret.front()),secret.size(),
(const unsigned char *)kv.data(),kv.length(),
0,&md_len);
sig = util::encode_base64(md,md_len);
}
string params_t::append_query(const string& url,const char *prefix) const {
string rv = url;
bool p = true;
if(rv.find('?')==string::npos) {
rv += '?';
p = false;
}
for(const_iterator i=begin();i!=end();++i) {
if(p)
rv += '&';
else
p = true;
rv += prefix;
rv += i->first;
rv += '=';
rv += util::url_encode(i->second);
}
return rv;
}