aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llmessage/lltransfertargetfile.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/llmessage/lltransfertargetfile.cpp
parentREADME.txt (diff)
downloadmeta-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/lltransfertargetfile.cpp')
-rw-r--r--linden/indra/llmessage/lltransfertargetfile.cpp132
1 files changed, 132 insertions, 0 deletions
diff --git a/linden/indra/llmessage/lltransfertargetfile.cpp b/linden/indra/llmessage/lltransfertargetfile.cpp
new file mode 100644
index 0000000..bb039d7
--- /dev/null
+++ b/linden/indra/llmessage/lltransfertargetfile.cpp
@@ -0,0 +1,132 @@
1/**
2 * @file lltransfertargetfile.cpp
3 * @brief Transfer system for receiving 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 "lltransfertargetfile.h"
31#include "llerror.h"
32
33
34
35
36LLTransferTargetFile::LLTransferTargetFile(
37 const LLUUID& uuid,
38 LLTransferSourceType src_type) :
39 LLTransferTarget(LLTTT_FILE, uuid, src_type),
40 mFP(NULL)
41{
42}
43
44LLTransferTargetFile::~LLTransferTargetFile()
45{
46 if (mFP)
47 {
48 llerrs << "LLTransferTargetFile::~LLTransferTargetFile - Should have been cleaned up in completion callback" << llendl;
49 fclose(mFP);
50 mFP = NULL;
51 }
52}
53
54// virtual
55bool LLTransferTargetFile::unpackParams(LLDataPacker& dp)
56{
57 // we can safely ignore this call
58 return true;
59}
60
61void LLTransferTargetFile::applyParams(const LLTransferTargetParams &params)
62{
63 if (params.getType() != mType)
64 {
65 llwarns << "Target parameter type doesn't match!" << llendl;
66 return;
67 }
68
69 mParams = (LLTransferTargetParamsFile &)params;
70}
71
72LLTSCode LLTransferTargetFile::dataCallback(const S32 packet_id, U8 *in_datap, const S32 in_size)
73{
74 //llinfos << "LLTransferTargetFile::dataCallback" << llendl;
75 //llinfos << "Packet: " << packet_id << llendl;
76
77 if (!mFP)
78 {
79 mFP = LLFile::fopen(mParams.mFilename.c_str(), "wb"); /* Flawfinder: ignore */
80
81 if (!mFP)
82 {
83 llwarns << "Failure opening " << mParams.mFilename << " for write by LLTransferTargetFile" << llendl;
84 return LLTS_ERROR;
85 }
86 }
87 if (!in_size)
88 {
89 return LLTS_OK;
90 }
91
92 S32 count = (S32)fwrite(in_datap, 1, in_size, mFP);
93 if (count != in_size)
94 {
95 llwarns << "Failure in LLTransferTargetFile::dataCallback!" << llendl;
96 return LLTS_ERROR;
97 }
98 return LLTS_OK;
99}
100
101void LLTransferTargetFile::completionCallback(const LLTSCode status)
102{
103 llinfos << "LLTransferTargetFile::completionCallback" << llendl;
104 if (mFP)
105 {
106 fclose(mFP);
107 }
108
109 // Still need to gracefully handle error conditions.
110 switch (status)
111 {
112 case LLTS_DONE:
113 break;
114 case LLTS_ABORT:
115 case LLTS_ERROR:
116 // We're aborting this transfer, we don't want to keep this file.
117 llwarns << "Aborting file transfer for " << mParams.mFilename << llendl;
118 if (mFP)
119 {
120 // Only need to remove file if we successfully opened it.
121 LLFile::remove(mParams.mFilename.c_str());
122 }
123 default:
124 break;
125 }
126
127 mFP = NULL;
128 if (mParams.mCompleteCallback)
129 {
130 mParams.mCompleteCallback(status, mParams.mUserData);
131 }
132}