diff options
author | UbitUmarov | 2015-09-01 11:43:07 +0100 |
---|---|---|
committer | UbitUmarov | 2015-09-01 11:43:07 +0100 |
commit | fb78b182520fc9bb0f971afd0322029c70278ea6 (patch) | |
tree | b4e30d383938fdeef8c92d1d1c2f44bb61d329bd /OpenSim/Capabilities | |
parent | lixo (diff) | |
parent | Mantis #7713: fixed bug introduced by 1st MOSES patch. (diff) | |
download | opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.zip opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.gz opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.bz2 opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.xz |
Merge remote-tracking branch 'os/master'
Diffstat (limited to 'OpenSim/Capabilities')
46 files changed, 5599 insertions, 0 deletions
diff --git a/OpenSim/Capabilities/Caps.cs b/OpenSim/Capabilities/Caps.cs new file mode 100644 index 0000000..049afab --- /dev/null +++ b/OpenSim/Capabilities/Caps.cs | |||
@@ -0,0 +1,259 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections; | ||
30 | using System.Collections.Generic; | ||
31 | using System.IO; | ||
32 | using System.Reflection; | ||
33 | using log4net; | ||
34 | using Nini.Config; | ||
35 | using OpenMetaverse; | ||
36 | using OpenSim.Framework.Servers; | ||
37 | using OpenSim.Framework.Servers.HttpServer; | ||
38 | using OpenSim.Services.Interfaces; | ||
39 | |||
40 | // using OpenSim.Region.Framework.Interfaces; | ||
41 | |||
42 | namespace OpenSim.Framework.Capabilities | ||
43 | { | ||
44 | /// <summary> | ||
45 | /// XXX Probably not a particularly nice way of allow us to get the scene presence from the scene (chiefly so that | ||
46 | /// we can popup a message on the user's client if the inventory service has permanently failed). But I didn't want | ||
47 | /// to just pass the whole Scene into CAPS. | ||
48 | /// </summary> | ||
49 | public delegate IClientAPI GetClientDelegate(UUID agentID); | ||
50 | |||
51 | public class Caps | ||
52 | { | ||
53 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
54 | |||
55 | private string m_httpListenerHostName; | ||
56 | private uint m_httpListenPort; | ||
57 | |||
58 | /// <summary> | ||
59 | /// This is the uuid portion of every CAPS path. It is used to make capability urls private to the requester. | ||
60 | /// </summary> | ||
61 | private string m_capsObjectPath; | ||
62 | public string CapsObjectPath { get { return m_capsObjectPath; } } | ||
63 | |||
64 | private CapsHandlers m_capsHandlers; | ||
65 | |||
66 | private Dictionary<string, PollServiceEventArgs> m_pollServiceHandlers | ||
67 | = new Dictionary<string, PollServiceEventArgs>(); | ||
68 | |||
69 | private Dictionary<string, string> m_externalCapsHandlers = new Dictionary<string, string>(); | ||
70 | |||
71 | private IHttpServer m_httpListener; | ||
72 | private UUID m_agentID; | ||
73 | private string m_regionName; | ||
74 | |||
75 | public UUID AgentID | ||
76 | { | ||
77 | get { return m_agentID; } | ||
78 | } | ||
79 | |||
80 | public string RegionName | ||
81 | { | ||
82 | get { return m_regionName; } | ||
83 | } | ||
84 | |||
85 | public string HostName | ||
86 | { | ||
87 | get { return m_httpListenerHostName; } | ||
88 | } | ||
89 | |||
90 | public uint Port | ||
91 | { | ||
92 | get { return m_httpListenPort; } | ||
93 | } | ||
94 | |||
95 | public IHttpServer HttpListener | ||
96 | { | ||
97 | get { return m_httpListener; } | ||
98 | } | ||
99 | |||
100 | public bool SSLCaps | ||
101 | { | ||
102 | get { return m_httpListener.UseSSL; } | ||
103 | } | ||
104 | |||
105 | public string SSLCommonName | ||
106 | { | ||
107 | get { return m_httpListener.SSLCommonName; } | ||
108 | } | ||
109 | |||
110 | public CapsHandlers CapsHandlers | ||
111 | { | ||
112 | get { return m_capsHandlers; } | ||
113 | } | ||
114 | |||
115 | public Dictionary<string, string> ExternalCapsHandlers | ||
116 | { | ||
117 | get { return m_externalCapsHandlers; } | ||
118 | } | ||
119 | |||
120 | public Caps(IHttpServer httpServer, string httpListen, uint httpPort, string capsPath, | ||
121 | UUID agent, string regionName) | ||
122 | { | ||
123 | m_capsObjectPath = capsPath; | ||
124 | m_httpListener = httpServer; | ||
125 | m_httpListenerHostName = httpListen; | ||
126 | |||
127 | m_httpListenPort = httpPort; | ||
128 | |||
129 | if (httpServer != null && httpServer.UseSSL) | ||
130 | { | ||
131 | m_httpListenPort = httpServer.SSLPort; | ||
132 | httpListen = httpServer.SSLCommonName; | ||
133 | httpPort = httpServer.SSLPort; | ||
134 | } | ||
135 | |||
136 | m_agentID = agent; | ||
137 | m_capsHandlers = new CapsHandlers(httpServer, httpListen, httpPort, (httpServer == null) ? false : httpServer.UseSSL); | ||
138 | m_regionName = regionName; | ||
139 | } | ||
140 | |||
141 | /// <summary> | ||
142 | /// Register a handler. This allows modules to register handlers. | ||
143 | /// </summary> | ||
144 | /// <param name="capName"></param> | ||
145 | /// <param name="handler"></param> | ||
146 | public void RegisterHandler(string capName, IRequestHandler handler) | ||
147 | { | ||
148 | //m_log.DebugFormat("[CAPS]: Registering handler for \"{0}\": path {1}", capName, handler.Path); | ||
149 | m_capsHandlers[capName] = handler; | ||
150 | } | ||
151 | |||
152 | public void RegisterPollHandler(string capName, PollServiceEventArgs pollServiceHandler) | ||
153 | { | ||
154 | // m_log.DebugFormat( | ||
155 | // "[CAPS]: Registering handler with name {0}, url {1} for {2}", | ||
156 | // capName, pollServiceHandler.Url, m_agentID, m_regionName); | ||
157 | |||
158 | m_pollServiceHandlers.Add(capName, pollServiceHandler); | ||
159 | |||
160 | m_httpListener.AddPollServiceHTTPHandler(pollServiceHandler.Url, pollServiceHandler); | ||
161 | |||
162 | // uint port = (MainServer.Instance == null) ? 0 : MainServer.Instance.Port; | ||
163 | // string protocol = "http"; | ||
164 | // string hostName = m_httpListenerHostName; | ||
165 | // | ||
166 | // if (MainServer.Instance.UseSSL) | ||
167 | // { | ||
168 | // hostName = MainServer.Instance.SSLCommonName; | ||
169 | // port = MainServer.Instance.SSLPort; | ||
170 | // protocol = "https"; | ||
171 | // } | ||
172 | |||
173 | // RegisterHandler( | ||
174 | // capName, String.Format("{0}://{1}:{2}{3}", protocol, hostName, port, pollServiceHandler.Url)); | ||
175 | } | ||
176 | |||
177 | /// <summary> | ||
178 | /// Register an external handler. The service for this capability is somewhere else | ||
179 | /// given by the URL. | ||
180 | /// </summary> | ||
181 | /// <param name="capsName"></param> | ||
182 | /// <param name="url"></param> | ||
183 | public void RegisterHandler(string capsName, string url) | ||
184 | { | ||
185 | m_externalCapsHandlers.Add(capsName, url); | ||
186 | } | ||
187 | |||
188 | /// <summary> | ||
189 | /// Remove all CAPS service handlers. | ||
190 | /// </summary> | ||
191 | public void DeregisterHandlers() | ||
192 | { | ||
193 | foreach (string capsName in m_capsHandlers.Caps) | ||
194 | { | ||
195 | m_capsHandlers.Remove(capsName); | ||
196 | } | ||
197 | |||
198 | foreach (PollServiceEventArgs handler in m_pollServiceHandlers.Values) | ||
199 | { | ||
200 | m_httpListener.RemovePollServiceHTTPHandler("", handler.Url); | ||
201 | } | ||
202 | } | ||
203 | |||
204 | public bool TryGetPollHandler(string name, out PollServiceEventArgs pollHandler) | ||
205 | { | ||
206 | return m_pollServiceHandlers.TryGetValue(name, out pollHandler); | ||
207 | } | ||
208 | |||
209 | public Dictionary<string, PollServiceEventArgs> GetPollHandlers() | ||
210 | { | ||
211 | return new Dictionary<string, PollServiceEventArgs>(m_pollServiceHandlers); | ||
212 | } | ||
213 | |||
214 | /// <summary> | ||
215 | /// Return an LLSD-serializable Hashtable describing the | ||
216 | /// capabilities and their handler details. | ||
217 | /// </summary> | ||
218 | /// <param name="excludeSeed">If true, then exclude the seed cap.</param> | ||
219 | public Hashtable GetCapsDetails(bool excludeSeed, List<string> requestedCaps) | ||
220 | { | ||
221 | Hashtable caps = CapsHandlers.GetCapsDetails(excludeSeed, requestedCaps); | ||
222 | |||
223 | lock (m_pollServiceHandlers) | ||
224 | { | ||
225 | foreach (KeyValuePair <string, PollServiceEventArgs> kvp in m_pollServiceHandlers) | ||
226 | { | ||
227 | if (!requestedCaps.Contains(kvp.Key)) | ||
228 | continue; | ||
229 | |||
230 | string hostName = m_httpListenerHostName; | ||
231 | uint port = (MainServer.Instance == null) ? 0 : MainServer.Instance.Port; | ||
232 | string protocol = "http"; | ||
233 | |||
234 | if (MainServer.Instance.UseSSL) | ||
235 | { | ||
236 | hostName = MainServer.Instance.SSLCommonName; | ||
237 | port = MainServer.Instance.SSLPort; | ||
238 | protocol = "https"; | ||
239 | } | ||
240 | // | ||
241 | // caps.RegisterHandler("FetchInventoryDescendents2", String.Format("{0}://{1}:{2}{3}", protocol, hostName, port, capUrl)); | ||
242 | |||
243 | caps[kvp.Key] = string.Format("{0}://{1}:{2}{3}", protocol, hostName, port, kvp.Value.Url); | ||
244 | } | ||
245 | } | ||
246 | |||
247 | // Add the external too | ||
248 | foreach (KeyValuePair<string, string> kvp in ExternalCapsHandlers) | ||
249 | { | ||
250 | if (!requestedCaps.Contains(kvp.Key)) | ||
251 | continue; | ||
252 | |||
253 | caps[kvp.Key] = kvp.Value; | ||
254 | } | ||
255 | |||
256 | return caps; | ||
257 | } | ||
258 | } | ||
259 | } \ No newline at end of file | ||
diff --git a/OpenSim/Capabilities/CapsHandlers.cs b/OpenSim/Capabilities/CapsHandlers.cs new file mode 100644 index 0000000..890df90 --- /dev/null +++ b/OpenSim/Capabilities/CapsHandlers.cs | |||
@@ -0,0 +1,200 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.Collections; | ||
29 | using System.Collections.Generic; | ||
30 | using OpenSim.Framework.Servers; | ||
31 | using OpenSim.Framework.Servers.HttpServer; | ||
32 | |||
33 | namespace OpenSim.Framework.Capabilities | ||
34 | { | ||
35 | /// <summary> | ||
36 | /// CapsHandlers is a cap handler container but also takes | ||
37 | /// care of adding and removing cap handlers to and from the | ||
38 | /// supplied BaseHttpServer. | ||
39 | /// </summary> | ||
40 | public class CapsHandlers | ||
41 | { | ||
42 | private Dictionary<string, IRequestHandler> m_capsHandlers = new Dictionary<string, IRequestHandler>(); | ||
43 | private IHttpServer m_httpListener; | ||
44 | private string m_httpListenerHostName; | ||
45 | private uint m_httpListenerPort; | ||
46 | private bool m_useSSL = false; | ||
47 | |||
48 | /// <summary></summary> | ||
49 | /// CapsHandlers is a cap handler container but also takes | ||
50 | /// care of adding and removing cap handlers to and from the | ||
51 | /// supplied BaseHttpServer. | ||
52 | /// </summary> | ||
53 | /// <param name="httpListener">base HTTP server</param> | ||
54 | /// <param name="httpListenerHostname">host name of the HTTP server</param> | ||
55 | /// <param name="httpListenerPort">HTTP port</param> | ||
56 | public CapsHandlers(BaseHttpServer httpListener, string httpListenerHostname, uint httpListenerPort) | ||
57 | : this(httpListener,httpListenerHostname,httpListenerPort, false) | ||
58 | { | ||
59 | } | ||
60 | |||
61 | /// <summary></summary> | ||
62 | /// CapsHandlers is a cap handler container but also takes | ||
63 | /// care of adding and removing cap handlers to and from the | ||
64 | /// supplied BaseHttpServer. | ||
65 | /// </summary> | ||
66 | /// <param name="httpListener">base HTTP server</param> | ||
67 | /// <param name="httpListenerHostname">host name of the HTTP | ||
68 | /// server</param> | ||
69 | /// <param name="httpListenerPort">HTTP port</param> | ||
70 | public CapsHandlers(IHttpServer httpListener, string httpListenerHostname, uint httpListenerPort, bool https) | ||
71 | { | ||
72 | m_httpListener = httpListener; | ||
73 | m_httpListenerHostName = httpListenerHostname; | ||
74 | m_httpListenerPort = httpListenerPort; | ||
75 | m_useSSL = https; | ||
76 | if (httpListener != null && m_useSSL) | ||
77 | { | ||
78 | m_httpListenerHostName = httpListener.SSLCommonName; | ||
79 | m_httpListenerPort = httpListener.SSLPort; | ||
80 | } | ||
81 | } | ||
82 | |||
83 | /// <summary> | ||
84 | /// Remove the cap handler for a capability. | ||
85 | /// </summary> | ||
86 | /// <param name="capsName">name of the capability of the cap | ||
87 | /// handler to be removed</param> | ||
88 | public void Remove(string capsName) | ||
89 | { | ||
90 | lock (m_capsHandlers) | ||
91 | { | ||
92 | m_httpListener.RemoveStreamHandler("POST", m_capsHandlers[capsName].Path); | ||
93 | m_httpListener.RemoveStreamHandler("GET", m_capsHandlers[capsName].Path); | ||
94 | m_capsHandlers.Remove(capsName); | ||
95 | } | ||
96 | } | ||
97 | |||
98 | public bool ContainsCap(string cap) | ||
99 | { | ||
100 | lock (m_capsHandlers) | ||
101 | return m_capsHandlers.ContainsKey(cap); | ||
102 | } | ||
103 | |||
104 | /// <summary> | ||
105 | /// The indexer allows us to treat the CapsHandlers object | ||
106 | /// in an intuitive dictionary like way. | ||
107 | /// </summary> | ||
108 | /// <remarks> | ||
109 | /// The indexer will throw an exception when you try to | ||
110 | /// retrieve a cap handler for a cap that is not contained in | ||
111 | /// CapsHandlers. | ||
112 | /// </remarks> | ||
113 | public IRequestHandler this[string idx] | ||
114 | { | ||
115 | get | ||
116 | { | ||
117 | lock (m_capsHandlers) | ||
118 | return m_capsHandlers[idx]; | ||
119 | } | ||
120 | |||
121 | set | ||
122 | { | ||
123 | lock (m_capsHandlers) | ||
124 | { | ||
125 | if (m_capsHandlers.ContainsKey(idx)) | ||
126 | { | ||
127 | m_httpListener.RemoveStreamHandler("POST", m_capsHandlers[idx].Path); | ||
128 | m_capsHandlers.Remove(idx); | ||
129 | } | ||
130 | |||
131 | if (null == value) return; | ||
132 | |||
133 | m_capsHandlers[idx] = value; | ||
134 | m_httpListener.AddStreamHandler(value); | ||
135 | } | ||
136 | } | ||
137 | } | ||
138 | |||
139 | /// <summary> | ||
140 | /// Return the list of cap names for which this CapsHandlers | ||
141 | /// object contains cap handlers. | ||
142 | /// </summary> | ||
143 | public string[] Caps | ||
144 | { | ||
145 | get | ||
146 | { | ||
147 | lock (m_capsHandlers) | ||
148 | { | ||
149 | string[] __keys = new string[m_capsHandlers.Keys.Count]; | ||
150 | m_capsHandlers.Keys.CopyTo(__keys, 0); | ||
151 | return __keys; | ||
152 | } | ||
153 | } | ||
154 | } | ||
155 | |||
156 | /// <summary> | ||
157 | /// Return an LLSD-serializable Hashtable describing the | ||
158 | /// capabilities and their handler details. | ||
159 | /// </summary> | ||
160 | /// <param name="excludeSeed">If true, then exclude the seed cap.</param> | ||
161 | public Hashtable GetCapsDetails(bool excludeSeed, List<string> requestedCaps) | ||
162 | { | ||
163 | Hashtable caps = new Hashtable(); | ||
164 | string protocol = "http://"; | ||
165 | |||
166 | if (m_useSSL) | ||
167 | protocol = "https://"; | ||
168 | |||
169 | string baseUrl = protocol + m_httpListenerHostName + ":" + m_httpListenerPort.ToString(); | ||
170 | |||
171 | lock (m_capsHandlers) | ||
172 | { | ||
173 | foreach (string capsName in m_capsHandlers.Keys) | ||
174 | { | ||
175 | if (excludeSeed && "SEED" == capsName) | ||
176 | continue; | ||
177 | |||
178 | if (requestedCaps != null && !requestedCaps.Contains(capsName)) | ||
179 | continue; | ||
180 | |||
181 | caps[capsName] = baseUrl + m_capsHandlers[capsName].Path; | ||
182 | } | ||
183 | } | ||
184 | |||
185 | return caps; | ||
186 | } | ||
187 | |||
188 | /// <summary> | ||
189 | /// Returns a copy of the dictionary of all the HTTP cap handlers | ||
190 | /// </summary> | ||
191 | /// <returns> | ||
192 | /// The dictionary copy. The key is the capability name, the value is the HTTP handler. | ||
193 | /// </returns> | ||
194 | public Dictionary<string, IRequestHandler> GetCapsHandlers() | ||
195 | { | ||
196 | lock (m_capsHandlers) | ||
197 | return new Dictionary<string, IRequestHandler>(m_capsHandlers); | ||
198 | } | ||
199 | } | ||
200 | } \ No newline at end of file | ||
diff --git a/OpenSim/Capabilities/Handlers/AvatarPickerSearch/AvatarPickerSearchHandler.cs b/OpenSim/Capabilities/Handlers/AvatarPickerSearch/AvatarPickerSearchHandler.cs new file mode 100644 index 0000000..426174d --- /dev/null +++ b/OpenSim/Capabilities/Handlers/AvatarPickerSearch/AvatarPickerSearchHandler.cs | |||
@@ -0,0 +1,116 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Collections.Specialized; | ||
31 | using System.IO; | ||
32 | using System.Reflection; | ||
33 | using System.Web; | ||
34 | using log4net; | ||
35 | using Nini.Config; | ||
36 | using OpenMetaverse; | ||
37 | using OpenSim.Framework; | ||
38 | using OpenSim.Framework.Capabilities; | ||
39 | using OpenSim.Framework.Servers; | ||
40 | using OpenSim.Framework.Servers.HttpServer; | ||
41 | //using OpenSim.Region.Framework.Interfaces; | ||
42 | using OpenSim.Services.Interfaces; | ||
43 | using Caps = OpenSim.Framework.Capabilities.Caps; | ||
44 | |||
45 | namespace OpenSim.Capabilities.Handlers | ||
46 | { | ||
47 | public class AvatarPickerSearchHandler : BaseStreamHandler | ||
48 | { | ||
49 | private static readonly ILog m_log = | ||
50 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
51 | private IPeople m_PeopleService; | ||
52 | |||
53 | public AvatarPickerSearchHandler(string path, IPeople peopleService, string name, string description) | ||
54 | : base("GET", path, name, description) | ||
55 | { | ||
56 | m_PeopleService = peopleService; | ||
57 | } | ||
58 | |||
59 | protected override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
60 | { | ||
61 | // Try to parse the texture ID from the request URL | ||
62 | NameValueCollection query = HttpUtility.ParseQueryString(httpRequest.Url.Query); | ||
63 | string names = query.GetOne("names"); | ||
64 | string psize = query.GetOne("page_size"); | ||
65 | string pnumber = query.GetOne("page"); | ||
66 | |||
67 | if (m_PeopleService == null) | ||
68 | return FailureResponse(names, (int)System.Net.HttpStatusCode.InternalServerError, httpResponse); | ||
69 | |||
70 | if (string.IsNullOrEmpty(names) || names.Length < 3) | ||
71 | return FailureResponse(names, (int)System.Net.HttpStatusCode.BadRequest, httpResponse); | ||
72 | |||
73 | m_log.DebugFormat("[AVATAR PICKER SEARCH]: search for {0}", names); | ||
74 | |||
75 | int page_size = (string.IsNullOrEmpty(psize) ? 500 : Int32.Parse(psize)); | ||
76 | int page_number = (string.IsNullOrEmpty(pnumber) ? 1 : Int32.Parse(pnumber)); | ||
77 | |||
78 | // Full content request | ||
79 | httpResponse.StatusCode = (int)System.Net.HttpStatusCode.OK; | ||
80 | //httpResponse.ContentLength = ??; | ||
81 | httpResponse.ContentType = "application/llsd+xml"; | ||
82 | |||
83 | List<UserData> users = m_PeopleService.GetUserData(names, page_size, page_number); | ||
84 | |||
85 | LLSDAvatarPicker osdReply = new LLSDAvatarPicker(); | ||
86 | osdReply.next_page_url = httpRequest.RawUrl; | ||
87 | foreach (UserData u in users) | ||
88 | osdReply.agents.Array.Add(ConvertUserData(u)); | ||
89 | |||
90 | string reply = LLSDHelpers.SerialiseLLSDReply(osdReply); | ||
91 | return System.Text.Encoding.UTF8.GetBytes(reply); | ||
92 | } | ||
93 | |||
94 | private LLSDPerson ConvertUserData(UserData user) | ||
95 | { | ||
96 | LLSDPerson p = new LLSDPerson(); | ||
97 | p.legacy_first_name = user.FirstName; | ||
98 | p.legacy_last_name = user.LastName; | ||
99 | p.display_name = user.FirstName + " " + user.LastName; | ||
100 | if (user.LastName.StartsWith("@")) | ||
101 | p.username = user.FirstName.ToLower() + user.LastName.ToLower(); | ||
102 | else | ||
103 | p.username = user.FirstName.ToLower() + "." + user.LastName.ToLower(); | ||
104 | p.id = user.Id; | ||
105 | p.is_display_name_default = false; | ||
106 | return p; | ||
107 | } | ||
108 | |||
109 | private byte[] FailureResponse(string names, int statuscode, IOSHttpResponse httpResponse) | ||
110 | { | ||
111 | m_log.Error("[AVATAR PICKER SEARCH]: Error searching for " + names); | ||
112 | httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; | ||
113 | return System.Text.Encoding.UTF8.GetBytes(string.Empty); | ||
114 | } | ||
115 | } | ||
116 | } \ No newline at end of file | ||
diff --git a/OpenSim/Capabilities/Handlers/FetchInventory/FetchInvDescHandler.cs b/OpenSim/Capabilities/Handlers/FetchInventory/FetchInvDescHandler.cs new file mode 100644 index 0000000..7197049 --- /dev/null +++ b/OpenSim/Capabilities/Handlers/FetchInventory/FetchInvDescHandler.cs | |||
@@ -0,0 +1,848 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Linq; | ||
32 | using System.Reflection; | ||
33 | using log4net; | ||
34 | using Nini.Config; | ||
35 | using OpenMetaverse; | ||
36 | using OpenMetaverse.StructuredData; | ||
37 | using OpenSim.Framework; | ||
38 | using OpenSim.Framework.Capabilities; | ||
39 | using OpenSim.Region.Framework.Interfaces; | ||
40 | using OpenSim.Framework.Servers.HttpServer; | ||
41 | using OpenSim.Services.Interfaces; | ||
42 | using Caps = OpenSim.Framework.Capabilities.Caps; | ||
43 | |||
44 | namespace OpenSim.Capabilities.Handlers | ||
45 | { | ||
46 | public class FetchInvDescHandler | ||
47 | { | ||
48 | private static readonly ILog m_log = | ||
49 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
50 | |||
51 | private IInventoryService m_InventoryService; | ||
52 | private ILibraryService m_LibraryService; | ||
53 | private IScene m_Scene; | ||
54 | // private object m_fetchLock = new Object(); | ||
55 | |||
56 | public FetchInvDescHandler(IInventoryService invService, ILibraryService libService, IScene s) | ||
57 | { | ||
58 | m_InventoryService = invService; | ||
59 | m_LibraryService = libService; | ||
60 | m_Scene = s; | ||
61 | } | ||
62 | |||
63 | |||
64 | public string FetchInventoryDescendentsRequest(string request, string path, string param, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
65 | { | ||
66 | //m_log.DebugFormat("[XXX]: FetchInventoryDescendentsRequest in {0}, {1}", (m_Scene == null) ? "none" : m_Scene.Name, request); | ||
67 | |||
68 | // nasty temporary hack here, the linden client falsely | ||
69 | // identifies the uuid 00000000-0000-0000-0000-000000000000 | ||
70 | // as a string which breaks us | ||
71 | // | ||
72 | // correctly mark it as a uuid | ||
73 | // | ||
74 | request = request.Replace("<string>00000000-0000-0000-0000-000000000000</string>", "<uuid>00000000-0000-0000-0000-000000000000</uuid>"); | ||
75 | |||
76 | // another hack <integer>1</integer> results in a | ||
77 | // System.ArgumentException: Object type System.Int32 cannot | ||
78 | // be converted to target type: System.Boolean | ||
79 | // | ||
80 | request = request.Replace("<key>fetch_folders</key><integer>0</integer>", "<key>fetch_folders</key><boolean>0</boolean>"); | ||
81 | request = request.Replace("<key>fetch_folders</key><integer>1</integer>", "<key>fetch_folders</key><boolean>1</boolean>"); | ||
82 | |||
83 | Hashtable hash = new Hashtable(); | ||
84 | try | ||
85 | { | ||
86 | hash = (Hashtable)LLSD.LLSDDeserialize(Utils.StringToBytes(request)); | ||
87 | } | ||
88 | catch (LLSD.LLSDParseException e) | ||
89 | { | ||
90 | m_log.ErrorFormat("[WEB FETCH INV DESC HANDLER]: Fetch error: {0}{1}" + e.Message, e.StackTrace); | ||
91 | m_log.Error("Request: " + request); | ||
92 | } | ||
93 | |||
94 | ArrayList foldersrequested = (ArrayList)hash["folders"]; | ||
95 | |||
96 | string response = ""; | ||
97 | string bad_folders_response = ""; | ||
98 | |||
99 | List<LLSDFetchInventoryDescendents> folders = new List<LLSDFetchInventoryDescendents>(); | ||
100 | for (int i = 0; i < foldersrequested.Count; i++) | ||
101 | { | ||
102 | Hashtable inventoryhash = (Hashtable)foldersrequested[i]; | ||
103 | |||
104 | LLSDFetchInventoryDescendents llsdRequest = new LLSDFetchInventoryDescendents(); | ||
105 | |||
106 | try | ||
107 | { | ||
108 | LLSDHelpers.DeserialiseOSDMap(inventoryhash, llsdRequest); | ||
109 | } | ||
110 | catch (Exception e) | ||
111 | { | ||
112 | m_log.Debug("[WEB FETCH INV DESC HANDLER]: caught exception doing OSD deserialize" + e); | ||
113 | continue; | ||
114 | } | ||
115 | |||
116 | // Filter duplicate folder ids that bad viewers may send | ||
117 | if (folders.Find(f => f.folder_id == llsdRequest.folder_id) == null) | ||
118 | folders.Add(llsdRequest); | ||
119 | |||
120 | } | ||
121 | |||
122 | if (folders.Count > 0) | ||
123 | { | ||
124 | List<UUID> bad_folders = new List<UUID>(); | ||
125 | List<InventoryCollectionWithDescendents> invcollSet = Fetch(folders, bad_folders); | ||
126 | //m_log.DebugFormat("[XXX]: Got {0} folders from a request of {1}", invcollSet.Count, folders.Count); | ||
127 | |||
128 | if (invcollSet == null) | ||
129 | { | ||
130 | m_log.DebugFormat("[WEB FETCH INV DESC HANDLER]: Multiple folder fetch failed. Trying old protocol."); | ||
131 | #pragma warning disable 0612 | ||
132 | return FetchInventoryDescendentsRequest(foldersrequested, httpRequest, httpResponse); | ||
133 | #pragma warning restore 0612 | ||
134 | } | ||
135 | |||
136 | string inventoryitemstr = string.Empty; | ||
137 | foreach (InventoryCollectionWithDescendents icoll in invcollSet) | ||
138 | { | ||
139 | LLSDInventoryDescendents reply = ToLLSD(icoll.Collection, icoll.Descendents); | ||
140 | |||
141 | inventoryitemstr = LLSDHelpers.SerialiseLLSDReply(reply); | ||
142 | inventoryitemstr = inventoryitemstr.Replace("<llsd><map><key>folders</key><array>", ""); | ||
143 | inventoryitemstr = inventoryitemstr.Replace("</array></map></llsd>", ""); | ||
144 | |||
145 | response += inventoryitemstr; | ||
146 | } | ||
147 | |||
148 | //m_log.DebugFormat("[WEB FETCH INV DESC HANDLER]: Bad folders {0}", string.Join(", ", bad_folders)); | ||
149 | foreach (UUID bad in bad_folders) | ||
150 | bad_folders_response += "<uuid>" + bad + "</uuid>"; | ||
151 | } | ||
152 | |||
153 | if (response.Length == 0) | ||
154 | { | ||
155 | /* Viewers expect a bad_folders array when not available */ | ||
156 | if (bad_folders_response.Length != 0) | ||
157 | { | ||
158 | response = "<llsd><map><key>bad_folders</key><array>" + bad_folders_response + "</array></map></llsd>"; | ||
159 | } | ||
160 | else | ||
161 | { | ||
162 | response = "<llsd><map><key>folders</key><array /></map></llsd>"; | ||
163 | } | ||
164 | } | ||
165 | else | ||
166 | { | ||
167 | if (bad_folders_response.Length != 0) | ||
168 | { | ||
169 | response = "<llsd><map><key>folders</key><array>" + response + "</array><key>bad_folders</key><array>" + bad_folders_response + "</array></map></llsd>"; | ||
170 | } | ||
171 | else | ||
172 | { | ||
173 | response = "<llsd><map><key>folders</key><array>" + response + "</array></map></llsd>"; | ||
174 | } | ||
175 | } | ||
176 | |||
177 | //m_log.DebugFormat("[WEB FETCH INV DESC HANDLER]: Replying to CAPS fetch inventory request for {0} folders. Item count {1}", folders.Count, item_count); | ||
178 | //m_log.Debug("[WEB FETCH INV DESC HANDLER] " + response); | ||
179 | |||
180 | return response; | ||
181 | |||
182 | } | ||
183 | |||
184 | /// <summary> | ||
185 | /// Construct an LLSD reply packet to a CAPS inventory request | ||
186 | /// </summary> | ||
187 | /// <param name="invFetch"></param> | ||
188 | /// <returns></returns> | ||
189 | private LLSDInventoryDescendents FetchInventoryReply(LLSDFetchInventoryDescendents invFetch) | ||
190 | { | ||
191 | LLSDInventoryDescendents reply = new LLSDInventoryDescendents(); | ||
192 | LLSDInventoryFolderContents contents = new LLSDInventoryFolderContents(); | ||
193 | contents.agent_id = invFetch.owner_id; | ||
194 | contents.owner_id = invFetch.owner_id; | ||
195 | contents.folder_id = invFetch.folder_id; | ||
196 | |||
197 | reply.folders.Array.Add(contents); | ||
198 | InventoryCollection inv = new InventoryCollection(); | ||
199 | inv.Folders = new List<InventoryFolderBase>(); | ||
200 | inv.Items = new List<InventoryItemBase>(); | ||
201 | int version = 0; | ||
202 | int descendents = 0; | ||
203 | |||
204 | #pragma warning disable 0612 | ||
205 | inv = Fetch( | ||
206 | invFetch.owner_id, invFetch.folder_id, invFetch.owner_id, | ||
207 | invFetch.fetch_folders, invFetch.fetch_items, invFetch.sort_order, out version, out descendents); | ||
208 | #pragma warning restore 0612 | ||
209 | |||
210 | if (inv != null && inv.Folders != null) | ||
211 | { | ||
212 | foreach (InventoryFolderBase invFolder in inv.Folders) | ||
213 | { | ||
214 | contents.categories.Array.Add(ConvertInventoryFolder(invFolder)); | ||
215 | } | ||
216 | |||
217 | descendents += inv.Folders.Count; | ||
218 | } | ||
219 | |||
220 | if (inv != null && inv.Items != null) | ||
221 | { | ||
222 | foreach (InventoryItemBase invItem in inv.Items) | ||
223 | { | ||
224 | contents.items.Array.Add(ConvertInventoryItem(invItem)); | ||
225 | } | ||
226 | } | ||
227 | |||
228 | contents.descendents = descendents; | ||
229 | contents.version = version; | ||
230 | |||
231 | //m_log.DebugFormat( | ||
232 | // "[WEB FETCH INV DESC HANDLER]: Replying to request for folder {0} (fetch items {1}, fetch folders {2}) with {3} items and {4} folders for agent {5}", | ||
233 | // invFetch.folder_id, | ||
234 | // invFetch.fetch_items, | ||
235 | // invFetch.fetch_folders, | ||
236 | // contents.items.Array.Count, | ||
237 | // contents.categories.Array.Count, | ||
238 | // invFetch.owner_id); | ||
239 | |||
240 | return reply; | ||
241 | } | ||
242 | |||
243 | private LLSDInventoryDescendents ToLLSD(InventoryCollection inv, int descendents) | ||
244 | { | ||
245 | LLSDInventoryDescendents reply = new LLSDInventoryDescendents(); | ||
246 | LLSDInventoryFolderContents contents = new LLSDInventoryFolderContents(); | ||
247 | contents.agent_id = inv.OwnerID; | ||
248 | contents.owner_id = inv.OwnerID; | ||
249 | contents.folder_id = inv.FolderID; | ||
250 | |||
251 | reply.folders.Array.Add(contents); | ||
252 | |||
253 | if (inv.Folders != null) | ||
254 | { | ||
255 | foreach (InventoryFolderBase invFolder in inv.Folders) | ||
256 | { | ||
257 | contents.categories.Array.Add(ConvertInventoryFolder(invFolder)); | ||
258 | } | ||
259 | |||
260 | descendents += inv.Folders.Count; | ||
261 | } | ||
262 | |||
263 | if (inv.Items != null) | ||
264 | { | ||
265 | foreach (InventoryItemBase invItem in inv.Items) | ||
266 | { | ||
267 | contents.items.Array.Add(ConvertInventoryItem(invItem)); | ||
268 | } | ||
269 | } | ||
270 | |||
271 | contents.descendents = descendents; | ||
272 | contents.version = inv.Version; | ||
273 | |||
274 | return reply; | ||
275 | } | ||
276 | /// <summary> | ||
277 | /// Old style. Soon to be deprecated. | ||
278 | /// </summary> | ||
279 | /// <param name="request"></param> | ||
280 | /// <param name="httpRequest"></param> | ||
281 | /// <param name="httpResponse"></param> | ||
282 | /// <returns></returns> | ||
283 | [Obsolete] | ||
284 | private string FetchInventoryDescendentsRequest(ArrayList foldersrequested, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
285 | { | ||
286 | //m_log.DebugFormat("[WEB FETCH INV DESC HANDLER]: Received request for {0} folders", foldersrequested.Count); | ||
287 | |||
288 | string response = ""; | ||
289 | string bad_folders_response = ""; | ||
290 | |||
291 | for (int i = 0; i < foldersrequested.Count; i++) | ||
292 | { | ||
293 | string inventoryitemstr = ""; | ||
294 | Hashtable inventoryhash = (Hashtable)foldersrequested[i]; | ||
295 | |||
296 | LLSDFetchInventoryDescendents llsdRequest = new LLSDFetchInventoryDescendents(); | ||
297 | |||
298 | try | ||
299 | { | ||
300 | LLSDHelpers.DeserialiseOSDMap(inventoryhash, llsdRequest); | ||
301 | } | ||
302 | catch (Exception e) | ||
303 | { | ||
304 | m_log.Debug("[WEB FETCH INV DESC HANDLER]: caught exception doing OSD deserialize" + e); | ||
305 | } | ||
306 | |||
307 | LLSDInventoryDescendents reply = FetchInventoryReply(llsdRequest); | ||
308 | |||
309 | if (null == reply) | ||
310 | { | ||
311 | bad_folders_response += "<uuid>" + llsdRequest.folder_id.ToString() + "</uuid>"; | ||
312 | } | ||
313 | else | ||
314 | { | ||
315 | inventoryitemstr = LLSDHelpers.SerialiseLLSDReply(reply); | ||
316 | inventoryitemstr = inventoryitemstr.Replace("<llsd><map><key>folders</key><array>", ""); | ||
317 | inventoryitemstr = inventoryitemstr.Replace("</array></map></llsd>", ""); | ||
318 | } | ||
319 | |||
320 | response += inventoryitemstr; | ||
321 | } | ||
322 | |||
323 | if (response.Length == 0) | ||
324 | { | ||
325 | /* Viewers expect a bad_folders array when not available */ | ||
326 | if (bad_folders_response.Length != 0) | ||
327 | { | ||
328 | response = "<llsd><map><key>bad_folders</key><array>" + bad_folders_response + "</array></map></llsd>"; | ||
329 | } | ||
330 | else | ||
331 | { | ||
332 | response = "<llsd><map><key>folders</key><array /></map></llsd>"; | ||
333 | } | ||
334 | } | ||
335 | else | ||
336 | { | ||
337 | if (bad_folders_response.Length != 0) | ||
338 | { | ||
339 | response = "<llsd><map><key>folders</key><array>" + response + "</array><key>bad_folders</key><array>" + bad_folders_response + "</array></map></llsd>"; | ||
340 | } | ||
341 | else | ||
342 | { | ||
343 | response = "<llsd><map><key>folders</key><array>" + response + "</array></map></llsd>"; | ||
344 | } | ||
345 | } | ||
346 | |||
347 | // m_log.DebugFormat("[WEB FETCH INV DESC HANDLER]: Replying to CAPS fetch inventory request"); | ||
348 | //m_log.Debug("[WEB FETCH INV DESC HANDLER] "+response); | ||
349 | |||
350 | return response; | ||
351 | |||
352 | // } | ||
353 | } | ||
354 | |||
355 | /// <summary> | ||
356 | /// Handle the caps inventory descendents fetch. | ||
357 | /// </summary> | ||
358 | /// <param name="agentID"></param> | ||
359 | /// <param name="folderID"></param> | ||
360 | /// <param name="ownerID"></param> | ||
361 | /// <param name="fetchFolders"></param> | ||
362 | /// <param name="fetchItems"></param> | ||
363 | /// <param name="sortOrder"></param> | ||
364 | /// <param name="version"></param> | ||
365 | /// <returns>An empty InventoryCollection if the inventory look up failed</returns> | ||
366 | [Obsolete] | ||
367 | private InventoryCollection Fetch( | ||
368 | UUID agentID, UUID folderID, UUID ownerID, | ||
369 | bool fetchFolders, bool fetchItems, int sortOrder, out int version, out int descendents) | ||
370 | { | ||
371 | //m_log.DebugFormat( | ||
372 | // "[WEB FETCH INV DESC HANDLER]: Fetching folders ({0}), items ({1}) from {2} for agent {3}", | ||
373 | // fetchFolders, fetchItems, folderID, agentID); | ||
374 | |||
375 | // FIXME MAYBE: We're not handling sortOrder! | ||
376 | |||
377 | version = 0; | ||
378 | descendents = 0; | ||
379 | |||
380 | InventoryFolderImpl fold; | ||
381 | if (m_LibraryService != null && m_LibraryService.LibraryRootFolder != null && agentID == m_LibraryService.LibraryRootFolder.Owner) | ||
382 | { | ||
383 | if ((fold = m_LibraryService.LibraryRootFolder.FindFolder(folderID)) != null) | ||
384 | { | ||
385 | InventoryCollection ret = new InventoryCollection(); | ||
386 | ret.Folders = new List<InventoryFolderBase>(); | ||
387 | ret.Items = fold.RequestListOfItems(); | ||
388 | descendents = ret.Folders.Count + ret.Items.Count; | ||
389 | |||
390 | return ret; | ||
391 | } | ||
392 | } | ||
393 | |||
394 | InventoryCollection contents = new InventoryCollection(); | ||
395 | |||
396 | if (folderID != UUID.Zero) | ||
397 | { | ||
398 | InventoryCollection fetchedContents = m_InventoryService.GetFolderContent(agentID, folderID); | ||
399 | |||
400 | if (fetchedContents == null) | ||
401 | { | ||
402 | m_log.WarnFormat("[WEB FETCH INV DESC HANDLER]: Could not get contents of folder {0} for user {1}", folderID, agentID); | ||
403 | return contents; | ||
404 | } | ||
405 | contents = fetchedContents; | ||
406 | InventoryFolderBase containingFolder = new InventoryFolderBase(); | ||
407 | containingFolder.ID = folderID; | ||
408 | containingFolder.Owner = agentID; | ||
409 | containingFolder = m_InventoryService.GetFolder(containingFolder); | ||
410 | |||
411 | if (containingFolder != null) | ||
412 | { | ||
413 | //m_log.DebugFormat( | ||
414 | // "[WEB FETCH INV DESC HANDLER]: Retrieved folder {0} {1} for agent id {2}", | ||
415 | // containingFolder.Name, containingFolder.ID, agentID); | ||
416 | |||
417 | version = containingFolder.Version; | ||
418 | |||
419 | if (fetchItems) | ||
420 | { | ||
421 | List<InventoryItemBase> itemsToReturn = contents.Items; | ||
422 | List<InventoryItemBase> originalItems = new List<InventoryItemBase>(itemsToReturn); | ||
423 | |||
424 | // descendents must only include the links, not the linked items we add | ||
425 | descendents = originalItems.Count; | ||
426 | |||
427 | // Add target items for links in this folder before the links themselves. | ||
428 | foreach (InventoryItemBase item in originalItems) | ||
429 | { | ||
430 | if (item.AssetType == (int)AssetType.Link) | ||
431 | { | ||
432 | InventoryItemBase linkedItem = m_InventoryService.GetItem(new InventoryItemBase(item.AssetID)); | ||
433 | |||
434 | // Take care of genuinely broken links where the target doesn't exist | ||
435 | // HACK: Also, don't follow up links that just point to other links. In theory this is legitimate, | ||
436 | // but no viewer has been observed to set these up and this is the lazy way of avoiding cycles | ||
437 | // rather than having to keep track of every folder requested in the recursion. | ||
438 | if (linkedItem != null && linkedItem.AssetType != (int)AssetType.Link) | ||
439 | itemsToReturn.Insert(0, linkedItem); | ||
440 | } | ||
441 | } | ||
442 | |||
443 | // Now scan for folder links and insert the items they target and those links at the head of the return data | ||
444 | foreach (InventoryItemBase item in originalItems) | ||
445 | { | ||
446 | if (item.AssetType == (int)AssetType.LinkFolder) | ||
447 | { | ||
448 | InventoryCollection linkedFolderContents = m_InventoryService.GetFolderContent(ownerID, item.AssetID); | ||
449 | List<InventoryItemBase> links = linkedFolderContents.Items; | ||
450 | |||
451 | itemsToReturn.InsertRange(0, links); | ||
452 | |||
453 | foreach (InventoryItemBase link in linkedFolderContents.Items) | ||
454 | { | ||
455 | // Take care of genuinely broken links where the target doesn't exist | ||
456 | // HACK: Also, don't follow up links that just point to other links. In theory this is legitimate, | ||
457 | // but no viewer has been observed to set these up and this is the lazy way of avoiding cycles | ||
458 | // rather than having to keep track of every folder requested in the recursion. | ||
459 | if (link != null) | ||
460 | { | ||
461 | // m_log.DebugFormat( | ||
462 | // "[WEB FETCH INV DESC HANDLER]: Adding item {0} {1} from folder {2} linked from {3}", | ||
463 | // link.Name, (AssetType)link.AssetType, item.AssetID, containingFolder.Name); | ||
464 | |||
465 | InventoryItemBase linkedItem | ||
466 | = m_InventoryService.GetItem(new InventoryItemBase(link.AssetID)); | ||
467 | |||
468 | if (linkedItem != null) | ||
469 | itemsToReturn.Insert(0, linkedItem); | ||
470 | } | ||
471 | } | ||
472 | } | ||
473 | } | ||
474 | } | ||
475 | |||
476 | // foreach (InventoryItemBase item in contents.Items) | ||
477 | // { | ||
478 | // m_log.DebugFormat( | ||
479 | // "[WEB FETCH INV DESC HANDLER]: Returning item {0}, type {1}, parent {2} in {3} {4}", | ||
480 | // item.Name, (AssetType)item.AssetType, item.Folder, containingFolder.Name, containingFolder.ID); | ||
481 | // } | ||
482 | |||
483 | // ===== | ||
484 | |||
485 | // | ||
486 | // foreach (InventoryItemBase linkedItem in linkedItemsToAdd) | ||
487 | // { | ||
488 | // m_log.DebugFormat( | ||
489 | // "[WEB FETCH INV DESC HANDLER]: Inserted linked item {0} for link in folder {1} for agent {2}", | ||
490 | // linkedItem.Name, folderID, agentID); | ||
491 | // | ||
492 | // contents.Items.Add(linkedItem); | ||
493 | // } | ||
494 | // | ||
495 | // // If the folder requested contains links, then we need to send those folders first, otherwise the links | ||
496 | // // will be broken in the viewer. | ||
497 | // HashSet<UUID> linkedItemFolderIdsToSend = new HashSet<UUID>(); | ||
498 | // foreach (InventoryItemBase item in contents.Items) | ||
499 | // { | ||
500 | // if (item.AssetType == (int)AssetType.Link) | ||
501 | // { | ||
502 | // InventoryItemBase linkedItem = m_InventoryService.GetItem(new InventoryItemBase(item.AssetID)); | ||
503 | // | ||
504 | // // Take care of genuinely broken links where the target doesn't exist | ||
505 | // // HACK: Also, don't follow up links that just point to other links. In theory this is legitimate, | ||
506 | // // but no viewer has been observed to set these up and this is the lazy way of avoiding cycles | ||
507 | // // rather than having to keep track of every folder requested in the recursion. | ||
508 | // if (linkedItem != null && linkedItem.AssetType != (int)AssetType.Link) | ||
509 | // { | ||
510 | // // We don't need to send the folder if source and destination of the link are in the same | ||
511 | // // folder. | ||
512 | // if (linkedItem.Folder != containingFolder.ID) | ||
513 | // linkedItemFolderIdsToSend.Add(linkedItem.Folder); | ||
514 | // } | ||
515 | // } | ||
516 | // } | ||
517 | // | ||
518 | // foreach (UUID linkedItemFolderId in linkedItemFolderIdsToSend) | ||
519 | // { | ||
520 | // m_log.DebugFormat( | ||
521 | // "[WEB FETCH INV DESC HANDLER]: Recursively fetching folder {0} linked by item in folder {1} for agent {2}", | ||
522 | // linkedItemFolderId, folderID, agentID); | ||
523 | // | ||
524 | // int dummyVersion; | ||
525 | // InventoryCollection linkedCollection | ||
526 | // = Fetch( | ||
527 | // agentID, linkedItemFolderId, ownerID, fetchFolders, fetchItems, sortOrder, out dummyVersion); | ||
528 | // | ||
529 | // InventoryFolderBase linkedFolder = new InventoryFolderBase(linkedItemFolderId); | ||
530 | // linkedFolder.Owner = agentID; | ||
531 | // linkedFolder = m_InventoryService.GetFolder(linkedFolder); | ||
532 | // | ||
533 | //// contents.Folders.AddRange(linkedCollection.Folders); | ||
534 | // | ||
535 | // contents.Folders.Add(linkedFolder); | ||
536 | // contents.Items.AddRange(linkedCollection.Items); | ||
537 | // } | ||
538 | // } | ||
539 | } | ||
540 | } | ||
541 | else | ||
542 | { | ||
543 | // Lost items don't really need a version | ||
544 | version = 1; | ||
545 | } | ||
546 | |||
547 | return contents; | ||
548 | |||
549 | } | ||
550 | |||
551 | private void AddLibraryFolders(List<LLSDFetchInventoryDescendents> fetchFolders, List<InventoryCollectionWithDescendents> result) | ||
552 | { | ||
553 | InventoryFolderImpl fold; | ||
554 | if (m_LibraryService != null && m_LibraryService.LibraryRootFolder != null) | ||
555 | { | ||
556 | List<LLSDFetchInventoryDescendents> libfolders = fetchFolders.FindAll(f => f.owner_id == m_LibraryService.LibraryRootFolder.Owner); | ||
557 | fetchFolders.RemoveAll(f => libfolders.Contains(f)); | ||
558 | |||
559 | //m_log.DebugFormat("[XXX]: Found {0} library folders in request", libfolders.Count); | ||
560 | |||
561 | foreach (LLSDFetchInventoryDescendents f in libfolders) | ||
562 | { | ||
563 | if ((fold = m_LibraryService.LibraryRootFolder.FindFolder(f.folder_id)) != null) | ||
564 | { | ||
565 | InventoryCollectionWithDescendents ret = new InventoryCollectionWithDescendents(); | ||
566 | ret.Collection = new InventoryCollection(); | ||
567 | ret.Collection.Folders = new List<InventoryFolderBase>(); | ||
568 | ret.Collection.Items = fold.RequestListOfItems(); | ||
569 | ret.Collection.OwnerID = m_LibraryService.LibraryRootFolder.Owner; | ||
570 | ret.Collection.FolderID = f.folder_id; | ||
571 | ret.Collection.Version = fold.Version; | ||
572 | |||
573 | ret.Descendents = ret.Collection.Items.Count; | ||
574 | result.Add(ret); | ||
575 | |||
576 | //m_log.DebugFormat("[XXX]: Added libfolder {0} ({1}) {2}", ret.Collection.FolderID, ret.Collection.OwnerID); | ||
577 | } | ||
578 | } | ||
579 | } | ||
580 | } | ||
581 | |||
582 | private List<InventoryCollectionWithDescendents> Fetch(List<LLSDFetchInventoryDescendents> fetchFolders, List<UUID> bad_folders) | ||
583 | { | ||
584 | //m_log.DebugFormat( | ||
585 | // "[WEB FETCH INV DESC HANDLER]: Fetching {0} folders for owner {1}", fetchFolders.Count, fetchFolders[0].owner_id); | ||
586 | |||
587 | // FIXME MAYBE: We're not handling sortOrder! | ||
588 | |||
589 | List<InventoryCollectionWithDescendents> result = new List<InventoryCollectionWithDescendents>(); | ||
590 | |||
591 | AddLibraryFolders(fetchFolders, result); | ||
592 | |||
593 | // Filter folder Zero right here. Some viewers (Firestorm) send request for folder Zero, which doesn't make sense | ||
594 | // and can kill the sim (all root folders have parent_id Zero) | ||
595 | LLSDFetchInventoryDescendents zero = fetchFolders.Find(f => f.folder_id == UUID.Zero); | ||
596 | if (zero != null) | ||
597 | { | ||
598 | fetchFolders.Remove(zero); | ||
599 | BadFolder(zero, null, bad_folders); | ||
600 | } | ||
601 | |||
602 | if (fetchFolders.Count > 0) | ||
603 | { | ||
604 | UUID[] fids = new UUID[fetchFolders.Count]; | ||
605 | int i = 0; | ||
606 | foreach (LLSDFetchInventoryDescendents f in fetchFolders) | ||
607 | fids[i++] = f.folder_id; | ||
608 | |||
609 | //m_log.DebugFormat("[XXX]: {0}", string.Join(",", fids)); | ||
610 | |||
611 | InventoryCollection[] fetchedContents = m_InventoryService.GetMultipleFoldersContent(fetchFolders[0].owner_id, fids); | ||
612 | |||
613 | if (fetchedContents == null || (fetchedContents != null && fetchedContents.Length == 0)) | ||
614 | { | ||
615 | m_log.WarnFormat("[WEB FETCH INV DESC HANDLER]: Could not get contents of multiple folders for user {0}", fetchFolders[0].owner_id); | ||
616 | foreach (LLSDFetchInventoryDescendents freq in fetchFolders) | ||
617 | BadFolder(freq, null, bad_folders); | ||
618 | return null; | ||
619 | } | ||
620 | |||
621 | i = 0; | ||
622 | // Do some post-processing. May need to fetch more from inv server for links | ||
623 | foreach (InventoryCollection contents in fetchedContents) | ||
624 | { | ||
625 | // Find the original request | ||
626 | LLSDFetchInventoryDescendents freq = fetchFolders[i++]; | ||
627 | |||
628 | InventoryCollectionWithDescendents coll = new InventoryCollectionWithDescendents(); | ||
629 | coll.Collection = contents; | ||
630 | |||
631 | if (BadFolder(freq, contents, bad_folders)) | ||
632 | continue; | ||
633 | |||
634 | // Next: link management | ||
635 | ProcessLinks(freq, coll); | ||
636 | |||
637 | result.Add(coll); | ||
638 | } | ||
639 | } | ||
640 | |||
641 | return result; | ||
642 | } | ||
643 | |||
644 | private bool BadFolder(LLSDFetchInventoryDescendents freq, InventoryCollection contents, List<UUID> bad_folders) | ||
645 | { | ||
646 | bool bad = false; | ||
647 | if (contents == null) | ||
648 | { | ||
649 | bad_folders.Add(freq.folder_id); | ||
650 | bad = true; | ||
651 | } | ||
652 | |||
653 | // The inventory server isn't sending FolderID in the collection... | ||
654 | // Must fetch it individually | ||
655 | else if (contents.FolderID == UUID.Zero) | ||
656 | { | ||
657 | InventoryFolderBase containingFolder = new InventoryFolderBase(); | ||
658 | containingFolder.ID = freq.folder_id; | ||
659 | containingFolder.Owner = freq.owner_id; | ||
660 | containingFolder = m_InventoryService.GetFolder(containingFolder); | ||
661 | |||
662 | if (containingFolder != null) | ||
663 | { | ||
664 | contents.FolderID = containingFolder.ID; | ||
665 | contents.OwnerID = containingFolder.Owner; | ||
666 | contents.Version = containingFolder.Version; | ||
667 | } | ||
668 | else | ||
669 | { | ||
670 | // Was it really a request for folder Zero? | ||
671 | // This is an overkill, but Firestorm really asks for folder Zero. | ||
672 | // I'm leaving the code here for the time being, but commented. | ||
673 | if (freq.folder_id == UUID.Zero) | ||
674 | { | ||
675 | //coll.Collection.OwnerID = freq.owner_id; | ||
676 | //coll.Collection.FolderID = contents.FolderID; | ||
677 | //containingFolder = m_InventoryService.GetRootFolder(freq.owner_id); | ||
678 | //if (containingFolder != null) | ||
679 | //{ | ||
680 | // m_log.WarnFormat("[WEB FETCH INV DESC HANDLER]: Request for parent of folder {0}", containingFolder.ID); | ||
681 | // coll.Collection.Folders.Clear(); | ||
682 | // coll.Collection.Folders.Add(containingFolder); | ||
683 | // if (m_LibraryService != null && m_LibraryService.LibraryRootFolder != null) | ||
684 | // { | ||
685 | // InventoryFolderBase lib = new InventoryFolderBase(m_LibraryService.LibraryRootFolder.ID, m_LibraryService.LibraryRootFolder.Owner); | ||
686 | // lib.Name = m_LibraryService.LibraryRootFolder.Name; | ||
687 | // lib.Type = m_LibraryService.LibraryRootFolder.Type; | ||
688 | // lib.Version = m_LibraryService.LibraryRootFolder.Version; | ||
689 | // coll.Collection.Folders.Add(lib); | ||
690 | // } | ||
691 | // coll.Collection.Items.Clear(); | ||
692 | //} | ||
693 | } | ||
694 | else | ||
695 | { | ||
696 | m_log.WarnFormat("[WEB FETCH INV DESC HANDLER]: Unable to fetch folder {0}", freq.folder_id); | ||
697 | bad_folders.Add(freq.folder_id); | ||
698 | } | ||
699 | bad = true; | ||
700 | } | ||
701 | } | ||
702 | |||
703 | return bad; | ||
704 | } | ||
705 | |||
706 | private void ProcessLinks(LLSDFetchInventoryDescendents freq, InventoryCollectionWithDescendents coll) | ||
707 | { | ||
708 | InventoryCollection contents = coll.Collection; | ||
709 | |||
710 | if (freq.fetch_items && contents.Items != null) | ||
711 | { | ||
712 | List<InventoryItemBase> itemsToReturn = contents.Items; | ||
713 | |||
714 | // descendents must only include the links, not the linked items we add | ||
715 | coll.Descendents = itemsToReturn.Count; | ||
716 | |||
717 | // Add target items for links in this folder before the links themselves. | ||
718 | List<UUID> itemIDs = new List<UUID>(); | ||
719 | List<UUID> folderIDs = new List<UUID>(); | ||
720 | foreach (InventoryItemBase item in itemsToReturn) | ||
721 | { | ||
722 | //m_log.DebugFormat("[XXX]: {0} {1}", item.Name, item.AssetType); | ||
723 | if (item.AssetType == (int)AssetType.Link) | ||
724 | itemIDs.Add(item.AssetID); | ||
725 | |||
726 | else if (item.AssetType == (int)AssetType.LinkFolder) | ||
727 | folderIDs.Add(item.AssetID); | ||
728 | } | ||
729 | |||
730 | //m_log.DebugFormat("[XXX]: folder {0} has {1} links and {2} linkfolders", contents.FolderID, itemIDs.Count, folderIDs.Count); | ||
731 | |||
732 | // Scan for folder links and insert the items they target and those links at the head of the return data | ||
733 | if (folderIDs.Count > 0) | ||
734 | { | ||
735 | InventoryCollection[] linkedFolders = m_InventoryService.GetMultipleFoldersContent(coll.Collection.OwnerID, folderIDs.ToArray()); | ||
736 | foreach (InventoryCollection linkedFolderContents in linkedFolders) | ||
737 | { | ||
738 | if (linkedFolderContents == null) | ||
739 | continue; | ||
740 | |||
741 | List<InventoryItemBase> links = linkedFolderContents.Items; | ||
742 | |||
743 | itemsToReturn.InsertRange(0, links); | ||
744 | |||
745 | } | ||
746 | } | ||
747 | |||
748 | if (itemIDs.Count > 0) | ||
749 | { | ||
750 | InventoryItemBase[] linked = m_InventoryService.GetMultipleItems(freq.owner_id, itemIDs.ToArray()); | ||
751 | if (linked == null) | ||
752 | { | ||
753 | // OMG!!! One by one!!! This is fallback code, in case the backend isn't updated | ||
754 | m_log.WarnFormat("[WEB FETCH INV DESC HANDLER]: GetMultipleItems failed. Falling back to fetching inventory items one by one."); | ||
755 | linked = new InventoryItemBase[itemIDs.Count]; | ||
756 | int i = 0; | ||
757 | InventoryItemBase item = new InventoryItemBase(); | ||
758 | item.Owner = freq.owner_id; | ||
759 | foreach (UUID id in itemIDs) | ||
760 | { | ||
761 | item.ID = id; | ||
762 | linked[i++] = m_InventoryService.GetItem(item); | ||
763 | } | ||
764 | } | ||
765 | |||
766 | //m_log.DebugFormat("[WEB FETCH INV DESC HANDLER]: Processing folder {0}. Existing items:", freq.folder_id); | ||
767 | //foreach (InventoryItemBase item in itemsToReturn) | ||
768 | // m_log.DebugFormat("[XXX]: {0} {1} {2}", item.Name, item.AssetType, item.Folder); | ||
769 | |||
770 | if (linked != null) | ||
771 | { | ||
772 | foreach (InventoryItemBase linkedItem in linked) | ||
773 | { | ||
774 | // Take care of genuinely broken links where the target doesn't exist | ||
775 | // HACK: Also, don't follow up links that just point to other links. In theory this is legitimate, | ||
776 | // but no viewer has been observed to set these up and this is the lazy way of avoiding cycles | ||
777 | // rather than having to keep track of every folder requested in the recursion. | ||
778 | if (linkedItem != null && linkedItem.AssetType != (int)AssetType.Link) | ||
779 | { | ||
780 | itemsToReturn.Insert(0, linkedItem); | ||
781 | //m_log.DebugFormat("[WEB FETCH INV DESC HANDLER]: Added {0} {1} {2}", linkedItem.Name, linkedItem.AssetType, linkedItem.Folder); | ||
782 | } | ||
783 | } | ||
784 | } | ||
785 | } | ||
786 | } | ||
787 | |||
788 | } | ||
789 | |||
790 | /// <summary> | ||
791 | /// Convert an internal inventory folder object into an LLSD object. | ||
792 | /// </summary> | ||
793 | /// <param name="invFolder"></param> | ||
794 | /// <returns></returns> | ||
795 | private LLSDInventoryFolder ConvertInventoryFolder(InventoryFolderBase invFolder) | ||
796 | { | ||
797 | LLSDInventoryFolder llsdFolder = new LLSDInventoryFolder(); | ||
798 | llsdFolder.folder_id = invFolder.ID; | ||
799 | llsdFolder.parent_id = invFolder.ParentID; | ||
800 | llsdFolder.name = invFolder.Name; | ||
801 | llsdFolder.type = invFolder.Type; | ||
802 | llsdFolder.preferred_type = -1; | ||
803 | |||
804 | return llsdFolder; | ||
805 | } | ||
806 | |||
807 | /// <summary> | ||
808 | /// Convert an internal inventory item object into an LLSD object. | ||
809 | /// </summary> | ||
810 | /// <param name="invItem"></param> | ||
811 | /// <returns></returns> | ||
812 | private LLSDInventoryItem ConvertInventoryItem(InventoryItemBase invItem) | ||
813 | { | ||
814 | LLSDInventoryItem llsdItem = new LLSDInventoryItem(); | ||
815 | llsdItem.asset_id = invItem.AssetID; | ||
816 | llsdItem.created_at = invItem.CreationDate; | ||
817 | llsdItem.desc = invItem.Description; | ||
818 | llsdItem.flags = (int)invItem.Flags; | ||
819 | llsdItem.item_id = invItem.ID; | ||
820 | llsdItem.name = invItem.Name; | ||
821 | llsdItem.parent_id = invItem.Folder; | ||
822 | llsdItem.type = invItem.AssetType; | ||
823 | llsdItem.inv_type = invItem.InvType; | ||
824 | |||
825 | llsdItem.permissions = new LLSDPermissions(); | ||
826 | llsdItem.permissions.creator_id = invItem.CreatorIdAsUuid; | ||
827 | llsdItem.permissions.base_mask = (int)invItem.CurrentPermissions; | ||
828 | llsdItem.permissions.everyone_mask = (int)invItem.EveryOnePermissions; | ||
829 | llsdItem.permissions.group_id = invItem.GroupID; | ||
830 | llsdItem.permissions.group_mask = (int)invItem.GroupPermissions; | ||
831 | llsdItem.permissions.is_owner_group = invItem.GroupOwned; | ||
832 | llsdItem.permissions.next_owner_mask = (int)invItem.NextPermissions; | ||
833 | llsdItem.permissions.owner_id = invItem.Owner; | ||
834 | llsdItem.permissions.owner_mask = (int)invItem.CurrentPermissions; | ||
835 | llsdItem.sale_info = new LLSDSaleInfo(); | ||
836 | llsdItem.sale_info.sale_price = invItem.SalePrice; | ||
837 | llsdItem.sale_info.sale_type = invItem.SaleType; | ||
838 | |||
839 | return llsdItem; | ||
840 | } | ||
841 | } | ||
842 | |||
843 | class InventoryCollectionWithDescendents | ||
844 | { | ||
845 | public InventoryCollection Collection; | ||
846 | public int Descendents; | ||
847 | } | ||
848 | } \ No newline at end of file | ||
diff --git a/OpenSim/Capabilities/Handlers/FetchInventory/FetchInvDescServerConnector.cs b/OpenSim/Capabilities/Handlers/FetchInventory/FetchInvDescServerConnector.cs new file mode 100644 index 0000000..9dcfaa4 --- /dev/null +++ b/OpenSim/Capabilities/Handlers/FetchInventory/FetchInvDescServerConnector.cs | |||
@@ -0,0 +1,82 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using Nini.Config; | ||
30 | using OpenSim.Server.Base; | ||
31 | using OpenSim.Services.Interfaces; | ||
32 | using OpenSim.Framework.Servers.HttpServer; | ||
33 | using OpenSim.Server.Handlers.Base; | ||
34 | using OpenMetaverse; | ||
35 | |||
36 | namespace OpenSim.Capabilities.Handlers | ||
37 | { | ||
38 | public class FetchInvDescServerConnector : ServiceConnector | ||
39 | { | ||
40 | private IInventoryService m_InventoryService; | ||
41 | private ILibraryService m_LibraryService; | ||
42 | private string m_ConfigName = "CapsService"; | ||
43 | |||
44 | public FetchInvDescServerConnector(IConfigSource config, IHttpServer server, string configName) : | ||
45 | base(config, server, configName) | ||
46 | { | ||
47 | if (configName != String.Empty) | ||
48 | m_ConfigName = configName; | ||
49 | |||
50 | IConfig serverConfig = config.Configs[m_ConfigName]; | ||
51 | if (serverConfig == null) | ||
52 | throw new Exception(String.Format("No section '{0}' in config file", m_ConfigName)); | ||
53 | |||
54 | string invService = serverConfig.GetString("InventoryService", String.Empty); | ||
55 | |||
56 | if (invService == String.Empty) | ||
57 | throw new Exception("No InventoryService in config file"); | ||
58 | |||
59 | Object[] args = new Object[] { config }; | ||
60 | m_InventoryService = | ||
61 | ServerUtils.LoadPlugin<IInventoryService>(invService, args); | ||
62 | |||
63 | if (m_InventoryService == null) | ||
64 | throw new Exception(String.Format("Failed to load InventoryService from {0}; config is {1}", invService, m_ConfigName)); | ||
65 | |||
66 | string libService = serverConfig.GetString("LibraryService", String.Empty); | ||
67 | m_LibraryService = | ||
68 | ServerUtils.LoadPlugin<ILibraryService>(libService, args); | ||
69 | |||
70 | FetchInvDescHandler webFetchHandler = new FetchInvDescHandler(m_InventoryService, m_LibraryService, null); | ||
71 | IRequestHandler reqHandler | ||
72 | = new RestStreamHandler( | ||
73 | "POST", | ||
74 | "/CAPS/WebFetchInvDesc/" /*+ UUID.Random()*/, | ||
75 | webFetchHandler.FetchInventoryDescendentsRequest, | ||
76 | "FetchInvDescendents", | ||
77 | null); | ||
78 | server.AddStreamHandler(reqHandler); | ||
79 | } | ||
80 | |||
81 | } | ||
82 | } | ||
diff --git a/OpenSim/Capabilities/Handlers/FetchInventory/FetchInventory2Handler.cs b/OpenSim/Capabilities/Handlers/FetchInventory/FetchInventory2Handler.cs new file mode 100644 index 0000000..c904392 --- /dev/null +++ b/OpenSim/Capabilities/Handlers/FetchInventory/FetchInventory2Handler.cs | |||
@@ -0,0 +1,141 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.Reflection; | ||
29 | using OpenMetaverse; | ||
30 | using OpenMetaverse.StructuredData; | ||
31 | using OpenSim.Framework; | ||
32 | using OpenSim.Framework.Capabilities; | ||
33 | using OpenSim.Framework.Servers.HttpServer; | ||
34 | using OpenSim.Services.Interfaces; | ||
35 | using OSDArray = OpenMetaverse.StructuredData.OSDArray; | ||
36 | using OSDMap = OpenMetaverse.StructuredData.OSDMap; | ||
37 | |||
38 | using log4net; | ||
39 | |||
40 | namespace OpenSim.Capabilities.Handlers | ||
41 | { | ||
42 | public class FetchInventory2Handler | ||
43 | { | ||
44 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
45 | |||
46 | private IInventoryService m_inventoryService; | ||
47 | private UUID m_agentID; | ||
48 | |||
49 | public FetchInventory2Handler(IInventoryService invService, UUID agentId) | ||
50 | { | ||
51 | m_inventoryService = invService; | ||
52 | m_agentID = agentId; | ||
53 | } | ||
54 | |||
55 | public string FetchInventoryRequest(string request, string path, string param, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
56 | { | ||
57 | //m_log.DebugFormat("[FETCH INVENTORY HANDLER]: Received FetchInventory capability request {0}", request); | ||
58 | |||
59 | OSDMap requestmap = (OSDMap)OSDParser.DeserializeLLSDXml(Utils.StringToBytes(request)); | ||
60 | OSDArray itemsRequested = (OSDArray)requestmap["items"]; | ||
61 | |||
62 | string reply; | ||
63 | LLSDFetchInventory llsdReply = new LLSDFetchInventory(); | ||
64 | |||
65 | UUID[] itemIDs = new UUID[itemsRequested.Count]; | ||
66 | int i = 0; | ||
67 | foreach (OSDMap osdItemId in itemsRequested) | ||
68 | { | ||
69 | itemIDs[i++] = osdItemId["item_id"].AsUUID(); | ||
70 | } | ||
71 | |||
72 | InventoryItemBase[] items = m_inventoryService.GetMultipleItems(m_agentID, itemIDs); | ||
73 | |||
74 | if (items == null) | ||
75 | { | ||
76 | // OMG!!! One by one!!! This is fallback code, in case the backend isn't updated | ||
77 | m_log.WarnFormat("[FETCH INVENTORY HANDLER]: GetMultipleItems failed. Falling back to fetching inventory items one by one."); | ||
78 | items = new InventoryItemBase[itemsRequested.Count]; | ||
79 | i = 0; | ||
80 | InventoryItemBase item = new InventoryItemBase(); | ||
81 | item.Owner = m_agentID; | ||
82 | foreach (UUID id in itemIDs) | ||
83 | { | ||
84 | item.ID = id; | ||
85 | items[i++] = m_inventoryService.GetItem(item); | ||
86 | } | ||
87 | } | ||
88 | |||
89 | foreach (InventoryItemBase item in items) | ||
90 | { | ||
91 | if (item != null) | ||
92 | { | ||
93 | // We don't know the agent that this request belongs to so we'll use the agent id of the item | ||
94 | // which will be the same for all items. | ||
95 | llsdReply.agent_id = item.Owner; | ||
96 | |||
97 | llsdReply.items.Array.Add(ConvertInventoryItem(item)); | ||
98 | } | ||
99 | } | ||
100 | |||
101 | reply = LLSDHelpers.SerialiseLLSDReply(llsdReply); | ||
102 | |||
103 | return reply; | ||
104 | } | ||
105 | |||
106 | /// <summary> | ||
107 | /// Convert an internal inventory item object into an LLSD object. | ||
108 | /// </summary> | ||
109 | /// <param name="invItem"></param> | ||
110 | /// <returns></returns> | ||
111 | private LLSDInventoryItem ConvertInventoryItem(InventoryItemBase invItem) | ||
112 | { | ||
113 | LLSDInventoryItem llsdItem = new LLSDInventoryItem(); | ||
114 | llsdItem.asset_id = invItem.AssetID; | ||
115 | llsdItem.created_at = invItem.CreationDate; | ||
116 | llsdItem.desc = invItem.Description; | ||
117 | llsdItem.flags = (int)invItem.Flags; | ||
118 | llsdItem.item_id = invItem.ID; | ||
119 | llsdItem.name = invItem.Name; | ||
120 | llsdItem.parent_id = invItem.Folder; | ||
121 | llsdItem.type = invItem.AssetType; | ||
122 | llsdItem.inv_type = invItem.InvType; | ||
123 | |||
124 | llsdItem.permissions = new LLSDPermissions(); | ||
125 | llsdItem.permissions.creator_id = invItem.CreatorIdAsUuid; | ||
126 | llsdItem.permissions.base_mask = (int)invItem.CurrentPermissions; | ||
127 | llsdItem.permissions.everyone_mask = (int)invItem.EveryOnePermissions; | ||
128 | llsdItem.permissions.group_id = invItem.GroupID; | ||
129 | llsdItem.permissions.group_mask = (int)invItem.GroupPermissions; | ||
130 | llsdItem.permissions.is_owner_group = invItem.GroupOwned; | ||
131 | llsdItem.permissions.next_owner_mask = (int)invItem.NextPermissions; | ||
132 | llsdItem.permissions.owner_id = invItem.Owner; | ||
133 | llsdItem.permissions.owner_mask = (int)invItem.CurrentPermissions; | ||
134 | llsdItem.sale_info = new LLSDSaleInfo(); | ||
135 | llsdItem.sale_info.sale_price = invItem.SalePrice; | ||
136 | llsdItem.sale_info.sale_type = invItem.SaleType; | ||
137 | |||
138 | return llsdItem; | ||
139 | } | ||
140 | } | ||
141 | } \ No newline at end of file | ||
diff --git a/OpenSim/Capabilities/Handlers/FetchInventory/Tests/FetchInventory2HandlerTests.cs b/OpenSim/Capabilities/Handlers/FetchInventory/Tests/FetchInventory2HandlerTests.cs new file mode 100644 index 0000000..8af3c64 --- /dev/null +++ b/OpenSim/Capabilities/Handlers/FetchInventory/Tests/FetchInventory2HandlerTests.cs | |||
@@ -0,0 +1,170 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Linq; | ||
31 | using System.Net; | ||
32 | using System.Text.RegularExpressions; | ||
33 | using log4net; | ||
34 | using log4net.Config; | ||
35 | using NUnit.Framework; | ||
36 | using OpenMetaverse; | ||
37 | using OpenSim.Capabilities.Handlers; | ||
38 | using OpenSim.Framework; | ||
39 | using OpenSim.Framework.Servers.HttpServer; | ||
40 | using OpenSim.Region.Framework.Scenes; | ||
41 | using OpenSim.Services.Interfaces; | ||
42 | using OpenSim.Tests.Common; | ||
43 | |||
44 | namespace OpenSim.Capabilities.Handlers.FetchInventory.Tests | ||
45 | { | ||
46 | [TestFixture] | ||
47 | public class FetchInventory2HandlerTests : OpenSimTestCase | ||
48 | { | ||
49 | private UUID m_userID = UUID.Random(); | ||
50 | private Scene m_scene; | ||
51 | private UUID m_rootFolderID; | ||
52 | private UUID m_notecardsFolder; | ||
53 | private UUID m_objectsFolder; | ||
54 | |||
55 | private void Init() | ||
56 | { | ||
57 | // Create an inventory that looks like this: | ||
58 | // | ||
59 | // /My Inventory | ||
60 | // <other system folders> | ||
61 | // /Objects | ||
62 | // Object 1 | ||
63 | // Object 2 | ||
64 | // Object 3 | ||
65 | // /Notecards | ||
66 | // Notecard 1 | ||
67 | // Notecard 2 | ||
68 | // Notecard 3 | ||
69 | // Notecard 4 | ||
70 | // Notecard 5 | ||
71 | |||
72 | m_scene = new SceneHelpers().SetupScene(); | ||
73 | |||
74 | m_scene.InventoryService.CreateUserInventory(m_userID); | ||
75 | |||
76 | m_rootFolderID = m_scene.InventoryService.GetRootFolder(m_userID).ID; | ||
77 | |||
78 | InventoryFolderBase of = m_scene.InventoryService.GetFolderForType(m_userID, FolderType.Object); | ||
79 | m_objectsFolder = of.ID; | ||
80 | |||
81 | // Add 3 objects | ||
82 | InventoryItemBase item; | ||
83 | for (int i = 1; i <= 3; i++) | ||
84 | { | ||
85 | item = new InventoryItemBase(new UUID("b0000000-0000-0000-0000-0000000000b" + i), m_userID); | ||
86 | item.AssetID = UUID.Random(); | ||
87 | item.AssetType = (int)AssetType.Object; | ||
88 | item.Folder = m_objectsFolder; | ||
89 | item.Name = "Object " + i; | ||
90 | m_scene.InventoryService.AddItem(item); | ||
91 | } | ||
92 | |||
93 | InventoryFolderBase ncf = m_scene.InventoryService.GetFolderForType(m_userID, FolderType.Notecard); | ||
94 | m_notecardsFolder = ncf.ID; | ||
95 | |||
96 | // Add 5 notecards | ||
97 | for (int i = 1; i <= 5; i++) | ||
98 | { | ||
99 | item = new InventoryItemBase(new UUID("10000000-0000-0000-0000-00000000000" + i), m_userID); | ||
100 | item.AssetID = UUID.Random(); | ||
101 | item.AssetType = (int)AssetType.Notecard; | ||
102 | item.Folder = m_notecardsFolder; | ||
103 | item.Name = "Notecard " + i; | ||
104 | m_scene.InventoryService.AddItem(item); | ||
105 | } | ||
106 | |||
107 | } | ||
108 | |||
109 | [Test] | ||
110 | public void Test_001_RequestOne() | ||
111 | { | ||
112 | TestHelpers.InMethod(); | ||
113 | |||
114 | Init(); | ||
115 | |||
116 | FetchInventory2Handler handler = new FetchInventory2Handler(m_scene.InventoryService, m_userID); | ||
117 | TestOSHttpRequest req = new TestOSHttpRequest(); | ||
118 | TestOSHttpResponse resp = new TestOSHttpResponse(); | ||
119 | |||
120 | string request = "<llsd><map><key>items</key><array><map><key>item_id</key><uuid>"; | ||
121 | request += "10000000-0000-0000-0000-000000000001"; // Notecard 1 | ||
122 | request += "</uuid></map></array></map></llsd>"; | ||
123 | |||
124 | string llsdresponse = handler.FetchInventoryRequest(request, "/FETCH", string.Empty, req, resp); | ||
125 | |||
126 | Assert.That(llsdresponse != null, Is.True, "Incorrect null response"); | ||
127 | Assert.That(llsdresponse != string.Empty, Is.True, "Incorrect empty response"); | ||
128 | Assert.That(llsdresponse.Contains(m_userID.ToString()), Is.True, "Response should contain userID"); | ||
129 | |||
130 | Assert.That(llsdresponse.Contains("10000000-0000-0000-0000-000000000001"), Is.True, "Response does not contain item uuid"); | ||
131 | Assert.That(llsdresponse.Contains("Notecard 1"), Is.True, "Response does not contain item Name"); | ||
132 | Console.WriteLine(llsdresponse); | ||
133 | } | ||
134 | |||
135 | [Test] | ||
136 | public void Test_002_RequestMany() | ||
137 | { | ||
138 | TestHelpers.InMethod(); | ||
139 | |||
140 | Init(); | ||
141 | |||
142 | FetchInventory2Handler handler = new FetchInventory2Handler(m_scene.InventoryService, m_userID); | ||
143 | TestOSHttpRequest req = new TestOSHttpRequest(); | ||
144 | TestOSHttpResponse resp = new TestOSHttpResponse(); | ||
145 | |||
146 | string request = "<llsd><map><key>items</key><array>"; | ||
147 | request += "<map><key>item_id</key><uuid>10000000-0000-0000-0000-000000000001</uuid></map>"; // Notecard 1 | ||
148 | request += "<map><key>item_id</key><uuid>10000000-0000-0000-0000-000000000002</uuid></map>"; // Notecard 2 | ||
149 | request += "<map><key>item_id</key><uuid>10000000-0000-0000-0000-000000000003</uuid></map>"; // Notecard 3 | ||
150 | request += "<map><key>item_id</key><uuid>10000000-0000-0000-0000-000000000004</uuid></map>"; // Notecard 4 | ||
151 | request += "<map><key>item_id</key><uuid>10000000-0000-0000-0000-000000000005</uuid></map>"; // Notecard 5 | ||
152 | request += "</array></map></llsd>"; | ||
153 | |||
154 | string llsdresponse = handler.FetchInventoryRequest(request, "/FETCH", string.Empty, req, resp); | ||
155 | |||
156 | Assert.That(llsdresponse != null, Is.True, "Incorrect null response"); | ||
157 | Assert.That(llsdresponse != string.Empty, Is.True, "Incorrect empty response"); | ||
158 | Assert.That(llsdresponse.Contains(m_userID.ToString()), Is.True, "Response should contain userID"); | ||
159 | |||
160 | Console.WriteLine(llsdresponse); | ||
161 | Assert.That(llsdresponse.Contains("10000000-0000-0000-0000-000000000001"), Is.True, "Response does not contain notecard 1"); | ||
162 | Assert.That(llsdresponse.Contains("10000000-0000-0000-0000-000000000002"), Is.True, "Response does not contain notecard 2"); | ||
163 | Assert.That(llsdresponse.Contains("10000000-0000-0000-0000-000000000003"), Is.True, "Response does not contain notecard 3"); | ||
164 | Assert.That(llsdresponse.Contains("10000000-0000-0000-0000-000000000004"), Is.True, "Response does not contain notecard 4"); | ||
165 | Assert.That(llsdresponse.Contains("10000000-0000-0000-0000-000000000005"), Is.True, "Response does not contain notecard 5"); | ||
166 | } | ||
167 | |||
168 | } | ||
169 | |||
170 | } \ No newline at end of file | ||
diff --git a/OpenSim/Capabilities/Handlers/FetchInventory/Tests/FetchInventoryDescendents2HandlerTests.cs b/OpenSim/Capabilities/Handlers/FetchInventory/Tests/FetchInventoryDescendents2HandlerTests.cs new file mode 100644 index 0000000..2d5531a --- /dev/null +++ b/OpenSim/Capabilities/Handlers/FetchInventory/Tests/FetchInventoryDescendents2HandlerTests.cs | |||
@@ -0,0 +1,292 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Linq; | ||
31 | using System.Net; | ||
32 | using System.Text.RegularExpressions; | ||
33 | using log4net; | ||
34 | using log4net.Config; | ||
35 | using NUnit.Framework; | ||
36 | using OpenMetaverse; | ||
37 | using OpenSim.Capabilities.Handlers; | ||
38 | using OpenSim.Framework; | ||
39 | using OpenSim.Framework.Servers.HttpServer; | ||
40 | using OpenSim.Region.Framework.Scenes; | ||
41 | using OpenSim.Services.Interfaces; | ||
42 | using OpenSim.Tests.Common; | ||
43 | |||
44 | namespace OpenSim.Capabilities.Handlers.FetchInventory.Tests | ||
45 | { | ||
46 | [TestFixture] | ||
47 | public class FetchInventoryDescendents2HandlerTests : OpenSimTestCase | ||
48 | { | ||
49 | private UUID m_userID = UUID.Zero; | ||
50 | private Scene m_scene; | ||
51 | private UUID m_rootFolderID; | ||
52 | private int m_rootDescendents; | ||
53 | private UUID m_notecardsFolder; | ||
54 | private UUID m_objectsFolder; | ||
55 | |||
56 | private void Init() | ||
57 | { | ||
58 | // Create an inventory that looks like this: | ||
59 | // | ||
60 | // /My Inventory | ||
61 | // <other system folders> | ||
62 | // /Objects | ||
63 | // Some Object | ||
64 | // /Notecards | ||
65 | // Notecard 1 | ||
66 | // Notecard 2 | ||
67 | // /Test Folder | ||
68 | // Link to notecard -> /Notecards/Notecard 2 | ||
69 | // Link to Objects folder -> /Objects | ||
70 | |||
71 | m_scene = new SceneHelpers().SetupScene(); | ||
72 | |||
73 | m_scene.InventoryService.CreateUserInventory(m_userID); | ||
74 | |||
75 | m_rootFolderID = m_scene.InventoryService.GetRootFolder(m_userID).ID; | ||
76 | |||
77 | InventoryFolderBase of = m_scene.InventoryService.GetFolderForType(m_userID, FolderType.Object); | ||
78 | m_objectsFolder = of.ID; | ||
79 | |||
80 | // Add an object | ||
81 | InventoryItemBase item = new InventoryItemBase(new UUID("b0000000-0000-0000-0000-00000000000b"), m_userID); | ||
82 | item.AssetID = UUID.Random(); | ||
83 | item.AssetType = (int)AssetType.Object; | ||
84 | item.Folder = m_objectsFolder; | ||
85 | item.Name = "Some Object"; | ||
86 | m_scene.InventoryService.AddItem(item); | ||
87 | |||
88 | InventoryFolderBase ncf = m_scene.InventoryService.GetFolderForType(m_userID, FolderType.Notecard); | ||
89 | m_notecardsFolder = ncf.ID; | ||
90 | |||
91 | // Add a notecard | ||
92 | item = new InventoryItemBase(new UUID("10000000-0000-0000-0000-000000000001"), m_userID); | ||
93 | item.AssetID = UUID.Random(); | ||
94 | item.AssetType = (int)AssetType.Notecard; | ||
95 | item.Folder = m_notecardsFolder; | ||
96 | item.Name = "Test Notecard 1"; | ||
97 | m_scene.InventoryService.AddItem(item); | ||
98 | // Add another notecard | ||
99 | item.ID = new UUID("20000000-0000-0000-0000-000000000002"); | ||
100 | item.AssetID = new UUID("a0000000-0000-0000-0000-00000000000a"); | ||
101 | item.Name = "Test Notecard 2"; | ||
102 | m_scene.InventoryService.AddItem(item); | ||
103 | |||
104 | // Add a folder | ||
105 | InventoryFolderBase folder = new InventoryFolderBase(new UUID("f0000000-0000-0000-0000-00000000000f"), "Test Folder", m_userID, m_rootFolderID); | ||
106 | m_scene.InventoryService.AddFolder(folder); | ||
107 | |||
108 | // Add a link to notecard 2 in Test Folder | ||
109 | item.AssetID = item.ID; // use item ID of notecard 2 | ||
110 | item.ID = new UUID("40000000-0000-0000-0000-000000000004"); | ||
111 | item.AssetType = (int)AssetType.Link; | ||
112 | item.Folder = folder.ID; | ||
113 | item.Name = "Link to notecard"; | ||
114 | m_scene.InventoryService.AddItem(item); | ||
115 | |||
116 | // Add a link to the Objects folder in Test Folder | ||
117 | item.AssetID = m_scene.InventoryService.GetFolderForType(m_userID, FolderType.Object).ID; // use item ID of Objects folder | ||
118 | item.ID = new UUID("50000000-0000-0000-0000-000000000005"); | ||
119 | item.AssetType = (int)AssetType.LinkFolder; | ||
120 | item.Folder = folder.ID; | ||
121 | item.Name = "Link to Objects folder"; | ||
122 | m_scene.InventoryService.AddItem(item); | ||
123 | |||
124 | InventoryCollection coll = m_scene.InventoryService.GetFolderContent(m_userID, m_rootFolderID); | ||
125 | m_rootDescendents = coll.Items.Count + coll.Folders.Count; | ||
126 | Console.WriteLine("Number of descendents: " + m_rootDescendents); | ||
127 | } | ||
128 | |||
129 | [Test] | ||
130 | public void Test_001_SimpleFolder() | ||
131 | { | ||
132 | TestHelpers.InMethod(); | ||
133 | |||
134 | Init(); | ||
135 | |||
136 | FetchInvDescHandler handler = new FetchInvDescHandler(m_scene.InventoryService, null, m_scene); | ||
137 | TestOSHttpRequest req = new TestOSHttpRequest(); | ||
138 | TestOSHttpResponse resp = new TestOSHttpResponse(); | ||
139 | |||
140 | string request = "<llsd><map><key>folders</key><array><map><key>fetch_folders</key><integer>1</integer><key>fetch_items</key><boolean>1</boolean><key>folder_id</key><uuid>"; | ||
141 | request += m_rootFolderID; | ||
142 | request += "</uuid><key>owner_id</key><uuid>00000000-0000-0000-0000-000000000000</uuid><key>sort_order</key><integer>1</integer></map></array></map></llsd>"; | ||
143 | |||
144 | string llsdresponse = handler.FetchInventoryDescendentsRequest(request, "/FETCH", string.Empty, req, resp); | ||
145 | |||
146 | Assert.That(llsdresponse != null, Is.True, "Incorrect null response"); | ||
147 | Assert.That(llsdresponse != string.Empty, Is.True, "Incorrect empty response"); | ||
148 | Assert.That(llsdresponse.Contains("00000000-0000-0000-0000-000000000000"), Is.True, "Response should contain userID"); | ||
149 | |||
150 | string descendents = "descendents</key><integer>" + m_rootDescendents + "</integer>"; | ||
151 | Assert.That(llsdresponse.Contains(descendents), Is.True, "Incorrect number of descendents"); | ||
152 | Console.WriteLine(llsdresponse); | ||
153 | } | ||
154 | |||
155 | [Test] | ||
156 | public void Test_002_MultipleFolders() | ||
157 | { | ||
158 | TestHelpers.InMethod(); | ||
159 | |||
160 | FetchInvDescHandler handler = new FetchInvDescHandler(m_scene.InventoryService, null, m_scene); | ||
161 | TestOSHttpRequest req = new TestOSHttpRequest(); | ||
162 | TestOSHttpResponse resp = new TestOSHttpResponse(); | ||
163 | |||
164 | string request = "<llsd><map><key>folders</key><array>"; | ||
165 | request += "<map><key>fetch_folders</key><integer>1</integer><key>fetch_items</key><boolean>1</boolean><key>folder_id</key><uuid>"; | ||
166 | request += m_rootFolderID; | ||
167 | request += "</uuid><key>owner_id</key><uuid>00000000-0000-0000-0000-000000000000</uuid><key>sort_order</key><integer>1</integer></map>"; | ||
168 | request += "<map><key>fetch_folders</key><integer>1</integer><key>fetch_items</key><boolean>1</boolean><key>folder_id</key><uuid>"; | ||
169 | request += m_notecardsFolder; | ||
170 | request += "</uuid><key>owner_id</key><uuid>00000000-0000-0000-0000-000000000000</uuid><key>sort_order</key><integer>1</integer></map>"; | ||
171 | request += "</array></map></llsd>"; | ||
172 | |||
173 | string llsdresponse = handler.FetchInventoryDescendentsRequest(request, "/FETCH", string.Empty, req, resp); | ||
174 | Console.WriteLine(llsdresponse); | ||
175 | |||
176 | string descendents = "descendents</key><integer>" + m_rootDescendents + "</integer>"; | ||
177 | Assert.That(llsdresponse.Contains(descendents), Is.True, "Incorrect number of descendents for root folder"); | ||
178 | descendents = "descendents</key><integer>2</integer>"; | ||
179 | Assert.That(llsdresponse.Contains(descendents), Is.True, "Incorrect number of descendents for Notecard folder"); | ||
180 | |||
181 | Assert.That(llsdresponse.Contains("10000000-0000-0000-0000-000000000001"), Is.True, "Notecard 1 is missing from response"); | ||
182 | Assert.That(llsdresponse.Contains("20000000-0000-0000-0000-000000000002"), Is.True, "Notecard 2 is missing from response"); | ||
183 | } | ||
184 | |||
185 | [Test] | ||
186 | public void Test_003_Links() | ||
187 | { | ||
188 | TestHelpers.InMethod(); | ||
189 | |||
190 | FetchInvDescHandler handler = new FetchInvDescHandler(m_scene.InventoryService, null, m_scene); | ||
191 | TestOSHttpRequest req = new TestOSHttpRequest(); | ||
192 | TestOSHttpResponse resp = new TestOSHttpResponse(); | ||
193 | |||
194 | string request = "<llsd><map><key>folders</key><array><map><key>fetch_folders</key><integer>1</integer><key>fetch_items</key><boolean>1</boolean><key>folder_id</key><uuid>"; | ||
195 | request += "f0000000-0000-0000-0000-00000000000f"; | ||
196 | request += "</uuid><key>owner_id</key><uuid>00000000-0000-0000-0000-000000000000</uuid><key>sort_order</key><integer>1</integer></map></array></map></llsd>"; | ||
197 | |||
198 | string llsdresponse = handler.FetchInventoryDescendentsRequest(request, "/FETCH", string.Empty, req, resp); | ||
199 | Console.WriteLine(llsdresponse); | ||
200 | |||
201 | string descendents = "descendents</key><integer>2</integer>"; | ||
202 | Assert.That(llsdresponse.Contains(descendents), Is.True, "Incorrect number of descendents for Test Folder"); | ||
203 | |||
204 | // Make sure that the note card link is included | ||
205 | Assert.That(llsdresponse.Contains("Link to notecard"), Is.True, "Link to notecard is missing"); | ||
206 | |||
207 | //Make sure the notecard item itself is included | ||
208 | Assert.That(llsdresponse.Contains("Test Notecard 2"), Is.True, "Notecard 2 item (the source) is missing"); | ||
209 | |||
210 | // Make sure that the source item is before the link item | ||
211 | int pos1 = llsdresponse.IndexOf("Test Notecard 2"); | ||
212 | int pos2 = llsdresponse.IndexOf("Link to notecard"); | ||
213 | Assert.Less(pos1, pos2, "Source of link is after link"); | ||
214 | |||
215 | // Make sure the folder link is included | ||
216 | Assert.That(llsdresponse.Contains("Link to Objects folder"), Is.True, "Link to Objects folder is missing"); | ||
217 | |||
218 | // Make sure the objects inside the Objects folder are included | ||
219 | // Note: I'm not entirely sure this is needed, but that's what I found in the implementation | ||
220 | Assert.That(llsdresponse.Contains("Some Object"), Is.True, "Some Object item (contents of the source) is missing"); | ||
221 | |||
222 | // Make sure that the source item is before the link item | ||
223 | pos1 = llsdresponse.IndexOf("Some Object"); | ||
224 | pos2 = llsdresponse.IndexOf("Link to Objects folder"); | ||
225 | Assert.Less(pos1, pos2, "Contents of source of folder link is after folder link"); | ||
226 | } | ||
227 | |||
228 | [Test] | ||
229 | public void Test_004_DuplicateFolders() | ||
230 | { | ||
231 | TestHelpers.InMethod(); | ||
232 | |||
233 | FetchInvDescHandler handler = new FetchInvDescHandler(m_scene.InventoryService, null, m_scene); | ||
234 | TestOSHttpRequest req = new TestOSHttpRequest(); | ||
235 | TestOSHttpResponse resp = new TestOSHttpResponse(); | ||
236 | |||
237 | string request = "<llsd><map><key>folders</key><array>"; | ||
238 | request += "<map><key>fetch_folders</key><integer>1</integer><key>fetch_items</key><boolean>1</boolean><key>folder_id</key><uuid>"; | ||
239 | request += m_rootFolderID; | ||
240 | request += "</uuid><key>owner_id</key><uuid>00000000-0000-0000-0000-000000000000</uuid><key>sort_order</key><integer>1</integer></map>"; | ||
241 | request += "<map><key>fetch_folders</key><integer>1</integer><key>fetch_items</key><boolean>1</boolean><key>folder_id</key><uuid>"; | ||
242 | request += m_notecardsFolder; | ||
243 | request += "</uuid><key>owner_id</key><uuid>00000000-0000-0000-0000-000000000000</uuid><key>sort_order</key><integer>1</integer></map>"; | ||
244 | request += "<map><key>fetch_folders</key><integer>1</integer><key>fetch_items</key><boolean>1</boolean><key>folder_id</key><uuid>"; | ||
245 | request += m_rootFolderID; | ||
246 | request += "</uuid><key>owner_id</key><uuid>00000000-0000-0000-0000-000000000000</uuid><key>sort_order</key><integer>1</integer></map>"; | ||
247 | request += "<map><key>fetch_folders</key><integer>1</integer><key>fetch_items</key><boolean>1</boolean><key>folder_id</key><uuid>"; | ||
248 | request += m_notecardsFolder; | ||
249 | request += "</uuid><key>owner_id</key><uuid>00000000-0000-0000-0000-000000000000</uuid><key>sort_order</key><integer>1</integer></map>"; | ||
250 | request += "</array></map></llsd>"; | ||
251 | |||
252 | string llsdresponse = handler.FetchInventoryDescendentsRequest(request, "/FETCH", string.Empty, req, resp); | ||
253 | Console.WriteLine(llsdresponse); | ||
254 | |||
255 | string root_folder = "<key>folder_id</key><uuid>" + m_rootFolderID + "</uuid>"; | ||
256 | string notecards_folder = "<key>folder_id</key><uuid>" + m_notecardsFolder + "</uuid>"; | ||
257 | |||
258 | Assert.That(llsdresponse.Contains(root_folder), "Missing root folder"); | ||
259 | Assert.That(llsdresponse.Contains(notecards_folder), "Missing notecards folder"); | ||
260 | int count = Regex.Matches(llsdresponse, root_folder).Count; | ||
261 | Assert.AreEqual(1, count, "More than 1 root folder in response"); | ||
262 | count = Regex.Matches(llsdresponse, notecards_folder).Count; | ||
263 | Assert.AreEqual(2, count, "More than 1 notecards folder in response"); // Notecards will also be under root, so 2 | ||
264 | } | ||
265 | |||
266 | [Test] | ||
267 | public void Test_005_FolderZero() | ||
268 | { | ||
269 | TestHelpers.InMethod(); | ||
270 | |||
271 | Init(); | ||
272 | |||
273 | FetchInvDescHandler handler = new FetchInvDescHandler(m_scene.InventoryService, null, m_scene); | ||
274 | TestOSHttpRequest req = new TestOSHttpRequest(); | ||
275 | TestOSHttpResponse resp = new TestOSHttpResponse(); | ||
276 | |||
277 | string request = "<llsd><map><key>folders</key><array><map><key>fetch_folders</key><integer>1</integer><key>fetch_items</key><boolean>1</boolean><key>folder_id</key><uuid>"; | ||
278 | request += UUID.Zero; | ||
279 | request += "</uuid><key>owner_id</key><uuid>00000000-0000-0000-0000-000000000000</uuid><key>sort_order</key><integer>1</integer></map></array></map></llsd>"; | ||
280 | |||
281 | string llsdresponse = handler.FetchInventoryDescendentsRequest(request, "/FETCH", string.Empty, req, resp); | ||
282 | |||
283 | Assert.That(llsdresponse != null, Is.True, "Incorrect null response"); | ||
284 | Assert.That(llsdresponse != string.Empty, Is.True, "Incorrect empty response"); | ||
285 | Assert.That(llsdresponse.Contains("bad_folders</key><array><uuid>00000000-0000-0000-0000-000000000000"), Is.True, "Folder Zero should be a bad folder"); | ||
286 | |||
287 | Console.WriteLine(llsdresponse); | ||
288 | } | ||
289 | |||
290 | } | ||
291 | |||
292 | } \ No newline at end of file | ||
diff --git a/OpenSim/Capabilities/Handlers/GetDisplayNames/GetDisplayNamesHandler.cs b/OpenSim/Capabilities/Handlers/GetDisplayNames/GetDisplayNamesHandler.cs new file mode 100644 index 0000000..589602d --- /dev/null +++ b/OpenSim/Capabilities/Handlers/GetDisplayNames/GetDisplayNamesHandler.cs | |||
@@ -0,0 +1,120 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Collections.Specialized; | ||
32 | using System.Drawing; | ||
33 | using System.Drawing.Imaging; | ||
34 | using System.Reflection; | ||
35 | using System.IO; | ||
36 | using System.Web; | ||
37 | using log4net; | ||
38 | using Nini.Config; | ||
39 | using OpenMetaverse; | ||
40 | using OpenMetaverse.StructuredData; | ||
41 | using OpenMetaverse.Imaging; | ||
42 | using OpenSim.Framework; | ||
43 | using OpenSim.Framework.Capabilities; | ||
44 | using OpenSim.Framework.Servers; | ||
45 | using OpenSim.Framework.Servers.HttpServer; | ||
46 | using OpenSim.Region.Framework.Interfaces; | ||
47 | using OpenSim.Services.Interfaces; | ||
48 | using Caps = OpenSim.Framework.Capabilities.Caps; | ||
49 | using OSDMap = OpenMetaverse.StructuredData.OSDMap; | ||
50 | using OSDArray = OpenMetaverse.StructuredData.OSDArray; | ||
51 | |||
52 | namespace OpenSim.Capabilities.Handlers | ||
53 | { | ||
54 | public class GetDisplayNamesHandler : BaseStreamHandler | ||
55 | { | ||
56 | private static readonly ILog m_log = | ||
57 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
58 | private IUserManagement m_UserManagement; | ||
59 | |||
60 | public GetDisplayNamesHandler(string path, IUserManagement umService, string name, string description) | ||
61 | : base("GET", path, name, description) | ||
62 | { | ||
63 | m_UserManagement = umService; | ||
64 | } | ||
65 | |||
66 | protected override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
67 | { | ||
68 | m_log.DebugFormat("[GET_DISPLAY_NAMES]: called {0}", httpRequest.Url.Query); | ||
69 | |||
70 | NameValueCollection query = HttpUtility.ParseQueryString(httpRequest.Url.Query); | ||
71 | string[] ids = query.GetValues("ids"); | ||
72 | |||
73 | |||
74 | if (m_UserManagement == null) | ||
75 | { | ||
76 | m_log.Error("[GET_DISPLAY_NAMES]: Cannot fetch display names without a user management component"); | ||
77 | httpResponse.StatusCode = (int)System.Net.HttpStatusCode.InternalServerError; | ||
78 | return new byte[0]; | ||
79 | } | ||
80 | |||
81 | OSDMap osdReply = new OSDMap(); | ||
82 | OSDArray agents = new OSDArray(); | ||
83 | |||
84 | osdReply["agents"] = agents; | ||
85 | foreach (string id in ids) | ||
86 | { | ||
87 | UUID uuid = UUID.Zero; | ||
88 | if (UUID.TryParse(id, out uuid)) | ||
89 | { | ||
90 | string name = m_UserManagement.GetUserName(uuid); | ||
91 | if (!string.IsNullOrEmpty(name)) | ||
92 | { | ||
93 | string[] parts = name.Split(new char[] {' '}); | ||
94 | OSDMap osdname = new OSDMap(); | ||
95 | osdname["display_name_next_update"] = OSD.FromDate(DateTime.MinValue); | ||
96 | osdname["display_name_expires"] = OSD.FromDate(DateTime.Now.AddMonths(1)); | ||
97 | osdname["display_name"] = OSD.FromString(name); | ||
98 | osdname["legacy_first_name"] = parts[0]; | ||
99 | osdname["legacy_last_name"] = parts[1]; | ||
100 | osdname["username"] = OSD.FromString(name); | ||
101 | osdname["id"] = OSD.FromUUID(uuid); | ||
102 | osdname["is_display_name_default"] = OSD.FromBoolean(true); | ||
103 | |||
104 | agents.Add(osdname); | ||
105 | } | ||
106 | } | ||
107 | } | ||
108 | |||
109 | // Full content request | ||
110 | httpResponse.StatusCode = (int)System.Net.HttpStatusCode.OK; | ||
111 | //httpResponse.ContentLength = ??; | ||
112 | httpResponse.ContentType = "application/llsd+xml"; | ||
113 | |||
114 | string reply = OSDParser.SerializeLLSDXmlString(osdReply); | ||
115 | return System.Text.Encoding.UTF8.GetBytes(reply); | ||
116 | |||
117 | } | ||
118 | |||
119 | } | ||
120 | } \ No newline at end of file | ||
diff --git a/OpenSim/Capabilities/Handlers/GetDisplayNames/GetDisplayNamesServerConnector.cs b/OpenSim/Capabilities/Handlers/GetDisplayNames/GetDisplayNamesServerConnector.cs new file mode 100644 index 0000000..d42de56 --- /dev/null +++ b/OpenSim/Capabilities/Handlers/GetDisplayNames/GetDisplayNamesServerConnector.cs | |||
@@ -0,0 +1,71 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using Nini.Config; | ||
30 | using OpenSim.Server.Base; | ||
31 | using OpenSim.Services.Interfaces; | ||
32 | using OpenSim.Framework.Servers.HttpServer; | ||
33 | using OpenSim.Server.Handlers.Base; | ||
34 | using OpenMetaverse; | ||
35 | |||
36 | namespace OpenSim.Capabilities.Handlers | ||
37 | { | ||
38 | public class GetDisplayNamesServerConnector : ServiceConnector | ||
39 | { | ||
40 | private IUserManagement m_UserManagement; | ||
41 | private string m_ConfigName = "CapsService"; | ||
42 | |||
43 | public GetDisplayNamesServerConnector(IConfigSource config, IHttpServer server, string configName) : | ||
44 | base(config, server, configName) | ||
45 | { | ||
46 | if (configName != String.Empty) | ||
47 | m_ConfigName = configName; | ||
48 | |||
49 | IConfig serverConfig = config.Configs[m_ConfigName]; | ||
50 | if (serverConfig == null) | ||
51 | throw new Exception(String.Format("No section '{0}' in config file", m_ConfigName)); | ||
52 | |||
53 | string umService = serverConfig.GetString("AssetService", String.Empty); | ||
54 | |||
55 | if (umService == String.Empty) | ||
56 | throw new Exception("No AssetService in config file"); | ||
57 | |||
58 | Object[] args = new Object[] { config }; | ||
59 | m_UserManagement = | ||
60 | ServerUtils.LoadPlugin<IUserManagement>(umService, args); | ||
61 | |||
62 | if (m_UserManagement == null) | ||
63 | throw new Exception(String.Format("Failed to load UserManagement from {0}; config is {1}", umService, m_ConfigName)); | ||
64 | |||
65 | string rurl = serverConfig.GetString("GetTextureRedirectURL"); | ||
66 | |||
67 | server.AddStreamHandler( | ||
68 | new GetDisplayNamesHandler("/CAPS/agents/", m_UserManagement, "GetDisplayNames", null)); | ||
69 | } | ||
70 | } | ||
71 | } \ No newline at end of file | ||
diff --git a/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs b/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs new file mode 100644 index 0000000..6b67da1 --- /dev/null +++ b/OpenSim/Capabilities/Handlers/GetMesh/GetMeshHandler.cs | |||
@@ -0,0 +1,253 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using log4net; | ||
29 | using OpenMetaverse; | ||
30 | using OpenMetaverse.Imaging; | ||
31 | using OpenSim.Framework; | ||
32 | using OpenSim.Framework.Servers.HttpServer; | ||
33 | using OpenSim.Services.Interfaces; | ||
34 | using System; | ||
35 | using System.Collections.Specialized; | ||
36 | using System.Drawing; | ||
37 | using System.Drawing.Imaging; | ||
38 | using System.IO; | ||
39 | using System.Reflection; | ||
40 | using System.Web; | ||
41 | |||
42 | namespace OpenSim.Capabilities.Handlers | ||
43 | { | ||
44 | public class GetMeshHandler : BaseStreamHandler | ||
45 | { | ||
46 | private static readonly ILog m_log = | ||
47 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
48 | private IAssetService m_assetService; | ||
49 | |||
50 | // TODO: Change this to a config option | ||
51 | private string m_RedirectURL = null; | ||
52 | |||
53 | public GetMeshHandler(string path, IAssetService assService, string name, string description, string redirectURL) | ||
54 | : base("GET", path, name, description) | ||
55 | { | ||
56 | m_assetService = assService; | ||
57 | m_RedirectURL = redirectURL; | ||
58 | if (m_RedirectURL != null && !m_RedirectURL.EndsWith("/")) | ||
59 | m_RedirectURL += "/"; | ||
60 | } | ||
61 | |||
62 | protected override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
63 | { | ||
64 | // Try to parse the texture ID from the request URL | ||
65 | NameValueCollection query = HttpUtility.ParseQueryString(httpRequest.Url.Query); | ||
66 | string textureStr = query.GetOne("mesh_id"); | ||
67 | |||
68 | if (m_assetService == null) | ||
69 | { | ||
70 | m_log.Error("[GETMESH]: Cannot fetch mesh " + textureStr + " without an asset service"); | ||
71 | httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; | ||
72 | } | ||
73 | |||
74 | UUID meshID; | ||
75 | if (!String.IsNullOrEmpty(textureStr) && UUID.TryParse(textureStr, out meshID)) | ||
76 | { | ||
77 | // OK, we have an array with preferred formats, possibly with only one entry | ||
78 | |||
79 | httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; | ||
80 | AssetBase mesh; | ||
81 | |||
82 | if (!String.IsNullOrEmpty(m_RedirectURL)) | ||
83 | { | ||
84 | // Only try to fetch locally cached meshes. Misses are redirected | ||
85 | mesh = m_assetService.GetCached(meshID.ToString()); | ||
86 | |||
87 | if (mesh != null) | ||
88 | { | ||
89 | if (mesh.Type != (sbyte)AssetType.Mesh) | ||
90 | { | ||
91 | httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; | ||
92 | } | ||
93 | WriteMeshData(httpRequest, httpResponse, mesh); | ||
94 | } | ||
95 | else | ||
96 | { | ||
97 | string textureUrl = m_RedirectURL + "?mesh_id="+ meshID.ToString(); | ||
98 | m_log.Debug("[GETMESH]: Redirecting mesh request to " + textureUrl); | ||
99 | httpResponse.StatusCode = (int)OSHttpStatusCode.RedirectMovedPermanently; | ||
100 | httpResponse.RedirectLocation = textureUrl; | ||
101 | return null; | ||
102 | } | ||
103 | } | ||
104 | else // no redirect | ||
105 | { | ||
106 | // try the cache | ||
107 | mesh = m_assetService.GetCached(meshID.ToString()); | ||
108 | |||
109 | if (mesh == null) | ||
110 | { | ||
111 | // Fetch locally or remotely. Misses return a 404 | ||
112 | mesh = m_assetService.Get(meshID.ToString()); | ||
113 | |||
114 | if (mesh != null) | ||
115 | { | ||
116 | if (mesh.Type != (sbyte)AssetType.Mesh) | ||
117 | { | ||
118 | httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; | ||
119 | return null; | ||
120 | } | ||
121 | WriteMeshData(httpRequest, httpResponse, mesh); | ||
122 | return null; | ||
123 | } | ||
124 | } | ||
125 | else // it was on the cache | ||
126 | { | ||
127 | if (mesh.Type != (sbyte)AssetType.Mesh) | ||
128 | { | ||
129 | httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; | ||
130 | return null; | ||
131 | } | ||
132 | WriteMeshData(httpRequest, httpResponse, mesh); | ||
133 | return null; | ||
134 | } | ||
135 | } | ||
136 | |||
137 | // not found | ||
138 | httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; | ||
139 | return null; | ||
140 | } | ||
141 | else | ||
142 | { | ||
143 | m_log.Warn("[GETTEXTURE]: Failed to parse a mesh_id from GetMesh request: " + httpRequest.Url); | ||
144 | } | ||
145 | |||
146 | return null; | ||
147 | } | ||
148 | |||
149 | private void WriteMeshData(IOSHttpRequest request, IOSHttpResponse response, AssetBase texture) | ||
150 | { | ||
151 | string range = request.Headers.GetOne("Range"); | ||
152 | |||
153 | if (!String.IsNullOrEmpty(range)) | ||
154 | { | ||
155 | // Range request | ||
156 | int start, end; | ||
157 | if (TryParseRange(range, out start, out end)) | ||
158 | { | ||
159 | // Before clamping start make sure we can satisfy it in order to avoid | ||
160 | // sending back the last byte instead of an error status | ||
161 | if (start >= texture.Data.Length) | ||
162 | { | ||
163 | response.StatusCode = (int)System.Net.HttpStatusCode.PartialContent; | ||
164 | response.ContentType = texture.Metadata.ContentType; | ||
165 | } | ||
166 | else | ||
167 | { | ||
168 | // Handle the case where no second range value was given. This is equivalent to requesting | ||
169 | // the rest of the entity. | ||
170 | if (end == -1) | ||
171 | end = int.MaxValue; | ||
172 | |||
173 | end = Utils.Clamp(end, 0, texture.Data.Length - 1); | ||
174 | start = Utils.Clamp(start, 0, end); | ||
175 | int len = end - start + 1; | ||
176 | |||
177 | if (0 == start && len == texture.Data.Length) | ||
178 | { | ||
179 | response.StatusCode = (int)System.Net.HttpStatusCode.OK; | ||
180 | } | ||
181 | else | ||
182 | { | ||
183 | response.StatusCode = (int)System.Net.HttpStatusCode.PartialContent; | ||
184 | response.AddHeader("Content-Range", String.Format("bytes {0}-{1}/{2}", start, end, texture.Data.Length)); | ||
185 | } | ||
186 | |||
187 | response.ContentLength = len; | ||
188 | response.ContentType = "application/vnd.ll.mesh"; | ||
189 | |||
190 | response.Body.Write(texture.Data, start, len); | ||
191 | } | ||
192 | } | ||
193 | else | ||
194 | { | ||
195 | m_log.Warn("[GETMESH]: Malformed Range header: " + range); | ||
196 | response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest; | ||
197 | } | ||
198 | } | ||
199 | else | ||
200 | { | ||
201 | // Full content request | ||
202 | response.StatusCode = (int)System.Net.HttpStatusCode.OK; | ||
203 | response.ContentLength = texture.Data.Length; | ||
204 | response.ContentType = "application/vnd.ll.mesh"; | ||
205 | response.Body.Write(texture.Data, 0, texture.Data.Length); | ||
206 | } | ||
207 | } | ||
208 | |||
209 | /// <summary> | ||
210 | /// Parse a range header. | ||
211 | /// </summary> | ||
212 | /// <remarks> | ||
213 | /// As per http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html, | ||
214 | /// this obeys range headers with two values (e.g. 533-4165) and no second value (e.g. 533-). | ||
215 | /// Where there is no value, -1 is returned. | ||
216 | /// FIXME: Need to cover the case where only a second value is specified (e.g. -4165), probably by returning -1 | ||
217 | /// for start.</remarks> | ||
218 | /// <returns></returns> | ||
219 | /// <param name='header'></param> | ||
220 | /// <param name='start'>Start of the range. Undefined if this was not a number.</param> | ||
221 | /// <param name='end'>End of the range. Will be -1 if no end specified. Undefined if there was a raw string but this was not a number.</param> | ||
222 | private bool TryParseRange(string header, out int start, out int end) | ||
223 | { | ||
224 | start = end = 0; | ||
225 | |||
226 | if (header.StartsWith("bytes=")) | ||
227 | { | ||
228 | string[] rangeValues = header.Substring(6).Split('-'); | ||
229 | |||
230 | if (rangeValues.Length == 2) | ||
231 | { | ||
232 | if (!Int32.TryParse(rangeValues[0], out start)) | ||
233 | return false; | ||
234 | |||
235 | string rawEnd = rangeValues[1]; | ||
236 | |||
237 | if (rawEnd == "") | ||
238 | { | ||
239 | end = -1; | ||
240 | return true; | ||
241 | } | ||
242 | else if (Int32.TryParse(rawEnd, out end)) | ||
243 | { | ||
244 | return true; | ||
245 | } | ||
246 | } | ||
247 | } | ||
248 | |||
249 | start = end = 0; | ||
250 | return false; | ||
251 | } | ||
252 | } | ||
253 | } \ No newline at end of file | ||
diff --git a/OpenSim/Capabilities/Handlers/GetMesh/GetMeshServerConnector.cs b/OpenSim/Capabilities/Handlers/GetMesh/GetMeshServerConnector.cs new file mode 100644 index 0000000..19de3cf --- /dev/null +++ b/OpenSim/Capabilities/Handlers/GetMesh/GetMeshServerConnector.cs | |||
@@ -0,0 +1,76 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using Nini.Config; | ||
29 | using OpenMetaverse; | ||
30 | using OpenSim.Framework.Servers.HttpServer; | ||
31 | using OpenSim.Server.Base; | ||
32 | using OpenSim.Server.Handlers.Base; | ||
33 | using OpenSim.Services.Interfaces; | ||
34 | using System; | ||
35 | |||
36 | namespace OpenSim.Capabilities.Handlers | ||
37 | { | ||
38 | public class GetMeshServerConnector : ServiceConnector | ||
39 | { | ||
40 | private IAssetService m_AssetService; | ||
41 | private string m_ConfigName = "CapsService"; | ||
42 | |||
43 | public GetMeshServerConnector(IConfigSource config, IHttpServer server, string configName) : | ||
44 | base(config, server, configName) | ||
45 | { | ||
46 | if (configName != String.Empty) | ||
47 | m_ConfigName = configName; | ||
48 | |||
49 | IConfig serverConfig = config.Configs[m_ConfigName]; | ||
50 | if (serverConfig == null) | ||
51 | throw new Exception(String.Format("No section '{0}' in config file", m_ConfigName)); | ||
52 | |||
53 | string assetService = serverConfig.GetString("AssetService", String.Empty); | ||
54 | |||
55 | if (assetService == String.Empty) | ||
56 | throw new Exception("No AssetService in config file"); | ||
57 | |||
58 | Object[] args = new Object[] { config }; | ||
59 | m_AssetService = | ||
60 | ServerUtils.LoadPlugin<IAssetService>(assetService, args); | ||
61 | |||
62 | if (m_AssetService == null) | ||
63 | throw new Exception(String.Format("Failed to load AssetService from {0}; config is {1}", assetService, m_ConfigName)); | ||
64 | |||
65 | string rurl = serverConfig.GetString("GetMeshRedirectURL"); | ||
66 | |||
67 | server.AddStreamHandler( | ||
68 | new GetTextureHandler("/CAPS/GetMesh/" /*+ UUID.Random() */, m_AssetService, "GetMesh", null, rurl)); | ||
69 | |||
70 | rurl = serverConfig.GetString("GetMesh2RedirectURL"); | ||
71 | |||
72 | server.AddStreamHandler( | ||
73 | new GetTextureHandler("/CAPS/GetMesh2/" /*+ UUID.Random() */, m_AssetService, "GetMesh2", null, rurl)); | ||
74 | } | ||
75 | } | ||
76 | } \ No newline at end of file | ||
diff --git a/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs b/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs new file mode 100644 index 0000000..828e943 --- /dev/null +++ b/OpenSim/Capabilities/Handlers/GetTexture/GetTextureHandler.cs | |||
@@ -0,0 +1,431 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections; | ||
30 | using System.Collections.Specialized; | ||
31 | using System.Drawing; | ||
32 | using System.Drawing.Imaging; | ||
33 | using System.Reflection; | ||
34 | using System.IO; | ||
35 | using System.Web; | ||
36 | using log4net; | ||
37 | using Nini.Config; | ||
38 | using OpenMetaverse; | ||
39 | using OpenMetaverse.StructuredData; | ||
40 | using OpenMetaverse.Imaging; | ||
41 | using OpenSim.Framework; | ||
42 | using OpenSim.Framework.Servers; | ||
43 | using OpenSim.Framework.Servers.HttpServer; | ||
44 | using OpenSim.Region.Framework.Interfaces; | ||
45 | using OpenSim.Services.Interfaces; | ||
46 | using Caps = OpenSim.Framework.Capabilities.Caps; | ||
47 | |||
48 | namespace OpenSim.Capabilities.Handlers | ||
49 | { | ||
50 | public class GetTextureHandler : BaseStreamHandler | ||
51 | { | ||
52 | private static readonly ILog m_log = | ||
53 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
54 | private IAssetService m_assetService; | ||
55 | |||
56 | public const string DefaultFormat = "x-j2c"; | ||
57 | |||
58 | // TODO: Change this to a config option | ||
59 | private string m_RedirectURL = null; | ||
60 | |||
61 | public GetTextureHandler(string path, IAssetService assService, string name, string description, string redirectURL) | ||
62 | : base("GET", path, name, description) | ||
63 | { | ||
64 | m_assetService = assService; | ||
65 | m_RedirectURL = redirectURL; | ||
66 | if (m_RedirectURL != null && !m_RedirectURL.EndsWith("/")) | ||
67 | m_RedirectURL += "/"; | ||
68 | } | ||
69 | |||
70 | protected override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
71 | { | ||
72 | // Try to parse the texture ID from the request URL | ||
73 | NameValueCollection query = HttpUtility.ParseQueryString(httpRequest.Url.Query); | ||
74 | string textureStr = query.GetOne("texture_id"); | ||
75 | string format = query.GetOne("format"); | ||
76 | |||
77 | //m_log.DebugFormat("[GETTEXTURE]: called {0}", textureStr); | ||
78 | |||
79 | if (m_assetService == null) | ||
80 | { | ||
81 | m_log.Error("[GETTEXTURE]: Cannot fetch texture " + textureStr + " without an asset service"); | ||
82 | httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; | ||
83 | } | ||
84 | |||
85 | UUID textureID; | ||
86 | if (!String.IsNullOrEmpty(textureStr) && UUID.TryParse(textureStr, out textureID)) | ||
87 | { | ||
88 | // m_log.DebugFormat("[GETTEXTURE]: Received request for texture id {0}", textureID); | ||
89 | |||
90 | string[] formats; | ||
91 | if (!string.IsNullOrEmpty(format)) | ||
92 | { | ||
93 | formats = new string[1] { format.ToLower() }; | ||
94 | } | ||
95 | else | ||
96 | { | ||
97 | formats = WebUtil.GetPreferredImageTypes(httpRequest.Headers.Get("Accept")); | ||
98 | if (formats.Length == 0) | ||
99 | formats = new string[1] { DefaultFormat }; // default | ||
100 | |||
101 | } | ||
102 | // OK, we have an array with preferred formats, possibly with only one entry | ||
103 | |||
104 | httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; | ||
105 | foreach (string f in formats) | ||
106 | { | ||
107 | if (FetchTexture(httpRequest, httpResponse, textureID, f)) | ||
108 | break; | ||
109 | } | ||
110 | } | ||
111 | else | ||
112 | { | ||
113 | m_log.Warn("[GETTEXTURE]: Failed to parse a texture_id from GetTexture request: " + httpRequest.Url); | ||
114 | } | ||
115 | |||
116 | // m_log.DebugFormat( | ||
117 | // "[GETTEXTURE]: For texture {0} sending back response {1}, data length {2}", | ||
118 | // textureID, httpResponse.StatusCode, httpResponse.ContentLength); | ||
119 | |||
120 | return null; | ||
121 | } | ||
122 | |||
123 | /// <summary> | ||
124 | /// | ||
125 | /// </summary> | ||
126 | /// <param name="httpRequest"></param> | ||
127 | /// <param name="httpResponse"></param> | ||
128 | /// <param name="textureID"></param> | ||
129 | /// <param name="format"></param> | ||
130 | /// <returns>False for "caller try another codec"; true otherwise</returns> | ||
131 | private bool FetchTexture(IOSHttpRequest httpRequest, IOSHttpResponse httpResponse, UUID textureID, string format) | ||
132 | { | ||
133 | // m_log.DebugFormat("[GETTEXTURE]: {0} with requested format {1}", textureID, format); | ||
134 | AssetBase texture; | ||
135 | |||
136 | string fullID = textureID.ToString(); | ||
137 | if (format != DefaultFormat) | ||
138 | fullID = fullID + "-" + format; | ||
139 | |||
140 | if (!String.IsNullOrEmpty(m_RedirectURL)) | ||
141 | { | ||
142 | // Only try to fetch locally cached textures. Misses are redirected | ||
143 | texture = m_assetService.GetCached(fullID); | ||
144 | |||
145 | if (texture != null) | ||
146 | { | ||
147 | if (texture.Type != (sbyte)AssetType.Texture) | ||
148 | { | ||
149 | httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; | ||
150 | return true; | ||
151 | } | ||
152 | WriteTextureData(httpRequest, httpResponse, texture, format); | ||
153 | } | ||
154 | else | ||
155 | { | ||
156 | string textureUrl = m_RedirectURL + "?texture_id="+ textureID.ToString(); | ||
157 | m_log.Debug("[GETTEXTURE]: Redirecting texture request to " + textureUrl); | ||
158 | httpResponse.StatusCode = (int)OSHttpStatusCode.RedirectMovedPermanently; | ||
159 | httpResponse.RedirectLocation = textureUrl; | ||
160 | return true; | ||
161 | } | ||
162 | } | ||
163 | else // no redirect | ||
164 | { | ||
165 | // try the cache | ||
166 | texture = m_assetService.GetCached(fullID); | ||
167 | |||
168 | if (texture == null) | ||
169 | { | ||
170 | // m_log.DebugFormat("[GETTEXTURE]: texture was not in the cache"); | ||
171 | |||
172 | // Fetch locally or remotely. Misses return a 404 | ||
173 | texture = m_assetService.Get(textureID.ToString()); | ||
174 | |||
175 | if (texture != null) | ||
176 | { | ||
177 | if (texture.Type != (sbyte)AssetType.Texture) | ||
178 | { | ||
179 | httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; | ||
180 | return true; | ||
181 | } | ||
182 | if (format == DefaultFormat) | ||
183 | { | ||
184 | WriteTextureData(httpRequest, httpResponse, texture, format); | ||
185 | return true; | ||
186 | } | ||
187 | else | ||
188 | { | ||
189 | AssetBase newTexture = new AssetBase(texture.ID + "-" + format, texture.Name, (sbyte)AssetType.Texture, texture.Metadata.CreatorID); | ||
190 | newTexture.Data = ConvertTextureData(texture, format); | ||
191 | if (newTexture.Data.Length == 0) | ||
192 | return false; // !!! Caller try another codec, please! | ||
193 | |||
194 | newTexture.Flags = AssetFlags.Collectable; | ||
195 | newTexture.Temporary = true; | ||
196 | newTexture.Local = true; | ||
197 | m_assetService.Store(newTexture); | ||
198 | WriteTextureData(httpRequest, httpResponse, newTexture, format); | ||
199 | return true; | ||
200 | } | ||
201 | } | ||
202 | } | ||
203 | else // it was on the cache | ||
204 | { | ||
205 | // m_log.DebugFormat("[GETTEXTURE]: texture was in the cache"); | ||
206 | WriteTextureData(httpRequest, httpResponse, texture, format); | ||
207 | return true; | ||
208 | } | ||
209 | } | ||
210 | |||
211 | // not found | ||
212 | // m_log.Warn("[GETTEXTURE]: Texture " + textureID + " not found"); | ||
213 | httpResponse.StatusCode = (int)System.Net.HttpStatusCode.NotFound; | ||
214 | return true; | ||
215 | } | ||
216 | |||
217 | private void WriteTextureData(IOSHttpRequest request, IOSHttpResponse response, AssetBase texture, string format) | ||
218 | { | ||
219 | string range = request.Headers.GetOne("Range"); | ||
220 | |||
221 | if (!String.IsNullOrEmpty(range)) // JP2's only | ||
222 | { | ||
223 | // Range request | ||
224 | int start, end; | ||
225 | if (TryParseRange(range, out start, out end)) | ||
226 | { | ||
227 | // Before clamping start make sure we can satisfy it in order to avoid | ||
228 | // sending back the last byte instead of an error status | ||
229 | if (start >= texture.Data.Length) | ||
230 | { | ||
231 | // m_log.DebugFormat( | ||
232 | // "[GETTEXTURE]: Client requested range for texture {0} starting at {1} but texture has end of {2}", | ||
233 | // texture.ID, start, texture.Data.Length); | ||
234 | |||
235 | // Stricly speaking, as per http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html, we should be sending back | ||
236 | // Requested Range Not Satisfiable (416) here. However, it appears that at least recent implementations | ||
237 | // of the Linden Lab viewer (3.2.1 and 3.3.4 and probably earlier), a viewer that has previously | ||
238 | // received a very small texture may attempt to fetch bytes from the server past the | ||
239 | // range of data that it received originally. Whether this happens appears to depend on whether | ||
240 | // the viewer's estimation of how large a request it needs to make for certain discard levels | ||
241 | // (http://wiki.secondlife.com/wiki/Image_System#Discard_Level_and_Mip_Mapping), chiefly discard | ||
242 | // level 2. If this estimate is greater than the total texture size, returning a RequestedRangeNotSatisfiable | ||
243 | // here will cause the viewer to treat the texture as bad and never display the full resolution | ||
244 | // However, if we return PartialContent (or OK) instead, the viewer will display that resolution. | ||
245 | |||
246 | // response.StatusCode = (int)System.Net.HttpStatusCode.RequestedRangeNotSatisfiable; | ||
247 | // response.AddHeader("Content-Range", String.Format("bytes */{0}", texture.Data.Length)); | ||
248 | // response.StatusCode = (int)System.Net.HttpStatusCode.OK; | ||
249 | response.StatusCode = (int)System.Net.HttpStatusCode.PartialContent; | ||
250 | response.ContentType = texture.Metadata.ContentType; | ||
251 | } | ||
252 | else | ||
253 | { | ||
254 | // Handle the case where no second range value was given. This is equivalent to requesting | ||
255 | // the rest of the entity. | ||
256 | if (end == -1) | ||
257 | end = int.MaxValue; | ||
258 | |||
259 | end = Utils.Clamp(end, 0, texture.Data.Length - 1); | ||
260 | start = Utils.Clamp(start, 0, end); | ||
261 | int len = end - start + 1; | ||
262 | |||
263 | // m_log.Debug("Serving " + start + " to " + end + " of " + texture.Data.Length + " bytes for texture " + texture.ID); | ||
264 | |||
265 | // Always return PartialContent, even if the range covered the entire data length | ||
266 | // We were accidentally sending back 404 before in this situation | ||
267 | // https://issues.apache.org/bugzilla/show_bug.cgi?id=51878 supports sending 206 even if the | ||
268 | // entire range is requested, and viewer 3.2.2 (and very probably earlier) seems fine with this. | ||
269 | // | ||
270 | // We also do not want to send back OK even if the whole range was satisfiable since this causes | ||
271 | // HTTP textures on at least Imprudence 1.4.0-beta2 to never display the final texture quality. | ||
272 | // if (end > maxEnd) | ||
273 | // response.StatusCode = (int)System.Net.HttpStatusCode.OK; | ||
274 | // else | ||
275 | response.StatusCode = (int)System.Net.HttpStatusCode.PartialContent; | ||
276 | |||
277 | response.ContentLength = len; | ||
278 | response.ContentType = texture.Metadata.ContentType; | ||
279 | response.AddHeader("Content-Range", String.Format("bytes {0}-{1}/{2}", start, end, texture.Data.Length)); | ||
280 | |||
281 | response.Body.Write(texture.Data, start, len); | ||
282 | } | ||
283 | } | ||
284 | else | ||
285 | { | ||
286 | m_log.Warn("[GETTEXTURE]: Malformed Range header: " + range); | ||
287 | response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest; | ||
288 | } | ||
289 | } | ||
290 | else // JP2's or other formats | ||
291 | { | ||
292 | // Full content request | ||
293 | response.StatusCode = (int)System.Net.HttpStatusCode.OK; | ||
294 | response.ContentLength = texture.Data.Length; | ||
295 | if (format == DefaultFormat) | ||
296 | response.ContentType = texture.Metadata.ContentType; | ||
297 | else | ||
298 | response.ContentType = "image/" + format; | ||
299 | response.Body.Write(texture.Data, 0, texture.Data.Length); | ||
300 | } | ||
301 | |||
302 | // if (response.StatusCode < 200 || response.StatusCode > 299) | ||
303 | // m_log.WarnFormat( | ||
304 | // "[GETTEXTURE]: For texture {0} requested range {1} responded {2} with content length {3} (actual {4})", | ||
305 | // texture.FullID, range, response.StatusCode, response.ContentLength, texture.Data.Length); | ||
306 | // else | ||
307 | // m_log.DebugFormat( | ||
308 | // "[GETTEXTURE]: For texture {0} requested range {1} responded {2} with content length {3} (actual {4})", | ||
309 | // texture.FullID, range, response.StatusCode, response.ContentLength, texture.Data.Length); | ||
310 | } | ||
311 | |||
312 | /// <summary> | ||
313 | /// Parse a range header. | ||
314 | /// </summary> | ||
315 | /// <remarks> | ||
316 | /// As per http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html, | ||
317 | /// this obeys range headers with two values (e.g. 533-4165) and no second value (e.g. 533-). | ||
318 | /// Where there is no value, -1 is returned. | ||
319 | /// FIXME: Need to cover the case where only a second value is specified (e.g. -4165), probably by returning -1 | ||
320 | /// for start.</remarks> | ||
321 | /// <returns></returns> | ||
322 | /// <param name='header'></param> | ||
323 | /// <param name='start'>Start of the range. Undefined if this was not a number.</param> | ||
324 | /// <param name='end'>End of the range. Will be -1 if no end specified. Undefined if there was a raw string but this was not a number.</param> | ||
325 | private bool TryParseRange(string header, out int start, out int end) | ||
326 | { | ||
327 | start = end = 0; | ||
328 | |||
329 | if (header.StartsWith("bytes=")) | ||
330 | { | ||
331 | string[] rangeValues = header.Substring(6).Split('-'); | ||
332 | |||
333 | if (rangeValues.Length == 2) | ||
334 | { | ||
335 | if (!Int32.TryParse(rangeValues[0], out start)) | ||
336 | return false; | ||
337 | |||
338 | string rawEnd = rangeValues[1]; | ||
339 | |||
340 | if (rawEnd == "") | ||
341 | { | ||
342 | end = -1; | ||
343 | return true; | ||
344 | } | ||
345 | else if (Int32.TryParse(rawEnd, out end)) | ||
346 | { | ||
347 | return true; | ||
348 | } | ||
349 | } | ||
350 | } | ||
351 | |||
352 | start = end = 0; | ||
353 | return false; | ||
354 | } | ||
355 | |||
356 | private byte[] ConvertTextureData(AssetBase texture, string format) | ||
357 | { | ||
358 | m_log.DebugFormat("[GETTEXTURE]: Converting texture {0} to {1}", texture.ID, format); | ||
359 | byte[] data = new byte[0]; | ||
360 | |||
361 | MemoryStream imgstream = new MemoryStream(); | ||
362 | Bitmap mTexture = new Bitmap(1, 1); | ||
363 | ManagedImage managedImage; | ||
364 | Image image = (Image)mTexture; | ||
365 | |||
366 | try | ||
367 | { | ||
368 | // Taking our jpeg2000 data, decoding it, then saving it to a byte array with regular data | ||
369 | |||
370 | imgstream = new MemoryStream(); | ||
371 | |||
372 | // Decode image to System.Drawing.Image | ||
373 | if (OpenJPEG.DecodeToImage(texture.Data, out managedImage, out image)) | ||
374 | { | ||
375 | // Save to bitmap | ||
376 | mTexture = new Bitmap(image); | ||
377 | |||
378 | EncoderParameters myEncoderParameters = new EncoderParameters(); | ||
379 | myEncoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, 95L); | ||
380 | |||
381 | // Save bitmap to stream | ||
382 | ImageCodecInfo codec = GetEncoderInfo("image/" + format); | ||
383 | if (codec != null) | ||
384 | { | ||
385 | mTexture.Save(imgstream, codec, myEncoderParameters); | ||
386 | // Write the stream to a byte array for output | ||
387 | data = imgstream.ToArray(); | ||
388 | } | ||
389 | else | ||
390 | m_log.WarnFormat("[GETTEXTURE]: No such codec {0}", format); | ||
391 | |||
392 | } | ||
393 | } | ||
394 | catch (Exception e) | ||
395 | { | ||
396 | m_log.WarnFormat("[GETTEXTURE]: Unable to convert texture {0} to {1}: {2}", texture.ID, format, e.Message); | ||
397 | } | ||
398 | finally | ||
399 | { | ||
400 | // Reclaim memory, these are unmanaged resources | ||
401 | // If we encountered an exception, one or more of these will be null | ||
402 | if (mTexture != null) | ||
403 | mTexture.Dispose(); | ||
404 | |||
405 | if (image != null) | ||
406 | image.Dispose(); | ||
407 | |||
408 | if (imgstream != null) | ||
409 | { | ||
410 | imgstream.Close(); | ||
411 | imgstream.Dispose(); | ||
412 | } | ||
413 | } | ||
414 | |||
415 | return data; | ||
416 | } | ||
417 | |||
418 | // From msdn | ||
419 | private static ImageCodecInfo GetEncoderInfo(String mimeType) | ||
420 | { | ||
421 | ImageCodecInfo[] encoders; | ||
422 | encoders = ImageCodecInfo.GetImageEncoders(); | ||
423 | for (int j = 0; j < encoders.Length; ++j) | ||
424 | { | ||
425 | if (encoders[j].MimeType == mimeType) | ||
426 | return encoders[j]; | ||
427 | } | ||
428 | return null; | ||
429 | } | ||
430 | } | ||
431 | } \ No newline at end of file | ||
diff --git a/OpenSim/Capabilities/Handlers/GetTexture/GetTextureServerConnector.cs b/OpenSim/Capabilities/Handlers/GetTexture/GetTextureServerConnector.cs new file mode 100644 index 0000000..fa0b228 --- /dev/null +++ b/OpenSim/Capabilities/Handlers/GetTexture/GetTextureServerConnector.cs | |||
@@ -0,0 +1,71 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using Nini.Config; | ||
30 | using OpenSim.Server.Base; | ||
31 | using OpenSim.Services.Interfaces; | ||
32 | using OpenSim.Framework.Servers.HttpServer; | ||
33 | using OpenSim.Server.Handlers.Base; | ||
34 | using OpenMetaverse; | ||
35 | |||
36 | namespace OpenSim.Capabilities.Handlers | ||
37 | { | ||
38 | public class GetTextureServerConnector : ServiceConnector | ||
39 | { | ||
40 | private IAssetService m_AssetService; | ||
41 | private string m_ConfigName = "CapsService"; | ||
42 | |||
43 | public GetTextureServerConnector(IConfigSource config, IHttpServer server, string configName) : | ||
44 | base(config, server, configName) | ||
45 | { | ||
46 | if (configName != String.Empty) | ||
47 | m_ConfigName = configName; | ||
48 | |||
49 | IConfig serverConfig = config.Configs[m_ConfigName]; | ||
50 | if (serverConfig == null) | ||
51 | throw new Exception(String.Format("No section '{0}' in config file", m_ConfigName)); | ||
52 | |||
53 | string assetService = serverConfig.GetString("AssetService", String.Empty); | ||
54 | |||
55 | if (assetService == String.Empty) | ||
56 | throw new Exception("No AssetService in config file"); | ||
57 | |||
58 | Object[] args = new Object[] { config }; | ||
59 | m_AssetService = | ||
60 | ServerUtils.LoadPlugin<IAssetService>(assetService, args); | ||
61 | |||
62 | if (m_AssetService == null) | ||
63 | throw new Exception(String.Format("Failed to load AssetService from {0}; config is {1}", assetService, m_ConfigName)); | ||
64 | |||
65 | string rurl = serverConfig.GetString("GetTextureRedirectURL"); | ||
66 | ; | ||
67 | server.AddStreamHandler( | ||
68 | new GetTextureHandler("/CAPS/GetTexture/" /*+ UUID.Random() */, m_AssetService, "GetTexture", null, rurl)); | ||
69 | } | ||
70 | } | ||
71 | } \ No newline at end of file | ||
diff --git a/OpenSim/Capabilities/Handlers/GetTexture/Tests/GetTextureHandlerTests.cs b/OpenSim/Capabilities/Handlers/GetTexture/Tests/GetTextureHandlerTests.cs new file mode 100644 index 0000000..e5d9618 --- /dev/null +++ b/OpenSim/Capabilities/Handlers/GetTexture/Tests/GetTextureHandlerTests.cs | |||
@@ -0,0 +1,62 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Net; | ||
31 | using log4net; | ||
32 | using log4net.Config; | ||
33 | using NUnit.Framework; | ||
34 | using OpenMetaverse; | ||
35 | using OpenSim.Capabilities.Handlers; | ||
36 | using OpenSim.Framework; | ||
37 | using OpenSim.Framework.Servers.HttpServer; | ||
38 | using OpenSim.Region.Framework.Scenes; | ||
39 | using OpenSim.Tests.Common; | ||
40 | |||
41 | namespace OpenSim.Capabilities.Handlers.GetTexture.Tests | ||
42 | { | ||
43 | [TestFixture] | ||
44 | public class GetTextureHandlerTests : OpenSimTestCase | ||
45 | { | ||
46 | [Test] | ||
47 | public void TestTextureNotFound() | ||
48 | { | ||
49 | TestHelpers.InMethod(); | ||
50 | |||
51 | // Overkill - we only really need the asset service, not a whole scene. | ||
52 | Scene scene = new SceneHelpers().SetupScene(); | ||
53 | |||
54 | GetTextureHandler handler = new GetTextureHandler("/gettexture", scene.AssetService, "TestGetTexture", null, null); | ||
55 | TestOSHttpRequest req = new TestOSHttpRequest(); | ||
56 | TestOSHttpResponse resp = new TestOSHttpResponse(); | ||
57 | req.Url = new Uri("http://localhost/?texture_id=00000000-0000-1111-9999-000000000012"); | ||
58 | handler.Handle(null, null, req, resp); | ||
59 | Assert.That(resp.StatusCode, Is.EqualTo((int)System.Net.HttpStatusCode.NotFound)); | ||
60 | } | ||
61 | } | ||
62 | } \ No newline at end of file | ||
diff --git a/OpenSim/Capabilities/Handlers/Properties/AssemblyInfo.cs b/OpenSim/Capabilities/Handlers/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..3579649 --- /dev/null +++ b/OpenSim/Capabilities/Handlers/Properties/AssemblyInfo.cs | |||
@@ -0,0 +1,33 @@ | |||
1 | using System.Reflection; | ||
2 | using System.Runtime.CompilerServices; | ||
3 | using System.Runtime.InteropServices; | ||
4 | |||
5 | // General Information about an assembly is controlled through the following | ||
6 | // set of attributes. Change these attribute values to modify the information | ||
7 | // associated with an assembly. | ||
8 | [assembly: AssemblyTitle("OpenSim.Capabilities.Handlers")] | ||
9 | [assembly: AssemblyDescription("")] | ||
10 | [assembly: AssemblyConfiguration("")] | ||
11 | [assembly: AssemblyCompany("http://opensimulator.org")] | ||
12 | [assembly: AssemblyProduct("OpenSim")] | ||
13 | [assembly: AssemblyCopyright("OpenSimulator developers")] | ||
14 | [assembly: AssemblyTrademark("")] | ||
15 | [assembly: AssemblyCulture("")] | ||
16 | |||
17 | // Setting ComVisible to false makes the types in this assembly not visible | ||
18 | // to COM components. If you need to access a type in this assembly from | ||
19 | // COM, set the ComVisible attribute to true on that type. | ||
20 | [assembly: ComVisible(false)] | ||
21 | |||
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM | ||
23 | [assembly: Guid("32350823-e1df-45e3-b7fa-0a58b4372433")] | ||
24 | |||
25 | // Version information for an assembly consists of the following four values: | ||
26 | // | ||
27 | // Major Version | ||
28 | // Minor Version | ||
29 | // Build Number | ||
30 | // Revision | ||
31 | // | ||
32 | [assembly: AssemblyVersion("0.8.2.*")] | ||
33 | |||
diff --git a/OpenSim/Capabilities/Handlers/UploadBakedTexture/UploadBakedTextureHandler.cs b/OpenSim/Capabilities/Handlers/UploadBakedTexture/UploadBakedTextureHandler.cs new file mode 100644 index 0000000..8849a59 --- /dev/null +++ b/OpenSim/Capabilities/Handlers/UploadBakedTexture/UploadBakedTextureHandler.cs | |||
@@ -0,0 +1,181 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections; | ||
30 | using System.Collections.Specialized; | ||
31 | using System.Drawing; | ||
32 | using System.Drawing.Imaging; | ||
33 | using System.Reflection; | ||
34 | using System.IO; | ||
35 | using System.Web; | ||
36 | using log4net; | ||
37 | using Nini.Config; | ||
38 | using OpenMetaverse; | ||
39 | using OpenMetaverse.StructuredData; | ||
40 | using OpenMetaverse.Imaging; | ||
41 | using OpenSim.Framework; | ||
42 | using OpenSim.Framework.Capabilities; | ||
43 | using OpenSim.Framework.Servers; | ||
44 | using OpenSim.Framework.Servers.HttpServer; | ||
45 | using OpenSim.Region.Framework.Interfaces; | ||
46 | using OpenSim.Services.Interfaces; | ||
47 | using Caps = OpenSim.Framework.Capabilities.Caps; | ||
48 | |||
49 | namespace OpenSim.Capabilities.Handlers | ||
50 | { | ||
51 | public class UploadBakedTextureHandler | ||
52 | { | ||
53 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
54 | |||
55 | private Caps m_HostCapsObj; | ||
56 | private IAssetService m_assetService; | ||
57 | private bool m_persistBakedTextures; | ||
58 | |||
59 | public UploadBakedTextureHandler(Caps caps, IAssetService assetService, bool persistBakedTextures) | ||
60 | { | ||
61 | m_HostCapsObj = caps; | ||
62 | m_assetService = assetService; | ||
63 | m_persistBakedTextures = persistBakedTextures; | ||
64 | } | ||
65 | |||
66 | /// <summary> | ||
67 | /// Handle a request from the client for a Uri to upload a baked texture. | ||
68 | /// </summary> | ||
69 | /// <param name="request"></param> | ||
70 | /// <param name="path"></param> | ||
71 | /// <param name="param"></param> | ||
72 | /// <param name="httpRequest"></param> | ||
73 | /// <param name="httpResponse"></param> | ||
74 | /// <returns>The upload response if the request is successful, null otherwise.</returns> | ||
75 | public string UploadBakedTexture( | ||
76 | string request, string path, string param, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
77 | { | ||
78 | try | ||
79 | { | ||
80 | string capsBase = "/CAPS/" + m_HostCapsObj.CapsObjectPath; | ||
81 | string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000"); | ||
82 | |||
83 | BakedTextureUploader uploader = | ||
84 | new BakedTextureUploader(capsBase + uploaderPath, m_HostCapsObj.HttpListener); | ||
85 | uploader.OnUpLoad += BakedTextureUploaded; | ||
86 | |||
87 | m_HostCapsObj.HttpListener.AddStreamHandler( | ||
88 | new BinaryStreamHandler( | ||
89 | "POST", capsBase + uploaderPath, uploader.uploaderCaps, "UploadBakedTexture", null)); | ||
90 | |||
91 | string protocol = "http://"; | ||
92 | |||
93 | if (m_HostCapsObj.SSLCaps) | ||
94 | protocol = "https://"; | ||
95 | |||
96 | string uploaderURL = protocol + m_HostCapsObj.HostName + ":" + | ||
97 | m_HostCapsObj.Port.ToString() + capsBase + uploaderPath; | ||
98 | |||
99 | LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse(); | ||
100 | uploadResponse.uploader = uploaderURL; | ||
101 | uploadResponse.state = "upload"; | ||
102 | |||
103 | return LLSDHelpers.SerialiseLLSDReply(uploadResponse); | ||
104 | } | ||
105 | catch (Exception e) | ||
106 | { | ||
107 | m_log.ErrorFormat("[UPLOAD BAKED TEXTURE HANDLER]: {0}{1}", e.Message, e.StackTrace); | ||
108 | } | ||
109 | |||
110 | return null; | ||
111 | } | ||
112 | |||
113 | /// <summary> | ||
114 | /// Called when a baked texture has been successfully uploaded by a client. | ||
115 | /// </summary> | ||
116 | /// <param name="assetID"></param> | ||
117 | /// <param name="data"></param> | ||
118 | private void BakedTextureUploaded(UUID assetID, byte[] data) | ||
119 | { | ||
120 | // m_log.DebugFormat("[UPLOAD BAKED TEXTURE HANDLER]: Received baked texture {0}", assetID.ToString()); | ||
121 | |||
122 | AssetBase asset; | ||
123 | asset = new AssetBase(assetID, "Baked Texture", (sbyte)AssetType.Texture, m_HostCapsObj.AgentID.ToString()); | ||
124 | asset.Data = data; | ||
125 | asset.Temporary = true; | ||
126 | asset.Local = !m_persistBakedTextures; // Local assets aren't persisted, non-local are | ||
127 | m_assetService.Store(asset); | ||
128 | } | ||
129 | } | ||
130 | |||
131 | class BakedTextureUploader | ||
132 | { | ||
133 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
134 | |||
135 | public event Action<UUID, byte[]> OnUpLoad; | ||
136 | |||
137 | private string uploaderPath = String.Empty; | ||
138 | private UUID newAssetID; | ||
139 | private IHttpServer httpListener; | ||
140 | |||
141 | public BakedTextureUploader(string path, IHttpServer httpServer) | ||
142 | { | ||
143 | newAssetID = UUID.Random(); | ||
144 | uploaderPath = path; | ||
145 | httpListener = httpServer; | ||
146 | // m_log.InfoFormat("[CAPS] baked texture upload starting for {0}",newAssetID); | ||
147 | } | ||
148 | |||
149 | /// <summary> | ||
150 | /// Handle raw uploaded baked texture data. | ||
151 | /// </summary> | ||
152 | /// <param name="data"></param> | ||
153 | /// <param name="path"></param> | ||
154 | /// <param name="param"></param> | ||
155 | /// <returns></returns> | ||
156 | public string uploaderCaps(byte[] data, string path, string param) | ||
157 | { | ||
158 | Action<UUID, byte[]> handlerUpLoad = OnUpLoad; | ||
159 | |||
160 | // Don't do this asynchronously, otherwise it's possible for the client to send set appearance information | ||
161 | // on another thread which might send out avatar updates before the asset has been put into the asset | ||
162 | // service. | ||
163 | if (handlerUpLoad != null) | ||
164 | handlerUpLoad(newAssetID, data); | ||
165 | |||
166 | string res = String.Empty; | ||
167 | LLSDAssetUploadComplete uploadComplete = new LLSDAssetUploadComplete(); | ||
168 | uploadComplete.new_asset = newAssetID.ToString(); | ||
169 | uploadComplete.new_inventory_item = UUID.Zero; | ||
170 | uploadComplete.state = "complete"; | ||
171 | |||
172 | res = LLSDHelpers.SerialiseLLSDReply(uploadComplete); | ||
173 | |||
174 | httpListener.RemoveStreamHandler("POST", uploaderPath); | ||
175 | |||
176 | // m_log.DebugFormat("[BAKED TEXTURE UPLOADER]: baked texture upload completed for {0}", newAssetID); | ||
177 | |||
178 | return res; | ||
179 | } | ||
180 | } | ||
181 | } \ No newline at end of file | ||
diff --git a/OpenSim/Capabilities/Handlers/UploadBakedTexture/UploadBakedTextureServerConnector.cs b/OpenSim/Capabilities/Handlers/UploadBakedTexture/UploadBakedTextureServerConnector.cs new file mode 100644 index 0000000..10ea8ee --- /dev/null +++ b/OpenSim/Capabilities/Handlers/UploadBakedTexture/UploadBakedTextureServerConnector.cs | |||
@@ -0,0 +1,76 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using Nini.Config; | ||
30 | using OpenSim.Server.Base; | ||
31 | using OpenSim.Services.Interfaces; | ||
32 | using OpenSim.Framework.Servers.HttpServer; | ||
33 | using OpenSim.Server.Handlers.Base; | ||
34 | using OpenMetaverse; | ||
35 | |||
36 | namespace OpenSim.Capabilities.Handlers | ||
37 | { | ||
38 | public class UploadBakedTextureServerConnector : ServiceConnector | ||
39 | { | ||
40 | private IAssetService m_AssetService; | ||
41 | private string m_ConfigName = "CapsService"; | ||
42 | |||
43 | public UploadBakedTextureServerConnector(IConfigSource config, IHttpServer server, string configName) : | ||
44 | base(config, server, configName) | ||
45 | { | ||
46 | if (configName != String.Empty) | ||
47 | m_ConfigName = configName; | ||
48 | |||
49 | IConfig serverConfig = config.Configs[m_ConfigName]; | ||
50 | if (serverConfig == null) | ||
51 | throw new Exception(String.Format("No section '{0}' in config file", m_ConfigName)); | ||
52 | |||
53 | string assetService = serverConfig.GetString("AssetService", String.Empty); | ||
54 | |||
55 | if (assetService == String.Empty) | ||
56 | throw new Exception("No AssetService in config file"); | ||
57 | |||
58 | Object[] args = new Object[] { config }; | ||
59 | m_AssetService = | ||
60 | ServerUtils.LoadPlugin<IAssetService>(assetService, args); | ||
61 | |||
62 | if (m_AssetService == null) | ||
63 | throw new Exception(String.Format("Failed to load AssetService from {0}; config is {1}", assetService, m_ConfigName)); | ||
64 | |||
65 | // NEED TO FIX THIS | ||
66 | OpenSim.Framework.Capabilities.Caps caps = new OpenSim.Framework.Capabilities.Caps(server, "", server.Port, "", UUID.Zero, ""); | ||
67 | server.AddStreamHandler(new RestStreamHandler( | ||
68 | "POST", | ||
69 | "/CAPS/UploadBakedTexture/", | ||
70 | new UploadBakedTextureHandler(caps, m_AssetService, true).UploadBakedTexture, | ||
71 | "UploadBakedTexture", | ||
72 | "Upload Baked Texture Capability")); | ||
73 | |||
74 | } | ||
75 | } | ||
76 | } \ No newline at end of file | ||
diff --git a/OpenSim/Capabilities/LLSD.cs b/OpenSim/Capabilities/LLSD.cs new file mode 100644 index 0000000..c59cede --- /dev/null +++ b/OpenSim/Capabilities/LLSD.cs | |||
@@ -0,0 +1,684 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections; | ||
30 | using System.Globalization; | ||
31 | using System.IO; | ||
32 | using System.Security.Cryptography; | ||
33 | using System.Text; | ||
34 | using System.Xml; | ||
35 | using OpenMetaverse; | ||
36 | |||
37 | namespace OpenSim.Framework.Capabilities | ||
38 | { | ||
39 | /// <summary> | ||
40 | /// Borrowed from (a older version of) libsl for now, as their new llsd code doesn't work we our decoding code. | ||
41 | /// </summary> | ||
42 | public static class LLSD | ||
43 | { | ||
44 | /// <summary> | ||
45 | /// | ||
46 | /// </summary> | ||
47 | public class LLSDParseException : Exception | ||
48 | { | ||
49 | public LLSDParseException(string message) : base(message) | ||
50 | { | ||
51 | } | ||
52 | } | ||
53 | |||
54 | /// <summary> | ||
55 | /// | ||
56 | /// </summary> | ||
57 | public class LLSDSerializeException : Exception | ||
58 | { | ||
59 | public LLSDSerializeException(string message) : base(message) | ||
60 | { | ||
61 | } | ||
62 | } | ||
63 | |||
64 | /// <summary> | ||
65 | /// | ||
66 | /// </summary> | ||
67 | /// <param name="b"></param> | ||
68 | /// <returns></returns> | ||
69 | public static object LLSDDeserialize(byte[] b) | ||
70 | { | ||
71 | using (MemoryStream ms = new MemoryStream(b, false)) | ||
72 | { | ||
73 | return LLSDDeserialize(ms); | ||
74 | } | ||
75 | } | ||
76 | |||
77 | /// <summary> | ||
78 | /// | ||
79 | /// </summary> | ||
80 | /// <param name="st"></param> | ||
81 | /// <returns></returns> | ||
82 | public static object LLSDDeserialize(Stream st) | ||
83 | { | ||
84 | using (XmlTextReader reader = new XmlTextReader(st)) | ||
85 | { | ||
86 | reader.Read(); | ||
87 | SkipWS(reader); | ||
88 | |||
89 | if (reader.NodeType != XmlNodeType.Element || reader.LocalName != "llsd") | ||
90 | throw new LLSDParseException("Expected <llsd>"); | ||
91 | |||
92 | reader.Read(); | ||
93 | object ret = LLSDParseOne(reader); | ||
94 | SkipWS(reader); | ||
95 | |||
96 | if (reader.NodeType != XmlNodeType.EndElement || reader.LocalName != "llsd") | ||
97 | throw new LLSDParseException("Expected </llsd>"); | ||
98 | |||
99 | return ret; | ||
100 | } | ||
101 | } | ||
102 | |||
103 | /// <summary> | ||
104 | /// | ||
105 | /// </summary> | ||
106 | /// <param name="obj"></param> | ||
107 | /// <returns></returns> | ||
108 | public static byte[] LLSDSerialize(object obj) | ||
109 | { | ||
110 | StringWriter sw = new StringWriter(); | ||
111 | XmlTextWriter writer = new XmlTextWriter(sw); | ||
112 | writer.Formatting = Formatting.None; | ||
113 | |||
114 | writer.WriteStartElement(String.Empty, "llsd", String.Empty); | ||
115 | LLSDWriteOne(writer, obj); | ||
116 | writer.WriteEndElement(); | ||
117 | |||
118 | writer.Close(); | ||
119 | |||
120 | return Util.UTF8.GetBytes(sw.ToString()); | ||
121 | } | ||
122 | |||
123 | /// <summary> | ||
124 | /// | ||
125 | /// </summary> | ||
126 | /// <param name="writer"></param> | ||
127 | /// <param name="obj"></param> | ||
128 | public static void LLSDWriteOne(XmlTextWriter writer, object obj) | ||
129 | { | ||
130 | if (obj == null) | ||
131 | { | ||
132 | writer.WriteStartElement(String.Empty, "undef", String.Empty); | ||
133 | writer.WriteEndElement(); | ||
134 | return; | ||
135 | } | ||
136 | |||
137 | if (obj is string) | ||
138 | { | ||
139 | writer.WriteStartElement(String.Empty, "string", String.Empty); | ||
140 | writer.WriteString((string) obj); | ||
141 | writer.WriteEndElement(); | ||
142 | } | ||
143 | else if (obj is int) | ||
144 | { | ||
145 | writer.WriteStartElement(String.Empty, "integer", String.Empty); | ||
146 | writer.WriteString(obj.ToString()); | ||
147 | writer.WriteEndElement(); | ||
148 | } | ||
149 | else if (obj is double) | ||
150 | { | ||
151 | writer.WriteStartElement(String.Empty, "real", String.Empty); | ||
152 | writer.WriteString(obj.ToString()); | ||
153 | writer.WriteEndElement(); | ||
154 | } | ||
155 | else if (obj is bool) | ||
156 | { | ||
157 | bool b = (bool) obj; | ||
158 | writer.WriteStartElement(String.Empty, "boolean", String.Empty); | ||
159 | writer.WriteString(b ? "1" : "0"); | ||
160 | writer.WriteEndElement(); | ||
161 | } | ||
162 | else if (obj is ulong) | ||
163 | { | ||
164 | throw new Exception("ulong in LLSD is currently not implemented, fix me!"); | ||
165 | } | ||
166 | else if (obj is UUID) | ||
167 | { | ||
168 | UUID u = (UUID) obj; | ||
169 | writer.WriteStartElement(String.Empty, "uuid", String.Empty); | ||
170 | writer.WriteString(u.ToString()); | ||
171 | writer.WriteEndElement(); | ||
172 | } | ||
173 | else if (obj is Hashtable) | ||
174 | { | ||
175 | Hashtable h = obj as Hashtable; | ||
176 | writer.WriteStartElement(String.Empty, "map", String.Empty); | ||
177 | foreach (string key in h.Keys) | ||
178 | { | ||
179 | writer.WriteStartElement(String.Empty, "key", String.Empty); | ||
180 | writer.WriteString(key); | ||
181 | writer.WriteEndElement(); | ||
182 | LLSDWriteOne(writer, h[key]); | ||
183 | } | ||
184 | writer.WriteEndElement(); | ||
185 | } | ||
186 | else if (obj is ArrayList) | ||
187 | { | ||
188 | ArrayList a = obj as ArrayList; | ||
189 | writer.WriteStartElement(String.Empty, "array", String.Empty); | ||
190 | foreach (object item in a) | ||
191 | { | ||
192 | LLSDWriteOne(writer, item); | ||
193 | } | ||
194 | writer.WriteEndElement(); | ||
195 | } | ||
196 | else if (obj is byte[]) | ||
197 | { | ||
198 | byte[] b = obj as byte[]; | ||
199 | writer.WriteStartElement(String.Empty, "binary", String.Empty); | ||
200 | |||
201 | writer.WriteStartAttribute(String.Empty, "encoding", String.Empty); | ||
202 | writer.WriteString("base64"); | ||
203 | writer.WriteEndAttribute(); | ||
204 | |||
205 | //// Calculate the length of the base64 output | ||
206 | //long length = (long)(4.0d * b.Length / 3.0d); | ||
207 | //if (length % 4 != 0) length += 4 - (length % 4); | ||
208 | |||
209 | //// Create the char[] for base64 output and fill it | ||
210 | //char[] tmp = new char[length]; | ||
211 | //int i = Convert.ToBase64CharArray(b, 0, b.Length, tmp, 0); | ||
212 | |||
213 | //writer.WriteString(new String(tmp)); | ||
214 | |||
215 | writer.WriteString(Convert.ToBase64String(b)); | ||
216 | writer.WriteEndElement(); | ||
217 | } | ||
218 | else | ||
219 | { | ||
220 | throw new LLSDSerializeException("Unknown type " + obj.GetType().Name); | ||
221 | } | ||
222 | } | ||
223 | |||
224 | /// <summary> | ||
225 | /// | ||
226 | /// </summary> | ||
227 | /// <param name="reader"></param> | ||
228 | /// <returns></returns> | ||
229 | public static object LLSDParseOne(XmlTextReader reader) | ||
230 | { | ||
231 | SkipWS(reader); | ||
232 | if (reader.NodeType != XmlNodeType.Element) | ||
233 | throw new LLSDParseException("Expected an element"); | ||
234 | |||
235 | string dtype = reader.LocalName; | ||
236 | object ret = null; | ||
237 | |||
238 | switch (dtype) | ||
239 | { | ||
240 | case "undef": | ||
241 | { | ||
242 | if (reader.IsEmptyElement) | ||
243 | { | ||
244 | reader.Read(); | ||
245 | return null; | ||
246 | } | ||
247 | |||
248 | reader.Read(); | ||
249 | SkipWS(reader); | ||
250 | ret = null; | ||
251 | break; | ||
252 | } | ||
253 | case "boolean": | ||
254 | { | ||
255 | if (reader.IsEmptyElement) | ||
256 | { | ||
257 | reader.Read(); | ||
258 | return false; | ||
259 | } | ||
260 | |||
261 | reader.Read(); | ||
262 | string s = reader.ReadString().Trim(); | ||
263 | |||
264 | if (s == String.Empty || s == "false" || s == "0") | ||
265 | ret = false; | ||
266 | else if (s == "true" || s == "1") | ||
267 | ret = true; | ||
268 | else | ||
269 | throw new LLSDParseException("Bad boolean value " + s); | ||
270 | |||
271 | break; | ||
272 | } | ||
273 | case "integer": | ||
274 | { | ||
275 | if (reader.IsEmptyElement) | ||
276 | { | ||
277 | reader.Read(); | ||
278 | return 0; | ||
279 | } | ||
280 | |||
281 | reader.Read(); | ||
282 | ret = Convert.ToInt32(reader.ReadString().Trim()); | ||
283 | break; | ||
284 | } | ||
285 | case "real": | ||
286 | { | ||
287 | if (reader.IsEmptyElement) | ||
288 | { | ||
289 | reader.Read(); | ||
290 | return 0.0f; | ||
291 | } | ||
292 | |||
293 | reader.Read(); | ||
294 | ret = Convert.ToDouble(reader.ReadString().Trim()); | ||
295 | break; | ||
296 | } | ||
297 | case "uuid": | ||
298 | { | ||
299 | if (reader.IsEmptyElement) | ||
300 | { | ||
301 | reader.Read(); | ||
302 | return UUID.Zero; | ||
303 | } | ||
304 | |||
305 | reader.Read(); | ||
306 | ret = new UUID(reader.ReadString().Trim()); | ||
307 | break; | ||
308 | } | ||
309 | case "string": | ||
310 | { | ||
311 | if (reader.IsEmptyElement) | ||
312 | { | ||
313 | reader.Read(); | ||
314 | return String.Empty; | ||
315 | } | ||
316 | |||
317 | reader.Read(); | ||
318 | ret = reader.ReadString(); | ||
319 | break; | ||
320 | } | ||
321 | case "binary": | ||
322 | { | ||
323 | if (reader.IsEmptyElement) | ||
324 | { | ||
325 | reader.Read(); | ||
326 | return new byte[0]; | ||
327 | } | ||
328 | |||
329 | if (reader.GetAttribute("encoding") != null && | ||
330 | reader.GetAttribute("encoding") != "base64") | ||
331 | { | ||
332 | throw new LLSDParseException("Unknown encoding: " + reader.GetAttribute("encoding")); | ||
333 | } | ||
334 | |||
335 | reader.Read(); | ||
336 | FromBase64Transform b64 = new FromBase64Transform(FromBase64TransformMode.IgnoreWhiteSpaces); | ||
337 | byte[] inp = Util.UTF8.GetBytes(reader.ReadString()); | ||
338 | ret = b64.TransformFinalBlock(inp, 0, inp.Length); | ||
339 | break; | ||
340 | } | ||
341 | case "date": | ||
342 | { | ||
343 | reader.Read(); | ||
344 | throw new Exception("LLSD TODO: date"); | ||
345 | } | ||
346 | case "map": | ||
347 | { | ||
348 | return LLSDParseMap(reader); | ||
349 | } | ||
350 | case "array": | ||
351 | { | ||
352 | return LLSDParseArray(reader); | ||
353 | } | ||
354 | default: | ||
355 | throw new LLSDParseException("Unknown element <" + dtype + ">"); | ||
356 | } | ||
357 | |||
358 | if (reader.NodeType != XmlNodeType.EndElement || reader.LocalName != dtype) | ||
359 | { | ||
360 | throw new LLSDParseException("Expected </" + dtype + ">"); | ||
361 | } | ||
362 | |||
363 | reader.Read(); | ||
364 | return ret; | ||
365 | } | ||
366 | |||
367 | /// <summary> | ||
368 | /// | ||
369 | /// </summary> | ||
370 | /// <param name="reader"></param> | ||
371 | /// <returns></returns> | ||
372 | public static Hashtable LLSDParseMap(XmlTextReader reader) | ||
373 | { | ||
374 | Hashtable ret = new Hashtable(); | ||
375 | |||
376 | if (reader.NodeType != XmlNodeType.Element || reader.LocalName != "map") | ||
377 | throw new LLSDParseException("Expected <map>"); | ||
378 | |||
379 | if (reader.IsEmptyElement) | ||
380 | { | ||
381 | reader.Read(); | ||
382 | return ret; | ||
383 | } | ||
384 | |||
385 | reader.Read(); | ||
386 | |||
387 | while (true) | ||
388 | { | ||
389 | SkipWS(reader); | ||
390 | if (reader.NodeType == XmlNodeType.EndElement && reader.LocalName == "map") | ||
391 | { | ||
392 | reader.Read(); | ||
393 | break; | ||
394 | } | ||
395 | |||
396 | if (reader.NodeType != XmlNodeType.Element || reader.LocalName != "key") | ||
397 | throw new LLSDParseException("Expected <key>"); | ||
398 | |||
399 | string key = reader.ReadString(); | ||
400 | |||
401 | if (reader.NodeType != XmlNodeType.EndElement || reader.LocalName != "key") | ||
402 | throw new LLSDParseException("Expected </key>"); | ||
403 | |||
404 | reader.Read(); | ||
405 | object val = LLSDParseOne(reader); | ||
406 | ret[key] = val; | ||
407 | } | ||
408 | |||
409 | return ret; // TODO | ||
410 | } | ||
411 | |||
412 | /// <summary> | ||
413 | /// | ||
414 | /// </summary> | ||
415 | /// <param name="reader"></param> | ||
416 | /// <returns></returns> | ||
417 | public static ArrayList LLSDParseArray(XmlTextReader reader) | ||
418 | { | ||
419 | ArrayList ret = new ArrayList(); | ||
420 | |||
421 | if (reader.NodeType != XmlNodeType.Element || reader.LocalName != "array") | ||
422 | throw new LLSDParseException("Expected <array>"); | ||
423 | |||
424 | if (reader.IsEmptyElement) | ||
425 | { | ||
426 | reader.Read(); | ||
427 | return ret; | ||
428 | } | ||
429 | |||
430 | reader.Read(); | ||
431 | |||
432 | while (true) | ||
433 | { | ||
434 | SkipWS(reader); | ||
435 | |||
436 | if (reader.NodeType == XmlNodeType.EndElement && reader.LocalName == "array") | ||
437 | { | ||
438 | reader.Read(); | ||
439 | break; | ||
440 | } | ||
441 | |||
442 | ret.Insert(ret.Count, LLSDParseOne(reader)); | ||
443 | } | ||
444 | |||
445 | return ret; // TODO | ||
446 | } | ||
447 | |||
448 | /// <summary> | ||
449 | /// | ||
450 | /// </summary> | ||
451 | /// <param name="count"></param> | ||
452 | /// <returns></returns> | ||
453 | private static string GetSpaces(int count) | ||
454 | { | ||
455 | StringBuilder b = new StringBuilder(); | ||
456 | for (int i = 0; i < count; i++) b.Append(" "); | ||
457 | return b.ToString(); | ||
458 | } | ||
459 | |||
460 | /// <summary> | ||
461 | /// | ||
462 | /// </summary> | ||
463 | /// <param name="obj"></param> | ||
464 | /// <param name="indent"></param> | ||
465 | /// <returns></returns> | ||
466 | public static String LLSDDump(object obj, int indent) | ||
467 | { | ||
468 | if (obj == null) | ||
469 | { | ||
470 | return GetSpaces(indent) + "- undef\n"; | ||
471 | } | ||
472 | else if (obj is string) | ||
473 | { | ||
474 | return GetSpaces(indent) + "- string \"" + (string) obj + "\"\n"; | ||
475 | } | ||
476 | else if (obj is int) | ||
477 | { | ||
478 | return GetSpaces(indent) + "- integer " + obj.ToString() + "\n"; | ||
479 | } | ||
480 | else if (obj is double) | ||
481 | { | ||
482 | return GetSpaces(indent) + "- float " + obj.ToString() + "\n"; | ||
483 | } | ||
484 | else if (obj is UUID) | ||
485 | { | ||
486 | return GetSpaces(indent) + "- uuid " + ((UUID) obj).ToString() + Environment.NewLine; | ||
487 | } | ||
488 | else if (obj is Hashtable) | ||
489 | { | ||
490 | StringBuilder ret = new StringBuilder(); | ||
491 | ret.Append(GetSpaces(indent) + "- map" + Environment.NewLine); | ||
492 | Hashtable map = (Hashtable) obj; | ||
493 | |||
494 | foreach (string key in map.Keys) | ||
495 | { | ||
496 | ret.Append(GetSpaces(indent + 2) + "- key \"" + key + "\"" + Environment.NewLine); | ||
497 | ret.Append(LLSDDump(map[key], indent + 3)); | ||
498 | } | ||
499 | |||
500 | return ret.ToString(); | ||
501 | } | ||
502 | else if (obj is ArrayList) | ||
503 | { | ||
504 | StringBuilder ret = new StringBuilder(); | ||
505 | ret.Append(GetSpaces(indent) + "- array\n"); | ||
506 | ArrayList list = (ArrayList) obj; | ||
507 | |||
508 | foreach (object item in list) | ||
509 | { | ||
510 | ret.Append(LLSDDump(item, indent + 2)); | ||
511 | } | ||
512 | |||
513 | return ret.ToString(); | ||
514 | } | ||
515 | else if (obj is byte[]) | ||
516 | { | ||
517 | return GetSpaces(indent) + "- binary\n" + Utils.BytesToHexString((byte[]) obj, GetSpaces(indent)) + | ||
518 | Environment.NewLine; | ||
519 | } | ||
520 | else | ||
521 | { | ||
522 | return GetSpaces(indent) + "- unknown type " + obj.GetType().Name + Environment.NewLine; | ||
523 | } | ||
524 | } | ||
525 | |||
526 | public static object ParseTerseLLSD(string llsd) | ||
527 | { | ||
528 | int notused; | ||
529 | return ParseTerseLLSD(llsd, out notused); | ||
530 | } | ||
531 | |||
532 | public static object ParseTerseLLSD(string llsd, out int endPos) | ||
533 | { | ||
534 | if (llsd.Length == 0) | ||
535 | { | ||
536 | endPos = 0; | ||
537 | return null; | ||
538 | } | ||
539 | |||
540 | // Identify what type of object this is | ||
541 | switch (llsd[0]) | ||
542 | { | ||
543 | case '!': | ||
544 | throw new LLSDParseException("Undefined value type encountered"); | ||
545 | case '1': | ||
546 | endPos = 1; | ||
547 | return true; | ||
548 | case '0': | ||
549 | endPos = 1; | ||
550 | return false; | ||
551 | case 'i': | ||
552 | { | ||
553 | if (llsd.Length < 2) throw new LLSDParseException("Integer value type with no value"); | ||
554 | int value; | ||
555 | endPos = FindEnd(llsd, 1); | ||
556 | |||
557 | if (Int32.TryParse(llsd.Substring(1, endPos - 1), out value)) | ||
558 | return value; | ||
559 | else | ||
560 | throw new LLSDParseException("Failed to parse integer value type"); | ||
561 | } | ||
562 | case 'r': | ||
563 | { | ||
564 | if (llsd.Length < 2) throw new LLSDParseException("Real value type with no value"); | ||
565 | double value; | ||
566 | endPos = FindEnd(llsd, 1); | ||
567 | |||
568 | if (Double.TryParse(llsd.Substring(1, endPos - 1), NumberStyles.Float, | ||
569 | Utils.EnUsCulture.NumberFormat, out value)) | ||
570 | return value; | ||
571 | else | ||
572 | throw new LLSDParseException("Failed to parse double value type"); | ||
573 | } | ||
574 | case 'u': | ||
575 | { | ||
576 | if (llsd.Length < 17) throw new LLSDParseException("UUID value type with no value"); | ||
577 | UUID value; | ||
578 | endPos = FindEnd(llsd, 1); | ||
579 | |||
580 | if (UUID.TryParse(llsd.Substring(1, endPos - 1), out value)) | ||
581 | return value; | ||
582 | else | ||
583 | throw new LLSDParseException("Failed to parse UUID value type"); | ||
584 | } | ||
585 | case 'b': | ||
586 | //byte[] value = new byte[llsd.Length - 1]; | ||
587 | // This isn't the actual binary LLSD format, just the terse format sent | ||
588 | // at login so I don't even know if there is a binary type | ||
589 | throw new LLSDParseException("Binary value type is unimplemented"); | ||
590 | case 's': | ||
591 | case 'l': | ||
592 | if (llsd.Length < 2) throw new LLSDParseException("String value type with no value"); | ||
593 | endPos = FindEnd(llsd, 1); | ||
594 | return llsd.Substring(1, endPos - 1); | ||
595 | case 'd': | ||
596 | // Never seen one before, don't know what the format is | ||
597 | throw new LLSDParseException("Date value type is unimplemented"); | ||
598 | case '[': | ||
599 | { | ||
600 | if (llsd.IndexOf(']') == -1) throw new LLSDParseException("Invalid array"); | ||
601 | |||
602 | int pos = 0; | ||
603 | ArrayList array = new ArrayList(); | ||
604 | |||
605 | while (llsd[pos] != ']') | ||
606 | { | ||
607 | ++pos; | ||
608 | |||
609 | // Advance past comma if need be | ||
610 | if (llsd[pos] == ',') ++pos; | ||
611 | |||
612 | // Allow a single whitespace character | ||
613 | if (pos < llsd.Length && llsd[pos] == ' ') ++pos; | ||
614 | |||
615 | int end; | ||
616 | array.Add(ParseTerseLLSD(llsd.Substring(pos), out end)); | ||
617 | pos += end; | ||
618 | } | ||
619 | |||
620 | endPos = pos + 1; | ||
621 | return array; | ||
622 | } | ||
623 | case '{': | ||
624 | { | ||
625 | if (llsd.IndexOf('}') == -1) throw new LLSDParseException("Invalid map"); | ||
626 | |||
627 | int pos = 0; | ||
628 | Hashtable hashtable = new Hashtable(); | ||
629 | |||
630 | while (llsd[pos] != '}') | ||
631 | { | ||
632 | ++pos; | ||
633 | |||
634 | // Advance past comma if need be | ||
635 | if (llsd[pos] == ',') ++pos; | ||
636 | |||
637 | // Allow a single whitespace character | ||
638 | if (pos < llsd.Length && llsd[pos] == ' ') ++pos; | ||
639 | |||
640 | if (llsd[pos] != '\'') throw new LLSDParseException("Expected a map key"); | ||
641 | int endquote = llsd.IndexOf('\'', pos + 1); | ||
642 | if (endquote == -1 || (endquote + 1) >= llsd.Length || llsd[endquote + 1] != ':') | ||
643 | throw new LLSDParseException("Invalid map format"); | ||
644 | string key = llsd.Substring(pos, endquote - pos); | ||
645 | key = key.Replace("'", String.Empty); | ||
646 | pos += (endquote - pos) + 2; | ||
647 | |||
648 | int end; | ||
649 | hashtable.Add(key, ParseTerseLLSD(llsd.Substring(pos), out end)); | ||
650 | pos += end; | ||
651 | } | ||
652 | |||
653 | endPos = pos + 1; | ||
654 | return hashtable; | ||
655 | } | ||
656 | default: | ||
657 | throw new Exception("Unknown value type"); | ||
658 | } | ||
659 | } | ||
660 | |||
661 | private static int FindEnd(string llsd, int start) | ||
662 | { | ||
663 | int end = llsd.IndexOfAny(new char[] {',', ']', '}'}); | ||
664 | if (end == -1) end = llsd.Length - 1; | ||
665 | return end; | ||
666 | } | ||
667 | |||
668 | /// <summary> | ||
669 | /// | ||
670 | /// </summary> | ||
671 | /// <param name="reader"></param> | ||
672 | private static void SkipWS(XmlTextReader reader) | ||
673 | { | ||
674 | while ( | ||
675 | reader.NodeType == XmlNodeType.Comment || | ||
676 | reader.NodeType == XmlNodeType.Whitespace || | ||
677 | reader.NodeType == XmlNodeType.SignificantWhitespace || | ||
678 | reader.NodeType == XmlNodeType.XmlDeclaration) | ||
679 | { | ||
680 | reader.Read(); | ||
681 | } | ||
682 | } | ||
683 | } | ||
684 | } | ||
diff --git a/OpenSim/Capabilities/LLSDArray.cs b/OpenSim/Capabilities/LLSDArray.cs new file mode 100644 index 0000000..3459e49 --- /dev/null +++ b/OpenSim/Capabilities/LLSDArray.cs | |||
@@ -0,0 +1,41 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.Collections; | ||
29 | |||
30 | namespace OpenSim.Framework.Capabilities | ||
31 | { | ||
32 | [LLSDType("ARRAY")] | ||
33 | public class OSDArray | ||
34 | { | ||
35 | public ArrayList Array = new ArrayList(); | ||
36 | |||
37 | public OSDArray() | ||
38 | { | ||
39 | } | ||
40 | } | ||
41 | } \ No newline at end of file | ||
diff --git a/OpenSim/Capabilities/LLSDAssetUploadComplete.cs b/OpenSim/Capabilities/LLSDAssetUploadComplete.cs new file mode 100644 index 0000000..ab6cee5 --- /dev/null +++ b/OpenSim/Capabilities/LLSDAssetUploadComplete.cs | |||
@@ -0,0 +1,45 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using OpenMetaverse; | ||
30 | |||
31 | namespace OpenSim.Framework.Capabilities | ||
32 | { | ||
33 | [LLSDType("MAP")] | ||
34 | public class LLSDAssetUploadComplete | ||
35 | { | ||
36 | public string new_asset = String.Empty; | ||
37 | public UUID new_inventory_item = UUID.Zero; | ||
38 | public string state = String.Empty; | ||
39 | //public bool success = false; | ||
40 | |||
41 | public LLSDAssetUploadComplete() | ||
42 | { | ||
43 | } | ||
44 | } | ||
45 | } | ||
diff --git a/OpenSim/Capabilities/LLSDAssetUploadRequest.cs b/OpenSim/Capabilities/LLSDAssetUploadRequest.cs new file mode 100644 index 0000000..6e66f0a --- /dev/null +++ b/OpenSim/Capabilities/LLSDAssetUploadRequest.cs | |||
@@ -0,0 +1,46 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using OpenMetaverse; | ||
30 | |||
31 | namespace OpenSim.Framework.Capabilities | ||
32 | { | ||
33 | [OSDMap] | ||
34 | public class LLSDAssetUploadRequest | ||
35 | { | ||
36 | public string asset_type = String.Empty; | ||
37 | public string description = String.Empty; | ||
38 | public UUID folder_id = UUID.Zero; | ||
39 | public string inventory_type = String.Empty; | ||
40 | public string name = String.Empty; | ||
41 | |||
42 | public LLSDAssetUploadRequest() | ||
43 | { | ||
44 | } | ||
45 | } | ||
46 | } | ||
diff --git a/OpenSim/Capabilities/LLSDAssetUploadResponse.cs b/OpenSim/Capabilities/LLSDAssetUploadResponse.cs new file mode 100644 index 0000000..0d6f7f9 --- /dev/null +++ b/OpenSim/Capabilities/LLSDAssetUploadResponse.cs | |||
@@ -0,0 +1,56 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | |||
30 | namespace OpenSim.Framework.Capabilities | ||
31 | { | ||
32 | [OSDMap] | ||
33 | public class LLSDAssetUploadResponse | ||
34 | { | ||
35 | public string uploader = String.Empty; | ||
36 | public string state = String.Empty; | ||
37 | |||
38 | public LLSDAssetUploadResponse() | ||
39 | { | ||
40 | } | ||
41 | } | ||
42 | |||
43 | [OSDMap] | ||
44 | public class LLSDNewFileAngentInventoryVariablePriceReplyResponse | ||
45 | { | ||
46 | public int resource_cost; | ||
47 | public string state; | ||
48 | public int upload_price; | ||
49 | public string rsvp; | ||
50 | |||
51 | public LLSDNewFileAngentInventoryVariablePriceReplyResponse() | ||
52 | { | ||
53 | state = "confirm_upload"; | ||
54 | } | ||
55 | } | ||
56 | } \ No newline at end of file | ||
diff --git a/OpenSim/Capabilities/LLSDAvatarPicker.cs b/OpenSim/Capabilities/LLSDAvatarPicker.cs new file mode 100644 index 0000000..d0b3f3a --- /dev/null +++ b/OpenSim/Capabilities/LLSDAvatarPicker.cs | |||
@@ -0,0 +1,51 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using OpenMetaverse; | ||
29 | |||
30 | namespace OpenSim.Framework.Capabilities | ||
31 | { | ||
32 | [OSDMap] | ||
33 | public class LLSDAvatarPicker | ||
34 | { | ||
35 | public string next_page_url; | ||
36 | // an array of LLSDPerson | ||
37 | public OSDArray agents = new OSDArray(); | ||
38 | } | ||
39 | |||
40 | [OSDMap] | ||
41 | public class LLSDPerson | ||
42 | { | ||
43 | public string username; | ||
44 | public string display_name; | ||
45 | //'display_name_next_update':d"1970-01-01T00:00:00Z" | ||
46 | public string legacy_first_name; | ||
47 | public string legacy_last_name; | ||
48 | public UUID id; | ||
49 | public bool is_display_name_default; | ||
50 | } | ||
51 | } \ No newline at end of file | ||
diff --git a/OpenSim/Capabilities/LLSDCapEvent.cs b/OpenSim/Capabilities/LLSDCapEvent.cs new file mode 100644 index 0000000..63abd62 --- /dev/null +++ b/OpenSim/Capabilities/LLSDCapEvent.cs | |||
@@ -0,0 +1,40 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | namespace OpenSim.Framework.Capabilities | ||
29 | { | ||
30 | [LLSDType("MAP")] | ||
31 | public class LLSDCapEvent | ||
32 | { | ||
33 | public int id = 0; | ||
34 | public OSDArray events = new OSDArray(); | ||
35 | |||
36 | public LLSDCapEvent() | ||
37 | { | ||
38 | } | ||
39 | } | ||
40 | } \ No newline at end of file | ||
diff --git a/OpenSim/Capabilities/LLSDEmpty.cs b/OpenSim/Capabilities/LLSDEmpty.cs new file mode 100644 index 0000000..f94fcba --- /dev/null +++ b/OpenSim/Capabilities/LLSDEmpty.cs | |||
@@ -0,0 +1,37 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | namespace OpenSim.Framework.Capabilities | ||
29 | { | ||
30 | [LLSDType("MAP")] | ||
31 | public class LLSDEmpty | ||
32 | { | ||
33 | public LLSDEmpty() | ||
34 | { | ||
35 | } | ||
36 | } | ||
37 | } \ No newline at end of file | ||
diff --git a/OpenSim/Capabilities/LLSDEnvironmentSettings.cs b/OpenSim/Capabilities/LLSDEnvironmentSettings.cs new file mode 100644 index 0000000..39019af --- /dev/null +++ b/OpenSim/Capabilities/LLSDEnvironmentSettings.cs | |||
@@ -0,0 +1,68 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using OpenMetaverse; | ||
31 | |||
32 | namespace OpenSim.Framework.Capabilities | ||
33 | { | ||
34 | [OSDMap] | ||
35 | public class LLSDEnvironmentRequest | ||
36 | { | ||
37 | public UUID messageID; | ||
38 | public UUID regionID; | ||
39 | } | ||
40 | |||
41 | [OSDMap] | ||
42 | public class LLSDEnvironmentSetResponse | ||
43 | { | ||
44 | public UUID regionID; | ||
45 | public UUID messageID; | ||
46 | public Boolean success; | ||
47 | public String fail_reason; | ||
48 | } | ||
49 | |||
50 | public class EnvironmentSettings | ||
51 | { | ||
52 | /// <summary> | ||
53 | /// generates a empty llsd settings response for viewer | ||
54 | /// </summary> | ||
55 | /// <param name="messageID">the message UUID</param> | ||
56 | /// <param name="regionID">the region UUID</param> | ||
57 | public static string EmptySettings(UUID messageID, UUID regionID) | ||
58 | { | ||
59 | OSDArray arr = new OSDArray(); | ||
60 | LLSDEnvironmentRequest msg = new LLSDEnvironmentRequest(); | ||
61 | msg.messageID = messageID; | ||
62 | msg.regionID = regionID; | ||
63 | arr.Array.Add(msg); | ||
64 | return LLSDHelpers.SerialiseLLSDReply(arr); | ||
65 | } | ||
66 | } | ||
67 | |||
68 | } | ||
diff --git a/OpenSim/Capabilities/LLSDHelpers.cs b/OpenSim/Capabilities/LLSDHelpers.cs new file mode 100644 index 0000000..8f1a40e --- /dev/null +++ b/OpenSim/Capabilities/LLSDHelpers.cs | |||
@@ -0,0 +1,172 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections; | ||
30 | using System.IO; | ||
31 | using System.Reflection; | ||
32 | using System.Xml; | ||
33 | |||
34 | namespace OpenSim.Framework.Capabilities | ||
35 | { | ||
36 | public class LLSDHelpers | ||
37 | { | ||
38 | // private static readonly log4net.ILog m_log | ||
39 | // = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||
40 | |||
41 | public static string SerialiseLLSDReply(object obj) | ||
42 | { | ||
43 | StringWriter sw = new StringWriter(); | ||
44 | XmlTextWriter writer = new XmlTextWriter(sw); | ||
45 | writer.Formatting = Formatting.None; | ||
46 | writer.WriteStartElement(String.Empty, "llsd", String.Empty); | ||
47 | SerializeOSDType(writer, obj); | ||
48 | writer.WriteEndElement(); | ||
49 | writer.Close(); | ||
50 | |||
51 | //m_log.DebugFormat("[LLSD Helpers]: Generated serialized LLSD reply {0}", sw.ToString()); | ||
52 | |||
53 | return sw.ToString(); | ||
54 | } | ||
55 | |||
56 | private static void SerializeOSDType(XmlTextWriter writer, object obj) | ||
57 | { | ||
58 | Type myType = obj.GetType(); | ||
59 | LLSDType[] llsdattributes = (LLSDType[]) myType.GetCustomAttributes(typeof (LLSDType), false); | ||
60 | if (llsdattributes.Length > 0) | ||
61 | { | ||
62 | switch (llsdattributes[0].ObjectType) | ||
63 | { | ||
64 | case "MAP": | ||
65 | writer.WriteStartElement(String.Empty, "map", String.Empty); | ||
66 | FieldInfo[] fields = myType.GetFields(); | ||
67 | for (int i = 0; i < fields.Length; i++) | ||
68 | { | ||
69 | if (fields[i] != null && fields[i].GetValue(obj) != null) | ||
70 | { | ||
71 | object fieldValue = fields[i].GetValue(obj); | ||
72 | LLSDType[] fieldAttributes = | ||
73 | (LLSDType[]) fieldValue.GetType().GetCustomAttributes(typeof (LLSDType), false); | ||
74 | if (fieldAttributes.Length > 0) | ||
75 | { | ||
76 | writer.WriteStartElement(String.Empty, "key", String.Empty); | ||
77 | string fieldName = fields[i].Name; | ||
78 | fieldName = fieldName.Replace("___", "-"); | ||
79 | writer.WriteString(fieldName); | ||
80 | writer.WriteEndElement(); | ||
81 | SerializeOSDType(writer, fieldValue); | ||
82 | } | ||
83 | else | ||
84 | { | ||
85 | writer.WriteStartElement(String.Empty, "key", String.Empty); | ||
86 | string fieldName = fields[i].Name; | ||
87 | fieldName = fieldName.Replace("___", "-"); | ||
88 | writer.WriteString(fieldName); | ||
89 | writer.WriteEndElement(); | ||
90 | LLSD.LLSDWriteOne(writer, fieldValue); | ||
91 | // OpenMetaverse.StructuredData.LLSDParser.SerializeXmlElement( | ||
92 | // writer, OpenMetaverse.StructuredData.OSD.FromObject(fieldValue)); | ||
93 | } | ||
94 | } | ||
95 | else | ||
96 | { | ||
97 | // TODO from ADAM: There is a nullref being caused by fields[i] being null | ||
98 | // on some computers. Unsure what is causing this, but would appreciate | ||
99 | // if sdague could take a look at this. | ||
100 | } | ||
101 | } | ||
102 | writer.WriteEndElement(); | ||
103 | break; | ||
104 | case "ARRAY": | ||
105 | // OSDArray arrayObject = obj as OSDArray; | ||
106 | // ArrayList a = arrayObject.Array; | ||
107 | ArrayList a = (ArrayList) obj.GetType().GetField("Array").GetValue(obj); | ||
108 | if (a != null) | ||
109 | { | ||
110 | writer.WriteStartElement(String.Empty, "array", String.Empty); | ||
111 | foreach (object item in a) | ||
112 | { | ||
113 | SerializeOSDType(writer, item); | ||
114 | } | ||
115 | writer.WriteEndElement(); | ||
116 | } | ||
117 | break; | ||
118 | } | ||
119 | } | ||
120 | else | ||
121 | { | ||
122 | LLSD.LLSDWriteOne(writer, obj); | ||
123 | //OpenMetaverse.StructuredData.LLSDParser.SerializeXmlElement( | ||
124 | // writer, OpenMetaverse.StructuredData.OSD.FromObject(obj)); | ||
125 | } | ||
126 | } | ||
127 | |||
128 | public static object DeserialiseOSDMap(Hashtable llsd, object obj) | ||
129 | { | ||
130 | Type myType = obj.GetType(); | ||
131 | LLSDType[] llsdattributes = (LLSDType[]) myType.GetCustomAttributes(typeof (LLSDType), false); | ||
132 | if (llsdattributes.Length > 0) | ||
133 | { | ||
134 | switch (llsdattributes[0].ObjectType) | ||
135 | { | ||
136 | case "MAP": | ||
137 | IDictionaryEnumerator enumerator = llsd.GetEnumerator(); | ||
138 | while (enumerator.MoveNext()) | ||
139 | { | ||
140 | string keyName = (string)enumerator.Key; | ||
141 | keyName = keyName.Replace("-","_"); | ||
142 | FieldInfo field = myType.GetField(keyName); | ||
143 | if (field != null) | ||
144 | { | ||
145 | // if (enumerator.Value is OpenMetaverse.StructuredData.OSDMap) | ||
146 | if (enumerator.Value is Hashtable) | ||
147 | { | ||
148 | object fieldValue = field.GetValue(obj); | ||
149 | DeserialiseOSDMap((Hashtable) enumerator.Value, fieldValue); | ||
150 | // DeserialiseOSDMap((OpenMetaverse.StructuredData.OSDMap) enumerator.Value, fieldValue); | ||
151 | } | ||
152 | else if (enumerator.Value is ArrayList) | ||
153 | { | ||
154 | object fieldValue = field.GetValue(obj); | ||
155 | fieldValue.GetType().GetField("Array").SetValue(fieldValue, enumerator.Value); | ||
156 | //TODO | ||
157 | // the LLSD map/array types in the array need to be deserialised | ||
158 | // but first we need to know the right class to deserialise them into. | ||
159 | } | ||
160 | else | ||
161 | { | ||
162 | field.SetValue(obj, enumerator.Value); | ||
163 | } | ||
164 | } | ||
165 | } | ||
166 | break; | ||
167 | } | ||
168 | } | ||
169 | return obj; | ||
170 | } | ||
171 | } | ||
172 | } | ||
diff --git a/OpenSim/Capabilities/LLSDInventoryFolder.cs b/OpenSim/Capabilities/LLSDInventoryFolder.cs new file mode 100644 index 0000000..d085430 --- /dev/null +++ b/OpenSim/Capabilities/LLSDInventoryFolder.cs | |||
@@ -0,0 +1,41 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using OpenMetaverse; | ||
29 | |||
30 | namespace OpenSim.Framework.Capabilities | ||
31 | { | ||
32 | [OSDMap] | ||
33 | public class LLSDInventoryFolder | ||
34 | { | ||
35 | public UUID folder_id; | ||
36 | public UUID parent_id; | ||
37 | public string name; | ||
38 | public int type; | ||
39 | public int preferred_type; | ||
40 | } | ||
41 | } | ||
diff --git a/OpenSim/Capabilities/LLSDInventoryItem.cs b/OpenSim/Capabilities/LLSDInventoryItem.cs new file mode 100644 index 0000000..958e807 --- /dev/null +++ b/OpenSim/Capabilities/LLSDInventoryItem.cs | |||
@@ -0,0 +1,105 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using OpenMetaverse; | ||
29 | |||
30 | namespace OpenSim.Framework.Capabilities | ||
31 | { | ||
32 | [OSDMap] | ||
33 | public class LLSDInventoryItem | ||
34 | { | ||
35 | public UUID parent_id; | ||
36 | |||
37 | public UUID asset_id; | ||
38 | public UUID item_id; | ||
39 | public LLSDPermissions permissions; | ||
40 | public int type; | ||
41 | public int inv_type; | ||
42 | public int flags; | ||
43 | |||
44 | public LLSDSaleInfo sale_info; | ||
45 | public string name; | ||
46 | public string desc; | ||
47 | public int created_at; | ||
48 | } | ||
49 | |||
50 | [OSDMap] | ||
51 | public class LLSDPermissions | ||
52 | { | ||
53 | public UUID creator_id; | ||
54 | public UUID owner_id; | ||
55 | public UUID group_id; | ||
56 | public int base_mask; | ||
57 | public int owner_mask; | ||
58 | public int group_mask; | ||
59 | public int everyone_mask; | ||
60 | public int next_owner_mask; | ||
61 | public bool is_owner_group; | ||
62 | } | ||
63 | |||
64 | [OSDMap] | ||
65 | public class LLSDSaleInfo | ||
66 | { | ||
67 | public int sale_price; | ||
68 | public int sale_type; | ||
69 | } | ||
70 | |||
71 | [OSDMap] | ||
72 | public class LLSDInventoryDescendents | ||
73 | { | ||
74 | public OSDArray folders = new OSDArray(); | ||
75 | } | ||
76 | |||
77 | [OSDMap] | ||
78 | public class LLSDFetchInventoryDescendents | ||
79 | { | ||
80 | public UUID folder_id; | ||
81 | public UUID owner_id; | ||
82 | public int sort_order; | ||
83 | public bool fetch_folders; | ||
84 | public bool fetch_items; | ||
85 | } | ||
86 | |||
87 | [OSDMap] | ||
88 | public class LLSDInventoryFolderContents | ||
89 | { | ||
90 | public UUID agent_id; | ||
91 | public int descendents; | ||
92 | public UUID folder_id; | ||
93 | public OSDArray categories = new OSDArray(); | ||
94 | public OSDArray items = new OSDArray(); | ||
95 | public UUID owner_id; | ||
96 | public int version; | ||
97 | } | ||
98 | |||
99 | [OSDMap] | ||
100 | public class LLSDFetchInventory | ||
101 | { | ||
102 | public UUID agent_id; | ||
103 | public OSDArray items = new OSDArray(); | ||
104 | } | ||
105 | } \ No newline at end of file | ||
diff --git a/OpenSim/Capabilities/LLSDItemUpdate.cs b/OpenSim/Capabilities/LLSDItemUpdate.cs new file mode 100644 index 0000000..96e2b61 --- /dev/null +++ b/OpenSim/Capabilities/LLSDItemUpdate.cs | |||
@@ -0,0 +1,41 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using OpenMetaverse; | ||
29 | |||
30 | namespace OpenSim.Framework.Capabilities | ||
31 | { | ||
32 | [OSDMap] | ||
33 | public class LLSDItemUpdate | ||
34 | { | ||
35 | public UUID item_id; | ||
36 | |||
37 | public LLSDItemUpdate() | ||
38 | { | ||
39 | } | ||
40 | } | ||
41 | } | ||
diff --git a/OpenSim/Capabilities/LLSDMapLayer.cs b/OpenSim/Capabilities/LLSDMapLayer.cs new file mode 100644 index 0000000..4aeb1ff --- /dev/null +++ b/OpenSim/Capabilities/LLSDMapLayer.cs | |||
@@ -0,0 +1,45 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using OpenMetaverse; | ||
29 | |||
30 | namespace OpenSim.Framework.Capabilities | ||
31 | { | ||
32 | [LLSDType("MAP")] | ||
33 | public class OSDMapLayer | ||
34 | { | ||
35 | public int Left = 0; | ||
36 | public int Right = 0; | ||
37 | public int Top = 0; | ||
38 | public int Bottom = 0; | ||
39 | public UUID ImageID = UUID.Zero; | ||
40 | |||
41 | public OSDMapLayer() | ||
42 | { | ||
43 | } | ||
44 | } | ||
45 | } | ||
diff --git a/OpenSim/Capabilities/LLSDMapLayerResponse.cs b/OpenSim/Capabilities/LLSDMapLayerResponse.cs new file mode 100644 index 0000000..839e34c --- /dev/null +++ b/OpenSim/Capabilities/LLSDMapLayerResponse.cs | |||
@@ -0,0 +1,40 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | namespace OpenSim.Framework.Capabilities | ||
29 | { | ||
30 | [LLSDType("MAP")] | ||
31 | public class LLSDMapLayerResponse | ||
32 | { | ||
33 | public LLSDMapRequest AgentData = new LLSDMapRequest(); | ||
34 | public OSDArray LayerData = new OSDArray(); | ||
35 | |||
36 | public LLSDMapLayerResponse() | ||
37 | { | ||
38 | } | ||
39 | } | ||
40 | } \ No newline at end of file | ||
diff --git a/OpenSim/Capabilities/LLSDMapRequest.cs b/OpenSim/Capabilities/LLSDMapRequest.cs new file mode 100644 index 0000000..debf387 --- /dev/null +++ b/OpenSim/Capabilities/LLSDMapRequest.cs | |||
@@ -0,0 +1,39 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | namespace OpenSim.Framework.Capabilities | ||
29 | { | ||
30 | [LLSDType("MAP")] | ||
31 | public class LLSDMapRequest | ||
32 | { | ||
33 | public int Flags = 0; | ||
34 | |||
35 | public LLSDMapRequest() | ||
36 | { | ||
37 | } | ||
38 | } | ||
39 | } \ No newline at end of file | ||
diff --git a/OpenSim/Capabilities/LLSDMethod.cs b/OpenSim/Capabilities/LLSDMethod.cs new file mode 100644 index 0000000..cd2574d --- /dev/null +++ b/OpenSim/Capabilities/LLSDMethod.cs | |||
@@ -0,0 +1,31 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | namespace OpenSim.Framework.Capabilities | ||
29 | { | ||
30 | public delegate TResponse LLSDMethod<TRequest, TResponse>(TRequest request); | ||
31 | } \ No newline at end of file | ||
diff --git a/OpenSim/Capabilities/LLSDMethodString.cs b/OpenSim/Capabilities/LLSDMethodString.cs new file mode 100644 index 0000000..38700d5 --- /dev/null +++ b/OpenSim/Capabilities/LLSDMethodString.cs | |||
@@ -0,0 +1,31 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | namespace OpenSim.Framework.Capabilities | ||
29 | { | ||
30 | public delegate TResponse LLSDMethodString<TRequest, TResponse>(TRequest request, string path); | ||
31 | } | ||
diff --git a/OpenSim/Capabilities/LLSDParcelVoiceInfoResponse.cs b/OpenSim/Capabilities/LLSDParcelVoiceInfoResponse.cs new file mode 100644 index 0000000..b34a668 --- /dev/null +++ b/OpenSim/Capabilities/LLSDParcelVoiceInfoResponse.cs | |||
@@ -0,0 +1,51 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | |||
29 | using System.Collections; | ||
30 | |||
31 | namespace OpenSim.Framework.Capabilities | ||
32 | { | ||
33 | [OSDMap] | ||
34 | public class LLSDParcelVoiceInfoResponse | ||
35 | { | ||
36 | public int parcel_local_id; | ||
37 | public string region_name; | ||
38 | public Hashtable voice_credentials; | ||
39 | |||
40 | public LLSDParcelVoiceInfoResponse() | ||
41 | { | ||
42 | } | ||
43 | |||
44 | public LLSDParcelVoiceInfoResponse(string region, int localID, Hashtable creds) | ||
45 | { | ||
46 | region_name = region; | ||
47 | parcel_local_id = localID; | ||
48 | voice_credentials = creds; | ||
49 | } | ||
50 | } | ||
51 | } \ No newline at end of file | ||
diff --git a/OpenSim/Capabilities/LLSDRemoteParcelResponse.cs b/OpenSim/Capabilities/LLSDRemoteParcelResponse.cs new file mode 100644 index 0000000..13d69d3 --- /dev/null +++ b/OpenSim/Capabilities/LLSDRemoteParcelResponse.cs | |||
@@ -0,0 +1,42 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | |||
29 | using OpenMetaverse; | ||
30 | |||
31 | namespace OpenSim.Framework.Capabilities | ||
32 | { | ||
33 | [LLSDType("MAP")] | ||
34 | public class LLSDRemoteParcelResponse | ||
35 | { | ||
36 | public UUID parcel_id; | ||
37 | |||
38 | public LLSDRemoteParcelResponse() | ||
39 | { | ||
40 | } | ||
41 | } | ||
42 | } | ||
diff --git a/OpenSim/Capabilities/LLSDStreamHandler.cs b/OpenSim/Capabilities/LLSDStreamHandler.cs new file mode 100644 index 0000000..4fa1153 --- /dev/null +++ b/OpenSim/Capabilities/LLSDStreamHandler.cs | |||
@@ -0,0 +1,72 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.Collections; | ||
29 | using System.IO; | ||
30 | using System.Text; | ||
31 | using OpenSim.Framework.Servers; | ||
32 | using OpenSim.Framework.Servers.HttpServer; | ||
33 | |||
34 | namespace OpenSim.Framework.Capabilities | ||
35 | { | ||
36 | public class LLSDStreamhandler<TRequest, TResponse> : BaseStreamHandler | ||
37 | where TRequest : new() | ||
38 | { | ||
39 | private LLSDMethod<TRequest, TResponse> m_method; | ||
40 | |||
41 | public LLSDStreamhandler(string httpMethod, string path, LLSDMethod<TRequest, TResponse> method) | ||
42 | : this(httpMethod, path, method, null, null) {} | ||
43 | |||
44 | public LLSDStreamhandler( | ||
45 | string httpMethod, string path, LLSDMethod<TRequest, TResponse> method, string name, string description) | ||
46 | : base(httpMethod, path, name, description) | ||
47 | { | ||
48 | m_method = method; | ||
49 | } | ||
50 | |||
51 | protected override byte[] ProcessRequest(string path, Stream request, | ||
52 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
53 | { | ||
54 | //Encoding encoding = Util.UTF8; | ||
55 | //StreamReader streamReader = new StreamReader(request, false); | ||
56 | |||
57 | //string requestBody = streamReader.ReadToEnd(); | ||
58 | //streamReader.Close(); | ||
59 | |||
60 | // OpenMetaverse.StructuredData.OSDMap hash = (OpenMetaverse.StructuredData.OSDMap) | ||
61 | // OpenMetaverse.StructuredData.LLSDParser.DeserializeXml(new XmlTextReader(request)); | ||
62 | |||
63 | Hashtable hash = (Hashtable) LLSD.LLSDDeserialize(request); | ||
64 | TRequest llsdRequest = new TRequest(); | ||
65 | LLSDHelpers.DeserialiseOSDMap(hash, llsdRequest); | ||
66 | |||
67 | TResponse response = m_method(llsdRequest); | ||
68 | |||
69 | return Util.UTF8NoBomEncoding.GetBytes(LLSDHelpers.SerialiseLLSDReply(response)); | ||
70 | } | ||
71 | } | ||
72 | } | ||
diff --git a/OpenSim/Capabilities/LLSDTaskInventoryUploadComplete.cs b/OpenSim/Capabilities/LLSDTaskInventoryUploadComplete.cs new file mode 100644 index 0000000..47fdaca --- /dev/null +++ b/OpenSim/Capabilities/LLSDTaskInventoryUploadComplete.cs | |||
@@ -0,0 +1,50 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using OpenMetaverse; | ||
29 | |||
30 | namespace OpenSim.Framework.Capabilities | ||
31 | { | ||
32 | [OSDMap] | ||
33 | public class LLSDTaskInventoryUploadComplete | ||
34 | { | ||
35 | /// <summary> | ||
36 | /// The task inventory item that was updated | ||
37 | /// </summary> | ||
38 | public UUID item_id; | ||
39 | |||
40 | /// <summary> | ||
41 | /// The task that was updated | ||
42 | /// </summary> | ||
43 | public UUID task_id; | ||
44 | |||
45 | /// <summary> | ||
46 | /// State of the upload. So far have only even seen this set to "complete" | ||
47 | /// </summary> | ||
48 | public string state; | ||
49 | } | ||
50 | } | ||
diff --git a/OpenSim/Capabilities/LLSDTaskScriptUpdate.cs b/OpenSim/Capabilities/LLSDTaskScriptUpdate.cs new file mode 100644 index 0000000..9d7c17f --- /dev/null +++ b/OpenSim/Capabilities/LLSDTaskScriptUpdate.cs | |||
@@ -0,0 +1,50 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using OpenMetaverse; | ||
29 | |||
30 | namespace OpenSim.Framework.Capabilities | ||
31 | { | ||
32 | [OSDMap] | ||
33 | public class LLSDTaskScriptUpdate | ||
34 | { | ||
35 | /// <summary> | ||
36 | /// The item containing the script to update | ||
37 | /// </summary> | ||
38 | public UUID item_id; | ||
39 | |||
40 | /// <summary> | ||
41 | /// The task containing the script | ||
42 | /// </summary> | ||
43 | public UUID task_id; | ||
44 | |||
45 | /// <summary> | ||
46 | /// Signals whether the script is currently active | ||
47 | /// </summary> | ||
48 | public int is_script_running; | ||
49 | } | ||
50 | } | ||
diff --git a/OpenSim/Capabilities/LLSDTaskScriptUploadComplete.cs b/OpenSim/Capabilities/LLSDTaskScriptUploadComplete.cs new file mode 100644 index 0000000..d308831 --- /dev/null +++ b/OpenSim/Capabilities/LLSDTaskScriptUploadComplete.cs | |||
@@ -0,0 +1,54 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using OpenMetaverse; | ||
29 | using System; | ||
30 | using System.Collections; | ||
31 | |||
32 | namespace OpenSim.Framework.Capabilities | ||
33 | { | ||
34 | [OSDMap] | ||
35 | public class LLSDTaskScriptUploadComplete | ||
36 | { | ||
37 | /// <summary> | ||
38 | /// The task inventory item that was updated | ||
39 | /// </summary> | ||
40 | public UUID new_asset; | ||
41 | |||
42 | /// <summary> | ||
43 | /// Was it compiled? | ||
44 | /// </summary> | ||
45 | public bool compiled; | ||
46 | |||
47 | /// <summary> | ||
48 | /// State of the upload. So far have only even seen this set to "complete" | ||
49 | /// </summary> | ||
50 | public string state; | ||
51 | |||
52 | public OSDArray errors; | ||
53 | } | ||
54 | } | ||
diff --git a/OpenSim/Capabilities/LLSDTest.cs b/OpenSim/Capabilities/LLSDTest.cs new file mode 100644 index 0000000..5f77c3d --- /dev/null +++ b/OpenSim/Capabilities/LLSDTest.cs | |||
@@ -0,0 +1,40 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | namespace OpenSim.Framework.Capabilities | ||
29 | { | ||
30 | [LLSDType("MAP")] | ||
31 | public class LLSDTest | ||
32 | { | ||
33 | public int Test1 = 20; | ||
34 | public int Test2 = 10; | ||
35 | |||
36 | public LLSDTest() | ||
37 | { | ||
38 | } | ||
39 | } | ||
40 | } \ No newline at end of file | ||
diff --git a/OpenSim/Capabilities/LLSDType.cs b/OpenSim/Capabilities/LLSDType.cs new file mode 100644 index 0000000..d5ca1ab --- /dev/null +++ b/OpenSim/Capabilities/LLSDType.cs | |||
@@ -0,0 +1,55 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | |||
30 | namespace OpenSim.Framework.Capabilities | ||
31 | { | ||
32 | [AttributeUsage(AttributeTargets.Class)] | ||
33 | public class LLSDType : Attribute | ||
34 | { | ||
35 | protected string myType; | ||
36 | |||
37 | public LLSDType(string type) | ||
38 | { | ||
39 | myType = type; | ||
40 | } | ||
41 | |||
42 | public string ObjectType | ||
43 | { | ||
44 | get { return myType; } | ||
45 | } | ||
46 | } | ||
47 | |||
48 | [AttributeUsage(AttributeTargets.Class)] | ||
49 | public class OSDMap : LLSDType | ||
50 | { | ||
51 | public OSDMap() : base("MAP") | ||
52 | { | ||
53 | } | ||
54 | } | ||
55 | } \ No newline at end of file | ||
diff --git a/OpenSim/Capabilities/LLSDVoiceAccountResponse.cs b/OpenSim/Capabilities/LLSDVoiceAccountResponse.cs new file mode 100644 index 0000000..53c11e7 --- /dev/null +++ b/OpenSim/Capabilities/LLSDVoiceAccountResponse.cs | |||
@@ -0,0 +1,57 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | |||
29 | namespace OpenSim.Framework.Capabilities | ||
30 | { | ||
31 | [OSDMap] | ||
32 | public class LLSDVoiceAccountResponse | ||
33 | { | ||
34 | public string username; | ||
35 | public string password; | ||
36 | public string voice_sip_uri_hostname; | ||
37 | public string voice_account_server_name; | ||
38 | |||
39 | public LLSDVoiceAccountResponse() | ||
40 | { | ||
41 | } | ||
42 | |||
43 | public LLSDVoiceAccountResponse(string user, string pass) | ||
44 | { | ||
45 | username = user; | ||
46 | password = pass; | ||
47 | } | ||
48 | |||
49 | public LLSDVoiceAccountResponse(string user, string pass, string sipUriHost, string accountServer) | ||
50 | { | ||
51 | username = user; | ||
52 | password = pass; | ||
53 | voice_sip_uri_hostname = sipUriHost; | ||
54 | voice_account_server_name = accountServer; | ||
55 | } | ||
56 | } | ||
57 | } \ No newline at end of file | ||
diff --git a/OpenSim/Capabilities/Properties/AssemblyInfo.cs b/OpenSim/Capabilities/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..f8a9dae --- /dev/null +++ b/OpenSim/Capabilities/Properties/AssemblyInfo.cs | |||
@@ -0,0 +1,33 @@ | |||
1 | using System.Reflection; | ||
2 | using System.Runtime.CompilerServices; | ||
3 | using System.Runtime.InteropServices; | ||
4 | |||
5 | // General Information about an assembly is controlled through the following | ||
6 | // set of attributes. Change these attribute values to modify the information | ||
7 | // associated with an assembly. | ||
8 | [assembly: AssemblyTitle("OpenSim.Capabilities")] | ||
9 | [assembly: AssemblyDescription("")] | ||
10 | [assembly: AssemblyConfiguration("")] | ||
11 | [assembly: AssemblyCompany("http://opensimulator.org")] | ||
12 | [assembly: AssemblyProduct("OpenSim")] | ||
13 | [assembly: AssemblyCopyright("OpenSimulator developers")] | ||
14 | [assembly: AssemblyTrademark("")] | ||
15 | [assembly: AssemblyCulture("")] | ||
16 | |||
17 | // Setting ComVisible to false makes the types in this assembly not visible | ||
18 | // to COM components. If you need to access a type in this assembly from | ||
19 | // COM, set the ComVisible attribute to true on that type. | ||
20 | [assembly: ComVisible(false)] | ||
21 | |||
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM | ||
23 | [assembly: Guid("7d1a55b1-8fab-42ff-9c83-066a9cc34d76")] | ||
24 | |||
25 | // Version information for an assembly consists of the following four values: | ||
26 | // | ||
27 | // Major Version | ||
28 | // Minor Version | ||
29 | // Build Number | ||
30 | // Revision | ||
31 | // | ||
32 | [assembly: AssemblyVersion("0.7.6.*")] | ||
33 | [assembly: AssemblyFileVersion("1.0.0.0")] | ||