UpdateManager.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright (c) 2002-2009 Moxie Marlinspike
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 3 of the
  7. * License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  17. * USA
  18. */
  19. #include "UpdateManager.hpp"
  20. #include "util/Util.hpp"
  21. #include <boost/filesystem.hpp>
  22. #define BUILD_ID "2010011112"
  23. #define UPDATE_ADDRESS "aus2.mozilla.org"
  24. #define ADDONS_ADDRESS "versioncheck.addons.mozilla.org"
  25. using namespace boost::asio;
  26. UpdateManager* UpdateManager::updateManager = new UpdateManager();
  27. UpdateManager* UpdateManager::getInstance() {
  28. return updateManager;
  29. }
  30. void UpdateManager::initialize(std::string &updatePath, std::string &addonPath, std::string &addonHash) {
  31. this->updatePath = updatePath;
  32. this->addonPath = addonPath;
  33. this->addonHash = addonHash;
  34. std::string updateUrl(UPDATE_ADDRESS);
  35. std::string addonsUrl(ADDONS_ADDRESS);
  36. Util::resolveName(updateUrl, updateAddresses);
  37. Util::resolveName(addonsUrl, addonsAddresses);
  38. }
  39. bool UpdateManager::isUpdatableRequest(std::string &buildId, std::string &buildTarget) {
  40. return
  41. buildId != BUILD_ID &&
  42. boost::filesystem::exists(updatePath + "/" + buildTarget + ".xml");
  43. }
  44. bool UpdateManager::isAddressInList(ip::tcp::endpoint &endpoint, std::list<boost::asio::ip::address> addresses) {
  45. ip::address address = endpoint.address();
  46. std::list<ip::address>::iterator i = addresses.begin();
  47. std::list<ip::address>::iterator end = addresses.end();
  48. for ( ; i != end ; i++) {
  49. if ((*i) == address) return true;
  50. }
  51. return false;
  52. }
  53. bool UpdateManager::isAddonTarget(ip::tcp::endpoint &endpoint) {
  54. if (addonPath.empty()) return false;
  55. return isAddressInList(endpoint, addonsAddresses);
  56. }
  57. bool UpdateManager::isUpdateTarget(ip::tcp::endpoint &endpoint) {
  58. if (updatePath.empty()) return false;
  59. return isAddressInList(endpoint, updateAddresses);
  60. }
  61. void UpdateManager::getUpdatePath(std::string &buildTarget, std::string &result) {
  62. result = updatePath + "/" + buildTarget + ".xml";
  63. }
  64. std::string UpdateManager::getAddonPath() {
  65. return addonPath;
  66. }
  67. std::string UpdateManager::getAddonHash() {
  68. return addonHash;
  69. }