From 8eaef864016080cc32cdfaff0f56e9a9a779a2cd Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Wed, 3 Feb 2010 01:35:17 -0700 Subject: [PATCH] Convert Horde_Ldap to H4 format --- framework/Group/Group/kolab.php | 3 +- framework/Kolab_Storage/package.xml | 2 +- framework/LDAP/package.xml | 67 ---------------- .../{LDAP/LDAP.php => Ldap/lib/Horde/Ldap.php} | 37 +++++---- framework/Ldap/package.xml | 92 ++++++++++++++++++++++ .../tests => Ldap/test/Horde/Ldap}/quoteDN.phpt | 18 ++--- turba/lib/Driver/Ldap.php | 43 +--------- 7 files changed, 127 insertions(+), 135 deletions(-) delete mode 100644 framework/LDAP/package.xml rename framework/{LDAP/LDAP.php => Ldap/lib/Horde/Ldap.php} (72%) create mode 100644 framework/Ldap/package.xml rename framework/{LDAP/tests => Ldap/test/Horde/Ldap}/quoteDN.phpt (68%) diff --git a/framework/Group/Group/kolab.php b/framework/Group/Group/kolab.php index 95ffed94e..d901e20fc 100644 --- a/framework/Group/Group/kolab.php +++ b/framework/Group/Group/kolab.php @@ -1,7 +1,6 @@ _ds, $this->_params['basedn'], $filter); if (!$search) { return PEAR::raiseError(_("Could not reach the LDAP server")); diff --git a/framework/Kolab_Storage/package.xml b/framework/Kolab_Storage/package.xml index ba419e6e3..31e10f22e 100644 --- a/framework/Kolab_Storage/package.xml +++ b/framework/Kolab_Storage/package.xml @@ -153,7 +153,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> pear.horde.org - Horde_LDAP + Ldap pear.horde.org diff --git a/framework/LDAP/package.xml b/framework/LDAP/package.xml deleted file mode 100644 index 8de8a2645..000000000 --- a/framework/LDAP/package.xml +++ /dev/null @@ -1,67 +0,0 @@ - - - Horde_LDAP - pear.horde.org - LDAP Utility Class - Horde_LDAP:: contains some utility functions for dealing with LDAP -servers and data. - - - Chuck Hagenbuch - chuck - chuck@horde.org - yes - - 2006-05-08 - - - 0.0.2 - 0.0.2 - - - alpha - alpha - - LGPL - * Converted to package.xml 2.0 for pear.horde.org -* Support approximate LDAP searches (requires openldap or another supported server). - - - - - - - - - - - - - 4.0.0 - - - 1.4.0b1 - - - - - - - - 0.0.1 - 0.0.1 - - - alpha - alpha - - 2004-01-12 - LGPL - Initial release as a PEAR package - - - - diff --git a/framework/LDAP/LDAP.php b/framework/Ldap/lib/Horde/Ldap.php similarity index 72% rename from framework/LDAP/LDAP.php rename to framework/Ldap/lib/Horde/Ldap.php index b9c471850..08d4b4866 100644 --- a/framework/LDAP/LDAP.php +++ b/framework/Ldap/lib/Horde/Ldap.php @@ -7,10 +7,11 @@ * See the enclosed file COPYING for license information (LGPL). If you * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. * - * @author Chuck Hagenbuch - * @package Horde_LDAP + * @author Chuck Hagenbuch + * @category Horde + * @package Horde_Ldap */ -class Horde_LDAP +class Horde_Ldap { /** * Return a boolean expression using the specified operator. @@ -22,21 +23,21 @@ class Horde_LDAP * * @return string The LDAP search fragment. */ - public static function buildClause($lhs, $op, $rhs, $params = array()) + static public function buildClause($lhs, $op, $rhs, $params = array()) { switch ($op) { case 'LIKE': if (empty($rhs)) { return '(' . $lhs . '=*)'; } elseif (!empty($params['begin'])) { - return sprintf('(|(%s=%s*)(%s=* %s*))', $lhs, Horde_LDAP::quote($rhs), $lhs, Horde_LDAP::quote($rhs)); + return sprintf('(|(%s=%s*)(%s=* %s*))', $lhs, self::quote($rhs), $lhs, self::quote($rhs)); } elseif (!empty($params['approximate'])) { - return sprintf('(%s=~%s)', $lhs, Horde_LDAP::quote($rhs)); + return sprintf('(%s=~%s)', $lhs, self::quote($rhs)); } - return sprintf('(%s=*%s*)', $lhs, Horde_LDAP::quote($rhs)); + return sprintf('(%s=*%s*)', $lhs, self::quote($rhs)); default: - return sprintf('(%s%s%s)', $lhs, $op, Horde_LDAP::quote($rhs)); + return sprintf('(%s%s%s)', $lhs, $op, self::quote($rhs)); } } @@ -47,7 +48,7 @@ class Horde_LDAP * * @return string The escaped string. */ - public static function quote($clause) + static public function quote($clause) { return str_replace(array('\\', '(', ')', '*', "\0"), array('\\5c', '\(', '\)', '\*', "\\00"), @@ -61,18 +62,21 @@ class Horde_LDAP * @param array $parts An array of tuples containing the attribute * name and that attribute's value which make * up the DN. Example: - * - * $parts = array(0 => array('cn', 'John Smith'), - * 1 => array('dc', 'example'), - * 2 => array('dc', 'com')); + *
+     * $parts = array(
+     *     0 => array('cn', 'John Smith'),
+     *     1 => array('dc', 'example'),
+     *     2 => array('dc', 'com')
+     * );
+     * 
* * @return string The properly quoted string DN. */ - public static function quoteDN($parts) + static public function quoteDN($parts) { $dn = ''; - $count = count($parts); - for ($i = 0; $i < $count; $i++) { + + for ($i = 0, $cnt = count($parts); $i < $cnt; ++$i) { if ($i > 0) { $dn .= ','; } @@ -88,4 +92,5 @@ class Horde_LDAP return $dn; } + } diff --git a/framework/Ldap/package.xml b/framework/Ldap/package.xml new file mode 100644 index 000000000..52e4a286f --- /dev/null +++ b/framework/Ldap/package.xml @@ -0,0 +1,92 @@ + + + Ldap + pear.horde.org + Ldap Utility Class + This package contains utility functions for dealing with LDAP servers and data. + + + Chuck Hagenbuch + chuck + chuck@horde.org + yes + + 2010-02-02 + + 0.1.0 + 0.1.0 + + + beta + beta + + LGPL + * Initial Horde 4 package. + + + + + + + + + + + + + + + + + + + + + 5.2.0 + + + 1.5.0 + + + + + + + + + + + 2006-05-08 + + + 0.0.2 + 0.0.2 + + + alpha + alpha + + LGPL + * Converted to package.xml 2.0 for pear.horde.org + * Support approximate LDAP searches (requires openldap or another supported server). + + + + + 0.0.1 + 0.0.1 + + + alpha + alpha + + 2004-01-12 + LGPL + Initial release as a PEAR package + + + + diff --git a/framework/LDAP/tests/quoteDN.phpt b/framework/Ldap/test/Horde/Ldap/quoteDN.phpt similarity index 68% rename from framework/LDAP/tests/quoteDN.phpt rename to framework/Ldap/test/Horde/Ldap/quoteDN.phpt index 631efa45f..a58ffcb14 100644 --- a/framework/LDAP/tests/quoteDN.phpt +++ b/framework/Ldap/test/Horde/Ldap/quoteDN.phpt @@ -1,35 +1,35 @@ --TEST-- -Horde_LDAP::quoteDN() tests +Horde_Ldap::quoteDN() tests --FILE-- _quoteDN($pairs); + return Horde_Ldap::quoteDN($pairs); } /** @@ -462,7 +462,7 @@ class Turba_Driver_Ldap extends Turba_Driver } else { if (isset($vals['field'])) { $rhs = Horde_String::convertCharset($vals['test'], Horde_Nls::getCharset(), $this->_params['charset']); - $clause .= Horde_LDAP::buildClause($vals['field'], $vals['op'], $rhs, array('begin' => !empty($vals['begin']))); + $clause .= Horde_Ldap::buildClause($vals['field'], $vals['op'], $rhs, array('begin' => !empty($vals['begin']))); } else { foreach ($vals as $test) { if (!empty($test['OR'])) { @@ -471,7 +471,7 @@ class Turba_Driver_Ldap extends Turba_Driver $clause .= '(&' . $this->_buildSearchQuery($test) . ')'; } else { $rhs = Horde_String::convertCharset($test['test'], Horde_Nls::getCharset(), $this->_params['charset']); - $clause .= Horde_LDAP::buildClause($test['field'], $test['op'], $rhs, array('begin' => !empty($vals['begin']))); + $clause .= Horde_Ldap::buildClause($test['field'], $test['op'], $rhs, array('begin' => !empty($vals['begin']))); } } } @@ -759,41 +759,4 @@ class Turba_Driver_Ldap extends Turba_Driver return $_schema; } - /** - * Take an array of DN elements and properly quote it according to - * RFC 1485. - * - * @see Horde_LDAP::quoteDN() - * - * @param array $parts An array of tuples containing the attribute - * name and that attribute's value which make - * up the DN. Example: - * - * $parts = array(0 => array('cn', 'John Smith'), - * 1 => array('dc', 'example'), - * 2 => array('dc', 'com')); - * - * @return string The properly quoted string DN. - */ - function _quoteDN($parts) - { - $dn = ''; - $count = count($parts); - for ($i = 0; $i < $count; $i++) { - if ($i > 0) { - $dn .= ','; - } - $dn .= $parts[$i][0] . '='; - - /* See if we need to quote the value. */ - if (preg_match('/^\s|\s$|\s\s|[,+="\r\n<>#;]/', $parts[$i][1])) { - $dn .= '"' . str_replace('"', '\\"', $parts[$i][1]) . '"'; - } else { - $dn .= $parts[$i][1]; - } - } - - return $dn; - } - } -- 2.11.0