6 commits - config/main.inc.php.dist lib/ext lib/kolab_sync.php lib/kolab_sync_timezone_converter.php
Aleksander Machniak
machniak at kolabsys.com
Sun May 26 12:37:44 CEST 2013
config/main.inc.php.dist | 13
lib/ext/Roundcube/html.php | 5
lib/ext/Roundcube/rcube.php | 36 ++
lib/ext/Roundcube/rcube_cache.php | 2
lib/ext/Roundcube/rcube_cache_shared.php | 544 +++++++++++++++++++++++++++++++
lib/ext/Roundcube/rcube_db_mysql.php | 7
lib/ext/Roundcube/rcube_imap.php | 3
lib/ext/Roundcube/rcube_message.php | 2
lib/ext/Roundcube/rcube_mime.php | 6
lib/ext/Roundcube/rcube_washtml.php | 33 +
lib/ext/Syncroton/Server.php | 3
lib/kolab_sync.php | 36 +-
lib/kolab_sync_timezone_converter.php | 11
13 files changed, 671 insertions(+), 30 deletions(-)
New commits:
commit 0e422607196ab68c12e7ef011f73a6bc254ea7a5
Author: Aleksander Machniak <alec at alec.pl>
Date: Sun May 26 12:23:23 2013 +0200
Cache also 'valid' flag of authenticate hook result
diff --git a/lib/kolab_sync.php b/lib/kolab_sync.php
index f02f2e4..0aacfa9 100644
--- a/lib/kolab_sync.php
+++ b/lib/kolab_sync.php
@@ -185,12 +185,15 @@ class kolab_sync extends rcube
));
if ($cache) {
- $cache->set($cache_key, array('user' => $auth['user'], 'host' => $auth['host']));
+ $cache->set($cache_key, array(
+ 'user' => $auth['user'],
+ 'host' => $auth['host'],
+ 'valid' => $auth['valid'],
+ ));
}
}
else {
$auth['pass'] = $password;
- $auth['valid'] = true;
}
// Authenticate - get Roundcube user ID
commit e7e4643853d6dc0ecc49ff7d59849a1609a5449e
Author: Aleksander Machniak <alec at alec.pl>
Date: Sun May 26 12:17:23 2013 +0200
Implemented shared cache for username canonification (#1886)
diff --git a/config/main.inc.php.dist b/config/main.inc.php.dist
index 4581508..d1e8f5d 100644
--- a/config/main.inc.php.dist
+++ b/config/main.inc.php.dist
@@ -20,6 +20,14 @@ $rcmail_config['activesync_cache'] = 'db';
// possible units: s, m, h, d, w
$rcmail_config['activesync_cache_ttl'] = '1d';
+// Type of ActiveSync Auth cache. Supported values: 'db', 'apc' and 'memcache'.
+// Note: This is only for username canonification map.
+$rcmail_config['activesync_cache_auth'] = 'db';
+
+// lifetime of ActiveSync Auth cache
+// possible units: s, m, h, d, w
+$rcmail_config['activesync_cache_auth_ttl'] = '1d';
+
// List of global addressbooks (GAL)
// Note: If empty 'autocomplete_addressbooks' setting will be used
$rcmail_config['activesync_addressbooks'] = array();
diff --git a/lib/ext/Roundcube/rcube_cache_shared.php b/lib/ext/Roundcube/rcube_cache_shared.php
index c43d2ca..5983bd3 100644
--- a/lib/ext/Roundcube/rcube_cache_shared.php
+++ b/lib/ext/Roundcube/rcube_cache_shared.php
@@ -27,7 +27,7 @@
* @author Thomas Bruederli <roundcube at gmail.com>
* @author Aleksander Machniak <alec at alec.pl>
*/
-class rcube_cache
+class rcube_cache_shared
{
/**
* Instance of database handler
diff --git a/lib/kolab_sync.php b/lib/kolab_sync.php
index 859d578..f02f2e4 100644
--- a/lib/kolab_sync.php
+++ b/lib/kolab_sync.php
@@ -172,16 +172,31 @@ class kolab_sync extends rcube
*/
public function authenticate($username, $password)
{
- $auth = $this->plugins->exec_hook('authenticate', array(
- 'host' => $this->select_host($username),
- 'user' => $username,
- 'pass' => $password,
- 'valid' => true,
- ));
+ // use shared cache for kolab_auth plugin result (username canonification)
+ $cache = $this->get_cache_shared('activesync_auth');
+ $cache_key = md5($username . '::' . $password);
+
+ if (!$cache || !($auth = $cache->get($cache_key))) {
+ $auth = $this->plugins->exec_hook('authenticate', array(
+ 'host' => $this->select_host($username),
+ 'user' => $username,
+ 'pass' => $password,
+ 'valid' => true,
+ ));
+
+ if ($cache) {
+ $cache->set($cache_key, array('user' => $auth['user'], 'host' => $auth['host']));
+ }
+ }
+ else {
+ $auth['pass'] = $password;
+ $auth['valid'] = true;
+ }
// Authenticate - get Roundcube user ID
if ($auth['valid'] && !$auth['abort']
- && ($userid = $this->login($auth['user'], $auth['pass'], $auth['host']))) {
+ && ($userid = $this->login($auth['user'], $auth['pass'], $auth['host']))
+ ) {
return $userid;
}
commit 6da4223eaf79758626c4cef065c68c5185523a6c
Author: Aleksander Machniak <alec at alec.pl>
Date: Sun May 26 11:26:04 2013 +0200
Don't require kolab_folders plugin
diff --git a/lib/kolab_sync.php b/lib/kolab_sync.php
index c9ccdc9..859d578 100644
--- a/lib/kolab_sync.php
+++ b/lib/kolab_sync.php
@@ -75,8 +75,8 @@ class kolab_sync extends rcube
// WARNING: We can use only plugins that are prepared for this
// e.g. are not using output or rcmail objects or
// doesn't throw errors when using them
- $plugins = (array)$this->config->get('activesync_plugins', array('kolab_auth', 'kolab_folders'));
- $required = array('libkolab', 'kolab_folders');
+ $plugins = (array)$this->config->get('activesync_plugins', array('kolab_auth'));
+ $required = array('libkolab');
// Initialize/load plugins
$this->plugins = kolab_sync_plugin_api::get_instance();
commit 2ee7f0d32882c2e5e3b06b70c4e7185d666dd3df
Author: Aleksander Machniak <alec at alec.pl>
Date: Sun May 26 11:22:43 2013 +0200
Use shared cache for timezone mapping
diff --git a/config/main.inc.php.dist b/config/main.inc.php.dist
index 513700c..4581508 100644
--- a/config/main.inc.php.dist
+++ b/config/main.inc.php.dist
@@ -14,12 +14,11 @@ $rcmail_config['activesync_log_file'] = null;
// Type of ActiveSync cache. Supported values: 'db', 'apc' and 'memcache'.
// Note: This is only for some additional data like timezones mapping.
-// Main ActiveSync cache uses Roundcube SQL database
-$rcmail_config['activesync_cache'] = null;
+$rcmail_config['activesync_cache'] = 'db';
// lifetime of ActiveSync cache
// possible units: s, m, h, d, w
-$rcmail_config['activesync_cache_lifetime'] = '10d';
+$rcmail_config['activesync_cache_ttl'] = '1d';
// List of global addressbooks (GAL)
// Note: If empty 'autocomplete_addressbooks' setting will be used
diff --git a/lib/ext/Roundcube/rcube.php b/lib/ext/Roundcube/rcube.php
index 78d7959..4471ace 100644
--- a/lib/ext/Roundcube/rcube.php
+++ b/lib/ext/Roundcube/rcube.php
@@ -269,16 +269,18 @@ class rcube
{
$shared_name = "shared_$name";
- if (!isset($this->caches[$shared_name])) {
+ if (!array_key_exists($shared_name, $this->caches)) {
$opt = strtolower($name) . '_cache';
$type = $this->config->get($opt);
$ttl = $this->config->get($opt . '_ttl');
if (!$type) {
- $type = $this->config->get('shared_cache');
+ // cache is disabled
+ return $this->caches[$shared_name] = null;
}
+
if ($ttl === null) {
- $ttl = $this->config->get('shared_cache_ttl');
+ $ttl = $this->config->get('shared_cache_ttl', '10d');
}
$this->caches[$shared_name] = new rcube_cache_shared($type, $name, $ttl, $packed);
diff --git a/lib/kolab_sync_timezone_converter.php b/lib/kolab_sync_timezone_converter.php
index 2915eb1..5bdc726 100644
--- a/lib/kolab_sync_timezone_converter.php
+++ b/lib/kolab_sync_timezone_converter.php
@@ -620,17 +620,10 @@ class kolab_sync_timezone_converter
{
if ($this->cache === null) {
$rcube = rcube::get_instance();
-
- if ($cache = $rcube->config->get('activesync_cache')) {
- $ttl = $rcube->config->get('activesync_cache_lifetime', '10d');
- $this->cache = $rcube->get_cache('ACTIVESYNC', $cache, $ttl);
- }
- else {
- $this->cache = false;
- }
+ $cache = $rcube->get_cache_shared('activesync');
+ $this->cache = $cache ? $cache : false;
}
return $this->cache;
}
-
}
commit c6893113d94b0d324ce3d28e34b9a879489640f6
Author: Aleksander Machniak <alec at alec.pl>
Date: Sun May 26 10:49:20 2013 +0200
Update Roundcube Framework
diff --git a/lib/ext/Roundcube/html.php b/lib/ext/Roundcube/html.php
index 830ada9..eb23c8b 100644
--- a/lib/ext/Roundcube/html.php
+++ b/lib/ext/Roundcube/html.php
@@ -784,6 +784,11 @@ class html_table extends html
$index = $this->rowindex;
}
+ // make sure row object exists (#1489094)
+ if (!$this->rows[$index]) {
+ $this->rows[$index] = new stdClass;
+ }
+
$this->rows[$index]->attrib = $attr;
}
diff --git a/lib/ext/Roundcube/rcube.php b/lib/ext/Roundcube/rcube.php
index eea2fde..78d7959 100644
--- a/lib/ext/Roundcube/rcube.php
+++ b/lib/ext/Roundcube/rcube.php
@@ -258,6 +258,37 @@ class rcube
/**
+ * Initialize and get shared cache object
+ *
+ * @param string $name Cache identifier
+ * @param bool $packed Enables/disables data serialization
+ *
+ * @return rcube_cache_shared Cache object
+ */
+ public function get_cache_shared($name, $packed=true)
+ {
+ $shared_name = "shared_$name";
+
+ if (!isset($this->caches[$shared_name])) {
+ $opt = strtolower($name) . '_cache';
+ $type = $this->config->get($opt);
+ $ttl = $this->config->get($opt . '_ttl');
+
+ if (!$type) {
+ $type = $this->config->get('shared_cache');
+ }
+ if ($ttl === null) {
+ $ttl = $this->config->get('shared_cache_ttl');
+ }
+
+ $this->caches[$shared_name] = new rcube_cache_shared($type, $name, $ttl, $packed);
+ }
+
+ return $this->caches[$shared_name];
+ }
+
+
+ /**
* Create SMTP object and connect to server
*
* @param boolean True if connection should be established
@@ -866,6 +897,9 @@ class rcube
foreach ($this->caches as $cache) {
if (is_object($cache)) {
+ if ($this->expunge_cache) {
+ $cache->expunge();
+ }
$cache->close();
}
}
diff --git a/lib/ext/Roundcube/rcube_cache.php b/lib/ext/Roundcube/rcube_cache.php
index 92f12a8..129f324 100644
--- a/lib/ext/Roundcube/rcube_cache.php
+++ b/lib/ext/Roundcube/rcube_cache.php
@@ -192,7 +192,7 @@ class rcube_cache
*/
function expunge()
{
- if ($this->type == 'db' && $this->db) {
+ if ($this->type == 'db' && $this->db && $this->ttl) {
$this->db->query(
"DELETE FROM ".$this->db->table_name('cache').
" WHERE user_id = ?".
diff --git a/lib/ext/Roundcube/rcube_cache_shared.php b/lib/ext/Roundcube/rcube_cache_shared.php
new file mode 100644
index 0000000..c43d2ca
--- /dev/null
+++ b/lib/ext/Roundcube/rcube_cache_shared.php
@@ -0,0 +1,544 @@
+<?php
+
+/*
+ +-----------------------------------------------------------------------+
+ | This file is part of the Roundcube Webmail client |
+ | Copyright (C) 2011-2013, The Roundcube Dev Team |
+ | Copyright (C) 2011-2013, Kolab Systems AG |
+ | |
+ | Licensed under the GNU General Public License version 3 or |
+ | any later version with exceptions for skins & plugins. |
+ | See the README file for a full license statement. |
+ | |
+ | PURPOSE: |
+ | Shared (cross-user) caching engine |
+ +-----------------------------------------------------------------------+
+ | Author: Thomas Bruederli <roundcube at gmail.com> |
+ | Author: Aleksander Machniak <alec at alec.pl> |
+ +-----------------------------------------------------------------------+
+*/
+
+
+/**
+ * Interface class for accessing Roundcube shared cache
+ *
+ * @package Framework
+ * @subpackage Cache
+ * @author Thomas Bruederli <roundcube at gmail.com>
+ * @author Aleksander Machniak <alec at alec.pl>
+ */
+class rcube_cache
+{
+ /**
+ * Instance of database handler
+ *
+ * @var rcube_db|Memcache|bool
+ */
+ private $db;
+ private $type;
+ private $prefix;
+ private $ttl;
+ private $packed;
+ private $index;
+ private $table;
+ private $cache = array();
+ private $cache_changes = array();
+ private $cache_sums = array();
+
+
+ /**
+ * Object constructor.
+ *
+ * @param string $type Engine type ('db' or 'memcache' or 'apc')
+ * @param string $prefix Key name prefix
+ * @param string $ttl Expiration time of memcache/apc items
+ * @param bool $packed Enables/disabled data serialization.
+ * It's possible to disable data serialization if you're sure
+ * stored data will be always a safe string
+ */
+ function __construct($type, $prefix='', $ttl=0, $packed=true)
+ {
+ $rcube = rcube::get_instance();
+ $type = strtolower($type);
+
+ if ($type == 'memcache') {
+ $this->type = 'memcache';
+ $this->db = $rcube->get_memcache();
+ }
+ else if ($type == 'apc') {
+ $this->type = 'apc';
+ $this->db = function_exists('apc_exists'); // APC 3.1.4 required
+ }
+ else {
+ $this->type = 'db';
+ $this->db = $rcube->get_dbh();
+ $this->table = $this->db->table_name('cache_shared');
+ }
+
+ // convert ttl string to seconds
+ $ttl = get_offset_sec($ttl);
+ if ($ttl > 2592000) $ttl = 2592000;
+
+ $this->ttl = $ttl;
+ $this->packed = $packed;
+ $this->prefix = $prefix;
+ }
+
+
+ /**
+ * Returns cached value.
+ *
+ * @param string $key Cache key name
+ *
+ * @return mixed Cached value
+ */
+ function get($key)
+ {
+ if (!array_key_exists($key, $this->cache)) {
+ return $this->read_record($key);
+ }
+
+ return $this->cache[$key];
+ }
+
+
+ /**
+ * Sets (add/update) value in cache.
+ *
+ * @param string $key Cache key name
+ * @param mixed $data Cache data
+ */
+ function set($key, $data)
+ {
+ $this->cache[$key] = $data;
+ $this->cache_changed = true;
+ $this->cache_changes[$key] = true;
+ }
+
+
+ /**
+ * Returns cached value without storing it in internal memory.
+ *
+ * @param string $key Cache key name
+ *
+ * @return mixed Cached value
+ */
+ function read($key)
+ {
+ if (array_key_exists($key, $this->cache)) {
+ return $this->cache[$key];
+ }
+
+ return $this->read_record($key, true);
+ }
+
+
+ /**
+ * Sets (add/update) value in cache and immediately saves
+ * it in the backend, no internal memory will be used.
+ *
+ * @param string $key Cache key name
+ * @param mixed $data Cache data
+ *
+ * @param boolean True on success, False on failure
+ */
+ function write($key, $data)
+ {
+ return $this->write_record($key, $this->packed ? serialize($data) : $data);
+ }
+
+
+ /**
+ * Clears the cache.
+ *
+ * @param string $key Cache key name or pattern
+ * @param boolean $prefix_mode Enable it to clear all keys starting
+ * with prefix specified in $key
+ */
+ function remove($key=null, $prefix_mode=false)
+ {
+ // Remove all keys
+ if ($key === null) {
+ $this->cache = array();
+ $this->cache_changed = false;
+ $this->cache_changes = array();
+ $this->cache_sums = array();
+ }
+ // Remove keys by name prefix
+ else if ($prefix_mode) {
+ foreach (array_keys($this->cache) as $k) {
+ if (strpos($k, $key) === 0) {
+ $this->cache[$k] = null;
+ $this->cache_changes[$k] = false;
+ unset($this->cache_sums[$k]);
+ }
+ }
+ }
+ // Remove one key by name
+ else {
+ $this->cache[$key] = null;
+ $this->cache_changes[$key] = false;
+ unset($this->cache_sums[$key]);
+ }
+
+ // Remove record(s) from the backend
+ $this->remove_record($key, $prefix_mode);
+ }
+
+
+ /**
+ * Remove cache records older than ttl
+ */
+ function expunge()
+ {
+ if ($this->type == 'db' && $this->db && $this->ttl) {
+ $this->db->query(
+ "DELETE FROM " . $this->table
+ . " WHERE cache_key LIKE ?"
+ . " AND " . $this->db->unixtimestamp('created') . " < ?",
+ $this->prefix . '.%',
+ time() - $this->ttl);
+ }
+ }
+
+
+ /**
+ * Writes the cache back to the DB.
+ */
+ function close()
+ {
+ if (!$this->cache_changed) {
+ return;
+ }
+
+ foreach ($this->cache as $key => $data) {
+ // The key has been used
+ if ($this->cache_changes[$key]) {
+ // Make sure we're not going to write unchanged data
+ // by comparing current md5 sum with the sum calculated on DB read
+ $data = $this->packed ? serialize($data) : $data;
+
+ if (!$this->cache_sums[$key] || $this->cache_sums[$key] != md5($data)) {
+ $this->write_record($key, $data);
+ }
+ }
+ }
+
+ $this->write_index();
+ }
+
+
+ /**
+ * Reads cache entry.
+ *
+ * @param string $key Cache key name
+ * @param boolean $nostore Enable to skip in-memory store
+ *
+ * @return mixed Cached value
+ */
+ private function read_record($key, $nostore=false)
+ {
+ if (!$this->db) {
+ return null;
+ }
+
+ if ($this->type != 'db') {
+ if ($this->type == 'memcache') {
+ $data = $this->db->get($this->ckey($key));
+ }
+ else if ($this->type == 'apc') {
+ $data = apc_fetch($this->ckey($key));
+ }
+
+ if ($data) {
+ $md5sum = md5($data);
+ $data = $this->packed ? unserialize($data) : $data;
+
+ if ($nostore) {
+ return $data;
+ }
+
+ $this->cache_sums[$key] = $md5sum;
+ $this->cache[$key] = $data;
+ }
+ else {
+ $this->cache[$key] = null;
+ }
+ }
+ else {
+ $sql_result = $this->db->limitquery(
+ "SELECT data, cache_key".
+ " FROM " . $this->table .
+ " WHERE cache_key = ?".
+ // for better performance we allow more records for one key
+ // get the newer one
+ " ORDER BY created DESC",
+ 0, 1, $this->prefix . '.' . $key);
+
+ if ($sql_arr = $this->db->fetch_assoc($sql_result)) {
+ $md5sum = $sql_arr['data'] ? md5($sql_arr['data']) : null;
+ if ($sql_arr['data']) {
+ $data = $this->packed ? unserialize($sql_arr['data']) : $sql_arr['data'];
+ }
+
+ if ($nostore) {
+ return $data;
+ }
+
+ $this->cache[$key] = $data;
+ $this->cache_sums[$key] = $md5sum;
+ }
+ else {
+ $this->cache[$key] = null;
+ }
+ }
+
+ return $this->cache[$key];
+ }
+
+
+ /**
+ * Writes single cache record into DB.
+ *
+ * @param string $key Cache key name
+ * @param mxied $data Serialized cache data
+ *
+ * @param boolean True on success, False on failure
+ */
+ private function write_record($key, $data)
+ {
+ if (!$this->db) {
+ return false;
+ }
+
+ if ($this->type == 'memcache' || $this->type == 'apc') {
+ return $this->add_record($this->ckey($key), $data);
+ }
+
+ $key_exists = array_key_exists($key, $this->cache_sums);
+ $key = $this->prefix . '.' . $key;
+
+ // Remove NULL rows (here we don't need to check if the record exist)
+ if ($data == 'N;') {
+ $this->db->query("DELETE FROM " . $this->table . " WHERE cache_key = ?", $key);
+ return true;
+ }
+
+ // update existing cache record
+ if ($key_exists) {
+ $result = $this->db->query(
+ "UPDATE " . $this->table .
+ " SET created = " . $this->db->now() . ", data = ?" .
+ " WHERE cache_key = ?",
+ $data, $key);
+ }
+ // add new cache record
+ else {
+ // for better performance we allow more records for one key
+ // so, no need to check if record exist (see rcube_cache::read_record())
+ $result = $this->db->query(
+ "INSERT INTO ".$this->table.
+ " (created, cache_key, data)".
+ " VALUES (".$this->db->now().", ?, ?)",
+ $key, $data);
+ }
+
+ return $this->db->affected_rows($result);
+ }
+
+
+ /**
+ * Deletes the cache record(s).
+ *
+ * @param string $key Cache key name or pattern
+ * @param boolean $prefix_mode Enable it to clear all keys starting
+ * with prefix specified in $key
+ */
+ private function remove_record($key=null, $prefix_mode=false)
+ {
+ if (!$this->db) {
+ return;
+ }
+
+ if ($this->type != 'db') {
+ $this->load_index();
+
+ // Remove all keys
+ if ($key === null) {
+ foreach ($this->index as $key) {
+ $this->delete_record($key, false);
+ }
+ $this->index = array();
+ }
+ // Remove keys by name prefix
+ else if ($prefix_mode) {
+ foreach ($this->index as $k) {
+ if (strpos($k, $key) === 0) {
+ $this->delete_record($k);
+ }
+ }
+ }
+ // Remove one key by name
+ else {
+ $this->delete_record($key);
+ }
+
+ return;
+ }
+
+ // Remove all keys (in specified cache)
+ if ($key === null) {
+ $where = " WHERE cache_key LIKE " . $this->db->quote($this->prefix.'.%');
+ }
+ // Remove keys by name prefix
+ else if ($prefix_mode) {
+ $where = " WHERE cache_key LIKE " . $this->db->quote($this->prefix.'.'.$key.'%');
+ }
+ // Remove one key by name
+ else {
+ $where = " WHERE cache_key = " . $this->db->quote($this->prefix.'.'.$key);
+ }
+
+ $this->db->query("DELETE FROM " . $this->table . $where);
+ }
+
+
+ /**
+ * Adds entry into memcache/apc DB.
+ *
+ * @param string $key Cache key name
+ * @param mxied $data Serialized cache data
+ * @param bollean $index Enables immediate index update
+ *
+ * @param boolean True on success, False on failure
+ */
+ private function add_record($key, $data, $index=false)
+ {
+ if ($this->type == 'memcache') {
+ $result = $this->db->replace($key, $data, MEMCACHE_COMPRESSED, $this->ttl);
+ if (!$result) {
+ $result = $this->db->set($key, $data, MEMCACHE_COMPRESSED, $this->ttl);
+ }
+ }
+ else if ($this->type == 'apc') {
+ if (apc_exists($key)) {
+ apc_delete($key);
+ }
+ $result = apc_store($key, $data, $this->ttl);
+ }
+
+ // Update index
+ if ($index && $result) {
+ $this->load_index();
+
+ if (array_search($key, $this->index) === false) {
+ $this->index[] = $key;
+ $data = serialize($this->index);
+ $this->add_record($this->ikey(), $data);
+ }
+ }
+
+ return $result;
+ }
+
+
+ /**
+ * Deletes entry from memcache/apc DB.
+ */
+ private function delete_record($key, $index=true)
+ {
+ if ($this->type == 'memcache') {
+ // #1488592: use 2nd argument
+ $this->db->delete($this->ckey($key), 0);
+ }
+ else {
+ apc_delete($this->ckey($key));
+ }
+
+ if ($index) {
+ if (($idx = array_search($key, $this->index)) !== false) {
+ unset($this->index[$idx]);
+ }
+ }
+ }
+
+
+ /**
+ * Writes the index entry into memcache/apc DB.
+ */
+ private function write_index()
+ {
+ if (!$this->db) {
+ return;
+ }
+
+ if ($this->type == 'db') {
+ return;
+ }
+
+ $this->load_index();
+
+ // Make sure index contains new keys
+ foreach ($this->cache as $key => $value) {
+ if ($value !== null) {
+ if (array_search($key, $this->index) === false) {
+ $this->index[] = $key;
+ }
+ }
+ }
+
+ $data = serialize($this->index);
+ $this->add_record($this->ikey(), $data);
+ }
+
+
+ /**
+ * Gets the index entry from memcache/apc DB.
+ */
+ private function load_index()
+ {
+ if (!$this->db) {
+ return;
+ }
+
+ if ($this->index !== null) {
+ return;
+ }
+
+ $index_key = $this->ikey();
+
+ if ($this->type == 'memcache') {
+ $data = $this->db->get($index_key);
+ }
+ else if ($this->type == 'apc') {
+ $data = apc_fetch($index_key);
+ }
+
+ $this->index = $data ? unserialize($data) : array();
+ }
+
+
+ /**
+ * Creates cache key name (for memcache and apc)
+ *
+ * @param string $key Cache key name
+ *
+ * @return string Cache key
+ */
+ private function ckey($key)
+ {
+ return $this->prefix . ':' . $key;
+ }
+
+
+ /**
+ * Creates index cache key name (for memcache and apc)
+ *
+ * @return string Cache key
+ */
+ private function ikey()
+ {
+ // This way each cache will have its own index
+ return $this->prefix . 'INDEX';
+ }
+}
diff --git a/lib/ext/Roundcube/rcube_db_mysql.php b/lib/ext/Roundcube/rcube_db_mysql.php
index b2cbab2..2d42610 100644
--- a/lib/ext/Roundcube/rcube_db_mysql.php
+++ b/lib/ext/Roundcube/rcube_db_mysql.php
@@ -34,6 +34,13 @@ class rcube_db_mysql extends rcube_db
*/
protected function init()
{
+ if (version_compare(PHP_VERSION, '5.3.0', '<')) {
+ rcube::raise_error(array('code' => 600, 'type' => 'db',
+ 'line' => __LINE__, 'file' => __FILE__,
+ 'message' => "MySQL driver requires PHP >= 5.3, current version is " . PHP_VERSION),
+ true, true);
+ }
+
// SQL identifiers quoting
$this->options['identifier_start'] = '`';
$this->options['identifier_end'] = '`';
diff --git a/lib/ext/Roundcube/rcube_imap.php b/lib/ext/Roundcube/rcube_imap.php
index 43c61fd..31e7079 100644
--- a/lib/ext/Roundcube/rcube_imap.php
+++ b/lib/ext/Roundcube/rcube_imap.php
@@ -3749,9 +3749,12 @@ class rcube_imap extends rcube_storage
$this->mcache->expunge($ttl);
}
+/*
+ // this cache is expunged by rcube class
if ($this->cache) {
$this->cache->expunge();
}
+*/
}
diff --git a/lib/ext/Roundcube/rcube_message.php b/lib/ext/Roundcube/rcube_message.php
index a42d3fb..797ca18 100644
--- a/lib/ext/Roundcube/rcube_message.php
+++ b/lib/ext/Roundcube/rcube_message.php
@@ -785,7 +785,7 @@ class rcube_message
$uupart->size = strlen($uupart->body);
$uupart->mime_id = 'uu.' . $part->mime_id . '.' . $pid;
- $ctype = rcube_mime::content_type($uupart->body, $uupart->filename, 'application/octet-stream', true);
+ $ctype = rcube_mime::file_content_type($uupart->body, $uupart->filename, 'application/octet-stream', true);
$uupart->mimetype = $ctype;
list($uupart->ctype_primary, $uupart->ctype_secondary) = explode('/', $ctype);
diff --git a/lib/ext/Roundcube/rcube_mime.php b/lib/ext/Roundcube/rcube_mime.php
index 5968288..5258af5 100644
--- a/lib/ext/Roundcube/rcube_mime.php
+++ b/lib/ext/Roundcube/rcube_mime.php
@@ -658,6 +658,10 @@ class rcube_mime
$subString = $substr_func($subString, 0, $spacePos, $charset);
$cutLength = $spacePos + 1;
}
+ else if ($cut === false && $breakPos === false) {
+ $subString = $string;
+ $cutLength = null;
+ }
else if ($cut === false) {
$spacePos = $strpos_func($string, ' ', 0, $charset);
@@ -795,7 +799,7 @@ class rcube_mime
}
foreach ($file_paths as $fp) {
- if (is_readable($fp)) {
+ if (@is_readable($fp)) {
$lines = file($fp, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
break;
}
diff --git a/lib/ext/Roundcube/rcube_washtml.php b/lib/ext/Roundcube/rcube_washtml.php
index 27dff9f..a11371c 100644
--- a/lib/ext/Roundcube/rcube_washtml.php
+++ b/lib/ext/Roundcube/rcube_washtml.php
@@ -140,6 +140,9 @@ class rcube_washtml
/* Allowed HTML attributes */
private $_html_attribs = array();
+ /* Max nesting level */
+ private $max_nesting_level;
+
/**
* Class constructor
@@ -284,12 +287,26 @@ class rcube_washtml
* It output only allowed tags with allowed attributes
* and allowed inline styles
*/
- private function dumpHtml($node)
+ private function dumpHtml($node, $level = 0)
{
if (!$node->hasChildNodes()) {
return '';
}
+ $level++;
+
+ if ($this->max_nesting_level > 0 && $level == $this->max_nesting_level - 1) {
+ // log error message once
+ if (!$this->max_nesting_level_error) {
+ $this->max_nesting_level_error = true;
+ rcube::raise_error(array('code' => 500, 'type' => 'php',
+ 'line' => __LINE__, 'file' => __FILE__,
+ 'message' => "Maximum nesting level exceeded (xdebug.max_nesting_level={$this->max_nesting_level})"),
+ true, false);
+ }
+ return '<!-- ignored -->';
+ }
+
$node = $node->firstChild;
$dump = '';
@@ -299,10 +316,10 @@ class rcube_washtml
$tagName = strtolower($node->tagName);
if ($callback = $this->handlers[$tagName]) {
$dump .= call_user_func($callback, $tagName,
- $this->wash_attribs($node), $this->dumpHtml($node), $this);
+ $this->wash_attribs($node), $this->dumpHtml($node, $level), $this);
}
else if (isset($this->_html_elements[$tagName])) {
- $content = $this->dumpHtml($node);
+ $content = $this->dumpHtml($node, $level);
$dump .= '<' . $tagName . $this->wash_attribs($node) .
($content != '' || isset($this->_block_elements[$tagName]) ? ">$content</$tagName>" : ' />');
}
@@ -311,7 +328,7 @@ class rcube_washtml
}
else {
$dump .= '<!-- ' . htmlspecialchars($tagName, ENT_QUOTES) . ' ignored -->';
- $dump .= $this->dumpHtml($node); // ignore tags not its content
+ $dump .= $this->dumpHtml($node, $level); // ignore tags not its content
}
break;
@@ -324,14 +341,14 @@ class rcube_washtml
break;
case XML_HTML_DOCUMENT_NODE:
- $dump .= $this->dumpHtml($node);
+ $dump .= $this->dumpHtml($node, $level);
break;
case XML_DOCUMENT_TYPE_NODE:
break;
default:
- $dump . '<!-- node type ' . $node->nodeType . ' -->';
+ $dump .= '<!-- node type ' . $node->nodeType . ' -->';
}
} while($node = $node->nextSibling);
@@ -358,6 +375,9 @@ class rcube_washtml
$this->config['base_url'] = '';
}
+ // Detect max nesting level (for dumpHTML) (#1489110)
+ $this->max_nesting_level = (int) @ini_get('xdebug.max_nesting_level');
+
@$node->loadHTML($html);
return $this->dumpHtml($node);
}
@@ -405,6 +425,7 @@ class rcube_washtml
rcube::raise_error(array('code' => 620, 'type' => 'php',
'line' => __LINE__, 'file' => __FILE__,
'message' => $errstr), true, false);
+
return '';
}
commit 8a89af6e07c7dc04a5e731cd362bfce09d3ee7ea
Author: Aleksander Machniak <alec at alec.pl>
Date: Sun May 26 10:47:44 2013 +0200
Avoid sending HTTP header "Content-Type: text/html" for empty sync responses
diff --git a/lib/ext/Syncroton/Server.php b/lib/ext/Syncroton/Server.php
index 0e57ddd..7b681a0 100644
--- a/lib/ext/Syncroton/Server.php
+++ b/lib/ext/Syncroton/Server.php
@@ -134,6 +134,9 @@ class Syncroton_Server
header("MS-Server-ActiveSync: 14.00.0536.000");
+ // avoid sending HTTP header "Content-Type: text/html" for empty sync responses
+ ini_set('default_mimetype', null);
+
try {
$command = new $className($requestBody, $device, $requestParameters);
More information about the commits
mailing list