aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs')
-rw-r--r--OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs155
1 files changed, 155 insertions, 0 deletions
diff --git a/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs b/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs
new file mode 100644
index 0000000..9ca5120
--- /dev/null
+++ b/OpenSim/Server/Handlers/Presence/PresenceServerPostHandler.cs
@@ -0,0 +1,155 @@
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 return FailureResult();
98 }
99
100 private byte[] SuccessResult()
101 {
102 XmlDocument doc = new XmlDocument();
103
104 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
105 "", "");
106
107 doc.AppendChild(xmlnode);
108
109 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
110 "");
111
112 doc.AppendChild(rootElement);
113
114 XmlElement result = doc.CreateElement("", "Result", "");
115 result.AppendChild(doc.CreateTextNode("Success"));
116
117 rootElement.AppendChild(result);
118
119 return DocToBytes(doc);
120 }
121
122 private byte[] FailureResult()
123 {
124 XmlDocument doc = new XmlDocument();
125
126 XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration,
127 "", "");
128
129 doc.AppendChild(xmlnode);
130
131 XmlElement rootElement = doc.CreateElement("", "ServerResponse",
132 "");
133
134 doc.AppendChild(rootElement);
135
136 XmlElement result = doc.CreateElement("", "Result", "");
137 result.AppendChild(doc.CreateTextNode("Failure"));
138
139 rootElement.AppendChild(result);
140
141 return DocToBytes(doc);
142 }
143
144 private byte[] DocToBytes(XmlDocument doc)
145 {
146 MemoryStream ms = new MemoryStream();
147 XmlTextWriter xw = new XmlTextWriter(ms, null);
148 xw.Formatting = Formatting.Indented;
149 doc.WriteTo(xw);
150 xw.Flush();
151
152 return ms.ToArray();
153 }
154 }
155}