1
0

IHttpServer.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. bool AddJsonRPCHandler(string method, JsonRPCMethod handler);
  91. /// <summary>
  92. /// Websocket HTTP server handlers.
  93. /// </summary>
  94. /// <param name="servicepath"></param>
  95. /// <param name="handler"></param>
  96. void AddWebSocketHandler(string servicepath, BaseHttpServer.WebSocketRequestDelegate handler);
  97. void RemoveWebSocketHandler(string servicepath);
  98. /// <summary>
  99. /// Gets the XML RPC handler for given method name
  100. /// </summary>
  101. /// <param name="method">Name of the method</param>
  102. /// <returns>Returns null if not found</returns>
  103. XmlRpcMethod GetXmlRPCHandler(string method);
  104. bool SetDefaultLLSDHandler(DefaultLLSDMethod handler);
  105. // /// <summary>
  106. // /// Remove the agent if it is registered.
  107. // /// </summary>
  108. // /// <param name="agent"></param>
  109. // /// <param name="handler"></param>
  110. // /// <returns></returns>
  111. // bool RemoveAgentHandler(string agent, IHttpAgentHandler handler);
  112. /// <summary>
  113. /// Remove an HTTP handler
  114. /// </summary>
  115. /// <param name="httpMethod"></param>
  116. /// <param name="path"></param>
  117. void RemoveHTTPHandler(string httpMethod, string path);
  118. void RemovePollServiceHTTPHandler(string httpMethod, string path);
  119. bool RemoveLLSDHandler(string path, LLSDMethod handler);
  120. void RemoveStreamHandler(string httpMethod, string path);
  121. void RemoveXmlRPCHandler(string method);
  122. void RemoveJsonRPCHandler(string method);
  123. string GetHTTP404(string host);
  124. string GetHTTP500();
  125. }
  126. }