load_data return allways, all exit() calls removed, all load_data calls are protected
[brisk.git] / web / index_rd.php
index c775dc1..0850a36 100644 (file)
@@ -58,10 +58,9 @@ if (DEBUGGING == "local" && $_SERVER['REMOTE_ADDR'] != '127.0.0.1') {
 
 function shutta()
 {
-  log_rd2("SHUTTA!".connection_status());
+  log_rd2("SHUTTA [".connection_status()."] !");
 }
 
-
 register_shutdown_function(shutta);
 
 function unrecerror()
@@ -105,7 +104,9 @@ function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_su
     $user = FALSE;
     $curtime = time();
     
-    if (($proxy_step = User::step_get($sess)) == FALSE) {
+    // NOTE: qui forse si potrebbe fallback-are a una User::load_data 
+    //       anche se non ce ne dovrebbe essere mai la necessità
+    if (($proxy_step = User::load_step($sess)) == FALSE) {
         log_only2("R");
         return (FALSE);
     }
@@ -118,7 +119,7 @@ function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_su
             // Aggiorna l'expire time lato server
             $S_load_stat['U_first_loop']++;
             if (($user = User::load_data($proxy_step['i'], $sess)) == FALSE) {
-                Room::unlock_data();
+                Room::unlock_data($sem);
                 ignore_user_abort(FALSE);
                 return (unrecerror());
             }
@@ -130,7 +131,7 @@ function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_su
                 
                 $S_load_stat['R_garbage']++;
                 if (($room = Room::load_data()) == FALSE) {
-                    Room::unlock_data();
+                    Room::unlock_data($sem);
                     ignore_user_abort(FALSE);
                     return (unrecerror());
                 }
@@ -139,7 +140,7 @@ function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_su
                 Room::save_data($room);
                 unset($room);
             }
-            log_lock("U");
+            log_main("infolock: U");
             Room::unlock_data($sem);
             ignore_user_abort(FALSE);
         } // if (($sem = Room::lock_data()) != FALSE) { 
@@ -153,7 +154,7 @@ function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_su
     } // if  ($first_loop == TRUE) {
     
     if ($cur_step == $proxy_step['s']) {
-        log_lock("P");
+        log_main("infolock: P");
         return (FALSE);
     }
     else {
@@ -167,7 +168,7 @@ function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_su
             if (($sem = Room::lock_data()) == FALSE) 
                 break;
             
-            log_lock("P");
+            log_main("infolock: P");
             $S_load_stat['U_heavy']++;
             if (($user = User::load_data($proxy_step['i'], $sess)) == FALSE) {
                 break;
@@ -195,7 +196,11 @@ function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_su
          */
         ignore_user_abort(TRUE);
         $sem = Room::lock_data();
-        $room = Room::load_data();
+        if (($room = Room::load_data()) == FALSE) {
+            Room::unlock_data($sem);
+            ignore_user_abort(FALSE);
+            return (unrecerror());
+        }
         $S_load_stat['R_minusone']++;
         
         /* unset the $user var to reload it from main structure */
@@ -281,7 +286,7 @@ function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_su
         $sem = Room::lock_data();
         $S_load_stat['U_heavy']++;
         if (($user = User::load_data($proxy_step['i'], $sess)) == FALSE) {
-            Room::unlock_data();
+            Room::unlock_data($sem);
             ignore_user_abort(FALSE);
             return (unrecerror());
         }
@@ -317,7 +322,12 @@ function maincheck($sess, $cur_stat, $cur_subst, $cur_step, &$new_stat, &$new_su
                 log_auth($user->sess, "Explicit logout.");
                 
                 $S_load_stat['R_the_end']++;
-                $room = Room::load_data();
+                if (($room = Room::load_data()) == FALSE) {
+                    Room::unlock_data($sem);
+                    ignore_user_abort(FALSE);
+                    return (unrecerror());
+                }
+
                 unset($user);
                 if (($user = $room->get_user($sess, $idx)) == FALSE) {
                     Room::unlock_data($sem);