Bug 278016 VersionCheck should support multiple items in one pass

Patch by Ted Mielczarek (luser) <ted.mielczarek@gmail.com>, r=me
This commit is contained in:
cst%andrew.cmu.edu 2005-01-23 20:08:32 +00:00
Родитель 4365a39770
Коммит d6ad344e3f
1 изменённых файлов: 106 добавлений и 98 удалений

Просмотреть файл

@ -21,6 +21,7 @@
*
* Contributor(s):
* Vladimir Vukicevic <vladimir@pobox.com>
* Ted Mielczarek <ted.mielczarek@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -105,38 +106,41 @@ function vercmp ($a, $b) {
}
//
// These are passed in the GET string
// These are passed in the GET string / POST request
//
if (!array_key_exists('reqVersion', $_GET))
if (!array_key_exists('reqVersion', $_REQUEST))
bail ("Invalid request.");
$reqVersion = $_GET['reqVersion'];
$reqVersion = $_REQUEST['reqVersion'];
if ($reqVersion == 1) {
if (!array_key_exists('id', $_GET) ||
!array_key_exists('version', $_GET) ||
!array_key_exists('maxAppVersion', $_GET) ||
!array_key_exists('appID', $_GET) ||
!array_key_exists('appVersion', $_GET))
if (!array_key_exists('id', $_REQUEST) ||
!array_key_exists('version', $_REQUEST) ||
!array_key_exists('maxAppVersion', $_REQUEST) ||
!array_key_exists('appID', $_REQUEST) ||
!array_key_exists('appVersion', $_REQUEST))
bail ("Invalid request.");
$reqItemGuid = mysql_real_escape_string($_GET['id']);
$reqItemVersion = mysql_real_escape_string($_GET['version']);
$reqItemMaxAppVersion = mysql_real_escape_string($_GET['maxAppVersion']);
$reqTargetAppGuid = mysql_real_escape_string($_GET['appID']);
$reqTargetAppVersion = mysql_real_escape_string($_GET['appVersion']);
// these three can have multiple values
$reqItemGuid = explode(",",mysql_real_escape_string($_REQUEST['id']));
$reqItemVersion = explode(",",mysql_real_escape_string($_REQUEST['version']));
// are we even using this?
$reqItemMaxAppVersion = explode(",",mysql_real_escape_string($_REQUEST['maxAppVersion']));
$reqTargetAppGuid = mysql_real_escape_string($_REQUEST['appID']);
$reqTargetAppVersion = mysql_real_escape_string($_REQUEST['appVersion']);
// For backwards compatibility, not required.
$reqTargetOS = mysql_real_escape_string($_GET['appOS']);
$reqTargetOS = mysql_real_escape_string($_REQUEST['appOS']);
} else {
// bail
bail ("Bad request version received");
}
// check args
if (empty($reqItemGuid) || empty($reqItemVersion) || empty($reqTargetAppGuid)) {
if (empty($reqItemGuid) || empty($reqItemVersion) || empty($reqTargetAppGuid)
|| (count($reqItemGuid) != count($reqItemVersion))) {
bail ("Invalid request.");
}
@ -203,6 +207,32 @@ if ( ( $reqTargetOS == 'WINNT' )
$osid = 6;
}
//
// Now to spit out the RDF. We hand-generate because the data is pretty simple.
//
print "<?xml version=\"1.0\"?>\n";
print "<RDF:RDF xmlns:RDF=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:em=\"http://www.mozilla.org/2004/em-rdf#\">\n\n";
function print_update ($data) {
global $ext_typemap;
$dataItemType = $ext_typemap[$data['exttype']];
print "<RDF:Description about=\"urn:mozilla:{$dataItemType}:{$data['extguid']}:{$data['extversion']}\">\n";
print " <em:version>{$data['extversion']}</em:version>\n";
print " <em:targetApplication>\n";
print " <RDF:Description>\n";
print " <em:id>{$data['appguid']}</em:id>\n";
print " <em:minVersion>{$data['appminver']}</em:minVersion>\n";
print " <em:maxVersion>{$data['appmaxver']}</em:maxVersion>\n";
print " <em:updateLink>{$data['exturi']}</em:updateLink>\n";
print " </RDF:Description>\n";
print " </em:targetApplication>\n";
print "</RDF:Description>\n\n";
}
// now we query for each item
for($i=0; $i < count($reqItemGuid); $i++)
{
$query =
"SELECT main.guid AS extguid,
main.type AS exttype,
@ -218,7 +248,7 @@ $query =
/* We want to filter the results so that only OS=ALL and OS specific
results show up. */
$where = " WHERE main.guid = '" . $reqItemGuid . "'
$where = " WHERE main.guid = '" . $reqItemGuid[$i] . "'
AND applications.guid = '" . $reqTargetAppGuid . "'
AND (version.OSID = 1 OR version.OSID = " . $osid . ")
AND version.approved = 'YES'";
@ -249,7 +279,7 @@ while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
}
// Do we already have the current or a newer one?
if (vercmp($line['extversion'], $reqItemVersion) <= 0) {
if (vercmp($line['extversion'], $reqItemVersion[$i]) <= 0) {
$thisVersionData = $line;
break;
}
@ -263,23 +293,14 @@ while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
// Keep going until we find one that is
}
mysql_free_result ($result);
//
// Now to spit out the RDF. We hand-generate because the data is pretty simple.
//
print "<?xml version=\"1.0\"?>\n";
print "<RDF:RDF xmlns:RDF=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:em=\"http://www.mozilla.org/2004/em-rdf#\">\n\n";
print "<RDF:Description about=\"urn:mozilla:{$itemType}:{$reqItemGuid}\">\n";
print "<RDF:Description about=\"urn:mozilla:{$itemType}:{$reqItemGuid[$i]}\">\n";
// output list of updates (just highest and this)
print " <em:updates><RDF:Seq>\n";
if (!empty($thisVersionData))
print " <RDF:li resource=\"urn:mozilla:{$itemType}:{$reqItemGuid}:{$thisVersionData['extversion']}\"/>\n";
print " <RDF:li resource=\"urn:mozilla:{$itemType}:{$reqItemGuid[$i]}:{$thisVersionData['extversion']}\"/>\n";
if (!empty($highestVersionData))
print " <RDF:li resource=\"urn:mozilla:{$itemType}:{$reqItemGuid}:{$highestVersionData['extversion']}\"/>\n";
print " <RDF:li resource=\"urn:mozilla:{$itemType}:{$reqItemGuid[$i]}:{$highestVersionData['extversion']}\"/>\n";
print " </RDF:Seq></em:updates>\n";
// output compat bits for firefox 0.9
@ -290,27 +311,14 @@ if (!empty($highestVersionData)) {
print "</RDF:Description>\n\n";
function print_update ($data) {
global $ext_typemap;
$dataItemType = $ext_typemap[$data['exttype']];
print "<RDF:Description about=\"urn:mozilla:{$dataItemType}:{$data['extguid']}:{$data['extversion']}\">\n";
print " <em:version>{$data['extversion']}</em:version>\n";
print " <em:targetApplication>\n";
print " <RDF:Description>\n";
print " <em:id>{$data['appguid']}</em:id>\n";
print " <em:minVersion>{$data['appminver']}</em:minVersion>\n";
print " <em:maxVersion>{$data['appmaxver']}</em:maxVersion>\n";
print " <em:updateLink>{$data['exturi']}</em:updateLink>\n";
print " </RDF:Description>\n";
print " </em:targetApplication>\n";
print "</RDF:Description>\n";
}
if (!empty($thisVersionData))
print_update ($thisVersionData);
if (!empty($highestVersionData))
print_update ($highestVersionData);
mysql_free_result ($result);
}
print "</RDF:RDF>\n";
?>