diff options
Diffstat (limited to 'indra/llmessage/llxfer_file.cpp')
-rw-r--r-- | indra/llmessage/llxfer_file.cpp | 85 |
1 files changed, 39 insertions, 46 deletions
diff --git a/indra/llmessage/llxfer_file.cpp b/indra/llmessage/llxfer_file.cpp index 6b71e7db8f..9e02af2c3e 100644 --- a/indra/llmessage/llxfer_file.cpp +++ b/indra/llmessage/llxfer_file.cpp @@ -2,30 +2,25 @@ * @file llxfer_file.cpp * @brief implementation of LLXfer_File class for a single xfer (file) * - * $LicenseInfo:firstyear=2001&license=viewergpl$ - * - * Copyright (c) 2001-2007, Linden Research, Inc. - * + * $LicenseInfo:firstyear=2001&license=viewerlgpl$ * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlife.com/developers/opensource/gplv2 + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlife.com/developers/opensource/flossexception + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ @@ -47,17 +42,17 @@ const U32 LL_MAX_XFER_FILE_BUFFER = 65536; // local function to copy a file -S32 copy_file(const char* from, const char* to); +S32 copy_file(const std::string& from, const std::string& to); /////////////////////////////////////////////////////////// LLXfer_File::LLXfer_File (S32 chunk_size) : LLXfer(chunk_size) { - init(LLString::null, FALSE, chunk_size); + init(LLStringUtil::null, FALSE, chunk_size); } -LLXfer_File::LLXfer_File (const LLString& local_filename, BOOL delete_local_on_completion, S32 chunk_size) +LLXfer_File::LLXfer_File (const std::string& local_filename, BOOL delete_local_on_completion, S32 chunk_size) : LLXfer(chunk_size) { init(local_filename, delete_local_on_completion, chunk_size); @@ -67,35 +62,35 @@ LLXfer_File::LLXfer_File (const LLString& local_filename, BOOL delete_local_on_c LLXfer_File::~LLXfer_File () { - free(); + cleanup(); } /////////////////////////////////////////////////////////// -void LLXfer_File::init (const LLString& local_filename, BOOL delete_local_on_completion, S32 chunk_size) +void LLXfer_File::init (const std::string& local_filename, BOOL delete_local_on_completion, S32 chunk_size) { mFp = NULL; - mLocalFilename[0] = 0; - mRemoteFilename[0] = 0; + mLocalFilename.clear(); + mRemoteFilename.clear(); mRemotePath = LL_PATH_NONE; - mTempFilename[0] = 0; + mTempFilename.clear(); mDeleteLocalOnCompletion = FALSE; mDeleteRemoteOnCompletion = FALSE; if (!local_filename.empty()) { - strncpy(mLocalFilename, local_filename.c_str(), LL_MAX_PATH-1); - mLocalFilename[LL_MAX_PATH-1] = '\0'; // stupid strncpy. + mLocalFilename = local_filename.substr(0,LL_MAX_PATH-1); // You can only automatically delete .tmp file as a safeguard against nasty messages. - mDeleteLocalOnCompletion = (delete_local_on_completion && (strstr(mLocalFilename,".tmp") == &mLocalFilename[strlen(mLocalFilename)-4])); /* Flawfinder : ignore */ + std::string exten = mLocalFilename.substr(mLocalFilename.length()-4, 4); + mDeleteLocalOnCompletion = (delete_local_on_completion && exten == ".tmp"); } } /////////////////////////////////////////////////////////// -void LLXfer_File::free () +void LLXfer_File::cleanup () { if (mFp) { @@ -115,14 +110,14 @@ void LLXfer_File::free () lldebugs << "Keeping local file: " << mLocalFilename << llendl; } - LLXfer::free(); + LLXfer::cleanup(); } /////////////////////////////////////////////////////////// S32 LLXfer_File::initializeRequest(U64 xfer_id, - const LLString& local_filename, - const LLString& remote_filename, + const std::string& local_filename, + const std::string& remote_filename, ELLPath remote_path, const LLHost& remote_host, BOOL delete_remote_on_completion, @@ -132,15 +127,13 @@ S32 LLXfer_File::initializeRequest(U64 xfer_id, S32 retval = 0; // presume success mID = xfer_id; - strncpy(mLocalFilename, local_filename.c_str(), LL_MAX_PATH-1); - mLocalFilename[LL_MAX_PATH-1] = '\0'; // stupid strncpy. - strncpy(mRemoteFilename,remote_filename.c_str(), LL_MAX_PATH-1); - mRemoteFilename[LL_MAX_PATH-1] = '\0'; // stupid strncpy. + mLocalFilename = local_filename; + mRemoteFilename = remote_filename; mRemotePath = remote_path; mRemoteHost = remote_host; mDeleteRemoteOnCompletion = delete_remote_on_completion; - snprintf(mTempFilename, sizeof(mTempFilename), "%s",gDirUtilp->getTempFilename().c_str()); /* Flawfinder: ignore */ + mTempFilename = gDirUtilp->getTempFilename(); mCallback = callback; mCallbackDataHandle = user_data; @@ -343,7 +336,7 @@ S32 LLXfer_File::processEOF() if(copy_file(mTempFilename, mLocalFilename) == 0) { llinfos << "Rename across mounts; copying+unlinking the file instead." << llendl; - unlink(mTempFilename); + unlink(mTempFilename.c_str()); } else { @@ -384,14 +377,14 @@ S32 LLXfer_File::processEOF() /////////////////////////////////////////////////////////// -BOOL LLXfer_File::matchesLocalFilename(const LLString& filename) +BOOL LLXfer_File::matchesLocalFilename(const std::string& filename) { return (filename == mLocalFilename); } /////////////////////////////////////////////////////////// -BOOL LLXfer_File::matchesRemoteFilename(const LLString& filename, ELLPath remote_path) +BOOL LLXfer_File::matchesRemoteFilename(const std::string& filename, ELLPath remote_path) { return ((filename == mRemoteFilename) && (remote_path == mRemotePath)); } @@ -399,9 +392,9 @@ BOOL LLXfer_File::matchesRemoteFilename(const LLString& filename, ELLPath remote /////////////////////////////////////////////////////////// -const char * LLXfer_File::getName() +std::string LLXfer_File::getFileName() { - return (mLocalFilename); + return mLocalFilename; } /////////////////////////////////////////////////////////// @@ -421,7 +414,7 @@ U32 LLXfer_File::getXferTypeTag() // function. It does not really spam enough information, but is useful // for this cpp file, because this should never be called in a // production environment. -S32 copy_file(const char* from, const char* to) +S32 copy_file(const std::string& from, const std::string& to) { S32 rv = 0; LLFILE* in = LLFile::fopen(from, "rb"); /*Flawfinder: ignore*/ |