Annotation of /trunk/indra/newview/llviewerassetstorage.cpp
Parent Directory
|
Revision Log
Revision 137 - (view) (download)
| 1 : | mjm | 135 | /** |
| 2 : | * @file llviewerassetstorage.cpp | ||
| 3 : | * @brief Subclass capable of loading asset data to/from an external source. | ||
| 4 : | * | ||
| 5 : | * $LicenseInfo:firstyear=2003&license=viewergpl$ | ||
| 6 : | * | ||
| 7 : | mjm | 137 | * Copyright (c) 2003-2010, Linden Research, Inc. |
| 8 : | mjm | 135 | * |
| 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 : | |||
| 33 : | #include "llviewerprecompiledheaders.h" | ||
| 34 : | |||
| 35 : | #include "linden_common.h" | ||
| 36 : | |||
| 37 : | #include "llagent.h" | ||
| 38 : | #include "llviewerassetstorage.h" | ||
| 39 : | #include "llviewerbuild.h" | ||
| 40 : | #include "llvfile.h" | ||
| 41 : | #include "llvfs.h" | ||
| 42 : | |||
| 43 : | LLViewerAssetStorage::LLViewerAssetStorage(LLMessageSystem *msg, LLXferManager *xfer, | ||
| 44 : | LLVFS *vfs, const LLHost &upstream_host) | ||
| 45 : | : LLAssetStorage(msg, xfer, vfs, upstream_host) | ||
| 46 : | { | ||
| 47 : | } | ||
| 48 : | |||
| 49 : | |||
| 50 : | LLViewerAssetStorage::LLViewerAssetStorage(LLMessageSystem *msg, LLXferManager *xfer, | ||
| 51 : | LLVFS *vfs) | ||
| 52 : | : LLAssetStorage(msg, xfer, vfs) | ||
| 53 : | { | ||
| 54 : | } | ||
| 55 : | |||
| 56 : | // virtual | ||
| 57 : | void LLViewerAssetStorage::storeAssetData( | ||
| 58 : | const LLTransactionID& tid, | ||
| 59 : | LLAssetType::EType asset_type, | ||
| 60 : | LLStoreAssetCallback callback, | ||
| 61 : | void* user_data, | ||
| 62 : | bool temp_file, | ||
| 63 : | bool is_priority, | ||
| 64 : | bool store_local, | ||
| 65 : | bool user_waiting, | ||
| 66 : | F64 timeout) | ||
| 67 : | { | ||
| 68 : | LLAssetID asset_id = tid.makeAssetID(gAgent.getSecureSessionID()); | ||
| 69 : | llinfos << "LLViewerAssetStorage::storeAssetData (legacy) " << tid << ":" << LLAssetType::lookup(asset_type) | ||
| 70 : | << " ASSET_ID: " << asset_id << llendl; | ||
| 71 : | |||
| 72 : | if (mUpstreamHost.isOk()) | ||
| 73 : | { | ||
| 74 : | if (mVFS->getExists(asset_id, asset_type)) | ||
| 75 : | { | ||
| 76 : | // Pack data into this packet if we can fit it. | ||
| 77 : | U8 buffer[MTUBYTES]; | ||
| 78 : | buffer[0] = 0; | ||
| 79 : | |||
| 80 : | LLVFile vfile(mVFS, asset_id, asset_type, LLVFile::READ); | ||
| 81 : | S32 asset_size = vfile.getSize(); | ||
| 82 : | |||
| 83 : | LLAssetRequest *req = new LLAssetRequest(asset_id, asset_type); | ||
| 84 : | req->mUpCallback = callback; | ||
| 85 : | req->mUserData = user_data; | ||
| 86 : | |||
| 87 : | if (asset_size < 1) | ||
| 88 : | { | ||
| 89 : | // This can happen if there's a bug in our code or if the VFS has been corrupted. | ||
| 90 : | llwarns << "LLViewerAssetStorage::storeAssetData() Data _should_ already be in the VFS, but it's not! " << asset_id << llendl; | ||
| 91 : | // LLAssetStorage metric: Zero size VFS | ||
| 92 : | reportMetric( asset_id, asset_type, LLStringUtil::null, LLUUID::null, 0, MR_ZERO_SIZE, __FILE__, __LINE__, "The file didn't exist or was zero length (VFS - can't tell which)" ); | ||
| 93 : | |||
| 94 : | delete req; | ||
| 95 : | if (callback) | ||
| 96 : | { | ||
| 97 : | callback(asset_id, user_data, LL_ERR_ASSET_REQUEST_FAILED, LL_EXSTAT_VFS_CORRUPT); | ||
| 98 : | } | ||
| 99 : | return; | ||
| 100 : | } | ||
| 101 : | else | ||
| 102 : | { | ||
| 103 : | // LLAssetStorage metric: Successful Request | ||
| 104 : | S32 size = mVFS->getSize(asset_id, asset_type); | ||
| 105 : | const char *message = "Added to upload queue"; | ||
| 106 : | reportMetric( asset_id, asset_type, LLStringUtil::null, LLUUID::null, size, MR_OKAY, __FILE__, __LINE__, message ); | ||
| 107 : | |||
| 108 : | if(is_priority) | ||
| 109 : | { | ||
| 110 : | mPendingUploads.push_front(req); | ||
| 111 : | } | ||
| 112 : | else | ||
| 113 : | { | ||
| 114 : | mPendingUploads.push_back(req); | ||
| 115 : | } | ||
| 116 : | } | ||
| 117 : | |||
| 118 : | // Read the data from the VFS if it'll fit in this packet. | ||
| 119 : | if (asset_size + 100 < MTUBYTES) | ||
| 120 : | { | ||
| 121 : | BOOL res = vfile.read(buffer, asset_size); /* Flawfinder: ignore */ | ||
| 122 : | S32 bytes_read = res ? vfile.getLastBytesRead() : 0; | ||
| 123 : | |||
| 124 : | if( bytes_read == asset_size ) | ||
| 125 : | { | ||
| 126 : | req->mDataSentInFirstPacket = TRUE; | ||
| 127 : | //llinfos << "LLViewerAssetStorage::createAsset sending data in first packet" << llendl; | ||
| 128 : | } | ||
| 129 : | else | ||
| 130 : | { | ||
| 131 : | llwarns << "Probable corruption in VFS file, aborting store asset data" << llendl; | ||
| 132 : | |||
| 133 : | // LLAssetStorage metric: VFS corrupt - bogus size | ||
| 134 : | reportMetric( asset_id, asset_type, LLStringUtil::null, LLUUID::null, asset_size, MR_VFS_CORRUPTION, __FILE__, __LINE__, "VFS corruption" ); | ||
| 135 : | |||
| 136 : | if (callback) | ||
| 137 : | { | ||
| 138 : | callback(asset_id, user_data, LL_ERR_ASSET_REQUEST_NONEXISTENT_FILE, LL_EXSTAT_VFS_CORRUPT); | ||
| 139 : | } | ||
| 140 : | return; | ||
| 141 : | } | ||
| 142 : | } | ||
| 143 : | else | ||
| 144 : | { | ||
| 145 : | // Too big, do an xfer | ||
| 146 : | buffer[0] = 0; | ||
| 147 : | asset_size = 0; | ||
| 148 : | } | ||
| 149 : | mMessageSys->newMessageFast(_PREHASH_AssetUploadRequest); | ||
| 150 : | mMessageSys->nextBlockFast(_PREHASH_AssetBlock); | ||
| 151 : | mMessageSys->addUUIDFast(_PREHASH_TransactionID, tid); | ||
| 152 : | mMessageSys->addS8Fast(_PREHASH_Type, (S8)asset_type); | ||
| 153 : | mMessageSys->addBOOLFast(_PREHASH_Tempfile, temp_file); | ||
| 154 : | mMessageSys->addBOOLFast(_PREHASH_StoreLocal, store_local); | ||
| 155 : | mMessageSys->addBinaryDataFast( _PREHASH_AssetData, buffer, asset_size ); | ||
| 156 : | mMessageSys->sendReliable(mUpstreamHost); | ||
| 157 : | } | ||
| 158 : | else | ||
| 159 : | { | ||
| 160 : | llwarns << "AssetStorage: attempt to upload non-existent vfile " << asset_id << ":" << LLAssetType::lookup(asset_type) << llendl; | ||
| 161 : | // LLAssetStorage metric: Zero size VFS | ||
| 162 : | reportMetric( asset_id, asset_type, LLStringUtil::null, LLUUID::null, 0, MR_ZERO_SIZE, __FILE__, __LINE__, "The file didn't exist or was zero length (VFS - can't tell which)" ); | ||
| 163 : | if (callback) | ||
| 164 : | { | ||
| 165 : | callback(asset_id, user_data, LL_ERR_ASSET_REQUEST_NONEXISTENT_FILE, LL_EXSTAT_NONEXISTENT_FILE); | ||
| 166 : | } | ||
| 167 : | } | ||
| 168 : | } | ||
| 169 : | else | ||
| 170 : | { | ||
| 171 : | llwarns << "Attempt to move asset store request upstream w/o valid upstream provider" << llendl; | ||
| 172 : | // LLAssetStorage metric: Upstream provider dead | ||
| 173 : | reportMetric( asset_id, asset_type, LLStringUtil::null, LLUUID::null, 0, MR_NO_UPSTREAM, __FILE__, __LINE__, "No upstream provider" ); | ||
| 174 : | if (callback) | ||
| 175 : | { | ||
| 176 : | callback(asset_id, user_data, LL_ERR_CIRCUIT_GONE, LL_EXSTAT_NO_UPSTREAM); | ||
| 177 : | } | ||
| 178 : | } | ||
| 179 : | } | ||
| 180 : | |||
| 181 : | void LLViewerAssetStorage::storeAssetData( | ||
| 182 : | const std::string& filename, | ||
| 183 : | const LLTransactionID& tid, | ||
| 184 : | LLAssetType::EType asset_type, | ||
| 185 : | LLStoreAssetCallback callback, | ||
| 186 : | void* user_data, | ||
| 187 : | bool temp_file, | ||
| 188 : | bool is_priority, | ||
| 189 : | bool user_waiting, | ||
| 190 : | F64 timeout) | ||
| 191 : | { | ||
| 192 : | if(filename.empty()) | ||
| 193 : | { | ||
| 194 : | // LLAssetStorage metric: no filename | ||
| 195 : | reportMetric( LLUUID::null, asset_type, LLStringUtil::null, LLUUID::null, 0, MR_VFS_CORRUPTION, __FILE__, __LINE__, "Filename missing" ); | ||
| 196 : | llerrs << "No filename specified" << llendl; | ||
| 197 : | return; | ||
| 198 : | } | ||
| 199 : | |||
| 200 : | LLAssetID asset_id = tid.makeAssetID(gAgent.getSecureSessionID()); | ||
| 201 : | llinfos << "LLViewerAssetStorage::storeAssetData (legacy)" << asset_id << ":" << LLAssetType::lookup(asset_type) << llendl; | ||
| 202 : | |||
| 203 : | llinfos << "ASSET_ID: " << asset_id << llendl; | ||
| 204 : | |||
| 205 : | S32 size = 0; | ||
| 206 : | LLFILE* fp = LLFile::fopen(filename, "rb"); | ||
| 207 : | if (fp) | ||
| 208 : | { | ||
| 209 : | fseek(fp, 0, SEEK_END); | ||
| 210 : | size = ftell(fp); | ||
| 211 : | fseek(fp, 0, SEEK_SET); | ||
| 212 : | } | ||
| 213 : | if( size ) | ||
| 214 : | { | ||
| 215 : | LLLegacyAssetRequest *legacy = new LLLegacyAssetRequest; | ||
| 216 : | |||
| 217 : | legacy->mUpCallback = callback; | ||
| 218 : | legacy->mUserData = user_data; | ||
| 219 : | |||
| 220 : | LLVFile file(mVFS, asset_id, asset_type, LLVFile::WRITE); | ||
| 221 : | |||
| 222 : | file.setMaxSize(size); | ||
| 223 : | |||
| 224 : | const S32 buf_size = 65536; | ||
| 225 : | U8 copy_buf[buf_size]; | ||
| 226 : | while ((size = (S32)fread(copy_buf, 1, buf_size, fp))) | ||
| 227 : | { | ||
| 228 : | file.write(copy_buf, size); | ||
| 229 : | } | ||
| 230 : | fclose(fp); | ||
| 231 : | |||
| 232 : | // if this upload fails, the caller needs to setup a new tempfile for us | ||
| 233 : | if (temp_file) | ||
| 234 : | { | ||
| 235 : | LLFile::remove(filename); | ||
| 236 : | } | ||
| 237 : | |||
| 238 : | // LLAssetStorage metric: Success not needed; handled in the overloaded method here: | ||
| 239 : | |||
| 240 : | LLViewerAssetStorage::storeAssetData( | ||
| 241 : | tid, | ||
| 242 : | asset_type, | ||
| 243 : | legacyStoreDataCallback, | ||
| 244 : | (void**)legacy, | ||
| 245 : | temp_file, | ||
| 246 : | is_priority); | ||
| 247 : | } | ||
| 248 : | else // size == 0 (but previous block changes size) | ||
| 249 : | { | ||
| 250 : | if( fp ) | ||
| 251 : | { | ||
| 252 : | // LLAssetStorage metric: Zero size | ||
| 253 : | reportMetric( asset_id, asset_type, filename, LLUUID::null, 0, MR_ZERO_SIZE, __FILE__, __LINE__, "The file was zero length" ); | ||
| 254 : | } | ||
| 255 : | else | ||
| 256 : | { | ||
| 257 : | // LLAssetStorage metric: Missing File | ||
| 258 : | reportMetric( asset_id, asset_type, filename, LLUUID::null, 0, MR_FILE_NONEXIST, __FILE__, __LINE__, "The file didn't exist" ); | ||
| 259 : | } | ||
| 260 : | if (callback) | ||
| 261 : | { | ||
| 262 : | callback(asset_id, user_data, LL_ERR_CANNOT_OPEN_FILE, LL_EXSTAT_BLOCKED_FILE); | ||
| 263 : | } | ||
| 264 : | } | ||
| 265 : | } |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |

