/toolkit/mozapps/plugins/service/PluginFinderService.php

http://github.com/zpao/v8monkey · PHP · 196 lines · 114 code · 31 blank · 51 comment · 30 complexity · 9775ef249daaf0c3abb5bd29c4604b28 MD5 · raw file

  1. <?php
  2. /* -*- Mode: php; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  3. /* ***** BEGIN LICENSE BLOCK *****
  4. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  5. *
  6. * The contents of this file are subject to the Mozilla Public License Version
  7. * 1.1 (the "License"); you may not use this file except in compliance with
  8. * the License. You may obtain a copy of the License at
  9. * http://www.mozilla.org/MPL/
  10. *
  11. * Software distributed under the License is distributed on an "AS IS" basis,
  12. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  13. * for the specific language governing rights and limitations under the
  14. * License.
  15. *
  16. * The Original Code is the Plugin Finder Service.
  17. *
  18. * The Initial Developer of the Original Code is Vladimir Vukicevic.
  19. * Portions created by the Initial Developer are Copyright (C) 2004
  20. * the Initial Developer. All Rights Reserved.
  21. *
  22. * Contributor(s):
  23. * Vladimir Vukicevic <vladimir@pobox.com>
  24. * Doron Rosenberg <doronr@us.ibm.com>
  25. *
  26. * Alternatively, the contents of this file may be used under the terms of
  27. * either the GNU General Public License Version 2 or later (the "GPL"), or
  28. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  29. * in which case the provisions of the GPL or the LGPL are applicable instead
  30. * of those above. If you wish to allow use of your version of this file only
  31. * under the terms of either the GPL or the LGPL, and not to allow others to
  32. * use your version of this file under the terms of the MPL, indicate your
  33. * decision by deleting the provisions above and replace them with the notice
  34. * and other provisions required by the GPL or the LGPL. If you do not delete
  35. * the provisions above, a recipient may use your version of this file under
  36. * the terms of any one of the MPL, the GPL or the LGPL.
  37. *
  38. * ***** END LICENSE BLOCK ***** */
  39. /// config bits:
  40. $db_server = "";
  41. $db_user = "";
  42. $db_pass = "";
  43. $db_name = "";
  44. // error handling
  45. function bail ($errstr) {
  46. die("Error: " . $errstr);
  47. }
  48. // major.minor.release.build[+]
  49. // make sure this is a valid version
  50. function expandversion ($vstr) {
  51. $v = explode('.', $vstr);
  52. if ($vstr == '' || count($v) == 0 || count($v) > 4) {
  53. bail ('Bogus version.');
  54. }
  55. $vlen = count($v);
  56. $ret = array();
  57. $hasplus = 0;
  58. for ($i = 0; $i < 4; $i++) {
  59. if ($i > $vlen-1) {
  60. // this version chunk was not specified; give 0
  61. $ret[] = 0;
  62. } else {
  63. $s = $v[$i];
  64. if ($i == 3) {
  65. // need to check for +
  66. $slen = strlen($s);
  67. if ($s{$slen-1} == '+') {
  68. $s = substr($s, 0, $slen-1);
  69. $hasplus = 1;
  70. }
  71. }
  72. $ret[] = intval($s);
  73. }
  74. }
  75. $ret[] = $hasplus;
  76. return $ret;
  77. }
  78. function vercmp ($a, $b) {
  79. if ($a == $b)
  80. return 0;
  81. $va = expandversion($a);
  82. $vb = expandversion($b);
  83. for ($i = 0; $i < 5; $i++)
  84. if ($va[$i] != $vb[$i])
  85. return ($vb[$i] - $va[$i]);
  86. return 0;
  87. }
  88. //
  89. // These are passed in the GET string
  90. //
  91. if (!array_key_exists('mimetype', $_GET))
  92. bail ("Invalid request.");
  93. $mimetype = $_GET['mimetype'];
  94. if (!array_key_exists('appID', $_GET)
  95. || !array_key_exists('appVersion', $_GET)
  96. || !array_key_exists('clientOS', $_GET))
  97. || !array_key_exists('chromeLocale', $_GET))
  98. )
  99. bail ("Invalid request.");
  100. $reqTargetAppGuid = $_GET['appID'];
  101. $reqTargetAppVersion = $_GET['appVersion'];
  102. $clientOS = $_GET['clientOS'];
  103. $chromeLocale = $_GET['chromeLocale'];
  104. // check args
  105. if (empty($reqTargetAppVersion) || empty($reqTargetAppGuid)) {
  106. bail ("Invalid request.");
  107. }
  108. //
  109. // Now to spit out the RDF. We hand-generate because the data is pretty simple.
  110. //
  111. if ($mimetype == "application/x-mtx") {
  112. $name = "Viewpoint Media Player";
  113. $guid = "{03F998B2-0E00-11D3-A498-00104B6EB52E}";
  114. $version = "5.0";
  115. $iconUrl = "";
  116. $XPILocation = "http://www.nexgenmedia.net/flashlinux/invalid.xpi";
  117. $InstallerShowsUI = false;
  118. $manualInstallationURL = "http://www.viewpoint.com/pub/products/vmp.html";
  119. $licenseURL = "http://www.viewpoint.com/pub/privacy.html";
  120. } else if ($mimetype == "application/x-shockwave-flash") {
  121. $name = "Flash Player";
  122. $guid = "{D27CDB6E-AE6D-11cf-96B8-444553540000}";
  123. $version = "7.0.16";
  124. $iconUrl = "http://goat.austin.ibm.com:8080/flash.gif";
  125. $XPILocation = "http://www.nexgenmedia.net/flashlinux/flash-linux.xpi";
  126. $InstallerShowsUI = "false";
  127. $manualInstallationURL = "http://www.macromedia.com/go/getflashplayer";
  128. $licenseURL = "http://www.macromedia.com/shockwave/download/license/desktop/";
  129. } else {
  130. $name = "";
  131. $guid = "-1";
  132. $version = "";
  133. $iconUrl = "";
  134. $XPILocation = "";
  135. $InstallerShowsUI = "";
  136. $manualInstallationURL = "";
  137. $licenseURL = "";
  138. }
  139. header("Content-type: application/xml");
  140. print "<?xml version=\"1.0\"?>\n";
  141. print "<RDF:RDF xmlns:RDF=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:pfs=\"http://www.mozilla.org/2004/pfs-rdf#\">\n\n";
  142. print "<RDF:Description about=\"urn:mozilla:plugin-results:{$mimetype}\">\n";
  143. // output list of matching plugins
  144. print " <pfs:plugins><RDF:Seq>\n";
  145. print " <RDF:li resource=\"urn:mozilla:plugin:{$guid}\"/>\n";
  146. print " </RDF:Seq></pfs:plugins>\n";
  147. print "</RDF:Description>\n\n";
  148. print "<RDF:Description about=\"urn:mozilla:plugin:{$guid}\">\n";
  149. print " <pfs:updates><RDF:Seq>\n";
  150. print " <RDF:li resource=\"urn:mozilla:plugin:{$guid}:{$version}\"/>\n";
  151. print " </RDF:Seq></pfs:updates>\n";
  152. print "</RDF:Description>\n\n";
  153. print "<RDF:Description about=\"urn:mozilla:plugin:{$guid}:{$version}\">\n";
  154. print " <pfs:name>{$name}</pfs:name>\n";
  155. print " <pfs:requestedMimetype>{$mimetype}</pfs:requestedMimetype>\n";
  156. print " <pfs:guid>{$guid}</pfs:guid>\n";
  157. print " <pfs:version>{$version}</pfs:version>\n";
  158. print " <pfs:IconUrl>{$iconUrl}</pfs:IconUrl>\n";
  159. print " <pfs:XPILocation>{$XPILocation}</pfs:XPILocation>\n";
  160. print " <pfs:InstallerShowsUI>{$InstallerShowsUI}</pfs:InstallerShowsUI>\n";
  161. print " <pfs:manualInstallationURL>{$manualInstallationURL}</pfs:manualInstallationURL>\n";
  162. print " <pfs:licenseURL>{$licenseURL}</pfs:licenseURL>\n";
  163. print "</RDF:Description>\n\n";
  164. print "</RDF:RDF>\n";
  165. ?>