llviewerassetupload.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. /**
  2. * @file llviewerassetupload.h
  3. * @brief Asset upload requests.
  4. *
  5. * $LicenseInfo:firstyear=2007&license=viewergpl$
  6. *
  7. * Copyright (c) 2007-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_VIEWER_ASSET_UPLOAD_H
  33. #define LL_VIEWER_ASSET_UPLOAD_H
  34. #include <deque>
  35. #include "llassetstorage.h"
  36. #include "llcorehttputil.h"
  37. #include "llfoldertype.h"
  38. #include "llimage.h"
  39. #include "llinventorytype.h"
  40. #include "llmutex.h"
  41. // Used to be in a separate llresourcedata.h file, but only used in
  42. // llviewerassetupload.cpp and in llfloaterreporter.cpp, both of which
  43. // #including llviewerassetupload.h...
  44. struct LLResourceData
  45. {
  46. LLAssetInfo mAssetInfo;
  47. LLFolderType::EType mPreferredLocation;
  48. LLInventoryType::EType mInventoryType;
  49. U32 mNextOwnerPerm;
  50. S32 mExpectedUploadCost;
  51. void* mUserData;
  52. static constexpr S8 INVALID_LOCATION = -2;
  53. };
  54. class LLResourceUploadInfo
  55. {
  56. protected:
  57. LOG_CLASS(LLResourceUploadInfo);
  58. public:
  59. typedef std::shared_ptr<LLResourceUploadInfo> ptr_t;
  60. LLResourceUploadInfo(const LLTransactionID& tid,
  61. LLAssetType::EType asset_type,
  62. const std::string& name,
  63. const std::string& description,
  64. S32 compression_info,
  65. LLFolderType::EType destination_type,
  66. LLInventoryType::EType inventory_type,
  67. U32 next_owner_perms, U32 group_perms,
  68. U32 everyone_perms, S32 expected_cost);
  69. virtual ~LLResourceUploadInfo() = default;
  70. virtual S32 getExpectedUploadCost();
  71. virtual LLSD prepareUpload();
  72. virtual LLSD generatePostBody();
  73. virtual void logPreparedUpload();
  74. virtual LLUUID finishUpload(const LLSD& result);
  75. LL_INLINE virtual void failedUpload(const LLSD& result,
  76. std::string& reason)
  77. {
  78. }
  79. LL_INLINE const LLTransactionID& getTransactionId() const
  80. {
  81. return mTransactionId;
  82. }
  83. LL_INLINE LLAssetType::EType getAssetType() const { return mAssetType; }
  84. std::string getAssetTypeString() const;
  85. LL_INLINE void setName(const std::string& name) { mName = name; }
  86. LL_INLINE const std::string& getName() const { return mName; }
  87. LL_INLINE const std::string& getDescription() const { return mDescription; }
  88. LL_INLINE S32 getCompressionInfo() const { return mCompressionInfo; }
  89. LL_INLINE LLFolderType::EType getDestinationFolderType() const
  90. {
  91. return mDestinationFolderType;
  92. }
  93. LL_INLINE LLInventoryType::EType getInventoryType() const
  94. {
  95. return mInventoryType;
  96. }
  97. std::string getInventoryTypeString() const;
  98. LL_INLINE U32 getNextOwnerPerms() const { return mNextOwnerPerms; }
  99. LL_INLINE U32 getGroupPerms() const { return mGroupPerms; }
  100. LL_INLINE U32 getEveryonePerms() const { return mEveryonePerms; }
  101. LL_INLINE virtual bool showUploadDialog() const { return true; }
  102. LL_INLINE void setShowInventoryPanel(bool show) { mShowInventoryPanel = show; }
  103. LL_INLINE bool showInventoryPanel() const { return mShowInventoryPanel; }
  104. virtual std::string getDisplayName() const;
  105. LL_INLINE const LLUUID& getFolderId() const { return mFolderId; }
  106. LL_INLINE const LLUUID& getItemId() const { return mItemId; }
  107. LL_INLINE const LLAssetID& getAssetId() const { return mAssetId; }
  108. // Additional "capability callback", for use with the global
  109. // upload_new_resource() utility function, when the latter creates the
  110. // new inventory item via the capability (the asset storage callback being
  111. // already passed as an optional parameter to upload_new_resource()).
  112. // This also can be used for any LLResourceUploadInfo and
  113. // LLNewFileResourceUploadInfo uploads that, unlike
  114. // LLBufferedAssetUploadInfo, do not have a finish callback mechanism.
  115. // In the case of upload_new_resource(), it will default to a callback
  116. // ensuring that the bulk uploads are chained one after the other. HB
  117. typedef void (*capability_cb_t)(const LLSD& result, void* userdata);
  118. LL_INLINE void setCapCallback(capability_cb_t cb, void* userdata)
  119. {
  120. mCapCallback = cb;
  121. mUserData = userdata;
  122. }
  123. LL_INLINE bool hasCapCallback() const { return mCapCallback != NULL; }
  124. void performCallback(const LLSD& result);
  125. protected:
  126. LLResourceUploadInfo(const std::string& name,
  127. const std::string& description,
  128. S32 compression_info,
  129. LLFolderType::EType destination_type,
  130. LLInventoryType::EType inventory_type,
  131. U32 next_owner_perms, U32 group_perms,
  132. U32 everyone_perms, S32 expected_cost);
  133. LLResourceUploadInfo(const LLAssetID& asset_id,
  134. LLAssetType::EType asset_type,
  135. const std::string& name);
  136. LL_INLINE void setTransactionId(const LLTransactionID& tid)
  137. {
  138. mTransactionId = tid;
  139. }
  140. LL_INLINE void setAssetType(LLAssetType::EType t) { mAssetType = t; }
  141. LL_INLINE void setItemId(const LLUUID& id) { mItemId = id; }
  142. LL_INLINE void setAssetId(const LLUUID& id) { mAssetId = id; }
  143. LL_INLINE void setExpectedUploadCost(S32 c) { mExpectedUploadCost = c; }
  144. LLAssetID generateNewAssetId();
  145. void incrementUploadStats() const;
  146. virtual void assignDefaults();
  147. private:
  148. LLTransactionID mTransactionId;
  149. LLAssetType::EType mAssetType;
  150. std::string mName;
  151. std::string mDescription;
  152. S32 mCompressionInfo;
  153. LLFolderType::EType mDestinationFolderType;
  154. LLInventoryType::EType mInventoryType;
  155. U32 mNextOwnerPerms;
  156. U32 mGroupPerms;
  157. U32 mEveryonePerms;
  158. S32 mExpectedUploadCost;
  159. LLUUID mFolderId;
  160. LLUUID mItemId;
  161. LLAssetID mAssetId;
  162. capability_cb_t mCapCallback;
  163. void* mUserData;
  164. bool mShowInventoryPanel;
  165. };
  166. class LLNewFileResourceUploadInfo : public LLResourceUploadInfo
  167. {
  168. protected:
  169. LOG_CLASS(LLNewFileResourceUploadInfo);
  170. public:
  171. LLNewFileResourceUploadInfo(const std::string& filename,
  172. const std::string& name,
  173. const std::string& description,
  174. S32 compression_info,
  175. LLFolderType::EType destination_type,
  176. LLInventoryType::EType inventory_type,
  177. U32 next_owner_perms, U32 group_perms,
  178. U32 everyone_perms, S32 expected_cost);
  179. virtual LLSD prepareUpload();
  180. LL_INLINE const std::string& getFileName() const { return mFileName; }
  181. LL_INLINE void setIsBulkUpload() { mIsBulkUpload = true; }
  182. protected:
  183. virtual LLSD exportTempFile();
  184. private:
  185. std::string mFileName;
  186. bool mIsBulkUpload;
  187. };
  188. class LLNewBufferedResourceUploadInfo : public LLResourceUploadInfo
  189. {
  190. protected:
  191. LOG_CLASS(LLNewBufferedResourceUploadInfo);
  192. public:
  193. typedef boost::function<void(LLUUID new_asset_id,
  194. LLSD response)> uploaded_cb_t;
  195. typedef boost::function<void(const LLUUID& asset_id, const LLSD& response,
  196. std::string reason)> failed_cb_t;
  197. LLNewBufferedResourceUploadInfo(const std::string& buffer,
  198. const LLAssetID& asset_id,
  199. const std::string& name,
  200. const std::string& description,
  201. S32 compression_info,
  202. LLFolderType::EType destination_type,
  203. LLInventoryType::EType inventory_type,
  204. LLAssetType::EType asset_type,
  205. U32 next_owner_perms, U32 group_perms,
  206. U32 everyone_perms, S32 expected_cost,
  207. uploaded_cb_t finish,
  208. failed_cb_t fail = failed_cb_t());
  209. virtual LLSD prepareUpload();
  210. protected:
  211. virtual LLSD exportTempFile();
  212. virtual LLUUID finishUpload(const LLSD& result);
  213. virtual void failedUpload(const LLSD& result, std::string& reason);
  214. private:
  215. uploaded_cb_t mFinishFn;
  216. failed_cb_t mFailureFn;
  217. std::string mBuffer;
  218. };
  219. class LLBufferedAssetUploadInfo : public LLResourceUploadInfo
  220. {
  221. protected:
  222. LOG_CLASS(LLBufferedAssetUploadInfo);
  223. public:
  224. typedef boost::function<void(LLUUID item_id,
  225. LLUUID new_asset_id,
  226. LLUUID new_item_id,
  227. LLSD response)> inv_uploaded_cb_t;
  228. typedef boost::function<void(LLUUID item_id,
  229. LLUUID task_id,
  230. LLUUID new_asset_id,
  231. LLSD response)> task_uploaded_cb_t;
  232. typedef boost::function<void(const LLUUID& item_id, const LLUUID& task_id,
  233. const LLSD& response,
  234. std::string reason)> failed_cb_t;
  235. LLBufferedAssetUploadInfo(const LLUUID& item_id,
  236. LLAssetType::EType asset_type,
  237. const std::string& buffer,
  238. inv_uploaded_cb_t finish,
  239. failed_cb_t failed = failed_cb_t());
  240. LLBufferedAssetUploadInfo(const LLUUID& item_id,
  241. LLPointer<LLImageFormatted> image,
  242. inv_uploaded_cb_t finish);
  243. LLBufferedAssetUploadInfo(const LLUUID& task_id, const LLUUID& item_id,
  244. LLAssetType::EType assetType,
  245. const std::string& buffer,
  246. task_uploaded_cb_t finish,
  247. failed_cb_t failed = failed_cb_t());
  248. virtual LLSD prepareUpload();
  249. virtual LLSD generatePostBody();
  250. virtual LLUUID finishUpload(const LLSD& result);
  251. virtual void failedUpload(const LLSD& result, std::string& reason);
  252. LL_INLINE const LLUUID& getTaskId() const { return mTaskId; }
  253. LL_INLINE const std::string& getContents() const { return mContents; }
  254. LL_INLINE virtual bool showUploadDialog() const { return false; }
  255. private:
  256. LLUUID mTaskId;
  257. std::string mContents;
  258. inv_uploaded_cb_t mInvnFinishFn;
  259. task_uploaded_cb_t mTaskFinishFn;
  260. failed_cb_t mFailureFn;
  261. bool mTaskUpload;
  262. bool mStoredToCache;
  263. };
  264. class LLScriptAssetUpload : public LLBufferedAssetUploadInfo
  265. {
  266. protected:
  267. LOG_CLASS(LLScriptAssetUpload);
  268. public:
  269. enum TargetType_t
  270. {
  271. LSL2,
  272. MONO
  273. };
  274. LLScriptAssetUpload(const LLUUID& item_id, const std::string& buffer,
  275. TargetType_t target_type, inv_uploaded_cb_t finish,
  276. failed_cb_t failed);
  277. LLScriptAssetUpload(const LLUUID& task_id, const LLUUID& item_id,
  278. TargetType_t target_type, bool running,
  279. const LLUUID& exerience_id, const std::string& buffer,
  280. task_uploaded_cb_t finish, failed_cb_t failed);
  281. virtual LLSD generatePostBody();
  282. LL_INLINE const LLUUID& getExerienceId() const { return mExerienceId; }
  283. LL_INLINE TargetType_t getTargetType() const { return mTargetType; }
  284. LL_INLINE bool getIsRunning() const { return mIsRunning; }
  285. private:
  286. LLUUID mExerienceId;
  287. TargetType_t mTargetType;
  288. bool mIsRunning;
  289. };
  290. class LLViewerAssetUpload
  291. {
  292. protected:
  293. LOG_CLASS(LLViewerAssetUpload);
  294. public:
  295. static LLUUID enqueueInventoryUpload(const std::string& url,
  296. const LLResourceUploadInfo::ptr_t& info);
  297. static void assetInventoryUploadCoproc(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t& adapter,
  298. std::string url,
  299. LLResourceUploadInfo::ptr_t info);
  300. private:
  301. static void handleUploadError(LLCore::HttpStatus status,
  302. const LLSD& result,
  303. LLResourceUploadInfo::ptr_t& uploadInfo);
  304. };
  305. // Bulk uploads queue
  306. extern std::deque<std::string> gUploadQueue;
  307. extern LLMutex gUploadQueueMutex;
  308. // Global utility function for uploading assets
  309. void upload_new_resource(LLResourceUploadInfo::ptr_t& info,
  310. LLAssetStorage::LLStoreAssetCallback callback = NULL,
  311. void* userdata = NULL, bool temp_upload = false);
  312. // Internal callback also used in llviewermenu.cpp to initiate bulk uploads.
  313. void process_bulk_upload_queue(const LLSD& result = LLSD(),
  314. void* userdata = NULL);
  315. // This callback was originally part of llassetuploadresponders.h/cpp
  316. void on_new_single_inventory_upload_complete(LLAssetType::EType asset_type,
  317. LLInventoryType::EType inventory_type,
  318. const std::string inventory_type_string,
  319. const LLUUID& item_folder_id,
  320. const std::string& item_name,
  321. const std::string& item_description,
  322. const LLSD& server_response,
  323. S32 upload_price);
  324. #endif // VIEWER_ASSET_UPLOAD_H