summaryrefslogtreecommitdiffabout
path: root/lib/openid_message.cc
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) (unidiff)
tree0e435d48a9d2b94ff309c8fea2d416e0e14d8b2a /lib/openid_message.cc
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 (limited to 'lib/openid_message.cc') (more/less context) (show whitespace changes)
-rw-r--r--lib/openid_message.cc9
1 files changed, 6 insertions, 3 deletions
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,78 +1,81 @@
1#include <cassert> 1#include <cassert>
2#include <opkele/types.h> 2#include <opkele/types.h>
3#include <opkele/exception.h> 3#include <opkele/exception.h>
4#include <opkele/util.h> 4#include <opkele/util.h>
5#include <opkele/debug.h> 5#include <opkele/debug.h>
6 6
7#include "config.h" 7#include "config.h"
8 8
9namespace opkele { 9namespace opkele {
10 using std::input_iterator_tag; 10 using std::input_iterator_tag;
11 using std::unary_function; 11 using std::unary_function;
12 12
13 struct __om_copier : public unary_function<const string&,void> { 13 struct __om_copier : public unary_function<const string&,void> {
14 public: 14 public:
15 const basic_openid_message& from; 15 const basic_openid_message& from;
16 basic_openid_message& to; 16 basic_openid_message& to;
17 17
18 __om_copier(basic_openid_message& t,const basic_openid_message& f) 18 __om_copier(basic_openid_message& t,const basic_openid_message& f)
19 : from(f), to(t) { 19 : from(f), to(t) { }
20 to.reset_fields();
21 }
22 20
23 result_type operator()(argument_type f) { 21 result_type operator()(argument_type f) {
24 to.set_field(f,from.get_field(f)); } 22 to.set_field(f,from.get_field(f)); }
25 }; 23 };
26 24
27 basic_openid_message::basic_openid_message(const basic_openid_message& x) { 25 basic_openid_message::basic_openid_message(const basic_openid_message& x) {
28 x.copy_to(*this); 26 x.copy_to(*this);
29 } 27 }
30 void basic_openid_message::copy_to(basic_openid_message& x) const { 28 void basic_openid_message::copy_to(basic_openid_message& x) const {
29 x.reset_fields();
30 for_each(fields_begin(),fields_end(),
31 __om_copier(x,*this) );
32 }
33 void basic_openid_message::append_to(basic_openid_message& x) const {
31 for_each(fields_begin(),fields_end(), 34 for_each(fields_begin(),fields_end(),
32 __om_copier(x,*this) ); 35 __om_copier(x,*this) );
33 } 36 }
34 37
35 struct __om_ns_finder : public unary_function<const string&,bool> { 38 struct __om_ns_finder : public unary_function<const string&,bool> {
36 public: 39 public:
37 const basic_openid_message& om; 40 const basic_openid_message& om;
38 const string& uri; 41 const string& uri;
39 42
40 __om_ns_finder(const basic_openid_message& m, 43 __om_ns_finder(const basic_openid_message& m,
41 const string& u) : om(m), uri(u) { } 44 const string& u) : om(m), uri(u) { }
42 45
43 result_type operator()(argument_type f) { 46 result_type operator()(argument_type f) {
44 return 47 return
45 (!strncmp(f.c_str(),"ns.",sizeof("ns.")-1)) 48 (!strncmp(f.c_str(),"ns.",sizeof("ns.")-1))
46 && om.get_field(f)==uri ; 49 && om.get_field(f)==uri ;
47 } 50 }
48 }; 51 };
49 52
50 bool basic_openid_message::has_ns(const string& uri) const { 53 bool basic_openid_message::has_ns(const string& uri) const {
51 fields_iterator ei = fields_end(); 54 fields_iterator ei = fields_end();
52 fields_iterator i = find_if(fields_begin(),fields_end(), 55 fields_iterator i = find_if(fields_begin(),fields_end(),
53 __om_ns_finder(*this,uri)); 56 __om_ns_finder(*this,uri));
54 return !(i==ei); 57 return !(i==ei);
55 } 58 }
56 string basic_openid_message::get_ns(const string& uri) const { 59 string basic_openid_message::get_ns(const string& uri) const {
57 fields_iterator ei = fields_end(); 60 fields_iterator ei = fields_end();
58 fields_iterator i = find_if(fields_begin(),fields_end(), 61 fields_iterator i = find_if(fields_begin(),fields_end(),
59 __om_ns_finder(*this,uri)); 62 __om_ns_finder(*this,uri));
60 if(i==ei) 63 if(i==ei)
61 throw failed_lookup(OPKELE_CP_ string("failed to find namespace ")+uri); 64 throw failed_lookup(OPKELE_CP_ string("failed to find namespace ")+uri);
62 return i->substr(3); 65 return i->substr(3);
63 } 66 }
64 67
65 struct __om_query_builder : public unary_function<const string&,void> { 68 struct __om_query_builder : public unary_function<const string&,void> {
66 public: 69 public:
67 const basic_openid_message& om; 70 const basic_openid_message& om;
68 bool first; 71 bool first;
69 string& rv; 72 string& rv;
70 const char *pfx; 73 const char *pfx;
71 74
72 __om_query_builder(const char *p,string& r,const basic_openid_message& m) 75 __om_query_builder(const char *p,string& r,const basic_openid_message& m)
73 : om(m), first(true), rv(r), pfx(p) { 76 : om(m), first(true), rv(r), pfx(p) {
74 for_each(om.fields_begin(),om.fields_end(),*this); 77 for_each(om.fields_begin(),om.fields_end(),*this);
75 } 78 }
76 __om_query_builder(const char *p,string& r,const basic_openid_message& m,const string& u) 79 __om_query_builder(const char *p,string& r,const basic_openid_message& m,const string& u)
77 : om(m), first(true), rv(r), pfx(p) { 80 : om(m), first(true), rv(r), pfx(p) {
78 rv = u; 81 rv = u;