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/llxfer_mem.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/llxfer_mem.cpp')
-rw-r--r-- | linden/indra/llmessage/llxfer_mem.cpp | 218 |
1 files changed, 218 insertions, 0 deletions
diff --git a/linden/indra/llmessage/llxfer_mem.cpp b/linden/indra/llmessage/llxfer_mem.cpp new file mode 100644 index 0000000..e9d7bf8 --- /dev/null +++ b/linden/indra/llmessage/llxfer_mem.cpp | |||
@@ -0,0 +1,218 @@ | |||
1 | /** | ||
2 | * @file llxfer_mem.cpp | ||
3 | * @brief implementation of LLXfer_Mem class for a single xfer | ||
4 | * | ||
5 | * Copyright (c) 2001-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 "llxfer_mem.h" | ||
31 | #include "lluuid.h" | ||
32 | #include "llerror.h" | ||
33 | #include "llmath.h" | ||
34 | |||
35 | /////////////////////////////////////////////////////////// | ||
36 | |||
37 | LLXfer_Mem::LLXfer_Mem () | ||
38 | : LLXfer(-1) | ||
39 | { | ||
40 | init(); | ||
41 | } | ||
42 | |||
43 | /////////////////////////////////////////////////////////// | ||
44 | |||
45 | LLXfer_Mem::~LLXfer_Mem () | ||
46 | { | ||
47 | free(); | ||
48 | } | ||
49 | |||
50 | /////////////////////////////////////////////////////////// | ||
51 | |||
52 | void LLXfer_Mem::init () | ||
53 | { | ||
54 | mRemoteFilename[0] = '\0'; | ||
55 | mRemotePath = LL_PATH_NONE; | ||
56 | mDeleteRemoteOnCompletion = FALSE; | ||
57 | } | ||
58 | |||
59 | /////////////////////////////////////////////////////////// | ||
60 | |||
61 | void LLXfer_Mem::free () | ||
62 | { | ||
63 | LLXfer::free(); | ||
64 | } | ||
65 | |||
66 | /////////////////////////////////////////////////////////// | ||
67 | |||
68 | void LLXfer_Mem::setXferSize (S32 xfer_size) | ||
69 | { | ||
70 | mXferSize = xfer_size; | ||
71 | |||
72 | delete[] mBuffer; | ||
73 | mBuffer = new char[xfer_size]; | ||
74 | |||
75 | mBufferLength = 0; | ||
76 | mBufferStartOffset = 0; | ||
77 | mBufferContainsEOF = TRUE; | ||
78 | |||
79 | // cout << "starting transfer of size: " << xfer_size << endl; | ||
80 | } | ||
81 | |||
82 | /////////////////////////////////////////////////////////// | ||
83 | |||
84 | U64 LLXfer_Mem::registerXfer(U64 xfer_id, const void *datap, const S32 length) | ||
85 | { | ||
86 | mID = xfer_id; | ||
87 | |||
88 | if (datap) | ||
89 | { | ||
90 | setXferSize(length); | ||
91 | if (mBuffer) | ||
92 | { | ||
93 | memcpy(mBuffer,datap,length); /* Flawfinder : ignore */ | ||
94 | mBufferLength = length; | ||
95 | } | ||
96 | else | ||
97 | { | ||
98 | xfer_id = 0; | ||
99 | } | ||
100 | } | ||
101 | |||
102 | mStatus = e_LL_XFER_REGISTERED; | ||
103 | return (xfer_id); | ||
104 | } | ||
105 | |||
106 | S32 LLXfer_Mem::startSend (U64 xfer_id, const LLHost &remote_host) | ||
107 | { | ||
108 | S32 retval = LL_ERR_NOERR; // presume success | ||
109 | |||
110 | if (mXferSize <= 0) | ||
111 | { | ||
112 | return LL_ERR_FILE_EMPTY; | ||
113 | } | ||
114 | |||
115 | mRemoteHost = remote_host; | ||
116 | mID = xfer_id; | ||
117 | mPacketNum = -1; | ||
118 | |||
119 | // cout << "Sending file: " << getName() << endl; | ||
120 | |||
121 | mStatus = e_LL_XFER_PENDING; | ||
122 | |||
123 | return (retval); | ||
124 | } | ||
125 | |||
126 | /////////////////////////////////////////////////////////// | ||
127 | |||
128 | S32 LLXfer_Mem::processEOF() | ||
129 | { | ||
130 | S32 retval = 0; | ||
131 | |||
132 | mStatus = e_LL_XFER_COMPLETE; | ||
133 | |||
134 | llinfos << "xfer complete: " << getName() << llendl; | ||
135 | |||
136 | if (mCallback) | ||
137 | { | ||
138 | mCallback((void *)mBuffer,mBufferLength,mCallbackDataHandle,mCallbackResult); | ||
139 | } | ||
140 | |||
141 | return(retval); | ||
142 | } | ||
143 | |||
144 | /////////////////////////////////////////////////////////// | ||
145 | |||
146 | S32 LLXfer_Mem::initializeRequest(U64 xfer_id, | ||
147 | const std::string& remote_filename, | ||
148 | ELLPath remote_path, | ||
149 | const LLHost& remote_host, | ||
150 | BOOL delete_remote_on_completion, | ||
151 | void (*callback)(void*,S32,void**,S32), | ||
152 | void** user_data) | ||
153 | { | ||
154 | S32 retval = 0; // presume success | ||
155 | |||
156 | mRemoteHost = remote_host; | ||
157 | |||
158 | // create a temp filename string using a GUID | ||
159 | mID = xfer_id; | ||
160 | mCallback = callback; | ||
161 | mCallbackDataHandle = user_data; | ||
162 | mCallbackResult = LL_ERR_NOERR; | ||
163 | |||
164 | strncpy(mRemoteFilename, remote_filename.c_str(), LL_MAX_PATH); /* Flawfinder : ignore */ | ||
165 | mRemotePath = remote_path; | ||
166 | mDeleteRemoteOnCompletion = delete_remote_on_completion; | ||
167 | |||
168 | llinfos << "Requesting file: " << remote_filename << llendl; | ||
169 | |||
170 | delete [] mBuffer; | ||
171 | mBuffer = NULL; | ||
172 | |||
173 | mBufferLength = 0; | ||
174 | mPacketNum = 0; | ||
175 | mStatus = e_LL_XFER_PENDING; | ||
176 | return retval; | ||
177 | } | ||
178 | |||
179 | ////////////////////////////////////////////////////////// | ||
180 | |||
181 | S32 LLXfer_Mem::startDownload() | ||
182 | { | ||
183 | S32 retval = 0; // presume success | ||
184 | gMessageSystem->newMessageFast(_PREHASH_RequestXfer); | ||
185 | gMessageSystem->nextBlockFast(_PREHASH_XferID); | ||
186 | gMessageSystem->addU64Fast(_PREHASH_ID, mID); | ||
187 | gMessageSystem->addStringFast(_PREHASH_Filename, mRemoteFilename); | ||
188 | gMessageSystem->addU8("FilePath", (U8) mRemotePath); | ||
189 | gMessageSystem->addBOOL("DeleteOnCompletion", mDeleteRemoteOnCompletion); | ||
190 | gMessageSystem->addBOOL("UseBigPackets", BOOL(mChunkSize == LL_XFER_LARGE_PAYLOAD)); | ||
191 | gMessageSystem->addUUIDFast(_PREHASH_VFileID, LLUUID::null); | ||
192 | gMessageSystem->addS16Fast(_PREHASH_VFileType, -1); | ||
193 | |||
194 | gMessageSystem->sendReliable(mRemoteHost); | ||
195 | mStatus = e_LL_XFER_IN_PROGRESS; | ||
196 | |||
197 | return (retval); | ||
198 | } | ||
199 | |||
200 | ////////////////////////////////////////////////////////// | ||
201 | |||
202 | U32 LLXfer_Mem::getXferTypeTag() | ||
203 | { | ||
204 | return LLXfer::XFER_MEM; | ||
205 | } | ||
206 | |||
207 | |||
208 | |||
209 | |||
210 | |||
211 | |||
212 | |||
213 | |||
214 | |||
215 | |||
216 | |||
217 | |||
218 | |||