xrds.inc

Archivo

drupal-6.x/modules/openid/xrds.inc
View source
  1. <?php
  2. // Global variables to track parsing state
  3. $xrds_open_elements = array();
  4. $xrds_services = array();
  5. $xrds_current_service = array();
  6. /**
  7. * Main entry point for parsing XRDS documents
  8. */
  9. function xrds_parse($xml) {
  10. global $xrds_services;
  11. $parser = xml_parser_create_ns();
  12. xml_set_element_handler($parser, '_xrds_element_start', '_xrds_element_end');
  13. xml_set_character_data_handler($parser, '_xrds_cdata');
  14. xml_parse($parser, $xml);
  15. xml_parser_free($parser);
  16. return $xrds_services;
  17. }
  18. /**
  19. * Parser callback functions
  20. */
  21. function _xrds_element_start(&$parser, $name, $attribs) {
  22. global $xrds_open_elements;
  23. $xrds_open_elements[] = _xrds_strip_namespace($name);
  24. }
  25. function _xrds_element_end(&$parser, $name) {
  26. global $xrds_open_elements, $xrds_services, $xrds_current_service;
  27. $name = _xrds_strip_namespace($name);
  28. if ($name == 'SERVICE') {
  29. if (in_array(OPENID_NS_2_0 .'/signon', $xrds_current_service['types']) ||
  30. in_array(OPENID_NS_2_0 .'/server', $xrds_current_service['types'])) {
  31. $xrds_current_service['version'] = 2;
  32. }
  33. elseif (in_array(OPENID_NS_1_1, $xrds_current_service['types']) ||
  34. in_array(OPENID_NS_1_0, $xrds_current_service['types'])) {
  35. $xrds_current_service['version'] = 1;
  36. }
  37. if (!empty($xrds_current_service['version'])) {
  38. $xrds_services[] = $xrds_current_service;
  39. }
  40. $xrds_current_service = array();
  41. }
  42. array_pop($xrds_open_elements);
  43. }
  44. function _xrds_cdata(&$parser, $data) {
  45. global $xrds_open_elements, $xrds_services, $xrds_current_service;
  46. $path = strtoupper(implode('/', $xrds_open_elements));
  47. switch ($path) {
  48. case 'XRDS/XRD/SERVICE/TYPE':
  49. $xrds_current_service['types'][] = $data;
  50. break;
  51. case 'XRDS/XRD/SERVICE/URI':
  52. $xrds_current_service['uri'] = $data;
  53. break;
  54. case 'XRDS/XRD/SERVICE/DELEGATE':
  55. $xrds_current_service['delegate'] = $data;
  56. break;
  57. case 'XRDS/XRD/SERVICE/LOCALID':
  58. $xrds_current_service['localid'] = $data;
  59. break;
  60. }
  61. }
  62. function _xrds_strip_namespace($name) {
  63. // Strip namespacing.
  64. $pos = strrpos($name, ':');
  65. if ($pos !== FALSE) {
  66. $name = substr($name, $pos + 1, strlen($name));
  67. }
  68. return $name;
  69. }

Functions

Nombreorden descendente Descripción
xrds_parse Main entry point for parsing XRDS documents
_xrds_cdata
_xrds_element_end
_xrds_element_start Parser callback functions
_xrds_strip_namespace