aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Servers
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/Servers')
-rw-r--r--OpenSim/Framework/Servers/BaseHttpServer.cs168
-rw-r--r--OpenSim/Framework/Servers/LLSDMethod.cs3
-rw-r--r--OpenSim/Framework/Servers/LLSDMethodString.cs33
3 files changed, 180 insertions, 24 deletions
diff --git a/OpenSim/Framework/Servers/BaseHttpServer.cs b/OpenSim/Framework/Servers/BaseHttpServer.cs
index 23c28e6..7b2b599 100644
--- a/OpenSim/Framework/Servers/BaseHttpServer.cs
+++ b/OpenSim/Framework/Servers/BaseHttpServer.cs
@@ -47,8 +47,9 @@ namespace OpenSim.Framework.Servers
47 47
48 protected Thread m_workerThread; 48 protected Thread m_workerThread;
49 protected HttpListener m_httpListener; 49 protected HttpListener m_httpListener;
50 protected Dictionary<string, XmlRpcMethod> m_rpcHandlers = new Dictionary<string, XmlRpcMethod>(); 50 protected Dictionary<string, XmlRpcMethod> m_rpcHandlers = new Dictionary<string, XmlRpcMethod>();
51 protected LLSDMethod m_llsdHandler = null; 51 protected DefaultLLSDMethod m_defaultLlsdHandler = null; // <-- Moving away from the monolithic.. and going to /registered/
52 protected Dictionary<string, LLSDMethod> m_llsdHandlers = new Dictionary<string, LLSDMethod>();
52 protected Dictionary<string, IRequestHandler> m_streamHandlers = new Dictionary<string, IRequestHandler>(); 53 protected Dictionary<string, IRequestHandler> m_streamHandlers = new Dictionary<string, IRequestHandler>();
53 protected Dictionary<string, GenericHTTPMethod> m_HTTPHandlers = new Dictionary<string, GenericHTTPMethod>(); 54 protected Dictionary<string, GenericHTTPMethod> m_HTTPHandlers = new Dictionary<string, GenericHTTPMethod>();
54 protected Dictionary<string, IHttpAgentHandler> m_agentHandlers = new Dictionary<string, IHttpAgentHandler>(); 55 protected Dictionary<string, IHttpAgentHandler> m_agentHandlers = new Dictionary<string, IHttpAgentHandler>();
@@ -148,9 +149,28 @@ namespace OpenSim.Framework.Servers
148 return false; 149 return false;
149 } 150 }
150 151
151 public bool SetLLSDHandler(LLSDMethod handler) 152 /// <summary>
153 /// Adds a LLSD handler, yay.
154 /// </summary>
155 /// <param name="path">/resource/ path</param>
156 /// <param name="handler">handle the LLSD response</param>
157 /// <returns></returns>
158 public bool AddLLSDHandler(string path, LLSDMethod handler)
152 { 159 {
153 m_llsdHandler = handler; 160 lock (m_llsdHandlers)
161 {
162 if (!m_llsdHandlers.ContainsKey(path))
163 {
164 m_llsdHandlers.Add(path, handler);
165 return true;
166 }
167 }
168 return false;
169 }
170
171 public bool SetDefaultLLSDHandler(DefaultLLSDMethod handler)
172 {
173 m_defaultLlsdHandler = handler;
154 return true; 174 return true;
155 } 175 }
156 176
@@ -239,20 +259,21 @@ namespace OpenSim.Framework.Servers
239 259
240 switch (request.ContentType) 260 switch (request.ContentType)
241 { 261 {
242 case null: 262 case null:
243 case "text/html": 263 case "text/html":
244 HandleHTTPRequest(request, response); 264 HandleHTTPRequest(request, response);
245 return; 265 return;
246 266
247 case "application/xml+llsd": 267 case "application/llsd+xml":
248 HandleLLSDRequests(request, response); 268 case "application/xml+llsd":
249 return; 269 HandleLLSDRequests(request, response);
270 return;
250 271
251 case "text/xml": 272 case "text/xml":
252 case "application/xml": 273 case "application/xml":
253 default: 274 default:
254 HandleXmlRpcRequests(request, response); 275 HandleXmlRpcRequests(request, response);
255 return; 276 return;
256 } 277 }
257 } 278 }
258 catch (SocketException e) 279 catch (SocketException e)
@@ -456,17 +477,37 @@ namespace OpenSim.Framework.Servers
456 m_log.Warn("[HTTPD]: Error - " + ex.Message); 477 m_log.Warn("[HTTPD]: Error - " + ex.Message);
457 } 478 }
458 479
459 if (llsdRequest != null && m_llsdHandler != null) 480 if (llsdRequest != null)// && m_defaultLlsdHandler != null)
460 { 481 {
461 llsdResponse = m_llsdHandler(llsdRequest); 482
483 LLSDMethod llsdhandler = null;
484
485 if (TryGetLLSDHandler(request.RawUrl, out llsdhandler))
486 {
487 // we found a registered llsd handler to service this request
488 llsdResponse = llsdhandler(request.RawUrl, llsdRequest, request.RemoteIPEndPoint.ToString());
489 }
490 else
491 {
492 // we didn't find a registered llsd handler to service this request
493 // check if we have a default llsd handler
494
495 if (m_defaultLlsdHandler != null)
496 {
497 // LibOMV path
498 llsdResponse = m_defaultLlsdHandler(llsdRequest);
499 }
500 else
501 {
502 // Oops, no handler for this.. give em the failed message
503 llsdResponse = GenerateNoLLSDHandlerResponse();
504 }
505 }
506
462 } 507 }
463 else 508 else
464 { 509 {
465 LLSDMap map = new LLSDMap(); 510 llsdResponse = GenerateNoLLSDHandlerResponse();
466 map["reason"] = LLSD.FromString("LLSDRequest");
467 map["message"] = LLSD.FromString("No handler registered for LLSD Requests");
468 map["login"] = LLSD.FromString("false");
469 llsdResponse = map;
470 } 511 }
471 512
472 response.ContentType = "application/xml+llsd"; 513 response.ContentType = "application/xml+llsd";
@@ -491,6 +532,68 @@ namespace OpenSim.Framework.Servers
491 } 532 }
492 } 533 }
493 534
535 private bool TryGetLLSDHandler(string path, out LLSDMethod llsdHandler)
536 {
537 llsdHandler = null;
538 // Pull out the first part of the path
539 // splitting the path by '/' means we'll get the following return..
540 // {0}/{1}/{2}
541 // where {0} isn't something we really control 100%
542
543 string[] pathbase = path.Split('/');
544 string searchquery = "/";
545
546 if (pathbase.Length < 1)
547 return false;
548
549 for (int i=1; i<pathbase.Length; i++)
550 {
551 searchquery += pathbase[i];
552 if (pathbase.Length-1 != i)
553 searchquery += "/";
554 }
555
556 // while the matching algorithm below doesn't require it, we're expecting a query in the form
557 //
558 // [] = optional
559 // /resource/UUID/action[/action]
560 //
561 // now try to get the closest match to the reigstered path
562 // at least for OGP, registered path would probably only consist of the /resource/
563
564 string bestMatch = null;
565
566 foreach (string pattern in m_llsdHandlers.Keys)
567 {
568 if (searchquery.StartsWith(searchquery))
569 {
570 if (String.IsNullOrEmpty(bestMatch) || searchquery.Length > bestMatch.Length)
571 {
572 bestMatch = pattern;
573 }
574 }
575 }
576
577 if (String.IsNullOrEmpty(bestMatch))
578 {
579 llsdHandler = null;
580 return false;
581 }
582 else
583 {
584 llsdHandler = m_llsdHandlers[bestMatch];
585 return true;
586 }
587 }
588
589 private LLSDMap GenerateNoLLSDHandlerResponse()
590 {
591 LLSDMap map = new LLSDMap();
592 map["reason"] = LLSD.FromString("LLSDRequest");
593 map["message"] = LLSD.FromString("No handler registered for LLSD Requests");
594 map["login"] = LLSD.FromString("false");
595 return map;
596 }
494 /// <summary> 597 /// <summary>
495 /// A specific agent handler was provided. Such a handler is expecetd to have an 598 /// A specific agent handler was provided. Such a handler is expecetd to have an
496 /// intimate, and highly specific relationship with the client. Consequently, 599 /// intimate, and highly specific relationship with the client. Consequently,
@@ -809,6 +912,25 @@ namespace OpenSim.Framework.Servers
809 912
810 return false; 913 return false;
811 } 914 }
915 public bool RemoveLLSDHandler(string path, LLSDMethod handler)
916 {
917
918 try
919 {
920 if (handler == m_llsdHandlers[path])
921 {
922 m_llsdHandlers.Remove(path);
923 return true;
924 }
925 }
926 catch (KeyNotFoundException)
927 {
928 // This is an exception to prevent crashing because of invalid code
929 }
930
931 return false;
932 }
933
812 934
813 public string GetHTTP404(string host) 935 public string GetHTTP404(string host)
814 { 936 {
diff --git a/OpenSim/Framework/Servers/LLSDMethod.cs b/OpenSim/Framework/Servers/LLSDMethod.cs
index 05c23b0..7bb946e 100644
--- a/OpenSim/Framework/Servers/LLSDMethod.cs
+++ b/OpenSim/Framework/Servers/LLSDMethod.cs
@@ -29,5 +29,6 @@ using libsecondlife.StructuredData;
29 29
30namespace OpenSim.Framework.Servers 30namespace OpenSim.Framework.Servers
31{ 31{
32 public delegate LLSD LLSDMethod(LLSD request); 32 public delegate LLSD LLSDMethod( string path, LLSD request, string endpoint );
33 public delegate LLSD DefaultLLSDMethod(LLSD request);
33} 34}
diff --git a/OpenSim/Framework/Servers/LLSDMethodString.cs b/OpenSim/Framework/Servers/LLSDMethodString.cs
new file mode 100644
index 0000000..8d20b69
--- /dev/null
+++ b/OpenSim/Framework/Servers/LLSDMethodString.cs
@@ -0,0 +1,33 @@
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 libsecondlife.StructuredData;
29
30namespace OpenSim.Framework.Servers
31{
32 public delegate LLSD LLSDMethodString(LLSD request, string thePath);
33}