29 using System.Collections.Generic;
30 using System.Reflection;
34 using OpenSim.Framework;
35 using OpenSim.Framework.Console;
36 using OpenSim.Framework.Servers.HttpServer;
38 namespace OpenSim.Framework.Servers
45 private static Dictionary<uint, BaseHttpServer> m_Servers =
new Dictionary<uint, BaseHttpServer>();
58 public static int DebugLevel
60 get {
return s_debugLevel; }
67 server.DebugLevel = s_debugLevel;
71 private static int s_debugLevel;
84 get {
return instance; }
89 if (!m_Servers.ContainsValue(value))
90 throw new Exception(
"HTTP server must already have been registered to be set as the main instance");
103 public static Dictionary<uint, BaseHttpServer> Servers
105 get {
return new Dictionary<uint, BaseHttpServer>(m_Servers); }
110 console.Commands.AddCommand(
111 "Comms",
false,
"show http-handlers",
112 "show http-handlers",
113 "Show all registered http handlers", HandleShowHttpHandlersCommand);
115 console.Commands.AddCommand(
116 "Debug",
false,
"debug http",
"debug http <in|out|all> [<level>]",
117 "Turn on http request logging.",
119 +
" level <= 0 then no extra logging is done.\n"
120 +
" level >= 1 then short warnings are logged when receiving bad input data.\n"
121 +
" level >= 2 then long warnings are logged when receiving bad input data.\n"
122 +
" level >= 3 then short notices about all incoming non-poll HTTP requests are logged.\n"
123 +
" level >= 4 then the time taken to fulfill the request is logged.\n"
124 +
" level >= 5 then a sample from the beginning of the data is logged.\n"
125 +
" level >= 6 then the entire data is logged.\n"
126 +
" no level is specified then the current level is returned.\n\n"
127 +
"If out or all and\n"
128 +
" level >= 3 then short notices about all outgoing requests going through WebUtil are logged.\n"
129 +
" level >= 4 then the time taken to fulfill the request is logged.\n"
130 +
" level >= 5 then a sample from the beginning of the data is logged.\n"
131 +
" level >= 6 then the entire data is logged.\n",
132 HandleDebugHttpCommand);
139 private static void HandleDebugHttpCommand(
string module,
string[] cmdparams)
141 if (cmdparams.Length < 3)
143 MainConsole.Instance.Output(
"Usage: debug http <in|out|all> 0..6");
148 bool outReqs =
false;
149 bool allReqs =
false;
151 string subCommand = cmdparams[2];
153 if (subCommand.ToLower() ==
"in")
157 else if (subCommand.ToLower() ==
"out")
161 else if (subCommand.ToLower() ==
"all")
167 MainConsole.Instance.Output(
"You must specify in, out or all");
171 if (cmdparams.Length >= 4)
173 string rawNewDebug = cmdparams[3];
176 if (!
int.TryParse(rawNewDebug, out newDebug))
178 MainConsole.Instance.OutputFormat(
"{0} is not a valid debug level", rawNewDebug);
182 if (newDebug < 0 || newDebug > 6)
184 MainConsole.Instance.OutputFormat(
"{0} is outside the valid debug level range of 0..6", newDebug);
188 if (allReqs || inReqs)
190 MainServer.DebugLevel = newDebug;
191 MainConsole.Instance.OutputFormat(
"IN debug level set to {0}", newDebug);
194 if (allReqs || outReqs)
196 WebUtil.DebugLevel = newDebug;
197 MainConsole.Instance.OutputFormat(
"OUT debug level set to {0}", newDebug);
202 if (allReqs || inReqs)
203 MainConsole.Instance.OutputFormat(
"Current IN debug level is {0}", MainServer.DebugLevel);
205 if (allReqs || outReqs)
206 MainConsole.Instance.OutputFormat(
"Current OUT debug level is {0}", WebUtil.DebugLevel);
210 private static void HandleShowHttpHandlersCommand(
string module,
string[] args)
212 if (args.Length != 2)
214 MainConsole.Instance.Output(
"Usage: show http-handlers");
218 StringBuilder handlers =
new StringBuilder();
224 handlers.AppendFormat(
225 "Registered HTTP Handlers for server at {0}:{1}\n", httpServer.ListenIPAddress, httpServer.Port);
227 handlers.AppendFormat(
"* XMLRPC:\n");
229 handlers.AppendFormat(
"\t{0}\n", s);
231 handlers.AppendFormat(
"* HTTP:\n");
233 handlers.AppendFormat(
"\t{0}\n", s);
235 handlers.AppendFormat(
"* HTTP (poll):\n");
237 handlers.AppendFormat(
"\t{0}\n", s);
239 handlers.AppendFormat(
"* JSONRPC:\n");
241 handlers.AppendFormat(
"\t{0}\n", s);
247 handlers.AppendFormat(
"* LLSD:\n");
249 handlers.AppendFormat(
"\t{0}\n", s);
251 handlers.AppendFormat(
"* StreamHandlers ({0}):\n", httpServer.GetStreamHandlerKeys().Count);
253 handlers.AppendFormat(
"\t{0}\n", s);
255 handlers.Append(
"\n");
259 MainConsole.Instance.Output(handlers.ToString());
270 if (m_Servers.ContainsKey(server.
Port))
271 throw new Exception(
string.Format(
"HTTP server for port {0} already exists.", server.
Port));
273 m_Servers.Add(server.Port, server);
289 if (instance != null && instance.Port == port)
292 return m_Servers.Remove(port);
307 return m_Servers.ContainsKey(port);
320 return GetHttpServer(port, null);
338 if (instance != null && port == Instance.Port)
343 if (m_Servers.ContainsKey(port))
344 return m_Servers[port];
349 m_Servers[port].ListenIPAddress = ipaddr;
351 m_Servers[port].Start();
353 return m_Servers[port];
static void AddHttpServer(BaseHttpServer server)
Register an already started HTTP server to the collection of known servers.
List< string > GetXmlRpcHandlerKeys()
List< string > GetJsonRpcHandlerKeys()
List< string > GetHTTPHandlerKeys()
List< string > GetLLSDHandlerKeys()
List< string > GetStreamHandlerKeys()
Interface to OpenSimulator's built in HTTP server. Use this to register handlers (http, llsd, xmlrpc, etc.) for given URLs.
List< string > GetPollServiceHandlerKeys()
static IHttpServer GetHttpServer(uint port)
Get the default http server or an http server for a specific port.
static bool ContainsHttpServer(uint port)
Does this collection of servers contain one with the given port?
static void RegisterHttpConsoleCommands(ICommandConsole console)
static IHttpServer GetHttpServer(uint port, IPAddress ipaddr)
Get the default http server, an http server for a specific port and/or an http server bound to a spec...
static bool RemoveHttpServer(uint port)
Removes the http server listening on the given port.