12 require_once
'Auth/Yadis/Misc.php';
17 return '&^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?&';
22 return '/^([^@]*@)?([^:]*)(:.*)?/';
27 return '/%([0-9A-Fa-f]{2})/';
30 # gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@"
32 # sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
33 # / "*" / "+" / "," / ";" / "="
35 # unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
38 return "/([^-A-Za-z0-9:\/\?#\[\]@\!\$&'\(\)\*\+,;=\._~\%])/";
43 $_unreserved = array();
44 for ($i = 0; $i < 256; $i++) {
45 $_unreserved[$i] =
false;
48 for ($i = ord(
'A'); $i <= ord(
'Z'); $i++) {
49 $_unreserved[$i] =
true;
52 for ($i = ord(
'0'); $i <= ord(
'9'); $i++) {
53 $_unreserved[$i] =
true;
56 for ($i = ord(
'a'); $i <= ord(
'z'); $i++) {
57 $_unreserved[$i] =
true;
60 $_unreserved[ord(
'-')] =
true;
61 $_unreserved[ord(
'.')] =
true;
62 $_unreserved[ord(
'_')] =
true;
63 $_unreserved[ord(
'~')] =
true;
74 $parts[] = sprintf(
"%s-%s", chr($m), chr(
$n));
77 return sprintf(
'[%s]', implode(
'', $parts));
84 $i = intval($mo[1], 16);
85 if ($_unreserved[$i]) {
88 return strtoupper($mo[0]);
96 return chr(intval($mo[1], 16));
101 $result_segments = array();
110 }
else if (
$path ==
'/.') {
114 if ($result_segments) {
115 array_pop($result_segments);
117 }
else if (
$path ==
'/..') {
119 if ($result_segments) {
120 array_pop($result_segments);
122 }
else if ((
$path ==
'..') ||
127 if (
$path[0] ==
'/') {
130 $i = strpos(
$path,
'/', $i);
134 $result_segments[] = substr(
$path, 0, $i);
139 return implode(
'', $result_segments);
144 $uri_matches = array();
147 if (count($uri_matches) < 9) {
148 for ($i = count($uri_matches); $i <= 9; $i++) {
153 $illegal_matches = array();
155 $uri, $illegal_matches);
156 if ($illegal_matches) {
160 $scheme = $uri_matches[2];
162 $scheme = strtolower($scheme);
165 $scheme = $uri_matches[2];
166 if ($scheme ===
'') {
171 $scheme = strtolower($scheme);
172 if (!in_array($scheme, array(
'http',
'https'))) {
177 $authority = $uri_matches[4];
178 if ($authority ===
'') {
183 $authority_matches = array();
185 $authority, $authority_matches);
186 if (count($authority_matches) === 0) {
191 if (count($authority_matches) < 4) {
192 for ($i = count($authority_matches); $i <= 4; $i++) {
193 $authority_matches[] =
'';
197 list($_whole, $userinfo, $host, $port) = $authority_matches;
199 if ($userinfo === null) {
203 if (strpos($host,
'%') !== -1) {
204 $host = strtolower($host);
205 $host = preg_replace_callback(
207 'Auth_OpenID_pct_encoded_replace', $host);
211 $host = strtolower($host);
215 if (($port ==
':') ||
216 ($scheme ==
'http' && $port ==
':80') ||
217 ($scheme ==
'https' && $port ==
':443')) {
224 $authority = $userinfo . $host . $port;
226 $path = $uri_matches[5];
227 $path = preg_replace_callback(
229 'Auth_OpenID_pct_encoded_replace_unreserved',
$path);
241 $fragment = $uri_matches[8];
242 if ($fragment === null) {
246 return $scheme .
'://' . $authority .
$path .
$query . $fragment;