Support Joomla!

Packages

Package: OpenID

License

Content on this site is copyright © 2005 - 2008 Open Source Matters Inc and can be used in accordance with the Joomla! Electronic Documentation License. Some parts of this website may be subject to other licenses.
Source code for file /openid/Auth/Yadis/XRI.php

Documentation is available at XRI.php

  1. <?php
  2.  
  3. /**
  4.  * Routines for XRI resolution.
  5.  *
  6.  * @package OpenID
  7.  * @author JanRain, Inc. <openid@janrain.com>
  8.  * @copyright 2005-2008 Janrain, Inc.
  9.  * @license http://www.apache.org/licenses/LICENSE-2.0 Apache
  10.  */
  11.  
  12. // Do not allow direct access
  13. defined'_JEXEC' or die'Restricted access' );
  14.  
  15. require_once 'Auth/Yadis/Misc.php';
  16. require_once 'Auth/Yadis/Yadis.php';
  17. require_once 'Auth/OpenID.php';
  18.  
  19. {
  20.     return 'http://xri.net/';
  21. }
  22.  
  23. {
  24.     return array('!''=''@''+''$''(');
  25. }
  26.  
  27. {
  28.     $parts array();
  29.     foreach (array_merge(Auth_Yadis_getUCSChars(),
  30.                          Auth_Yadis_getIPrivateChars()) as $pair{
  31.         list($m$n$pair;
  32.         $parts[sprintf("%s-%s"chr($m)chr($n));
  33.     }
  34.  
  35.     return sprintf('/[%s]/'implode(''$parts));
  36. }
  37.  
  38. {
  39.     return '/\((.*?)\)/';
  40. }
  41.  
  42. function Auth_Yadis_identifierScheme($identifier)
  43. {
  44.     if (Auth_Yadis_startswith($identifier'xri://'||
  45.         ($identifier &&
  46.           in_array($identifier[0]Auth_Yadis_getXRIAuthorities()))) {
  47.         return "XRI";
  48.     else {
  49.         return "URI";
  50.     }
  51. }
  52.  
  53. function Auth_Yadis_toIRINormal($xri)
  54. {
  55.     if (!Auth_Yadis_startswith($xri'xri://')) {
  56.         $xri 'xri://' $xri;
  57.     }
  58.  
  59.     return Auth_Yadis_escapeForIRI($xri);
  60. }
  61.  
  62. function _escape_xref($xref_match)
  63. {
  64.     $xref $xref_match[0];
  65.     $xref str_replace('/''%2F'$xref);
  66.     $xref str_replace('?''%3F'$xref);
  67.     $xref str_replace('#''%23'$xref);
  68.     return $xref;
  69. }
  70.  
  71. function Auth_Yadis_escapeForIRI($xri)
  72. {
  73.     $xri str_replace('%''%25'$xri);
  74.                                  '_escape_xref'$xri);
  75.     return $xri;
  76. }
  77.  
  78. function Auth_Yadis_toURINormal($xri)
  79. {
  80. }
  81.  
  82. function Auth_Yadis_iriToURI($iri)
  83. {
  84.     if (1{
  85.         return $iri;
  86.     else {
  87.         // According to RFC 3987, section 3.1, "Mapping of IRIs to URIs"
  88.                                      'Auth_Yadis_pct_escape_unicode'$iri);
  89.     }
  90. }
  91.  
  92.  
  93. function Auth_Yadis_XRIAppendArgs($url$args)
  94. {
  95.     // Append some arguments to an HTTP query.  Yes, this is just like
  96.     // OpenID's appendArgs, but with special seasoning for XRI
  97.     // queries.
  98.  
  99.     if (count($args== 0{
  100.         return $url;
  101.     }
  102.  
  103.     // Non-empty array; if it is an array of arrays, use multisort;
  104.     // otherwise use sort.
  105.     if (array_key_exists(0$args&&
  106.         is_array($args[0])) {
  107.         // Do nothing here.
  108.     else {
  109.         $keys array_keys($args);
  110.         sort($keys);
  111.         $new_args array();
  112.         foreach ($keys as $key{
  113.             $new_args[array($key$args[$key]);
  114.         }
  115.         $args $new_args;
  116.     }
  117.  
  118.     // According to XRI Resolution section "QXRI query parameters":
  119.     //
  120.     // "If the original QXRI had a null query component (only a
  121.     //  leading question mark), or a query component consisting of
  122.     //  only question marks, one additional leading question mark MUST
  123.     //  be added when adding any XRI resolution parameters."
  124.     if (strpos(rtrim($url'?')'?'!== false{
  125.         $sep '&';
  126.     else {
  127.         $sep '?';
  128.     }
  129.  
  130.     return $url $sep Auth_OpenID::httpBuildQuery($args);
  131. }
  132.  
  133. function Auth_Yadis_providerIsAuthoritative($providerID$canonicalID)
  134. {
  135.     $lastbang strrpos($canonicalID'!');
  136.     $p substr($canonicalID0$lastbang);
  137.     return $p == $providerID;
  138. }
  139.  
  140. function Auth_Yadis_rootAuthority($xri)
  141. {
  142.     // Return the root authority for an XRI.
  143.  
  144.     $root null;
  145.  
  146.     if (Auth_Yadis_startswith($xri'xri://')) {
  147.         $xri substr($xri6);
  148.     }
  149.  
  150.     $authority explode('/'$xri2);
  151.     $authority $authority[0];
  152.     if ($authority[0== '('{
  153.         // Cross-reference.
  154.         // XXX: This is incorrect if someone nests cross-references so
  155.         //   there is another close-paren in there.  Hopefully nobody
  156.         //   does that before we have a real xriparse function.
  157.         //   Hopefully nobody does that *ever*.
  158.         $root substr($authority0strpos($authority')'1);
  159.     else if (in_array($authority[0]Auth_Yadis_getXRIAuthorities())) {
  160.         // Other XRI reference.
  161.         $root $authority[0];
  162.     else {
  163.         // IRI reference.
  164.         $_segments explode("!"$authority);
  165.         $segments array();
  166.         foreach ($_segments as $s{
  167.             $segments array_merge($segmentsexplode("*"$s));
  168.         }
  169.         $root $segments[0];
  170.     }
  171.  
  172.     return Auth_Yadis_XRI($root);
  173. }
  174.  
  175. function Auth_Yadis_XRI($xri)
  176. {
  177.     if (!Auth_Yadis_startswith($xri'xri://')) {
  178.         $xri 'xri://' $xri;
  179.     }
  180.     return $xri;
  181. }
  182.  
  183. function Auth_Yadis_getCanonicalID($iname$xrds)
  184. {
  185.     // Returns false or a canonical ID value.
  186.  
  187.     // Now nodes are in reverse order.
  188.     $xrd_list array_reverse($xrds->allXrdNodes);
  189.     $parser =$xrds->parser;
  190.     $node $xrd_list[0];
  191.  
  192.     $canonicalID_nodes $parser->evalXPath('xrd:CanonicalID'$node);
  193.  
  194.     if (!$canonicalID_nodes{
  195.         return false;
  196.     }
  197.  
  198.     $canonicalID $canonicalID_nodes[0];
  199.     $canonicalID Auth_Yadis_XRI($parser->content($canonicalID));
  200.  
  201.     $childID $canonicalID;
  202.  
  203.     for ($i 1$i count($xrd_list)$i++{
  204.         $xrd $xrd_list[$i];
  205.  
  206.         $parent_sought substr($childID0strrpos($childID'!'));
  207.         $parentCID $parser->evalXPath('xrd:CanonicalID'$xrd);
  208.         if (!$parentCID{
  209.             return false;
  210.         }
  211.         $parentCID Auth_Yadis_XRI($parser->content($parentCID[0]));
  212.  
  213.         if (strcasecmp($parent_sought$parentCID)) {
  214.             // raise XRDSFraud.
  215.             return false;
  216.         }
  217.  
  218.         $childID $parent_sought;
  219.     }
  220.  
  221.     $root Auth_Yadis_rootAuthority($iname);
  222.     if (!Auth_Yadis_providerIsAuthoritative($root$childID)) {
  223.         // raise XRDSFraud.
  224.         return false;
  225.     }
  226.  
  227.     return $canonicalID;
  228. }
  229.  
  230. ?>

Documentation generated on Sat, 14 Nov 2009 11:23:47 +0000 by phpDocumentor 1.3.1