Copyright date updated
[brisk.git] / web / Obj / hardban.phh
index e2eeaba..e14e2d6 100644 (file)
@@ -2,7 +2,7 @@
 /*
  *  brisk - auth.phh
  *
- *  Copyright (C) 2006-2011 Matteo Nastasi
+ *  Copyright (C) 2006-2012 Matteo Nastasi
  *                          mailto: nastasi@alternativeoutput.it 
  *                                  matteo.nastasi@milug.org
  *                          web: http://www.alternativeoutput.it
  *
  */
 
-define(HBAN_SHM_DIMS_MIN, 16384);
-define(HBAN_SHM_DIMS_MAX, 65536);
-define(HBAN_SHM_DIMS_DLT, 16384);
-define(HBAN_VALID_TIME,      15);
-define(HBAN_GARBAGE_TIMEOUT,  5);
+define('HBAN_SHM_DIMS_MIN', 16384);
+define('HBAN_SHM_DIMS_MAX', 65536);
+define('HBAN_SHM_DIMS_DLT', 16384);
+define('HBAN_VALID_TIME',      15);
+define('HBAN_GARBAGE_TIMEOUT',  5);
 
 class Hardban {
   var $login;
@@ -238,21 +238,15 @@ class Hardbans {
     return (FALSE);
   }
 
-  static function lock_data()
+  static function lock_data($is_exclusive)
   {
-    if (($tok = @ftok(FTOK_PATH."/hardbans", "B")) == -1) {
-      return (FALSE);
-    }
-    // echo "FTOK ".$tok."<br>";
-    if (($res = sem_get($tok)) == FALSE) {
-      return (FALSE);
-    }
-    if (sem_acquire($res)) {   
-        self::$delta_t = microtime(TRUE);
-        log_lock("LOCK   hardbans     [".self::$delta_t."]");
-      return ($res);
-    }
-    else
+      if (($res = file_lock(FTOK_PATH."/hardbans", $is_exclusive)) != FALSE) {
+          self::$delta_t = microtime(TRUE);
+          log_lock("LOCK   hardbans     [".self::$delta_t."]");
+          
+          return ($res);
+      }
+
       return (FALSE);
   }
   
@@ -262,7 +256,7 @@ class Hardbans {
     
     log_lock("UNLOCK hardbans     [".(microtime(TRUE) - (self::$delta_t))."]");
 
-    return (sem_release($res));
+    file_unlock($res);
   }
 
 
@@ -270,7 +264,7 @@ class Hardbans {
   {
     $bantime = -1;
     /* if it exists check for a valid challenge */
-    if (($a_sem = Hardbans::lock_data()) != FALSE) { 
+    if (($a_sem = Hardbans::lock_data(TRUE)) != FALSE) { 
       
       if (($hban = &Hardbans::load_data()) != FALSE) {
         for ($e = 0 ; $e < $hban->item_n ; $e++) {
@@ -304,7 +298,7 @@ class Hardbans {
   {
     $found = FALSE;
     /* if it exists check for a valid challenge */
-    if (($a_sem = Hardbans::lock_data()) != FALSE) { 
+    if (($a_sem = Hardbans::lock_data(TRUE)) != FALSE) { 
       
       if (($hban = &Hardbans::load_data()) != FALSE) {