| | |
| | | /* |
| | | +-----------------------------------------------------------------------+ |
| | | | This file is part of the Roundcube Webmail client | |
| | | | Copyright (C) 2005-2012, The Roundcube Dev Team | |
| | | | Copyright (C) 2005-2014, The Roundcube Dev Team | |
| | | | Copyright (C) 2011, Kolab Systems AG | |
| | | | | |
| | | | Licensed under the GNU General Public License version 3 or | |
| | |
| | | private $changed; |
| | | private $time_diff = 0; |
| | | private $reloaded = false; |
| | | private $appends = array(); |
| | | private $unsets = array(); |
| | | private $gc_handlers = array(); |
| | | private $cookiename = 'roundcube_sessauth'; |
| | |
| | | private $logging = false; |
| | | private $storage; |
| | | private $memcache; |
| | | |
| | | /** |
| | | * Blocks session data from being written to database. |
| | | * Can be used if write-race conditions are to be expected |
| | | * @var boolean |
| | | */ |
| | | public $nowrite = false; |
| | | |
| | | |
| | | /** |
| | |
| | | $now = $this->db->now(); |
| | | $table = $this->db->table_name('session'); |
| | | $ts = microtime(true); |
| | | |
| | | if ($this->nowrite) |
| | | return true; |
| | | |
| | | // no session row in DB (db_read() returns false) |
| | | if (!$this->key) { |
| | |
| | | |
| | | $node = &$this->get_node(explode('.', $path), $_SESSION); |
| | | |
| | | if ($key !== null) $node[$key] = $value; |
| | | else $node[] = $value; |
| | | if ($key !== null) { |
| | | $node[$key] = $value; |
| | | $path .= '.' . $key; |
| | | } |
| | | else { |
| | | $node[] = $value; |
| | | } |
| | | |
| | | $this->appends[] = $path; |
| | | |
| | | // when overwriting a previously unset variable |
| | | if ($this->unsets[$path]) |
| | | unset($this->unsets[$path]); |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | public function reload() |
| | | { |
| | | // collect updated data from previous appends |
| | | $merge_data = array(); |
| | | foreach ((array)$this->appends as $var) { |
| | | $path = explode('.', $var); |
| | | $value = $this->get_node($path, $_SESSION); |
| | | $k = array_pop($path); |
| | | $node = &$this->get_node($path, $merge_data); |
| | | $node[$k] = $value; |
| | | } |
| | | |
| | | if ($this->key && $this->memcache) |
| | | $data = $this->mc_read($this->key); |
| | | else if ($this->key) |
| | | $data = $this->db_read($this->key); |
| | | |
| | | if ($data) |
| | | if ($data) { |
| | | session_decode($data); |
| | | |
| | | // apply appends and unsets to reloaded data |
| | | $_SESSION = array_merge_recursive($_SESSION, $merge_data); |
| | | |
| | | foreach ((array)$this->unsets as $var) { |
| | | if (isset($_SESSION[$var])) { |
| | | unset($_SESSION[$var]); |
| | | } |
| | | else { |
| | | $path = explode('.', $var); |
| | | $k = array_pop($path); |
| | | $node = &$this->get_node($path, $_SESSION); |
| | | unset($node[$k]); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |