1 <?php rcs_id('$Id: dba.php,v 1.1 2005-02-11 14:41:40 rurban Exp $');
6 * Values: date : IP : data
7 * @author: Reini Urban.
12 var $_backend_type = "dba";
14 function DbSession_dba (&$dbh, $table) {
16 ini_set('session.save_handler','user');
17 session_module_name('user'); // new style
18 session_set_save_handler(array(&$this, 'open'),
19 array(&$this, 'close'),
20 array(&$this, 'read'),
21 array(&$this, 'write'),
22 array(&$this, 'destroy'),
27 function quote($str) { return $str; }
28 function query($sql) { return false; }
36 $dba_handler = 'gdbm';
39 $dbfile = "$directory/$prefix" . 'session' . '.' . $dba_handler;
40 $dbh = new DbaDatabase($dbfile, false, $dba_handler);
41 $dbh->set_timeout($timeout);
42 if (!$dbh->open('c')) {
43 trigger_error(sprintf(_("%s: Can't open dba database"), $dbfile), E_USER_ERROR);
45 $request->finish(fmt("%s: Can't open dba database", $dbfile));
52 function _disconnect() {
53 if (0 and isset($this->_dbh))
57 function open ($save_path, $session_name) {
58 $dbh = &$this->_connect();
68 $dbh = &$this->_connect();
69 $result = $dbh->get($id);
73 list(,,$packed) = explode(':', $result, 3);
75 if (strlen($packed) > 4000) {
76 trigger_error("Overlarge session data!", E_USER_WARNING);
78 //$res = preg_replace('/s:6:"_cache";O:12:"WikiDB_cache".+}$/',"",$res);
83 function write ($id, $sess_data) {
84 $dbh = &$this->_connect();
86 $ip = $GLOBALS['request']->get('REMOTE_ADDR');
87 if (strlen($sess_data) > 4000) {
88 trigger_error("Overlarge session data!", E_USER_WARNING);
91 $dbh->set($id,$time.':'.$ip.':'.$sess_data);
96 function destroy ($id) {
97 $dbh = &$this->_connect();
103 function gc ($maxlifetime) {
104 $dbh = &$this->_connect();
105 $threshold = time() - $maxlifetime;
106 for ($id = $dbh->firstkey(); $id !== false; $id = $dbh->nextkey()) {
107 $result = $dbh->get($id);
108 list($date,,) = explode(':', $result, 3);
109 if ($date < $threshold)
112 $this->_disconnect();
116 // WhoIsOnline support.
117 // TODO: ip-accesstime dynamic blocking API
118 function currentSessions() {
120 $dbh = &$this->_connect();
121 for ($id = $dbh->firstkey(); $id !== false; $id = $dbh->nextkey()) {
122 $result = $dbh->get($id);
123 list($date,$ip,$packed) = explode(':', $result, 3);
124 if (!$packed) continue;
125 // session_data contains the <variable name> + "|" + <packed string>
126 // we need just the wiki_user object (might be array as well)
127 if ($date < 908437560 or $date > 1588437560)
129 $user = strstr($packed, "wiki_user|");
130 $sessions[] = array('wiki_user' => substr($user,10), // from "O:" onwards
134 $this->_disconnect();
139 // $Log: not supported by cvs2svn $
145 // c-hanging-comment-ender-p: nil
146 // indent-tabs-mode: nil