-rw-r--r-- | lib/message.cc | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/message.cc b/lib/message.cc index 524946a..c1f8088 100644 --- a/lib/message.cc +++ b/lib/message.cc | |||
@@ -97,100 +97,100 @@ namespace opkele { | |||
97 | const char *pfx; | 97 | const char *pfx; |
98 | 98 | ||
99 | __om_html_outputter(const basic_openid_message& m,ostream& s,const char *p=0) | 99 | __om_html_outputter(const basic_openid_message& m,ostream& s,const char *p=0) |
100 | : om(m), os(s), pfx(p) { } | 100 | : om(m), os(s), pfx(p) { } |
101 | 101 | ||
102 | result_type operator()(argument_type f) { | 102 | result_type operator()(argument_type f) { |
103 | os << | 103 | os << |
104 | "<input type=\"hidden\"" | 104 | "<input type=\"hidden\"" |
105 | " name=\""; | 105 | " name=\""; |
106 | if(pfx) | 106 | if(pfx) |
107 | os << util::attr_escape(pfx); | 107 | os << util::attr_escape(pfx); |
108 | os << util::attr_escape(f) << "\"" | 108 | os << util::attr_escape(f) << "\"" |
109 | " value=\"" << util::attr_escape(om.get_field(f)) << "\" />"; | 109 | " value=\"" << util::attr_escape(om.get_field(f)) << "\" />"; |
110 | } | 110 | } |
111 | }; | 111 | }; |
112 | 112 | ||
113 | void basic_openid_message::to_htmlhiddens(ostream& o,const char* pfx) const { | 113 | void basic_openid_message::to_htmlhiddens(ostream& o,const char* pfx) const { |
114 | for_each(fields_begin(),fields_end(),__om_html_outputter(*this,o,pfx)); | 114 | for_each(fields_begin(),fields_end(),__om_html_outputter(*this,o,pfx)); |
115 | } | 115 | } |
116 | 116 | ||
117 | void basic_openid_message::add_to_signed(const string& fields) { | 117 | void basic_openid_message::add_to_signed(const string& fields) { |
118 | string::size_type fnc = fields.find_first_not_of(","); | 118 | string::size_type fnc = fields.find_first_not_of(","); |
119 | if(fnc==string::npos) | 119 | if(fnc==string::npos) |
120 | throw bad_input(OPKELE_CP_ "Trying to add nothing in particular to the list of signed fields"); | 120 | throw bad_input(OPKELE_CP_ "Trying to add nothing in particular to the list of signed fields"); |
121 | string signeds; | 121 | string signeds; |
122 | try { | 122 | try { |
123 | signeds = get_field("signed"); | 123 | signeds = get_field("signed"); |
124 | string::size_type lnc = signeds.find_last_not_of(","); | 124 | string::size_type lnc = signeds.find_last_not_of(","); |
125 | if(lnc==string::npos) | 125 | if(lnc==string::npos) |
126 | signeds.assign(fields,fnc,fields.size()-fnc); | 126 | signeds.assign(fields,fnc,fields.size()-fnc); |
127 | else{ | 127 | else{ |
128 | string::size_type ss = signeds.size(); | 128 | string::size_type ss = signeds.size(); |
129 | if(lnc==(ss-1)) { | 129 | if(lnc==(ss-1)) { |
130 | signeds+= ','; | 130 | signeds+= ','; |
131 | signeds.append(fields,fnc,fields.size()-fnc); | 131 | signeds.append(fields,fnc,fields.size()-fnc); |
132 | }else{ | 132 | }else{ |
133 | if(lnc<(ss-2)) | 133 | if(lnc<(ss-2)) |
134 | signeds.replace(lnc+2,ss-lnc-2, | 134 | signeds.replace(lnc+2,ss-lnc-2, |
135 | fields,fnc,fields.size()-fnc); | 135 | fields,fnc,fields.size()-fnc); |
136 | else | 136 | else |
137 | signeds.append(fields,fnc,fields.size()-fnc); | 137 | signeds.append(fields,fnc,fields.size()-fnc); |
138 | } | 138 | } |
139 | } | 139 | } |
140 | }catch(failed_lookup&) { | 140 | }catch(failed_lookup&) { |
141 | signeds.assign(fields,fnc,fields.size()-fnc); | 141 | signeds.assign(fields,fnc,fields.size()-fnc); |
142 | } | 142 | } |
143 | set_field("signed",signeds); | 143 | set_field("signed",signeds); |
144 | } | 144 | } |
145 | 145 | ||
146 | string basic_openid_message::find_ns(const string& uri,const char *pfx) const { | 146 | string basic_openid_message::find_ns(const string& uri,const char *pfx) const { |
147 | try { | 147 | try { |
148 | return get_ns(uri); | 148 | return get_ns(uri); |
149 | }catch(failed_lookup&) { | 149 | }catch(failed_lookup&) { |
150 | return pfx; | 150 | return pfx; |
151 | } | 151 | } |
152 | } | 152 | } |
153 | string basic_openid_message::allocate_ns(const string& uri,const char *pfx) { | 153 | string basic_openid_message::allocate_ns(const string& uri,const char *pfx) { |
154 | if(!has_field("ns")) | 154 | if(!has_field("ns")) |
155 | return pfx; | 155 | return pfx; |
156 | if(has_ns(uri)) | 156 | if(has_ns(uri)) |
157 | throw bad_input(OPKELE_CP_ "OpenID message already contains namespace"); | 157 | throw bad_input(OPKELE_CP_ "OpenID message already contains namespace"); |
158 | string rv = pfx; | 158 | string rv = pfx; |
159 | if(has_field("ns."+rv)) { | 159 | if(has_field("ns."+rv)) { |
160 | string::reference c=rv[rv.length()]; | 160 | string::reference c=rv[rv.length()]; |
161 | for(c='a';c<='z' && has_field("ns."+rv);++c); | 161 | for(c='a';c<='z' && has_field("ns."+rv);++c) ; |
162 | if(c=='z') | 162 | if(c=='z') |
163 | throw exception(OPKELE_CP_ "Failed to allocate namespace"); | 163 | throw exception(OPKELE_CP_ "Failed to allocate namespace"); |
164 | } | 164 | } |
165 | set_field("ns."+rv,uri); | 165 | set_field("ns."+rv,uri); |
166 | return rv; | 166 | return rv; |
167 | } | 167 | } |
168 | 168 | ||
169 | bool openid_message_t::has_field(const string& n) const { | 169 | bool openid_message_t::has_field(const string& n) const { |
170 | return find(n)!=end(); | 170 | return find(n)!=end(); |
171 | } | 171 | } |
172 | const string& openid_message_t::get_field(const string& n) const { | 172 | const string& openid_message_t::get_field(const string& n) const { |
173 | const_iterator i=find(n); | 173 | const_iterator i=find(n); |
174 | if(i==end()) | 174 | if(i==end()) |
175 | throw failed_lookup(OPKELE_CP_ n+": no such field"); | 175 | throw failed_lookup(OPKELE_CP_ n+": no such field"); |
176 | return i->second; | 176 | return i->second; |
177 | } | 177 | } |
178 | 178 | ||
179 | openid_message_t::fields_iterator openid_message_t::fields_begin() const { | 179 | openid_message_t::fields_iterator openid_message_t::fields_begin() const { |
180 | return util::map_keys_iterator<const_iterator,string,const string&,const string*>(begin(),end()); | 180 | return util::map_keys_iterator<const_iterator,string,const string&,const string*>(begin(),end()); |
181 | } | 181 | } |
182 | openid_message_t::fields_iterator openid_message_t::fields_end() const { | 182 | openid_message_t::fields_iterator openid_message_t::fields_end() const { |
183 | return util::map_keys_iterator<const_iterator,string,const string&,const string*>(end(),end()); | 183 | return util::map_keys_iterator<const_iterator,string,const string&,const string*>(end(),end()); |
184 | } | 184 | } |
185 | 185 | ||
186 | void openid_message_t::reset_fields() { | 186 | void openid_message_t::reset_fields() { |
187 | clear(); | 187 | clear(); |
188 | } | 188 | } |
189 | void openid_message_t::set_field(const string& n,const string& v) { | 189 | void openid_message_t::set_field(const string& n,const string& v) { |
190 | (*this)[n]=v; | 190 | (*this)[n]=v; |
191 | } | 191 | } |
192 | void openid_message_t::reset_field(const string& n) { | 192 | void openid_message_t::reset_field(const string& n) { |
193 | erase(n); | 193 | erase(n); |
194 | } | 194 | } |
195 | 195 | ||
196 | } | 196 | } |