SOURCES: turba-attrcache.patch (NEW) - ldap driver from HEAD (incl...

glen glen at pld-linux.org
Wed Aug 2 10:28:20 CEST 2006


Author: glen                         Date: Wed Aug  2 08:28:20 2006 GMT
Module: SOURCES                       Tag: HEAD
---- Log message:
- ldap driver from HEAD (includes attrcache patch)

---- Files affected:
SOURCES:
   turba-attrcache.patch (NONE -> 1.1)  (NEW)

---- Diffs:

================================================================
Index: SOURCES/turba-attrcache.patch
diff -u /dev/null SOURCES/turba-attrcache.patch:1.1
--- /dev/null	Wed Aug  2 10:28:20 2006
+++ SOURCES/turba-attrcache.patch	Wed Aug  2 10:28:15 2006
@@ -0,0 +1,156 @@
+--- lib/Driver/ldap.php	2006-04-13 01:24:23.000000000 +0300
++++ lib/Driver/ldap.php-bug4207	2006-07-31 23:35:13.954033485 +0300
+@@ -18,6 +18,13 @@
+     var $_ds = 0;
+ 
+     /**
++     * Cache _getSyntax calls to avoid lots of repeated server calls.
++     *
++     * @var array
++     */
++    var $_syntaxCache = array();
++
++    /**
+      * Constructs a new Turba LDAP driver object.
+      *
+      * @access private
+@@ -26,10 +33,6 @@
+      */
+     function Turba_Driver_ldap($params)
+     {
+-        if (!Util::extensionExists('ldap')) {
+-            Horde::fatal(PEAR::raiseError(_("LDAP support is required but the LDAP module is not available or not loaded.")), __FILE__, __LINE__);
+-        }
+-
+         if (empty($params['server'])) {
+             $params['server'] = 'localhost';
+         }
+@@ -54,6 +57,10 @@
+ 
+     function _init()
+     {
++        if (!Util::extensionExists('ldap')) {
++            return PEAR::raiseError(_("LDAP support is required but the LDAP module is not available or not loaded."));
++        }
++
+         if (!($this->_ds = @ldap_connect($this->_params['server'], $this->_params['port']))) {
+             return PEAR::raiseError(_("Connection failure"));
+         }
+@@ -290,15 +297,8 @@
+         /* Check if we need to rename the object. */
+         if ($this->_params['version'] == 3 &&
+             String::lower($this->_makeKey($attributes)) != String::lower($object_id)) {
+-            if (isset($this->_params['dn']) && is_array($this->_params['dn']) && count($this->_params['dn'])) {
+-                $pairs = array();
+-                foreach ($this->_params['dn'] as $param) {
+-                    if (isset($attributes[$param])) {
+-                        $pairs[] = array($param, $attributes[$param]);
+-                    }
+-                }
+-                $newrdn = $this->_quoteDN($pairs);
+-            } else {
++            $newrdn = $this->_makeRDN($attributes);
++            if ($newrdn == '') {
+                 return PEAR::raiseError(_("Missing DN in LDAP source configuration."));
+             }
+ 
+@@ -351,6 +351,30 @@
+     }
+ 
+     /**
++     * Build a RDN based on a set of attributes and what attributes
++     * make a RDN for the current source.
++     *
++     * @param array $attributes The attributes (in driver keys) of the
++     *                          object being added.
++     *
++     * @return string  The RDN for the new object.
++     */
++    function _makeRDN($attributes)
++    {
++        if (!is_array($this->_params['dn'])) {
++            return '';
++        }
++
++        $pairs = array();
++        foreach ($this->_params['dn'] as $param) {
++            if (isset($attributes[$param])) {
++                $pairs[] = array($param, $attributes[$param]);
++            }
++        }
++        return $this->_quoteDN($pairs);
++    }
++
++    /**
+      * Build a DN based on a set of attributes and what attributes
+      * make a DN for the current source.
+      *
+@@ -361,18 +385,7 @@
+      */
+     function _makeKey($attributes)
+     {
+-        $dn = '';
+-        if (is_array($this->_params['dn'])) {
+-            $pairs = array();
+-            foreach ($this->_params['dn'] as $param) {
+-                if (isset($attributes[$param])) {
+-                    $pairs[] = array($param, $attributes[$param]);
+-                }
+-            }
+-            $dn = $this->_quoteDN($pairs);
+-        }
+-
+-        return $dn . ',' . $this->_params['root'];
++        return $this->_makeRDN($attributes) . ',' . $this->_params['root'];
+     }
+ 
+     /**
+@@ -626,14 +639,9 @@
+      */
+     function _isPostalAddress($attribute)
+     {
+-        $syntax = $this->_getSyntax($attribute);
+-
+-        /** LDAP postal address syntax
++        /* LDAP postal address syntax is
+          * 1.3.6.1.4.1.1466.115.121.1.41 */
+-        if ($syntax == "1.3.6.1.4.1.1466.115.121.1.41") {
+-            return true;
+-        }
+-        return false;
++        return $this->_getSyntax($attribute) == '1.3.6.1.4.1.1466.115.121.1.41';
+     }
+ 
+     /**
+@@ -651,13 +659,17 @@
+         if (is_a($schema, 'PEAR_Error')) {
+             return $schema;
+         }
+-        $attv = $schema->get('attribute', $att);
+ 
+-        if (isset($attv['syntax'])) {
+-            return $attv['syntax'];
+-        } else {
+-            return $this->_getSyntax($attv['sup'][0]);
++        if (!isset($this->_syntaxCache[$att])) {
++            $attv = $schema->get('attribute', $att);
++            if (isset($attv['syntax'])) {
++                $this->_syntaxCache[$att] = $attv['syntax'];
++            } else {
++                $this->_syntaxCache[$att] = $this->_getSyntax($attv['sup'][0]);
++            }
+         }
++
++        return $this->_syntaxCache[$att];
+     }
+ 
+     /**
+@@ -680,7 +692,7 @@
+ 
+         $config = array('host' => $this->_params['server'],
+                         'port' => $this->_params['port']);
+-        $ldap = &new Net_LDAP($config);
++        $ldap = new Net_LDAP($config);
+         $ldap->_link = $this->_ds;
+ 
+         $_schema = &$ldap->schema();
================================================================


More information about the pld-cvs-commit mailing list