summaryrefslogtreecommitdiffabout
path: root/lib/message.cc
authorMichael Krelin <hacker@klever.net>2008-06-27 18:32:31 (UTC)
committer Michael Krelin <hacker@klever.net>2008-06-27 18:32:31 (UTC)
commita344edbdddeac51524001faa10d06f85cfdb041c (patch) (side-by-side diff)
treebca2afabf4fdc53324fc48e101fc9de068404e47 /lib/message.cc
parent9737a1eb0f01cdc805c4a28f0a86734eb3bb4d31 (diff)
downloadlibopkele-a344edbdddeac51524001faa10d06f85cfdb041c.zip
libopkele-a344edbdddeac51524001faa10d06f85cfdb041c.tar.gz
libopkele-a344edbdddeac51524001faa10d06f85cfdb041c.tar.bz2
Fix for gcc 4.3
Thanks to Oden Eriksson of Mandriva for report and patch Signed-off-by: Michael Krelin <hacker@klever.net>
Diffstat (limited to 'lib/message.cc') (more/less context) (ignore whitespace changes)
-rw-r--r--lib/message.cc2
1 files changed, 2 insertions, 0 deletions
diff --git a/lib/message.cc b/lib/message.cc
index b2324b7..524946a 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -1,97 +1,99 @@
#include <cassert>
+#include <algorithm>
+
#include <opkele/types.h>
#include <opkele/exception.h>
#include <opkele/util.h>
#include <opkele/debug.h>
#include "config.h"
namespace opkele {
using std::input_iterator_tag;
using std::unary_function;
struct __om_ns_finder : public unary_function<const string&,bool> {
public:
const basic_openid_message& om;
const string& uri;
__om_ns_finder(const basic_openid_message& m,
const string& u) : om(m), uri(u) { }
result_type operator()(argument_type f) {
return
(!strncmp(f.c_str(),"ns.",sizeof("ns.")-1))
&& om.get_field(f)==uri ;
}
};
bool basic_openid_message::has_ns(const string& uri) const {
fields_iterator ei = fields_end();
fields_iterator i = find_if(fields_begin(),fields_end(),
__om_ns_finder(*this,uri));
return !(i==ei);
}
string basic_openid_message::get_ns(const string& uri) const {
fields_iterator ei = fields_end();
fields_iterator i = find_if(fields_begin(),fields_end(),
__om_ns_finder(*this,uri));
if(i==ei)
throw failed_lookup(OPKELE_CP_ string("failed to find namespace ")+uri);
return i->substr(3);
}
void basic_openid_message::from_keyvalues(const string& kv) {
reset_fields();
string::size_type p = 0;
while(true) {
string::size_type co = kv.find(':',p);
if(co==string::npos)
break;
#ifndef POSTELS_LAW
string::size_type nl = kv.find('\n',co+1);
if(nl==string::npos)
throw bad_input(OPKELE_CP_ "malformed input");
if(nl>co)
set_field(kv.substr(p,co-p),kv.substr(co+1,nl-co-1));
p = nl+1;
#else /* POSTELS_LAW */
string::size_type lb = kv.find_first_of("\r\n",co+1);
if(lb==string::npos) {
set_field(kv.substr(p,co-p),kv.substr(co+1));
break;
}
if(lb>co)
set_field(kv.substr(p,co-p),kv.substr(co+1,lb-co-1));
string::size_type nolb = kv.find_first_not_of("\r\n",lb);
if(nolb==string::npos)
break;
p = nolb;
#endif /* POSTELS_LAW */
}
}
struct __om_kv_outputter : public unary_function<const string&,void> {
public:
const basic_openid_message& om;
ostream& os;
__om_kv_outputter(const basic_openid_message& m,ostream& s)
: om(m), os(s) { }
result_type operator()(argument_type f) {
os << f << ':' << om.get_field(f) << '\n';
}
};
void basic_openid_message::to_keyvalues(ostream& o) const {
for_each(fields_begin(),fields_end(),__om_kv_outputter(*this,o));
}
struct __om_html_outputter : public unary_function<const string&,void> {
public:
const basic_openid_message& om;
ostream& os;
const char *pfx;
__om_html_outputter(const basic_openid_message& m,ostream& s,const char *p=0)