summaryrefslogtreecommitdiffabout
authorMichael Krelin <hacker@klever.net>2008-03-03 14:58:09 (UTC)
committer Michael Krelin <hacker@klever.net>2008-03-03 14:58:09 (UTC)
commit0182b9dee269f1a8f3fc0794bfdf4a143fa1b5be (patch) (side-by-side diff)
tree0e435d48a9d2b94ff309c8fea2d416e0e14d8b2a
parent5fd5ecad8c2bd1e8846c11fa9b281f0f4ab8a4a7 (diff)
downloadlibopkele-0182b9dee269f1a8f3fc0794bfdf4a143fa1b5be.zip
libopkele-0182b9dee269f1a8f3fc0794bfdf4a143fa1b5be.tar.gz
libopkele-0182b9dee269f1a8f3fc0794bfdf4a143fa1b5be.tar.bz2
added append_to() to basic_openid_message
Signed-off-by: Michael Krelin <hacker@klever.net>
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--include/opkele/types.h1
-rw-r--r--lib/openid_message.cc9
2 files changed, 7 insertions, 3 deletions
diff --git a/include/opkele/types.h b/include/opkele/types.h
index af7fb1a..ffb9afb 100644
--- a/include/opkele/types.h
+++ b/include/opkele/types.h
@@ -108,48 +108,49 @@ namespace opkele {
virtual bool stateless() const = 0;
/**
* check whether the association is expired.
* @return true if expired
*/
virtual bool is_expired() const = 0;
};
/**
* the shared_ptr<> for association_t object type
*/
typedef tr1mem::shared_ptr<association_t> assoc_t;
class basic_openid_message {
public:
typedef list<string> fields_t;
typedef util::forward_iterator_proxy<
string,const string&,const string*
> fields_iterator;
basic_openid_message() { }
virtual ~basic_openid_message() { }
basic_openid_message(const basic_openid_message& x);
void copy_to(basic_openid_message& x) const;
+ void append_to(basic_openid_message& x) const;
virtual bool has_field(const string& n) const = 0;
virtual const string& get_field(const string& n) const = 0;
virtual bool has_ns(const string& uri) const;
virtual string get_ns(const string& uri) const;
virtual fields_iterator fields_begin() const = 0;
virtual fields_iterator fields_end() const = 0;
virtual string append_query(const string& url,const char *pfx="openid.") const;
virtual string query_string(const char *pfx="openid.") const;
virtual void reset_fields();
virtual void set_field(const string& n,const string& v);
virtual void reset_field(const string& n);
virtual void from_keyvalues(const string& kv);
virtual void to_keyvalues(ostream& o) const;
virtual void to_htmlhiddens(ostream& o,const char* pfx=0) const;
void add_to_signed(const string& fields);
diff --git a/lib/openid_message.cc b/lib/openid_message.cc
index 4b9179b..e244f43 100644
--- a/lib/openid_message.cc
+++ b/lib/openid_message.cc
@@ -1,54 +1,57 @@
#include <cassert>
#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_copier : public unary_function<const string&,void> {
public:
const basic_openid_message& from;
basic_openid_message& to;
__om_copier(basic_openid_message& t,const basic_openid_message& f)
- : from(f), to(t) {
- to.reset_fields();
- }
+ : from(f), to(t) { }
result_type operator()(argument_type f) {
to.set_field(f,from.get_field(f)); }
};
basic_openid_message::basic_openid_message(const basic_openid_message& x) {
x.copy_to(*this);
}
void basic_openid_message::copy_to(basic_openid_message& x) const {
+ x.reset_fields();
+ for_each(fields_begin(),fields_end(),
+ __om_copier(x,*this) );
+ }
+ void basic_openid_message::append_to(basic_openid_message& x) const {
for_each(fields_begin(),fields_end(),
__om_copier(x,*this) );
}
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);