-rw-r--r-- | lib/basic_rp.cc | 3 | ||||
-rw-r--r-- | lib/discovery.cc | 31 | ||||
-rw-r--r-- | lib/expat.cc | 9 |
3 files changed, 38 insertions, 5 deletions
diff --git a/lib/basic_rp.cc b/lib/basic_rp.cc index 3cad71c..9c7113b 100644 --- a/lib/basic_rp.cc +++ b/lib/basic_rp.cc | |||
@@ -209,25 +209,26 @@ namespace opkele { | |||
209 | p[""] = u.substr(q,eq-q); | 209 | p[""] = u.substr(q,eq-q); |
210 | }else{ | 210 | }else{ |
211 | p[u.substr(q,eq-q)] = u.substr(eq+1,am-eq-1); | 211 | p[u.substr(q,eq-q)] = u.substr(eq+1,am-eq-1); |
212 | } | 212 | } |
213 | q = ++am; | 213 | q = ++am; |
214 | } | 214 | } |
215 | } | 215 | } |
216 | } | 216 | } |
217 | 217 | ||
218 | void basic_RP::id_res(const basic_openid_message& om,extension_t *ext) { | 218 | void basic_RP::id_res(const basic_openid_message& om,extension_t *ext) { |
219 | reset_vars(); | 219 | reset_vars(); |
220 | bool o2 = om.has_field("ns") | 220 | bool o2 = om.has_field("ns") |
221 | && om.get_field("ns")==OIURI_OPENID20; | 221 | && om.get_field("ns")==OIURI_OPENID20 |
222 | && om.has_field("op_endpoint") && !om.get_field("op_endpoint").empty(); | ||
222 | if( (!o2) && om.has_field("user_setup_url")) | 223 | if( (!o2) && om.has_field("user_setup_url")) |
223 | throw id_res_setup(OPKELE_CP_ "assertion failed, setup url provided", | 224 | throw id_res_setup(OPKELE_CP_ "assertion failed, setup url provided", |
224 | om.get_field("user_setup_url")); | 225 | om.get_field("user_setup_url")); |
225 | string m = om.get_field("mode"); | 226 | string m = om.get_field("mode"); |
226 | if(o2 && m=="setup_needed") | 227 | if(o2 && m=="setup_needed") |
227 | throw id_res_setup(OPKELE_CP_ "setup needed, no setup url provided"); | 228 | throw id_res_setup(OPKELE_CP_ "setup needed, no setup url provided"); |
228 | if(m=="cancel") | 229 | if(m=="cancel") |
229 | throw id_res_cancel(OPKELE_CP_ "authentication cancelled"); | 230 | throw id_res_cancel(OPKELE_CP_ "authentication cancelled"); |
230 | bool go_dumb=false; | 231 | bool go_dumb=false; |
231 | try { | 232 | try { |
232 | string OP = o2 | 233 | string OP = o2 |
233 | ?om.get_field("op_endpoint") | 234 | ?om.get_field("op_endpoint") |
diff --git a/lib/discovery.cc b/lib/discovery.cc index bd1f917..b4ed3b6 100644 --- a/lib/discovery.cc +++ b/lib/discovery.cc | |||
@@ -274,24 +274,25 @@ namespace opkele { | |||
274 | throw exception_tidy(OPKELE_CP_ "tidy failed to save buffer"); | 274 | throw exception_tidy(OPKELE_CP_ "tidy failed to save buffer"); |
275 | prepare_to_parse(); | 275 | prepare_to_parse(); |
276 | parse(tide.c_str(),tide.size(),true); | 276 | parse(tide.c_str(),tide.size(),true); |
277 | }catch(exception_tidy& et) { } | 277 | }catch(exception_tidy& et) { } |
278 | } | 278 | } |
279 | save_html.clear(); | 279 | save_html.clear(); |
280 | } | 280 | } |
281 | 281 | ||
282 | void prepare_to_parse() { | 282 | void prepare_to_parse() { |
283 | (*(expat_t*)this) = parser_create_ns(); | 283 | (*(expat_t*)this) = parser_create_ns(); |
284 | set_user_data(); set_element_handler(); | 284 | set_user_data(); set_element_handler(); |
285 | set_character_data_handler(); | 285 | set_character_data_handler(); |
286 | set_unknown_encoding_handler(); | ||
286 | 287 | ||
287 | if(xmode&xmode_html) { | 288 | if(xmode&xmode_html) { |
288 | html_openid1.clear(); html_openid2.clear(); | 289 | html_openid1.clear(); html_openid2.clear(); |
289 | parser_choked = false; | 290 | parser_choked = false; |
290 | } | 291 | } |
291 | 292 | ||
292 | cdata = 0; xrd_service = 0; skipping = 0; | 293 | cdata = 0; xrd_service = 0; skipping = 0; |
293 | pt_stack.clear(); | 294 | pt_stack.clear(); |
294 | status_code = 100; status_string.clear(); | 295 | status_code = 100; status_string.clear(); |
295 | } | 296 | } |
296 | 297 | ||
297 | void html2xrd(endpoint_discovery_iterator& oi,idiscovery_t& id) { | 298 | void html2xrd(endpoint_discovery_iterator& oi,idiscovery_t& id) { |
@@ -444,43 +445,58 @@ namespace opkele { | |||
444 | html_start_element(n,a); | 445 | html_start_element(n,a); |
445 | }else{ | 446 | }else{ |
446 | skipping = 1; | 447 | skipping = 1; |
447 | } | 448 | } |
448 | } | 449 | } |
449 | } | 450 | } |
450 | void end_element(const XML_Char *n) { | 451 | void end_element(const XML_Char *n) { |
451 | if(skipping<0) return; | 452 | if(skipping<0) return; |
452 | if(skipping) { | 453 | if(skipping) { |
453 | --skipping; return; | 454 | --skipping; return; |
454 | } | 455 | } |
455 | if(is_qelement(n,NSURI_XRD "\tType")) { | 456 | if(is_qelement(n,NSURI_XRD "\tType")) { |
456 | assert(xrd); assert(xrd_service); assert(cdata==&cdata_buf); | 457 | if(xrd && xrd_service) { |
458 | assert(cdata==&cdata_buf); | ||
457 | xrd_service->types.insert(cdata_buf); | 459 | xrd_service->types.insert(cdata_buf); |
460 | } | ||
458 | }else if(is_qelement(n,NSURI_XRD "\tService")) { | 461 | }else if(is_qelement(n,NSURI_XRD "\tService")) { |
459 | assert(xrd); assert(xrd_service); | 462 | if(!(xrd && xrd_service)) { |
463 | skipping = -1; | ||
464 | }else{ | ||
460 | assert(!pt_stack.empty()); | 465 | assert(!pt_stack.empty()); |
461 | assert(pt_stack.back()==(NSURI_XRD "\tService")); | 466 | assert(pt_stack.back()==(NSURI_XRD "\tService")); |
462 | pt_stack.pop_back(); | 467 | pt_stack.pop_back(); |
463 | xrd_service = 0; | 468 | xrd_service = 0; |
469 | } | ||
464 | }else if(is_qelement(n,NSURI_XRD "\tStatus")) { | 470 | }else if(is_qelement(n,NSURI_XRD "\tStatus")) { |
465 | assert(xrd); | 471 | if(!xrd) { |
472 | skipping=-1; | ||
473 | }else{ | ||
466 | if(is_qelement(pt_stack.back().c_str(),n)) { | 474 | if(is_qelement(pt_stack.back().c_str(),n)) { |
467 | assert(cdata==&status_string); | 475 | assert(cdata==&status_string); |
468 | pt_stack.pop_back(); | 476 | pt_stack.pop_back(); |
469 | if(status_code!=100) | 477 | if(status_code!=100) |
470 | skipping = -1; | 478 | skipping = -1; |
471 | } | 479 | } |
480 | } | ||
472 | }else if(is_qelement(n,NSURI_XRD "\tExpires")) { | 481 | }else if(is_qelement(n,NSURI_XRD "\tExpires")) { |
473 | assert(xrd); | 482 | if(!xrd) { |
483 | skipping=-1; | ||
484 | }else{ | ||
474 | xrd->expires = util::w3c_to_time(cdata_buf); | 485 | xrd->expires = util::w3c_to_time(cdata_buf); |
486 | } | ||
487 | }else if(is_qelement(n,NSURI_XRD "\tXRD")) { | ||
488 | assert(!pt_stack.empty()); | ||
489 | assert(pt_stack.back()==(NSURI_XRD "\tXRD")); | ||
490 | pt_stack.pop_back(); | ||
475 | }else if((xmode&xmode_html) && is_element(n,"head")) { | 491 | }else if((xmode&xmode_html) && is_element(n,"head")) { |
476 | skipping = -1; | 492 | skipping = -1; |
477 | } | 493 | } |
478 | cdata = 0; | 494 | cdata = 0; |
479 | } | 495 | } |
480 | void character_data(const XML_Char *s,int l) { | 496 | void character_data(const XML_Char *s,int l) { |
481 | if(skipping) return; | 497 | if(skipping) return; |
482 | if(cdata) cdata->append(s,l); | 498 | if(cdata) cdata->append(s,l); |
483 | } | 499 | } |
484 | 500 | ||
485 | void html_start_element(const XML_Char *n,const XML_Char **a) { | 501 | void html_start_element(const XML_Char *n,const XML_Char **a) { |
486 | if(is_element(n,"meta")) { | 502 | if(is_element(n,"meta")) { |
@@ -560,24 +576,31 @@ namespace opkele { | |||
560 | }else{ | 576 | }else{ |
561 | for(xrd::local_ids_t::const_iterator ilid=svc.local_ids.begin(); | 577 | for(xrd::local_ids_t::const_iterator ilid=svc.local_ids.begin(); |
562 | ilid!=svc.local_ids.end(); ++ilid) { | 578 | ilid!=svc.local_ids.end(); ++ilid) { |
563 | ep.local_id = ilid->second; | 579 | ep.local_id = ilid->second; |
564 | *(oi++) = ep; | 580 | *(oi++) = ep; |
565 | } | 581 | } |
566 | } | 582 | } |
567 | } | 583 | } |
568 | } | 584 | } |
569 | } | 585 | } |
570 | } | 586 | } |
571 | 587 | ||
588 | int unknown_encoding(const XML_Char* /* n */,XML_Encoding *i) { | ||
589 | for(unsigned int ii=0;ii < sizeof(i->map)/sizeof(i->map[0]);++ii) | ||
590 | i->map[ii] = ii; | ||
591 | i->convert = 0; i->release = 0; | ||
592 | return XML_STATUS_OK; | ||
593 | } | ||
594 | |||
572 | }; | 595 | }; |
573 | 596 | ||
574 | string idiscover(endpoint_discovery_iterator oi,const string& identity) { | 597 | string idiscover(endpoint_discovery_iterator oi,const string& identity) { |
575 | idigger_t idigger; | 598 | idigger_t idigger; |
576 | return idigger.discover(oi,identity); | 599 | return idigger.discover(oi,identity); |
577 | } | 600 | } |
578 | 601 | ||
579 | void yadiscover(endpoint_discovery_iterator oi,const string& yurl,const char **types,bool redirs) try { | 602 | void yadiscover(endpoint_discovery_iterator oi,const string& yurl,const char **types,bool redirs) try { |
580 | idigger_t idigger; | 603 | idigger_t idigger; |
581 | idigger.yadiscover(oi,yurl,types,redirs); | 604 | idigger.yadiscover(oi,yurl,types,redirs); |
582 | }catch(exception_curl& ec) { | 605 | }catch(exception_curl& ec) { |
583 | if(redirs || ec._error!=CURLE_TOO_MANY_REDIRECTS) | 606 | if(redirs || ec._error!=CURLE_TOO_MANY_REDIRECTS) |
diff --git a/lib/expat.cc b/lib/expat.cc index c4dab7e..fb58a9a 100644 --- a/lib/expat.cc +++ b/lib/expat.cc | |||
@@ -83,15 +83,24 @@ namespace opkele { | |||
83 | static void _start_namespace_decl(void *ud,const XML_Char *p,const XML_Char *u) { | 83 | static void _start_namespace_decl(void *ud,const XML_Char *p,const XML_Char *u) { |
84 | ((expat_t*)ud)->start_namespace_decl(p,u); | 84 | ((expat_t*)ud)->start_namespace_decl(p,u); |
85 | } | 85 | } |
86 | static void _end_namespace_decl(void *ud,const XML_Char *p) { | 86 | static void _end_namespace_decl(void *ud,const XML_Char *p) { |
87 | ((expat_t*)ud)->end_namespace_decl(p); | 87 | ((expat_t*)ud)->end_namespace_decl(p); |
88 | } | 88 | } |
89 | 89 | ||
90 | void expat_t::set_namespace_decl_handler() { | 90 | void expat_t::set_namespace_decl_handler() { |
91 | assert(_x); | 91 | assert(_x); |
92 | XML_SetNamespaceDeclHandler(_x,_start_namespace_decl,_end_namespace_decl); | 92 | XML_SetNamespaceDeclHandler(_x,_start_namespace_decl,_end_namespace_decl); |
93 | } | 93 | } |
94 | 94 | ||
95 | static int _unknown_encoding(void *ehd,const XML_Char *n,XML_Encoding *i) { | ||
96 | return ((expat_t*)ehd)->unknown_encoding(n,i); | ||
97 | } | ||
98 | |||
99 | void expat_t::set_unknown_encoding_handler() { | ||
100 | assert(_x); | ||
101 | XML_SetUnknownEncodingHandler(_x,_unknown_encoding,this); | ||
102 | } | ||
103 | |||
95 | } | 104 | } |
96 | 105 | ||
97 | } | 106 | } |