IHttpServer.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. using Nwc.XmlRpc;
  28. namespace OpenSim.Framework.Servers.HttpServer
  29. {
  30. /// <summary>
  31. /// Interface to OpenSimulator's built in HTTP server. Use this to register handlers (http, llsd, xmlrpc, etc.)
  32. /// for given URLs.
  33. /// </summary>
  34. public interface IHttpServer
  35. {
  36. uint SSLPort { get; }
  37. string SSLCommonName { get; }
  38. uint Port { get; }
  39. bool UseSSL { get; }
  40. // Note that the agent string is provided simply to differentiate
  41. // the handlers - it is NOT required to be an actual agent header
  42. // value.
  43. bool AddAgentHandler(string agent, IHttpAgentHandler handler);
  44. /// <summary>
  45. /// Add a handler for an HTTP request.
  46. /// </summary>
  47. /// <remarks>
  48. /// This handler can actually be invoked either as
  49. ///
  50. /// http://<hostname>:<port>/?method=<methodName>
  51. ///
  52. /// or
  53. ///
  54. /// http://<hostname>:<port><method>
  55. ///
  56. /// if the method name starts with a slash. For example, AddHTTPHandler("/object/", ...) on a standalone region
  57. /// server will register a handler that can be invoked with either
  58. ///
  59. /// http://localhost:9000/?method=/object/
  60. ///
  61. /// or
  62. ///
  63. /// http://localhost:9000/object/
  64. ///
  65. /// In addition, the handler invoked by the HTTP server for any request is the one when best matches the request
  66. /// URI. So if a handler for "/myapp/" is registered and a request for "/myapp/page" is received, then
  67. /// the "/myapp/" handler is invoked if no "/myapp/page" handler exists.
  68. /// </remarks>
  69. /// <param name="methodName"></param>
  70. /// <param name="handler"></param>
  71. /// <returns>
  72. /// true if the handler was successfully registered, false if a handler with the same name already existed.
  73. /// </returns>
  74. bool AddHTTPHandler(string methodName, GenericHTTPMethod handler);
  75. bool AddPollServiceHTTPHandler(string methodName, PollServiceEventArgs args);
  76. /// <summary>
  77. /// Adds a LLSD handler, yay.
  78. /// </summary>
  79. /// <param name="path">/resource/ path</param>
  80. /// <param name="handler">handle the LLSD response</param>
  81. /// <returns></returns>
  82. bool AddLLSDHandler(string path, LLSDMethod handler);
  83. /// <summary>
  84. /// Add a stream handler to the http server. If the handler already exists, then nothing happens.
  85. /// </summary>
  86. /// <param name="handler"></param>
  87. void AddStreamHandler(IRequestHandler handler);
  88. bool AddXmlRPCHandler(string method, XmlRpcMethod handler);
  89. bool AddXmlRPCHandler(string method, XmlRpcMethod handler, bool keepAlive);
  90. /// <summary>
  91. /// Gets the XML RPC handler for given method name
  92. /// </summary>
  93. /// <param name="method">Name of the method</param>
  94. /// <returns>Returns null if not found</returns>
  95. XmlRpcMethod GetXmlRPCHandler(string method);
  96. bool SetDefaultLLSDHandler(DefaultLLSDMethod handler);
  97. /// <summary>
  98. /// Remove the agent if it is registered.
  99. /// </summary>
  100. /// <param name="agent"></param>
  101. /// <param name="handler"></param>
  102. /// <returns></returns>
  103. bool RemoveAgentHandler(string agent, IHttpAgentHandler handler);
  104. /// <summary>
  105. /// Remove an HTTP handler
  106. /// </summary>
  107. /// <param name="httpMethod"></param>
  108. /// <param name="path"></param>
  109. void RemoveHTTPHandler(string httpMethod, string path);
  110. void RemovePollServiceHTTPHandler(string httpMethod, string path);
  111. bool RemoveLLSDHandler(string path, LLSDMethod handler);
  112. void RemoveStreamHandler(string httpMethod, string path);
  113. void RemoveXmlRPCHandler(string method);
  114. string GetHTTP404(string host);
  115. string GetHTTP500();
  116. }
  117. }