* Ted Mielczarek * * 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 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), * in which case the provisions of the GPL or the LGPL are applicable instead * of those above. If you wish to allow use of your version of this file only * under the terms of either the GPL or the LGPL, and not to allow others to * use your version of this file under the terms of the MPL, indicate your * decision by deleting the provisions above and replace them with the notice * and other provisions required by the GPL or the LGPL. If you do not delete * the provisions above, a recipient may use your version of this file under * the terms of any one of the MPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */ /// config bits: /// dbconfig.php sets up a connection for us, we should use it... include("../core/dbconfig.php"); // map the mysql main.type enum into the right type $ext_typemap = array('T' => 'theme', 'E' => 'extension', 'P' => 'plugin'); header("Content-type: text/rdf"); // error handling function bail ($errstr) { die("Error: " . $errstr); } // major.minor.release.build[+] // make sure this is a valid version function expandversion ($vstr) { $v = explode('.', $vstr); if ($vstr == '' || count($v) == 0 || count($v) > 4) { bail ('Bogus version.'); } $vlen = count($v); $ret = array(); $hasplus = 0; for ($i = 0; $i < 4; $i++) { if ($i > $vlen-1) { // this version chunk was not specified; give 0 $ret[] = 0; } else { $s = $v[$i]; if ($i == 3) { // need to check for + $slen = strlen($s); if ($s{$slen-1} == '+') { $s = substr($s, 0, $slen-1); $hasplus = 1; } } $ret[] = intval($s); } } $ret[] = $hasplus; return $ret; } function vercmp ($a, $b) { if ($a == $b) return 0; $va = expandversion($a); $vb = expandversion($b); for ($i = 0; $i < 5; $i++) if ($va[$i] != $vb[$i]) return ($vb[$i] - $va[$i]); return 0; } // // These are passed in the GET string / POST request // if (!array_key_exists('reqVersion', $_REQUEST)) bail ("Invalid request."); $reqVersion = $_REQUEST['reqVersion']; if ($reqVersion == 1) { 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."); // 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($_REQUEST['appOS']); } else { // bail bail ("Bad request version received"); } // check args if (empty($reqItemGuid) || empty($reqItemVersion) || empty($reqTargetAppGuid) || (count($reqItemGuid) != count($reqItemVersion))) { bail ("Invalid request."); } // We need to fetch two things for the database: // 1) The current extension version's info, for a possibly updated max version // 2) The latest version available, if different from the above. // // We know: // - $reqItemGuid // - $reqItemVersion // - $reqTargetAppGuid // - $reqTargetAppVersion // - $reqTargetOS // // We need to get: // - extension GUID // - extension version // - extension xpi link // - app ID // - app min version // - app max version /* os from UMO database 1 ALL 2 Linux 3 MacOSX 4 BSD 5 Solaris 6 Windows */ $osid = 0; /* If we do not get the OS from the URI, try the UA */ if ( ( $reqTargetOS == 'Linux' ) || ( strpos(getenv("HTTP_USER_AGENT"),"Linux") > 0 ) ) { $osid = 2; } if ( ( $reqTargetOS == 'Darwin' ) || ( strpos(getenv("HTTP_USER_AGENT"),"MAC") > 0 ) ) { $osid = 3; } if ( ( $reqTargetOS == 'BSD_OS' ) || ( strpos(getenv("HTTP_USER_AGENT"),"BSD") > 0 ) ) { $osid = 4; } if ( ( $reqTargetOS == 'SunOS' ) || ( strpos(getenv("HTTP_USER_AGENT"),"SOLARIS") > 0 ) ) { $osid = 5; } if ( ( $reqTargetOS == 'WINNT' ) || ( strpos(getenv("HTTP_USER_AGENT"),"WIN") > 0 ) ) { $osid = 6; } // // Now to spit out the RDF. We hand-generate because the data is pretty simple. // print "\n"; print "\n\n"; function print_update ($data) { global $ext_typemap; $dataItemType = $ext_typemap[$data['exttype']]; print "\n"; print " {$data['extversion']}\n"; print " \n"; print " \n"; print " {$data['appguid']}\n"; print " {$data['appminver']}\n"; print " {$data['appmaxver']}\n"; print " {$data['exturi']}\n"; print " \n"; print " \n"; print "\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, version.version AS extversion, version.uri AS exturi, version.minappver AS appminver, version.maxappver AS appmaxver, applications.guid AS appguid FROM main INNER JOIN version ON main.id = version.id INNER JOIN applications ON version.appid = applications.appid "; /* We want to filter the results so that only OS=ALL and OS specific results show up. */ $where = " WHERE main.guid = '" . $reqItemGuid[$i] . "' AND applications.guid = '" . $reqTargetAppGuid . "' AND (version.OSID = 1 OR version.OSID = " . $osid . ") AND version.approved = 'YES'"; /* Sort the result set so that the greatest OS Specific is the last one at each level. */ $order = " ORDER BY version.MaxAppVer_int DESC, version.version DESC, version.osid DESC"; $result = mysql_query ($query . $where . $order); if (!$result) { bail ('Query error: ' . mysql_error()); } // info for this version $thisVersionData = ''; // info for highest version $highestVersionData = ''; $itemType = ''; while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { if (empty($itemType)) { $itemType = $ext_typemap[$line['exttype']]; } // Do we already have the current or a newer one? if (vercmp($line['extversion'], $reqItemVersion[$i]) <= 0) { $thisVersionData = $line; break; } // Is this one compatible? if (vercmp($line['appmaxver'], $reqTargetAppVersion) >= 0 && vercmp($line['appminver'], $reqTargetAppVersion) <= 0) { $highestVersionData = $line; break; } // Keep going until we find one that is } print "\n"; // output list of updates (just highest and this) print " \n"; if (!empty($thisVersionData)) print " \n"; if (!empty($highestVersionData)) print " \n"; print " \n"; // output compat bits for firefox 0.9 if (!empty($highestVersionData)) { print " {$highestVersionData['extversion']}\n"; print " {$highestVersionData['exturi']}\n"; } print "\n\n"; if (!empty($thisVersionData)) print_update ($thisVersionData); if (!empty($highestVersionData)) print_update ($highestVersionData); mysql_free_result ($result); } print "\n"; ?>