Second attempt of using XML parser

This commit is contained in:
mkuba50 2018-10-11 21:48:46 +02:00
parent b3c0a47186
commit d01e2ad508
2 changed files with 24 additions and 19 deletions

41
get.php
View File

@ -170,6 +170,10 @@ function uupGetFiles($updateId = 'c2a1d787-647b-486d-b264-f90f3782cdc6', $usePac
$updateId = preg_replace('/_rev\..*/', '', $updateId); $updateId = preg_replace('/_rev\..*/', '', $updateId);
} }
$updateArch = (isset($info['arch'])) ? $info['arch'] : 'UNKNOWN';
$updateBuild = (isset($info['build'])) ? $info['build'] : 'UNKNOWN';
$updateName = (isset($info['title'])) ? $info['title'] : 'Unknown update: '.$updateId;
$fetchTime = time(); $fetchTime = time();
consoleLogger('Fetching information from the server...'); consoleLogger('Fetching information from the server...');
$postData = composeFileGetRequest($updateId, uupDevice(), $info, $rev); $postData = composeFileGetRequest($updateId, uupDevice(), $info, $rev);
@ -177,27 +181,32 @@ function uupGetFiles($updateId = 'c2a1d787-647b-486d-b264-f90f3782cdc6', $usePac
consoleLogger('Information has been successfully fetched.'); consoleLogger('Information has been successfully fetched.');
consoleLogger('Parsing information...'); consoleLogger('Parsing information...');
preg_match_all('/<FileLocation>.*?<\/FileLocation>/', $out, $out); $xmlOut = simplexml_load_string($out);
if(empty($out[0])) { $xmlBody = $xmlOut->children('s', true)->Body->children();
if(!isset($xmlBody->GetExtendedUpdateInfo2Response)) {
consoleLogger('An error has occurred'); consoleLogger('An error has occurred');
return array('error' => 'EMPTY_FILELIST'); return array('error' => 'EMPTY_FILELIST');
} }
$updateArch = (isset($info['arch'])) ? $info['arch'] : 'UNKNOWN'; $getResponse = $xmlBody->GetExtendedUpdateInfo2Response;
$updateBuild = (isset($info['build'])) ? $info['build'] : 'UNKNOWN'; $getResult = $getResponse->GetExtendedUpdateInfo2Result;
$updateName = (isset($info['title'])) ? $info['title'] : 'Unknown update: '.$updateId;
if(!isset($getResult->FileLocations)) {
consoleLogger('An error has occurred');
return array('error' => 'EMPTY_FILELIST');
}
$fileLocations = $getResult->FileLocations;
$info = $info['files']; $info = $info['files'];
$out = preg_replace('/<FileLocation>|<\/FileLocation>/', '', $out[0]);
$files = array(); $files = array();
foreach($out as $val) { foreach($fileLocations->FileLocation as $val) {
$sha1 = explode('<FileDigest>', $val, 2); $sha1 = bin2hex(base64_decode((string)$val->FileDigest));
$sha1 = explode('</FileDigest>', $sha1[1], 2); $url = (string)$val->Url;
$sha1 = bin2hex(base64_decode($sha1[0]));
preg_match('/files\/.{8}-.{4}-.{4}-.{4}-.{12}/', $val, $guid); preg_match('/files\/(.{8}-.{4}-.{4}-.{4}-.{12})/', $url, $guid);
$guid = preg_replace('/files\/|\?$/', '', $guid[0]); $guid = $guid[1];
if(empty($info[$sha1]['name'])) { if(empty($info[$sha1]['name'])) {
$name = $guid; $name = $guid;
@ -214,13 +223,9 @@ function uupGetFiles($updateId = 'c2a1d787-647b-486d-b264-f90f3782cdc6', $usePac
if(!isset($fileSizes[$name])) $fileSizes[$name] = -2; if(!isset($fileSizes[$name])) $fileSizes[$name] = -2;
if($size > $fileSizes[$name]) { if($size > $fileSizes[$name]) {
$url = explode('<Url>', $val, 2); preg_match('/P1=(.*?)&/', $url, $expire);
$url = explode('</Url>', $url[1], 2);
$url = html_entity_decode($url[0]);
preg_match('/P1=.*?&/', $url, $expire);
if(isset($expire[0])) { if(isset($expire[0])) {
$expire = preg_replace('/P1=|&$/', '', $expire[0]); $expire = $expire[1];
} }
$expire = intval($expire); $expire = intval($expire);

View File

@ -16,7 +16,7 @@ limitations under the License.
*/ */
function uupApiVersion() { function uupApiVersion() {
return '1.15.11'; return '1.15.12';
} }
require_once dirname(__FILE__).'/auths.php'; require_once dirname(__FILE__).'/auths.php';