diff options
Diffstat (limited to 'OpenSim/Server/Handlers/Inventory')
-rw-r--r-- | OpenSim/Server/Handlers/Inventory/XInventoryInConnector.cs | 167 |
1 files changed, 167 insertions, 0 deletions
diff --git a/OpenSim/Server/Handlers/Inventory/XInventoryInConnector.cs b/OpenSim/Server/Handlers/Inventory/XInventoryInConnector.cs new file mode 100644 index 0000000..8c6eca7 --- /dev/null +++ b/OpenSim/Server/Handlers/Inventory/XInventoryInConnector.cs | |||
@@ -0,0 +1,167 @@ | |||
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.Reflection; | ||
30 | using System.Text; | ||
31 | using System.Xml; | ||
32 | using System.Collections.Generic; | ||
33 | using System.IO; | ||
34 | using Nini.Config; | ||
35 | using OpenSim.Framework; | ||
36 | using OpenSim.Server.Base; | ||
37 | using OpenSim.Services.Interfaces; | ||
38 | using OpenSim.Framework.Servers.HttpServer; | ||
39 | using OpenSim.Server.Handlers.Base; | ||
40 | using log4net; | ||
41 | |||
42 | namespace OpenSim.Server.Handlers.Asset | ||
43 | { | ||
44 | public class XInventoryInConnector : ServiceConnector | ||
45 | { | ||
46 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
47 | |||
48 | private IInventoryService m_InventoryService; | ||
49 | private string m_ConfigName = "InventoryService"; | ||
50 | |||
51 | public XInventoryInConnector(IConfigSource config, IHttpServer server, string configName) : | ||
52 | base(config, server, configName) | ||
53 | { | ||
54 | if (configName != String.Empty) | ||
55 | m_ConfigName = configName; | ||
56 | |||
57 | IConfig serverConfig = config.Configs[m_ConfigName]; | ||
58 | if (serverConfig == null) | ||
59 | throw new Exception(String.Format("No section '{0}' in config file", m_ConfigName)); | ||
60 | |||
61 | string inventoryService = serverConfig.GetString("LocalServiceModule", | ||
62 | String.Empty); | ||
63 | |||
64 | if (inventoryService == String.Empty) | ||
65 | throw new Exception("No InventoryService in config file"); | ||
66 | |||
67 | Object[] args = new Object[] { config }; | ||
68 | m_InventoryService = | ||
69 | ServerUtils.LoadPlugin<IInventoryService>(inventoryService, args); | ||
70 | |||
71 | server.AddStreamHandler(new XInventoryConnectorPostHandler(m_InventoryService)); | ||
72 | } | ||
73 | } | ||
74 | |||
75 | public class XInventoryConnectorPostHandler : BaseStreamHandler | ||
76 | { | ||
77 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
78 | |||
79 | private IInventoryService m_InventoryService; | ||
80 | |||
81 | public XInventoryConnectorPostHandler(IInventoryService service) : | ||
82 | base("POST", "/xinventory") | ||
83 | { | ||
84 | m_InventoryService = service; | ||
85 | } | ||
86 | |||
87 | public override byte[] Handle(string path, Stream requestData, | ||
88 | OSHttpRequest httpRequest, OSHttpResponse httpResponse) | ||
89 | { | ||
90 | StreamReader sr = new StreamReader(requestData); | ||
91 | string body = sr.ReadToEnd(); | ||
92 | sr.Close(); | ||
93 | body = body.Trim(); | ||
94 | |||
95 | //m_log.DebugFormat("[XXX]: query String: {0}", body); | ||
96 | |||
97 | try | ||
98 | { | ||
99 | Dictionary<string, object> request = | ||
100 | ServerUtils.ParseQueryString(body); | ||
101 | |||
102 | if (!request.ContainsKey("METHOD")) | ||
103 | return FailureResult(); | ||
104 | |||
105 | string method = request["METHOD"].ToString(); | ||
106 | request.Remove("METHOD"); | ||
107 | |||
108 | switch (method) | ||
109 | { | ||
110 | case "TEST": | ||
111 | return HandleTest(request); | ||
112 | } | ||
113 | m_log.DebugFormat("[XINVENTORY HANDLER]: unknown method request: {0}", method); | ||
114 | } | ||
115 | catch (Exception e) | ||
116 | { | ||
117 | m_log.Debug("[XINVENTORY HANDLER]: Exception {0}" + e); | ||
118 | } | ||
119 | |||
120 | return FailureResult(); | ||
121 | } | ||
122 | |||
123 | private byte[] FailureResult() | ||
124 | { | ||
125 | XmlDocument doc = new XmlDocument(); | ||
126 | |||
127 | XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, | ||
128 | "", ""); | ||
129 | |||
130 | doc.AppendChild(xmlnode); | ||
131 | |||
132 | XmlElement rootElement = doc.CreateElement("", "ServerResponse", | ||
133 | ""); | ||
134 | |||
135 | doc.AppendChild(rootElement); | ||
136 | |||
137 | XmlElement result = doc.CreateElement("", "RESULT", ""); | ||
138 | result.AppendChild(doc.CreateTextNode("False")); | ||
139 | |||
140 | rootElement.AppendChild(result); | ||
141 | |||
142 | return DocToBytes(doc); | ||
143 | } | ||
144 | |||
145 | private byte[] DocToBytes(XmlDocument doc) | ||
146 | { | ||
147 | MemoryStream ms = new MemoryStream(); | ||
148 | XmlTextWriter xw = new XmlTextWriter(ms, null); | ||
149 | xw.Formatting = Formatting.Indented; | ||
150 | doc.WriteTo(xw); | ||
151 | xw.Flush(); | ||
152 | |||
153 | return ms.ToArray(); | ||
154 | } | ||
155 | |||
156 | byte[] HandleTest(Dictionary<string,object> request) | ||
157 | { | ||
158 | Dictionary<string,object> result = new Dictionary<string,object>(); | ||
159 | |||
160 | string xmlString = ServerUtils.BuildXmlResponse(result); | ||
161 | //m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString); | ||
162 | UTF8Encoding encoding = new UTF8Encoding(); | ||
163 | return encoding.GetBytes(xmlString); | ||
164 | } | ||
165 | |||
166 | } | ||
167 | } | ||