OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
NeighbourHandlers.cs
Go to the documentation of this file.
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.IO;
30 using System.Reflection;
31 using System.Net;
32 using System.Text;
33 
34 using OpenSim.Server.Base;
35 using OpenSim.Server.Handlers.Base;
36 using OpenSim.Services.Interfaces;
37 using OpenSim.Framework;
38 using OpenSim.Framework.Servers.HttpServer;
40 
41 using OpenMetaverse;
42 using OpenMetaverse.StructuredData;
43 using Nini.Config;
44 using log4net;
45 
46 
47 namespace OpenSim.Server.Handlers.Neighbour
48 {
50  {
51  // TODO: unused: private ISimulationService m_SimulationService;
52  // TODO: unused: private IAuthenticationService m_AuthenticationService;
53 
55  base("GET", "/region")
56  {
57  // TODO: unused: m_SimulationService = service;
58  // TODO: unused: m_AuthenticationService = authentication;
59  }
60 
61  protected override byte[] ProcessRequest(string path, Stream request,
62  IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
63  {
64  // Not implemented yet
65  Console.WriteLine("--- Get region --- " + path);
66  httpResponse.StatusCode = (int)HttpStatusCode.NotImplemented;
67  return new byte[] { };
68  }
69  }
70 
72  {
73  private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
74  private INeighbourService m_NeighbourService;
75  private IAuthenticationService m_AuthenticationService;
76  // TODO: unused: private bool m_AllowForeignGuests;
77 
79  base("POST", "/region")
80  {
81  m_NeighbourService = service;
82  m_AuthenticationService = authentication;
83  // TODO: unused: m_AllowForeignGuests = foreignGuests;
84  }
85 
86  protected override byte[] ProcessRequest(string path, Stream request,
87  IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
88  {
89  byte[] result = new byte[0];
90 
91  UUID regionID;
92  string action;
93  ulong regionHandle;
94  if (RestHandlerUtils.GetParams(path, out regionID, out regionHandle, out action))
95  {
96  m_log.InfoFormat("[RegionPostHandler]: Invalid parameters for neighbour message {0}", path);
97  httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
98  httpResponse.StatusDescription = "Invalid parameters for neighbour message " + path;
99 
100  return result;
101  }
102 
103  if (m_AuthenticationService != null)
104  {
105  // Authentication
106  string authority = string.Empty;
107  string authToken = string.Empty;
108  if (!RestHandlerUtils.GetAuthentication(httpRequest, out authority, out authToken))
109  {
110  m_log.InfoFormat("[RegionPostHandler]: Authentication failed for neighbour message {0}", path);
111  httpResponse.StatusCode = (int)HttpStatusCode.Unauthorized;
112  return result;
113  }
114  // TODO: Rethink this
115  //if (!m_AuthenticationService.VerifyKey(regionID, authToken))
116  //{
117  // m_log.InfoFormat("[RegionPostHandler]: Authentication failed for neighbour message {0}", path);
118  // httpResponse.StatusCode = (int)HttpStatusCode.Forbidden;
119  // return result;
120  //}
121  m_log.DebugFormat("[RegionPostHandler]: Authentication succeeded for {0}", regionID);
122  }
123 
124  OSDMap args = Util.GetOSDMap(request, (int)httpRequest.ContentLength);
125  if (args == null)
126  {
127  httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
128  httpResponse.StatusDescription = "Unable to retrieve data";
129  m_log.DebugFormat("[RegionPostHandler]: Unable to retrieve data for post {0}", path);
130  return result;
131  }
132 
133  // retrieve the regionhandle
134  ulong regionhandle = 0;
135  if (args["destination_handle"] != null)
136  UInt64.TryParse(args["destination_handle"].AsString(), out regionhandle);
137 
138  RegionInfo aRegion = new RegionInfo();
139  try
140  {
141  aRegion.UnpackRegionInfoData(args);
142  }
143  catch (Exception ex)
144  {
145  m_log.InfoFormat("[RegionPostHandler]: exception on unpacking region info {0}", ex.Message);
146  httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
147  httpResponse.StatusDescription = "Problems with data deserialization";
148  return result;
149  }
150 
151  // Finally!
152  GridRegion thisRegion = m_NeighbourService.HelloNeighbour(regionhandle, aRegion);
153 
154  OSDMap resp = new OSDMap(1);
155 
156  if (thisRegion != null)
157  resp["success"] = OSD.FromBoolean(true);
158  else
159  resp["success"] = OSD.FromBoolean(false);
160 
161  httpResponse.StatusCode = (int)HttpStatusCode.OK;
162 
163  return Util.UTF8.GetBytes(OSDParser.SerializeJsonString(resp));
164  }
165  }
166 
168  {
169  // TODO: unused: private ISimulationService m_SimulationService;
170  // TODO: unused: private IAuthenticationService m_AuthenticationService;
171 
173  base("PUT", "/region")
174  {
175  // TODO: unused: m_SimulationService = service;
176  // TODO: unused: m_AuthenticationService = authentication;
177  }
178 
179  protected override byte[] ProcessRequest(string path, Stream request,
180  IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
181  {
182  // Not implemented yet
183  httpResponse.StatusCode = (int)HttpStatusCode.NotImplemented;
184  return new byte[] { };
185  }
186  }
187 
189  {
190  // TODO: unused: private ISimulationService m_SimulationService;
191  // TODO: unused: private IAuthenticationService m_AuthenticationService;
192 
194  base("DELETE", "/region")
195  {
196  // TODO: unused: m_SimulationService = service;
197  // TODO: unused: m_AuthenticationService = authentication;
198  }
199 
200  protected override byte[] ProcessRequest(string path, Stream request,
201  IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
202  {
203  // Not implemented yet
204  httpResponse.StatusCode = (int)HttpStatusCode.NotImplemented;
205  return new byte[] { };
206  }
207  }
208 }
NeighbourDeleteHandler(INeighbourService service, IAuthenticationService authentication)
override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
NeighbourPutHandler(INeighbourService service, IAuthenticationService authentication)
static bool GetParams(string path, out UUID uuid, out ulong regionHandle, out string action)
Extract the param from an uri.
Definition: Utils.cs:47
OpenSim.Framework.RegionInfo RegionInfo
OpenMetaverse.StructuredData.OSDMap OSDMap
OpenSim.Services.Interfaces.GridRegion GridRegion
NeighbourPostHandler(INeighbourService service, IAuthenticationService authentication)
NeighbourGetHandler(INeighbourService service, IAuthenticationService authentication)
override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
Interactive OpenSim region server
Definition: OpenSim.cs:55
override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
static bool GetAuthentication(IOSHttpRequest httpRequest, out string authority, out string authKey)
Definition: Utils.cs:73