Changeset 5372 in subversion


Ignore:
Timestamp:
Oct 28, 2011 4:05:32 PM (19 months ago)
Author:
thomasb
Message:

LDAP: use VLV pseudo-search for autocompletion

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/program/include/rcube_ldap.php

    r5356 r5372  
    711711            } 
    712712            return $result; 
     713        } 
     714 
     715        // use VLV pseudo-search for autocompletion 
     716        if ($this->prop['vlv_search'] && $this->conn && join(',', $fields) == 'email,name') 
     717        { 
     718            // add general filter to query 
     719            if (!empty($this->prop['filter']) && empty($this->filter)) 
     720                $this->set_search_set($this->prop['filter']); 
     721 
     722            // set VLV controls with encoded search string 
     723            $this->_vlv_set_controls($this->prop, $this->list_page, $this->page_size, $value); 
     724 
     725            $function = $this->_scope2func($this->prop['scope']); 
     726            $this->ldap_result = @$function($this->conn, $this->base_dn, $this->filter ? $this->filter : '(objectclass=*)', 
     727                array_values($this->fieldmap), 0, (int)$this->prop['sizelimit'], (int)$this->prop['timelimit']); 
     728 
     729            // get all entries of this page and post-filter those that really match the query 
     730            $this->result = new rcube_result_set(0); 
     731            $entries = ldap_get_entries($this->conn, $this->ldap_result); 
     732            for ($i = 0; $i < $entries['count']; $i++) { 
     733                $rec = $this->_ldap2result($entries[$i]); 
     734                if (stripos($rec['name'] . $rec['email'], $value) !== false) { 
     735                    $this->result->add($rec); 
     736                    $this->result->count++; 
     737                } 
     738            } 
     739 
     740            return $this->result; 
    713741        } 
    714742 
     
    12091237     * Set server controls for Virtual List View (paginated listing) 
    12101238     */ 
    1211     private function _vlv_set_controls($prop, $list_page, $page_size) 
     1239    private function _vlv_set_controls($prop, $list_page, $page_size, $search = null) 
    12121240    { 
    12131241        $sort_ctrl = array('oid' => "1.2.840.113556.1.4.473",  'value' => $this->_sort_ber_encode((array)$prop['sort'])); 
    1214         $vlv_ctrl  = array('oid' => "2.16.840.1.113730.3.4.9", 'value' => $this->_vlv_ber_encode(($offset = ($list_page-1) * $page_size + 1), $page_size), 'iscritical' => true); 
     1242        $vlv_ctrl  = array('oid' => "2.16.840.1.113730.3.4.9", 'value' => $this->_vlv_ber_encode(($offset = ($list_page-1) * $page_size + 1), $page_size, $search), 'iscritical' => true); 
    12151243 
    12161244        $sort = (array)$prop['sort']; 
     
    17281756     * @return string BER encoded option value 
    17291757     */ 
    1730     private function _vlv_ber_encode($offset, $rpp) 
     1758    private function _vlv_ber_encode($offset, $rpp, $search = '') 
    17311759    { 
    17321760        # this string is ber-encoded, php will prefix this value with: 
     
    17391767        # 02 = type integer with 2 bytes following (offset): 01 01 (ie 1) 
    17401768        # 02 = type integer with 2 bytes following (contentCount):  01 00 
     1769         
     1770        # whith a search string present: 
     1771        # 81 = type context-specific/constructed with a length of 04 (4) bytes following (the length will change here) 
     1772        # 81 indicates a user string is present where as a a0 indicates just a offset search 
     1773        # 81 = type context-specific/constructed with a length of 06 (6) bytes following 
     1774         
    17411775        # the following info was taken from the ISO/IEC 8825-1:2003 x.690 standard re: the 
    17421776        # encoding of integer values (note: these values are in 
     
    17481782        # a) shall not all be ones; and 
    17491783        # b) shall not all be zero 
    1750  
    1751         # construct the string from right to left 
    1752         $str = "020100"; # contentCount 
    1753  
    1754         $ber_val = self::_ber_encode_int($offset);  // returns encoded integer value in hex format 
    1755  
    1756         // calculate octet length of $ber_val 
    1757         $str = self::_ber_addseq($ber_val, '02') . $str; 
    1758  
    1759         // now compute length over $str 
    1760         $str = self::_ber_addseq($str, 'a0'); 
    1761  
     1784         
     1785        if ($search) 
     1786        { 
     1787            $search = preg_replace('/[^-[:alpha:] ,.()0-9]+/', '', $search); 
     1788            $ber_val = self::_string2hex($search); 
     1789            $str = self::_ber_addseq($ber_val, '81'); 
     1790        } 
     1791        else 
     1792        { 
     1793            # construct the string from right to left 
     1794            $str = "020100"; # contentCount 
     1795 
     1796            $ber_val = self::_ber_encode_int($offset);  // returns encoded integer value in hex format 
     1797 
     1798            // calculate octet length of $ber_val 
     1799            $str = self::_ber_addseq($ber_val, '02') . $str; 
     1800 
     1801            // now compute length over $str 
     1802            $str = self::_ber_addseq($str, 'a0'); 
     1803        } 
     1804         
    17621805        // now tack on records per page 
    17631806        $str = "020100" . self::_ber_addseq(self::_ber_encode_int($rpp-1), '02') . $str; 
Note: See TracChangeset for help on using the changeset viewer.