Skip to content

Commit f2a5a28

Browse files
committed
Cosmetic
1 parent 0df48a8 commit f2a5a28

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

Lock.php

+15-15
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Lock {
1212
const LOCK_SHARED = 25; // NOT USED
1313
const LOCK_EXCLUSIVE = 50;
1414

15-
function __construct($params, $tmpdir = null) {
15+
function __construct ($params, $tmpdir = null) {
1616
$this->Crypto = new \artnum\Crypto();
1717
$this->RKey = false;
1818

@@ -46,7 +46,7 @@ function __construct($params, $tmpdir = null) {
4646
}
4747
}
4848

49-
function _getOrGenKey() {
49+
function _getOrGenKey () {
5050
$stmt = $this->DB->prepare('SELECT "cle_data" FROM "cle" ORDER BY "cle_id" DESC;');
5151
if ($stmt->execute()) {
5252
$key = $stmt->fetch();
@@ -65,7 +65,7 @@ function _getOrGenKey() {
6565
}
6666
}
6767

68-
function _sqlite($project, $tmpdir = NULL) {
68+
function _sqlite ($project, $tmpdir = NULL) {
6969
$file = $project .'-verrou.sqlite';
7070
$crypto = $project . '-verrou.rand';
7171
$dir = '';
@@ -106,8 +106,7 @@ function _sqlite($project, $tmpdir = NULL) {
106106
}
107107
}
108108

109-
110-
function _genkey($id, $prev_key = null) {
109+
function _genkey ($id, $prev_key = null) {
111110
$data = $id;
112111
$data .= $prev_key ? $prev_key : '-';
113112
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) {
121120
return $key[0];
122121
}
123122

124-
function _is_locked($id) {
123+
function _is_locked ($id) {
125124
$stmt = $this->DB->prepare('SELECT "verrou_state", "verrou_timestamp", "verrou_key" FROM "verrou" WHERE "verrou_path" = :id');
126125
$stmt->bindValue(':id', $id, \PDO::PARAM_LOB);
127126
$res = $stmt->execute();
@@ -142,8 +141,10 @@ function _is_locked($id) {
142141
return false;
143142
}
144143

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+
}
147148
}
148149

149150
function lock ($path, $prev_key = null, $type = self::LOCK_EXCLUSIVE) {
@@ -203,7 +204,7 @@ function lock ($path, $prev_key = null, $type = self::LOCK_EXCLUSIVE) {
203204
return $result;
204205
}
205206

206-
function _commit() {
207+
function _commit () {
207208
switch ($this->Type) {
208209
default:
209210
case 'pdo':
@@ -215,7 +216,7 @@ function _commit() {
215216
}
216217
}
217218

218-
function _begin_transaction() {
219+
function _begin_transaction () {
219220
$i = 0;
220221
$available = false;
221222
do {
@@ -240,7 +241,7 @@ function _begin_transaction() {
240241
return $available;
241242
}
242243

243-
function unlock($path, $key) {
244+
function unlock ($path, $key) {
244245
$result = array('lock' => $path, 'state' => 'unlocked', 'key' => '', 'timeout' => 0, 'error' => false);
245246
$id = $this->Crypto->hash($path, true)[0];
246247
$key = $this->Crypto->y64decode($key);
@@ -265,7 +266,7 @@ function unlock($path, $key) {
265266
return $result;
266267
}
267268

268-
function state($path) {
269+
function state ($path) {
269270
$result = array('lock' => $path, 'state' => 'unlocked', 'key' => '', 'timeout' => 0, 'error' => false);
270271
$id = $this->Crypto->hash($path, true)[0];
271272
if (! $this->_begin_transaction()) {
@@ -282,7 +283,7 @@ function state($path) {
282283
return $result;
283284
}
284285

285-
function request($req) {
286+
function request ($req) {
286287
$now = time();
287288
$result = false;
288289
if (!isset($req['key']) || empty($req['key'])) { $req['key'] = null; }
@@ -305,7 +306,7 @@ function request($req) {
305306
return $result;
306307
}
307308

308-
function http_locking() {
309+
function http_locking () {
309310
$key = isset($_GET['key']) ? $_GET['key'] : null;
310311
$result = array('lock' => '', 'state' => 'unlocked', 'key'=>'');
311312
if (!empty($_GET['lock'])) {
@@ -320,7 +321,6 @@ function http_locking() {
320321
$result = $this->request(array('on' => $_GET['state'], 'operation' => 'state'));
321322
}
322323
echo json_encode($result);
323-
324324
}
325325
}
326326
?>

0 commit comments

Comments
 (0)