@@ -12,7 +12,7 @@ class Lock {
12
12
const LOCK_SHARED = 25 ; // NOT USED
13
13
const LOCK_EXCLUSIVE = 50 ;
14
14
15
- function __construct ($ params , $ tmpdir = null ) {
15
+ function __construct ($ params , $ tmpdir = null ) {
16
16
$ this ->Crypto = new \artnum \Crypto ();
17
17
$ this ->RKey = false ;
18
18
@@ -46,7 +46,7 @@ function __construct($params, $tmpdir = null) {
46
46
}
47
47
}
48
48
49
- function _getOrGenKey () {
49
+ function _getOrGenKey () {
50
50
$ stmt = $ this ->DB ->prepare ('SELECT "cle_data" FROM "cle" ORDER BY "cle_id" DESC; ' );
51
51
if ($ stmt ->execute ()) {
52
52
$ key = $ stmt ->fetch ();
@@ -65,7 +65,7 @@ function _getOrGenKey() {
65
65
}
66
66
}
67
67
68
- function _sqlite ($ project , $ tmpdir = NULL ) {
68
+ function _sqlite ($ project , $ tmpdir = NULL ) {
69
69
$ file = $ project .'-verrou.sqlite ' ;
70
70
$ crypto = $ project . '-verrou.rand ' ;
71
71
$ dir = '' ;
@@ -106,8 +106,7 @@ function _sqlite($project, $tmpdir = NULL) {
106
106
}
107
107
}
108
108
109
-
110
- function _genkey ($ id , $ prev_key = null ) {
109
+ function _genkey ($ id , $ prev_key = null ) {
111
110
$ data = $ id ;
112
111
$ data .= $ prev_key ? $ prev_key : '- ' ;
113
112
foreach (array ('REMOTE_ADDR ' , 'REMOTE_HOST ' , 'REMOTE_PORT ' , 'HTTP_REFERER ' , 'HTTP_ACCEPT_ENCODING ' , 'HTTP_USER_AGENT ' , 'HTTP_ACCEPT_LANGUAGE ' ) as $ i ) {
@@ -121,7 +120,7 @@ function _genkey($id, $prev_key = null) {
121
120
return $ key [0 ];
122
121
}
123
122
124
- function _is_locked ($ id ) {
123
+ function _is_locked ($ id ) {
125
124
$ stmt = $ this ->DB ->prepare ('SELECT "verrou_state", "verrou_timestamp", "verrou_key" FROM "verrou" WHERE "verrou_path" = :id ' );
126
125
$ stmt ->bindValue (':id ' , $ id , \PDO ::PARAM_LOB );
127
126
$ res = $ stmt ->execute ();
@@ -142,8 +141,10 @@ function _is_locked($id) {
142
141
return false ;
143
142
}
144
143
145
- function set_timeout ($ timeout ) {
146
- $ this ->Timeout = $ timeout ;
144
+ function set_timeout ($ timeout ) {
145
+ if (is_integer ($ timeout ) && intval ($ timeout ) >= 0 ) {
146
+ $ this ->Timeout = $ timeout ;
147
+ }
147
148
}
148
149
149
150
function lock ($ path , $ prev_key = null , $ type = self ::LOCK_EXCLUSIVE ) {
@@ -203,7 +204,7 @@ function lock ($path, $prev_key = null, $type = self::LOCK_EXCLUSIVE) {
203
204
return $ result ;
204
205
}
205
206
206
- function _commit () {
207
+ function _commit () {
207
208
switch ($ this ->Type ) {
208
209
default :
209
210
case 'pdo ' :
@@ -215,7 +216,7 @@ function _commit() {
215
216
}
216
217
}
217
218
218
- function _begin_transaction () {
219
+ function _begin_transaction () {
219
220
$ i = 0 ;
220
221
$ available = false ;
221
222
do {
@@ -240,7 +241,7 @@ function _begin_transaction() {
240
241
return $ available ;
241
242
}
242
243
243
- function unlock ($ path , $ key ) {
244
+ function unlock ($ path , $ key ) {
244
245
$ result = array ('lock ' => $ path , 'state ' => 'unlocked ' , 'key ' => '' , 'timeout ' => 0 , 'error ' => false );
245
246
$ id = $ this ->Crypto ->hash ($ path , true )[0 ];
246
247
$ key = $ this ->Crypto ->y64decode ($ key );
@@ -265,7 +266,7 @@ function unlock($path, $key) {
265
266
return $ result ;
266
267
}
267
268
268
- function state ($ path ) {
269
+ function state ($ path ) {
269
270
$ result = array ('lock ' => $ path , 'state ' => 'unlocked ' , 'key ' => '' , 'timeout ' => 0 , 'error ' => false );
270
271
$ id = $ this ->Crypto ->hash ($ path , true )[0 ];
271
272
if (! $ this ->_begin_transaction ()) {
@@ -282,7 +283,7 @@ function state($path) {
282
283
return $ result ;
283
284
}
284
285
285
- function request ($ req ) {
286
+ function request ($ req ) {
286
287
$ now = time ();
287
288
$ result = false ;
288
289
if (!isset ($ req ['key ' ]) || empty ($ req ['key ' ])) { $ req ['key ' ] = null ; }
@@ -305,7 +306,7 @@ function request($req) {
305
306
return $ result ;
306
307
}
307
308
308
- function http_locking () {
309
+ function http_locking () {
309
310
$ key = isset ($ _GET ['key ' ]) ? $ _GET ['key ' ] : null ;
310
311
$ result = array ('lock ' => '' , 'state ' => 'unlocked ' , 'key ' =>'' );
311
312
if (!empty ($ _GET ['lock ' ])) {
@@ -320,7 +321,6 @@ function http_locking() {
320
321
$ result = $ this ->request (array ('on ' => $ _GET ['state ' ], 'operation ' => 'state ' ));
321
322
}
322
323
echo json_encode ($ result );
323
-
324
324
}
325
325
}
326
326
?>
0 commit comments