diff options
author | Jeff Ames | 2008-12-13 12:22:52 +0000 |
---|---|---|
committer | Jeff Ames | 2008-12-13 12:22:52 +0000 |
commit | 4f9d5d955b08c18733d72d4b70e441c555b6bccf (patch) | |
tree | eef69a77f1e074b5369fdee2eac6112eb50111dc | |
parent | more work on moving FileTransfer code to the clientstack. (diff) | |
download | opensim-SC_OLD-4f9d5d955b08c18733d72d4b70e441c555b6bccf.zip opensim-SC_OLD-4f9d5d955b08c18733d72d4b70e441c555b6bccf.tar.gz opensim-SC_OLD-4f9d5d955b08c18733d72d4b70e441c555b6bccf.tar.bz2 opensim-SC_OLD-4f9d5d955b08c18733d72d4b70e441c555b6bccf.tar.xz |
Update svn properties.
-rw-r--r-- | OpenSim/Framework/IClientFileTransfer.cs | 30 | ||||
-rw-r--r-- | OpenSim/Region/ClientStack/LindenUDP/LLFileTransfer.cs | 478 |
2 files changed, 254 insertions, 254 deletions
diff --git a/OpenSim/Framework/IClientFileTransfer.cs b/OpenSim/Framework/IClientFileTransfer.cs index ec8e623..fc9ec79 100644 --- a/OpenSim/Framework/IClientFileTransfer.cs +++ b/OpenSim/Framework/IClientFileTransfer.cs | |||
@@ -1,15 +1,15 @@ | |||
1 | using System; | 1 | using System; |
2 | using System.Collections.Generic; | 2 | using System.Collections.Generic; |
3 | using System.Text; | 3 | using System.Text; |
4 | using OpenMetaverse; | 4 | using OpenMetaverse; |
5 | 5 | ||
6 | namespace OpenSim.Framework | 6 | namespace OpenSim.Framework |
7 | { | 7 | { |
8 | public delegate void UploadComplete(string filename, UUID fileID, byte[] fileData, IClientAPI remoteClient); | 8 | public delegate void UploadComplete(string filename, UUID fileID, byte[] fileData, IClientAPI remoteClient); |
9 | public delegate void UploadAborted(string filename, ulong id, IClientAPI remoteClient); | 9 | public delegate void UploadAborted(string filename, ulong id, IClientAPI remoteClient); |
10 | 10 | ||
11 | public interface IClientFileTransfer | 11 | public interface IClientFileTransfer |
12 | { | 12 | { |
13 | bool RequestUpload(string clientFileName, UploadComplete uploadCompleteCallback, UploadAborted abortCallback); | 13 | bool RequestUpload(string clientFileName, UploadComplete uploadCompleteCallback, UploadAborted abortCallback); |
14 | } | 14 | } |
15 | } | 15 | } |
diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLFileTransfer.cs b/OpenSim/Region/ClientStack/LindenUDP/LLFileTransfer.cs index 5526a16..692318a 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLFileTransfer.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLFileTransfer.cs | |||
@@ -1,239 +1,239 @@ | |||
1 | using System; | 1 | using System; |
2 | using System.Collections.Generic; | 2 | using System.Collections.Generic; |
3 | using System.Text; | 3 | using System.Text; |
4 | using System.Xml; | 4 | using System.Xml; |
5 | using OpenMetaverse; | 5 | using OpenMetaverse; |
6 | using OpenMetaverse.Packets; | 6 | using OpenMetaverse.Packets; |
7 | using OpenSim.Framework; | 7 | using OpenSim.Framework; |
8 | using OpenSim.Framework.Client; | 8 | using OpenSim.Framework.Client; |
9 | using OpenSim.Framework.Communications.Cache; | 9 | using OpenSim.Framework.Communications.Cache; |
10 | using OpenSim.Framework.Statistics; | 10 | using OpenSim.Framework.Statistics; |
11 | using OpenSim.Region.Interfaces; | 11 | using OpenSim.Region.Interfaces; |
12 | using OpenSim.Region.Environment.Scenes; | 12 | using OpenSim.Region.Environment.Scenes; |
13 | 13 | ||
14 | namespace OpenSim.Region.ClientStack.LindenUDP | 14 | namespace OpenSim.Region.ClientStack.LindenUDP |
15 | { | 15 | { |
16 | public class LLFileTransfer : IClientFileTransfer | 16 | public class LLFileTransfer : IClientFileTransfer |
17 | { | 17 | { |
18 | protected IClientAPI m_clientAPI; | 18 | protected IClientAPI m_clientAPI; |
19 | 19 | ||
20 | /// Dictionary of handlers for uploading files from client | 20 | /// Dictionary of handlers for uploading files from client |
21 | /// TODO: Need to add cleanup code to remove handlers that have completed their upload | 21 | /// TODO: Need to add cleanup code to remove handlers that have completed their upload |
22 | protected Dictionary<ulong, XferHandler> m_handlers; | 22 | protected Dictionary<ulong, XferHandler> m_handlers; |
23 | protected object m_handlerLock = new object(); | 23 | protected object m_handlerLock = new object(); |
24 | 24 | ||
25 | public LLFileTransfer(IClientAPI clientAPI) | 25 | public LLFileTransfer(IClientAPI clientAPI) |
26 | { | 26 | { |
27 | m_handlers = new Dictionary<ulong, XferHandler>(); | 27 | m_handlers = new Dictionary<ulong, XferHandler>(); |
28 | m_clientAPI = clientAPI; | 28 | m_clientAPI = clientAPI; |
29 | 29 | ||
30 | m_clientAPI.OnXferReceive += XferReceive; | 30 | m_clientAPI.OnXferReceive += XferReceive; |
31 | m_clientAPI.OnAbortXfer += AbortXferHandler; | 31 | m_clientAPI.OnAbortXfer += AbortXferHandler; |
32 | } | 32 | } |
33 | 33 | ||
34 | public void Close() | 34 | public void Close() |
35 | { | 35 | { |
36 | if (m_clientAPI != null) | 36 | if (m_clientAPI != null) |
37 | { | 37 | { |
38 | m_clientAPI.OnXferReceive -= XferReceive; | 38 | m_clientAPI.OnXferReceive -= XferReceive; |
39 | m_clientAPI.OnAbortXfer -= AbortXferHandler; | 39 | m_clientAPI.OnAbortXfer -= AbortXferHandler; |
40 | m_clientAPI = null; | 40 | m_clientAPI = null; |
41 | } | 41 | } |
42 | } | 42 | } |
43 | 43 | ||
44 | public bool RequestUpload(string clientFileName, UploadComplete uploadCompleteCallback, UploadAborted abortCallback) | 44 | public bool RequestUpload(string clientFileName, UploadComplete uploadCompleteCallback, UploadAborted abortCallback) |
45 | { | 45 | { |
46 | if ((String.IsNullOrEmpty(clientFileName)) || (uploadCompleteCallback == null)) | 46 | if ((String.IsNullOrEmpty(clientFileName)) || (uploadCompleteCallback == null)) |
47 | { | 47 | { |
48 | return false; | 48 | return false; |
49 | } | 49 | } |
50 | 50 | ||
51 | XferHandler uploader = new XferHandler(m_clientAPI, clientFileName); | 51 | XferHandler uploader = new XferHandler(m_clientAPI, clientFileName); |
52 | 52 | ||
53 | return StartUpload(uploader, uploadCompleteCallback, abortCallback); | 53 | return StartUpload(uploader, uploadCompleteCallback, abortCallback); |
54 | } | 54 | } |
55 | 55 | ||
56 | public bool RequestUpload(UUID fileID, UploadComplete uploadCompleteCallback, UploadAborted abortCallback) | 56 | public bool RequestUpload(UUID fileID, UploadComplete uploadCompleteCallback, UploadAborted abortCallback) |
57 | { | 57 | { |
58 | if ((fileID == UUID.Zero) || (uploadCompleteCallback == null)) | 58 | if ((fileID == UUID.Zero) || (uploadCompleteCallback == null)) |
59 | { | 59 | { |
60 | return false; | 60 | return false; |
61 | } | 61 | } |
62 | 62 | ||
63 | XferHandler uploader = new XferHandler(m_clientAPI, fileID); | 63 | XferHandler uploader = new XferHandler(m_clientAPI, fileID); |
64 | 64 | ||
65 | return StartUpload(uploader, uploadCompleteCallback, abortCallback); | 65 | return StartUpload(uploader, uploadCompleteCallback, abortCallback); |
66 | } | 66 | } |
67 | 67 | ||
68 | private bool StartUpload(XferHandler uploader, UploadComplete uploadCompleteCallback, UploadAborted abortCallback) | 68 | private bool StartUpload(XferHandler uploader, UploadComplete uploadCompleteCallback, UploadAborted abortCallback) |
69 | { | 69 | { |
70 | uploader.UploadDone += uploadCompleteCallback; | 70 | uploader.UploadDone += uploadCompleteCallback; |
71 | 71 | ||
72 | if (abortCallback != null) | 72 | if (abortCallback != null) |
73 | { | 73 | { |
74 | uploader.UploadAborted += abortCallback; | 74 | uploader.UploadAborted += abortCallback; |
75 | } | 75 | } |
76 | 76 | ||
77 | lock (m_handlerLock) | 77 | lock (m_handlerLock) |
78 | { | 78 | { |
79 | if (!m_handlers.ContainsKey(uploader.XferID)) | 79 | if (!m_handlers.ContainsKey(uploader.XferID)) |
80 | { | 80 | { |
81 | m_handlers.Add(uploader.XferID, uploader); | 81 | m_handlers.Add(uploader.XferID, uploader); |
82 | uploader.RequestStartXfer(m_clientAPI); | 82 | uploader.RequestStartXfer(m_clientAPI); |
83 | return true; | 83 | return true; |
84 | } | 84 | } |
85 | else | 85 | else |
86 | { | 86 | { |
87 | // something went wrong with the xferID allocation | 87 | // something went wrong with the xferID allocation |
88 | uploader.UploadDone -= uploadCompleteCallback; | 88 | uploader.UploadDone -= uploadCompleteCallback; |
89 | if (abortCallback != null) | 89 | if (abortCallback != null) |
90 | { | 90 | { |
91 | uploader.UploadAborted -= abortCallback; | 91 | uploader.UploadAborted -= abortCallback; |
92 | } | 92 | } |
93 | return false; | 93 | return false; |
94 | } | 94 | } |
95 | } | 95 | } |
96 | } | 96 | } |
97 | 97 | ||
98 | protected void AbortXferHandler(IClientAPI remoteClient, ulong xferID) | 98 | protected void AbortXferHandler(IClientAPI remoteClient, ulong xferID) |
99 | { | 99 | { |
100 | lock (m_handlerLock) | 100 | lock (m_handlerLock) |
101 | { | 101 | { |
102 | if (m_handlers.ContainsKey(xferID)) | 102 | if (m_handlers.ContainsKey(xferID)) |
103 | { | 103 | { |
104 | m_handlers[xferID].AbortUpload(remoteClient); | 104 | m_handlers[xferID].AbortUpload(remoteClient); |
105 | m_handlers.Remove(xferID); | 105 | m_handlers.Remove(xferID); |
106 | } | 106 | } |
107 | } | 107 | } |
108 | } | 108 | } |
109 | 109 | ||
110 | protected void XferReceive(IClientAPI remoteClient, ulong xferID, uint packetID, byte[] data) | 110 | protected void XferReceive(IClientAPI remoteClient, ulong xferID, uint packetID, byte[] data) |
111 | { | 111 | { |
112 | lock (m_handlerLock) | 112 | lock (m_handlerLock) |
113 | { | 113 | { |
114 | if (m_handlers.ContainsKey(xferID)) | 114 | if (m_handlers.ContainsKey(xferID)) |
115 | { | 115 | { |
116 | m_handlers[xferID].XferReceive(remoteClient, xferID, packetID, data); | 116 | m_handlers[xferID].XferReceive(remoteClient, xferID, packetID, data); |
117 | } | 117 | } |
118 | } | 118 | } |
119 | } | 119 | } |
120 | } | 120 | } |
121 | 121 | ||
122 | public class XferHandler | 122 | public class XferHandler |
123 | { | 123 | { |
124 | private AssetBase m_asset; | 124 | private AssetBase m_asset; |
125 | 125 | ||
126 | public event UploadComplete UploadDone; | 126 | public event UploadComplete UploadDone; |
127 | public event UploadAborted UploadAborted; | 127 | public event UploadAborted UploadAborted; |
128 | 128 | ||
129 | private sbyte type = 0; | 129 | private sbyte type = 0; |
130 | 130 | ||
131 | public ulong mXferID; | 131 | public ulong mXferID; |
132 | private UploadComplete handlerUploadDone; | 132 | private UploadComplete handlerUploadDone; |
133 | private UploadAborted handlerAbort; | 133 | private UploadAborted handlerAbort; |
134 | 134 | ||
135 | private bool m_complete = false; | 135 | private bool m_complete = false; |
136 | 136 | ||
137 | public bool UploadComplete | 137 | public bool UploadComplete |
138 | { | 138 | { |
139 | get { return m_complete; } | 139 | get { return m_complete; } |
140 | } | 140 | } |
141 | 141 | ||
142 | public XferHandler(IClientAPI pRemoteClient, string pClientFilename) | 142 | public XferHandler(IClientAPI pRemoteClient, string pClientFilename) |
143 | { | 143 | { |
144 | 144 | ||
145 | m_asset = new AssetBase(); | 145 | m_asset = new AssetBase(); |
146 | m_asset.FullID = UUID.Zero; | 146 | m_asset.FullID = UUID.Zero; |
147 | m_asset.Type = type; | 147 | m_asset.Type = type; |
148 | m_asset.Data = new byte[0]; | 148 | m_asset.Data = new byte[0]; |
149 | m_asset.Name = pClientFilename; | 149 | m_asset.Name = pClientFilename; |
150 | m_asset.Description = "empty"; | 150 | m_asset.Description = "empty"; |
151 | m_asset.Local = true; | 151 | m_asset.Local = true; |
152 | m_asset.Temporary = true; | 152 | m_asset.Temporary = true; |
153 | mXferID = Util.GetNextXferID(); | 153 | mXferID = Util.GetNextXferID(); |
154 | } | 154 | } |
155 | 155 | ||
156 | public XferHandler(IClientAPI pRemoteClient, UUID fileID) | 156 | public XferHandler(IClientAPI pRemoteClient, UUID fileID) |
157 | { | 157 | { |
158 | m_asset = new AssetBase(); | 158 | m_asset = new AssetBase(); |
159 | m_asset.FullID = fileID; | 159 | m_asset.FullID = fileID; |
160 | m_asset.Type = type; | 160 | m_asset.Type = type; |
161 | m_asset.Data = new byte[0]; | 161 | m_asset.Data = new byte[0]; |
162 | m_asset.Name = null; | 162 | m_asset.Name = null; |
163 | m_asset.Description = "empty"; | 163 | m_asset.Description = "empty"; |
164 | m_asset.Local = true; | 164 | m_asset.Local = true; |
165 | m_asset.Temporary = true; | 165 | m_asset.Temporary = true; |
166 | mXferID = Util.GetNextXferID(); | 166 | mXferID = Util.GetNextXferID(); |
167 | } | 167 | } |
168 | 168 | ||
169 | public ulong XferID | 169 | public ulong XferID |
170 | { | 170 | { |
171 | get { return mXferID; } | 171 | get { return mXferID; } |
172 | } | 172 | } |
173 | 173 | ||
174 | public void RequestStartXfer(IClientAPI pRemoteClient) | 174 | public void RequestStartXfer(IClientAPI pRemoteClient) |
175 | { | 175 | { |
176 | if (m_asset.Name != null) | 176 | if (m_asset.Name != null) |
177 | { | 177 | { |
178 | pRemoteClient.SendXferRequest(mXferID, m_asset.Type, m_asset.FullID, 0, Utils.StringToBytes(m_asset.Name)); | 178 | pRemoteClient.SendXferRequest(mXferID, m_asset.Type, m_asset.FullID, 0, Utils.StringToBytes(m_asset.Name)); |
179 | } | 179 | } |
180 | else | 180 | else |
181 | { | 181 | { |
182 | pRemoteClient.SendXferRequest(mXferID, m_asset.Type, m_asset.FullID, 0, new byte[0]); | 182 | pRemoteClient.SendXferRequest(mXferID, m_asset.Type, m_asset.FullID, 0, new byte[0]); |
183 | } | 183 | } |
184 | } | 184 | } |
185 | 185 | ||
186 | /// <summary> | 186 | /// <summary> |
187 | /// Process transfer data received from the client. | 187 | /// Process transfer data received from the client. |
188 | /// </summary> | 188 | /// </summary> |
189 | /// <param name="xferID"></param> | 189 | /// <param name="xferID"></param> |
190 | /// <param name="packetID"></param> | 190 | /// <param name="packetID"></param> |
191 | /// <param name="data"></param> | 191 | /// <param name="data"></param> |
192 | public void XferReceive(IClientAPI remoteClient, ulong xferID, uint packetID, byte[] data) | 192 | public void XferReceive(IClientAPI remoteClient, ulong xferID, uint packetID, byte[] data) |
193 | { | 193 | { |
194 | if (mXferID == xferID) | 194 | if (mXferID == xferID) |
195 | { | 195 | { |
196 | if (m_asset.Data.Length > 1) | 196 | if (m_asset.Data.Length > 1) |
197 | { | 197 | { |
198 | byte[] destinationArray = new byte[m_asset.Data.Length + data.Length]; | 198 | byte[] destinationArray = new byte[m_asset.Data.Length + data.Length]; |
199 | Array.Copy(m_asset.Data, 0, destinationArray, 0, m_asset.Data.Length); | 199 | Array.Copy(m_asset.Data, 0, destinationArray, 0, m_asset.Data.Length); |
200 | Array.Copy(data, 0, destinationArray, m_asset.Data.Length, data.Length); | 200 | Array.Copy(data, 0, destinationArray, m_asset.Data.Length, data.Length); |
201 | m_asset.Data = destinationArray; | 201 | m_asset.Data = destinationArray; |
202 | } | 202 | } |
203 | else | 203 | else |
204 | { | 204 | { |
205 | byte[] buffer2 = new byte[data.Length - 4]; | 205 | byte[] buffer2 = new byte[data.Length - 4]; |
206 | Array.Copy(data, 4, buffer2, 0, data.Length - 4); | 206 | Array.Copy(data, 4, buffer2, 0, data.Length - 4); |
207 | m_asset.Data = buffer2; | 207 | m_asset.Data = buffer2; |
208 | } | 208 | } |
209 | 209 | ||
210 | remoteClient.SendConfirmXfer(xferID, packetID); | 210 | remoteClient.SendConfirmXfer(xferID, packetID); |
211 | 211 | ||
212 | if ((packetID & 0x80000000) != 0) | 212 | if ((packetID & 0x80000000) != 0) |
213 | { | 213 | { |
214 | SendCompleteMessage(remoteClient); | 214 | SendCompleteMessage(remoteClient); |
215 | 215 | ||
216 | } | 216 | } |
217 | } | 217 | } |
218 | } | 218 | } |
219 | 219 | ||
220 | protected void SendCompleteMessage(IClientAPI remoteClient) | 220 | protected void SendCompleteMessage(IClientAPI remoteClient) |
221 | { | 221 | { |
222 | m_complete = true; | 222 | m_complete = true; |
223 | handlerUploadDone = UploadDone; | 223 | handlerUploadDone = UploadDone; |
224 | if (handlerUploadDone != null) | 224 | if (handlerUploadDone != null) |
225 | { | 225 | { |
226 | handlerUploadDone(m_asset.Name, m_asset.FullID, m_asset.Data, remoteClient); | 226 | handlerUploadDone(m_asset.Name, m_asset.FullID, m_asset.Data, remoteClient); |
227 | } | 227 | } |
228 | } | 228 | } |
229 | 229 | ||
230 | public void AbortUpload(IClientAPI remoteClient) | 230 | public void AbortUpload(IClientAPI remoteClient) |
231 | { | 231 | { |
232 | handlerAbort = UploadAborted; | 232 | handlerAbort = UploadAborted; |
233 | if (handlerAbort != null) | 233 | if (handlerAbort != null) |
234 | { | 234 | { |
235 | handlerAbort(m_asset.Name, mXferID, remoteClient); | 235 | handlerAbort(m_asset.Name, mXferID, remoteClient); |
236 | } | 236 | } |
237 | } | 237 | } |
238 | } | 238 | } |
239 | } | 239 | } |