ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
XRI.php File Reference

Go to the source code of this file.

Namespaces

 OpenID
 This module contains code for dealing with associations between consumers and servers.
 

Functions

 Auth_Yadis_getDefaultProxy ()
 
 Auth_Yadis_getXRIAuthorities ()
 
 Auth_Yadis_getEscapeRE ()
 
 Auth_Yadis_getXrefRE ()
 
 Auth_Yadis_identifierScheme ($identifier)
 
 Auth_Yadis_toIRINormal ($xri)
 
 _escape_xref ($xref_match)
 
 Auth_Yadis_escapeForIRI ($xri)
 
 Auth_Yadis_toURINormal ($xri)
 
 Auth_Yadis_iriToURI ($iri)
 
 Auth_Yadis_XRIAppendArgs ($url, $args)
 
 Auth_Yadis_providerIsAuthoritative ($providerID, $canonicalID)
 
 Auth_Yadis_rootAuthority ($xri)
 
 Auth_Yadis_XRI ($xri)
 
 Auth_Yadis_getCanonicalID ($iname, $xrds)
 

Function Documentation

◆ _escape_xref()

_escape_xref (   $xref_match)

Definition at line 63 of file XRI.php.

64 {
65  $xref = $xref_match[0];
66  $xref = str_replace('/', '%2F', $xref);
67  $xref = str_replace('?', '%3F', $xref);
68  $xref = str_replace('#', '%23', $xref);
69  return $xref;
70 }

◆ Auth_Yadis_escapeForIRI()

Auth_Yadis_escapeForIRI (   $xri)

Definition at line 72 of file XRI.php.

References Auth_Yadis_getXrefRE().

Referenced by Auth_Yadis_toIRINormal().

73 {
74  $xri = str_replace('%', '%25', $xri);
75  $xri = preg_replace_callback(Auth_Yadis_getXrefRE(),
76  '_escape_xref', $xri);
77  return $xri;
78 }
Auth_Yadis_getXrefRE()
Definition: XRI.php:38
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Auth_Yadis_getCanonicalID()

Auth_Yadis_getCanonicalID (   $iname,
  $xrds 
)

Definition at line 187 of file XRI.php.

References Auth_Yadis_providerIsAuthoritative(), Auth_Yadis_rootAuthority(), and Auth_Yadis_XRI().

Referenced by Auth_Yadis_ProxyResolver\query().

188 {
189  // Returns false or a canonical ID value.
190 
191  // Now nodes are in reverse order.
192  $xrd_list = array_reverse($xrds->allXrdNodes);
193  $parser = $xrds->parser;
194  $node = $xrd_list[0];
195 
196  $canonicalID_nodes = $parser->evalXPath('xrd:CanonicalID', $node);
197 
198  if (!$canonicalID_nodes) {
199  return false;
200  }
201 
202  $canonicalID = $canonicalID_nodes[0];
203  $canonicalID = Auth_Yadis_XRI($parser->content($canonicalID));
204 
205  $childID = $canonicalID;
206 
207  for ($i = 1; $i < count($xrd_list); $i++) {
208  $xrd = $xrd_list[$i];
209 
210  $parent_sought = substr($childID, 0, strrpos($childID, '!'));
211  $parentCID = $parser->evalXPath('xrd:CanonicalID', $xrd);
212  if (!$parentCID) {
213  return false;
214  }
215  $parentCID = Auth_Yadis_XRI($parser->content($parentCID[0]));
216 
217  if (strcasecmp($parent_sought, $parentCID)) {
218  // raise XRDSFraud.
219  return false;
220  }
221 
222  $childID = $parent_sought;
223  }
224 
225  $root = Auth_Yadis_rootAuthority($iname);
226  if (!Auth_Yadis_providerIsAuthoritative($root, $childID)) {
227  // raise XRDSFraud.
228  return false;
229  }
230 
231  return $canonicalID;
232 }
Auth_Yadis_rootAuthority($xri)
Definition: XRI.php:144
Auth_Yadis_XRI($xri)
Definition: XRI.php:179
Auth_Yadis_providerIsAuthoritative($providerID, $canonicalID)
Definition: XRI.php:137
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Auth_Yadis_getDefaultProxy()

Auth_Yadis_getDefaultProxy ( )

Definition at line 16 of file XRI.php.

Referenced by Auth_Yadis_ProxyResolver\Auth_Yadis_ProxyResolver().

17 {
18  return 'http://xri.net/';
19 }
+ Here is the caller graph for this function:

◆ Auth_Yadis_getEscapeRE()

Auth_Yadis_getEscapeRE ( )

Definition at line 26 of file XRI.php.

References $n, Auth_Yadis_getIPrivateChars(), and Auth_Yadis_getUCSChars().

Referenced by Auth_Yadis_iriToURI().

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 }
Auth_Yadis_getIPrivateChars()
Definition: Misc.php:35
$n
Definition: RandomTest.php:80
Auth_Yadis_getUCSChars()
Definition: Misc.php:12
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Auth_Yadis_getXrefRE()

Auth_Yadis_getXrefRE ( )

Definition at line 38 of file XRI.php.

Referenced by Auth_Yadis_escapeForIRI().

39 {
40  return '/\((.*?)\)/';
41 }
+ Here is the caller graph for this function:

◆ Auth_Yadis_getXRIAuthorities()

Auth_Yadis_getXRIAuthorities ( )

Definition at line 21 of file XRI.php.

Referenced by Auth_Yadis_identifierScheme(), and Auth_Yadis_rootAuthority().

22 {
23  return array('!', '=', '@', '+', '$', '(');
24 }
+ Here is the caller graph for this function:

◆ Auth_Yadis_identifierScheme()

Auth_Yadis_identifierScheme (   $identifier)

Definition at line 43 of file XRI.php.

References Auth_Yadis_getXRIAuthorities(), and Auth_Yadis_startswith().

Referenced by Auth_OpenID_discover().

44 {
45  if (Auth_Yadis_startswith($identifier, 'xri://') ||
46  ($identifier &&
47  in_array($identifier[0], Auth_Yadis_getXRIAuthorities()))) {
48  return "XRI";
49  } else {
50  return "URI";
51  }
52 }
Auth_Yadis_getXRIAuthorities()
Definition: XRI.php:21
Auth_Yadis_startswith($s, $stuff)
Definition: Misc.php:54
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Auth_Yadis_iriToURI()

Auth_Yadis_iriToURI (   $iri)

Definition at line 85 of file XRI.php.

References Auth_Yadis_getEscapeRE().

Referenced by Auth_Yadis_toURINormal().

86 {
87  if (1) {
88  return $iri;
89  } else {
90  // According to RFC 3987, section 3.1, "Mapping of IRIs to URIs"
91  return preg_replace_callback(Auth_Yadis_getEscapeRE(),
92  'Auth_Yadis_pct_escape_unicode', $iri);
93  }
94 }
Auth_Yadis_getEscapeRE()
Definition: XRI.php:26
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Auth_Yadis_providerIsAuthoritative()

Auth_Yadis_providerIsAuthoritative (   $providerID,
  $canonicalID 
)

Definition at line 137 of file XRI.php.

Referenced by Auth_Yadis_getCanonicalID().

138 {
139  $lastbang = strrpos($canonicalID, '!');
140  $p = substr($canonicalID, 0, $lastbang);
141  return $p == $providerID;
142 }
+ Here is the caller graph for this function:

◆ Auth_Yadis_rootAuthority()

Auth_Yadis_rootAuthority (   $xri)

Definition at line 144 of file XRI.php.

References Auth_Yadis_getXRIAuthorities(), Auth_Yadis_startswith(), and Auth_Yadis_XRI().

Referenced by Auth_Yadis_getCanonicalID().

145 {
146  // Return the root authority for an XRI.
147 
148  $root = null;
149 
150  if (Auth_Yadis_startswith($xri, 'xri://')) {
151  $xri = substr($xri, 6);
152  }
153 
154  $authority = explode('/', $xri, 2);
155  $authority = $authority[0];
156  if ($authority[0] == '(') {
157  // Cross-reference.
158  // XXX: This is incorrect if someone nests cross-references so
159  // there is another close-paren in there. Hopefully nobody
160  // does that before we have a real xriparse function.
161  // Hopefully nobody does that *ever*.
162  $root = substr($authority, 0, strpos($authority, ')') + 1);
163  } else if (in_array($authority[0], Auth_Yadis_getXRIAuthorities())) {
164  // Other XRI reference.
165  $root = $authority[0];
166  } else {
167  // IRI reference.
168  $_segments = explode("!", $authority);
169  $segments = array();
170  foreach ($_segments as $s) {
171  $segments = array_merge($segments, explode("*", $s));
172  }
173  $root = $segments[0];
174  }
175 
176  return Auth_Yadis_XRI($root);
177 }
Auth_Yadis_getXRIAuthorities()
Definition: XRI.php:21
Auth_Yadis_XRI($xri)
Definition: XRI.php:179
Auth_Yadis_startswith($s, $stuff)
Definition: Misc.php:54
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Auth_Yadis_toIRINormal()

Auth_Yadis_toIRINormal (   $xri)

Definition at line 54 of file XRI.php.

References Auth_Yadis_escapeForIRI(), and Auth_Yadis_startswith().

Referenced by Auth_Yadis_toURINormal().

55 {
56  if (!Auth_Yadis_startswith($xri, 'xri://')) {
57  $xri = 'xri://' . $xri;
58  }
59 
60  return Auth_Yadis_escapeForIRI($xri);
61 }
Auth_Yadis_escapeForIRI($xri)
Definition: XRI.php:72
Auth_Yadis_startswith($s, $stuff)
Definition: Misc.php:54
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Auth_Yadis_toURINormal()

Auth_Yadis_toURINormal (   $xri)

Definition at line 80 of file XRI.php.

References Auth_Yadis_iriToURI(), and Auth_Yadis_toIRINormal().

Referenced by Auth_Yadis_ProxyResolver\queryURL().

81 {
83 }
Auth_Yadis_iriToURI($iri)
Definition: XRI.php:85
Auth_Yadis_toIRINormal($xri)
Definition: XRI.php:54
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Auth_Yadis_XRI()

Auth_Yadis_XRI (   $xri)

Definition at line 179 of file XRI.php.

References Auth_Yadis_startswith().

Referenced by Auth_Yadis_getCanonicalID(), and Auth_Yadis_rootAuthority().

180 {
181  if (!Auth_Yadis_startswith($xri, 'xri://')) {
182  $xri = 'xri://' . $xri;
183  }
184  return $xri;
185 }
Auth_Yadis_startswith($s, $stuff)
Definition: Misc.php:54
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Auth_Yadis_XRIAppendArgs()

Auth_Yadis_XRIAppendArgs (   $url,
  $args 
)

Definition at line 97 of file XRI.php.

References Auth_OpenID\httpBuildQuery().

Referenced by Auth_Yadis_ProxyResolver\queryURL().

98 {
99  // Append some arguments to an HTTP query. Yes, this is just like
100  // OpenID's appendArgs, but with special seasoning for XRI
101  // queries.
102 
103  if (count($args) == 0) {
104  return $url;
105  }
106 
107  // Non-empty array; if it is an array of arrays, use multisort;
108  // otherwise use sort.
109  if (array_key_exists(0, $args) &&
110  is_array($args[0])) {
111  // Do nothing here.
112  } else {
113  $keys = array_keys($args);
114  sort($keys);
115  $new_args = array();
116  foreach ($keys as $key) {
117  $new_args[] = array($key, $args[$key]);
118  }
119  $args = $new_args;
120  }
121 
122  // According to XRI Resolution section "QXRI query parameters":
123  //
124  // "If the original QXRI had a null query component (only a
125  // leading question mark), or a query component consisting of
126  // only question marks, one additional leading question mark MUST
127  // be added when adding any XRI resolution parameters."
128  if (strpos(rtrim($url, '?'), '?') !== false) {
129  $sep = '&';
130  } else {
131  $sep = '?';
132  }
133 
134  return $url . $sep . Auth_OpenID::httpBuildQuery($args);
135 }
static httpBuildQuery($data)
Implements the PHP 5 &#39;http_build_query&#39; functionality.
Definition: OpenID.php:296
+ Here is the call graph for this function:
+ Here is the caller graph for this function: