aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorDiva Canto2011-06-13 09:13:44 -0700
committerDiva Canto2011-06-13 09:13:44 -0700
commitecb28ae130d1fc212c72af887fc75ae2bf64ab97 (patch)
tree40ab53e950d7e15b0cbd0e9f90d9eb7a286be139 /OpenSim
parentSame processing of the "/" in the MapImageService Cap as the one in the login... (diff)
downloadopensim-SC-ecb28ae130d1fc212c72af887fc75ae2bf64ab97.zip
opensim-SC-ecb28ae130d1fc212c72af887fc75ae2bf64ab97.tar.gz
opensim-SC-ecb28ae130d1fc212c72af887fc75ae2bf64ab97.tar.bz2
opensim-SC-ecb28ae130d1fc212c72af887fc75ae2bf64ab97.tar.xz
V2 map now working in grids too. WARNING: A few visible configuration variables added in order for this to work. See .ini.example changes
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Server/Handlers/Map/MapAddServerConnector.cs124
-rw-r--r--OpenSim/Server/Handlers/Map/MapGetServerConnector.cs1
-rw-r--r--OpenSim/Services/Connectors/MapImage/MapImageServiceConnector.cs81
-rw-r--r--OpenSim/Services/MapImageService/MapImageService.cs2
4 files changed, 164 insertions, 44 deletions
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
28using System; 28using System;
29using System.Collections.Generic;
30using System.IO;
31using System.Reflection;
32using System.Xml;
33
29using Nini.Config; 34using Nini.Config;
35using log4net;
36
30using OpenSim.Server.Base; 37using OpenSim.Server.Base;
31using OpenSim.Services.Interfaces; 38using OpenSim.Services.Interfaces;
32using OpenSim.Framework.Servers.HttpServer; 39using 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;
36using OpenSim.Framework; 36using OpenSim.Framework;
37using OpenSim.Framework.Console; 37using OpenSim.Framework.Console;
38using OpenSim.Framework.Communications; 38using OpenSim.Framework.Communications;
39using OpenSim.Server.Base;
39using OpenSim.Services.Interfaces; 40using OpenSim.Services.Interfaces;
40using OpenMetaverse; 41using OpenMetaverse;
41using OpenMetaverse.StructuredData; 42using 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))