[Fixed] Removed use of STATES_CONF : relation between GLOBAL_STATE <=> CHIP_STATE

This commit is contained in:
xdrm-brackets 2017-02-23 15:12:01 +01:00
parent e044ad028b
commit 78fe237d8a
1 changed files with 13 additions and 35 deletions

View File

@ -6,13 +6,11 @@
$f_auth; $f_auth;
$f_accesslog; $f_accesslog;
$f_states;
$f_actions; $f_actions;
$state = []; $state = null;
$actions = []; $actions = [];
$states = [];
$last_user = null; $last_user = null;
$timeout = 0; $timeout = 0;
@ -82,7 +80,7 @@
global $timeout; global $timeout;
/* (2) Caches */ /* (2) Caches */
global $actions, $states, $state; global $actions, $state;
/* (3) Log history file descriptor */ /* (3) Log history file descriptor */
global $f_accesslog; global $f_accesslog;
@ -218,7 +216,7 @@
global $f_auth, $f_accesslog; global $f_auth, $f_accesslog;
/* (2) Caches */ /* (2) Caches */
global $actions, $states, $state; global $actions, $state;
@ -226,7 +224,6 @@
=========================================================*/ =========================================================*/
/* (1) Read accesses */ /* (1) Read accesses */
$f_auth = new SplFileObject(AUTH_CONF, 'r'); $f_auth = new SplFileObject(AUTH_CONF, 'r');
$f_states = new SplFileObject(STATES_CONF, 'r');
$f_actions = new SplFileObject(ACTIONS_CONF, 'r'); $f_actions = new SplFileObject(ACTIONS_CONF, 'r');
$f_gstate = @file_get_contents(STATE_CONF); $f_gstate = @file_get_contents(STATE_CONF);
@ -264,43 +261,24 @@
/* [3] Parse STATES and cache them /* [3] Cache global state
=========================================================*/
/* (1) Parse each line */
while( $f_states->eof() ){
/* (2) Try to parse line */
$parsed = json_decode($f_states->fgets(), true);
/* (2) Ignore if parse error */
if( is_null($parsed) )
continue;
/* (3) Add entry to cache */
$states[] = $parsed;
}
/* (4) Free file descriptor */
$f_states = null;
/* [4] Cache global state
=========================================================*/ =========================================================*/
/* (1) Check file */ /* (1) Check file */
if( $f_gstate === false ) if( $f_gstate === false )
return false; return 127;
/* (2) Remove surrounding spaces */ /* (2) Remove surrounding spaces */
$f_gstate = preg_replace('@^\s+@', '', $f_gstate); $f_gstate = preg_replace('@^\s+@', '', $f_gstate);
$f_gstate = preg_replace('@\s+$@', '', $f_gstate); $f_gstate = preg_replace('@\s+$@', '', $f_gstate);
/* (3) For each character create an entry */ /* (3) For each character create an entry */
for( $c = 0 ; $c < strlen($f_gstate) ; $c++ ) $state = str_split($f_gstate);
$state[] = $c;
/* (4) Manage error */
if( is_null($state) )
return 127;
return true; return 0;
} }
@ -316,7 +294,7 @@
global $timeout; global $timeout;
/* (2) Caches */ /* (2) Caches */
global $actions, $states, $state; global $actions, $state;
@ -411,7 +389,7 @@
$exec = mfrc522_setup(); $exec = mfrc522_setup();
/* (2) Manage error */ /* (2) Manage error */
if( $exec === false ){ if( $exec != 0 ){
slog('cannot set up the daemon', 'mfrc522:loop'); slog('cannot set up the daemon', 'mfrc522:loop');
echo $exec; echo $exec;
die($exec); die($exec);