| [ Index ] |
PHP Cross Reference of Joomla 1.5.26 DE |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * Extension argument processing code 5 * 6 * @package OpenID 7 */ 8 9 // Do not allow direct access 10 defined( '_JEXEC' ) or die( 'Restricted access' ); 11 12 /** 13 * Import tools needed to deal with messages. 14 */ 15 require_once 'Auth/OpenID.php'; 16 require_once 'Auth/OpenID/KVForm.php'; 17 require_once 'Auth/Yadis/XML.php'; 18 require_once 'Auth/OpenID/Consumer.php'; // For Auth_OpenID_FailureResponse 19 20 // This doesn't REALLY belong here, but where is better? 21 define('Auth_OpenID_IDENTIFIER_SELECT', 22 "http://specs.openid.net/auth/2.0/identifier_select"); 23 24 // URI for Simple Registration extension, the only commonly deployed 25 // OpenID 1.x extension, and so a special case 26 define('Auth_OpenID_SREG_URI', 'http://openid.net/sreg/1.0'); 27 28 // The OpenID 1.X namespace URI 29 define('Auth_OpenID_OPENID1_NS', 'http://openid.net/signon/1.0'); 30 define('Auth_OpenID_THE_OTHER_OPENID1_NS', 'http://openid.net/signon/1.1'); 31 32 function Auth_OpenID_isOpenID1($ns) 33 { 34 return ($ns == Auth_OpenID_THE_OTHER_OPENID1_NS) || 35 ($ns == Auth_OpenID_OPENID1_NS); 36 } 37 38 // The OpenID 2.0 namespace URI 39 define('Auth_OpenID_OPENID2_NS', 'http://specs.openid.net/auth/2.0'); 40 41 // The namespace consisting of pairs with keys that are prefixed with 42 // "openid." but not in another namespace. 43 define('Auth_OpenID_NULL_NAMESPACE', 'Null namespace'); 44 45 // The null namespace, when it is an allowed OpenID namespace 46 define('Auth_OpenID_OPENID_NS', 'OpenID namespace'); 47 48 // The top-level namespace, excluding all pairs with keys that start 49 // with "openid." 50 define('Auth_OpenID_BARE_NS', 'Bare namespace'); 51 52 // Sentinel for Message implementation to indicate that getArg should 53 // return null instead of returning a default. 54 define('Auth_OpenID_NO_DEFAULT', 'NO DEFAULT ALLOWED'); 55 56 // Limit, in bytes, of identity provider and return_to URLs, including 57 // response payload. See OpenID 1.1 specification, Appendix D. 58 define('Auth_OpenID_OPENID1_URL_LIMIT', 2047); 59 60 // All OpenID protocol fields. Used to check namespace aliases. 61 global $Auth_OpenID_OPENID_PROTOCOL_FIELDS; 62 $Auth_OpenID_OPENID_PROTOCOL_FIELDS = array( 63 'ns', 'mode', 'error', 'return_to', 'contact', 'reference', 64 'signed', 'assoc_type', 'session_type', 'dh_modulus', 'dh_gen', 65 'dh_consumer_public', 'claimed_id', 'identity', 'realm', 66 'invalidate_handle', 'op_endpoint', 'response_nonce', 'sig', 67 'assoc_handle', 'trust_root', 'openid'); 68 69 // Global namespace / alias registration map. See 70 // Auth_OpenID_registerNamespaceAlias. 71 global $Auth_OpenID_registered_aliases; 72 $Auth_OpenID_registered_aliases = array(); 73 74 /** 75 * Registers a (namespace URI, alias) mapping in a global namespace 76 * alias map. Raises NamespaceAliasRegistrationError if either the 77 * namespace URI or alias has already been registered with a different 78 * value. This function is required if you want to use a namespace 79 * with an OpenID 1 message. 80 */ 81 function Auth_OpenID_registerNamespaceAlias($namespace_uri, $alias) 82 { 83 global $Auth_OpenID_registered_aliases; 84 85 if (Auth_OpenID::arrayGet($Auth_OpenID_registered_aliases, 86 $alias) == $namespace_uri) { 87 return true; 88 } 89 90 if (in_array($namespace_uri, 91 array_values($Auth_OpenID_registered_aliases))) { 92 return false; 93 } 94 95 if (in_array($alias, array_keys($Auth_OpenID_registered_aliases))) { 96 return false; 97 } 98 99 $Auth_OpenID_registered_aliases[$alias] = $namespace_uri; 100 return true; 101 } 102 103 /** 104 * Removes a (namespace_uri, alias) registration from the global 105 * namespace alias map. Returns true if the removal succeeded; false 106 * if not (if the mapping did not exist). 107 */ 108 function Auth_OpenID_removeNamespaceAlias($namespace_uri, $alias) 109 { 110 global $Auth_OpenID_registered_aliases; 111 112 if (Auth_OpenID::arrayGet($Auth_OpenID_registered_aliases, 113 $alias) === $namespace_uri) { 114 unset($Auth_OpenID_registered_aliases[$alias]); 115 return true; 116 } 117 118 return false; 119 } 120 121 /** 122 * An Auth_OpenID_Mapping maintains a mapping from arbitrary keys to 123 * arbitrary values. (This is unlike an ordinary PHP array, whose 124 * keys may be only simple scalars.) 125 * 126 * @package OpenID 127 */ 128 class Auth_OpenID_Mapping { 129 /** 130 * Initialize a mapping. If $classic_array is specified, its keys 131 * and values are used to populate the mapping. 132 */ 133 function Auth_OpenID_Mapping($classic_array = null) 134 { 135 $this->keys = array(); 136 $this->values = array(); 137 138 if (is_array($classic_array)) { 139 foreach ($classic_array as $key => $value) { 140 $this->set($key, $value); 141 } 142 } 143 } 144 145 /** 146 * Returns true if $thing is an Auth_OpenID_Mapping object; false 147 * if not. 148 */ 149 function isA($thing) 150 { 151 return (is_object($thing) && 152 strtolower(get_class($thing)) == 'auth_openid_mapping'); 153 } 154 155 /** 156 * Returns an array of the keys in the mapping. 157 */ 158 function keys() 159 { 160 return $this->keys; 161 } 162 163 /** 164 * Returns an array of values in the mapping. 165 */ 166 function values() 167 { 168 return $this->values; 169 } 170 171 /** 172 * Returns an array of (key, value) pairs in the mapping. 173 */ 174 function items() 175 { 176 $temp = array(); 177 178 for ($i = 0; $i < count($this->keys); $i++) { 179 $temp[] = array($this->keys[$i], 180 $this->values[$i]); 181 } 182 return $temp; 183 } 184 185 /** 186 * Returns the "length" of the mapping, or the number of keys. 187 */ 188 function len() 189 { 190 return count($this->keys); 191 } 192 193 /** 194 * Sets a key-value pair in the mapping. If the key already 195 * exists, its value is replaced with the new value. 196 */ 197 function set($key, $value) 198 { 199 $index = array_search($key, $this->keys); 200 201 if ($index !== false) { 202 $this->values[$index] = $value; 203 } else { 204 $this->keys[] = $key; 205 $this->values[] = $value; 206 } 207 } 208 209 /** 210 * Gets a specified value from the mapping, associated with the 211 * specified key. If the key does not exist in the mapping, 212 * $default is returned instead. 213 */ 214 function get($key, $default = null) 215 { 216 $index = array_search($key, $this->keys); 217 218 if ($index !== false) { 219 return $this->values[$index]; 220 } else { 221 return $default; 222 } 223 } 224 225 /** 226 * @access private 227 */ 228 function _reflow() 229 { 230 // PHP is broken yet again. Sort the arrays to remove the 231 // hole in the numeric indexes that make up the array. 232 $old_keys = $this->keys; 233 $old_values = $this->values; 234 235 $this->keys = array(); 236 $this->values = array(); 237 238 foreach ($old_keys as $k) { 239 $this->keys[] = $k; 240 } 241 242 foreach ($old_values as $v) { 243 $this->values[] = $v; 244 } 245 } 246 247 /** 248 * Deletes a key-value pair from the mapping with the specified 249 * key. 250 */ 251 function del($key) 252 { 253 $index = array_search($key, $this->keys); 254 255 if ($index !== false) { 256 unset($this->keys[$index]); 257 unset($this->values[$index]); 258 $this->_reflow(); 259 return true; 260 } 261 return false; 262 } 263 264 /** 265 * Returns true if the specified value has a key in the mapping; 266 * false if not. 267 */ 268 function contains($value) 269 { 270 return (array_search($value, $this->keys) !== false); 271 } 272 } 273 274 /** 275 * Maintains a bijective map between namespace uris and aliases. 276 * 277 * @package OpenID 278 */ 279 class Auth_OpenID_NamespaceMap { 280 function Auth_OpenID_NamespaceMap() 281 { 282 $this->alias_to_namespace = new Auth_OpenID_Mapping(); 283 $this->namespace_to_alias = new Auth_OpenID_Mapping(); 284 $this->implicit_namespaces = array(); 285 } 286 287 function getAlias($namespace_uri) 288 { 289 return $this->namespace_to_alias->get($namespace_uri); 290 } 291 292 function getNamespaceURI($alias) 293 { 294 return $this->alias_to_namespace->get($alias); 295 } 296 297 function iterNamespaceURIs() 298 { 299 // Return an iterator over the namespace URIs 300 return $this->namespace_to_alias->keys(); 301 } 302 303 function iterAliases() 304 { 305 // Return an iterator over the aliases""" 306 return $this->alias_to_namespace->keys(); 307 } 308 309 function iteritems() 310 { 311 return $this->namespace_to_alias->items(); 312 } 313 314 function isImplicit($namespace_uri) 315 { 316 return in_array($namespace_uri, $this->implicit_namespaces); 317 } 318 319 function addAlias($namespace_uri, $desired_alias, $implicit=false) 320 { 321 // Add an alias from this namespace URI to the desired alias 322 global $Auth_OpenID_OPENID_PROTOCOL_FIELDS; 323 324 // Check that desired_alias is not an openid protocol field as 325 // per the spec. 326 if (in_array($desired_alias, $Auth_OpenID_OPENID_PROTOCOL_FIELDS)) { 327 Auth_OpenID::log("\"%s\" is not an allowed namespace alias", 328 $desired_alias); 329 return null; 330 } 331 332 // Check that desired_alias does not contain a period as per 333 // the spec. 334 if (strpos($desired_alias, '.') !== false) { 335 Auth_OpenID::log('"%s" must not contain a dot', $desired_alias); 336 return null; 337 } 338 339 // Check that there is not a namespace already defined for the 340 // desired alias 341 $current_namespace_uri = 342 $this->alias_to_namespace->get($desired_alias); 343 344 if (($current_namespace_uri !== null) && 345 ($current_namespace_uri != $namespace_uri)) { 346 Auth_OpenID::log('Cannot map "%s" because previous mapping exists', 347 $namespace_uri); 348 return null; 349 } 350 351 // Check that there is not already a (different) alias for 352 // this namespace URI 353 $alias = $this->namespace_to_alias->get($namespace_uri); 354 355 if (($alias !== null) && ($alias != $desired_alias)) { 356 Auth_OpenID::log('Cannot map %s to alias %s. ' . 357 'It is already mapped to alias %s', 358 $namespace_uri, $desired_alias, $alias); 359 return null; 360 } 361 362 assert((Auth_OpenID_NULL_NAMESPACE === $desired_alias) || 363 is_string($desired_alias)); 364 365 $this->alias_to_namespace->set($desired_alias, $namespace_uri); 366 $this->namespace_to_alias->set($namespace_uri, $desired_alias); 367 if ($implicit) { 368 array_push($this->implicit_namespaces, $namespace_uri); 369 } 370 371 return $desired_alias; 372 } 373 374 function add($namespace_uri) 375 { 376 // Add this namespace URI to the mapping, without caring what 377 // alias it ends up with 378 379 // See if this namespace is already mapped to an alias 380 $alias = $this->namespace_to_alias->get($namespace_uri); 381 382 if ($alias !== null) { 383 return $alias; 384 } 385 386 // Fall back to generating a numerical alias 387 $i = 0; 388 while (1) { 389 $alias = 'ext' . strval($i); 390 if ($this->addAlias($namespace_uri, $alias) === null) { 391 $i += 1; 392 } else { 393 return $alias; 394 } 395 } 396 397 // Should NEVER be reached! 398 return null; 399 } 400 401 function contains($namespace_uri) 402 { 403 return $this->isDefined($namespace_uri); 404 } 405 406 function isDefined($namespace_uri) 407 { 408 return $this->namespace_to_alias->contains($namespace_uri); 409 } 410 } 411 412 /** 413 * In the implementation of this object, null represents the global 414 * namespace as well as a namespace with no key. 415 * 416 * @package OpenID 417 */ 418 class Auth_OpenID_Message { 419 420 function Auth_OpenID_Message($openid_namespace = null) 421 { 422 // Create an empty Message 423 $this->allowed_openid_namespaces = array( 424 Auth_OpenID_OPENID1_NS, 425 Auth_OpenID_THE_OTHER_OPENID1_NS, 426 Auth_OpenID_OPENID2_NS); 427 428 $this->args = new Auth_OpenID_Mapping(); 429 $this->namespaces = new Auth_OpenID_NamespaceMap(); 430 if ($openid_namespace === null) { 431 $this->_openid_ns_uri = null; 432 } else { 433 $implicit = Auth_OpenID_isOpenID1($openid_namespace); 434 $this->setOpenIDNamespace($openid_namespace, $implicit); 435 } 436 } 437 438 function isOpenID1() 439 { 440 return Auth_OpenID_isOpenID1($this->getOpenIDNamespace()); 441 } 442 443 function isOpenID2() 444 { 445 return $this->getOpenIDNamespace() == Auth_OpenID_OPENID2_NS; 446 } 447 448 function fromPostArgs($args) 449 { 450 // Construct a Message containing a set of POST arguments 451 $obj = new Auth_OpenID_Message(); 452 453 // Partition into "openid." args and bare args 454 $openid_args = array(); 455 foreach ($args as $key => $value) { 456 457 if (is_array($value)) { 458 return null; 459 } 460 461 $parts = explode('.', $key, 2); 462 463 if (count($parts) == 2) { 464 list($prefix, $rest) = $parts; 465 } else { 466 $prefix = null; 467 } 468 469 if ($prefix != 'openid') { 470 $obj->args->set(array(Auth_OpenID_BARE_NS, $key), $value); 471 } else { 472 $openid_args[$rest] = $value; 473 } 474 } 475 476 if ($obj->_fromOpenIDArgs($openid_args)) { 477 return $obj; 478 } else { 479 return null; 480 } 481 } 482 483 function fromOpenIDArgs($openid_args) 484 { 485 // Takes an array. 486 487 // Construct a Message from a parsed KVForm message 488 $obj = new Auth_OpenID_Message(); 489 if ($obj->_fromOpenIDArgs($openid_args)) { 490 return $obj; 491 } else { 492 return null; 493 } 494 } 495 496 /** 497 * @access private 498 */ 499 function _fromOpenIDArgs($openid_args) 500 { 501 global $Auth_OpenID_registered_aliases; 502 503 // Takes an Auth_OpenID_Mapping instance OR an array. 504 505 if (!Auth_OpenID_Mapping::isA($openid_args)) { 506 $openid_args = new Auth_OpenID_Mapping($openid_args); 507 } 508 509 $ns_args = array(); 510 511 // Resolve namespaces 512 foreach ($openid_args->items() as $pair) { 513 list($rest, $value) = $pair; 514 515 $parts = explode('.', $rest, 2); 516 517 if (count($parts) == 2) { 518 list($ns_alias, $ns_key) = $parts; 519 } else { 520 $ns_alias = Auth_OpenID_NULL_NAMESPACE; 521 $ns_key = $rest; 522 } 523 524 if ($ns_alias == 'ns') { 525 if ($this->namespaces->addAlias($value, $ns_key) === null) { 526 return false; 527 } 528 } else if (($ns_alias == Auth_OpenID_NULL_NAMESPACE) && 529 ($ns_key == 'ns')) { 530 // null namespace 531 if ($this->setOpenIDNamespace($value, false) === false) { 532 return false; 533 } 534 } else { 535 $ns_args[] = array($ns_alias, $ns_key, $value); 536 } 537 } 538 539 if (!$this->getOpenIDNamespace()) { 540 if ($this->setOpenIDNamespace(Auth_OpenID_OPENID1_NS, true) === 541 false) { 542 return false; 543 } 544 } 545 546 // Actually put the pairs into the appropriate namespaces 547 foreach ($ns_args as $triple) { 548 list($ns_alias, $ns_key, $value) = $triple; 549 $ns_uri = $this->namespaces->getNamespaceURI($ns_alias); 550 if ($ns_uri === null) { 551 $ns_uri = $this->_getDefaultNamespace($ns_alias); 552 if ($ns_uri === null) { 553 554 $ns_uri = Auth_OpenID_OPENID_NS; 555 $ns_key = sprintf('%s.%s', $ns_alias, $ns_key); 556 } else { 557 $this->namespaces->addAlias($ns_uri, $ns_alias, true); 558 } 559 } 560 561 $this->setArg($ns_uri, $ns_key, $value); 562 } 563 564 return true; 565 } 566 567 function _getDefaultNamespace($mystery_alias) 568 { 569 global $Auth_OpenID_registered_aliases; 570 if ($this->isOpenID1()) { 571 return @$Auth_OpenID_registered_aliases[$mystery_alias]; 572 } 573 return null; 574 } 575 576 function setOpenIDNamespace($openid_ns_uri, $implicit) 577 { 578 if (!in_array($openid_ns_uri, $this->allowed_openid_namespaces)) { 579 Auth_OpenID::log('Invalid null namespace: "%s"', $openid_ns_uri); 580 return false; 581 } 582 583 $succeeded = $this->namespaces->addAlias($openid_ns_uri, 584 Auth_OpenID_NULL_NAMESPACE, 585 $implicit); 586 if ($succeeded === false) { 587 return false; 588 } 589 590 $this->_openid_ns_uri = $openid_ns_uri; 591 592 return true; 593 } 594 595 function getOpenIDNamespace() 596 { 597 return $this->_openid_ns_uri; 598 } 599 600 function fromKVForm($kvform_string) 601 { 602 // Create a Message from a KVForm string 603 return Auth_OpenID_Message::fromOpenIDArgs( 604 Auth_OpenID_KVForm::toArray($kvform_string)); 605 } 606 607 function copy() 608 { 609 return $this; 610 } 611 612 function toPostArgs() 613 { 614 // Return all arguments with openid. in front of namespaced 615 // arguments. 616 617 $args = array(); 618 619 // Add namespace definitions to the output 620 foreach ($this->namespaces->iteritems() as $pair) { 621 list($ns_uri, $alias) = $pair; 622 if ($this->namespaces->isImplicit($ns_uri)) { 623 continue; 624 } 625 if ($alias == Auth_OpenID_NULL_NAMESPACE) { 626 $ns_key = 'openid.ns'; 627 } else { 628 $ns_key = 'openid.ns.' . $alias; 629 } 630 $args[$ns_key] = $ns_uri; 631 } 632 633 foreach ($this->args->items() as $pair) { 634 list($ns_parts, $value) = $pair; 635 list($ns_uri, $ns_key) = $ns_parts; 636 $key = $this->getKey($ns_uri, $ns_key); 637 $args[$key] = $value; 638 } 639 640 return $args; 641 } 642 643 function toArgs() 644 { 645 // Return all namespaced arguments, failing if any 646 // non-namespaced arguments exist. 647 $post_args = $this->toPostArgs(); 648 $kvargs = array(); 649 foreach ($post_args as $k => $v) { 650 if (strpos($k, 'openid.') !== 0) { 651 // raise ValueError( 652 // 'This message can only be encoded as a POST, because it ' 653 // 'contains arguments that are not prefixed with "openid."') 654 return null; 655 } else { 656 $kvargs[substr($k, 7)] = $v; 657 } 658 } 659 660 return $kvargs; 661 } 662 663 function toFormMarkup($action_url, $form_tag_attrs = null, 664 $submit_text = "Continue") 665 { 666 $form = "<form accept-charset=\"UTF-8\" ". 667 "enctype=\"application/x-www-form-urlencoded\""; 668 669 if (!$form_tag_attrs) { 670 $form_tag_attrs = array(); 671 } 672 673 $form_tag_attrs['action'] = $action_url; 674 $form_tag_attrs['method'] = 'post'; 675 676 unset($form_tag_attrs['enctype']); 677 unset($form_tag_attrs['accept-charset']); 678 679 if ($form_tag_attrs) { 680 foreach ($form_tag_attrs as $name => $attr) { 681 $form .= sprintf(" %s=\"%s\"", $name, $attr); 682 } 683 } 684 685 $form .= ">\n"; 686 687 foreach ($this->toPostArgs() as $name => $value) { 688 $form .= sprintf( 689 "<input type=\"hidden\" name=\"%s\" value=\"%s\" />\n", 690 $name, $value); 691 } 692 693 $form .= sprintf("<input type=\"submit\" value=\"%s\" />\n", 694 $submit_text); 695 696 $form .= "</form>\n"; 697 698 return $form; 699 } 700 701 function toURL($base_url) 702 { 703 // Generate a GET URL with the parameters in this message 704 // attached as query parameters. 705 return Auth_OpenID::appendArgs($base_url, $this->toPostArgs()); 706 } 707 708 function toKVForm() 709 { 710 // Generate a KVForm string that contains the parameters in 711 // this message. This will fail if the message contains 712 // arguments outside of the 'openid.' prefix. 713 return Auth_OpenID_KVForm::fromArray($this->toArgs()); 714 } 715 716 function toURLEncoded() 717 { 718 // Generate an x-www-urlencoded string 719 $args = array(); 720 721 foreach ($this->toPostArgs() as $k => $v) { 722 $args[] = array($k, $v); 723 } 724 725 sort($args); 726 return Auth_OpenID::httpBuildQuery($args); 727 } 728 729 /** 730 * @access private 731 */ 732 function _fixNS($namespace) 733 { 734 // Convert an input value into the internally used values of 735 // this object 736 737 if ($namespace == Auth_OpenID_OPENID_NS) { 738 if ($this->_openid_ns_uri === null) { 739 return new Auth_OpenID_FailureResponse(null, 740 'OpenID namespace not set'); 741 } else { 742 $namespace = $this->_openid_ns_uri; 743 } 744 } 745 746 if (($namespace != Auth_OpenID_BARE_NS) && 747 (!is_string($namespace))) { 748 //TypeError 749 $err_msg = sprintf("Namespace must be Auth_OpenID_BARE_NS, ". 750 "Auth_OpenID_OPENID_NS or a string. got %s", 751 print_r($namespace, true)); 752 return new Auth_OpenID_FailureResponse(null, $err_msg); 753 } 754 755 if (($namespace != Auth_OpenID_BARE_NS) && 756 (strpos($namespace, ':') === false)) { 757 // fmt = 'OpenID 2.0 namespace identifiers SHOULD be URIs. Got %r' 758 // warnings.warn(fmt % (namespace,), DeprecationWarning) 759 760 if ($namespace == 'sreg') { 761 // fmt = 'Using %r instead of "sreg" as namespace' 762 // warnings.warn(fmt % (SREG_URI,), DeprecationWarning,) 763 return Auth_OpenID_SREG_URI; 764 } 765 } 766 767 return $namespace; 768 } 769 770 function hasKey($namespace, $ns_key) 771 { 772 $namespace = $this->_fixNS($namespace); 773 if (Auth_OpenID::isFailure($namespace)) { 774 // XXX log me 775 return false; 776 } else { 777 return $this->args->contains(array($namespace, $ns_key)); 778 } 779 } 780 781 function getKey($namespace, $ns_key) 782 { 783 // Get the key for a particular namespaced argument 784 $namespace = $this->_fixNS($namespace); 785 if (Auth_OpenID::isFailure($namespace)) { 786 return $namespace; 787 } 788 if ($namespace == Auth_OpenID_BARE_NS) { 789 return $ns_key; 790 } 791 792 $ns_alias = $this->namespaces->getAlias($namespace); 793 794 // No alias is defined, so no key can exist 795 if ($ns_alias === null) { 796 return null; 797 } 798 799 if ($ns_alias == Auth_OpenID_NULL_NAMESPACE) { 800 $tail = $ns_key; 801 } else { 802 $tail = sprintf('%s.%s', $ns_alias, $ns_key); 803 } 804 805 return 'openid.' . $tail; 806 } 807 808 function getArg($namespace, $key, $default = null) 809 { 810 // Get a value for a namespaced key. 811 $namespace = $this->_fixNS($namespace); 812 813 if (Auth_OpenID::isFailure($namespace)) { 814 return $namespace; 815 } else { 816 if ((!$this->args->contains(array($namespace, $key))) && 817 ($default == Auth_OpenID_NO_DEFAULT)) { 818 $err_msg = sprintf("Namespace %s missing required field %s", 819 $namespace, $key); 820 return new Auth_OpenID_FailureResponse(null, $err_msg); 821 } else { 822 return $this->args->get(array($namespace, $key), $default); 823 } 824 } 825 } 826 827 function getArgs($namespace) 828 { 829 // Get the arguments that are defined for this namespace URI 830 831 $namespace = $this->_fixNS($namespace); 832 if (Auth_OpenID::isFailure($namespace)) { 833 return $namespace; 834 } else { 835 $stuff = array(); 836 foreach ($this->args->items() as $pair) { 837 list($key, $value) = $pair; 838 list($pair_ns, $ns_key) = $key; 839 if ($pair_ns == $namespace) { 840 $stuff[$ns_key] = $value; 841 } 842 } 843 844 return $stuff; 845 } 846 } 847 848 function updateArgs($namespace, $updates) 849 { 850 // Set multiple key/value pairs in one call 851 852 $namespace = $this->_fixNS($namespace); 853 854 if (Auth_OpenID::isFailure($namespace)) { 855 return $namespace; 856 } else { 857 foreach ($updates as $k => $v) { 858 $this->setArg($namespace, $k, $v); 859 } 860 return true; 861 } 862 } 863 864 function setArg($namespace, $key, $value) 865 { 866 // Set a single argument in this namespace 867 $namespace = $this->_fixNS($namespace); 868 869 if (Auth_OpenID::isFailure($namespace)) { 870 return $namespace; 871 } else { 872 $this->args->set(array($namespace, $key), $value); 873 if ($namespace !== Auth_OpenID_BARE_NS) { 874 $this->namespaces->add($namespace); 875 } 876 return true; 877 } 878 } 879 880 function delArg($namespace, $key) 881 { 882 $namespace = $this->_fixNS($namespace); 883 884 if (Auth_OpenID::isFailure($namespace)) { 885 return $namespace; 886 } else { 887 return $this->args->del(array($namespace, $key)); 888 } 889 } 890 891 function getAliasedArg($aliased_key, $default = null) 892 { 893 $parts = explode('.', $aliased_key, 2); 894 895 if (count($parts) != 2) { 896 $ns = null; 897 } else { 898 list($alias, $key) = $parts; 899 900 if ($alias == 'ns') { 901 // Return the namespace URI for a namespace alias 902 // parameter. 903 return $this->namespaces->getNamespaceURI($key); 904 } else { 905 $ns = $this->namespaces->getNamespaceURI($alias); 906 } 907 } 908 909 if ($ns === null) { 910 $key = $aliased_key; 911 $ns = $this->getOpenIDNamespace(); 912 } 913 914 return $this->getArg($ns, $key, $default); 915 } 916 } 917 918 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Mar 28 15:54:07 2012 | Cross-referenced by PHPXref 0.7.1 |