Convert Horde_Ldap to H4 format
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 3 Feb 2010 08:35:17 +0000 (01:35 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 3 Feb 2010 08:35:17 +0000 (01:35 -0700)
framework/Group/Group/kolab.php
framework/Kolab_Storage/package.xml
framework/LDAP/LDAP.php [deleted file]
framework/LDAP/package.xml [deleted file]
framework/LDAP/tests/quoteDN.phpt [deleted file]
framework/Ldap/lib/Horde/Ldap.php [new file with mode: 0644]
framework/Ldap/package.xml [new file with mode: 0644]
framework/Ldap/test/Horde/Ldap/quoteDN.phpt [new file with mode: 0644]
turba/lib/Driver/Ldap.php

index 95ffed9..d901e20 100644 (file)
@@ -1,7 +1,6 @@
 <?php
 
 require_once 'Horde/Group/ldap.php';
-require_once 'Horde/LDAP.php';
 
 /**
  * The Group_kolab class provides a Kolab backend for the Horde groups
@@ -270,7 +269,7 @@ class Group_kolab extends Group_ldap {
      */
     function dnForMail($mail)
     {
-        $filter = '(&(objectclass=kolabInetOrgPerson)(mail=' . Horde_LDAP::quote($mail) . '))';
+        $filter = '(&(objectclass=kolabInetOrgPerson)(mail=' . Horde_Ldap::quote($mail) . '))';
         $search = @ldap_search($this->_ds, $this->_params['basedn'], $filter);
         if (!$search) {
             return PEAR::raiseError(_("Could not reach the LDAP server"));
index ba419e6..31e10f2 100644 (file)
@@ -153,7 +153,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
     <channel>pear.horde.org</channel>
    </package>
    <package>
-    <name>Horde_LDAP</name>
+    <name>Ldap</name>
     <channel>pear.horde.org</channel>
    </package>
    <package>
diff --git a/framework/LDAP/LDAP.php b/framework/LDAP/LDAP.php
deleted file mode 100644 (file)
index b9c4718..0000000
+++ /dev/null
@@ -1,91 +0,0 @@
-<?php
-/**
- * This is a utility class, every method is static.
- *
- * Copyright 1999-2010 The Horde Project (http://www.horde.org/)
- *
- * 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 <chuck@horde.org>
- * @package Horde_LDAP
- */
-class Horde_LDAP
-{
-    /**
-     * Return a boolean expression using the specified operator.
-     *
-     * @param string $lhs    The attribute to test.
-     * @param string $op     The operator.
-     * @param string $rhs    The comparison value.
-     * @param array $params  Any additional parameters for the operator.
-     *
-     * @return string  The LDAP search fragment.
-     */
-    public static 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));
-            } elseif (!empty($params['approximate'])) {
-                return sprintf('(%s=~%s)', $lhs, Horde_LDAP::quote($rhs));
-            }
-            return sprintf('(%s=*%s*)', $lhs, Horde_LDAP::quote($rhs));
-
-        default:
-            return sprintf('(%s%s%s)', $lhs, $op, Horde_LDAP::quote($rhs));
-        }
-    }
-
-    /**
-     * Escape characters with special meaning in LDAP searches.
-     *
-     * @param string $clause  The string to escape.
-     *
-     * @return string  The escaped string.
-     */
-    public static function quote($clause)
-    {
-        return str_replace(array('\\',   '(',  ')',  '*',  "\0"),
-                           array('\\5c', '\(', '\)', '\*', "\\00"),
-                           $clause);
-    }
-
-    /**
-     * Take an array of DN elements and properly quote it according to RFC
-     * 1485.
-     *
-     * @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.
-     */
-    public static 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;
-    }
-}
diff --git a/framework/LDAP/package.xml b/framework/LDAP/package.xml
deleted file mode 100644 (file)
index 8de8a26..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<package packagerversion="1.4.9" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0
-http://pear.php.net/dtd/tasks-1.0.xsd
-http://pear.php.net/dtd/package-2.0
-http://pear.php.net/dtd/package-2.0.xsd">
- <name>Horde_LDAP</name>
- <channel>pear.horde.org</channel>
- <summary>LDAP Utility Class</summary>
- <description>Horde_LDAP:: contains some utility functions for dealing with LDAP
-servers and data.
- </description>
- <lead>
-  <name>Chuck Hagenbuch</name>
-  <user>chuck</user>
-  <email>chuck@horde.org</email>
-  <active>yes</active>
- </lead>
- <date>2006-05-08</date>
- <time>22:19:35</time>
- <version>
-  <release>0.0.2</release>
-  <api>0.0.2</api>
- </version>
- <stability>
-  <release>alpha</release>
-  <api>alpha</api>
- </stability>
- <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
- <notes>* Converted to package.xml 2.0 for pear.horde.org
-* Support approximate LDAP searches (requires openldap or another supported server).
- </notes>
- <contents>
-  <dir name="/">
-   <dir name="tests">
-    <file name="quoteDN.phpt" role="test" />
-   </dir> <!-- //tests -->
-   <file baseinstalldir="/Horde" name="LDAP.php" role="php" />
-  </dir> <!-- / -->
- </contents>
- <dependencies>
-  <required>
-   <php>
-    <min>4.0.0</min>
-   </php>
-   <pearinstaller>
-    <min>1.4.0b1</min>
-   </pearinstaller>
-  </required>
- </dependencies>
- <phprelease />
- <changelog>
-  <release>
-   <version>
-    <release>0.0.1</release>
-    <api>0.0.1</api>
-   </version>
-   <stability>
-    <release>alpha</release>
-    <api>alpha</api>
-   </stability>
-   <date>2004-01-12</date>
-   <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
-   <notes>Initial release as a PEAR package
-   </notes>
-  </release>
- </changelog>
-</package>
diff --git a/framework/LDAP/tests/quoteDN.phpt b/framework/LDAP/tests/quoteDN.phpt
deleted file mode 100644 (file)
index 631efa4..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
---TEST--
-Horde_LDAP::quoteDN() tests
---FILE--
-<?php
-
-require_once dirname(__FILE__) . '/../LDAP.php';
-
-echo Horde_LDAP::quoteDN(array(array('cn', 'John Smith'),
-                               array('dc', 'example'),
-                               array('dc', 'com'))) . "\n";
-
-echo Horde_LDAP::quoteDN(array(array('cn', 'Smith, John'),
-                               array('dc', 'example'),
-                               array('dc', 'com'))) . "\n";
-
-echo Horde_LDAP::quoteDN(array(array('cn', ' John Smith'),
-                               array('dc', 'example'),
-                               array('dc', 'com'))) . "\n";
-
-echo Horde_LDAP::quoteDN(array(array('cn', 'John Smith '),
-                               array('dc', 'example'),
-                               array('dc', 'com'))) . "\n";
-
-echo Horde_LDAP::quoteDN(array(array('cn', 'John  Smith'),
-                               array('dc', 'example'),
-                               array('dc', 'com'))) . "\n";
-
-echo Horde_LDAP::quoteDN(array(array('cn', 'John+Smith'),
-                               array('dc', 'example'),
-                               array('dc', 'com'))) . "\n";
-
-echo Horde_LDAP::quoteDN(array(array('cn', 'John "Bugsy" Smith'),
-                               array('dc', 'example'),
-                               array('dc', 'com'))) . "\n";
-
-?>
---EXPECT--
-cn=John Smith,dc=example,dc=com
-cn="Smith, John",dc=example,dc=com
-cn=" John Smith",dc=example,dc=com
-cn="John Smith ",dc=example,dc=com
-cn="John  Smith",dc=example,dc=com
-cn="John+Smith",dc=example,dc=com
-cn="John \"Bugsy\" Smith",dc=example,dc=com
diff --git a/framework/Ldap/lib/Horde/Ldap.php b/framework/Ldap/lib/Horde/Ldap.php
new file mode 100644 (file)
index 0000000..08d4b48
--- /dev/null
@@ -0,0 +1,96 @@
+<?php
+/**
+ * This is a utility class, every method is static.
+ *
+ * Copyright 1999-2010 The Horde Project (http://www.horde.org/)
+ *
+ * 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 <chuck@horde.org>
+ * @category Horde
+ * @package  Horde_Ldap
+ */
+class Horde_Ldap
+{
+    /**
+     * Return a boolean expression using the specified operator.
+     *
+     * @param string $lhs    The attribute to test.
+     * @param string $op     The operator.
+     * @param string $rhs    The comparison value.
+     * @param array $params  Any additional parameters for the operator.
+     *
+     * @return string  The LDAP search fragment.
+     */
+    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, self::quote($rhs), $lhs, self::quote($rhs));
+            } elseif (!empty($params['approximate'])) {
+                return sprintf('(%s=~%s)', $lhs, self::quote($rhs));
+            }
+            return sprintf('(%s=*%s*)', $lhs, self::quote($rhs));
+
+        default:
+            return sprintf('(%s%s%s)', $lhs, $op, self::quote($rhs));
+        }
+    }
+
+    /**
+     * Escape characters with special meaning in LDAP searches.
+     *
+     * @param string $clause  The string to escape.
+     *
+     * @return string  The escaped string.
+     */
+    static public function quote($clause)
+    {
+        return str_replace(array('\\',   '(',  ')',  '*',  "\0"),
+                           array('\\5c', '\(', '\)', '\*', "\\00"),
+                           $clause);
+    }
+
+    /**
+     * Take an array of DN elements and properly quote it according to RFC
+     * 1485.
+     *
+     * @param array $parts  An array of tuples containing the attribute
+     *                      name and that attribute's value which make
+     *                      up the DN. Example:
+     * <pre>
+     * $parts = array(
+     *     0 => array('cn', 'John Smith'),
+     *     1 => array('dc', 'example'),
+     *     2 => array('dc', 'com')
+     * );
+     * </pre>
+     *
+     * @return string  The properly quoted string DN.
+     */
+    static public function quoteDN($parts)
+    {
+        $dn = '';
+
+        for ($i = 0, $cnt = count($parts); $i < $cnt; ++$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;
+    }
+
+}
diff --git a/framework/Ldap/package.xml b/framework/Ldap/package.xml
new file mode 100644 (file)
index 0000000..52e4a28
--- /dev/null
@@ -0,0 +1,92 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<package packagerversion="1.4.9" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0
+http://pear.php.net/dtd/tasks-1.0.xsd
+http://pear.php.net/dtd/package-2.0
+http://pear.php.net/dtd/package-2.0.xsd">
+ <name>Ldap</name>
+ <channel>pear.horde.org</channel>
+ <summary>Ldap Utility Class</summary>
+ <description>This package contains utility functions for dealing with LDAP servers and data.
+ </description>
+ <lead>
+  <name>Chuck Hagenbuch</name>
+  <user>chuck</user>
+  <email>chuck@horde.org</email>
+  <active>yes</active>
+ </lead>
+ <date>2010-02-02</date>
+ <version>
+  <release>0.1.0</release>
+  <api>0.1.0</api>
+ </version>
+ <stability>
+  <release>beta</release>
+  <api>beta</api>
+ </stability>
+ <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
+ <notes>* Initial Horde 4 package.
+ </notes>
+ <contents>
+  <dir name="/">
+   <dir name="lib">
+    <dir name="Horde">
+     <file name="Ldap.php" role="php" />
+    </dir> <!-- /lib/Horde -->
+   </dir> <!-- /lib -->
+   <dir name="test">
+    <dir name="Horde">
+     <dir name="Ldap">
+      <file name="quoteDN.phpt" role="test" />
+     </dir> <!-- /test/Horde/Ldap -->
+    </dir> <!-- /test/Horde -->
+   </dir> <!-- /test -->
+  </dir> <!-- / -->
+ </contents>
+ <dependencies>
+  <required>
+   <php>
+    <min>5.2.0</min>
+   </php>
+   <pearinstaller>
+    <min>1.5.0</min>
+   </pearinstaller>
+  </required>
+ </dependencies>
+ <phprelease>
+  <filelist>
+   <install name="lib/Horde/Ldap.php" as="Horde/Ldap.php" />
+  </filelist>
+ </phprelease>
+ <changelog>
+  <release>
+   <date>2006-05-08</date>
+   <time>22:19:35</time>
+   <version>
+    <release>0.0.2</release>
+    <api>0.0.2</api>
+   </version>
+   <stability>
+    <release>alpha</release>
+    <api>alpha</api>
+   </stability>
+   <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
+   <notes>* Converted to package.xml 2.0 for pear.horde.org
+   * Support approximate LDAP searches (requires openldap or another supported server).
+   </notes>
+  </release>
+  <release>
+   <version>
+    <release>0.0.1</release>
+    <api>0.0.1</api>
+   </version>
+   <stability>
+    <release>alpha</release>
+    <api>alpha</api>
+   </stability>
+   <date>2004-01-12</date>
+   <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
+   <notes>Initial release as a PEAR package
+   </notes>
+  </release>
+ </changelog>
+</package>
diff --git a/framework/Ldap/test/Horde/Ldap/quoteDN.phpt b/framework/Ldap/test/Horde/Ldap/quoteDN.phpt
new file mode 100644 (file)
index 0000000..a58ffcb
--- /dev/null
@@ -0,0 +1,44 @@
+--TEST--
+Horde_Ldap::quoteDN() tests
+--FILE--
+<?php
+
+require_once dirname(__FILE__) . '/../../../lib/Horde/Ldap.php';
+
+echo Horde_Ldap::quoteDN(array(array('cn', 'John Smith'),
+                               array('dc', 'example'),
+                               array('dc', 'com'))) . "\n";
+
+echo Horde_Ldap::quoteDN(array(array('cn', 'Smith, John'),
+                               array('dc', 'example'),
+                               array('dc', 'com'))) . "\n";
+
+echo Horde_Ldap::quoteDN(array(array('cn', ' John Smith'),
+                               array('dc', 'example'),
+                               array('dc', 'com'))) . "\n";
+
+echo Horde_Ldap::quoteDN(array(array('cn', 'John Smith '),
+                               array('dc', 'example'),
+                               array('dc', 'com'))) . "\n";
+
+echo Horde_Ldap::quoteDN(array(array('cn', 'John  Smith'),
+                               array('dc', 'example'),
+                               array('dc', 'com'))) . "\n";
+
+echo Horde_Ldap::quoteDN(array(array('cn', 'John+Smith'),
+                               array('dc', 'example'),
+                               array('dc', 'com'))) . "\n";
+
+echo Horde_Ldap::quoteDN(array(array('cn', 'John "Bugsy" Smith'),
+                               array('dc', 'example'),
+                               array('dc', 'com'))) . "\n";
+
+?>
+--EXPECT--
+cn=John Smith,dc=example,dc=com
+cn="Smith, John",dc=example,dc=com
+cn=" John Smith",dc=example,dc=com
+cn="John Smith ",dc=example,dc=com
+cn="John  Smith",dc=example,dc=com
+cn="John+Smith",dc=example,dc=com
+cn="John \"Bugsy\" Smith",dc=example,dc=com
index 62f0d49..7216f57 100644 (file)
@@ -427,7 +427,7 @@ class Turba_Driver_Ldap extends Turba_Driver
                 $pairs[] = array($param, $attributes[$param]);
             }
         }
-        return $this->_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;
-    }
-
 }