aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server/Handlers
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/Server/Handlers
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/Server/Handlers')
-rw-r--r--OpenSim/Server/Handlers/Map/MapAddServerConnector.cs124
-rw-r--r--OpenSim/Server/Handlers/Map/MapGetServerConnector.cs1
2 files changed, 123 insertions, 2 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;