summaryrefslogtreecommitdiffabout
authorMichael Krelin <hacker@klever.net>2008-02-02 10:49:52 (UTC)
committer Michael Krelin <hacker@klever.net>2008-02-02 10:49:52 (UTC)
commitf29ad6501686e5f43b536258b86d12683c711f02 (patch) (unidiff)
tree79ce9cf3f75449846bdf556550eaa927b20074be
parent61e6da06804f98d0cbb9d27eeb335351b3e05d4d (diff)
downloadlibopkele-f29ad6501686e5f43b536258b86d12683c711f02.zip
libopkele-f29ad6501686e5f43b536258b86d12683c711f02.tar.gz
libopkele-f29ad6501686e5f43b536258b86d12683c711f02.tar.bz2
generate html form hiddens from the openid message
Signed-off-by: Michael Krelin <hacker@klever.net>
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--include/opkele/types.h2
-rw-r--r--lib/openid_message.cc20
2 files changed, 22 insertions, 0 deletions
diff --git a/include/opkele/types.h b/include/opkele/types.h
index 842a722..5d39a5c 100644
--- a/include/opkele/types.h
+++ b/include/opkele/types.h
@@ -139,24 +139,26 @@ namespace opkele {
139 139
140 virtual string append_query(const string& url) const; 140 virtual string append_query(const string& url) const;
141 virtual string query_string() const; 141 virtual string query_string() const;
142 142
143 143
144 virtual void reset_fields(); 144 virtual void reset_fields();
145 virtual void set_field(const string& n,const string& v); 145 virtual void set_field(const string& n,const string& v);
146 virtual void reset_field(const string& n); 146 virtual void reset_field(const string& n);
147 147
148 virtual void from_keyvalues(const string& kv); 148 virtual void from_keyvalues(const string& kv);
149 virtual void to_keyvalues(ostream& o) const; 149 virtual void to_keyvalues(ostream& o) const;
150 150
151 virtual void to_htmlhiddens(ostream& o) const;
152
151 void add_to_signed(const string& fields); 153 void add_to_signed(const string& fields);
152 string find_ns(const string& uri,const char *pfx) const; 154 string find_ns(const string& uri,const char *pfx) const;
153 string allocate_ns(const string& uri,const char *pfx); 155 string allocate_ns(const string& uri,const char *pfx);
154 }; 156 };
155 157
156 class openid_message_t : public basic_openid_message, public map<string,string> { 158 class openid_message_t : public basic_openid_message, public map<string,string> {
157 public: 159 public:
158 openid_message_t() { } 160 openid_message_t() { }
159 openid_message_t(const basic_openid_message& x) 161 openid_message_t(const basic_openid_message& x)
160 : basic_openid_message(x) { } 162 : basic_openid_message(x) { }
161 163
162 void copy_to(basic_openid_message& x) const; 164 void copy_to(basic_openid_message& x) const;
diff --git a/lib/openid_message.cc b/lib/openid_message.cc
index 905ea95..fdb4b04 100644
--- a/lib/openid_message.cc
+++ b/lib/openid_message.cc
@@ -150,24 +150,44 @@ namespace opkele {
150 __om_kv_outputter(const basic_openid_message& om,ostream& os) 150 __om_kv_outputter(const basic_openid_message& om,ostream& os)
151 : om(om), os(os) { } 151 : om(om), os(os) { }
152 152
153 result_type operator()(argument_type f) { 153 result_type operator()(argument_type f) {
154 os << f << ':' << om.get_field(f) << '\n'; 154 os << f << ':' << om.get_field(f) << '\n';
155 } 155 }
156 }; 156 };
157 157
158 void basic_openid_message::to_keyvalues(ostream& o) const { 158 void basic_openid_message::to_keyvalues(ostream& o) const {
159 for_each(fields_begin(),fields_end(),__om_kv_outputter(*this,o)); 159 for_each(fields_begin(),fields_end(),__om_kv_outputter(*this,o));
160 } 160 }
161 161
162 struct __om_html_outputter : public unary_function<const string&,void> {
163 public:
164 const basic_openid_message& om;
165 ostream& os;
166
167 __om_html_outputter(const basic_openid_message& om,ostream& os)
168 : om(om), os(os) { }
169
170 result_type operator()(argument_type f) {
171 os <<
172 "<input type=\"hidden\""
173 " name=\"" << util::attr_escape(f) << "\""
174 " value=\"" << util::attr_escape(om.get_field(f)) << "\" />";
175 }
176 };
177
178 void basic_openid_message::to_htmlhiddens(ostream& o) const {
179 for_each(fields_begin(),fields_end(),__om_html_outputter(*this,o));
180 }
181
162 void basic_openid_message::add_to_signed(const string& fields) { 182 void basic_openid_message::add_to_signed(const string& fields) {
163 string::size_type fnc = fields.find_first_not_of(","); 183 string::size_type fnc = fields.find_first_not_of(",");
164 if(fnc==string::npos) 184 if(fnc==string::npos)
165 throw bad_input(OPKELE_CP_ "Trying to add nothing in particular to the list of signed fields"); 185 throw bad_input(OPKELE_CP_ "Trying to add nothing in particular to the list of signed fields");
166 string signeds; 186 string signeds;
167 try { 187 try {
168 signeds = get_field("signed"); 188 signeds = get_field("signed");
169 string::size_type lnc = signeds.find_last_not_of(","); 189 string::size_type lnc = signeds.find_last_not_of(",");
170 if(lnc==string::npos) 190 if(lnc==string::npos)
171 signeds.assign(fields,fnc,fields.size()-fnc); 191 signeds.assign(fields,fnc,fields.size()-fnc);
172 else{ 192 else{
173 string::size_type ss = signeds.size(); 193 string::size_type ss = signeds.size();