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

