diff options
author | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
commit | 38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch) | |
tree | adca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/llmessage/lltransfersourcefile.cpp | |
parent | README.txt (diff) | |
download | meta-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/lltransfersourcefile.cpp')
-rw-r--r-- | linden/indra/llmessage/lltransfersourcefile.cpp | 173 |
1 files changed, 173 insertions, 0 deletions
diff --git a/linden/indra/llmessage/lltransfersourcefile.cpp b/linden/indra/llmessage/lltransfersourcefile.cpp new file mode 100644 index 0000000..a8625b0 --- /dev/null +++ b/linden/indra/llmessage/lltransfersourcefile.cpp | |||
@@ -0,0 +1,173 @@ | |||
1 | /** | ||
2 | * @file lltransfersourcefile.cpp | ||
3 | * @brief Transfer system for sending a file. | ||
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 "lltransfersourcefile.h" | ||
31 | |||
32 | #include "llerror.h" | ||
33 | #include "message.h" | ||
34 | #include "lldatapacker.h" | ||
35 | #include "lldir.h" | ||
36 | |||
37 | LLTransferSourceFile::LLTransferSourceFile(const LLUUID &request_id, const F32 priority) : | ||
38 | LLTransferSource(LLTST_FILE, request_id, priority), | ||
39 | mFP(NULL) | ||
40 | { | ||
41 | } | ||
42 | |||
43 | LLTransferSourceFile::~LLTransferSourceFile() | ||
44 | { | ||
45 | if (mFP) | ||
46 | { | ||
47 | llerrs << "Destructor called without the completion callback being called!" << llendl; | ||
48 | } | ||
49 | } | ||
50 | |||
51 | void LLTransferSourceFile::initTransfer() | ||
52 | { | ||
53 | std::string filename = mParams.getFilename(); | ||
54 | std::string delimiter = gDirUtilp->getDirDelimiter(); | ||
55 | |||
56 | if((filename == ".") | ||
57 | || (filename == "..") | ||
58 | || (filename.find(delimiter[0]) != std::string::npos)) | ||
59 | { | ||
60 | llwarns << "Attempting to transfer file " << filename << " with path delimiter, aborting!" << llendl; | ||
61 | |||
62 | sendTransferStatus(LLTS_ERROR); | ||
63 | return; | ||
64 | } | ||
65 | // Look for the file. | ||
66 | mFP = LLFile::fopen(mParams.getFilename().c_str(), "rb"); /* Flawfinder: ignore */ | ||
67 | if (!mFP) | ||
68 | { | ||
69 | sendTransferStatus(LLTS_ERROR); | ||
70 | return; | ||
71 | } | ||
72 | |||
73 | // Get the size of the file using the hack from | ||
74 | fseek(mFP,0,SEEK_END); | ||
75 | mSize = ftell(mFP); | ||
76 | fseek(mFP,0,SEEK_SET); | ||
77 | |||
78 | sendTransferStatus(LLTS_OK); | ||
79 | } | ||
80 | |||
81 | F32 LLTransferSourceFile::updatePriority() | ||
82 | { | ||
83 | return 0.f; | ||
84 | } | ||
85 | |||
86 | LLTSCode LLTransferSourceFile::dataCallback(const S32 packet_id, | ||
87 | const S32 max_bytes, | ||
88 | U8 **data_handle, | ||
89 | S32 &returned_bytes, | ||
90 | BOOL &delete_returned) | ||
91 | { | ||
92 | //llinfos << "LLTransferSourceFile::dataCallback" << llendl; | ||
93 | |||
94 | if (!mFP) | ||
95 | { | ||
96 | llerrs << "Data callback without file set!" << llendl; | ||
97 | return LLTS_ERROR; | ||
98 | } | ||
99 | |||
100 | if (packet_id != mLastPacketID + 1) | ||
101 | { | ||
102 | llerrs << "Can't handle out of order file transfer yet!" << llendl; | ||
103 | } | ||
104 | |||
105 | // Grab up until the max number of bytes from the file. | ||
106 | delete_returned = TRUE; | ||
107 | U8 *tmpp = new U8[max_bytes]; | ||
108 | *data_handle = tmpp; | ||
109 | returned_bytes = (S32)fread(tmpp, 1, max_bytes, mFP); | ||
110 | if (!returned_bytes) | ||
111 | { | ||
112 | delete[] tmpp; | ||
113 | *data_handle = NULL; | ||
114 | returned_bytes = 0; | ||
115 | delete_returned = FALSE; | ||
116 | return LLTS_DONE; | ||
117 | } | ||
118 | |||
119 | return LLTS_OK; | ||
120 | } | ||
121 | |||
122 | void LLTransferSourceFile::completionCallback(const LLTSCode status) | ||
123 | { | ||
124 | // No matter what happens, all we want to do is close the file pointer if | ||
125 | // we've got it open. | ||
126 | if (mFP) | ||
127 | { | ||
128 | fclose(mFP); | ||
129 | mFP = NULL; | ||
130 | |||
131 | } | ||
132 | // Delete the file iff the filename begins with "TEMP" | ||
133 | if (mParams.getDeleteOnCompletion() && memcmp(mParams.getFilename().c_str(), "TEMP", 4) == 0) | ||
134 | { | ||
135 | LLFile::remove(mParams.getFilename().c_str()); | ||
136 | } | ||
137 | } | ||
138 | |||
139 | void LLTransferSourceFile::packParams(LLDataPacker& dp) const | ||
140 | { | ||
141 | //llinfos << "LLTransferSourceFile::packParams" << llendl; | ||
142 | mParams.packParams(dp); | ||
143 | } | ||
144 | |||
145 | BOOL LLTransferSourceFile::unpackParams(LLDataPacker &dp) | ||
146 | { | ||
147 | //llinfos << "LLTransferSourceFile::unpackParams" << llendl; | ||
148 | return mParams.unpackParams(dp); | ||
149 | } | ||
150 | |||
151 | |||
152 | LLTransferSourceParamsFile::LLTransferSourceParamsFile() : LLTransferSourceParams(LLTST_FILE) | ||
153 | { | ||
154 | } | ||
155 | |||
156 | |||
157 | void LLTransferSourceParamsFile::packParams(LLDataPacker &dp) const | ||
158 | { | ||
159 | dp.packString(mFilename.c_str(), "Filename"); | ||
160 | dp.packU8((U8)mDeleteOnCompletion, "Delete"); | ||
161 | } | ||
162 | |||
163 | |||
164 | BOOL LLTransferSourceParamsFile::unpackParams(LLDataPacker &dp) | ||
165 | { | ||
166 | dp.unpackString(mFilename, "Filename"); | ||
167 | U8 delete_flag; | ||
168 | dp.unpackU8(delete_flag, "Delete"); | ||
169 | mDeleteOnCompletion = delete_flag; | ||
170 | |||
171 | llinfos << "Unpacked filename: " << mFilename << llendl; | ||
172 | return TRUE; | ||
173 | } | ||