aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llmessage/lltransfersourceasset.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/llmessage/lltransfersourceasset.cpp
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/llmessage/lltransfersourceasset.cpp')
-rw-r--r--linden/indra/llmessage/lltransfersourceasset.cpp296
1 files changed, 296 insertions, 0 deletions
diff --git a/linden/indra/llmessage/lltransfersourceasset.cpp b/linden/indra/llmessage/lltransfersourceasset.cpp
new file mode 100644
index 0000000..0285896
--- /dev/null
+++ b/linden/indra/llmessage/lltransfersourceasset.cpp
@@ -0,0 +1,296 @@
1/**
2 * @file lltransfersourceasset.cpp
3 * @brief Transfer system for sending an asset.
4 *
5 * Copyright (c) 2006-2007, Linden Research, Inc.
6 *
7 * The source code in this file ("Source Code") is provided by Linden Lab
8 * to you under the terms of the GNU General Public License, version 2.0
9 * ("GPL"), unless you have obtained a separate licensing agreement
10 * ("Other License"), formally executed by you and Linden Lab. Terms of
11 * the GPL can be found in doc/GPL-license.txt in this distribution, or
12 * online at http://secondlife.com/developers/opensource/gplv2
13 *
14 * There are special exceptions to the terms and conditions of the GPL as
15 * it is applied to this Source Code. View the full text of the exception
16 * in the file doc/FLOSS-exception.txt in this software distribution, or
17 * online at http://secondlife.com/developers/opensource/flossexception
18 *
19 * By copying, modifying or distributing this software, you acknowledge
20 * that you have read and understood your obligations described above,
21 * and agree to abide by those obligations.
22 *
23 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
24 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
25 * COMPLETENESS OR PERFORMANCE.
26 */
27
28#include "linden_common.h"
29
30#include "lltransfersourceasset.h"
31
32#include "llerror.h"
33#include "message.h"
34#include "lldatapacker.h"
35#include "lldir.h"
36#include "llvfile.h"
37
38LLTransferSourceAsset::LLTransferSourceAsset(const LLUUID &request_id, const F32 priority) :
39 LLTransferSource(LLTST_ASSET, request_id, priority),
40 mGotResponse(FALSE),
41 mCurPos(0)
42{
43}
44
45LLTransferSourceAsset::~LLTransferSourceAsset()
46{
47}
48
49
50void LLTransferSourceAsset::initTransfer()
51{
52 if (gAssetStorage)
53 {
54 // *HACK: asset transfers will only be coming from the viewer
55 // to the simulator. This is subset of assets we allow to be
56 // simply pulled straight from the asset system.
57 LLUUID* tidp;
58 if(is_asset_fetch_by_id_allowed(mParams.getAssetType()))
59 {
60 tidp = new LLUUID(getID());
61 gAssetStorage->getAssetData(
62 mParams.getAssetID(),
63 mParams.getAssetType(),
64 LLTransferSourceAsset::responderCallback,
65 tidp,
66 FALSE);
67 }
68 else
69 {
70 llwarns << "Attempted to request blocked asset "
71 << mParams.getAssetID() << ":"
72 << LLAssetType::lookupHumanReadable(mParams.getAssetType())
73 << llendl;
74 sendTransferStatus(LLTS_ERROR);
75 }
76 }
77 else
78 {
79 llwarns << "Attempted to request asset " << mParams.getAssetID()
80 << ":" << LLAssetType::lookupHumanReadable(mParams.getAssetType())
81 << " without an asset system!" << llendl;
82 sendTransferStatus(LLTS_ERROR);
83 }
84}
85
86F32 LLTransferSourceAsset::updatePriority()
87{
88 return 0.f;
89}
90
91LLTSCode LLTransferSourceAsset::dataCallback(const S32 packet_id,
92 const S32 max_bytes,
93 U8 **data_handle,
94 S32 &returned_bytes,
95 BOOL &delete_returned)
96{
97 //llinfos << "LLTransferSourceAsset::dataCallback" << llendl;
98 if (!mGotResponse)
99 {
100 return LLTS_SKIP;
101 }
102
103 LLVFile vf(gAssetStorage->mVFS, mParams.getAssetID(), mParams.getAssetType(), LLVFile::READ);
104
105 if (!vf.getSize())
106 {
107 // Something bad happened with the asset request!
108 return LLTS_ERROR;
109 }
110
111 if (packet_id != mLastPacketID + 1)
112 {
113 llerrs << "Can't handle out of order file transfer yet!" << llendl;
114 }
115
116 // grab a buffer from the right place in the file
117 if (!vf.seek(mCurPos, 0))
118 {
119 llwarns << "LLTransferSourceAsset Can't seek to " << mCurPos << " length " << vf.getSize() << llendl;
120 llwarns << "While sending " << mParams.getAssetID() << llendl;
121 return LLTS_ERROR;
122 }
123
124 delete_returned = TRUE;
125 U8 *tmpp = new U8[max_bytes];
126 *data_handle = tmpp;
127 if (!vf.read(tmpp, max_bytes)) /* Flawfinder: Ignore */
128 {
129 // Crap, read failure, need to deal with it.
130 delete[] tmpp;
131 *data_handle = NULL;
132 returned_bytes = 0;
133 delete_returned = FALSE;
134 return LLTS_ERROR;
135 }
136
137 returned_bytes = vf.getLastBytesRead();
138 mCurPos += returned_bytes;
139
140
141 if (vf.eof())
142 {
143 if (!returned_bytes)
144 {
145 delete[] tmpp;
146 *data_handle = NULL;
147 returned_bytes = 0;
148 delete_returned = FALSE;
149 }
150 return LLTS_DONE;
151 }
152
153 return LLTS_OK;
154}
155
156void LLTransferSourceAsset::completionCallback(const LLTSCode status)
157{
158 // No matter what happens, all we want to do is close the vfile if
159 // we've got it open.
160}
161
162void LLTransferSourceAsset::packParams(LLDataPacker& dp) const
163{
164 //llinfos << "LLTransferSourceAsset::packParams" << llendl;
165 mParams.packParams(dp);
166}
167
168BOOL LLTransferSourceAsset::unpackParams(LLDataPacker &dp)
169{
170 //llinfos << "LLTransferSourceAsset::unpackParams" << llendl;
171 return mParams.unpackParams(dp);
172}
173
174
175void LLTransferSourceAsset::responderCallback(LLVFS *vfs, const LLUUID& uuid, LLAssetType::EType type,
176 void *user_data, S32 result)
177{
178 LLUUID *tidp = ((LLUUID*) user_data);
179 LLUUID transfer_id = *(tidp);
180 delete tidp;
181 tidp = NULL;
182
183 LLTransferSourceAsset *tsap = (LLTransferSourceAsset *) gTransferManager.findTransferSource(transfer_id);
184
185 if (!tsap)
186 {
187 llinfos << "Aborting transfer " << transfer_id << " callback, transfer source went away" << llendl;
188 return;
189 }
190
191 if (result)
192 {
193 llinfos << "AssetStorage: Error " << gAssetStorage->getErrorString(result) << " downloading uuid " << uuid << llendl;
194 }
195
196 LLTSCode status;
197
198 tsap->mGotResponse = TRUE;
199 if (LL_ERR_NOERR == result)
200 {
201 // Everything's OK.
202 LLVFile vf(gAssetStorage->mVFS, uuid, type, LLVFile::READ);
203 tsap->mSize = vf.getSize();
204 status = LLTS_OK;
205 }
206 else
207 {
208 // Uh oh, something bad happened when we tried to get this asset!
209 switch (result)
210 {
211 case LL_ERR_ASSET_REQUEST_NOT_IN_DATABASE:
212 status = LLTS_UNKNOWN_SOURCE;
213 break;
214 default:
215 status = LLTS_ERROR;
216 }
217 }
218
219 tsap->sendTransferStatus(status);
220}
221
222
223
224LLTransferSourceParamsAsset::LLTransferSourceParamsAsset() : LLTransferSourceParams(LLTST_ASSET)
225{
226}
227
228void LLTransferSourceParamsAsset::setAsset(const LLUUID &asset_id, const LLAssetType::EType asset_type)
229{
230 mAssetID = asset_id;
231 mAssetType = asset_type;
232}
233
234void LLTransferSourceParamsAsset::packParams(LLDataPacker &dp) const
235{
236 dp.packUUID(mAssetID, "AssetID");
237 dp.packS32(mAssetType, "AssetType");
238}
239
240
241BOOL LLTransferSourceParamsAsset::unpackParams(LLDataPacker &dp)
242{
243 S32 tmp_at;
244
245 dp.unpackUUID(mAssetID, "AssetID");
246 dp.unpackS32(tmp_at, "AssetType");
247
248 mAssetType = (LLAssetType::EType)tmp_at;
249
250 return TRUE;
251}
252
253/**
254 * Helper functions
255 */
256bool is_asset_fetch_by_id_allowed(LLAssetType::EType type)
257{
258 // *FIX: Make this list smaller.
259 bool rv = false;
260 switch(type)
261 {
262 case LLAssetType::AT_SOUND:
263 case LLAssetType::AT_LANDMARK:
264 case LLAssetType::AT_CLOTHING:
265 case LLAssetType::AT_BODYPART:
266 case LLAssetType::AT_ANIMATION:
267 case LLAssetType::AT_GESTURE:
268 rv = true;
269 break;
270 default:
271 break;
272 }
273 return rv;
274}
275
276bool is_asset_id_knowable(LLAssetType::EType type)
277{
278 // *FIX: Make this list smaller.
279 bool rv = false;
280 switch(type)
281 {
282 case LLAssetType::AT_TEXTURE:
283 case LLAssetType::AT_SOUND:
284 case LLAssetType::AT_LANDMARK:
285 case LLAssetType::AT_CLOTHING:
286 case LLAssetType::AT_NOTECARD:
287 case LLAssetType::AT_BODYPART:
288 case LLAssetType::AT_ANIMATION:
289 case LLAssetType::AT_GESTURE:
290 rv = true;
291 break;
292 default:
293 break;
294 }
295 return rv;
296}