XRIRes.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * Code for using a proxy XRI resolver.
  4. */
  5. require_once 'Auth/Yadis/XRDS.php';
  6. require_once 'Auth/Yadis/XRI.php';
  7. class Auth_Yadis_ProxyResolver {
  8. function Auth_Yadis_ProxyResolver($fetcher, $proxy_url = null)
  9. {
  10. $this->fetcher = $fetcher;
  11. $this->proxy_url = $proxy_url;
  12. if (!$this->proxy_url) {
  13. $this->proxy_url = Auth_Yadis_getDefaultProxy();
  14. }
  15. }
  16. function queryURL($xri, $service_type = null)
  17. {
  18. // trim off the xri:// prefix
  19. $qxri = substr(Auth_Yadis_toURINormal($xri), 6);
  20. $hxri = $this->proxy_url . $qxri;
  21. $args = array(
  22. '_xrd_r' => 'application/xrds+xml'
  23. );
  24. if ($service_type) {
  25. $args['_xrd_t'] = $service_type;
  26. } else {
  27. // Don't perform service endpoint selection.
  28. $args['_xrd_r'] .= ';sep=false';
  29. }
  30. $query = Auth_Yadis_XRIAppendArgs($hxri, $args);
  31. return $query;
  32. }
  33. function query($xri, $service_types, $filters = array())
  34. {
  35. $services = array();
  36. $canonicalID = null;
  37. foreach ($service_types as $service_type) {
  38. $url = $this->queryURL($xri, $service_type);
  39. $response = $this->fetcher->get($url);
  40. if ($response->status != 200 and $response->status != 206) {
  41. continue;
  42. }
  43. $xrds = Auth_Yadis_XRDS::parseXRDS($response->body);
  44. if (!$xrds) {
  45. continue;
  46. }
  47. $canonicalID = Auth_Yadis_getCanonicalID($xri,
  48. $xrds);
  49. if ($canonicalID === false) {
  50. return null;
  51. }
  52. $some_services = $xrds->services($filters);
  53. $services = array_merge($services, $some_services);
  54. // TODO:
  55. // * If we do get hits for multiple service_types, we're
  56. // almost certainly going to have duplicated service
  57. // entries and broken priority ordering.
  58. }
  59. return array($canonicalID, $services);
  60. }
  61. }