aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorTeravus Ovares2008-09-27 09:42:31 +0000
committerTeravus Ovares2008-09-27 09:42:31 +0000
commit85b280385fd7400da8bc721131d25eee9fd7f8da (patch)
treef0fdba12f4442e01c9a3032c6c0b8881194f3509 /OpenSim
parentUpdate unit tests (diff)
downloadopensim-SC_OLD-85b280385fd7400da8bc721131d25eee9fd7f8da.zip
opensim-SC_OLD-85b280385fd7400da8bc721131d25eee9fd7f8da.tar.gz
opensim-SC_OLD-85b280385fd7400da8bc721131d25eee9fd7f8da.tar.bz2
opensim-SC_OLD-85b280385fd7400da8bc721131d25eee9fd7f8da.tar.xz
* This is the very very early beginnings of an EventQueue:get module.
* This won't function yet as far as the client can tell.. because it doesn't respond to the first query with a 200 message. * We have to figure out how to encode those binary values in the example code in the module... * Committing this so we have a start point. Will continue to work on this more today.
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Framework/Servers/BaseHTTPHandler.cs42
-rw-r--r--OpenSim/Framework/Servers/BaseHttpServer.cs61
-rw-r--r--OpenSim/Framework/Servers/RestHTTPHandler.cs57
-rw-r--r--OpenSim/Region/Environment/Modules/Framework/EventQueueGetModule.cs164
-rw-r--r--OpenSim/Region/Interfaces/IEventQueue.cs40
5 files changed, 359 insertions, 5 deletions
diff --git a/OpenSim/Framework/Servers/BaseHTTPHandler.cs b/OpenSim/Framework/Servers/BaseHTTPHandler.cs
new file mode 100644
index 0000000..a7c3562
--- /dev/null
+++ b/OpenSim/Framework/Servers/BaseHTTPHandler.cs
@@ -0,0 +1,42 @@
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 OpenSim 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 System.Collections;
30
31namespace OpenSim.Framework.Servers
32{
33 public abstract class BaseHTTPHandler : BaseRequestHandler, IGenericHTTPHandler
34 {
35 public abstract Hashtable Handle(string path, Hashtable Request);
36
37 protected BaseHTTPHandler(string httpMethod, string path)
38 : base(httpMethod, path)
39 {
40 }
41 }
42} \ No newline at end of file
diff --git a/OpenSim/Framework/Servers/BaseHttpServer.cs b/OpenSim/Framework/Servers/BaseHttpServer.cs
index ae07895..24bba2b 100644
--- a/OpenSim/Framework/Servers/BaseHttpServer.cs
+++ b/OpenSim/Framework/Servers/BaseHttpServer.cs
@@ -361,9 +361,57 @@ namespace OpenSim.Framework.Servers
361 361
362 buffer = streamedRequestHandler.Handle(path, request.InputStream, request, response); 362 buffer = streamedRequestHandler.Handle(path, request.InputStream, request, response);
363 } 363 }
364 else if (requestHandler is IGenericHTTPHandler)
365 {
366 IGenericHTTPHandler HTTPRequestHandler = requestHandler as IGenericHTTPHandler;
367 Stream requestStream = request.InputStream;
368
369 Encoding encoding = Encoding.UTF8;
370 StreamReader reader = new StreamReader(requestStream, encoding);
371
372 string requestBody = reader.ReadToEnd();
373
374
375 reader.Close();
376 requestStream.Close();
377
378 Hashtable keysvals = new Hashtable();
379 Hashtable headervals = new Hashtable();
380 string host = String.Empty;
381
382 string[] querystringkeys = request.QueryString.AllKeys;
383 string[] rHeaders = request.Headers.AllKeys;
384
385
386 foreach (string queryname in querystringkeys)
387 {
388 keysvals.Add(queryname, request.QueryString[queryname]);
389 }
390
391 foreach (string headername in rHeaders)
392 {
393 //m_log.Warn("[HEADER]: " + headername + "=" + request.Headers[headername]);
394 headervals[headername] = request.Headers[headername];
395 }
396
397 if (headervals.Contains("Host"))
398 {
399 host = (string)headervals["Host"];
400 }
401 keysvals.Add("requestbody",requestBody);
402 if (keysvals.Contains("method"))
403 {
404 //m_log.Warn("[HTTP]: Contains Method");
405 string method = (string)keysvals["method"];
406 //m_log.Warn("[HTTP]: " + requestBody);
407
408 }
409 DoHTTPGruntWork(HTTPRequestHandler.Handle(path,keysvals), response);
410 return;
411 }
364 else 412 else
365 { 413 {
366 IStreamHandler streamHandler = (IStreamHandler) requestHandler; 414 IStreamHandler streamHandler = (IStreamHandler)requestHandler;
367 415
368 using (MemoryStream memoryStream = new MemoryStream()) 416 using (MemoryStream memoryStream = new MemoryStream())
369 { 417 {
@@ -943,6 +991,9 @@ namespace OpenSim.Framework.Servers
943 string responseString = (string)responsedata["str_response_string"]; 991 string responseString = (string)responsedata["str_response_string"];
944 string contentType = (string)responsedata["content_type"]; 992 string contentType = (string)responsedata["content_type"];
945 993
994 if (responsedata.ContainsKey("keepalive"))
995 response.KeepAlive = true;
996
946 //Even though only one other part of the entire code uses HTTPHandlers, we shouldn't expect this 997 //Even though only one other part of the entire code uses HTTPHandlers, we shouldn't expect this
947 //and should check for NullReferenceExceptions 998 //and should check for NullReferenceExceptions
948 999
@@ -951,10 +1002,9 @@ namespace OpenSim.Framework.Servers
951 contentType = "text/html"; 1002 contentType = "text/html";
952 } 1003 }
953 1004
954 // We're forgoing the usual error status codes here because the client 1005 // The client ignores anything but 200 here for web login, so ensure that this is 200 for that
955 // ignores anything but 200 and 301 1006
956 1007 response.StatusCode = responsecode;
957 response.StatusCode = (int)OSHttpStatusCode.SuccessOk;
958 1008
959 if (responsecode == (int)OSHttpStatusCode.RedirectMovedPermanently) 1009 if (responsecode == (int)OSHttpStatusCode.RedirectMovedPermanently)
960 { 1010 {
@@ -978,6 +1028,7 @@ namespace OpenSim.Framework.Servers
978 response.SendChunked = false; 1028 response.SendChunked = false;
979 response.ContentLength64 = buffer.Length; 1029 response.ContentLength64 = buffer.Length;
980 response.ContentEncoding = Encoding.UTF8; 1030 response.ContentEncoding = Encoding.UTF8;
1031
981 1032
982 try 1033 try
983 { 1034 {
diff --git a/OpenSim/Framework/Servers/RestHTTPHandler.cs b/OpenSim/Framework/Servers/RestHTTPHandler.cs
new file mode 100644
index 0000000..2974c56
--- /dev/null
+++ b/OpenSim/Framework/Servers/RestHTTPHandler.cs
@@ -0,0 +1,57 @@
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 OpenSim 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 System.Collections;
30
31namespace OpenSim.Framework.Servers
32{
33 public class RestHTTPHandler : BaseHTTPHandler
34 {
35 private GenericHTTPMethod m_dhttpMethod;
36
37 public GenericHTTPMethod Method
38 {
39 get { return m_dhttpMethod; }
40 }
41
42 public override Hashtable Handle(string path, Hashtable request)
43 {
44
45 string param = GetParam(path);
46 request.Add("param", param);
47 request.Add("path", path);
48 return m_dhttpMethod(request);
49 }
50
51 public RestHTTPHandler(string httpMethod, string path, GenericHTTPMethod dhttpMethod)
52 : base(httpMethod, path)
53 {
54 m_dhttpMethod = dhttpMethod;
55 }
56 }
57}
diff --git a/OpenSim/Region/Environment/Modules/Framework/EventQueueGetModule.cs b/OpenSim/Region/Environment/Modules/Framework/EventQueueGetModule.cs
new file mode 100644
index 0000000..ea6c663
--- /dev/null
+++ b/OpenSim/Region/Environment/Modules/Framework/EventQueueGetModule.cs
@@ -0,0 +1,164 @@
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using System.Net;
5using System.Net.Sockets;
6using System.Reflection;
7using System.Xml;
8using OpenMetaverse;
9using OpenMetaverse.StructuredData;
10using log4net;
11using Nini.Config;
12using Nwc.XmlRpc;
13using OpenSim.Framework;
14using OpenSim.Framework.Communications.Cache;
15using OpenSim.Framework.Communications.Capabilities;
16using OpenSim.Framework.Servers;
17using OpenSim.Region.Environment.Interfaces;
18using OpenSim.Region.Interfaces;
19using OpenSim.Region.Environment.Scenes;
20
21using LLSD = OpenMetaverse.StructuredData.LLSD;
22using LLSDMap = OpenMetaverse.StructuredData.LLSDMap;
23using LLSDArray = OpenMetaverse.StructuredData.LLSDArray;
24using Caps = OpenSim.Framework.Communications.Capabilities.Caps;
25
26namespace OpenSim.Region.Environment.Modules.Framework
27{
28 public class EventQueueGetModule : IEventQueue, IRegionModule
29 {
30 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
31 Scene m_scene = null;
32 IConfigSource m_gConfig;
33
34 #region IRegionModule methods
35 public void Initialise(Scene scene, IConfigSource config)
36 {
37 m_gConfig = config;
38 m_scene = scene;
39
40
41 IConfig startupConfig = m_gConfig.Configs["Startup"];
42
43 ReadConfigAndPopulate(scene, startupConfig, "Startup");
44
45 scene.RegisterModuleInterface<IEventQueue>(this);
46
47 scene.EventManager.OnNewClient += OnNewClient;
48 scene.EventManager.OnClientClosed += ClientClosed;
49 scene.EventManager.OnAvatarEnteringNewParcel += AvatarEnteringParcel;
50 scene.EventManager.OnMakeChildAgent += MakeChildAgent;
51 scene.EventManager.OnClientClosed += ClientLoggedOut;
52 scene.EventManager.OnRegisterCaps += OnRegisterCaps;
53
54 }
55
56 private void ReadConfigAndPopulate(Scene scene, IConfig startupConfig, string p)
57 {
58
59 }
60
61
62
63
64
65 public void PostInitialise()
66 {
67 }
68
69 public void Close()
70 {
71 }
72
73 public string Name
74 {
75 get { return "EventQueueGetModule"; }
76 }
77
78 public bool IsSharedModule
79 {
80 get { return false; }
81 }
82 #endregion
83
84 #region IEventQueue Members
85 public bool Enqueue(object o, UUID avatarID)
86 {
87
88 return false;
89 }
90 #endregion
91
92 private void OnNewClient(IClientAPI client)
93 {
94
95 client.OnLogout += ClientClosed;
96 }
97
98
99 public void ClientClosed(IClientAPI client)
100 {
101 ClientClosed(client.AgentId);
102 }
103
104 private void ClientLoggedOut(UUID AgentId)
105 {
106
107 }
108
109 private void AvatarEnteringParcel(ScenePresence avatar, int localLandID, UUID regionID)
110 {
111
112 }
113
114 public void ClientClosed(UUID AgentID)
115 {
116
117 }
118 private void MakeChildAgent(ScenePresence avatar)
119 {
120 }
121 public void OnRegisterCaps(UUID agentID, Caps caps)
122 {
123 m_log.DebugFormat("[EVENTQUEUE] OnRegisterCaps: agentID {0} caps {1}", agentID, caps);
124 string capsBase = "/CAPS/";
125 caps.RegisterHandler("EventQueueGet",
126 new RestHTTPHandler("POST", capsBase + UUID.Random().ToString(),
127 delegate(Hashtable m_dhttpMethod)
128 {
129 return ProcessQueue(m_dhttpMethod,agentID, caps);
130 }));
131 }
132 public Hashtable ProcessQueue(Hashtable request,UUID agentID, Caps caps)
133 {
134
135 Hashtable responsedata = new Hashtable();
136 responsedata["int_response_code"] = 502;
137 responsedata["str_response_string"] = "Upstream error:";
138 responsedata["content_type"] = "text/plain";
139 responsedata["keepalive"] = true;
140
141 /*
142 responsedata["int_response_code"] = 200;
143 responsedata["content_type"] = "application/xml";
144 responsedata["keepalive"] = true;
145
146 responsedata["str_response_string"] = @"<llsd><map><key>events</key><array><map><key>body</key><map><key>AgentData</key><map><key>AgentID</key>
147 <uuid>0fd0e798-a54f-40b1-0000-000000000000</uuid><key>SessionID</key><uuid>cc91f1fe-9d52-435d-0000-000000000000
148 </uuid></map><key>Info</key><map><key>LookAt</key><array><real>0.9869639873504638671875</real><real>
149 -0.1609439998865127563476562</real><real>0</real></array><key>Position</key><array><real>1.43747997283935546875
150 </real><real>95.30560302734375</real><real>57.3480987548828125</real></array></map><key>RegionData</key><map>
151 <key>RegionHandle</key><binary encoding=" + "\"base64\"" + @">AAPnAAAD8AA=</binary><key>SeedCapability</key><string>
152 https://sim7.aditi.lindenlab.com:12043/cap/64015fb3-6fee-9205-0000-000000000000</string><key>SimIP</key><binary
153 encoding=" + "\"base64\"" + @">yA8FSA==</binary><key>SimPort</key><integer>13005</integer></map></map><key>message</key>
154 <string>CrossedRegion</string></map></array><key>id</key><integer>1</integer></map></llsd>";
155
156 */
157 //string requestbody = (string)request["requestbody"];
158 //LLSD llsdRequest = LLSDParser.DeserializeXml(request);
159 //System.Console.WriteLine(requestbody);
160 return responsedata;
161
162 }
163 }
164}
diff --git a/OpenSim/Region/Interfaces/IEventQueue.cs b/OpenSim/Region/Interfaces/IEventQueue.cs
new file mode 100644
index 0000000..a11eebe
--- /dev/null
+++ b/OpenSim/Region/Interfaces/IEventQueue.cs
@@ -0,0 +1,40 @@
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 OpenSim 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 OpenSim.Framework;
30using OpenMetaverse;
31using System.Collections.Generic;
32using System.Text;
33
34namespace OpenSim.Region.Interfaces
35{
36 public interface IEventQueue
37 {
38 bool Enqueue(object o, UUID avatarID);
39 }
40}