6 * Values: date : IP : data
7 * Already open sessions, e.g. interim xmlrpc requests are
8 * are treated specially. see write().
9 * To avoid deadlocks in the session.db3 access,
10 * the db is opened and closed for each access.
11 * @author: Reini Urban.
16 var $_backend_type = "dba";
18 function DbSession_dba (&$dbh, $table) {
20 ini_set('session.save_handler','user');
21 session_module_name('user'); // new style
22 session_set_save_handler(array(&$this, 'open'),
23 array(&$this, 'close'),
24 array(&$this, 'read'),
25 array(&$this, 'write'),
26 array(&$this, 'destroy'),
31 function quote($str) { return $str; }
32 function query($sql) { return false; }
34 function & _connect() {
40 $dba_handler = 'gdbm';
42 extract($DBParams); // overwrite the defaults
43 $dbfile = "$directory/$prefix" . 'session' . '.' . $dba_handler;
44 $dbh = new DbaDatabase($dbfile, 'c', $dba_handler);
50 function _disconnect() {
51 if (isset($this->_dbh)) {
57 function open ($save_path, $session_name) {
58 $dbh = $this->_connect();
67 $dbh = $this->_connect();
68 $result = $dbh->get($id);
72 list(,,$packed) = explode(':', $result, 3);
74 if (strlen($packed) > 4000) {
75 trigger_error("Overlarge session data!", E_USER_WARNING);
77 //$res = preg_replace('/s:6:"_cache";O:12:"WikiDB_cache".+}$/',"",$res);
82 function write ($id, $sess_data) {
83 if (defined("WIKI_XMLRPC") or defined("WIKI_SOAP")) return;
85 $dbh = $this->_connect();
87 $ip = $GLOBALS['request']->get('REMOTE_ADDR');
88 if (strlen($sess_data) > 4000) {
89 trigger_error("Overlarge session data!", E_USER_WARNING);
92 $dbh->set($id, $time.':'.$ip.':'.$sess_data);
97 function destroy ($id) {
98 $dbh = $this->_connect();
100 $this->_disconnect();
104 function gc ($maxlifetime) {
105 $dbh = $this->_connect();
106 $threshold = time() - $maxlifetime;
107 for ($id = $dbh->firstkey(); $id !== false; $id = $dbh->nextkey()) {
108 $result = $dbh->get($id);
109 list($date,,) = explode(':', $result, 3);
110 if ($date < $threshold)
113 $this->_disconnect();
117 // WhoIsOnline support.
118 // TODO: ip-accesstime dynamic blocking API
119 function currentSessions() {
121 $dbh = $this->_connect();
122 for ($id = $dbh->firstkey(); $id !== false; $id = $dbh->nextkey()) {
123 $result = $dbh->get($id);
124 list($date,$ip,$packed) = explode(':', $result, 3);
125 if (!$packed) continue;
126 // session_data contains the <variable name> + "|" + <packed string>
127 // we need just the wiki_user object (might be array as well)
128 if ($date < 908437560 or $date > 1588437560)
130 $user = strstr($packed, "wiki_user|");
131 $sessions[] = array('wiki_user' => substr($user,10), // from "O:" onwards
135 $this->_disconnect();
144 // c-hanging-comment-ender-p: nil
145 // indent-tabs-mode: nil