diff options
Diffstat (limited to '')
5 files changed, 289 insertions, 44 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/Caps/MiscCapsModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/MiscCapsModule.cs new file mode 100644 index 0000000..3dcd1e3 --- /dev/null +++ b/OpenSim/Region/ClientStack/Linden/Caps/MiscCapsModule.cs | |||
@@ -0,0 +1,125 @@ | |||
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.Reflection; | ||
31 | using log4net; | ||
32 | using Nini.Config; | ||
33 | using Mono.Addins; | ||
34 | using OpenMetaverse; | ||
35 | using OpenSim.Framework; | ||
36 | using OpenSim.Framework.Servers.HttpServer; | ||
37 | using OpenSim.Region.Framework.Interfaces; | ||
38 | using OpenSim.Region.Framework.Scenes; | ||
39 | using OpenSim.Services.Interfaces; | ||
40 | using Caps = OpenSim.Framework.Capabilities.Caps; | ||
41 | using OpenSim.Capabilities.Handlers; | ||
42 | |||
43 | namespace OpenSim.Region.ClientStack.Linden | ||
44 | { | ||
45 | /// <summary> | ||
46 | /// A module to place miscellaneous capabilities | ||
47 | /// </summary> | ||
48 | /// | ||
49 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")] | ||
50 | public class MiscCapsModule : INonSharedRegionModule | ||
51 | { | ||
52 | private static readonly ILog m_log = | ||
53 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
54 | private Scene m_scene; | ||
55 | |||
56 | private bool m_Enabled = false; | ||
57 | private string m_MapImageServerURL; | ||
58 | |||
59 | #region ISharedRegionModule Members | ||
60 | |||
61 | public void Initialise(IConfigSource source) | ||
62 | { | ||
63 | m_Enabled = true; | ||
64 | IConfig config = source.Configs["ClientStack.LindenCaps"]; | ||
65 | if (config == null) | ||
66 | return; | ||
67 | |||
68 | m_MapImageServerURL = config.GetString("Cap_MapImageService", string.Empty); | ||
69 | if (m_MapImageServerURL != string.Empty) | ||
70 | { | ||
71 | m_MapImageServerURL = m_MapImageServerURL.Trim(); | ||
72 | if (!m_MapImageServerURL.EndsWith("/")) | ||
73 | m_MapImageServerURL = m_MapImageServerURL + "/"; | ||
74 | } | ||
75 | } | ||
76 | |||
77 | public void AddRegion(Scene s) | ||
78 | { | ||
79 | if (!m_Enabled) | ||
80 | return; | ||
81 | |||
82 | m_scene = s; | ||
83 | } | ||
84 | |||
85 | public void RemoveRegion(Scene s) | ||
86 | { | ||
87 | if (!m_Enabled) | ||
88 | return; | ||
89 | |||
90 | m_scene.EventManager.OnRegisterCaps -= RegisterCaps; | ||
91 | m_scene = null; | ||
92 | } | ||
93 | |||
94 | public void RegionLoaded(Scene s) | ||
95 | { | ||
96 | if (!m_Enabled) | ||
97 | return; | ||
98 | |||
99 | m_scene.EventManager.OnRegisterCaps += RegisterCaps; | ||
100 | } | ||
101 | |||
102 | public void PostInitialise() | ||
103 | { | ||
104 | } | ||
105 | |||
106 | public void Close() { } | ||
107 | |||
108 | public string Name { get { return "MiscCapsModule"; } } | ||
109 | |||
110 | public Type ReplaceableInterface | ||
111 | { | ||
112 | get { return null; } | ||
113 | } | ||
114 | |||
115 | #endregion | ||
116 | |||
117 | public void RegisterCaps(UUID agentID, Caps caps) | ||
118 | { | ||
119 | m_log.InfoFormat("[MISC CAPS MODULE]: {0} in region {1}", m_MapImageServerURL, m_scene.RegionInfo.RegionName); | ||
120 | if (m_MapImageServerURL != string.Empty) | ||
121 | caps.RegisterHandler("MapImageService", m_MapImageServerURL); | ||
122 | } | ||
123 | |||
124 | } | ||
125 | } | ||
diff --git a/OpenSim/Server/Handlers/Map/MapAddServerConnector.cs b/OpenSim/Server/Handlers/Map/MapAddServerConnector.cs index a953cd7..99f98b6 100644 --- a/OpenSim/Server/Handlers/Map/MapAddServerConnector.cs +++ b/OpenSim/Server/Handlers/Map/MapAddServerConnector.cs | |||
@@ -26,7 +26,14 @@ | |||
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.Collections.Generic; | ||
30 | using System.IO; | ||
31 | using System.Reflection; | ||
32 | using System.Xml; | ||
33 | |||
29 | using Nini.Config; | 34 | using Nini.Config; |
35 | using log4net; | ||
36 | |||
30 | using OpenSim.Server.Base; | 37 | using OpenSim.Server.Base; |
31 | using OpenSim.Services.Interfaces; | 38 | using OpenSim.Services.Interfaces; |
32 | using OpenSim.Framework.Servers.HttpServer; | 39 | using OpenSim.Framework.Servers.HttpServer; |
@@ -55,7 +62,122 @@ namespace OpenSim.Server.Handlers.MapImage | |||
55 | Object[] args = new Object[] { config }; | 62 | Object[] args = new Object[] { config }; |
56 | m_MapService = ServerUtils.LoadPlugin<IMapImageService>(gridService, args); | 63 | m_MapService = ServerUtils.LoadPlugin<IMapImageService>(gridService, args); |
57 | 64 | ||
58 | //server.AddStreamHandler(new PresenceServerPostHandler(m_PresenceService)); | 65 | server.AddStreamHandler(new MapServerPostHandler(m_MapService)); |
66 | } | ||
67 | } | ||
68 | |||
69 | class MapServerPostHandler : BaseStreamHandler | ||
70 | { | ||
71 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
72 | private IMapImageService m_MapService; | ||
73 | |||
74 | public MapServerPostHandler(IMapImageService service) : | ||
75 | base("POST", "/map") | ||
76 | { | ||
77 | m_MapService = service; | ||
78 | } | ||
79 | |||
80 | public override byte[] Handle(string path, Stream requestData, OSHttpRequest httpRequest, OSHttpResponse httpResponse) | ||
81 | { | ||
82 | m_log.DebugFormat("[MAP SERVICE IMAGE HANDLER]: Received {0}", path); | ||
83 | StreamReader sr = new StreamReader(requestData); | ||
84 | string body = sr.ReadToEnd(); | ||
85 | sr.Close(); | ||
86 | body = body.Trim(); | ||
87 | |||
88 | try | ||
89 | { | ||
90 | Dictionary<string, object> request = ServerUtils.ParseQueryString(body); | ||
91 | |||
92 | if (!request.ContainsKey("X") || !request.ContainsKey("Y") || !request.ContainsKey("DATA")) | ||
93 | { | ||
94 | httpResponse.StatusCode = (int)OSHttpStatusCode.ClientErrorBadRequest; | ||
95 | return FailureResult("Bad request."); | ||
96 | } | ||
97 | int x = 0, y = 0; | ||
98 | Int32.TryParse(request["X"].ToString(), out x); | ||
99 | Int32.TryParse(request["Y"].ToString(), out y); | ||
100 | string type = "image/jpeg"; | ||
101 | if (request.ContainsKey("TYPE")) | ||
102 | type = request["TYPE"].ToString(); | ||
103 | byte[] data = Convert.FromBase64String(request["DATA"].ToString()); | ||
104 | |||
105 | string reason = string.Empty; | ||
106 | bool result = m_MapService.AddMapTile(x, y, data, out reason); | ||
107 | |||
108 | if (result) | ||
109 | return SuccessResult(); | ||
110 | else | ||
111 | return FailureResult(reason); | ||
112 | |||
113 | } | ||
114 | catch (Exception e) | ||
115 | { | ||
116 | m_log.ErrorFormat("[MAP SERVICE IMAGE HANDLER]: Exception {0} {1}", e.Message, e.StackTrace); | ||
117 | } | ||
118 | |||
119 | return FailureResult("Unexpected server error"); | ||
120 | |||
121 | } | ||
122 | |||
123 | private byte[] SuccessResult() | ||
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("Success")); | ||
139 | |||
140 | rootElement.AppendChild(result); | ||
141 | |||
142 | return DocToBytes(doc); | ||
143 | } | ||
144 | |||
145 | private byte[] FailureResult(string msg) | ||
146 | { | ||
147 | XmlDocument doc = new XmlDocument(); | ||
148 | |||
149 | XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, | ||
150 | "", ""); | ||
151 | |||
152 | doc.AppendChild(xmlnode); | ||
153 | |||
154 | XmlElement rootElement = doc.CreateElement("", "ServerResponse", | ||
155 | ""); | ||
156 | |||
157 | doc.AppendChild(rootElement); | ||
158 | |||
159 | XmlElement result = doc.CreateElement("", "Result", ""); | ||
160 | result.AppendChild(doc.CreateTextNode("Failure")); | ||
161 | |||
162 | rootElement.AppendChild(result); | ||
163 | |||
164 | XmlElement message = doc.CreateElement("", "Message", ""); | ||
165 | message.AppendChild(doc.CreateTextNode(msg)); | ||
166 | |||
167 | rootElement.AppendChild(message); | ||
168 | |||
169 | return DocToBytes(doc); | ||
170 | } | ||
171 | |||
172 | private byte[] DocToBytes(XmlDocument doc) | ||
173 | { | ||
174 | MemoryStream ms = new MemoryStream(); | ||
175 | XmlTextWriter xw = new XmlTextWriter(ms, null); | ||
176 | xw.Formatting = Formatting.Indented; | ||
177 | doc.WriteTo(xw); | ||
178 | xw.Flush(); | ||
179 | |||
180 | return ms.ToArray(); | ||
59 | } | 181 | } |
60 | } | 182 | } |
61 | } | 183 | } |
diff --git a/OpenSim/Server/Handlers/Map/MapGetServerConnector.cs b/OpenSim/Server/Handlers/Map/MapGetServerConnector.cs index 53d08fa..e8a424f 100644 --- a/OpenSim/Server/Handlers/Map/MapGetServerConnector.cs +++ b/OpenSim/Server/Handlers/Map/MapGetServerConnector.cs | |||
@@ -80,7 +80,6 @@ namespace OpenSim.Server.Handlers.MapImage | |||
80 | 80 | ||
81 | public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) | 81 | public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) |
82 | { | 82 | { |
83 | m_log.DebugFormat("[MAP SERVICE IMAGE HANDLER]: retrieving {0}", path); | ||
84 | byte[] result = new byte[0]; | 83 | byte[] result = new byte[0]; |
85 | 84 | ||
86 | string format = string.Empty; | 85 | string format = string.Empty; |
diff --git a/OpenSim/Services/Connectors/MapImage/MapImageServiceConnector.cs b/OpenSim/Services/Connectors/MapImage/MapImageServiceConnector.cs index ff0e9d9..520d639 100644 --- a/OpenSim/Services/Connectors/MapImage/MapImageServiceConnector.cs +++ b/OpenSim/Services/Connectors/MapImage/MapImageServiceConnector.cs | |||
@@ -36,6 +36,7 @@ using Nini.Config; | |||
36 | using OpenSim.Framework; | 36 | using OpenSim.Framework; |
37 | using OpenSim.Framework.Console; | 37 | using OpenSim.Framework.Console; |
38 | using OpenSim.Framework.Communications; | 38 | using OpenSim.Framework.Communications; |
39 | using OpenSim.Server.Base; | ||
39 | using OpenSim.Services.Interfaces; | 40 | using OpenSim.Services.Interfaces; |
40 | using OpenMetaverse; | 41 | using OpenMetaverse; |
41 | using OpenMetaverse.StructuredData; | 42 | using OpenMetaverse.StructuredData; |
@@ -83,60 +84,57 @@ namespace OpenSim.Services.Connectors | |||
83 | throw new Exception("MapImage connector init error"); | 84 | throw new Exception("MapImage connector init error"); |
84 | } | 85 | } |
85 | m_ServerURI = serviceURI; | 86 | m_ServerURI = serviceURI; |
87 | m_ServerURI = serviceURI.TrimEnd('/'); | ||
86 | } | 88 | } |
87 | 89 | ||
88 | public bool AddMapTile(int x, int y, byte[] pngData, out string reason) | 90 | public bool AddMapTile(int x, int y, byte[] jpgData, out string reason) |
89 | { | 91 | { |
90 | List<MultipartForm.Element> postParameters = new List<MultipartForm.Element>() | 92 | reason = string.Empty; |
91 | { | ||
92 | new MultipartForm.Parameter("X", x.ToString()), | ||
93 | new MultipartForm.Parameter("Y", y.ToString()), | ||
94 | new MultipartForm.File("Tile", "tile.png", "image/png", pngData) | ||
95 | }; | ||
96 | |||
97 | reason = string.Empty; | ||
98 | int tickstart = Util.EnvironmentTickCount(); | 93 | int tickstart = Util.EnvironmentTickCount(); |
94 | Dictionary<string, object> sendData = new Dictionary<string, object>(); | ||
95 | sendData["X"] = x.ToString(); | ||
96 | sendData["Y"] = y.ToString(); | ||
97 | sendData["TYPE"] = "image/jpeg"; | ||
98 | sendData["DATA"] = Convert.ToBase64String(jpgData); | ||
99 | |||
100 | string reqString = ServerUtils.BuildQueryString(sendData); | ||
99 | 101 | ||
100 | // Make the remote storage request | ||
101 | try | 102 | try |
102 | { | 103 | { |
103 | HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(m_ServerURI); | 104 | string reply = SynchronousRestFormsRequester.MakeRequest("POST", |
104 | request.Timeout = 20000; | 105 | m_ServerURI + "/map", |
105 | request.ReadWriteTimeout = 5000; | 106 | reqString); |
106 | 107 | if (reply != string.Empty) | |
107 | using (HttpWebResponse response = MultipartForm.Post(request, postParameters)) | ||
108 | { | 108 | { |
109 | using (Stream responseStream = response.GetResponseStream()) | 109 | Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply); |
110 | |||
111 | if (replyData.ContainsKey("Result") && (replyData["Result"].ToString().ToLower() == "success")) | ||
110 | { | 112 | { |
111 | string responseStr = responseStream.GetStreamString(); | 113 | return true; |
112 | OSD responseOSD = OSDParser.Deserialize(responseStr); | ||
113 | if (responseOSD.Type == OSDType.Map) | ||
114 | { | ||
115 | OSDMap responseMap = (OSDMap)responseOSD; | ||
116 | if (responseMap["Success"].AsBoolean()) | ||
117 | return true; | ||
118 | |||
119 | reason = "Upload failed: " + responseMap["Message"].AsString(); | ||
120 | } | ||
121 | else | ||
122 | { | ||
123 | reason = "Response format was invalid:\n" + responseStr; | ||
124 | } | ||
125 | } | 114 | } |
115 | else if (replyData.ContainsKey("Result") && (replyData["Result"].ToString().ToLower() == "failure")) | ||
116 | { | ||
117 | m_log.DebugFormat("[MAP IMAGE CONNECTOR]: Registration failed: {0}", replyData["Message"].ToString()); | ||
118 | reason = replyData["Message"].ToString(); | ||
119 | return false; | ||
120 | } | ||
121 | else if (!replyData.ContainsKey("Result")) | ||
122 | { | ||
123 | m_log.DebugFormat("[MAP IMAGE CONNECTOR]: reply data does not contain result field"); | ||
124 | } | ||
125 | else | ||
126 | { | ||
127 | m_log.DebugFormat("[MAP IMAGE CONNECTOR]: unexpected result {0}", replyData["Result"].ToString()); | ||
128 | reason = "Unexpected result " + replyData["Result"].ToString(); | ||
129 | } | ||
130 | |||
126 | } | 131 | } |
132 | else | ||
133 | m_log.DebugFormat("[MAP IMAGE CONNECTOR]: RegisterRegion received null reply"); | ||
127 | } | 134 | } |
128 | catch (WebException we) | 135 | catch (Exception e) |
129 | { | ||
130 | reason = we.Message; | ||
131 | if (we.Status == WebExceptionStatus.ProtocolError) | ||
132 | { | ||
133 | HttpWebResponse webResponse = (HttpWebResponse)we.Response; | ||
134 | reason = String.Format("[{0}] {1}", webResponse.StatusCode, webResponse.StatusDescription); | ||
135 | } | ||
136 | } | ||
137 | catch (Exception ex) | ||
138 | { | 136 | { |
139 | reason = ex.Message; | 137 | m_log.DebugFormat("[MAP IMAGE CONNECTOR]: Exception when contacting grid server: {0}", e.Message); |
140 | } | 138 | } |
141 | finally | 139 | finally |
142 | { | 140 | { |
@@ -146,6 +144,7 @@ namespace OpenSim.Services.Connectors | |||
146 | } | 144 | } |
147 | 145 | ||
148 | return false; | 146 | return false; |
147 | |||
149 | } | 148 | } |
150 | 149 | ||
151 | public byte[] GetMapTile(string fileName, out string format) | 150 | public byte[] GetMapTile(string fileName, out string format) |
diff --git a/OpenSim/Services/MapImageService/MapImageService.cs b/OpenSim/Services/MapImageService/MapImageService.cs index 27722bb..7e7391c 100644 --- a/OpenSim/Services/MapImageService/MapImageService.cs +++ b/OpenSim/Services/MapImageService/MapImageService.cs | |||
@@ -143,7 +143,7 @@ namespace OpenSim.Services.MapImageService | |||
143 | if (File.Exists(fullName)) | 143 | if (File.Exists(fullName)) |
144 | { | 144 | { |
145 | format = Path.GetExtension(fileName).ToLower(); | 145 | format = Path.GetExtension(fileName).ToLower(); |
146 | m_log.DebugFormat("[MAP IMAGE SERVICE]: Found file {0}, extension {1}", fileName, format); | 146 | //m_log.DebugFormat("[MAP IMAGE SERVICE]: Found file {0}, extension {1}", fileName, format); |
147 | return File.ReadAllBytes(fullName); | 147 | return File.ReadAllBytes(fullName); |
148 | } | 148 | } |
149 | else if (File.Exists(m_WaterTileFile)) | 149 | else if (File.Exists(m_WaterTileFile)) |