IHttpServer.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 uripath, PollServiceEventArgs args);
  76. bool AddPollServiceHTTPHandler(PollServiceEventArgs args);
  77. void RemovePollServiceHTTPHandler(string url, string path);
  78. void RemovePollServiceHTTPHandler(string path);
  79. /// <summary>
  80. /// Adds a LLSD handler, yay.
  81. /// </summary>
  82. /// <param name="path">/resource/ path</param>
  83. /// <param name="handler">handle the LLSD response</param>
  84. /// <returns></returns>
  85. bool AddLLSDHandler(string path, LLSDMethod handler);
  86. /// <summary>
  87. /// Add a stream handler to the http server. If the handler already exists, then nothing happens.
  88. /// </summary>
  89. /// <param name="handler"></param>
  90. void AddStreamHandler(IRequestHandler handler);
  91. void AddSimpleStreamHandler(ISimpleStreamHandler handler, bool varPath = false);
  92. bool AddXmlRPCHandler(string method, XmlRpcMethod handler);
  93. bool AddXmlRPCHandler(string method, XmlRpcMethod handler, bool keepAlive);
  94. bool AddJsonRPCHandler(string method, JsonRPCMethod handler);
  95. /// <summary>
  96. /// Websocket HTTP server handlers.
  97. /// </summary>
  98. /// <param name="servicepath"></param>
  99. /// <param name="handler"></param>
  100. void AddWebSocketHandler(string servicepath, BaseHttpServer.WebSocketRequestDelegate handler);
  101. void RemoveWebSocketHandler(string servicepath);
  102. /// <summary>
  103. /// Gets the XML RPC handler for given method name
  104. /// </summary>
  105. /// <param name="method">Name of the method</param>
  106. /// <returns>Returns null if not found</returns>
  107. XmlRpcMethod GetXmlRPCHandler(string method);
  108. bool SetDefaultLLSDHandler(DefaultLLSDMethod handler);
  109. // /// <summary>
  110. // /// Remove the agent if it is registered.
  111. // /// </summary>
  112. // /// <param name="agent"></param>
  113. // /// <param name="handler"></param>
  114. // /// <returns></returns>
  115. // bool RemoveAgentHandler(string agent, IHttpAgentHandler handler);
  116. /// <summary>
  117. /// Remove an HTTP handler
  118. /// </summary>
  119. /// <param name="httpMethod"></param>
  120. /// <param name="path"></param>
  121. void RemoveHTTPHandler(string httpMethod, string path);
  122. bool RemoveLLSDHandler(string path, LLSDMethod handler);
  123. void RemoveStreamHandler(string httpMethod, string path);
  124. void RemoveSimpleStreamHandler(string path);
  125. void RemoveXmlRPCHandler(string method);
  126. void RemoveJsonRPCHandler(string method);
  127. string GetHTTP404();
  128. void AddIndexPHPMethodHandler(string key, SimpleStreamMethod sh);
  129. void RemoveIndexPHPMethodHandler(string key);
  130. SimpleStreamMethod TryGetIndexPHPMethodHandler(string key);
  131. }
  132. }