aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server/Handlers/Presence
diff options
context:
space:
mode:
authorKittoFlora2009-11-19 20:20:03 +0100
committerKittoFlora2009-11-19 20:20:03 +0100
commit251d1b8fbbc311ea267d0a44d5878df480d69338 (patch)
tree4ef142946d9b05d42564ddba63a99a67db5659bc /OpenSim/Server/Handlers/Presence
parentClean up messages in ODE (diff)
parentMerge branch 'master' into careminster (diff)
downloadopensim-SC-251d1b8fbbc311ea267d0a44d5878df480d69338.zip
opensim-SC-251d1b8fbbc311ea267d0a44d5878df480d69338.tar.gz
opensim-SC-251d1b8fbbc311ea267d0a44d5878df480d69338.tar.bz2
opensim-SC-251d1b8fbbc311ea267d0a44d5878df480d69338.tar.xz
Merge branch 'careminster' into tests
Diffstat (limited to 'OpenSim/Server/Handlers/Presence')
-rw-r--r--OpenSim/Server/Handlers/Presence/PresenceServerConnector.cs61
-rw-r--r--OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs182
2 files changed, 243 insertions, 0 deletions
diff --git a/OpenSim/Server/Handlers/Presence/PresenceServerConnector.cs b/OpenSim/Server/Handlers/Presence/PresenceServerConnector.cs
new file mode 100644
index 0000000..899cd8f
--- /dev/null
+++ b/OpenSim/Server/Handlers/Presence/PresenceServerConnector.cs
@@ -0,0 +1,61 @@
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
28using System;
29using Nini.Config;
30using OpenSim.Server.Base;
31using OpenSim.Services.Interfaces;
32using OpenSim.Framework.Servers.HttpServer;
33using OpenSim.Server.Handlers.Base;
34
35namespace OpenSim.Server.Handlers.Presence
36{
37 public class PresenceServiceConnector : ServiceConnector
38 {
39 private IPresenceService m_PresenceService;
40 private string m_ConfigName = "PresenceService";
41
42 public PresenceServiceConnector(IConfigSource config, IHttpServer server, string configName) :
43 base(config, server, configName)
44 {
45 IConfig serverConfig = config.Configs[m_ConfigName];
46 if (serverConfig == null)
47 throw new Exception(String.Format("No section {0} in config file", m_ConfigName));
48
49 string gridService = serverConfig.GetString("LocalServiceModule",
50 String.Empty);
51
52 if (gridService == String.Empty)
53 throw new Exception("No LocalServiceModule in config file");
54
55 Object[] args = new Object[] { config };
56 m_PresenceService = ServerUtils.LoadPlugin<IPresenceService>(gridService, args);
57
58 server.AddStreamHandler(new PresenceServerPostHandler(m_PresenceService));
59 }
60 }
61}
diff --git a/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs b/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs
new file mode 100644
index 0000000..2558fa0
--- /dev/null
+++ b/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs
@@ -0,0 +1,182 @@
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
28using Nini.Config;
29using log4net;
30using System;
31using System.Reflection;
32using System.IO;
33using System.Net;
34using System.Text;
35using System.Text.RegularExpressions;
36using System.Xml;
37using System.Xml.Serialization;
38using System.Collections.Generic;
39using OpenSim.Server.Base;
40using OpenSim.Services.Interfaces;
41using OpenSim.Framework;
42using OpenSim.Framework.Servers.HttpServer;
43using OpenMetaverse;
44
45namespace OpenSim.Server.Handlers.Presence
46{
47 public class PresenceServerPostHandler : BaseStreamHandler
48 {
49 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
50
51 private IPresenceService m_PresenceService;
52
53 public PresenceServerPostHandler(IPresenceService service) :
54 base("POST", "/presence")
55 {
56 m_PresenceService = service;
57 }
58
59 public override byte[] Handle(string path, Stream requestData,
60 OSHttpRequest httpRequest, OSHttpResponse httpResponse)
61 {
62 StreamReader sr = new StreamReader(requestData);
63 string body = sr.ReadToEnd();
64 sr.Close();
65 body = body.Trim();
66
67 //m_log.DebugFormat("[XXX]: query String: {0}", body);
68
69 try
70 {
71 Dictionary<string, string> request =
72 ServerUtils.ParseQueryString(body);
73
74 if (!request.ContainsKey("METHOD"))
75 return FailureResult();
76
77 string method = request["METHOD"];
78
79 switch (method)
80 {
81 case "report":
82 return Report(request);
83 }
84 m_log.DebugFormat("[PRESENCE HANDLER]: unknown method request: {0}", method);
85 }
86 catch (Exception e)
87 {
88 m_log.Debug("[PRESENCE HANDLER]: Exception {0}" + e);
89 }
90
91 return FailureResult();
92
93 }
94
95 byte[] Report(Dictionary<string, string> request)
96 {
97 PresenceInfo info = new PresenceInfo();
98 info.Data = new Dictionary<string, string>();
99
100 if (request["PrincipalID"] == null || request["RegionID"] == null)
101 return FailureResult();
102
103 if (!UUID.TryParse(request["PrincipalID"].ToString(),
104 out info.PrincipalID))
105 return FailureResult();
106
107 if (!UUID.TryParse(request["RegionID"].ToString(),
108 out info.RegionID))
109 return FailureResult();
110
111 foreach (KeyValuePair<string, string> kvp in request)
112 {
113 if (kvp.Key == "METHOD" ||
114 kvp.Key == "PrincipalID" ||
115 kvp.Key == "RegionID")
116 continue;
117
118 info.Data[kvp.Key] = kvp.Value;
119 }
120
121 if (m_PresenceService.Report(info))
122 return SuccessResult();
123
124 return FailureResult();
125 }
126
127 private byte[] SuccessResult()
128 {
129 XmlDocument doc = new XmlDocument();
130
131 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
132 "", "");
133
134 doc.AppendChild(xmlnode);
135
136 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
137 "");
138
139 doc.AppendChild(rootElement);
140
141 XmlElement result = doc.CreateElement("", "Result", "");
142 result.AppendChild(doc.CreateTextNode("Success"));
143
144 rootElement.AppendChild(result);
145
146 return DocToBytes(doc);
147 }
148
149 private byte[] FailureResult()
150 {
151 XmlDocument doc = new XmlDocument();
152
153 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
154 "", "");
155
156 doc.AppendChild(xmlnode);
157
158 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
159 "");
160
161 doc.AppendChild(rootElement);
162
163 XmlElement result = doc.CreateElement("", "Result", "");
164 result.AppendChild(doc.CreateTextNode("Failure"));
165
166 rootElement.AppendChild(result);
167
168 return DocToBytes(doc);
169 }
170
171 private byte[] DocToBytes(XmlDocument doc)
172 {
173 MemoryStream ms = new MemoryStream();
174 XmlTextWriter xw = new XmlTextWriter(ms, null);
175 xw.Formatting = Formatting.Indented;
176 doc.WriteTo(xw);
177 xw.Flush();
178
179 return ms.ToArray();
180 }
181 }
182}