diff options
author | Melanie | 2012-06-15 02:53:34 +0100 |
---|---|---|
committer | Melanie | 2012-06-15 02:53:34 +0100 |
commit | 30d872caadc063e15a48c77e40c83dded8b4400e (patch) | |
tree | 92b0dcb17d7851f7c4b27887d5960c273bf0cef1 /OpenSim/Framework/Servers | |
parent | Merge branch 'master' into careminster (diff) | |
parent | Make the "debug http" command available for robust as well as the simulator. ... (diff) | |
download | opensim-SC-30d872caadc063e15a48c77e40c83dded8b4400e.zip opensim-SC-30d872caadc063e15a48c77e40c83dded8b4400e.tar.gz opensim-SC-30d872caadc063e15a48c77e40c83dded8b4400e.tar.bz2 opensim-SC-30d872caadc063e15a48c77e40c83dded8b4400e.tar.xz |
Merge branch 'master' into careminster
Diffstat (limited to 'OpenSim/Framework/Servers')
-rw-r--r-- | OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs | 40 | ||||
-rw-r--r-- | OpenSim/Framework/Servers/MainServer.cs | 184 |
2 files changed, 195 insertions, 29 deletions
diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index 31af44c..1d5b426 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs | |||
@@ -53,6 +53,8 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
53 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 53 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
54 | private HttpServerLogWriter httpserverlog = new HttpServerLogWriter(); | 54 | private HttpServerLogWriter httpserverlog = new HttpServerLogWriter(); |
55 | 55 | ||
56 | public int DebugLevel { get; set; } | ||
57 | |||
56 | private volatile int NotSocketErrors = 0; | 58 | private volatile int NotSocketErrors = 0; |
57 | public volatile bool HTTPDRunning = false; | 59 | public volatile bool HTTPDRunning = false; |
58 | 60 | ||
@@ -79,11 +81,6 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
79 | 81 | ||
80 | private PollServiceRequestManager m_PollServiceManager; | 82 | private PollServiceRequestManager m_PollServiceManager; |
81 | 83 | ||
82 | /// <summary> | ||
83 | /// Control the printing of certain debug messages. | ||
84 | /// </summary> | ||
85 | public int DebugLevel { get; set; } | ||
86 | |||
87 | public uint SSLPort | 84 | public uint SSLPort |
88 | { | 85 | { |
89 | get { return m_sslport; } | 86 | get { return m_sslport; } |
@@ -450,7 +447,7 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
450 | 447 | ||
451 | if (TryGetStreamHandler(handlerKey, out requestHandler)) | 448 | if (TryGetStreamHandler(handlerKey, out requestHandler)) |
452 | { | 449 | { |
453 | if (DebugLevel >= 1) | 450 | if (DebugLevel >= 3) |
454 | m_log.DebugFormat( | 451 | m_log.DebugFormat( |
455 | "[BASE HTTP SERVER]: Found stream handler for {0} {1} {2} {3}", | 452 | "[BASE HTTP SERVER]: Found stream handler for {0} {1} {2} {3}", |
456 | request.HttpMethod, request.Url.PathAndQuery, requestHandler.Name, requestHandler.Description); | 453 | request.HttpMethod, request.Url.PathAndQuery, requestHandler.Name, requestHandler.Description); |
@@ -531,7 +528,7 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
531 | case null: | 528 | case null: |
532 | case "text/html": | 529 | case "text/html": |
533 | 530 | ||
534 | if (DebugLevel >= 1) | 531 | if (DebugLevel >= 3) |
535 | m_log.DebugFormat( | 532 | m_log.DebugFormat( |
536 | "[BASE HTTP SERVER]: Found a {0} content type handler for {1} {2}", | 533 | "[BASE HTTP SERVER]: Found a {0} content type handler for {1} {2}", |
537 | request.ContentType, request.HttpMethod, request.Url.PathAndQuery); | 534 | request.ContentType, request.HttpMethod, request.Url.PathAndQuery); |
@@ -543,7 +540,7 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
543 | case "application/xml+llsd": | 540 | case "application/xml+llsd": |
544 | case "application/llsd+json": | 541 | case "application/llsd+json": |
545 | 542 | ||
546 | if (DebugLevel >= 1) | 543 | if (DebugLevel >= 3) |
547 | m_log.DebugFormat( | 544 | m_log.DebugFormat( |
548 | "[BASE HTTP SERVER]: Found a {0} content type handler for {1} {2}", | 545 | "[BASE HTTP SERVER]: Found a {0} content type handler for {1} {2}", |
549 | request.ContentType, request.HttpMethod, request.Url.PathAndQuery); | 546 | request.ContentType, request.HttpMethod, request.Url.PathAndQuery); |
@@ -564,7 +561,7 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
564 | //m_log.Info("[Debug BASE HTTP SERVER]: Checking for LLSD Handler"); | 561 | //m_log.Info("[Debug BASE HTTP SERVER]: Checking for LLSD Handler"); |
565 | if (DoWeHaveALLSDHandler(request.RawUrl)) | 562 | if (DoWeHaveALLSDHandler(request.RawUrl)) |
566 | { | 563 | { |
567 | if (DebugLevel >= 1) | 564 | if (DebugLevel >= 3) |
568 | m_log.DebugFormat( | 565 | m_log.DebugFormat( |
569 | "[BASE HTTP SERVER]: Found a {0} content type handler for {1} {2}", | 566 | "[BASE HTTP SERVER]: Found a {0} content type handler for {1} {2}", |
570 | request.ContentType, request.HttpMethod, request.Url.PathAndQuery); | 567 | request.ContentType, request.HttpMethod, request.Url.PathAndQuery); |
@@ -574,7 +571,7 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
574 | // m_log.DebugFormat("[BASE HTTP SERVER]: Checking for HTTP Handler for request {0}", request.RawUrl); | 571 | // m_log.DebugFormat("[BASE HTTP SERVER]: Checking for HTTP Handler for request {0}", request.RawUrl); |
575 | else if (DoWeHaveAHTTPHandler(request.RawUrl)) | 572 | else if (DoWeHaveAHTTPHandler(request.RawUrl)) |
576 | { | 573 | { |
577 | if (DebugLevel >= 1) | 574 | if (DebugLevel >= 3) |
578 | m_log.DebugFormat( | 575 | m_log.DebugFormat( |
579 | "[BASE HTTP SERVER]: Found a {0} content type handler for {1} {2}", | 576 | "[BASE HTTP SERVER]: Found a {0} content type handler for {1} {2}", |
580 | request.ContentType, request.HttpMethod, request.Url.PathAndQuery); | 577 | request.ContentType, request.HttpMethod, request.Url.PathAndQuery); |
@@ -583,8 +580,7 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
583 | } | 580 | } |
584 | else | 581 | else |
585 | { | 582 | { |
586 | 583 | if (DebugLevel >= 3) | |
587 | if (DebugLevel >= 1) | ||
588 | m_log.DebugFormat( | 584 | m_log.DebugFormat( |
589 | "[BASE HTTP SERVER]: Assuming a generic XMLRPC request for {0} {1}", | 585 | "[BASE HTTP SERVER]: Assuming a generic XMLRPC request for {0} {1}", |
590 | request.HttpMethod, request.Url.PathAndQuery); | 586 | request.HttpMethod, request.Url.PathAndQuery); |
@@ -793,8 +789,23 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
793 | { | 789 | { |
794 | xmlRprcRequest = (XmlRpcRequest) (new XmlRpcRequestDeserializer()).Deserialize(requestBody); | 790 | xmlRprcRequest = (XmlRpcRequest) (new XmlRpcRequestDeserializer()).Deserialize(requestBody); |
795 | } | 791 | } |
796 | catch (XmlException) | 792 | catch (XmlException e) |
797 | { | 793 | { |
794 | if (DebugLevel >= 1) | ||
795 | { | ||
796 | if (DebugLevel >= 2) | ||
797 | m_log.Warn( | ||
798 | string.Format( | ||
799 | "[BASE HTTP SERVER]: Got XMLRPC request with invalid XML from {0}. XML was '{1}'. Sending blank response. Exception ", | ||
800 | request.RemoteIPEndPoint, requestBody), | ||
801 | e); | ||
802 | else | ||
803 | { | ||
804 | m_log.WarnFormat( | ||
805 | "[BASE HTTP SERVER]: Got XMLRPC request with invalid XML from {0}, length {1}. Sending blank response.", | ||
806 | request.RemoteIPEndPoint, requestBody.Length); | ||
807 | } | ||
808 | } | ||
798 | } | 809 | } |
799 | 810 | ||
800 | if (xmlRprcRequest != null) | 811 | if (xmlRprcRequest != null) |
@@ -1570,6 +1581,9 @@ namespace OpenSim.Framework.Servers.HttpServer | |||
1570 | 1581 | ||
1571 | private void StartHTTP() | 1582 | private void StartHTTP() |
1572 | { | 1583 | { |
1584 | m_log.InfoFormat( | ||
1585 | "[BASE HTTP SERVER]: Starting {0} server on port {1}", UseSSL ? "HTTPS" : "HTTP", Port); | ||
1586 | |||
1573 | try | 1587 | try |
1574 | { | 1588 | { |
1575 | //m_httpListener = new HttpListener(); | 1589 | //m_httpListener = new HttpListener(); |
diff --git a/OpenSim/Framework/Servers/MainServer.cs b/OpenSim/Framework/Servers/MainServer.cs index b8ab8d9..07ff60c 100644 --- a/OpenSim/Framework/Servers/MainServer.cs +++ b/OpenSim/Framework/Servers/MainServer.cs | |||
@@ -25,57 +25,209 @@ | |||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | ||
28 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
29 | using System.Reflection; | 30 | using System.Reflection; |
30 | using System.Net; | 31 | using System.Net; |
31 | using log4net; | 32 | using log4net; |
33 | using OpenSim.Framework; | ||
34 | using OpenSim.Framework.Console; | ||
32 | using OpenSim.Framework.Servers.HttpServer; | 35 | using OpenSim.Framework.Servers.HttpServer; |
33 | 36 | ||
34 | namespace OpenSim.Framework.Servers | 37 | namespace OpenSim.Framework.Servers |
35 | { | 38 | { |
36 | public class MainServer | 39 | public class MainServer |
37 | { | 40 | { |
38 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 41 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
39 | 42 | ||
40 | private static BaseHttpServer instance = null; | 43 | private static BaseHttpServer instance = null; |
41 | private static Dictionary<uint, BaseHttpServer> m_Servers = | 44 | private static Dictionary<uint, BaseHttpServer> m_Servers = new Dictionary<uint, BaseHttpServer>(); |
42 | new Dictionary<uint, BaseHttpServer>(); | ||
43 | 45 | ||
46 | /// <summary> | ||
47 | /// Control the printing of certain debug messages. | ||
48 | /// </summary> | ||
49 | /// <remarks> | ||
50 | /// If DebugLevel >= 1, then short warnings are logged when receiving bad input data. | ||
51 | /// If DebugLevel >= 2, then long warnings are logged when receiving bad input data. | ||
52 | /// If DebugLevel >= 3, then short notices about all incoming non-poll HTTP requests are logged. | ||
53 | /// </remarks> | ||
54 | public static int DebugLevel | ||
55 | { | ||
56 | get { return s_debugLevel; } | ||
57 | set | ||
58 | { | ||
59 | s_debugLevel = value; | ||
60 | |||
61 | lock (m_Servers) | ||
62 | foreach (BaseHttpServer server in m_Servers.Values) | ||
63 | server.DebugLevel = s_debugLevel; | ||
64 | } | ||
65 | } | ||
66 | |||
67 | private static int s_debugLevel; | ||
68 | |||
69 | /// <summary> | ||
70 | /// Set the main HTTP server instance. | ||
71 | /// </summary> | ||
72 | /// <remarks> | ||
73 | /// This will be used to register all handlers that listen to the default port. | ||
74 | /// </remarks> | ||
75 | /// <exception cref='Exception'> | ||
76 | /// Thrown if the HTTP server has not already been registered via AddHttpServer() | ||
77 | /// </exception> | ||
44 | public static BaseHttpServer Instance | 78 | public static BaseHttpServer Instance |
45 | { | 79 | { |
46 | get { return instance; } | 80 | get { return instance; } |
47 | set { instance = value; } | 81 | |
82 | set | ||
83 | { | ||
84 | lock (m_Servers) | ||
85 | if (!m_Servers.ContainsValue(value)) | ||
86 | throw new Exception("HTTP server must already have been registered to be set as the main instance"); | ||
87 | |||
88 | instance = value; | ||
89 | } | ||
48 | } | 90 | } |
49 | 91 | ||
50 | public static IHttpServer GetHttpServer(uint port) | 92 | /// <summary> |
93 | /// Get all the registered servers. | ||
94 | /// </summary> | ||
95 | /// <remarks> | ||
96 | /// Returns a copy of the dictionary so this can be iterated through without locking. | ||
97 | /// </remarks> | ||
98 | /// <value></value> | ||
99 | public static Dictionary<uint, BaseHttpServer> Servers | ||
100 | { | ||
101 | get { return new Dictionary<uint, BaseHttpServer>(m_Servers); } | ||
102 | } | ||
103 | |||
104 | |||
105 | public static void RegisterHttpConsoleCommands(ICommandConsole console) | ||
106 | { | ||
107 | console.Commands.AddCommand( | ||
108 | "Comms", false, "debug http", "debug http [<level>]", | ||
109 | "Turn on inbound non-poll http request debugging.", | ||
110 | "If level <= 0, then no extra logging is done.\n" | ||
111 | + "If level >= 1, then short warnings are logged when receiving bad input data.\n" | ||
112 | + "If level >= 2, then long warnings are logged when receiving bad input data.\n" | ||
113 | + "If level >= 3, then short notices about all incoming non-poll HTTP requests are logged.\n" | ||
114 | + "If no level is specified then the current level is returned.", | ||
115 | HandleDebugHttpCommand); | ||
116 | } | ||
117 | |||
118 | /// <summary> | ||
119 | /// Turn on some debugging values for OpenSim. | ||
120 | /// </summary> | ||
121 | /// <param name="args"></param> | ||
122 | private static void HandleDebugHttpCommand(string module, string[] args) | ||
51 | { | 123 | { |
52 | return GetHttpServer(port,null); | 124 | if (args.Length == 3) |
125 | { | ||
126 | int newDebug; | ||
127 | if (int.TryParse(args[2], out newDebug)) | ||
128 | { | ||
129 | MainServer.DebugLevel = newDebug; | ||
130 | MainConsole.Instance.OutputFormat("Debug http level set to {0}", newDebug); | ||
131 | } | ||
132 | } | ||
133 | else if (args.Length == 2) | ||
134 | { | ||
135 | MainConsole.Instance.OutputFormat("Current debug http level is {0}", MainServer.DebugLevel); | ||
136 | } | ||
137 | else | ||
138 | { | ||
139 | MainConsole.Instance.Output("Usage: debug http 0..3"); | ||
140 | } | ||
53 | } | 141 | } |
54 | 142 | ||
143 | /// <summary> | ||
144 | /// Register an already started HTTP server to the collection of known servers. | ||
145 | /// </summary> | ||
146 | /// <param name='server'></param> | ||
55 | public static void AddHttpServer(BaseHttpServer server) | 147 | public static void AddHttpServer(BaseHttpServer server) |
56 | { | 148 | { |
57 | m_Servers.Add(server.Port, server); | 149 | lock (m_Servers) |
150 | { | ||
151 | if (m_Servers.ContainsKey(server.Port)) | ||
152 | throw new Exception(string.Format("HTTP server for port {0} already exists.", server.Port)); | ||
153 | |||
154 | m_Servers.Add(server.Port, server); | ||
155 | } | ||
156 | } | ||
157 | |||
158 | /// <summary> | ||
159 | /// Removes the http server listening on the given port. | ||
160 | /// </summary> | ||
161 | /// <remarks> | ||
162 | /// It is the responsibility of the caller to do clean up. | ||
163 | /// </remarks> | ||
164 | /// <param name='port'></param> | ||
165 | /// <returns></returns> | ||
166 | public static bool RemoveHttpServer(uint port) | ||
167 | { | ||
168 | lock (m_Servers) | ||
169 | return m_Servers.Remove(port); | ||
170 | } | ||
171 | |||
172 | /// <summary> | ||
173 | /// Does this collection of servers contain one with the given port? | ||
174 | /// </summary> | ||
175 | /// <remarks> | ||
176 | /// Unlike GetHttpServer, this will not instantiate a server if one does not exist on that port. | ||
177 | /// </remarks> | ||
178 | /// <param name='port'></param> | ||
179 | /// <returns>true if a server with the given port is registered, false otherwise.</returns> | ||
180 | public static bool ContainsHttpServer(uint port) | ||
181 | { | ||
182 | lock (m_Servers) | ||
183 | return m_Servers.ContainsKey(port); | ||
58 | } | 184 | } |
59 | 185 | ||
186 | /// <summary> | ||
187 | /// Get the default http server or an http server for a specific port. | ||
188 | /// </summary> | ||
189 | /// <remarks> | ||
190 | /// If the requested HTTP server doesn't already exist then a new one is instantiated and started. | ||
191 | /// </remarks> | ||
192 | /// <returns></returns> | ||
193 | /// <param name='port'>If 0 then the default HTTP server is returned.</param> | ||
194 | public static IHttpServer GetHttpServer(uint port) | ||
195 | { | ||
196 | return GetHttpServer(port, null); | ||
197 | } | ||
198 | |||
199 | /// <summary> | ||
200 | /// Get the default http server, an http server for a specific port | ||
201 | /// and/or an http server bound to a specific address | ||
202 | /// </summary> | ||
203 | /// <remarks> | ||
204 | /// If the requested HTTP server doesn't already exist then a new one is instantiated and started. | ||
205 | /// </remarks> | ||
206 | /// <returns></returns> | ||
207 | /// <param name='port'>If 0 then the default HTTP server is returned.</param> | ||
208 | /// <param name='ipaddr'>A specific IP address to bind to. If null then the default IP address is used.</param> | ||
60 | public static IHttpServer GetHttpServer(uint port, IPAddress ipaddr) | 209 | public static IHttpServer GetHttpServer(uint port, IPAddress ipaddr) |
61 | { | 210 | { |
62 | if (port == 0) | 211 | if (port == 0) |
63 | return Instance; | 212 | return Instance; |
213 | |||
64 | if (instance != null && port == Instance.Port) | 214 | if (instance != null && port == Instance.Port) |
65 | return Instance; | 215 | return Instance; |
66 | 216 | ||
67 | if (m_Servers.ContainsKey(port)) | 217 | lock (m_Servers) |
68 | return m_Servers[port]; | 218 | { |
219 | if (m_Servers.ContainsKey(port)) | ||
220 | return m_Servers[port]; | ||
69 | 221 | ||
70 | m_Servers[port] = new BaseHttpServer(port); | 222 | m_Servers[port] = new BaseHttpServer(port); |
71 | 223 | ||
72 | if (ipaddr != null) | 224 | if (ipaddr != null) |
73 | m_Servers[port].ListenIPAddress = ipaddr; | 225 | m_Servers[port].ListenIPAddress = ipaddr; |
74 | 226 | ||
75 | m_log.InfoFormat("[MAIN HTTP SERVER]: Starting main http server on port {0}", port); | 227 | m_Servers[port].Start(); |
76 | m_Servers[port].Start(); | ||
77 | 228 | ||
78 | return m_Servers[port]; | 229 | return m_Servers[port]; |
230 | } | ||
79 | } | 231 | } |
80 | } | 232 | } |
81 | } | 233 | } \ No newline at end of file |