author | Michael Krelin <hacker@klever.net> | 2008-06-27 21:00:41 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2008-06-27 21:00:41 (UTC) |
commit | 362678728b8232c9490e14ba14ff323d9a92d6be (patch) (unidiff) | |
tree | 105675f96fff87916b2fdea8b51ad9fe98c5531d | |
parent | a344edbdddeac51524001faa10d06f85cfdb041c (diff) | |
download | libopkele-362678728b8232c9490e14ba14ff323d9a92d6be.zip libopkele-362678728b8232c9490e14ba14ff323d9a92d6be.tar.gz libopkele-362678728b8232c9490e14ba14ff323d9a92d6be.tar.bz2 |
made gcc 4.3 a bit happier
Signed-off-by: Michael Krelin <hacker@klever.net>
-rw-r--r-- | include/opkele/iterator.h | 4 | ||||
-rw-r--r-- | lib/discovery.cc | 4 | ||||
-rw-r--r-- | lib/message.cc | 2 | ||||
-rw-r--r-- | lib/prequeue_rp.cc | 4 | ||||
-rw-r--r-- | lib/secret.cc | 2 | ||||
-rw-r--r-- | lib/util.cc | 6 |
6 files changed, 11 insertions, 11 deletions
diff --git a/include/opkele/iterator.h b/include/opkele/iterator.h index 28c1c83..8f86234 100644 --- a/include/opkele/iterator.h +++ b/include/opkele/iterator.h | |||
@@ -126,77 +126,77 @@ namespace opkele { | |||
126 | class basic_filterator : public iterator< | 126 | class basic_filterator : public iterator< |
127 | typename IT::iterator_category, | 127 | typename IT::iterator_category, |
128 | typename IT::value_type, | 128 | typename IT::value_type, |
129 | typename IT::difference_type, | 129 | typename IT::difference_type, |
130 | typename IT::pointer, | 130 | typename IT::pointer, |
131 | typename IT::reference> { | 131 | typename IT::reference> { |
132 | public: | 132 | public: |
133 | IT it; | 133 | IT it; |
134 | IT ei; | 134 | IT ei; |
135 | bool empty; | 135 | bool empty; |
136 | 136 | ||
137 | basic_filterator() : empty(true) { } | 137 | basic_filterator() : empty(true) { } |
138 | basic_filterator(const IT& _bi,const IT& _ei) | 138 | basic_filterator(const IT& _bi,const IT& _ei) |
139 | : it(_bi), ei(_ei) { empty = (it==ei); } | 139 | : it(_bi), ei(_ei) { empty = (it==ei); } |
140 | basic_filterator(const basic_filterator<IT>& x) | 140 | basic_filterator(const basic_filterator<IT>& x) |
141 | : it(x.it), ei(x.ei), empty(x.empty) { } | 141 | : it(x.it), ei(x.ei), empty(x.empty) { } |
142 | virtual ~basic_filterator() { } | 142 | virtual ~basic_filterator() { } |
143 | 143 | ||
144 | bool operator==(const basic_filterator<IT>& x) const { | 144 | bool operator==(const basic_filterator<IT>& x) const { |
145 | return empty?x.empty:(it==x.it); } | 145 | return empty?x.empty:(it==x.it); } |
146 | bool operator!=(const basic_filterator<IT>& x) const { | 146 | bool operator!=(const basic_filterator<IT>& x) const { |
147 | return empty!=x.empty || it!=x.it; } | 147 | return empty!=x.empty || it!=x.it; } |
148 | 148 | ||
149 | typename IT::reference operator*() const { | 149 | typename IT::reference operator*() const { |
150 | assert(!empty); | 150 | assert(!empty); |
151 | return *it; } | 151 | return *it; } |
152 | typename IT::pointer operator->() const { | 152 | typename IT::pointer operator->() const { |
153 | assert(!empty); | 153 | assert(!empty); |
154 | return it.operator->(); } | 154 | return it.operator->(); } |
155 | 155 | ||
156 | basic_filterator<IT>& operator++() { | 156 | basic_filterator<IT>& operator++() { |
157 | bool found = false; | 157 | bool found = false; |
158 | for(++it;!(it==ei || (found=is_interesting()));++it); | 158 | for(++it;!(it==ei || (found=is_interesting()));++it) ; |
159 | if(!found) empty=true; | 159 | if(!found) empty=true; |
160 | return *this; | 160 | return *this; |
161 | } | 161 | } |
162 | basic_filterator<IT> operator++(int) { | 162 | basic_filterator<IT> operator++(int) { |
163 | basic_filterator<IT> rv(*this); | 163 | basic_filterator<IT> rv(*this); |
164 | ++(*this); | 164 | ++(*this); |
165 | return rv; | 165 | return rv; |
166 | } | 166 | } |
167 | 167 | ||
168 | void prepare() { | 168 | void prepare() { |
169 | bool found = false; | 169 | bool found = false; |
170 | for(;!(it==ei || (found=is_interesting()));++it); | 170 | for(;!(it==ei || (found=is_interesting()));++it) ; |
171 | if(!found) empty = true; | 171 | if(!found) empty = true; |
172 | } | 172 | } |
173 | virtual bool is_interesting() const = 0; | 173 | virtual bool is_interesting() const = 0; |
174 | }; | 174 | }; |
175 | 175 | ||
176 | template<typename IT,typename T=typename IT::value_type::first_type,typename TR=T&,typename TP=T*> | 176 | template<typename IT,typename T=typename IT::value_type::first_type,typename TR=T&,typename TP=T*> |
177 | class map_keys_iterator : public iterator< | 177 | class map_keys_iterator : public iterator< |
178 | typename IT::iterator_category, | 178 | typename IT::iterator_category, |
179 | T,void,TP,TR> { | 179 | T,void,TP,TR> { |
180 | public: | 180 | public: |
181 | typedef map_keys_iterator<IT,T,TR,TP> self_type; | 181 | typedef map_keys_iterator<IT,T,TR,TP> self_type; |
182 | IT it; | 182 | IT it; |
183 | IT ei; | 183 | IT ei; |
184 | bool empty; | 184 | bool empty; |
185 | 185 | ||
186 | map_keys_iterator() : empty(true) { } | 186 | map_keys_iterator() : empty(true) { } |
187 | map_keys_iterator(const IT& _bi, | 187 | map_keys_iterator(const IT& _bi, |
188 | const IT& _ei) | 188 | const IT& _ei) |
189 | : it(_bi), ei(_ei) { empty = (it==ei); } | 189 | : it(_bi), ei(_ei) { empty = (it==ei); } |
190 | map_keys_iterator(const self_type& x) | 190 | map_keys_iterator(const self_type& x) |
191 | : it(x.it), ei(x.ei), empty(x.empty) { } | 191 | : it(x.it), ei(x.ei), empty(x.empty) { } |
192 | 192 | ||
193 | bool operator==(const self_type& x) const { | 193 | bool operator==(const self_type& x) const { |
194 | return empty?x.empty:(it==x.it); } | 194 | return empty?x.empty:(it==x.it); } |
195 | bool operator!=(const self_type& x) const { | 195 | bool operator!=(const self_type& x) const { |
196 | return empty!=x.empty || it!=x.it; } | 196 | return empty!=x.empty || it!=x.it; } |
197 | 197 | ||
198 | TR operator*() const { | 198 | TR operator*() const { |
199 | assert(!empty); | 199 | assert(!empty); |
200 | return it->first; } | 200 | return it->first; } |
201 | TP operator->() const { | 201 | TP operator->() const { |
202 | assert(!empty); | 202 | assert(!empty); |
diff --git a/lib/discovery.cc b/lib/discovery.cc index d1989ec..984e308 100644 --- a/lib/discovery.cc +++ b/lib/discovery.cc | |||
@@ -310,65 +310,65 @@ namespace opkele { | |||
310 | size_t bytes = s*nm; | 310 | size_t bytes = s*nm; |
311 | const char *inbuf = (const char*)p; | 311 | const char *inbuf = (const char*)p; |
312 | if(xmode&xmode_html) { | 312 | if(xmode&xmode_html) { |
313 | size_t mbts = save_html.capacity()-save_html.size(); | 313 | size_t mbts = save_html.capacity()-save_html.size(); |
314 | size_t bts = 0; | 314 | size_t bts = 0; |
315 | if(mbts>0) { | 315 | if(mbts>0) { |
316 | bts = (bytes>mbts)?mbts:bytes; | 316 | bts = (bytes>mbts)?mbts:bytes; |
317 | save_html.append(inbuf,bts); | 317 | save_html.append(inbuf,bts); |
318 | } | 318 | } |
319 | if(skipping<0) return bts; | 319 | if(skipping<0) return bts; |
320 | } | 320 | } |
321 | if(skipping<0) return 0; | 321 | if(skipping<0) return 0; |
322 | bool rp = parse(inbuf,bytes,false); | 322 | bool rp = parse(inbuf,bytes,false); |
323 | if(!rp) { | 323 | if(!rp) { |
324 | parser_choked = true; | 324 | parser_choked = true; |
325 | skipping = -1; | 325 | skipping = -1; |
326 | if(!(xmode&xmode_html)) | 326 | if(!(xmode&xmode_html)) |
327 | bytes = 0; | 327 | bytes = 0; |
328 | } | 328 | } |
329 | return bytes; | 329 | return bytes; |
330 | } | 330 | } |
331 | size_t header(void *p,size_t s,size_t nm) { | 331 | size_t header(void *p,size_t s,size_t nm) { |
332 | size_t bytes = s*nm; | 332 | size_t bytes = s*nm; |
333 | const char *h = (const char*)p; | 333 | const char *h = (const char*)p; |
334 | const char *colon = (const char*)memchr(p,':',bytes); | 334 | const char *colon = (const char*)memchr(p,':',bytes); |
335 | const char *space = (const char*)memchr(p,' ',bytes); | 335 | const char *space = (const char*)memchr(p,' ',bytes); |
336 | if(space && ( (!colon) || space<colon ) ) { | 336 | if(space && ( (!colon) || space<colon ) ) { |
337 | xrds_location.clear(); http_content_type.clear(); | 337 | xrds_location.clear(); http_content_type.clear(); |
338 | }else if(colon) { | 338 | }else if(colon) { |
339 | const char *hv = ++colon; | 339 | const char *hv = ++colon; |
340 | size_t hnl = colon-h; | 340 | size_t hnl = colon-h; |
341 | int rb; | 341 | int rb; |
342 | for(rb = bytes-hnl-1;rb>0 && isspace(*hv);++hv,--rb); | 342 | for(rb = bytes-hnl-1;rb>0 && isspace(*hv);++hv,--rb) ; |
343 | while(rb>0 && isspace(hv[rb-1])) --rb; | 343 | while(rb>0 && isspace(hv[rb-1])) --rb; |
344 | if(rb) { | 344 | if(rb) { |
345 | if( (hnl>=sizeof(XRDS_HEADER)) | 345 | if( (hnl>=sizeof(XRDS_HEADER)) |
346 | && !strncasecmp(h,XRDS_HEADER":", | 346 | && !strncasecmp(h,XRDS_HEADER":", |
347 | sizeof(XRDS_HEADER)) ) { | 347 | sizeof(XRDS_HEADER)) ) { |
348 | xrds_location.assign(hv,rb); | 348 | xrds_location.assign(hv,rb); |
349 | }else if( (hnl>=sizeof(CT_HEADER)) | 349 | }else if( (hnl>=sizeof(CT_HEADER)) |
350 | && !strncasecmp(h,CT_HEADER":", | 350 | && !strncasecmp(h,CT_HEADER":", |
351 | sizeof(CT_HEADER)) ) { | 351 | sizeof(CT_HEADER)) ) { |
352 | const char *sc = (const char*)memchr( | 352 | const char *sc = (const char*)memchr( |
353 | hv,';',rb); | 353 | hv,';',rb); |
354 | http_content_type.assign(hv,sc?(sc-hv):rb); | 354 | http_content_type.assign(hv,sc?(sc-hv):rb); |
355 | } | 355 | } |
356 | } | 356 | } |
357 | } | 357 | } |
358 | return curl_t::header(p,s,nm); | 358 | return curl_t::header(p,s,nm); |
359 | } | 359 | } |
360 | 360 | ||
361 | void start_element(const XML_Char *n,const XML_Char **a) { | 361 | void start_element(const XML_Char *n,const XML_Char **a) { |
362 | if(skipping<0) return; | 362 | if(skipping<0) return; |
363 | if(skipping) { | 363 | if(skipping) { |
364 | if(xmode&xmode_html) | 364 | if(xmode&xmode_html) |
365 | html_start_element(n,a); | 365 | html_start_element(n,a); |
366 | ++skipping; return; | 366 | ++skipping; return; |
367 | } | 367 | } |
368 | if(pt_stack.empty()) { | 368 | if(pt_stack.empty()) { |
369 | if(is_qelement(n,NSURI_XRDS "\tXRDS")) | 369 | if(is_qelement(n,NSURI_XRDS "\tXRDS")) |
370 | return; | 370 | return; |
371 | if(is_qelement(n,NSURI_XRD "\tXRD")) { | 371 | if(is_qelement(n,NSURI_XRD "\tXRD")) { |
372 | assert(xrd); | 372 | assert(xrd); |
373 | xrd->clear(); | 373 | xrd->clear(); |
374 | pt_stack.push_back(n); | 374 | pt_stack.push_back(n); |
@@ -471,65 +471,65 @@ namespace opkele { | |||
471 | xrd->expires = util::w3c_to_time(cdata_buf); | 471 | xrd->expires = util::w3c_to_time(cdata_buf); |
472 | }else if((xmode&xmode_html) && is_element(n,"head")) { | 472 | }else if((xmode&xmode_html) && is_element(n,"head")) { |
473 | skipping = -1; | 473 | skipping = -1; |
474 | } | 474 | } |
475 | cdata = 0; | 475 | cdata = 0; |
476 | } | 476 | } |
477 | void character_data(const XML_Char *s,int l) { | 477 | void character_data(const XML_Char *s,int l) { |
478 | if(skipping) return; | 478 | if(skipping) return; |
479 | if(cdata) cdata->append(s,l); | 479 | if(cdata) cdata->append(s,l); |
480 | } | 480 | } |
481 | 481 | ||
482 | void html_start_element(const XML_Char *n,const XML_Char **a) { | 482 | void html_start_element(const XML_Char *n,const XML_Char **a) { |
483 | if(is_element(n,"meta")) { | 483 | if(is_element(n,"meta")) { |
484 | bool heq = false; | 484 | bool heq = false; |
485 | string l; | 485 | string l; |
486 | for(;*a;a+=2) { | 486 | for(;*a;a+=2) { |
487 | if(!( strcasecmp(a[0],"http-equiv") | 487 | if(!( strcasecmp(a[0],"http-equiv") |
488 | || strcasecmp(a[1],XRDS_HEADER) )) | 488 | || strcasecmp(a[1],XRDS_HEADER) )) |
489 | heq = true; | 489 | heq = true; |
490 | else if(!strcasecmp(a[0],"content")) | 490 | else if(!strcasecmp(a[0],"content")) |
491 | l.assign(a[1]); | 491 | l.assign(a[1]); |
492 | } | 492 | } |
493 | if(heq) | 493 | if(heq) |
494 | xrds_location = l; | 494 | xrds_location = l; |
495 | }else if(is_element(n,"link")) { | 495 | }else if(is_element(n,"link")) { |
496 | string rels; | 496 | string rels; |
497 | string href; | 497 | string href; |
498 | for(;*a;a+=2) { | 498 | for(;*a;a+=2) { |
499 | if( !strcasecmp(a[0],"rel") ) { | 499 | if( !strcasecmp(a[0],"rel") ) { |
500 | rels.assign(a[1]); | 500 | rels.assign(a[1]); |
501 | }else if( !strcasecmp(a[0],"href") ) { | 501 | }else if( !strcasecmp(a[0],"href") ) { |
502 | const char *ns = a[1]; | 502 | const char *ns = a[1]; |
503 | for(;*ns && isspace(*ns);++ns); | 503 | for(;*ns && isspace(*ns);++ns) ; |
504 | href.assign(ns); | 504 | href.assign(ns); |
505 | string::size_type lns=href.find_last_not_of(data::_whitespace_chars); | 505 | string::size_type lns=href.find_last_not_of(data::_whitespace_chars); |
506 | href.erase(lns+1); | 506 | href.erase(lns+1); |
507 | } | 507 | } |
508 | } | 508 | } |
509 | for(string::size_type ns=rels.find_first_not_of(data::_whitespace_chars); | 509 | for(string::size_type ns=rels.find_first_not_of(data::_whitespace_chars); |
510 | ns!=string::npos; ns=rels.find_first_not_of(data::_whitespace_chars,ns)) { | 510 | ns!=string::npos; ns=rels.find_first_not_of(data::_whitespace_chars,ns)) { |
511 | string::size_type s = rels.find_first_of(data::_whitespace_chars,ns); | 511 | string::size_type s = rels.find_first_of(data::_whitespace_chars,ns); |
512 | string rel; | 512 | string rel; |
513 | if(s==string::npos) { | 513 | if(s==string::npos) { |
514 | rel.assign(rels,ns,string::npos); | 514 | rel.assign(rels,ns,string::npos); |
515 | ns = string::npos; | 515 | ns = string::npos; |
516 | }else{ | 516 | }else{ |
517 | rel.assign(rels,ns,s-ns); | 517 | rel.assign(rels,ns,s-ns); |
518 | ns = s; | 518 | ns = s; |
519 | } | 519 | } |
520 | if(rel=="openid.server") | 520 | if(rel=="openid.server") |
521 | html_openid1.uris.add(-1,xrd::uri_t(href)); | 521 | html_openid1.uris.add(-1,xrd::uri_t(href)); |
522 | else if(rel=="openid.delegate") | 522 | else if(rel=="openid.delegate") |
523 | html_openid1.local_ids.add(-1,href); | 523 | html_openid1.local_ids.add(-1,href); |
524 | else if(rel=="openid2.provider") | 524 | else if(rel=="openid2.provider") |
525 | html_openid2.uris.add(-1,xrd::uri_t(href)); | 525 | html_openid2.uris.add(-1,xrd::uri_t(href)); |
526 | else if(rel=="openid2.local_id") | 526 | else if(rel=="openid2.local_id") |
527 | html_openid2.local_ids.add(-1,href); | 527 | html_openid2.local_ids.add(-1,href); |
528 | } | 528 | } |
529 | }else if(is_element(n,"body")) { | 529 | }else if(is_element(n,"body")) { |
530 | skipping = -1; | 530 | skipping = -1; |
531 | } | 531 | } |
532 | } | 532 | } |
533 | 533 | ||
534 | void queue_endpoints(endpoint_discovery_iterator& oi, | 534 | void queue_endpoints(endpoint_discovery_iterator& oi, |
535 | const idiscovery_t &id, | 535 | const idiscovery_t &id, |
diff --git a/lib/message.cc b/lib/message.cc index 524946a..c1f8088 100644 --- a/lib/message.cc +++ b/lib/message.cc | |||
@@ -129,65 +129,65 @@ namespace opkele { | |||
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); |
diff --git a/lib/prequeue_rp.cc b/lib/prequeue_rp.cc index e499d08..886efae 100644 --- a/lib/prequeue_rp.cc +++ b/lib/prequeue_rp.cc | |||
@@ -13,67 +13,67 @@ | |||
13 | namespace opkele { | 13 | namespace opkele { |
14 | 14 | ||
15 | class __OP_verifier_good_input : public exception { | 15 | class __OP_verifier_good_input : public exception { |
16 | public: | 16 | public: |
17 | __OP_verifier_good_input(OPKELE_E_PARS) | 17 | __OP_verifier_good_input(OPKELE_E_PARS) |
18 | : exception(OPKELE_E_CONS) { } | 18 | : exception(OPKELE_E_CONS) { } |
19 | }; | 19 | }; |
20 | 20 | ||
21 | class OP_verifier : public iterator<output_iterator_tag,openid_endpoint_t,void> { | 21 | class OP_verifier : public iterator<output_iterator_tag,openid_endpoint_t,void> { |
22 | public: | 22 | public: |
23 | const string& OP; | 23 | const string& OP; |
24 | const string& id; | 24 | const string& id; |
25 | 25 | ||
26 | OP_verifier(const string& o,const string& i) | 26 | OP_verifier(const string& o,const string& i) |
27 | : OP(o), id(i) { } | 27 | : OP(o), id(i) { } |
28 | 28 | ||
29 | OP_verifier& operator*() { return *this; } | 29 | OP_verifier& operator*() { return *this; } |
30 | OP_verifier& operator=(const openid_endpoint_t& oep) { | 30 | OP_verifier& operator=(const openid_endpoint_t& oep) { |
31 | if(oep.uri==OP) { | 31 | if(oep.uri==OP) { |
32 | if(oep.claimed_id==IDURI_SELECT20 | 32 | if(oep.claimed_id==IDURI_SELECT20 |
33 | || oep.local_id==IDURI_SELECT20 ) | 33 | || oep.local_id==IDURI_SELECT20 ) |
34 | throw bad_input(OPKELE_CP_ "claimed_id is an OP-Id"); | 34 | throw bad_input(OPKELE_CP_ "claimed_id is an OP-Id"); |
35 | if(oep.local_id==id) | 35 | if(oep.local_id==id) |
36 | throw __OP_verifier_good_input(OPKELE_CP_ "Found corresponding endpoint"); | 36 | throw __OP_verifier_good_input(OPKELE_CP_ "Found corresponding endpoint"); |
37 | } | 37 | } |
38 | return *this; | 38 | return *this; |
39 | } | 39 | } |
40 | 40 | ||
41 | OP_verifier& operator++() { return *this; } | 41 | OP_verifier& operator++() { return *this; } |
42 | OP_verifier& operator++(int) { return *this; } | 42 | OP_verifier& operator++(int) { return *this; } |
43 | }; | 43 | }; |
44 | 44 | ||
45 | void prequeue_RP::verify_OP(const string& OP,const string& claimed_id,const string& id) const { | 45 | void prequeue_RP::verify_OP(const string& OP,const string& _claimed_id,const string& id) const { |
46 | try { | 46 | try { |
47 | discover(OP_verifier(OP,id),claimed_id); | 47 | discover(OP_verifier(OP,id),_claimed_id); |
48 | throw id_res_unauthorized(OPKELE_CP_ | 48 | throw id_res_unauthorized(OPKELE_CP_ |
49 | "OP is not authorized to make an assertion regarding the identity"); | 49 | "OP is not authorized to make an assertion regarding the identity"); |
50 | }catch(__OP_verifier_good_input& ovgi) { | 50 | }catch(__OP_verifier_good_input& ovgi) { |
51 | } | 51 | } |
52 | } | 52 | } |
53 | 53 | ||
54 | class endpoint_queuer : public iterator<output_iterator_tag,openid_endpoint_t,void> { | 54 | class endpoint_queuer : public iterator<output_iterator_tag,openid_endpoint_t,void> { |
55 | public: | 55 | public: |
56 | prequeue_RP& rp; | 56 | prequeue_RP& rp; |
57 | 57 | ||
58 | endpoint_queuer(prequeue_RP& r) : rp(r) { } | 58 | endpoint_queuer(prequeue_RP& r) : rp(r) { } |
59 | 59 | ||
60 | endpoint_queuer& operator*() { return *this; } | 60 | endpoint_queuer& operator*() { return *this; } |
61 | endpoint_queuer& operator=(const openid_endpoint_t& oep) { | 61 | endpoint_queuer& operator=(const openid_endpoint_t& oep) { |
62 | rp.queue_endpoint(oep); return *this; } | 62 | rp.queue_endpoint(oep); return *this; } |
63 | 63 | ||
64 | endpoint_queuer& operator++() { return *this; } | 64 | endpoint_queuer& operator++() { return *this; } |
65 | endpoint_queuer& operator++(int) { return *this; } | 65 | endpoint_queuer& operator++(int) { return *this; } |
66 | }; | 66 | }; |
67 | 67 | ||
68 | void prequeue_RP::initiate(const string& usi) { | 68 | void prequeue_RP::initiate(const string& usi) { |
69 | begin_queueing(); | 69 | begin_queueing(); |
70 | set_normalized_id( discover(endpoint_queuer(*this),usi) ); | 70 | set_normalized_id( discover(endpoint_queuer(*this),usi) ); |
71 | end_queueing(); | 71 | end_queueing(); |
72 | } | 72 | } |
73 | 73 | ||
74 | void prequeue_RP::set_normalized_id(const string&) { | 74 | void prequeue_RP::set_normalized_id(const string&) { |
75 | } | 75 | } |
76 | 76 | ||
77 | const string prequeue_RP::get_normalized_id() const { | 77 | const string prequeue_RP::get_normalized_id() const { |
78 | throw not_implemented(OPKELE_CP_ "get_normalized_id() is not implemented"); | 78 | throw not_implemented(OPKELE_CP_ "get_normalized_id() is not implemented"); |
79 | } | 79 | } |
diff --git a/lib/secret.cc b/lib/secret.cc index d538890..3f1e39c 100644 --- a/lib/secret.cc +++ b/lib/secret.cc | |||
@@ -1,45 +1,45 @@ | |||
1 | #include <algorithm> | 1 | #include <algorithm> |
2 | #include <functional> | 2 | #include <functional> |
3 | #include <opkele/types.h> | 3 | #include <opkele/types.h> |
4 | #include <opkele/exception.h> | 4 | #include <opkele/exception.h> |
5 | #include <opkele/util.h> | 5 | #include <opkele/util.h> |
6 | 6 | ||
7 | namespace opkele { | 7 | namespace opkele { |
8 | using namespace std; | 8 | using namespace std; |
9 | 9 | ||
10 | template<class __a1,class __a2,class __r> | 10 | template<class __a1,class __a2,class __r> |
11 | struct bitwise_xor : public binary_function<__a1,__a2,__r> { | 11 | struct bitwise_xor : public binary_function<__a1,__a2,__r> { |
12 | __r operator() (const __a1& a1,const __a2& a2) const { | 12 | __r operator() (const __a1& a1,const __a2& a2) const { |
13 | return a1^a2; | 13 | return (__r)(a1^a2); |
14 | } | 14 | } |
15 | }; | 15 | }; |
16 | 16 | ||
17 | void secret_t::enxor_to_base64(const unsigned char *key_d,string& rv) const { | 17 | void secret_t::enxor_to_base64(const unsigned char *key_d,string& rv) const { |
18 | vector<unsigned char> tmp; | 18 | vector<unsigned char> tmp; |
19 | transform( | 19 | transform( |
20 | begin(), end(), | 20 | begin(), end(), |
21 | key_d, | 21 | key_d, |
22 | back_insert_iterator<vector<unsigned char> >(tmp), | 22 | back_insert_iterator<vector<unsigned char> >(tmp), |
23 | bitwise_xor<unsigned char,unsigned char,unsigned char>() ); | 23 | bitwise_xor<unsigned char,unsigned char,unsigned char>() ); |
24 | rv = util::encode_base64(&(tmp.front()),tmp.size()); | 24 | rv = util::encode_base64(&(tmp.front()),tmp.size()); |
25 | } | 25 | } |
26 | 26 | ||
27 | void secret_t::enxor_from_base64(const unsigned char *key_d,const string& b64) { | 27 | void secret_t::enxor_from_base64(const unsigned char *key_d,const string& b64) { |
28 | clear(); | 28 | clear(); |
29 | util::decode_base64(b64,*this); | 29 | util::decode_base64(b64,*this); |
30 | transform( | 30 | transform( |
31 | begin(), end(), | 31 | begin(), end(), |
32 | key_d, | 32 | key_d, |
33 | begin(), | 33 | begin(), |
34 | bitwise_xor<unsigned char,unsigned char,unsigned char>() ); | 34 | bitwise_xor<unsigned char,unsigned char,unsigned char>() ); |
35 | } | 35 | } |
36 | 36 | ||
37 | void secret_t::to_base64(string& rv) const { | 37 | void secret_t::to_base64(string& rv) const { |
38 | rv = util::encode_base64(&(front()),size()); | 38 | rv = util::encode_base64(&(front()),size()); |
39 | } | 39 | } |
40 | 40 | ||
41 | void secret_t::from_base64(const string& b64) { | 41 | void secret_t::from_base64(const string& b64) { |
42 | util::decode_base64(b64,*this); | 42 | util::decode_base64(b64,*this); |
43 | } | 43 | } |
44 | 44 | ||
45 | } | 45 | } |
diff --git a/lib/util.cc b/lib/util.cc index b702291..d979502 100644 --- a/lib/util.cc +++ b/lib/util.cc | |||
@@ -182,65 +182,65 @@ namespace opkele { | |||
182 | (c&0xff)); | 182 | (c&0xff)); |
183 | rv += tmp; | 183 | rv += tmp; |
184 | } | 184 | } |
185 | } | 185 | } |
186 | }; | 186 | }; |
187 | 187 | ||
188 | string url_encode(const string& str) { | 188 | string url_encode(const string& str) { |
189 | string rv; | 189 | string rv; |
190 | for_each(str.begin(),str.end(), | 190 | for_each(str.begin(),str.end(), |
191 | __url_encoder(rv)); | 191 | __url_encoder(rv)); |
192 | return rv; | 192 | return rv; |
193 | } | 193 | } |
194 | 194 | ||
195 | string url_decode(const string& str) { | 195 | string url_decode(const string& str) { |
196 | string rv; | 196 | string rv; |
197 | back_insert_iterator<string> ii(rv); | 197 | back_insert_iterator<string> ii(rv); |
198 | for(string::const_iterator i=str.begin(),ie=str.end(); | 198 | for(string::const_iterator i=str.begin(),ie=str.end(); |
199 | i!=ie;++i) { | 199 | i!=ie;++i) { |
200 | switch(*i) { | 200 | switch(*i) { |
201 | case '+': | 201 | case '+': |
202 | *(ii++) = ' '; break; | 202 | *(ii++) = ' '; break; |
203 | case '%': | 203 | case '%': |
204 | ++i; | 204 | ++i; |
205 | static char tmp[3] = {0,0,0}; | 205 | static char tmp[3] = {0,0,0}; |
206 | if(i==ie) | 206 | if(i==ie) |
207 | throw failed_conversion(OPKELE_CP_ "trailing percent in the url-encoded string"); | 207 | throw failed_conversion(OPKELE_CP_ "trailing percent in the url-encoded string"); |
208 | tmp[0] = *(i++); | 208 | tmp[0] = *(i++); |
209 | if(i==ie) | 209 | if(i==ie) |
210 | throw failed_conversion(OPKELE_CP_ "not enough hexadecimals after the percent sign in url-encoded string"); | 210 | throw failed_conversion(OPKELE_CP_ "not enough hexadecimals after the percent sign in url-encoded string"); |
211 | tmp[1] = *i; | 211 | tmp[1] = *i; |
212 | if(!(isxdigit(tmp[0]) && isxdigit(tmp[1]))) | 212 | if(!(isxdigit(tmp[0]) && isxdigit(tmp[1]))) |
213 | throw failed_conversion(OPKELE_CP_ "non-hex follows percent in url-encoded string"); | 213 | throw failed_conversion(OPKELE_CP_ "non-hex follows percent in url-encoded string"); |
214 | *(ii++) = strtol(tmp,0,16); | 214 | *(ii++) = (char)strtol(tmp,0,16); |
215 | break; | 215 | break; |
216 | default: | 216 | default: |
217 | *(ii++) = *i; break; | 217 | *(ii++) = *i; break; |
218 | } | 218 | } |
219 | } | 219 | } |
220 | return rv; | 220 | return rv; |
221 | } | 221 | } |
222 | 222 | ||
223 | string attr_escape(const string& str) { | 223 | string attr_escape(const string& str) { |
224 | static const char *unsafechars = "<>&\n\"'"; | 224 | static const char *unsafechars = "<>&\n\"'"; |
225 | string rv; | 225 | string rv; |
226 | string::size_type p=0; | 226 | string::size_type p=0; |
227 | while(true) { | 227 | while(true) { |
228 | string::size_type us = str.find_first_of(unsafechars,p); | 228 | string::size_type us = str.find_first_of(unsafechars,p); |
229 | if(us==string::npos) { | 229 | if(us==string::npos) { |
230 | if(p!=str.length()) | 230 | if(p!=str.length()) |
231 | rv.append(str,p,str.length()-p); | 231 | rv.append(str,p,str.length()-p); |
232 | return rv; | 232 | return rv; |
233 | } | 233 | } |
234 | rv.append(str,p,us-p); | 234 | rv.append(str,p,us-p); |
235 | rv += "&#"; | 235 | rv += "&#"; |
236 | rv += long_to_string((long)str[us]); | 236 | rv += long_to_string((long)str[us]); |
237 | rv += ';'; | 237 | rv += ';'; |
238 | p = us+1; | 238 | p = us+1; |
239 | } | 239 | } |
240 | } | 240 | } |
241 | 241 | ||
242 | string long_to_string(long l) { | 242 | string long_to_string(long l) { |
243 | char rv[32]; | 243 | char rv[32]; |
244 | int r=snprintf(rv,sizeof(rv),"%ld",l); | 244 | int r=snprintf(rv,sizeof(rv),"%ld",l); |
245 | if(r<0 || r>=(int)sizeof(rv)) | 245 | if(r<0 || r>=(int)sizeof(rv)) |
246 | throw failed_conversion(OPKELE_CP_ "failed to snprintf()"); | 246 | throw failed_conversion(OPKELE_CP_ "failed to snprintf()"); |
@@ -319,68 +319,68 @@ namespace opkele { | |||
319 | } | 319 | } |
320 | if(ni==string::npos) { | 320 | if(ni==string::npos) { |
321 | rv += '/'; return rv; | 321 | rv += '/'; return rv; |
322 | } | 322 | } |
323 | interesting = ni; | 323 | interesting = ni; |
324 | }else if(ic!='/') { | 324 | }else if(ic!='/') { |
325 | rv += '/'; rv += ic; | 325 | rv += '/'; rv += ic; |
326 | qf = true; | 326 | qf = true; |
327 | ++interesting; | 327 | ++interesting; |
328 | } | 328 | } |
329 | string::size_type n = interesting; | 329 | string::size_type n = interesting; |
330 | char tmp[3] = { 0,0,0 }; | 330 | char tmp[3] = { 0,0,0 }; |
331 | stack<string::size_type> psegs; psegs.push(rv.length()); | 331 | stack<string::size_type> psegs; psegs.push(rv.length()); |
332 | string pseg; | 332 | string pseg; |
333 | for(;n<ul;) { | 333 | for(;n<ul;) { |
334 | string::size_type unsafe = uri.find_first_of(qf?"%":"%/?#",n); | 334 | string::size_type unsafe = uri.find_first_of(qf?"%":"%/?#",n); |
335 | if(unsafe==string::npos) { | 335 | if(unsafe==string::npos) { |
336 | pseg.append(uri,n,ul-n-1); n = ul-1; | 336 | pseg.append(uri,n,ul-n-1); n = ul-1; |
337 | }else{ | 337 | }else{ |
338 | pseg.append(uri,n,unsafe-n); | 338 | pseg.append(uri,n,unsafe-n); |
339 | n = unsafe; | 339 | n = unsafe; |
340 | } | 340 | } |
341 | char c = uri[n++]; | 341 | char c = uri[n++]; |
342 | if(c=='%') { | 342 | if(c=='%') { |
343 | if((n+1)>=ul) | 343 | if((n+1)>=ul) |
344 | throw bad_input(OPKELE_CP_ "Unexpected end of URI encountered while parsing percent-encoded character"); | 344 | throw bad_input(OPKELE_CP_ "Unexpected end of URI encountered while parsing percent-encoded character"); |
345 | tmp[0] = uri[n++]; | 345 | tmp[0] = uri[n++]; |
346 | tmp[1] = uri[n++]; | 346 | tmp[1] = uri[n++]; |
347 | if(!( isxdigit(tmp[0]) && isxdigit(tmp[1]) )) | 347 | if(!( isxdigit(tmp[0]) && isxdigit(tmp[1]) )) |
348 | throw bad_input(OPKELE_CP_ "Invalid percent-encoded character in URI being normalized"); | 348 | throw bad_input(OPKELE_CP_ "Invalid percent-encoded character in URI being normalized"); |
349 | int cc = strtol(tmp,0,16); | 349 | int cc = strtol(tmp,0,16); |
350 | if( isalpha(cc) || isdigit(cc) || strchr("._~-",cc) ) | 350 | if( isalpha(cc) || isdigit(cc) || strchr("._~-",cc) ) |
351 | pseg += cc; | 351 | pseg += (char)cc; |
352 | else{ | 352 | else{ |
353 | pseg += '%'; | 353 | pseg += '%'; |
354 | pseg += toupper(tmp[0]); pseg += toupper(tmp[1]); | 354 | pseg += (char)toupper(tmp[0]); pseg += (char)toupper(tmp[1]); |
355 | } | 355 | } |
356 | }else if(qf) { | 356 | }else if(qf) { |
357 | rv += pseg; rv += c; | 357 | rv += pseg; rv += c; |
358 | pseg.clear(); | 358 | pseg.clear(); |
359 | }else if(n>=ul || strchr("?/#",c)) { | 359 | }else if(n>=ul || strchr("?/#",c)) { |
360 | if(pseg.empty() || pseg==".") { | 360 | if(pseg.empty() || pseg==".") { |
361 | }else if(pseg=="..") { | 361 | }else if(pseg=="..") { |
362 | if(psegs.size()>1) { | 362 | if(psegs.size()>1) { |
363 | rv.resize(psegs.top()); psegs.pop(); | 363 | rv.resize(psegs.top()); psegs.pop(); |
364 | } | 364 | } |
365 | }else{ | 365 | }else{ |
366 | psegs.push(rv.length()); | 366 | psegs.push(rv.length()); |
367 | if(c!='/') { | 367 | if(c!='/') { |
368 | pseg += c; | 368 | pseg += c; |
369 | qf = true; | 369 | qf = true; |
370 | } | 370 | } |
371 | rv += '/'; rv += pseg; | 371 | rv += '/'; rv += pseg; |
372 | } | 372 | } |
373 | if(c=='/' && (n>=ul || strchr("?#",uri[n])) ) { | 373 | if(c=='/' && (n>=ul || strchr("?#",uri[n])) ) { |
374 | rv += '/'; | 374 | rv += '/'; |
375 | if(n<ul) | 375 | if(n<ul) |
376 | qf = true; | 376 | qf = true; |
377 | }else if(strchr("?#",c)) { | 377 | }else if(strchr("?#",c)) { |
378 | if(psegs.size()==1 && psegs.top()==rv.length()) | 378 | if(psegs.size()==1 && psegs.top()==rv.length()) |
379 | rv += '/'; | 379 | rv += '/'; |
380 | if(pseg.empty()) | 380 | if(pseg.empty()) |
381 | rv += c; | 381 | rv += c; |
382 | qf = true; | 382 | qf = true; |
383 | } | 383 | } |
384 | pseg.clear(); | 384 | pseg.clear(); |
385 | }else{ | 385 | }else{ |
386 | pseg += c; | 386 | pseg += c; |