PageRenderTime 26ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llmessage/llhttpassetstorage.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 159 lines | 93 code | 32 blank | 34 comment | 0 complexity | 317355f8ee237c531e1e60938d5f7b35 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llhttpassetstorage.h
  3. * @brief Class for loading asset data to/from an external source over http.
  4. *
  5. * $LicenseInfo:firstyear=2003&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LLHTTPASSETSTORAGE_H
  27. #define LLHTTPASSETSTORAGE_H
  28. #include "llassetstorage.h"
  29. #include "curl/curl.h"
  30. class LLVFile;
  31. class LLHTTPAssetRequest;
  32. typedef void (*progress_callback)(void* userdata);
  33. struct LLTempAssetData;
  34. typedef std::map<LLUUID,LLTempAssetData> uuid_tempdata_map;
  35. class LLHTTPAssetStorage : public LLAssetStorage
  36. {
  37. public:
  38. LLHTTPAssetStorage(LLMessageSystem *msg, LLXferManager *xfer,
  39. LLVFS *vfs, LLVFS *static_vfs,
  40. const LLHost &upstream_host,
  41. const std::string& web_host,
  42. const std::string& local_web_host,
  43. const std::string& host_name);
  44. LLHTTPAssetStorage(LLMessageSystem *msg, LLXferManager *xfer,
  45. LLVFS *vfs, LLVFS *static_vfs,
  46. const std::string& web_host,
  47. const std::string& local_web_host,
  48. const std::string& host_name);
  49. virtual ~LLHTTPAssetStorage();
  50. using LLAssetStorage::storeAssetData; // Unhiding virtuals...
  51. virtual void storeAssetData(
  52. const LLUUID& uuid,
  53. LLAssetType::EType atype,
  54. LLStoreAssetCallback callback,
  55. void* user_data,
  56. bool temp_file = false,
  57. bool is_priority = false,
  58. bool store_local = false,
  59. const LLUUID& requesting_agent_id = LLUUID::null,
  60. bool user_waiting=FALSE,
  61. F64 timeout=LL_ASSET_STORAGE_TIMEOUT);
  62. virtual void storeAssetData(
  63. const std::string& filename,
  64. const LLUUID& asset_id,
  65. LLAssetType::EType atype,
  66. LLStoreAssetCallback callback,
  67. void* user_data,
  68. bool temp_file,
  69. bool is_priority,
  70. bool user_waiting=FALSE,
  71. F64 timeout=LL_ASSET_STORAGE_TIMEOUT);
  72. virtual LLSD getPendingDetails(ERequestType rt,
  73. LLAssetType::EType asset_type,
  74. const std::string& detail_prefix) const;
  75. virtual LLSD getPendingRequest(ERequestType rt,
  76. LLAssetType::EType asset_type,
  77. const LLUUID& asset_id) const;
  78. virtual bool deletePendingRequest(ERequestType rt,
  79. LLAssetType::EType asset_type,
  80. const LLUUID& asset_id);
  81. // Hack. One off curl download an URL to a file. Probably should be elsewhere.
  82. // Only used by lldynamicstate. The API is broken, and should be replaced with
  83. // a generic HTTP file fetch - Doug 9/25/06
  84. S32 getURLToFile(const LLUUID& uuid, LLAssetType::EType asset_type, const std::string &url, const std::string& filename, progress_callback callback, void *userdata);
  85. LLAssetRequest* findNextRequest(request_list_t& pending, request_list_t& running);
  86. void checkForTimeouts();
  87. static size_t curlDownCallback(void *data, size_t size, size_t nmemb, void *user_data);
  88. static size_t curlFileDownCallback(void *data, size_t size, size_t nmemb, void *user_data);
  89. static size_t curlUpCallback(void *data, size_t size, size_t nmemb, void *user_data);
  90. static size_t nullOutputCallback(void *data, size_t size, size_t nmemb, void *user_data);
  91. // Should only be used by the LLHTTPAssetRequest
  92. void addRunningRequest(ERequestType rt, LLHTTPAssetRequest* request);
  93. void removeRunningRequest(ERequestType rt, LLHTTPAssetRequest* request);
  94. request_list_t* getRunningList(ERequestType rt);
  95. const request_list_t* getRunningList(ERequestType rt) const;
  96. // Temp assets are stored on sim nodes, they have agent ID and location data associated with them.
  97. virtual void addTempAssetData(const LLUUID& asset_id, const LLUUID& agent_id, const std::string& host_name);
  98. virtual BOOL hasTempAssetData(const LLUUID& texture_id) const;
  99. virtual std::string getTempAssetHostName(const LLUUID& texture_id) const;
  100. virtual LLUUID getTempAssetAgentID(const LLUUID& texture_id) const;
  101. virtual void removeTempAssetData(const LLUUID& asset_id);
  102. virtual void removeTempAssetDataByAgentID(const LLUUID& agent_id);
  103. // Pass LLUUID::null for all
  104. virtual void dumpTempAssetData(const LLUUID& avatar_id) const;
  105. virtual void clearTempAssetData();
  106. protected:
  107. void _queueDataRequest(const LLUUID& uuid, LLAssetType::EType type,
  108. void (*callback)(LLVFS *vfs, const LLUUID&, LLAssetType::EType, void *, S32, LLExtStat),
  109. void *user_data, BOOL duplicate, BOOL is_priority);
  110. private:
  111. void _init(const std::string& web_host, const std::string& local_web_host, const std::string& host_name);
  112. // This will return the correct base URI for any http asset request
  113. std::string getBaseURL(const LLUUID& asset_id, LLAssetType::EType asset_type);
  114. // Check for running uploads that have timed out
  115. // Bump these to the back of the line to let other uploads complete.
  116. void bumpTimedOutUploads();
  117. protected:
  118. std::string mBaseURL;
  119. std::string mLocalBaseURL;
  120. std::string mHostName;
  121. CURLM *mCurlMultiHandle;
  122. request_list_t mRunningDownloads;
  123. request_list_t mRunningUploads;
  124. request_list_t mRunningLocalUploads;
  125. uuid_tempdata_map mTempAssets;
  126. };
  127. #endif