From 3412e50b54e3daac8745234e21ab6e72be0ed165 Mon Sep 17 00:00:00 2001
From: Thomas Bruederli <thomas@roundcube.net>
Date: Wed, 04 Jun 2014 11:20:33 -0400
Subject: [PATCH] Fix attachment menu structure and aria-attributes
---
program/lib/Roundcube/rcube_ldap_generic.php | 395 ++++++++++++++++++++++++++++++++++++++-----------------
1 files changed, 271 insertions(+), 124 deletions(-)
diff --git a/program/lib/Roundcube/rcube_ldap_generic.php b/program/lib/Roundcube/rcube_ldap_generic.php
index 01d3fa8..f1048ef 100644
--- a/program/lib/Roundcube/rcube_ldap_generic.php
+++ b/program/lib/Roundcube/rcube_ldap_generic.php
@@ -31,12 +31,12 @@
// or
'hosts' => array('directory.verisign.com'),
'port' => 389,
- 'use_tls' => true|false,
+ 'use_tls' => true|false,
'ldap_version' => 3, // using LDAPv3
'auth_method' => '', // SASL authentication method (for proxy auth), e.g. DIGEST-MD5
'attributes' => array('dn'), // List of attributes to read from the server
'vlv' => false, // Enable Virtual List View to more efficiently fetch paginated data (if server supports it)
- 'sort' => array('cn'), // Sort attributes of the VLV index
+ 'config_root_dn' => 'cn=config', // Root DN to read config (e.g. vlv indexes) from
'numsub_filter' => '(objectClass=organizationalUnit)', // with VLV, we also use numSubOrdinates to query the total number of records. Set this filter to get all numSubOrdinates attributes for counting
'sizelimit' => '0', // Enables you to limit the count of entries fetched. Setting this to 0 means no limit.
'timelimit' => '0', // Sets the number of seconds how long is spend on the search. Setting this to 0 means no limit.
@@ -62,6 +62,7 @@
public $vlv_active = false;
/** private properties */
+ protected $cache = null;
protected $config = array();
protected $attributes = array('dn');
protected $entries = null;
@@ -69,15 +70,15 @@
protected $debug = false;
protected $list_page = 1;
protected $page_size = 10;
+ protected $vlv_config = null;
/**
* Object constructor
*
- * @param array $p LDAP connection properties
- * @param boolean $debug Enables debug mode
+ * @param array $p LDAP connection properties
*/
- function __construct($p, $debug = false)
+ function __construct($p)
{
$this->config = $p;
@@ -86,8 +87,6 @@
if (!is_array($p['hosts']) && !empty($p['host']))
$this->config['hosts'] = array($p['host']);
-
- $this->debug = $debug;
}
/**
@@ -114,6 +113,15 @@
$this->config[$opt] = $value;
}
+ /**
+ * Enable caching by passing an instance of rcube_cache to be used by this object
+ *
+ * @param object rcube_cache Instance or False to disable caching
+ */
+ public function set_cache($cache_engine)
+ {
+ $this->cache = $cache_engine;
+ }
/**
* Set properties for VLV-based paging
@@ -126,7 +134,6 @@
$this->list_page = $page;
$this->page_size = $size;
}
-
/**
* Establish a connection to the LDAP server
@@ -153,7 +160,7 @@
$this->config['hosts'] = array($this->config['hosts']);
foreach ($this->config['hosts'] as $host) {
- if ($this->connect($host)) {
+ if (!empty($host) && $this->connect($host)) {
return true;
}
}
@@ -165,7 +172,7 @@
$host = rcube_utils::idn_to_ascii(rcube_utils::parse_host($host));
$hostname = $host . ($this->config['port'] ? ':'.$this->config['port'] : '');
- $this->_debug("C: Connect [$hostname] [{$this->config['name']}]");
+ $this->_debug("C: Connect to $hostname [{$this->config['name']}]");
if ($lc = @ldap_connect($host, $this->config['port'])) {
if ($this->config['use_tls'] === true)
@@ -198,7 +205,6 @@
return true;
}
-
/**
* Bind connection with (SASL-) user and password
@@ -234,7 +240,7 @@
$method = 'DIGEST-MD5';
}
- $this->_debug("C: Bind [mech: $method, authc: $authc, authz: $authz] [pass: $pass]");
+ $this->_debug("C: SASL Bind [mech: $method, authc: $authc, authz: $authz, pass: **** [" . strlen($pass) . "]");
if (ldap_sasl_bind($this->conn, NULL, $pass, $method, NULL, $authc, $authz)) {
$this->_debug("S: OK");
@@ -251,7 +257,6 @@
return false;
}
-
/**
* Bind connection with DN and password
*
@@ -266,7 +271,7 @@
return false;
}
- $this->_debug("C: Bind [dn: $dn] [pass: $pass]");
+ $this->_debug("C: Bind $dn, pass: **** [" . strlen($pass) . "]");
if (@ldap_bind($this->conn, $dn, $pass)) {
$this->_debug("S: OK");
@@ -284,7 +289,6 @@
return false;
}
-
/**
* Close connection to LDAP server
*/
@@ -297,7 +301,6 @@
}
}
-
/**
* Return the last result set
*
@@ -307,7 +310,6 @@
{
return $this->result;
}
-
/**
* Get a specific LDAP entry, identified by its DN
@@ -320,7 +322,7 @@
$rec = null;
if ($this->conn && $dn) {
- $this->_debug("C: Read [dn: $dn] [(objectclass=*)]");
+ $this->_debug("C: Read $dn [(objectclass=*)]");
if ($ldap_result = @ldap_read($this->conn, $dn, '(objectclass=*)', $this->attributes)) {
$this->_debug("S: OK");
@@ -341,7 +343,6 @@
return $rec;
}
-
/**
* Execute the LDAP search based on the stored credentials
*
@@ -350,7 +351,6 @@
* @param string $scope The LDAP scope (list|sub|base)
* @param array $attrs List of entry attributes to read
* @param array $prop Hash array with query configuration properties:
- * - vlv: true if VLV index should be used
* - sort: array of sort attributes (has to be in sync with the VLV index)
* - search: search string used for VLV controls
* @param boolean $count_only Set to true if only entry count is requested
@@ -359,58 +359,70 @@
*/
public function search($base_dn, $filter = '', $scope = 'sub', $attrs = array('dn'), $prop = array(), $count_only = false)
{
- if ($this->conn) {
- if (empty($filter))
- $filter = $filter = '(objectclass=*)';
+ if (!$this->conn) {
+ return false;
+ }
- $this->_debug("C: Search [$filter][dn: $base_dn]");
+ if (empty($filter)) {
+ $filter = '(objectclass=*)';
+ }
- $function = self::scope2func($scope, $ns_function);
+ $this->_debug("C: Search $base_dn for $filter");
+ $function = self::scope2func($scope, $ns_function);
+
+ // find available VLV index for this query
+ if (!$count_only && ($vlv_sort = $this->_find_vlv($base_dn, $filter, $scope, $prop['sort']))) {
// when using VLV, we get the total count by...
- if (!$count_only && $function != 'ldap_read' && $prop['vlv']) { // TODO: auto-detect VLV support for the given query
- // ...either reading numSubOrdinates attribute
- if ($this->config['numsub_filter'] && ($result_count = @$ns_function($this->conn, $base_dn, $this->config['numsub_filter'], array('numSubOrdinates'), 0, 0, 0))) {
- $counts = ldap_get_entries($this->conn, $result_count);
- for ($vlv_count = $j = 0; $j < $counts['count']; $j++)
- $vlv_count += $counts[$j]['numsubordinates'][0];
- $this->_debug("D: total numsubordinates = " . $vlv_count);
- }
- else if (!function_exists('ldap_parse_virtuallist_control')) // ...or by fetching all records dn and count them
- $vlv_count = $this->search($base_dn, $filter, $scope, array('dn'), $prop, true);
-
- $this->vlv_active = $this->_vlv_set_controls($this->config, $this->list_page, $this->page_size, $vlv_search);
- }
- else
- $this->vlv_active = false;
-
- // only fetch dn for count (should keep the payload low)
- if ($ldap_result = $function($this->conn, $base_dn, $filter,
- $attrs, 0, (int)$this->config['sizelimit'], (int)$this->config['timelimit'])
+ // ...either reading numSubOrdinates attribute
+ if (($sub_filter = $this->config['numsub_filter']) &&
+ ($result_count = @$ns_function($this->conn, $base_dn, $sub_filter, array('numSubOrdinates'), 0, 0, 0))
) {
- // when running on a patched PHP we can use the extended functions to retrieve the total count from the LDAP search result
- if ($this->vlv_active && function_exists('ldap_parse_virtuallist_control')) {
- if (ldap_parse_result($this->conn, $ldap_result, $errcode, $matcheddn, $errmsg, $referrals, $serverctrls)) {
- ldap_parse_virtuallist_control($this->conn, $serverctrls, $last_offset, $vlv_count, $vresult);
- $this->_debug("S: VLV result: last_offset=$last_offset; content_count=$vlv_count");
- }
- else {
- $this->_debug("S: ".($errmsg ? $errmsg : ldap_error($this->conn)));
- }
+ $counts = ldap_get_entries($this->conn, $result_count);
+ for ($vlv_count = $j = 0; $j < $counts['count']; $j++)
+ $vlv_count += $counts[$j]['numsubordinates'][0];
+ $this->_debug("D: total numsubordinates = " . $vlv_count);
+ }
+ // ...or by fetching all records dn and count them
+ else if (!function_exists('ldap_parse_virtuallist_control')) {
+ $vlv_count = $this->search($base_dn, $filter, $scope, array('dn'), $prop, true);
+ }
+
+ $this->vlv_active = $this->_vlv_set_controls($vlv_sort, $this->list_page, $this->page_size, $prop['search']);
+ }
+ else {
+ $this->vlv_active = false;
+ }
+
+ // only fetch dn for count (should keep the payload low)
+ if ($ldap_result = @$function($this->conn, $base_dn, $filter,
+ $attrs, 0, (int)$this->config['sizelimit'], (int)$this->config['timelimit'])
+ ) {
+ // when running on a patched PHP we can use the extended functions
+ // to retrieve the total count from the LDAP search result
+ if ($this->vlv_active && function_exists('ldap_parse_virtuallist_control')) {
+ if (ldap_parse_result($this->conn, $ldap_result, $errcode, $matcheddn, $errmsg, $referrals, $serverctrls)) {
+ ldap_parse_virtuallist_control($this->conn, $serverctrls, $last_offset, $vlv_count, $vresult);
+ $this->_debug("S: VLV result: last_offset=$last_offset; content_count=$vlv_count");
}
-
- $this->result = new rcube_ldap_result($this->conn, $ldap_result, $base_dn, $filter, $vlv_count);
-
- return $count_only ? $this->result->count() : $this->result;
+ else {
+ $this->_debug("S: ".($errmsg ? $errmsg : ldap_error($this->conn)));
+ }
}
- else {
- $this->_debug("S: ".ldap_error($this->conn));
+ else if ($this->debug) {
+ $this->_debug("S: ".ldap_count_entries($this->conn, $ldap_result)." record(s) found");
}
+
+ $this->result = new rcube_ldap_result($this->conn, $ldap_result, $base_dn, $filter, $vlv_count);
+
+ return $count_only ? $this->result->count() : $this->result;
+ }
+ else {
+ $this->_debug("S: ".ldap_error($this->conn));
}
return false;
}
-
/**
* Modify an LDAP entry on the server
@@ -433,7 +445,7 @@
*/
public function add($dn, $entry)
{
- $this->_debug("C: Add [dn: $dn]: ".print_r($entry, true));
+ $this->_debug("C: Add $dn: ".print_r($entry, true));
$res = ldap_add($this->conn, $dn, $entry);
if ($res === false) {
@@ -452,7 +464,7 @@
*/
public function delete($dn)
{
- $this->_debug("C: Delete [dn: $dn]");
+ $this->_debug("C: Delete $dn");
$res = ldap_delete($this->conn, $dn);
if ($res === false) {
@@ -471,7 +483,7 @@
*/
public function mod_replace($dn, $entry)
{
- $this->_debug("C: Replace [dn: $dn]: ".print_r($entry, true));
+ $this->_debug("C: Replace $dn: ".print_r($entry, true));
if (!ldap_mod_replace($this->conn, $dn, $entry)) {
$this->_debug("S: ".ldap_error($this->conn));
@@ -489,7 +501,7 @@
*/
public function mod_add($dn, $entry)
{
- $this->_debug("C: Add [dn: $dn]: ".print_r($entry, true));
+ $this->_debug("C: Add $dn: ".print_r($entry, true));
if (!ldap_mod_add($this->conn, $dn, $entry)) {
$this->_debug("S: ".ldap_error($this->conn));
@@ -507,7 +519,7 @@
*/
public function mod_del($dn, $entry)
{
- $this->_debug("C: Delete [dn: $dn]: ".print_r($entry, true));
+ $this->_debug("C: Delete $dn: ".print_r($entry, true));
if (!ldap_mod_del($this->conn, $dn, $entry)) {
$this->_debug("S: ".ldap_error($this->conn));
@@ -525,7 +537,7 @@
*/
public function rename($dn, $newrdn, $newparent = null, $deleteoldrdn = true)
{
- $this->_debug("C: Rename [dn: $dn] [dn: $newrdn]");
+ $this->_debug("C: Rename $dn to $newrdn");
if (!ldap_rename($this->conn, $dn, $newrdn, $newparent, $deleteoldrdn)) {
$this->_debug("S: ".ldap_error($this->conn));
@@ -545,7 +557,7 @@
public function list_entries($dn, $filter, $attributes = array('dn'))
{
$list = array();
- $this->_debug("C: List [dn: $dn] [{$filter}]");
+ $this->_debug("C: List $dn [{$filter}]");
if ($result = ldap_list($this->conn, $dn, $filter, $attributes)) {
$list = ldap_get_entries($this->conn, $result);
@@ -575,7 +587,7 @@
*/
public function read_entries($dn, $filter, $attributes = null)
{
- $this->_debug("C: Read [dn: $dn] [{$filter}]");
+ $this->_debug("C: Read $dn [{$filter}]");
if ($this->conn && $dn) {
if (!$attributes)
@@ -593,7 +605,6 @@
return false;
}
-
/**
* Choose the right PHP function according to scope property
@@ -618,6 +629,21 @@
}
return $function;
+ }
+
+ /**
+ * Convert the given scope integer value to a string representation
+ */
+ public static function scopeint2str($scope)
+ {
+ switch ($scope) {
+ case 2: return 'sub';
+ case 1: return 'one';
+ case 0: return 'base';
+ default: $this->_debug("Scope $scope is not a valid scope integer");
+ }
+
+ return '';
}
/**
@@ -665,16 +691,22 @@
return $entries;
}
-
+
/**
* Turn an LDAP entry into a regular PHP array with attributes as keys.
*
* @param array $entry Attributes array as retrieved from ldap_get_attributes() or ldap_get_entries()
+ *
* @return array Hash array with attributes as keys
*/
public static function normalize_entry($entry)
{
+ if (!isset($entry['count'])) {
+ return $entry;
+ }
+
$rec = array();
+
for ($i=0; $i < $entry['count']; $i++) {
$attr = $entry[$i];
if ($entry[$attr]['count'] == 1) {
@@ -700,14 +732,13 @@
/**
* Set server controls for Virtual List View (paginated listing)
*/
- private function _vlv_set_controls($prop, $list_page, $page_size, $search = null)
+ private function _vlv_set_controls($sort, $list_page, $page_size, $search = null)
{
- $sort_ctrl = array('oid' => "1.2.840.113556.1.4.473", 'value' => self::_sort_ber_encode((array)$prop['sort']));
+ $sort_ctrl = array('oid' => "1.2.840.113556.1.4.473", 'value' => self::_sort_ber_encode((array)$sort));
$vlv_ctrl = array('oid' => "2.16.840.1.113730.3.4.9", 'value' => self::_vlv_ber_encode(($offset = ($list_page-1) * $page_size + 1), $page_size, $search), 'iscritical' => true);
- $sort = (array)$prop['sort'];
- $this->_debug("C: set controls sort=" . join(' ', unpack('H'.(strlen($sort_ctrl['value'])*2), $sort_ctrl['value'])) . " ($sort[0]);"
- . " vlv=" . join(' ', (unpack('H'.(strlen($vlv_ctrl['value'])*2), $vlv_ctrl['value']))) . " ($offset/$page_size)");
+ $this->_debug("C: Set controls sort=" . join(' ', unpack('H'.(strlen($sort_ctrl['value'])*2), $sort_ctrl['value'])) . " ($sort[0]);"
+ . " vlv=" . join(' ', (unpack('H'.(strlen($vlv_ctrl['value'])*2), $vlv_ctrl['value']))) . " ($offset/$page_size; $search)");
if (!ldap_set_option($this->conn, LDAP_OPT_SERVER_CONTROLS, array($sort_ctrl, $vlv_ctrl))) {
$this->_debug("S: ".ldap_error($this->conn));
@@ -717,7 +748,6 @@
return true;
}
-
/**
* Returns unified attribute name (resolving aliases)
@@ -739,18 +769,6 @@
return (isset($aliases[$name]) ? $aliases[$name] : $name) . $suffix;
}
-
- /**
- * Prints debug info to the log
- */
- private function _debug($str)
- {
- if ($this->debug && class_exists('rcube')) {
- rcube::write_log('ldap', $str);
- }
- }
-
-
/**
* Quotes attribute value string
*
@@ -759,7 +777,7 @@
*
* @return string Quoted string
*/
- private static function _quote_string($str, $dn=false)
+ public static function quote_string($str, $dn=false)
{
// take firt entry if array given
if (is_array($str))
@@ -775,50 +793,179 @@
return strtr($str, $replace);
}
+ /**
+ * Prints debug info to the log
+ */
+ private function _debug($str)
+ {
+ if ($this->debug && class_exists('rcube')) {
+ rcube::write_log('ldap', $str);
+ }
+ }
+
+
+ /***************** Virtual List View (VLV) related utility functions **************** */
+
+ /**
+ * Return the search string value to be used in VLV controls
+ */
+ private function _vlv_search($sort, $search)
+ {
+ foreach ($search as $attr => $value) {
+ if (!in_array(strtolower($attr), $sort)) {
+ $this->_debug("d: Cannot use VLV search using attribute not indexed: $attr (not in " . var_export($sort, true) . ")");
+ return null;
+ } else {
+ return $value;
+ }
+ }
+ }
+
+ /**
+ * Find a VLV index matching the given query attributes
+ *
+ * @return string Sort attribute or False if no match
+ */
+ private function _find_vlv($base_dn, $filter, $scope, $sort_attrs = null)
+ {
+ if (!$this->config['vlv'] || $scope == 'base') {
+ return false;
+ }
+
+ // get vlv config
+ $vlv_config = $this->_read_vlv_config();
+
+ if ($vlv = $vlv_config[$base_dn]) {
+ $this->_debug("D: Found a VLV for $base_dn");
+
+ if ($vlv['filter'] == strtolower($filter) || stripos($filter, '(&'.$vlv['filter'].'(') === 0) {
+ $this->_debug("D: Filter matches");
+ if ($vlv['scope'] == $scope) {
+ // Not passing any sort attributes means you don't care
+ if (empty($sort_attrs) || in_array($sort_attrs, $vlv['sort'])) {
+ return $vlv['sort'][0];
+ }
+ }
+ else {
+ $this->_debug("D: Scope does not match");
+ }
+ }
+ else {
+ $this->_debug("D: Filter does not match");
+ }
+ }
+ else {
+ $this->_debug("D: No VLV for $base_dn");
+ }
+
+ return false;
+ }
+
+ /**
+ * Return VLV indexes and searches including necessary configuration
+ * details.
+ */
+ private function _read_vlv_config()
+ {
+ if (empty($this->config['vlv']) || empty($this->config['config_root_dn'])) {
+ return array();
+ }
+ // return hard-coded VLV config
+ else if (is_array($this->config['vlv'])) {
+ return $this->config['vlv'];
+ }
+
+ // return cached result
+ if (is_array($this->vlv_config)) {
+ return $this->vlv_config;
+ }
+
+ if ($this->cache && ($cached_config = $this->cache->get('vlvconfig'))) {
+ $this->vlv_config = $cached_config;
+ return $this->vlv_config;
+ }
+
+ $this->vlv_config = array();
+
+ $ldap_result = ldap_search($this->conn, $this->config['config_root_dn'], '(objectclass=vlvsearch)', array('*'), 0, 0, 0);
+ $vlv_searches = new rcube_ldap_result($this->conn, $ldap_result, $this->config['config_root_dn'], '(objectclass=vlvsearch)');
+
+ if ($vlv_searches->count() < 1) {
+ $this->_debug("D: Empty result from search for '(objectclass=vlvsearch)' on '$config_root_dn'");
+ return array();
+ }
+
+ foreach ($vlv_searches->entries(true) as $vlv_search_dn => $vlv_search_attrs) {
+ // Multiple indexes may exist
+ $ldap_result = ldap_search($this->conn, $vlv_search_dn, '(objectclass=vlvindex)', array('*'), 0, 0, 0);
+ $vlv_indexes = new rcube_ldap_result($this->conn, $ldap_result, $vlv_search_dn, '(objectclass=vlvindex)');
+
+ // Reset this one for each VLV search.
+ $_vlv_sort = array();
+ foreach ($vlv_indexes->entries(true) as $vlv_index_dn => $vlv_index_attrs) {
+ $_vlv_sort[] = explode(' ', $vlv_index_attrs['vlvsort']);
+ }
+
+ $this->vlv_config[$vlv_search_attrs['vlvbase']] = array(
+ 'scope' => self::scopeint2str($vlv_search_attrs['vlvscope']),
+ 'filter' => strtolower($vlv_search_attrs['vlvfilter']),
+ 'sort' => $_vlv_sort,
+ );
+ }
+
+ // cache this
+ if ($this->cache)
+ $this->cache->set('vlvconfig', $this->vlv_config);
+
+ $this->_debug("D: Refreshed VLV config: " . var_export($this->vlv_config, true));
+
+ return $this->vlv_config;
+ }
/**
* Generate BER encoded string for Virtual List View option
*
* @param integer List offset (first record)
* @param integer Records per page
+ *
* @return string BER encoded option value
*/
private static function _vlv_ber_encode($offset, $rpp, $search = '')
{
- # this string is ber-encoded, php will prefix this value with:
- # 04 (octet string) and 10 (length of 16 bytes)
- # the code behind this string is broken down as follows:
- # 30 = ber sequence with a length of 0e (14) bytes following
- # 02 = type integer (in two's complement form) with 2 bytes following (beforeCount): 01 00 (ie 0)
- # 02 = type integer (in two's complement form) with 2 bytes following (afterCount): 01 18 (ie 25-1=24)
- # a0 = type context-specific/constructed with a length of 06 (6) bytes following
- # 02 = type integer with 2 bytes following (offset): 01 01 (ie 1)
- # 02 = type integer with 2 bytes following (contentCount): 01 00
-
- # whith a search string present:
- # 81 = type context-specific/constructed with a length of 04 (4) bytes following (the length will change here)
- # 81 indicates a user string is present where as a a0 indicates just a offset search
- # 81 = type context-specific/constructed with a length of 06 (6) bytes following
-
- # the following info was taken from the ISO/IEC 8825-1:2003 x.690 standard re: the
- # encoding of integer values (note: these values are in
- # two-complement form so since offset will never be negative bit 8 of the
- # leftmost octet should never by set to 1):
- # 8.3.2: If the contents octets of an integer value encoding consist
- # of more than one octet, then the bits of the first octet (rightmost) and bit 8
- # of the second (to the left of first octet) octet:
- # a) shall not all be ones; and
- # b) shall not all be zero
-
- if ($search)
- {
+ /*
+ this string is ber-encoded, php will prefix this value with:
+ 04 (octet string) and 10 (length of 16 bytes)
+ the code behind this string is broken down as follows:
+ 30 = ber sequence with a length of 0e (14) bytes following
+ 02 = type integer (in two's complement form) with 2 bytes following (beforeCount): 01 00 (ie 0)
+ 02 = type integer (in two's complement form) with 2 bytes following (afterCount): 01 18 (ie 25-1=24)
+ a0 = type context-specific/constructed with a length of 06 (6) bytes following
+ 02 = type integer with 2 bytes following (offset): 01 01 (ie 1)
+ 02 = type integer with 2 bytes following (contentCount): 01 00
+
+ with a search string present:
+ 81 = type context-specific/constructed with a length of 04 (4) bytes following (the length will change here)
+ 81 indicates a user string is present where as a a0 indicates just a offset search
+ 81 = type context-specific/constructed with a length of 06 (6) bytes following
+
+ The following info was taken from the ISO/IEC 8825-1:2003 x.690 standard re: the
+ encoding of integer values (note: these values are in
+ two-complement form so since offset will never be negative bit 8 of the
+ leftmost octet should never by set to 1):
+ 8.3.2: If the contents octets of an integer value encoding consist
+ of more than one octet, then the bits of the first octet (rightmost)
+ and bit 8 of the second (to the left of first octet) octet:
+ a) shall not all be ones; and
+ b) shall not all be zero
+ */
+
+ if ($search) {
$search = preg_replace('/[^-[:alpha:] ,.()0-9]+/', '', $search);
$ber_val = self::_string2hex($search);
$str = self::_ber_addseq($ber_val, '81');
}
- else
- {
- # construct the string from right to left
+ else {
+ // construct the string from right to left
$str = "020100"; # contentCount
$ber_val = self::_ber_encode_int($offset); // returns encoded integer value in hex format
@@ -829,7 +976,7 @@
// now compute length over $str
$str = self::_ber_addseq($str, 'a0');
}
-
+
// now tack on records per page
$str = "020100" . self::_ber_addseq(self::_ber_encode_int($rpp-1), '02') . $str;
@@ -838,7 +985,6 @@
return pack('H'.strlen($str), $str);
}
-
/**
* create ber encoding for sort control
@@ -852,8 +998,8 @@
foreach (array_reverse((array)$sortcols) as $col) {
$ber_val = self::_string2hex($col);
- # 30 = ber sequence with a length of octet value
- # 04 = octet string with a length of the ascii value
+ // 30 = ber sequence with a length of octet value
+ // 04 = octet string with a length of the ascii value
$oct = self::_ber_addseq($ber_val, '04');
$str = self::_ber_addseq($oct, '30') . $str;
}
@@ -900,8 +1046,9 @@
private static function _string2hex($str)
{
$hex = '';
- for ($i=0; $i < strlen($str); $i++)
+ for ($i=0; $i < strlen($str); $i++) {
$hex .= dechex(ord($str[$i]));
+ }
return $hex;
}
--
Gitblit v1.9.1