diff options
author | Melanie | 2010-02-25 01:46:34 +0000 |
---|---|---|
committer | Melanie | 2010-02-25 01:46:34 +0000 |
commit | c7b1e76eb5fbc73ccbde6f91718e5454a1e3a228 (patch) | |
tree | 6e3df1364e14fc2e610bb0e97afa4079227d52d5 /OpenSim | |
parent | Remove some obsolete files from MSSQL. Fix a missing constructor arg that (diff) | |
download | opensim-SC-c7b1e76eb5fbc73ccbde6f91718e5454a1e3a228.zip opensim-SC-c7b1e76eb5fbc73ccbde6f91718e5454a1e3a228.tar.gz opensim-SC-c7b1e76eb5fbc73ccbde6f91718e5454a1e3a228.tar.bz2 opensim-SC-c7b1e76eb5fbc73ccbde6f91718e5454a1e3a228.tar.xz |
Add the stream handler/listener and requisite methods to the friends module
for the friends interregion comms.
Diffstat (limited to 'OpenSim')
-rw-r--r-- | OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs | 106 |
1 files changed, 103 insertions, 3 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs index f383bad..fe027c6 100644 --- a/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Friends/FriendsModule.cs | |||
@@ -26,9 +26,10 @@ | |||
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using System.IO; | ||
29 | using System.Collections; | 30 | using System.Collections; |
30 | using System.Collections.Generic; | 31 | using System.Collections.Generic; |
31 | using System.Net; | 32 | using System.Xml; |
32 | using System.Reflection; | 33 | using System.Reflection; |
33 | using log4net; | 34 | using log4net; |
34 | using Nini.Config; | 35 | using Nini.Config; |
@@ -36,17 +37,38 @@ using Nwc.XmlRpc; | |||
36 | using OpenMetaverse; | 37 | using OpenMetaverse; |
37 | using OpenSim.Framework; | 38 | using OpenSim.Framework; |
38 | using OpenSim.Framework.Communications; | 39 | using OpenSim.Framework.Communications; |
39 | |||
40 | using OpenSim.Region.Framework.Interfaces; | 40 | using OpenSim.Region.Framework.Interfaces; |
41 | using OpenSim.Region.Framework.Scenes; | 41 | using OpenSim.Region.Framework.Scenes; |
42 | using OpenSim.Services.Interfaces; | 42 | using OpenSim.Services.Interfaces; |
43 | using OpenSim.Server.Base; | ||
44 | using OpenSim.Framework.Servers.HttpServer; | ||
45 | using log4net; | ||
43 | 46 | ||
44 | namespace OpenSim.Region.CoreModules.Avatar.Friends | 47 | namespace OpenSim.Region.CoreModules.Avatar.Friends |
45 | { | 48 | { |
46 | public class FriendsModule : ISharedRegionModule, IFriendsModule | 49 | public class FriendsModule : BaseStreamHandler, ISharedRegionModule, IFriendsModule |
47 | { | 50 | { |
51 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
52 | |||
53 | protected int m_Port = 0; | ||
54 | |||
55 | public FriendsModule() | ||
56 | : base("POST", "/friends") | ||
57 | { | ||
58 | } | ||
59 | |||
48 | public void Initialise(IConfigSource config) | 60 | public void Initialise(IConfigSource config) |
49 | { | 61 | { |
62 | IConfig friendsConfig = config.Configs["Friends"]; | ||
63 | if (friendsConfig != null) | ||
64 | { | ||
65 | m_Port = friendsConfig.GetInt("Port", m_Port); | ||
66 | } | ||
67 | |||
68 | IHttpServer server = MainServer.GetHttpServer((uint)m_Port); | ||
69 | |||
70 | server.AddStreamHandler(this); | ||
71 | |||
50 | } | 72 | } |
51 | 73 | ||
52 | public void PostInitialise() | 74 | public void PostInitialise() |
@@ -69,6 +91,41 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
69 | { | 91 | { |
70 | } | 92 | } |
71 | 93 | ||
94 | public override byte[] Handle(string path, Stream requestData, | ||
95 | OSHttpRequest httpRequest, OSHttpResponse httpResponse) | ||
96 | { | ||
97 | StreamReader sr = new StreamReader(requestData); | ||
98 | string body = sr.ReadToEnd(); | ||
99 | sr.Close(); | ||
100 | body = body.Trim(); | ||
101 | |||
102 | m_log.DebugFormat("[XXX]: query String: {0}", body); | ||
103 | |||
104 | try | ||
105 | { | ||
106 | Dictionary<string, object> request = | ||
107 | ServerUtils.ParseQueryString(body); | ||
108 | |||
109 | if (!request.ContainsKey("METHOD")) | ||
110 | return FailureResult(); | ||
111 | |||
112 | string method = request["METHOD"].ToString(); | ||
113 | request.Remove("METHOD"); | ||
114 | |||
115 | switch (method) | ||
116 | { | ||
117 | case "TEST": | ||
118 | break; | ||
119 | } | ||
120 | } | ||
121 | catch (Exception e) | ||
122 | { | ||
123 | m_log.Debug("[FRIENDS]: Exception {0}" + e.ToString()); | ||
124 | } | ||
125 | |||
126 | return FailureResult(); | ||
127 | } | ||
128 | |||
72 | public string Name | 129 | public string Name |
73 | { | 130 | { |
74 | get { return "FriendsModule"; } | 131 | get { return "FriendsModule"; } |
@@ -87,5 +144,48 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends | |||
87 | { | 144 | { |
88 | return 1; | 145 | return 1; |
89 | } | 146 | } |
147 | |||
148 | private byte[] FailureResult() | ||
149 | { | ||
150 | return BoolResult(false); | ||
151 | } | ||
152 | |||
153 | private byte[] SuccessResult() | ||
154 | { | ||
155 | return BoolResult(true); | ||
156 | } | ||
157 | |||
158 | private byte[] BoolResult(bool value) | ||
159 | { | ||
160 | XmlDocument doc = new XmlDocument(); | ||
161 | |||
162 | XmlNode xmlnode = doc.CreateNode(XmlNodeType.XmlDeclaration, | ||
163 | "", ""); | ||
164 | |||
165 | doc.AppendChild(xmlnode); | ||
166 | |||
167 | XmlElement rootElement = doc.CreateElement("", "ServerResponse", | ||
168 | ""); | ||
169 | |||
170 | doc.AppendChild(rootElement); | ||
171 | |||
172 | XmlElement result = doc.CreateElement("", "RESULT", ""); | ||
173 | result.AppendChild(doc.CreateTextNode(value.ToString())); | ||
174 | |||
175 | rootElement.AppendChild(result); | ||
176 | |||
177 | return DocToBytes(doc); | ||
178 | } | ||
179 | |||
180 | private byte[] DocToBytes(XmlDocument doc) | ||
181 | { | ||
182 | MemoryStream ms = new MemoryStream(); | ||
183 | XmlTextWriter xw = new XmlTextWriter(ms, null); | ||
184 | xw.Formatting = Formatting.Indented; | ||
185 | doc.WriteTo(xw); | ||
186 | xw.Flush(); | ||
187 | |||
188 | return ms.ToArray(); | ||
189 | } | ||
90 | } | 190 | } |
91 | } | 191 | } |