+ function step_set($step)
+ {
+ $this->step = $step & 0x7fffffff;
+
+ do {
+ if (validate_sess($this->sess) == FALSE)
+ break;
+ if (file_exists(BIN5_PROXY_PATH) == FALSE)
+ mkdir(BIN5_PROXY_PATH, 0775, TRUE);
+ if (($fp = @fopen(BIN5_PROXY_PATH."/".$this->sess.".step", 'w')) == FALSE)
+ break;
+ fwrite($fp, pack("LL",$this->step, $this->idx));
+ fclose($fp);
+
+ log_main("step_set [".$this->sess. "] [".$this->step."]");
+
+ return (TRUE);
+ } while (0);
+
+ return (FALSE);
+ }
+
+ function step_inc($delta = 1) {
+ $this->step += $delta;
+ /* modularization because unpack() not manage unsigned 32bit int correctly */
+ $this->step &= 0x7fffffff;
+
+ if (validate_sess($this->sess)) {
+ if (file_exists(BIN5_PROXY_PATH) == FALSE)
+ mkdir(BIN5_PROXY_PATH);
+ $fp = fopen(BIN5_PROXY_PATH."/".$this->sess.".step", 'w');
+ fwrite($fp, pack("LL", $this->step, $this->idx));
+ fclose($fp);
+
+ log_main("step_inc [".$this->sess. "] [".$this->step."]");
+
+ return (TRUE);
+ }
+
+ return (FALSE);
+ }
+
+ static function step_get($sess)
+ {
+ $fp = FALSE;
+ do {
+ if (validate_sess($sess) == FALSE)
+ break;
+
+ if (file_exists(BIN5_PROXY_PATH) == FALSE)
+ mkdir(BIN5_PROXY_PATH);
+ if (($fp = @fopen(BIN5_PROXY_PATH."/".$sess.".step", 'rb')) == FALSE)
+ break;
+ if (($s = fread($fp, 8)) == FALSE)
+ break;
+ if (strlen($s) != 8)
+ break;
+ $arr = unpack('Ls/Li', $s);
+ fclose($fp);
+
+ // log_rd2("A0: ".$arr[0]." A1: ".$arr[1]);
+ return ($arr);
+ } while (0);
+
+ if ($fp != FALSE)
+ fclose($fp);
+
+ log_rd2("STEP_GET [".$sess."]: return false ");
+
+ return (FALSE);
+ }
+
+ static function load_data($tab_id, $id, $sess)
+ {
+ log_main("Bin5_user::load_data: tab_id [".$tab_id."] id [".$id."] sess [".($sess == FALSE ? "FALSE" : $sess)."] ");
+
+ $doexit = FALSE;
+ do {
+ if (($tok = @ftok(FTOK_PATH."/bin5/table".$tab_id."/user".$id, "B")) == -1) {
+ log_main("ftok failed");
+ $doexit = TRUE;
+ break;
+ }
+
+ if (($shm_sz = sharedmem_sz($tok)) == -1) {
+ log_main("shmop_open failed");
+ }
+
+ if ($shm_sz == -1)
+ $shm_sz = SHM_DIMS_U_MIN;
+
+ if ($shm = shm_attach($tok, $shm_sz)) {
+ $user = @shm_get_var($shm, $tok);
+
+ if ($sess != FALSE && $user->sess != $sess) {
+ $doexit = TRUE;
+ break;
+ }
+ log_only("user == ".($user == FALSE ? "FALSE" : "TRUE")." user === ".($user === FALSE ? "FALSE" : "TRUE")." user isset ".(isset($user) ? "TRUE" : "FALSE"));
+
+ if ($user == FALSE) {
+ log_only("INIT MAIN DATA");
+
+ // SHSPLIT FIXME: init_data for User class ??
+ $user = User::create($id, "", "");
+ if (@shm_put_var($shm, $tok, $user) == FALSE) {
+ log_only("PUT_VAR FALLITA ".strlen(serialize($user)));
+ log_only(serialize($user));
+ }
+ }
+
+ $user->shm_sz = $shm_sz;
+
+ shm_detach($shm);
+ }
+
+ //
+ // SHSPLIT: load users from the shared memory
+ //
+ return ($user);
+ } while (0);
+
+ if ($doexit)
+ exit();
+
+ return (FALSE);
+ }