cvs: pear /Net_LDAP/LDAP RootDSE.php Schema.php Search.php Util.php
| From: | Jan Wagner | Date: | Fri, 14 Nov 2003 11:21:27 +0000 |
| Subject: | cvs: pear /Net_LDAP/LDAP RootDSE.php Schema.php Search.php Util.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-14270@lists.php.net to get a copy of this message | ||
jw Fri Nov 14 06:21:27 2003 EDT
Modified files:
/pear/Net_LDAP/LDAP RootDSE.php Schema.php Search.php Util.php
Log:
changes to fullfil PCS
Index: pear/Net_LDAP/LDAP/RootDSE.php diff -u pear/Net_LDAP/LDAP/RootDSE.php:1.3 pear/Net_LDAP/LDAP/RootDSE.php:1.4 --- pear/Net_LDAP/LDAP/RootDSE.php:1.3 Wed Nov 12 05:53:13 2003 +++ pear/Net_LDAP/LDAP/RootDSE.php Fri Nov 14 06:21:27 2003 @@ -1,17 +1,29 @@ -<?PHP - -/** - * Net_LDAP_RootDSE - * - * @package Net_LDAP - * @author Jan Wagner <wagner@netsols.de> - * @version $Id: RootDSE.php,v 1.3 2003/11/12 10:53:13 jw Exp $ - */ +<?php +/* vim: set expandtab tabstop=4 shiftwidth=4: */ +// +----------------------------------------------------------------------+ +// | PHP version 4 | +// +----------------------------------------------------------------------+ +// | Copyright (c) 1997-2003 The PHP Group | +// +----------------------------------------------------------------------+ +// | This source file is subject to version 2.0 of the PHP license, | +// | that is bundled with this package in the file LICENSE, and is | +// | available through the world-wide-web at | +// | http://www.php.net/license/2_02.txt. | +// | If you did not receive a copy of the PHP license and are unable to | +// | obtain it through the world-wide-web, please send a note to | +// | license@php.net so we can mail you a copy immediately. | +// +----------------------------------------------------------------------+ +// | Authors: Jan Wagner <wagner@netsols.de> | +// +----------------------------------------------------------------------+ +// +// $Id: RootDSE.php,v 1.4 2003/11/14 11:21:27 jw Exp $ /** * Getting the rootDSE entry of a LDAP server * * @package Net_LDAP + * @author Jan Wagner <wagner@netsols.de> + * @version $Revision: 1.4 $ */ class Net_LDAP_RootDSE extends PEAR { @@ -26,7 +38,7 @@ * * @param object Net_LDAP_Entry */ - function Net_LDAP_RootDSE( &$entry ) + function Net_LDAP_RootDSE(&$entry) { $this->_entry = $entry; } @@ -37,14 +49,14 @@ * Same usuage as Net_LDAP_Entry::get_value() * * @access public - * @param string $attr Attribute name - * @param array $options Array of options - * @return mixed Ldap_Error object or attribute values + * @param string Attribute name + * @param array Array of options + * @return mixed Net_LDAP_Error object or attribute values * @see Net_LDAP_Entry::get_value() */ - function getValue( $attr = '', $options = '' ) + function getValue($attr = '', $options = '') { - return $this->_entry->get_value( $attr, $options ); + return $this->_entry->get_value($attr, $options); } /** @@ -55,19 +67,19 @@ function get_value() { $args = func_get_args(); - return call_user_func_array( array( &$this, 'getValue' ), $args ); - } + return call_user_func_array(array( &$this, 'getValue' ), $args); + } /** * Determines if the extension is supported * * @access public - * @param array $oids array of oids to check + * @param array Array of oids to check * @return boolean */ - function supportedExtension ( $oids ) + function supportedExtension($oids) { - return $this->_check_attr( $oids, 'supportedExtension' ); + return $this->_checkAttr($oids, 'supportedExtension'); } /** @@ -78,19 +90,19 @@ function supported_extension() { $args = func_get_args(); - return call_user_func_array( array( &$this, 'supportedExtension' ), $args ); + return call_user_func_array(array( &$this, 'supportedExtension'), $args); } /** * Determines if the version is supported * * @access public - * @param array $versions versions to check + * @param array Versions to check * @return boolean */ - function supportedVersion ( $versions ) + function supportedVersion($versions) { - return $this->_check_attr( $versions, 'supportedLDAPVersion' ); + return $this->_checkAttr($versions, 'supportedLDAPVersion'); } /** @@ -101,19 +113,19 @@ function supported_version() { $args = func_get_args(); - return call_user_func_array( array( &$this, 'supportedVersion' ), $args ); + return call_user_func_array(array(&$this, 'supportedVersion'), $args); } /** * Determines if the control is supported * * @access public - * @param array $oids control oids to check + * @param array Control oids to check * @return boolean */ - function supportedControl ( $oids ) + function supportedControl($oids) { - return $this->_check_attr( $oids, 'supportedControl' ); + return $this->_checkAttr($oids, 'supportedControl'); } /** @@ -124,19 +136,19 @@ function supported_control() { $args = func_get_args(); - return call_user_func_array( array( &$this, 'supportedControl' ), $args ); + return call_user_func_array(array(&$this, 'supportedControl' ), $args); } /** * Determines if the sasl mechanism is supported * * @access public - * @param array $mechlist sasl mechanisms to check + * @param array SASL mechanisms to check * @return boolean */ - function supportedSASLMechanism ( $mechlist ) + function supportedSASLMechanism($mechlist) { - return $this->_check_attr( $mechlist, 'supportedSASLMechanisms' ); + return $this->_checkAttr($mechlist, 'supportedSASLMechanisms'); } /** @@ -147,7 +159,7 @@ function supported_sasl_mechanism() { $args = func_get_args(); - return call_user_func_array( array( &$this, 'supportedSASLMechanism' ), $args ); + return call_user_func_array(array(&$this, 'supportedSASLMechanism'), $args); } /** @@ -158,14 +170,15 @@ * @param attr $attr attribute name * @return boolean */ - function _check_attr( $values, $attr ) + function _checkAttr($values, $attr) { - if( !is_array( $values ) ) $values = array( $values ); + if (!is_array($values)) $values = array($values); - foreach( $values as $value ) { - if( !@in_array( $value, $this->get_value( $attr ) ) ) return false; - } - + foreach ($values as $value) { + if (!@in_array($value, $this->get_value($attr))) { + return false; + } + } return true; } } Index: pear/Net_LDAP/LDAP/Schema.php diff -u pear/Net_LDAP/LDAP/Schema.php:1.6 pear/Net_LDAP/LDAP/Schema.php:1.7 --- pear/Net_LDAP/LDAP/Schema.php:1.6 Wed Nov 12 05:53:13 2003 +++ pear/Net_LDAP/LDAP/Schema.php Fri Nov 14 06:21:27 2003 @@ -1,12 +1,22 @@ -<?PHP - -/** - * Net_LDAP_Schema - * - * @package Net_LDAP - * @author Jan Wagner <wagner@netsols.de> - * @version $Id: Schema.php,v 1.6 2003/11/12 10:53:13 jw Exp $ - */ +<?php +/* vim: set expandtab tabstop=4 shiftwidth=4: */ +// +----------------------------------------------------------------------+ +// | PHP version 4 | +// +----------------------------------------------------------------------+ +// | Copyright (c) 1997-2003 The PHP Group | +// +----------------------------------------------------------------------+ +// | This source file is subject to version 2.0 of the PHP license, | +// | that is bundled with this package in the file LICENSE, and is | +// | available through the world-wide-web at | +// | http://www.php.net/license/2_02.txt. | +// | If you did not receive a copy of the PHP license and are unable to | +// | obtain it through the world-wide-web, please send a note to | +// | license@php.net so we can mail you a copy immediately. | +// +----------------------------------------------------------------------+ +// | Authors: Jan Wagner <wagner@netsols.de> | +// +----------------------------------------------------------------------+ +// +// $Id: Schema.php,v 1.7 2003/11/14 11:21:27 jw Exp $ /** * Load an LDAP Schema and provide information @@ -17,6 +27,8 @@ * You will find portions of their implementation in here. * * @package Net_LDAP + * @author Jan Wagner <wagner@netsols.de> + * @version $Revision: 1.7 $ */ class Net_LDAP_Schema extends PEAR { @@ -26,14 +38,14 @@ * @access public * @var array */ - var $types = array( 'attribute' => 'attributeTypes', - 'ditcontentrule' => 'dITContentRules', - 'ditstructurerule' => 'dITStructureRules', - 'matchingrule' => 'matchingRules', - 'matchingruleuse' => 'matchingRuleUse', - 'nameform' => 'nameForms', - 'objectclass' => 'objectClasses', - 'syntax' => 'ldapSyntaxes' ); + var $types = array('attribute' => 'attributeTypes', + 'ditcontentrule' => 'dITContentRules', + 'ditstructurerule' => 'dITStructureRules', + 'matchingrule' => 'matchingRules', + 'matchingruleuse' => 'matchingRuleUse', + 'nameform' => 'nameForms', + 'objectclass' => 'objectClasses', + 'syntax' => 'ldapSyntaxes'); /**#@+ * Array of entries belonging to this type @@ -41,31 +53,32 @@ * @access private * @var array */ - var $_attributeTypes = array(); - var $_matchingRules = array(); - var $_matchingRuleUse = array(); - var $_ldapSyntaxes = array(); - var $_objectClasses = array(); - var $_dITContentRules = array(); + var $_attributeTypes = array(); + var $_matchingRules = array(); + var $_matchingRuleUse = array(); + var $_ldapSyntaxes = array(); + var $_objectClasses = array(); + var $_dITContentRules = array(); var $_dITStructureRules = array(); - var $_nameForms = array(); + var $_nameForms = array(); /**#@-*/ /** * hash of all fetched oids * * @access private + * @var array */ var $_oids = array(); /** * constructor of the class * - * @access public + * @access protected */ function Net_LDAP_Schema() { - $this->PEAR( 'Net_LDAP_Error' ); // default error class + $this->PEAR('Net_LDAP_Error'); // default error class } /** @@ -76,46 +89,48 @@ * matchingruleuses, nameforms, syntaxes * * @access public - * @param string $type + * @param string Type to fetch * @return mixed Array or Net_LDAP_Error */ - function &getAll( $type ) + function &getAll($type) { - $map = array( 'objectclasses' => &$this->_objectClasses, - 'attributes' => &$this->_attributeTypes, - 'ditcontentrules' => &$this->_dITContentRules, - 'ditstructurerules' => &$this->_dITStructureRules, - 'matchingrules' => &$this->_matchingRules, - 'matchingruleuses' => &$this->_matchingRuleUse, - 'nameforms' => &$this->_nameForms, - 'syntaxes' => &$this->_ldapSyntaxes ); + $map = array('objectclasses' => &$this->_objectClasses, + 'attributes' => &$this->_attributeTypes, + 'ditcontentrules' => &$this->_dITContentRules, + 'ditstructurerules' => &$this->_dITStructureRules, + 'matchingrules' => &$this->_matchingRules, + 'matchingruleuses' => &$this->_matchingRuleUse, + 'nameforms' => &$this->_nameForms, + 'syntaxes' => &$this->_ldapSyntaxes ); - $key = strtolower( $type ); - return ( ( key_exists( $key, $map ) ) ? $map[ $key ] : $this->raiseError( "Unknown type $type" ) ); + $key = strtolower($type); + return ((key_exists($key, $map)) ? $map[$key] : $this->raiseError("Unknown type $type")); } /** * Return a specific entry * * @access public - * @param string $type Type of name - * @param string $name Name or OID to fetch + * @param string Type of name + * @param string Name or OID to fetch * @return mixed Entry or Net_LDAP_Error */ - function &get( $type, $name ) + function &get($type, $name) { - $type = strtolower( $type ); - if( false == key_exists( $type, $this->types ) ) return $this->raiseError( "No such type $type" ); + $type = strtolower($type); + if (false == key_exists($type, $this->types)) { + return $this->raiseError("No such type $type"); + } - $name = strtolower( $name ); - $type_var = &$this->{ '_' . $this->types[ $type ] }; + $name = strtolower($name); + $type_var = &$this->{'_' . $this->types[$type]}; - if( key_exists( $name, $type_var ) ) { - return $type_var[ $name ]; - } elseif( key_exists( $name, $this->_oids ) && $this->_oids[ $name ][ 'type' ] == $type ) { - return $this->_oids[ $name ]; + if( key_exists($name, $type_var)) { + return $type_var[$name]; + } elseif(key_exists($name, $this->_oids) && $this->_oids[$name]['type'] == $type) { + return $this->_oids[$name]; } else { - return $this->raiseError( "Could not find $type $name" ); + return $this->raiseError("Could not find $type $name"); } } @@ -124,64 +139,62 @@ * Fetches attributes that MAY be present in the given objectclass * * @access public - * @param string $oc Name or OID of objectclass + * @param string Name or OID of objectclass * @return mixed Array with attributes or Net_LDAP_Error */ - function may( $oc ) + function may($oc) { - return $this->_getAttr( $oc, 'may' ); + return $this->_getAttr($oc, 'may'); } /** * Fetches attributes that MUST be present in the given objectclass * * @access public - * @param string $oc Name or OID of objectclass + * @param string Name or OID of objectclass * @return mixed Array with attributes or Net_LDAP_Error */ - function must( $oc ) + function must($oc) { - return $this->_getAttr( $oc, 'must' ); + return $this->_getAttr($oc, 'must'); } /** * Fetches the given attribute from the given objectclass * * @access private - * @param string $oc Name or OID of objectclass - * @param string attr Name of attribute to fetch + * @param string Name or OID of objectclass + * @param string Name of attribute to fetch * @return mixed The attribute or Net_LDAP_Error */ - function _getAttr( $oc, $attr ) + function _getAttr($oc, $attr) { - $oc = strtolower( $oc ); - if( key_exists( $oc, $this->_objectClasses ) && - key_exists( $attr, $this->_objectClasses[ $oc ] ) ) - { - return $this->_objectClasses[ $oc ][ $attr ]; + $oc = strtolower($oc); + if (key_exists($oc, $this->_objectClasses) && key_exists($attr, $this->_objectClasses[$oc])) { + return $this->_objectClasses[$oc][$attr]; } - elseif ( key_exists( $oc, $this->_oids) && - $this->_oids[ $oc ][ 'type' ] == 'objectclass' && - key_exists( $attr, $this->_oids[ $oc ] ) ) - { - return $this->_oids[ $oc ][ $attr ]; + elseif (key_exists($oc, $this->_oids) && + $this->_oids[$oc]['type'] == 'objectclass' && + key_exists($attr, $this->_oids[$oc])) { + return $this->_oids[$oc][$attr]; } else { - return $this->raiseError( "Could not find $attr attributes for $oc " ); + return $this->raiseError("Could not find $attr attributes for $oc "); } } /** * Returns the name(s) of the immediate superclass(es) * - * @param string $oc + * @param string Name or OID of objectclass * @return mixed Array of names or Net_LDAP_Error */ - function superclass( $oc ) + function superclass($oc) { - $o = $this->get( 'objectclass', $oc ); - if( Net_LDAP::isError( $o ) ) return $o; - - return ( key_exists( 'sup', $o ) ? $o['sup'] : array() ); + $o = $this->get('objectclass', $oc); + if (Net_LDAP::isError($o)) { + return $o; + } + return (key_exists('sup', $o) ? $o['sup'] : array()); } /** @@ -190,36 +203,38 @@ * @access public * @param object Net_LDAP_Entry Subschema entry */ - function parse( &$entry ) + function parse(&$entry) { - foreach ( $this->types as $type => $attr ) + foreach ($this->types as $type => $attr) { // initialize map type to entry - $type_var = '_' . $attr ; - $this->{ $type_var } = array(); + $type_var = '_' . $attr; + $this->{$type_var} = array(); // get values for this type - $values = $entry->get_value( $attr ); + $values = $entry->get_value($attr); - if( is_array( $values ) ) + if (is_array($values)) { - foreach ( $values as $value ) - { - unset( $schema_entry ); // this was a real mess without it + foreach ($values as $value) { + + unset($schema_entry); // this was a real mess without it // get the schema entry - $schema_entry = $this->_parse_entry( $value ); + $schema_entry = $this->_parse_entry($value); // set the type - $schema_entry[ 'type' ] = $type; + $schema_entry['type'] = $type; // save a ref in $_oids - $this->_oids[ $schema_entry[ 'oid' ] ] = &$schema_entry; + $this->_oids[$schema_entry['oid']] = &$schema_entry; // save refs for all names in type map - $names = $schema_entry[ 'aliases' ]; - array_push( $names, $schema_entry[ 'name' ] ); - foreach( $names as $name ) $this->{ $type_var }[ strtolower( $name ) ] = &$schema_entry; + $names = $schema_entry['aliases']; + array_push($names, $schema_entry['name']); + foreach ($names as $name) { + $this->{$type_var}[strtolower($name)] = &$schema_entry; + } } } } @@ -229,72 +244,71 @@ * parses an attribute value into a schema entry * * @access private - * @param string $value Attribute values + * @param string Attribute value * @return mixed Schema entry array or false */ - function &_parse_entry( $value ) + function &_parse_entry($value) { // tokens that have no value associated - $noValue = array( 'single-value', - 'obsolete', - 'collective', - 'no-user-modification', - 'abstract', - 'structural', - 'auxiliary' ); + $noValue = array('single-value', + 'obsolete', + 'collective', + 'no-user-modification', + 'abstract', + 'structural', + 'auxiliary'); // tokens that can have multiple values - $multiValue = array( 'must', 'may', 'sup' ); + $multiValue = array('must', 'may', 'sup'); - $schema_entry = array( 'aliases' => array() ); // initilization + $schema_entry = array('aliases' => array()); // initilization - $tokens = $this->_tokenize( $value ); // get an array of tokens + $tokens = $this->_tokenize($value); // get an array of tokens // remove surrounding brackets - if( $tokens[0] == '(' ) array_shift( $tokens ); - if( $tokens[ count( $tokens ) - 1 ] == ')' ) array_pop( $tokens ); // -1 doesnt work on arrays :-( + if ($tokens[0] == '(') array_shift($tokens); + if ($tokens[count($tokens) - 1] == ')') array_pop($tokens); // -1 doesnt work on arrays :-( - $schema_entry[ 'oid' ] = array_shift( $tokens ); // first token is the oid + $schema_entry['oid'] = array_shift($tokens); // first token is the oid - while( count( $tokens ) > 0 ) // cycle over the tokens until none are left - { - $token = strtolower( array_shift( $tokens ) ); - if(in_array( $token, $noValue ) ) $schema_entry[ $token ] = 1; // single value token - else { + // cycle over the tokens until none are left + while (count($tokens) > 0) { + $token = strtolower(array_shift($tokens)); + if (in_array($token, $noValue)) { + $schema_entry[$token] = 1; // single value token + } else { // this one follows a string or a list if it is multivalued - if( ( $schema_entry[ $token ] = array_shift( $tokens ) ) == '(' ) - { + if (($schema_entry[$token] = array_shift($tokens)) == '(') { // this creates the list of values and cycles through the tokens // until the end of the list is reached ')' - $schema_entry[ $token ] = array(); - while( $tmp = array_shift( $tokens ) ) { - if( $tmp == ')' ) break; - if( $tmp != '$' ) array_push( $schema_entry[ $token ], $tmp ); + $schema_entry[$token] = array(); + while ($tmp = array_shift($tokens)) { + if ($tmp == ')') break; + if ($tmp != '$') array_push($schema_entry[$token], $tmp); } } // create a array if the value should be multivalued but was not - if( in_array( $token, $multiValue ) && !is_array( $schema_entry[ $token ] ) ) { - $schema_entry[ $token ] = array( $schema_entry[ $token ] ); + if (in_array($token, $multiValue ) && !is_array($schema_entry[$token])) { + $schema_entry[$token] = array($schema_entry[$token]); } } - } - + } // get max length from syntax - if( key_exists( 'syntax', $schema_entry ) ) { - if( preg_match( '/{(\d+)}/', $schema_entry[ 'syntax'], $matches ) ) { - $schema_entry[ 'max_length' ] = $matches[1]; + if (key_exists('syntax', $schema_entry)) { + if (preg_match('/{(\d+)}/', $schema_entry['syntax'], $matches)) { + $schema_entry['max_length'] = $matches[1]; } - } + } // force a name - if( empty( $schema_entry[ 'name' ] ) ) $schema_entry[ 'name' ] = $schema_entry[ 'oid' ]; - + if (empty($schema_entry['name'])) { + $schema_entry['name'] = $schema_entry['oid']; + } // make one name the default and put the other ones into aliases - if( is_array( $schema_entry[ 'name' ] ) ) { - $aliases = $schema_entry[ 'name' ]; - $schema_entry[ 'name' ] = array_shift( $aliases ); - $schema_entry[ 'aliases' ] = $aliases; - } - + if (is_array($schema_entry['name'])) { + $aliases = $schema_entry['name']; + $schema_entry['name'] = array_shift($aliases); + $schema_entry['aliases'] = $aliases; + } return $schema_entry; } @@ -302,10 +316,10 @@ * tokenizes the given value into an array of tokens * * @access private - * @param string $value String to parse - * @return array $tokens Array of tokens + * @param string String to parse + * @return array Array of tokens */ - function _tokenize( $value ) + function _tokenize($value) { $tokens = array(); // array of tokens $matches = array(); // matches[0] full pattern match, [1,2,3] subpatterns @@ -319,17 +333,17 @@ * non-empty and so it is a token. Tokens may be round brackets, a string, or a string * enclosed by ' */ - preg_match_all( $pattern, $value, $matches ); + preg_match_all($pattern, $value, $matches); - for( $i = 0; $i < count( $matches[ 0 ] ); $i++ ) { // number of tokens (full pattern match) - for( $j = 1; $j < 4; $j++ ) { // each subpattern - if( null != trim( $matches[ $j ][ $i ]) ) { // pattern match in this subpattern - $tokens[ $i ] = trim( $matches[ $j ][ $i ] ); // this is the token + for ($i = 0; $i < count($matches[0]); $i++) { // number of tokens (full pattern match) + for ($j = 1; $j < 4; $j++) { // each subpattern + if (null != trim($matches[$j][$i])) { // pattern match in this subpattern + $tokens[$i] = trim($matches[$j][$i]); // this is the token } } } return $tokens; - } + } } ?> Index: pear/Net_LDAP/LDAP/Search.php diff -u pear/Net_LDAP/LDAP/Search.php:1.2 pear/Net_LDAP/LDAP/Search.php:1.3 --- pear/Net_LDAP/LDAP/Search.php:1.2 Wed Nov 12 05:53:13 2003 +++ pear/Net_LDAP/LDAP/Search.php Fri Nov 14 06:21:27 2003 @@ -1,16 +1,28 @@ <?php - -/** - * Net_LDAP_Search - * - * @author Tarjei Huse - * @version $Id: Search.php,v 1.2 2003/11/12 10:53:13 jw Exp $ - * @package Net_LDAP - */ +/* vim: set expandtab tabstop=4 shiftwidth=4: */ +// +----------------------------------------------------------------------+ +// | PHP version 4 | +// +----------------------------------------------------------------------+ +// | Copyright (c) 1997-2003 The PHP Group | +// +----------------------------------------------------------------------+ +// | This source file is subject to version 2.0 of the PHP license, | +// | that is bundled with this package in the file LICENSE, and is | +// | available through the world-wide-web at | +// | http://www.php.net/license/2_02.txt. | +// | If you did not receive a copy of the PHP license and are unable to | +// | obtain it through the world-wide-web, please send a note to | +// | license@php.net so we can mail you a copy immediately. | +// +----------------------------------------------------------------------+ +// | Authors: Jan Wagner <wagner@netsols.de> | +// +----------------------------------------------------------------------+ +// +// $Id: Search.php,v 1.3 2003/11/14 11:21:27 jw Exp $ /** * Result set of an LDAP search * + * @author Tarjei Huse + * @version $Revision: 1.3 $ * @package Net_LDAP */ class Net_LDAP_Search extends PEAR @@ -70,7 +82,7 @@ */ function Net_LDAP_Search (&$search, &$link) { - $this->_set_search($search, $link); + $this->_setSearch($search, $link); $this->_errorCode = ldap_errno($link); } @@ -81,16 +93,20 @@ */ function entries() { - if ($this->count() == 0) return array(); - - $this->_elink = ldap_first_entry( $this->_link,$this->_search); - $entry = new Net_Ldap_Entry(&$this->_link,ldap_get_dn($this->_link,$this->_elink),ldap_get_attributes($this->_link,$this->_elink)); + if ($this->count() == 0) { + return array(); + } + + $this->_elink = @ldap_first_entry( $this->_link,$this->_search); + $entry = new Net_LDAP_Entry(&$this->_link, + @ldap_get_dn($this->_link, $this->_elink), + @ldap_get_attributes($this->_link, $this->_elink)); array_push ( $entry); - while ($this->_elink = ldap_next_entry($this->_link,$this->_elink)) { + while ($this->_elink = @ldap_next_entry($this->_link,$this->_elink)) { $entry = new Net_ldap_entry(&$this->_link, - ldap_get_dn($this->_link,$this->_elink), - ldap_get_attributes($this->_link,$this->_elink)); + ldap_get_dn($this->_link, $this->_elink), + ldap_get_attributes($this->_link, $this->_elink)); array_push ($entry); } } @@ -100,17 +116,19 @@ * * @return mixed Net_LDAP_Entry object or false */ - function shift_entry () + function shiftEntry() { - if ($this->count() == 0 ) return false; + if ($this->count() == 0 ) { + return false; + } if (is_null($this->_elink)) { - $this->_elink = ldap_first_entry($this -> _link, $this -> _search); - $entry = new Net_ldap_entry(&$this -> _link, - ldap_get_dn($this->_link, $this -> _elink), - ldap_get_attributes($this -> _link, $this -> _elink)); + $this->_elink = @ldap_first_entry($this->_link, $this->_search); + $entry = new Net_ldap_entry(&$this->_link, + ldap_get_dn($this->_link, $this->_elink), + ldap_get_attributes($this->_link, $this->_elink)); } else { - if (!$this->_elink = ldap_next_entry($this -> _link, $this -> _elink)) { + if (!$this->_elink = ldap_next_entry($this->_link, $this->_elink)) { return false; } $entry = new Net_ldap_entry(&$this->_link, @@ -119,6 +137,17 @@ } return $entry; } + + /** + * alias function of shiftEntry() for perl-ldap interface + * + * @see shiftEntry() + */ + function shift_entry() + { + $args = func_get_args(); + return call_user_func_array(array( &$this, 'shiftEntry' ), $args); + } /** * Retrieve the last entry of the searchset. NOT IMPLEMENTED @@ -158,10 +187,10 @@ * @param resource Search result identifier * @param resource Resource link identifier */ - function _set_search (&$search,&$link) + function _setSearch(&$search,&$link) { $this->_search = $search; - $this->_link = $link; + $this->_link = $link; } /** @@ -169,13 +198,13 @@ * * @return int Number of entries in search. */ - function count () + function count() { /* this catches the situation where OL returned errno 32 = no such object! */ if (!$this->_search) { return 0; } - return ldap_count_entries ($this->_link,$this->_search); + return @ldap_count_entries($this->_link, $this->_search); } /** @@ -183,10 +212,10 @@ * * @return int The ldap error number. */ - function getErrorCode () + function getErrorCode() { return $this->_errorCode; - } + } /** Destructor * @@ -194,7 +223,7 @@ */ function _Net_LDAP_Search() { - ldap_free_result($this->_search); + @ldap_free_result($this->_search); } /** @@ -202,9 +231,8 @@ */ function done() { - $this->_Net_Ldap_Search(); + $this->_Net_LDAP_Search(); } - - } + ?> Index: pear/Net_LDAP/LDAP/Util.php diff -u pear/Net_LDAP/LDAP/Util.php:1.3 pear/Net_LDAP/LDAP/Util.php:1.4 --- pear/Net_LDAP/LDAP/Util.php:1.3 Wed Nov 12 05:53:13 2003 +++ pear/Net_LDAP/LDAP/Util.php Fri Nov 14 06:21:27 2003 @@ -1,17 +1,29 @@ <?php - -/** - * Net_LDAP_Util - * - * @package Net_LDAP - * @author Jan Wagner <wagner@netsols.de> - * @version $Id: Util.php,v 1.3 2003/11/12 10:53:13 jw Exp $ - */ - +/* vim: set expandtab tabstop=4 shiftwidth=4: */ +// +----------------------------------------------------------------------+ +// | PHP version 4 | +// +----------------------------------------------------------------------+ +// | Copyright (c) 1997-2003 The PHP Group | +// +----------------------------------------------------------------------+ +// | This source file is subject to version 2.0 of the PHP license, | +// | that is bundled with this package in the file LICENSE, and is | +// | available through the world-wide-web at | +// | http://www.php.net/license/2_02.txt. | +// | If you did not receive a copy of the PHP license and are unable to | +// | obtain it through the world-wide-web, please send a note to | +// | license@php.net so we can mail you a copy immediately. | +// +----------------------------------------------------------------------+ +// | Authors: Jan Wagner <wagner@netsols.de> | +// +----------------------------------------------------------------------+ +// +// $Id: Util.php,v 1.4 2003/11/14 11:21:27 jw Exp $ + /** * Utility Class for Net_LDAP * * @package Net_LDAP + * @author Jan Wagner <wagner@netsols.de> + * @version $Revision: 1.4 $ */ class Net_LDAP_Util extends PEAR { @@ -37,12 +49,11 @@ * Takes an LDAP object by reference and saves it. Then the schema will be fetched. * * @access public - * @param object $ldap Net_LDAP + * @param object Net_LDAP */ - function Net_LDAP_Util( &$ldap ) + function Net_LDAP_Util(&$ldap) { - if (is_object($ldap) && (get_class($ldap) == 'net_ldap')) - { + if (is_object($ldap) && (get_class($ldap) == 'net_ldap')) { $this->_ldap = $ldap; $this->_schema = $this->_ldap->schema(); if (Net_LDAP::isError($this->_schema)) $this->_schema = null; @@ -57,10 +68,10 @@ * can be used for adding or modifying. * * @access public - * @param array $attributes Array of attributes + * @param array Array of attributes * @return array Array of UTF8 encoded attributes */ - function utf8Encode( $attributes ) + function utf8Encode($attributes) { return $this->_utf8($attributes, 'utf8_encode'); } @@ -69,10 +80,10 @@ * Decodes the given attribute values * * @access public - * @param array attributes Array of attributes - * @return array array Array with decoded attribute values + * @param array Array of attributes + * @return array Array with decoded attribute values */ - function utf8Decode( $attributes ) + function utf8Decode($attributes) { return $this->_utf8($attributes, 'utf8_decode'); } @@ -81,25 +92,26 @@ * Encodes or decodes attribute values if needed * * @access private - * @param array $attributes Array of attributes - * @param array $function Function to apply to attribute values + * @param array Array of attributes + * @param array Function to apply to attribute values * @return array Array of attributes with function applied to values */ - function _utf8( $attributes, $function ) + function _utf8($attributes, $function) { - if (!$this->_ldap || !$this->_schema || !function_exists($function)) return $attributes; - - if (is_array($attributes) && count($attributes) > 0) - { - foreach( $attributes as $k => $v ) - { + if (!$this->_ldap || !$this->_schema || !function_exists($function)) { + return $attributes; + } + if (is_array($attributes) && count($attributes) > 0) { + foreach( $attributes as $k => $v ) { $attr = $this->_schema->get('attribute', $k); - if (Net_LDAP::isError($attr)) continue; - - if (false !== strpos($attr['syntax'], '1.3.6.1.4.1.1466.115.121.1.15')) - { + if (Net_LDAP::isError($attr)) { + continue; + } + if (false !== strpos($attr['syntax'], '1.3.6.1.4.1.1466.115.121.1.15')) { if (is_array($v)) { - foreach( $v as $ak => $av ) $v[$ak] = call_user_func($function, $av ); + foreach ($v as $ak => $av ) { + $v[$ak] = call_user_func($function, $av ); + } } else { $v = call_user_func($function, $v); } @@ -108,8 +120,7 @@ } } return $attributes; - } - + } } ?>
Index: pear/Net_LDAP/LDAP/RootDSE.php diff -u pear/Net_LDAP/LDAP/RootDSE.php:1.3 pear/Net_LDAP/LDAP/RootDSE.php:1.4 --- pear/Net_LDAP/LDAP/RootDSE.php:1.3 Wed Nov 12 05:53:13 2003 +++ pear/Net_LDAP/LDAP/RootDSE.php Fri Nov 14 06:21:27 2003 @@ -1,17 +1,29 @@ -<?PHP - -/** - * Net_LDAP_RootDSE - * - * @package Net_LDAP - * @author Jan Wagner <wagner@netsols.de> - * @version $Id: RootDSE.php,v 1.3 2003/11/12 10:53:13 jw Exp $ - */ +<?php +/* vim: set expandtab tabstop=4 shiftwidth=4: */ +// +----------------------------------------------------------------------+ +// | PHP version 4 | +// +----------------------------------------------------------------------+ +// | Copyright (c) 1997-2003 The PHP Group | +// +----------------------------------------------------------------------+ +// | This source file is subject to version 2.0 of the PHP license, | +// | that is bundled with this package in the file LICENSE, and is | +// | available through the world-wide-web at | +// | http://www.php.net/license/2_02.txt. | +// | If you did not receive a copy of the PHP license and are unable to | +// | obtain it through the world-wide-web, please send a note to | +// | license@php.net so we can mail you a copy immediately. | +// +----------------------------------------------------------------------+ +// | Authors: Jan Wagner <wagner@netsols.de> | +// +----------------------------------------------------------------------+ +// +// $Id: RootDSE.php,v 1.4 2003/11/14 11:21:27 jw Exp $ /** * Getting the rootDSE entry of a LDAP server * * @package Net_LDAP + * @author Jan Wagner <wagner@netsols.de> + * @version $Revision: 1.4 $ */ class Net_LDAP_RootDSE extends PEAR { @@ -26,7 +38,7 @@ * * @param object Net_LDAP_Entry */ - function Net_LDAP_RootDSE( &$entry ) + function Net_LDAP_RootDSE(&$entry) { $this->_entry = $entry; } @@ -37,14 +49,14 @@ * Same usuage as Net_LDAP_Entry::get_value() * * @access public - * @param string $attr Attribute name - * @param array $options Array of options - * @return mixed Ldap_Error object or attribute values + * @param string Attribute name + * @param array Array of options + * @return mixed Net_LDAP_Error object or attribute values * @see Net_LDAP_Entry::get_value() */ - function getValue( $attr = '', $options = '' ) + function getValue($attr = '', $options = '') { - return $this->_entry->get_value( $attr, $options ); + return $this->_entry->get_value($attr, $options); } /** @@ -55,19 +67,19 @@ function get_value() { $args = func_get_args(); - return call_user_func_array( array( &$this, 'getValue' ), $args ); - } + return call_user_func_array(array( &$this, 'getValue' ), $args); + } /** * Determines if the extension is supported * * @access public - * @param array $oids array of oids to check + * @param array Array of oids to check * @return boolean */ - function supportedExtension ( $oids ) + function supportedExtension($oids) { - return $this->_check_attr( $oids, 'supportedExtension' ); + return $this->_checkAttr($oids, 'supportedExtension'); } /** @@ -78,19 +90,19 @@ function supported_extension() { $args = func_get_args(); - return call_user_func_array( array( &$this, 'supportedExtension' ), $args ); + return call_user_func_array(array( &$this, 'supportedExtension'), $args); } /** * Determines if the version is supported * * @access public - * @param array $versions versions to check + * @param array Versions to check * @return boolean */ - function supportedVersion ( $versions ) + function supportedVersion($versions) { - return $this->_check_attr( $versions, 'supportedLDAPVersion' ); + return $this->_checkAttr($versions, 'supportedLDAPVersion'); } /** @@ -101,19 +113,19 @@ function supported_version() { $args = func_get_args(); - return call_user_func_array( array( &$this, 'supportedVersion' ), $args ); + return call_user_func_array(array(&$this, 'supportedVersion'), $args); } /** * Determines if the control is supported * * @access public - * @param array $oids control oids to check + * @param array Control oids to check * @return boolean */ - function supportedControl ( $oids ) + function supportedControl($oids) { - return $this->_check_attr( $oids, 'supportedControl' ); + return $this->_checkAttr($oids, 'supportedControl'); } /** @@ -124,19 +136,19 @@ function supported_control() { $args = func_get_args(); - return call_user_func_array( array( &$this, 'supportedControl' ), $args ); + return call_user_func_array(array(&$this, 'supportedControl' ), $args); } /** * Determines if the sasl mechanism is supported * * @access public - * @param array $mechlist sasl mechanisms to check + * @param array SASL mechanisms to check * @return boolean */ - function supportedSASLMechanism ( $mechlist ) + function supportedSASLMechanism($mechlist) { - return $this->_check_attr( $mechlist, 'supportedSASLMechanisms' ); + return $this->_checkAttr($mechlist, 'supportedSASLMechanisms'); } /** @@ -147,7 +159,7 @@ function supported_sasl_mechanism() { $args = func_get_args(); - return call_user_func_array( array( &$this, 'supportedSASLMechanism' ), $args ); + return call_user_func_array(array(&$this, 'supportedSASLMechanism'), $args); } /** @@ -158,14 +170,15 @@ * @param attr $attr attribute name * @return boolean */ - function _check_attr( $values, $attr ) + function _checkAttr($values, $attr) { - if( !is_array( $values ) ) $values = array( $values ); + if (!is_array($values)) $values = array($values); - foreach( $values as $value ) { - if( !@in_array( $value, $this->get_value( $attr ) ) ) return false; - } - + foreach ($values as $value) { + if (!@in_array($value, $this->get_value($attr))) { + return false; + } + } return true; } } Index: pear/Net_LDAP/LDAP/Schema.php diff -u pear/Net_LDAP/LDAP/Schema.php:1.6 pear/Net_LDAP/LDAP/Schema.php:1.7 --- pear/Net_LDAP/LDAP/Schema.php:1.6 Wed Nov 12 05:53:13 2003 +++ pear/Net_LDAP/LDAP/Schema.php Fri Nov 14 06:21:27 2003 @@ -1,12 +1,22 @@ -<?PHP - -/** - * Net_LDAP_Schema - * - * @package Net_LDAP - * @author Jan Wagner <wagner@netsols.de> - * @version $Id: Schema.php,v 1.6 2003/11/12 10:53:13 jw Exp $ - */ +<?php +/* vim: set expandtab tabstop=4 shiftwidth=4: */ +// +----------------------------------------------------------------------+ +// | PHP version 4 | +// +----------------------------------------------------------------------+ +// | Copyright (c) 1997-2003 The PHP Group | +// +----------------------------------------------------------------------+ +// | This source file is subject to version 2.0 of the PHP license, | +// | that is bundled with this package in the file LICENSE, and is | +// | available through the world-wide-web at | +// | http://www.php.net/license/2_02.txt. | +// | If you did not receive a copy of the PHP license and are unable to | +// | obtain it through the world-wide-web, please send a note to | +// | license@php.net so we can mail you a copy immediately. | +// +----------------------------------------------------------------------+ +// | Authors: Jan Wagner <wagner@netsols.de> | +// +----------------------------------------------------------------------+ +// +// $Id: Schema.php,v 1.7 2003/11/14 11:21:27 jw Exp $ /** * Load an LDAP Schema and provide information @@ -17,6 +27,8 @@ * You will find portions of their implementation in here. * * @package Net_LDAP + * @author Jan Wagner <wagner@netsols.de> + * @version $Revision: 1.7 $ */ class Net_LDAP_Schema extends PEAR { @@ -26,14 +38,14 @@ * @access public * @var array */ - var $types = array( 'attribute' => 'attributeTypes', - 'ditcontentrule' => 'dITContentRules', - 'ditstructurerule' => 'dITStructureRules', - 'matchingrule' => 'matchingRules', - 'matchingruleuse' => 'matchingRuleUse', - 'nameform' => 'nameForms', - 'objectclass' => 'objectClasses', - 'syntax' => 'ldapSyntaxes' ); + var $types = array('attribute' => 'attributeTypes', + 'ditcontentrule' => 'dITContentRules', + 'ditstructurerule' => 'dITStructureRules', + 'matchingrule' => 'matchingRules', + 'matchingruleuse' => 'matchingRuleUse', + 'nameform' => 'nameForms', + 'objectclass' => 'objectClasses', + 'syntax' => 'ldapSyntaxes'); /**#@+ * Array of entries belonging to this type @@ -41,31 +53,32 @@ * @access private * @var array */ - var $_attributeTypes = array(); - var $_matchingRules = array(); - var $_matchingRuleUse = array(); - var $_ldapSyntaxes = array(); - var $_objectClasses = array(); - var $_dITContentRules = array(); + var $_attributeTypes = array(); + var $_matchingRules = array(); + var $_matchingRuleUse = array(); + var $_ldapSyntaxes = array(); + var $_objectClasses = array(); + var $_dITContentRules = array(); var $_dITStructureRules = array(); - var $_nameForms = array(); + var $_nameForms = array(); /**#@-*/ /** * hash of all fetched oids * * @access private + * @var array */ var $_oids = array(); /** * constructor of the class * - * @access public + * @access protected */ function Net_LDAP_Schema() { - $this->PEAR( 'Net_LDAP_Error' ); // default error class + $this->PEAR('Net_LDAP_Error'); // default error class } /** @@ -76,46 +89,48 @@ * matchingruleuses, nameforms, syntaxes * * @access public - * @param string $type + * @param string Type to fetch * @return mixed Array or Net_LDAP_Error */ - function &getAll( $type ) + function &getAll($type) { - $map = array( 'objectclasses' => &$this->_objectClasses, - 'attributes' => &$this->_attributeTypes, - 'ditcontentrules' => &$this->_dITContentRules, - 'ditstructurerules' => &$this->_dITStructureRules, - 'matchingrules' => &$this->_matchingRules, - 'matchingruleuses' => &$this->_matchingRuleUse, - 'nameforms' => &$this->_nameForms, - 'syntaxes' => &$this->_ldapSyntaxes ); + $map = array('objectclasses' => &$this->_objectClasses, + 'attributes' => &$this->_attributeTypes, + 'ditcontentrules' => &$this->_dITContentRules, + 'ditstructurerules' => &$this->_dITStructureRules, + 'matchingrules' => &$this->_matchingRules, + 'matchingruleuses' => &$this->_matchingRuleUse, + 'nameforms' => &$this->_nameForms, + 'syntaxes' => &$this->_ldapSyntaxes ); - $key = strtolower( $type ); - return ( ( key_exists( $key, $map ) ) ? $map[ $key ] : $this->raiseError( "Unknown type $type" ) ); + $key = strtolower($type); + return ((key_exists($key, $map)) ? $map[$key] : $this->raiseError("Unknown type $type")); } /** * Return a specific entry * * @access public - * @param string $type Type of name - * @param string $name Name or OID to fetch + * @param string Type of name + * @param string Name or OID to fetch * @return mixed Entry or Net_LDAP_Error */ - function &get( $type, $name ) + function &get($type, $name) { - $type = strtolower( $type ); - if( false == key_exists( $type, $this->types ) ) return $this->raiseError( "No such type $type" ); + $type = strtolower($type); + if (false == key_exists($type, $this->types)) { + return $this->raiseError("No such type $type"); + } - $name = strtolower( $name ); - $type_var = &$this->{ '_' . $this->types[ $type ] }; + $name = strtolower($name); + $type_var = &$this->{'_' . $this->types[$type]}; - if( key_exists( $name, $type_var ) ) { - return $type_var[ $name ]; - } elseif( key_exists( $name, $this->_oids ) && $this->_oids[ $name ][ 'type' ] == $type ) { - return $this->_oids[ $name ]; + if( key_exists($name, $type_var)) { + return $type_var[$name]; + } elseif(key_exists($name, $this->_oids) && $this->_oids[$name]['type'] == $type) { + return $this->_oids[$name]; } else { - return $this->raiseError( "Could not find $type $name" ); + return $this->raiseError("Could not find $type $name"); } } @@ -124,64 +139,62 @@ * Fetches attributes that MAY be present in the given objectclass * * @access public - * @param string $oc Name or OID of objectclass + * @param string Name or OID of objectclass * @return mixed Array with attributes or Net_LDAP_Error */ - function may( $oc ) + function may($oc) { - return $this->_getAttr( $oc, 'may' ); + return $this->_getAttr($oc, 'may'); } /** * Fetches attributes that MUST be present in the given objectclass * * @access public - * @param string $oc Name or OID of objectclass + * @param string Name or OID of objectclass * @return mixed Array with attributes or Net_LDAP_Error */ - function must( $oc ) + function must($oc) { - return $this->_getAttr( $oc, 'must' ); + return $this->_getAttr($oc, 'must'); } /** * Fetches the given attribute from the given objectclass * * @access private - * @param string $oc Name or OID of objectclass - * @param string attr Name of attribute to fetch + * @param string Name or OID of objectclass + * @param string Name of attribute to fetch * @return mixed The attribute or Net_LDAP_Error */ - function _getAttr( $oc, $attr ) + function _getAttr($oc, $attr) { - $oc = strtolower( $oc ); - if( key_exists( $oc, $this->_objectClasses ) && - key_exists( $attr, $this->_objectClasses[ $oc ] ) ) - { - return $this->_objectClasses[ $oc ][ $attr ]; + $oc = strtolower($oc); + if (key_exists($oc, $this->_objectClasses) && key_exists($attr, $this->_objectClasses[$oc])) { + return $this->_objectClasses[$oc][$attr]; } - elseif ( key_exists( $oc, $this->_oids) && - $this->_oids[ $oc ][ 'type' ] == 'objectclass' && - key_exists( $attr, $this->_oids[ $oc ] ) ) - { - return $this->_oids[ $oc ][ $attr ]; + elseif (key_exists($oc, $this->_oids) && + $this->_oids[$oc]['type'] == 'objectclass' && + key_exists($attr, $this->_oids[$oc])) { + return $this->_oids[$oc][$attr]; } else { - return $this->raiseError( "Could not find $attr attributes for $oc " ); + return $this->raiseError("Could not find $attr attributes for $oc "); } } /** * Returns the name(s) of the immediate superclass(es) * - * @param string $oc + * @param string Name or OID of objectclass * @return mixed Array of names or Net_LDAP_Error */ - function superclass( $oc ) + function superclass($oc) { - $o = $this->get( 'objectclass', $oc ); - if( Net_LDAP::isError( $o ) ) return $o; - - return ( key_exists( 'sup', $o ) ? $o['sup'] : array() ); + $o = $this->get('objectclass', $oc); + if (Net_LDAP::isError($o)) { + return $o; + } + return (key_exists('sup', $o) ? $o['sup'] : array()); } /** @@ -190,36 +203,38 @@ * @access public * @param object Net_LDAP_Entry Subschema entry */ - function parse( &$entry ) + function parse(&$entry) { - foreach ( $this->types as $type => $attr ) + foreach ($this->types as $type => $attr) { // initialize map type to entry - $type_var = '_' . $attr ; - $this->{ $type_var } = array(); + $type_var = '_' . $attr; + $this->{$type_var} = array(); // get values for this type - $values = $entry->get_value( $attr ); + $values = $entry->get_value($attr); - if( is_array( $values ) ) + if (is_array($values)) { - foreach ( $values as $value ) - { - unset( $schema_entry ); // this was a real mess without it + foreach ($values as $value) { + + unset($schema_entry); // this was a real mess without it // get the schema entry - $schema_entry = $this->_parse_entry( $value ); + $schema_entry = $this->_parse_entry($value); // set the type - $schema_entry[ 'type' ] = $type; + $schema_entry['type'] = $type; // save a ref in $_oids - $this->_oids[ $schema_entry[ 'oid' ] ] = &$schema_entry; + $this->_oids[$schema_entry['oid']] = &$schema_entry; // save refs for all names in type map - $names = $schema_entry[ 'aliases' ]; - array_push( $names, $schema_entry[ 'name' ] ); - foreach( $names as $name ) $this->{ $type_var }[ strtolower( $name ) ] = &$schema_entry; + $names = $schema_entry['aliases']; + array_push($names, $schema_entry['name']); + foreach ($names as $name) { + $this->{$type_var}[strtolower($name)] = &$schema_entry; + } } } } @@ -229,72 +244,71 @@ * parses an attribute value into a schema entry * * @access private - * @param string $value Attribute values + * @param string Attribute value * @return mixed Schema entry array or false */ - function &_parse_entry( $value ) + function &_parse_entry($value) { // tokens that have no value associated - $noValue = array( 'single-value', - 'obsolete', - 'collective', - 'no-user-modification', - 'abstract', - 'structural', - 'auxiliary' ); + $noValue = array('single-value', + 'obsolete', + 'collective', + 'no-user-modification', + 'abstract', + 'structural', + 'auxiliary'); // tokens that can have multiple values - $multiValue = array( 'must', 'may', 'sup' ); + $multiValue = array('must', 'may', 'sup'); - $schema_entry = array( 'aliases' => array() ); // initilization + $schema_entry = array('aliases' => array()); // initilization - $tokens = $this->_tokenize( $value ); // get an array of tokens + $tokens = $this->_tokenize($value); // get an array of tokens // remove surrounding brackets - if( $tokens[0] == '(' ) array_shift( $tokens ); - if( $tokens[ count( $tokens ) - 1 ] == ')' ) array_pop( $tokens ); // -1 doesnt work on arrays :-( + if ($tokens[0] == '(') array_shift($tokens); + if ($tokens[count($tokens) - 1] == ')') array_pop($tokens); // -1 doesnt work on arrays :-( - $schema_entry[ 'oid' ] = array_shift( $tokens ); // first token is the oid + $schema_entry['oid'] = array_shift($tokens); // first token is the oid - while( count( $tokens ) > 0 ) // cycle over the tokens until none are left - { - $token = strtolower( array_shift( $tokens ) ); - if(in_array( $token, $noValue ) ) $schema_entry[ $token ] = 1; // single value token - else { + // cycle over the tokens until none are left + while (count($tokens) > 0) { + $token = strtolower(array_shift($tokens)); + if (in_array($token, $noValue)) { + $schema_entry[$token] = 1; // single value token + } else { // this one follows a string or a list if it is multivalued - if( ( $schema_entry[ $token ] = array_shift( $tokens ) ) == '(' ) - { + if (($schema_entry[$token] = array_shift($tokens)) == '(') { // this creates the list of values and cycles through the tokens // until the end of the list is reached ')' - $schema_entry[ $token ] = array(); - while( $tmp = array_shift( $tokens ) ) { - if( $tmp == ')' ) break; - if( $tmp != '$' ) array_push( $schema_entry[ $token ], $tmp ); + $schema_entry[$token] = array(); + while ($tmp = array_shift($tokens)) { + if ($tmp == ')') break; + if ($tmp != '$') array_push($schema_entry[$token], $tmp); } } // create a array if the value should be multivalued but was not - if( in_array( $token, $multiValue ) && !is_array( $schema_entry[ $token ] ) ) { - $schema_entry[ $token ] = array( $schema_entry[ $token ] ); + if (in_array($token, $multiValue ) && !is_array($schema_entry[$token])) { + $schema_entry[$token] = array($schema_entry[$token]); } } - } - + } // get max length from syntax - if( key_exists( 'syntax', $schema_entry ) ) { - if( preg_match( '/{(\d+)}/', $schema_entry[ 'syntax'], $matches ) ) { - $schema_entry[ 'max_length' ] = $matches[1]; + if (key_exists('syntax', $schema_entry)) { + if (preg_match('/{(\d+)}/', $schema_entry['syntax'], $matches)) { + $schema_entry['max_length'] = $matches[1]; } - } + } // force a name - if( empty( $schema_entry[ 'name' ] ) ) $schema_entry[ 'name' ] = $schema_entry[ 'oid' ]; - + if (empty($schema_entry['name'])) { + $schema_entry['name'] = $schema_entry['oid']; + } // make one name the default and put the other ones into aliases - if( is_array( $schema_entry[ 'name' ] ) ) { - $aliases = $schema_entry[ 'name' ]; - $schema_entry[ 'name' ] = array_shift( $aliases ); - $schema_entry[ 'aliases' ] = $aliases; - } - + if (is_array($schema_entry['name'])) { + $aliases = $schema_entry['name']; + $schema_entry['name'] = array_shift($aliases); + $schema_entry['aliases'] = $aliases; + } return $schema_entry; } @@ -302,10 +316,10 @@ * tokenizes the given value into an array of tokens * * @access private - * @param string $value String to parse - * @return array $tokens Array of tokens + * @param string String to parse + * @return array Array of tokens */ - function _tokenize( $value ) + function _tokenize($value) { $tokens = array(); // array of tokens $matches = array(); // matches[0] full pattern match, [1,2,3] subpatterns @@ -319,17 +333,17 @@ * non-empty and so it is a token. Tokens may be round brackets, a string, or a string * enclosed by ' */ - preg_match_all( $pattern, $value, $matches ); + preg_match_all($pattern, $value, $matches); - for( $i = 0; $i < count( $matches[ 0 ] ); $i++ ) { // number of tokens (full pattern match) - for( $j = 1; $j < 4; $j++ ) { // each subpattern - if( null != trim( $matches[ $j ][ $i ]) ) { // pattern match in this subpattern - $tokens[ $i ] = trim( $matches[ $j ][ $i ] ); // this is the token + for ($i = 0; $i < count($matches[0]); $i++) { // number of tokens (full pattern match) + for ($j = 1; $j < 4; $j++) { // each subpattern + if (null != trim($matches[$j][$i])) { // pattern match in this subpattern + $tokens[$i] = trim($matches[$j][$i]); // this is the token } } } return $tokens; - } + } } ?> Index: pear/Net_LDAP/LDAP/Search.php diff -u pear/Net_LDAP/LDAP/Search.php:1.2 pear/Net_LDAP/LDAP/Search.php:1.3 --- pear/Net_LDAP/LDAP/Search.php:1.2 Wed Nov 12 05:53:13 2003 +++ pear/Net_LDAP/LDAP/Search.php Fri Nov 14 06:21:27 2003 @@ -1,16 +1,28 @@ <?php - -/** - * Net_LDAP_Search - * - * @author Tarjei Huse - * @version $Id: Search.php,v 1.2 2003/11/12 10:53:13 jw Exp $ - * @package Net_LDAP - */ +/* vim: set expandtab tabstop=4 shiftwidth=4: */ +// +----------------------------------------------------------------------+ +// | PHP version 4 | +// +----------------------------------------------------------------------+ +// | Copyright (c) 1997-2003 The PHP Group | +// +----------------------------------------------------------------------+ +// | This source file is subject to version 2.0 of the PHP license, | +// | that is bundled with this package in the file LICENSE, and is | +// | available through the world-wide-web at | +// | http://www.php.net/license/2_02.txt. | +// | If you did not receive a copy of the PHP license and are unable to | +// | obtain it through the world-wide-web, please send a note to | +// | license@php.net so we can mail you a copy immediately. | +// +----------------------------------------------------------------------+ +// | Authors: Jan Wagner <wagner@netsols.de> | +// +----------------------------------------------------------------------+ +// +// $Id: Search.php,v 1.3 2003/11/14 11:21:27 jw Exp $ /** * Result set of an LDAP search * + * @author Tarjei Huse + * @version $Revision: 1.3 $ * @package Net_LDAP */ class Net_LDAP_Search extends PEAR @@ -70,7 +82,7 @@ */ function Net_LDAP_Search (&$search, &$link) { - $this->_set_search($search, $link); + $this->_setSearch($search, $link); $this->_errorCode = ldap_errno($link); } @@ -81,16 +93,20 @@ */ function entries() { - if ($this->count() == 0) return array(); - - $this->_elink = ldap_first_entry( $this->_link,$this->_search); - $entry = new Net_Ldap_Entry(&$this->_link,ldap_get_dn($this->_link,$this->_elink),ldap_get_attributes($this->_link,$this->_elink)); + if ($this->count() == 0) { + return array(); + } + + $this->_elink = @ldap_first_entry( $this->_link,$this->_search); + $entry = new Net_LDAP_Entry(&$this->_link, + @ldap_get_dn($this->_link, $this->_elink), + @ldap_get_attributes($this->_link, $this->_elink)); array_push ( $entry); - while ($this->_elink = ldap_next_entry($this->_link,$this->_elink)) { + while ($this->_elink = @ldap_next_entry($this->_link,$this->_elink)) { $entry = new Net_ldap_entry(&$this->_link, - ldap_get_dn($this->_link,$this->_elink), - ldap_get_attributes($this->_link,$this->_elink)); + ldap_get_dn($this->_link, $this->_elink), + ldap_get_attributes($this->_link, $this->_elink)); array_push ($entry); } } @@ -100,17 +116,19 @@ * * @return mixed Net_LDAP_Entry object or false */ - function shift_entry () + function shiftEntry() { - if ($this->count() == 0 ) return false; + if ($this->count() == 0 ) { + return false; + } if (is_null($this->_elink)) { - $this->_elink = ldap_first_entry($this -> _link, $this -> _search); - $entry = new Net_ldap_entry(&$this -> _link, - ldap_get_dn($this->_link, $this -> _elink), - ldap_get_attributes($this -> _link, $this -> _elink)); + $this->_elink = @ldap_first_entry($this->_link, $this->_search); + $entry = new Net_ldap_entry(&$this->_link, + ldap_get_dn($this->_link, $this->_elink), + ldap_get_attributes($this->_link, $this->_elink)); } else { - if (!$this->_elink = ldap_next_entry($this -> _link, $this -> _elink)) { + if (!$this->_elink = ldap_next_entry($this->_link, $this->_elink)) { return false; } $entry = new Net_ldap_entry(&$this->_link, @@ -119,6 +137,17 @@ } return $entry; } + + /** + * alias function of shiftEntry() for perl-ldap interface + * + * @see shiftEntry() + */ + function shift_entry() + { + $args = func_get_args(); + return call_user_func_array(array( &$this, 'shiftEntry' ), $args); + } /** * Retrieve the last entry of the searchset. NOT IMPLEMENTED @@ -158,10 +187,10 @@ * @param resource Search result identifier * @param resource Resource link identifier */ - function _set_search (&$search,&$link) + function _setSearch(&$search,&$link) { $this->_search = $search; - $this->_link = $link; + $this->_link = $link; } /** @@ -169,13 +198,13 @@ * * @return int Number of entries in search. */ - function count () + function count() { /* this catches the situation where OL returned errno 32 = no such object! */ if (!$this->_search) { return 0; } - return ldap_count_entries ($this->_link,$this->_search); + return @ldap_count_entries($this->_link, $this->_search); } /** @@ -183,10 +212,10 @@ * * @return int The ldap error number. */ - function getErrorCode () + function getErrorCode() { return $this->_errorCode; - } + } /** Destructor * @@ -194,7 +223,7 @@ */ function _Net_LDAP_Search() { - ldap_free_result($this->_search); + @ldap_free_result($this->_search); } /** @@ -202,9 +231,8 @@ */ function done() { - $this->_Net_Ldap_Search(); + $this->_Net_LDAP_Search(); } - - } + ?> Index: pear/Net_LDAP/LDAP/Util.php diff -u pear/Net_LDAP/LDAP/Util.php:1.3 pear/Net_LDAP/LDAP/Util.php:1.4 --- pear/Net_LDAP/LDAP/Util.php:1.3 Wed Nov 12 05:53:13 2003 +++ pear/Net_LDAP/LDAP/Util.php Fri Nov 14 06:21:27 2003 @@ -1,17 +1,29 @@ <?php - -/** - * Net_LDAP_Util - * - * @package Net_LDAP - * @author Jan Wagner <wagner@netsols.de> - * @version $Id: Util.php,v 1.3 2003/11/12 10:53:13 jw Exp $ - */ - +/* vim: set expandtab tabstop=4 shiftwidth=4: */ +// +----------------------------------------------------------------------+ +// | PHP version 4 | +// +----------------------------------------------------------------------+ +// | Copyright (c) 1997-2003 The PHP Group | +// +----------------------------------------------------------------------+ +// | This source file is subject to version 2.0 of the PHP license, | +// | that is bundled with this package in the file LICENSE, and is | +// | available through the world-wide-web at | +// | http://www.php.net/license/2_02.txt. | +// | If you did not receive a copy of the PHP license and are unable to | +// | obtain it through the world-wide-web, please send a note to | +// | license@php.net so we can mail you a copy immediately. | +// +----------------------------------------------------------------------+ +// | Authors: Jan Wagner <wagner@netsols.de> | +// +----------------------------------------------------------------------+ +// +// $Id: Util.php,v 1.4 2003/11/14 11:21:27 jw Exp $ + /** * Utility Class for Net_LDAP * * @package Net_LDAP + * @author Jan Wagner <wagner@netsols.de> + * @version $Revision: 1.4 $ */ class Net_LDAP_Util extends PEAR { @@ -37,12 +49,11 @@ * Takes an LDAP object by reference and saves it. Then the schema will be fetched. * * @access public - * @param object $ldap Net_LDAP + * @param object Net_LDAP */ - function Net_LDAP_Util( &$ldap ) + function Net_LDAP_Util(&$ldap) { - if (is_object($ldap) && (get_class($ldap) == 'net_ldap')) - { + if (is_object($ldap) && (get_class($ldap) == 'net_ldap')) { $this->_ldap = $ldap; $this->_schema = $this->_ldap->schema(); if (Net_LDAP::isError($this->_schema)) $this->_schema = null; @@ -57,10 +68,10 @@ * can be used for adding or modifying. * * @access public - * @param array $attributes Array of attributes + * @param array Array of attributes * @return array Array of UTF8 encoded attributes */ - function utf8Encode( $attributes ) + function utf8Encode($attributes) { return $this->_utf8($attributes, 'utf8_encode'); } @@ -69,10 +80,10 @@ * Decodes the given attribute values * * @access public - * @param array attributes Array of attributes - * @return array array Array with decoded attribute values + * @param array Array of attributes + * @return array Array with decoded attribute values */ - function utf8Decode( $attributes ) + function utf8Decode($attributes) { return $this->_utf8($attributes, 'utf8_decode'); } @@ -81,25 +92,26 @@ * Encodes or decodes attribute values if needed * * @access private - * @param array $attributes Array of attributes - * @param array $function Function to apply to attribute values + * @param array Array of attributes + * @param array Function to apply to attribute values * @return array Array of attributes with function applied to values */ - function _utf8( $attributes, $function ) + function _utf8($attributes, $function) { - if (!$this->_ldap || !$this->_schema || !function_exists($function)) return $attributes; - - if (is_array($attributes) && count($attributes) > 0) - { - foreach( $attributes as $k => $v ) - { + if (!$this->_ldap || !$this->_schema || !function_exists($function)) { + return $attributes; + } + if (is_array($attributes) && count($attributes) > 0) { + foreach( $attributes as $k => $v ) { $attr = $this->_schema->get('attribute', $k); - if (Net_LDAP::isError($attr)) continue; - - if (false !== strpos($attr['syntax'], '1.3.6.1.4.1.1466.115.121.1.15')) - { + if (Net_LDAP::isError($attr)) { + continue; + } + if (false !== strpos($attr['syntax'], '1.3.6.1.4.1.1466.115.121.1.15')) { if (is_array($v)) { - foreach( $v as $ak => $av ) $v[$ak] = call_user_func($function, $av ); + foreach ($v as $ak => $av ) { + $v[$ak] = call_user_func($function, $av ); + } } else { $v = call_user_func($function, $v); } @@ -108,8 +120,7 @@ } } return $attributes; - } - + } } ?>