29 using System.Collections.Generic;
 
   31 using System.Reflection;
 
   38 using OpenSim.Framework;
 
   39 using OpenSim.Server.Base;
 
   40 using OpenSim.Services.Interfaces;
 
   41 using OpenSim.Framework.ServiceAuth;
 
   42 using OpenSim.Framework.Servers.HttpServer;
 
   43 using OpenSim.Server.Handlers.Base;
 
   47 namespace OpenSim.Server.Handlers.MapImage
 
   51         private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
 
   55         private string m_ConfigName = 
"MapImageService";
 
   58                 base(config, server, configName)
 
   60             IConfig serverConfig = config.Configs[m_ConfigName];
 
   61             if (serverConfig == null)
 
   62                 throw new Exception(String.Format(
"No section {0} in config file", m_ConfigName));
 
   64             string mapService = serverConfig.GetString(
"LocalServiceModule",
 
   67             if (mapService == String.Empty)
 
   68                 throw new Exception(
"No LocalServiceModule in config file");
 
   70             Object[] args = 
new Object[] { config };
 
   73             string gridService = serverConfig.GetString(
"GridService", String.Empty);
 
   74             if (gridService != 
string.Empty)
 
   75                 m_GridService = ServerUtils.LoadPlugin<
IGridService>(gridService, args);
 
   77             if (m_GridService != null)
 
   78                 m_log.InfoFormat(
"[MAP IMAGE HANDLER]: GridService check is ON");
 
   80                 m_log.InfoFormat(
"[MAP IMAGE HANDLER]: GridService check is OFF");
 
   82             bool proxy = serverConfig.GetBoolean(
"HasProxy", 
false);
 
   83             IServiceAuth auth = ServiceAuth.Create(config, m_ConfigName);
 
   91         private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
 
   97             base(
"POST", 
"/map", auth)
 
   99             m_MapService = service;
 
  100             m_GridService = grid;
 
  107             StreamReader sr = 
new StreamReader(requestData);
 
  108             string body = sr.ReadToEnd();
 
  114                 Dictionary<string, object> request = ServerUtils.ParseQueryString(body);
 
  116                 if (!request.ContainsKey(
"X") || !request.ContainsKey(
"Y") || !request.ContainsKey(
"DATA"))
 
  119                     return FailureResult(
"Bad request.");
 
  123                 UUID scopeID = UUID.Zero;
 
  124                 Int32.TryParse(request[
"X"].ToString(), out x);
 
  125                 Int32.TryParse(request[
"Y"].ToString(), out y);
 
  126                 if (request.ContainsKey(
"SCOPE"))
 
  127                     UUID.TryParse(request[
"SCOPE"].ToString(), out scopeID);
 
  129                 m_log.DebugFormat(
"[MAP ADD SERVER CONNECTOR]: Received map data for region at {0}-{1}", x, y);
 
  136                 if (m_GridService != null)
 
  138                     System.Net.IPAddress ipAddr = GetCallerIP(httpRequest);
 
  139                     GridRegion r = m_GridService.GetRegionByPosition(UUID.Zero, (int)Util.RegionToWorldLoc((uint)x), (int)Util.RegionToWorldLoc((uint)y));
 
  144                             m_log.WarnFormat(
"[MAP IMAGE HANDLER]: IP address {0} may be trying to impersonate region in IP {1}", ipAddr, r.ExternalEndPoint.Address);
 
  145                             return FailureResult(
"IP address of caller does not match IP address of registered region");
 
  151                         m_log.WarnFormat(
"[MAP IMAGE HANDLER]: IP address {0} may be rogue. Region not found at coordinates {1}-{2}", 
 
  153                         return FailureResult(
"Region not found at given coordinates");
 
  157                 byte[] data = Convert.FromBase64String(request[
"DATA"].ToString());
 
  159                 string reason = string.Empty;
 
  161                 bool result = m_MapService.AddMapTile((int)x, (
int)y, data, scopeID, out reason);
 
  164                     return SuccessResult();
 
  166                     return FailureResult(reason);
 
  171                 m_log.ErrorFormat(
"[MAP SERVICE IMAGE HANDLER]: Exception {0} {1}", e.Message, e.StackTrace);
 
  174             return FailureResult(
"Unexpected server error");
 
  177         private byte[] SuccessResult()
 
  179             XmlDocument doc = 
new XmlDocument();
 
  181             XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
 
  184             doc.AppendChild(xmlnode);
 
  186             XmlElement rootElement = doc.CreateElement(
"", 
"ServerResponse",
 
  189             doc.AppendChild(rootElement);
 
  191             XmlElement result = doc.CreateElement(
"", 
"Result", 
"");
 
  192             result.AppendChild(doc.CreateTextNode(
"Success"));
 
  194             rootElement.AppendChild(result);
 
  196             return Util.DocToBytes(doc);
 
  199         private byte[] FailureResult(
string msg)
 
  201             XmlDocument doc = 
new XmlDocument();
 
  203             XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
 
  206             doc.AppendChild(xmlnode);
 
  208             XmlElement rootElement = doc.CreateElement(
"", 
"ServerResponse",
 
  211             doc.AppendChild(rootElement);
 
  213             XmlElement result = doc.CreateElement(
"", 
"Result", 
"");
 
  214             result.AppendChild(doc.CreateTextNode(
"Failure"));
 
  216             rootElement.AppendChild(result);
 
  218             XmlElement message = doc.CreateElement(
"", 
"Message", 
"");
 
  219             message.AppendChild(doc.CreateTextNode(msg));
 
  221             rootElement.AppendChild(message);
 
  223             return Util.DocToBytes(doc);
 
  229                 return request.RemoteIPEndPoint.Address;
 
  232             string xff = 
"X-Forwarded-For";
 
  233             string xffValue = request.Headers[xff.ToLower()];
 
  234             if (xffValue == null || (xffValue != null && xffValue == 
string.Empty))
 
  235                 xffValue = request.
Headers[xff];
 
  237             if (xffValue == null || (xffValue != null && xffValue == 
string.Empty))
 
  239                 m_log.WarnFormat(
"[MAP IMAGE HANDLER]: No XFF header");
 
  240                 return request.RemoteIPEndPoint.Address;
 
  243             System.Net.IPEndPoint ep = Util.GetClientIPFromXFF(xffValue);
 
  248             return request.RemoteIPEndPoint.Address;
 
OpenSim.Services.Interfaces.GridRegion GridRegion
 
MapServerPostHandler(IMapImageService service, IGridService grid, bool proxy, IServiceAuth auth)
 
Base streamed request handler. 
 
MapAddServiceConnector(IConfigSource config, IHttpServer server, string configName)
 
Interface to OpenSimulator's built in HTTP server. Use this to register handlers (http, llsd, xmlrpc, etc.) for given URLs. 
 
Interactive OpenSim region server 
 
IPEndPoint ExternalEndPoint
 
NameValueCollection Headers
 
OSHttpStatusCode
HTTP status codes (almost) as defined by W3C in http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html and IETF in http://tools.ietf.org/html/rfc6585 
 
override byte[] ProcessRequest(string path, Stream requestData, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)