aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Server/Handlers/Simulation/AgentHandlers.cs')
-rw-r--r--OpenSim/Server/Handlers/Simulation/AgentHandlers.cs182
1 files changed, 182 insertions, 0 deletions
diff --git a/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs b/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs
new file mode 100644
index 0000000..1d455c6
--- /dev/null
+++ b/OpenSim/Server/Handlers/Simulation/AgentHandlers.cs
@@ -0,0 +1,182 @@
1using System;
2using System.IO;
3using System.Reflection;
4using System.Net;
5using System.Text;
6
7using OpenSim.Server.Base;
8using OpenSim.Services.Interfaces;
9using OpenSim.Framework;
10using OpenSim.Framework.Servers.HttpServer;
11
12using OpenMetaverse;
13using OpenMetaverse.StructuredData;
14using Nini.Config;
15using log4net;
16
17
18namespace OpenSim.Server.Handlers.Simulation
19{
20 public class AgentGetHandler : BaseStreamHandler
21 {
22 private ISimulationService m_SimulationService;
23 private IAuthenticationService m_AuthenticationService;
24
25 public AgentGetHandler(ISimulationService service, IAuthenticationService authentication) :
26 base("GET", "/agent")
27 {
28 m_SimulationService = service;
29 m_AuthenticationService = authentication;
30 }
31
32 public override byte[] Handle(string path, Stream request,
33 OSHttpRequest httpRequest, OSHttpResponse httpResponse)
34 {
35 // Not implemented yet
36 httpResponse.StatusCode = (int)HttpStatusCode.NotImplemented;
37 return new byte[] { };
38 }
39 }
40
41 public class AgentPostHandler : BaseStreamHandler
42 {
43 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
44 private ISimulationService m_SimulationService;
45 private IAuthenticationService m_AuthenticationService;
46 private bool m_AllowForeignGuests;
47
48 public AgentPostHandler(ISimulationService service, IAuthenticationService authentication, bool foreignGuests) :
49 base("POST", "/agent")
50 {
51 m_SimulationService = service;
52 m_AuthenticationService = authentication;
53 m_AllowForeignGuests = foreignGuests;
54 }
55
56 public override byte[] Handle(string path, Stream request,
57 OSHttpRequest httpRequest, OSHttpResponse httpResponse)
58 {
59 byte[] result = new byte[0];
60
61 UUID agentID;
62 string action;
63 ulong regionHandle;
64 if (!Utils.GetParams(path, out agentID, out regionHandle, out action))
65 {
66 m_log.InfoFormat("[AgentPostHandler]: Invalid parameters for agent message {0}", path);
67 httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
68 httpResponse.StatusDescription = "Invalid parameters for agent message " + path;
69
70 return result;
71 }
72
73 if (m_AuthenticationService != null)
74 {
75 // Authentication
76 string authority = string.Empty;
77 string authToken = string.Empty;
78 if (!Utils.GetAuthentication(httpRequest, out authority, out authToken))
79 {
80 m_log.InfoFormat("[AgentPostHandler]: Authentication failed for agent message {0}", path);
81 httpResponse.StatusCode = (int)HttpStatusCode.Unauthorized;
82 return result;
83 }
84 if (!m_AuthenticationService.VerifyKey(agentID, authToken))
85 {
86 m_log.InfoFormat("[AgentPostHandler]: Authentication failed for agent message {0}", path);
87 httpResponse.StatusCode = (int)HttpStatusCode.Forbidden;
88 return result;
89 }
90 m_log.DebugFormat("[AgentPostHandler]: Authentication succeeded for {0}", agentID);
91 }
92
93 OSDMap args = Util.GetOSDMap(request, (int)httpRequest.ContentLength);
94 if (args == null)
95 {
96 httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
97 httpResponse.StatusDescription = "Unable to retrieve data";
98 m_log.DebugFormat("[AgentPostHandler]: Unable to retrieve data for post {0}", path);
99 return result;
100 }
101
102 // retrieve the regionhandle
103 ulong regionhandle = 0;
104 if (args["destination_handle"] != null)
105 UInt64.TryParse(args["destination_handle"].AsString(), out regionhandle);
106
107 AgentCircuitData aCircuit = new AgentCircuitData();
108 try
109 {
110 aCircuit.UnpackAgentCircuitData(args);
111 }
112 catch (Exception ex)
113 {
114 m_log.InfoFormat("[AgentPostHandler]: exception on unpacking CreateAgent message {0}", ex.Message);
115 httpResponse.StatusCode = (int)HttpStatusCode.BadRequest;
116 httpResponse.StatusDescription = "Problems with data deserialization";
117 return result;
118 }
119
120 string reason = string.Empty;
121
122 // We need to clean up a few things in the user service before I can do this
123 //if (m_AllowForeignGuests)
124 // m_regionClient.AdjustUserInformation(aCircuit);
125
126 // Finally!
127 bool success = m_SimulationService.CreateAgent(regionhandle, aCircuit, out reason);
128
129 OSDMap resp = new OSDMap(1);
130
131 resp["success"] = OSD.FromBoolean(success);
132
133 httpResponse.StatusCode = (int)HttpStatusCode.OK;
134
135 return Encoding.UTF8.GetBytes(OSDParser.SerializeJsonString(resp));
136
137 }
138 }
139
140 public class AgentPutHandler : BaseStreamHandler
141 {
142 private ISimulationService m_SimulationService;
143 private IAuthenticationService m_AuthenticationService;
144
145 public AgentPutHandler(ISimulationService service, IAuthenticationService authentication) :
146 base("PUT", "/agent")
147 {
148 m_SimulationService = service;
149 m_AuthenticationService = authentication;
150 }
151
152 public override byte[] Handle(string path, Stream request,
153 OSHttpRequest httpRequest, OSHttpResponse httpResponse)
154 {
155 // Not implemented yet
156 httpResponse.StatusCode = (int)HttpStatusCode.NotImplemented;
157 return new byte[] { };
158 }
159 }
160
161 public class AgentDeleteHandler : BaseStreamHandler
162 {
163 private ISimulationService m_SimulationService;
164 private IAuthenticationService m_AuthenticationService;
165
166 public AgentDeleteHandler(ISimulationService service, IAuthenticationService authentication) :
167 base("DELETE", "/agent")
168 {
169 m_SimulationService = service;
170 m_AuthenticationService = authentication;
171 }
172
173 public override byte[] Handle(string path, Stream request,
174 OSHttpRequest httpRequest, OSHttpResponse httpResponse)
175 {
176 // Not implemented yet
177 httpResponse.StatusCode = (int)HttpStatusCode.NotImplemented;
178 return new byte[] { };
179 }
180 }
181
182}