Merge branch '1.0-local' into 1.0

This commit is contained in:
xdrm-brackets 2017-02-19 15:45:24 +01:00
commit 2760a1489f
2 changed files with 48 additions and 27 deletions

View File

@ -15,7 +15,7 @@
} }
// remove unwanted spaces or linebreaks // remove unwanted spaces or linebreaks
$url = preg_replace('/\s/', '', $url).'/init'; $url = preg_replace('/\s/', '', $url).'/init/';
/* (2) Fetch machine id */ /* (2) Fetch machine id */
@ -26,6 +26,7 @@
return 127; return 127;
} }
$id_machine = (int) preg_replace('/\s/', '', $id_machine);
/* (3) Fetch cyclic hash */ /* (3) Fetch cyclic hash */
@ -121,8 +122,25 @@
} }
/* [6] Response management
=========================================================*/
/* (1) Try to json_decode response */
$response_arr = json_decode($response, true);
/* [6] Decrement cyclic-hash so request has ran successfully // if cannot, abort
if( is_null($response_arr) )
return 127;
/* (2) Check response error */
if( !isset($response_arr['error']) || $response_arr['error'] != 0 )
return 127;
/* (3) Writes request to temporary pipe */
file_put_contents(TMP_DIR.'/api.response', $response);
/* [7] Decrement cyclic-hash so request has ran successfully
=========================================================*/ =========================================================*/
/* (1) Decrement the hash */ /* (1) Decrement the hash */
$decr = syscall(SOURCE_DIR.'/lib/cyclic-hash/decr'); $decr = syscall(SOURCE_DIR.'/lib/cyclic-hash/decr');
@ -132,21 +150,21 @@
return 127; return 127;
} }
return 0;
/* [6] Response management
/* [8] Deploy received data
=========================================================*/ =========================================================*/
/* (1) Writes request to temporary pipe */ /* (1) Manage response deployement */
file_put_contents(TMP_DIR.'/api.response', $response);
/* (2) Manage response deployement */
$deploy = syscall(SOURCE_DIR.'/lib/api/deploy init'); $deploy = syscall(SOURCE_DIR.'/lib/api/deploy init');
/* (3) Return state */ /* (2) Return state */
return ($deploy === true) ? 0 : 127; return ($deploy === true) ? 0 : 127;
} }
echo api_init(); die(api_init());

View File

@ -15,7 +15,7 @@
} }
// remove unwanted spaces or linebreaks // remove unwanted spaces or linebreaks
$url = preg_replace('/\s/', '', $url).'/sync'; $url = preg_replace('/\s/', '', $url).'/sync/';
/* (2) Fetch cyclic hash */ /* (2) Fetch cyclic hash */
@ -108,19 +108,6 @@
return 127; return 127;
} }
/* [6] Decrement cyclic-hash so request has ran successfully
=========================================================*/
/* (1) Decrement the hash */
$decr = syscall(SOURCE_DIR.'/lib/cyclic-hash/decr');
if( $decr === false ){
slog("cyclic-hash:decr returned $decr EXIT_STATUS", 'api:sync','update');
return 127;
}
/* [6] Response management /* [6] Response management
=========================================================*/ =========================================================*/
/* (1) Try to json_decode response */ /* (1) Try to json_decode response */
@ -137,15 +124,31 @@
/* (3) Writes request to temporary pipe */ /* (3) Writes request to temporary pipe */
file_put_contents(TMP_DIR.'/api.response', $response); file_put_contents(TMP_DIR.'/api.response', $response);
/* (4) Manage response deployement */
/* [7] Decrement cyclic-hash so request has ran successfully
=========================================================*/
/* (1) Decrement the hash */
$decr = syscall(SOURCE_DIR.'/lib/cyclic-hash/decr');
if( $decr === false ){
slog("cyclic-hash:decr returned $decr EXIT_STATUS", 'api:init','update');
return 127;
}
return 0;
/* [8] Deploy received data
=========================================================*/
/* (1) Manage response deployement */
$deploy = syscall(SOURCE_DIR.'/lib/api/deploy sync'); $deploy = syscall(SOURCE_DIR.'/lib/api/deploy sync');
/* (5) Return state */ /* (2) Return state */
return ($deploy === true) ? 0 : 127; return ($deploy === true) ? 0 : 127;
} }
echo api_request(); die(api_request());