BaseHttpServer.cs 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968
  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 System;
  28. using System.Collections;
  29. using System.Collections.Generic;
  30. using System.Collections.Specialized;
  31. using System.IO;
  32. using System.Net;
  33. using System.Net.Sockets;
  34. using System.Security.Cryptography.X509Certificates;
  35. using System.Reflection;
  36. using System.Globalization;
  37. using System.Text;
  38. using System.Threading;
  39. using System.Xml;
  40. using HttpServer;
  41. using log4net;
  42. using Nwc.XmlRpc;
  43. using OpenMetaverse.StructuredData;
  44. using CoolHTTPListener = HttpServer.HttpListener;
  45. using HttpListener=System.Net.HttpListener;
  46. using LogPrio=HttpServer.LogPrio;
  47. namespace OpenSim.Framework.Servers.HttpServer
  48. {
  49. public class BaseHttpServer : IHttpServer
  50. {
  51. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  52. private HttpServerLogWriter httpserverlog = new HttpServerLogWriter();
  53. private volatile int NotSocketErrors = 0;
  54. public volatile bool HTTPDRunning = false;
  55. // protected HttpListener m_httpListener;
  56. protected CoolHTTPListener m_httpListener2;
  57. protected Dictionary<string, XmlRpcMethod> m_rpcHandlers = new Dictionary<string, XmlRpcMethod>();
  58. protected Dictionary<string, bool> m_rpcHandlersKeepAlive = new Dictionary<string, bool>();
  59. protected DefaultLLSDMethod m_defaultLlsdHandler = null; // <-- Moving away from the monolithic.. and going to /registered/
  60. protected Dictionary<string, LLSDMethod> m_llsdHandlers = new Dictionary<string, LLSDMethod>();
  61. protected Dictionary<string, IRequestHandler> m_streamHandlers = new Dictionary<string, IRequestHandler>();
  62. protected Dictionary<string, GenericHTTPMethod> m_HTTPHandlers = new Dictionary<string, GenericHTTPMethod>();
  63. protected Dictionary<string, IHttpAgentHandler> m_agentHandlers = new Dictionary<string, IHttpAgentHandler>();
  64. protected Dictionary<string, PollServiceEventArgs> m_pollHandlers =
  65. new Dictionary<string, PollServiceEventArgs>();
  66. protected uint m_port;
  67. protected uint m_sslport;
  68. protected bool m_ssl;
  69. private X509Certificate2 m_cert;
  70. protected bool m_firstcaps = true;
  71. protected string m_SSLCommonName = "";
  72. protected IPAddress m_listenIPAddress = IPAddress.Any;
  73. private PollServiceRequestManager m_PollServiceManager;
  74. public uint SSLPort
  75. {
  76. get { return m_sslport; }
  77. }
  78. public string SSLCommonName
  79. {
  80. get { return m_SSLCommonName; }
  81. }
  82. public uint Port
  83. {
  84. get { return m_port; }
  85. }
  86. public bool UseSSL
  87. {
  88. get { return m_ssl; }
  89. }
  90. public IPAddress ListenIPAddress
  91. {
  92. get { return m_listenIPAddress; }
  93. set { m_listenIPAddress = value; }
  94. }
  95. public BaseHttpServer(uint port)
  96. {
  97. m_port = port;
  98. }
  99. public BaseHttpServer(uint port, bool ssl) : this (port)
  100. {
  101. m_ssl = ssl;
  102. }
  103. public BaseHttpServer(uint port, bool ssl, uint sslport, string CN) : this (port, ssl)
  104. {
  105. if (m_ssl)
  106. {
  107. m_sslport = sslport;
  108. }
  109. }
  110. public BaseHttpServer(uint port, bool ssl, string CPath, string CPass) : this (port, ssl)
  111. {
  112. if (m_ssl)
  113. {
  114. m_cert = new X509Certificate2(CPath, CPass);
  115. }
  116. }
  117. /// <summary>
  118. /// Add a stream handler to the http server. If the handler already exists, then nothing happens.
  119. /// </summary>
  120. /// <param name="handler"></param>
  121. public void AddStreamHandler(IRequestHandler handler)
  122. {
  123. string httpMethod = handler.HttpMethod;
  124. string path = handler.Path;
  125. string handlerKey = GetHandlerKey(httpMethod, path);
  126. lock (m_streamHandlers)
  127. {
  128. if (!m_streamHandlers.ContainsKey(handlerKey))
  129. {
  130. // m_log.DebugFormat("[BASE HTTP SERVER]: Adding handler key {0}", handlerKey);
  131. m_streamHandlers.Add(handlerKey, handler);
  132. }
  133. }
  134. }
  135. public List<string> GetStreamHandlerKeys()
  136. {
  137. lock (m_streamHandlers)
  138. return new List<string>(m_streamHandlers.Keys);
  139. }
  140. private static string GetHandlerKey(string httpMethod, string path)
  141. {
  142. return httpMethod + ":" + path;
  143. }
  144. public bool AddXmlRPCHandler(string method, XmlRpcMethod handler)
  145. {
  146. return AddXmlRPCHandler(method, handler, true);
  147. }
  148. public bool AddXmlRPCHandler(string method, XmlRpcMethod handler, bool keepAlive)
  149. {
  150. lock (m_rpcHandlers)
  151. {
  152. m_rpcHandlers[method] = handler;
  153. m_rpcHandlersKeepAlive[method] = keepAlive; // default
  154. }
  155. return true;
  156. }
  157. public XmlRpcMethod GetXmlRPCHandler(string method)
  158. {
  159. lock (m_rpcHandlers)
  160. {
  161. if (m_rpcHandlers.ContainsKey(method))
  162. {
  163. return m_rpcHandlers[method];
  164. }
  165. else
  166. {
  167. return null;
  168. }
  169. }
  170. }
  171. public List<string> GetXmlRpcHandlerKeys()
  172. {
  173. lock (m_rpcHandlers)
  174. return new List<string>(m_rpcHandlers.Keys);
  175. }
  176. public bool AddHTTPHandler(string methodName, GenericHTTPMethod handler)
  177. {
  178. //m_log.DebugFormat("[BASE HTTP SERVER]: Registering {0}", methodName);
  179. lock (m_HTTPHandlers)
  180. {
  181. if (!m_HTTPHandlers.ContainsKey(methodName))
  182. {
  183. m_HTTPHandlers.Add(methodName, handler);
  184. return true;
  185. }
  186. }
  187. //must already have a handler for that path so return false
  188. return false;
  189. }
  190. public List<string> GetHTTPHandlerKeys()
  191. {
  192. lock (m_HTTPHandlers)
  193. return new List<string>(m_HTTPHandlers.Keys);
  194. }
  195. public bool AddPollServiceHTTPHandler(string methodName, GenericHTTPMethod handler, PollServiceEventArgs args)
  196. {
  197. bool pollHandlerResult = false;
  198. lock (m_pollHandlers)
  199. {
  200. if (!m_pollHandlers.ContainsKey(methodName))
  201. {
  202. m_pollHandlers.Add(methodName,args);
  203. pollHandlerResult = true;
  204. }
  205. }
  206. if (pollHandlerResult)
  207. return AddHTTPHandler(methodName, handler);
  208. return false;
  209. }
  210. public List<string> GetPollServiceHandlerKeys()
  211. {
  212. lock (m_pollHandlers)
  213. return new List<string>(m_pollHandlers.Keys);
  214. }
  215. // Note that the agent string is provided simply to differentiate
  216. // the handlers - it is NOT required to be an actual agent header
  217. // value.
  218. public bool AddAgentHandler(string agent, IHttpAgentHandler handler)
  219. {
  220. lock (m_agentHandlers)
  221. {
  222. if (!m_agentHandlers.ContainsKey(agent))
  223. {
  224. m_agentHandlers.Add(agent, handler);
  225. return true;
  226. }
  227. }
  228. //must already have a handler for that path so return false
  229. return false;
  230. }
  231. public List<string> GetAgentHandlerKeys()
  232. {
  233. lock (m_agentHandlers)
  234. return new List<string>(m_agentHandlers.Keys);
  235. }
  236. public bool AddLLSDHandler(string path, LLSDMethod handler)
  237. {
  238. lock (m_llsdHandlers)
  239. {
  240. if (!m_llsdHandlers.ContainsKey(path))
  241. {
  242. m_llsdHandlers.Add(path, handler);
  243. return true;
  244. }
  245. }
  246. return false;
  247. }
  248. public List<string> GetLLSDHandlerKeys()
  249. {
  250. lock (m_llsdHandlers)
  251. return new List<string>(m_llsdHandlers.Keys);
  252. }
  253. public bool SetDefaultLLSDHandler(DefaultLLSDMethod handler)
  254. {
  255. m_defaultLlsdHandler = handler;
  256. return true;
  257. }
  258. private void OnRequest(object source, RequestEventArgs args)
  259. {
  260. try
  261. {
  262. IHttpClientContext context = (IHttpClientContext)source;
  263. IHttpRequest request = args.Request;
  264. PollServiceEventArgs psEvArgs;
  265. if (TryGetPollServiceHTTPHandler(request.UriPath.ToString(), out psEvArgs))
  266. {
  267. PollServiceHttpRequest psreq = new PollServiceHttpRequest(psEvArgs, context, request);
  268. if (psEvArgs.Request != null)
  269. {
  270. OSHttpRequest req = new OSHttpRequest(context, request);
  271. Stream requestStream = req.InputStream;
  272. Encoding encoding = Encoding.UTF8;
  273. StreamReader reader = new StreamReader(requestStream, encoding);
  274. string requestBody = reader.ReadToEnd();
  275. Hashtable keysvals = new Hashtable();
  276. Hashtable headervals = new Hashtable();
  277. string[] querystringkeys = req.QueryString.AllKeys;
  278. string[] rHeaders = req.Headers.AllKeys;
  279. keysvals.Add("body", requestBody);
  280. keysvals.Add("uri", req.RawUrl);
  281. keysvals.Add("content-type", req.ContentType);
  282. keysvals.Add("http-method", req.HttpMethod);
  283. foreach (string queryname in querystringkeys)
  284. {
  285. keysvals.Add(queryname, req.QueryString[queryname]);
  286. }
  287. foreach (string headername in rHeaders)
  288. {
  289. headervals[headername] = req.Headers[headername];
  290. }
  291. keysvals.Add("headers", headervals);
  292. keysvals.Add("querystringkeys", querystringkeys);
  293. psEvArgs.Request(psreq.RequestID, keysvals);
  294. }
  295. m_PollServiceManager.Enqueue(psreq);
  296. }
  297. else
  298. {
  299. OnHandleRequestIOThread(context, request);
  300. }
  301. }
  302. catch (Exception e)
  303. {
  304. m_log.ErrorFormat("[BASE HTTP SERVER]: OnRequest() failed with {0}{1}", e.Message, e.StackTrace);
  305. }
  306. }
  307. public void OnHandleRequestIOThread(IHttpClientContext context, IHttpRequest request)
  308. {
  309. OSHttpRequest req = new OSHttpRequest(context, request);
  310. OSHttpResponse resp = new OSHttpResponse(new HttpResponse(context, request),context);
  311. HandleRequest(req, resp);
  312. // !!!HACK ALERT!!!
  313. // There seems to be a bug in the underlying http code that makes subsequent requests
  314. // come up with trash in Accept headers. Until that gets fixed, we're cleaning them up here.
  315. if (request.AcceptTypes != null)
  316. for (int i = 0; i < request.AcceptTypes.Length; i++)
  317. request.AcceptTypes[i] = string.Empty;
  318. }
  319. // public void ConvertIHttpClientContextToOSHttp(object stateinfo)
  320. // {
  321. // HttpServerContextObj objstate = (HttpServerContextObj)stateinfo;
  322. // OSHttpRequest request = objstate.oreq;
  323. // OSHttpResponse resp = objstate.oresp;
  324. // HandleRequest(request,resp);
  325. // }
  326. /// <summary>
  327. /// This methods is the start of incoming HTTP request handling.
  328. /// </summary>
  329. /// <param name="request"></param>
  330. /// <param name="response"></param>
  331. public virtual void HandleRequest(OSHttpRequest request, OSHttpResponse response)
  332. {
  333. if (request.HttpMethod == String.Empty) // Can't handle empty requests, not wasting a thread
  334. {
  335. try
  336. {
  337. SendHTML500(response);
  338. }
  339. catch
  340. {
  341. }
  342. return;
  343. }
  344. string requestMethod = request.HttpMethod;
  345. string uriString = request.RawUrl;
  346. // string reqnum = "unknown";
  347. int tickstart = Environment.TickCount;
  348. try
  349. {
  350. // OpenSim.Framework.WebUtil.OSHeaderRequestID
  351. // if (request.Headers["opensim-request-id"] != null)
  352. // reqnum = String.Format("{0}:{1}",request.RemoteIPEndPoint,request.Headers["opensim-request-id"]);
  353. //m_log.DebugFormat("[BASE HTTP SERVER]: <{0}> handle request for {1}",reqnum,request.RawUrl);
  354. Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US", true);
  355. // This is the REST agent interface. We require an agent to properly identify
  356. // itself. If the REST handler recognizes the prefix it will attempt to
  357. // satisfy the request. If it is not recognizable, and no damage has occurred
  358. // the request can be passed through to the other handlers. This is a low
  359. // probability event; if a request is matched it is normally expected to be
  360. // handled
  361. IHttpAgentHandler agentHandler;
  362. if (TryGetAgentHandler(request, response, out agentHandler))
  363. {
  364. if (HandleAgentRequest(agentHandler, request, response))
  365. {
  366. return;
  367. }
  368. }
  369. //response.KeepAlive = true;
  370. response.SendChunked = false;
  371. IRequestHandler requestHandler;
  372. string path = request.RawUrl;
  373. string handlerKey = GetHandlerKey(request.HttpMethod, path);
  374. //m_log.DebugFormat("[BASE HTTP SERVER]: Handling {0} request for {1}", request.HttpMethod, path);
  375. if (TryGetStreamHandler(handlerKey, out requestHandler))
  376. {
  377. //m_log.Debug("[BASE HTTP SERVER]: Found Stream Handler");
  378. // Okay, so this is bad, but should be considered temporary until everything is IStreamHandler.
  379. byte[] buffer = null;
  380. response.ContentType = requestHandler.ContentType; // Lets do this defaulting before in case handler has varying content type.
  381. if (requestHandler is IStreamedRequestHandler)
  382. {
  383. IStreamedRequestHandler streamedRequestHandler = requestHandler as IStreamedRequestHandler;
  384. buffer = streamedRequestHandler.Handle(path, request.InputStream, request, response);
  385. }
  386. else if (requestHandler is IGenericHTTPHandler)
  387. {
  388. //m_log.Debug("[BASE HTTP SERVER]: Found Caps based HTTP Handler");
  389. IGenericHTTPHandler HTTPRequestHandler = requestHandler as IGenericHTTPHandler;
  390. Stream requestStream = request.InputStream;
  391. Encoding encoding = Encoding.UTF8;
  392. StreamReader reader = new StreamReader(requestStream, encoding);
  393. string requestBody = reader.ReadToEnd();
  394. reader.Close();
  395. //requestStream.Close();
  396. Hashtable keysvals = new Hashtable();
  397. Hashtable headervals = new Hashtable();
  398. //string host = String.Empty;
  399. string[] querystringkeys = request.QueryString.AllKeys;
  400. string[] rHeaders = request.Headers.AllKeys;
  401. foreach (string queryname in querystringkeys)
  402. {
  403. keysvals.Add(queryname, request.QueryString[queryname]);
  404. }
  405. foreach (string headername in rHeaders)
  406. {
  407. //m_log.Warn("[HEADER]: " + headername + "=" + request.Headers[headername]);
  408. headervals[headername] = request.Headers[headername];
  409. }
  410. // if (headervals.Contains("Host"))
  411. // {
  412. // host = (string)headervals["Host"];
  413. // }
  414. keysvals.Add("requestbody", requestBody);
  415. keysvals.Add("headers",headervals);
  416. if (keysvals.Contains("method"))
  417. {
  418. //m_log.Warn("[HTTP]: Contains Method");
  419. //string method = (string)keysvals["method"];
  420. //m_log.Warn("[HTTP]: " + requestBody);
  421. }
  422. DoHTTPGruntWork(HTTPRequestHandler.Handle(path, keysvals), response);
  423. return;
  424. }
  425. else
  426. {
  427. IStreamHandler streamHandler = (IStreamHandler)requestHandler;
  428. using (MemoryStream memoryStream = new MemoryStream())
  429. {
  430. streamHandler.Handle(path, request.InputStream, memoryStream, request, response);
  431. memoryStream.Flush();
  432. buffer = memoryStream.ToArray();
  433. }
  434. }
  435. request.InputStream.Close();
  436. // HTTP IN support. The script engine takes it from here
  437. // Nothing to worry about for us.
  438. //
  439. if (buffer == null)
  440. return;
  441. if (!response.SendChunked)
  442. response.ContentLength64 = buffer.LongLength;
  443. try
  444. {
  445. response.OutputStream.Write(buffer, 0, buffer.Length);
  446. //response.OutputStream.Close();
  447. }
  448. catch (HttpListenerException)
  449. {
  450. m_log.WarnFormat("[BASE HTTP SERVER]: HTTP request abnormally terminated.");
  451. }
  452. //response.OutputStream.Close();
  453. try
  454. {
  455. response.Send();
  456. //response.FreeContext();
  457. }
  458. catch (SocketException e)
  459. {
  460. // This has to be here to prevent a Linux/Mono crash
  461. m_log.WarnFormat("[BASE HTTP SERVER]: XmlRpcRequest issue {0}.\nNOTE: this may be spurious on Linux.", e);
  462. }
  463. catch (IOException e)
  464. {
  465. m_log.Warn("[BASE HTTP SERVER]: XmlRpcRequest issue: " + e.Message);
  466. }
  467. return;
  468. }
  469. if (request.AcceptTypes != null && request.AcceptTypes.Length > 0)
  470. {
  471. foreach (string strAccept in request.AcceptTypes)
  472. {
  473. if (strAccept.Contains("application/llsd+xml") ||
  474. strAccept.Contains("application/llsd+json"))
  475. {
  476. //m_log.Info("[Debug BASE HTTP SERVER]: Found an application/llsd+xml accept header");
  477. HandleLLSDRequests(request, response);
  478. return;
  479. }
  480. }
  481. }
  482. switch (request.ContentType)
  483. {
  484. case null:
  485. case "text/html":
  486. // m_log.DebugFormat(
  487. // "[BASE HTTP SERVER]: Found a text/html content type for request {0}", request.RawUrl);
  488. HandleHTTPRequest(request, response);
  489. return;
  490. case "application/llsd+xml":
  491. case "application/xml+llsd":
  492. case "application/llsd+json":
  493. //m_log.Info("[Debug BASE HTTP SERVER]: found a application/llsd+xml content type");
  494. HandleLLSDRequests(request, response);
  495. return;
  496. case "text/xml":
  497. case "application/xml":
  498. case "application/json":
  499. default:
  500. //m_log.Info("[Debug BASE HTTP SERVER]: in default handler");
  501. // Point of note.. the DoWeHaveA methods check for an EXACT path
  502. // if (request.RawUrl.Contains("/CAPS/EQG"))
  503. // {
  504. // int i = 1;
  505. // }
  506. //m_log.Info("[Debug BASE HTTP SERVER]: Checking for LLSD Handler");
  507. if (DoWeHaveALLSDHandler(request.RawUrl))
  508. {
  509. //m_log.Info("[Debug BASE HTTP SERVER]: Found LLSD Handler");
  510. HandleLLSDRequests(request, response);
  511. return;
  512. }
  513. // m_log.DebugFormat("[BASE HTTP SERVER]: Checking for HTTP Handler for request {0}", request.RawUrl);
  514. if (DoWeHaveAHTTPHandler(request.RawUrl))
  515. {
  516. // m_log.DebugFormat("[BASE HTTP SERVER]: Found HTTP Handler for request {0}", request.RawUrl);
  517. HandleHTTPRequest(request, response);
  518. return;
  519. }
  520. //m_log.Info("[Debug BASE HTTP SERVER]: Generic XMLRPC");
  521. // generic login request.
  522. HandleXmlRpcRequests(request, response);
  523. return;
  524. }
  525. }
  526. catch (SocketException e)
  527. {
  528. // At least on linux, it appears that if the client makes a request without requiring the response,
  529. // an unconnected socket exception is thrown when we close the response output stream. There's no
  530. // obvious way to tell if the client didn't require the response, so instead we'll catch and ignore
  531. // the exception instead.
  532. //
  533. // An alternative may be to turn off all response write exceptions on the HttpListener, but let's go
  534. // with the minimum first
  535. m_log.WarnFormat("[BASE HTTP SERVER]: HandleRequest threw {0}.\nNOTE: this may be spurious on Linux", e);
  536. }
  537. catch (IOException e)
  538. {
  539. m_log.ErrorFormat("[BASE HTTP SERVER]: HandleRequest() threw ", e);
  540. }
  541. catch (Exception e)
  542. {
  543. m_log.ErrorFormat("[BASE HTTP SERVER]: HandleRequest() threw " + e.ToString());
  544. SendHTML500(response);
  545. }
  546. finally
  547. {
  548. // Every month or so this will wrap and give bad numbers, not really a problem
  549. // since its just for reporting, tickdiff limit can be adjusted
  550. int tickdiff = Environment.TickCount - tickstart;
  551. if (tickdiff > 3000)
  552. m_log.InfoFormat(
  553. "[BASE HTTP SERVER]: slow {0} request for {1} from {2} took {3} ms", requestMethod, uriString, request.RemoteIPEndPoint.ToString(), tickdiff);
  554. }
  555. }
  556. private bool TryGetStreamHandler(string handlerKey, out IRequestHandler streamHandler)
  557. {
  558. string bestMatch = null;
  559. lock (m_streamHandlers)
  560. {
  561. foreach (string pattern in m_streamHandlers.Keys)
  562. {
  563. if (handlerKey.StartsWith(pattern))
  564. {
  565. if (String.IsNullOrEmpty(bestMatch) || pattern.Length > bestMatch.Length)
  566. {
  567. bestMatch = pattern;
  568. }
  569. }
  570. }
  571. if (String.IsNullOrEmpty(bestMatch))
  572. {
  573. streamHandler = null;
  574. return false;
  575. }
  576. else
  577. {
  578. streamHandler = m_streamHandlers[bestMatch];
  579. return true;
  580. }
  581. }
  582. }
  583. private bool TryGetPollServiceHTTPHandler(string handlerKey, out PollServiceEventArgs oServiceEventArgs)
  584. {
  585. string bestMatch = null;
  586. lock (m_pollHandlers)
  587. {
  588. foreach (string pattern in m_pollHandlers.Keys)
  589. {
  590. if (handlerKey.StartsWith(pattern))
  591. {
  592. if (String.IsNullOrEmpty(bestMatch) || pattern.Length > bestMatch.Length)
  593. {
  594. bestMatch = pattern;
  595. }
  596. }
  597. }
  598. if (String.IsNullOrEmpty(bestMatch))
  599. {
  600. oServiceEventArgs = null;
  601. return false;
  602. }
  603. else
  604. {
  605. oServiceEventArgs = m_pollHandlers[bestMatch];
  606. return true;
  607. }
  608. }
  609. }
  610. private bool TryGetHTTPHandler(string handlerKey, out GenericHTTPMethod HTTPHandler)
  611. {
  612. // m_log.DebugFormat("[BASE HTTP HANDLER]: Looking for HTTP handler for {0}", handlerKey);
  613. string bestMatch = null;
  614. lock (m_HTTPHandlers)
  615. {
  616. foreach (string pattern in m_HTTPHandlers.Keys)
  617. {
  618. if (handlerKey.StartsWith(pattern))
  619. {
  620. if (String.IsNullOrEmpty(bestMatch) || pattern.Length > bestMatch.Length)
  621. {
  622. bestMatch = pattern;
  623. }
  624. }
  625. }
  626. if (String.IsNullOrEmpty(bestMatch))
  627. {
  628. HTTPHandler = null;
  629. return false;
  630. }
  631. else
  632. {
  633. HTTPHandler = m_HTTPHandlers[bestMatch];
  634. return true;
  635. }
  636. }
  637. }
  638. private bool TryGetAgentHandler(OSHttpRequest request, OSHttpResponse response, out IHttpAgentHandler agentHandler)
  639. {
  640. agentHandler = null;
  641. lock (m_agentHandlers)
  642. {
  643. foreach (IHttpAgentHandler handler in m_agentHandlers.Values)
  644. {
  645. if (handler.Match(request, response))
  646. {
  647. agentHandler = handler;
  648. return true;
  649. }
  650. }
  651. }
  652. return false;
  653. }
  654. /// <summary>
  655. /// Try all the registered xmlrpc handlers when an xmlrpc request is received.
  656. /// Sends back an XMLRPC unknown request response if no handler is registered for the requested method.
  657. /// </summary>
  658. /// <param name="request"></param>
  659. /// <param name="response"></param>
  660. private void HandleXmlRpcRequests(OSHttpRequest request, OSHttpResponse response)
  661. {
  662. Stream requestStream = request.InputStream;
  663. Encoding encoding = Encoding.UTF8;
  664. StreamReader reader = new StreamReader(requestStream, encoding);
  665. string requestBody = reader.ReadToEnd();
  666. reader.Close();
  667. requestStream.Close();
  668. //m_log.Debug(requestBody);
  669. requestBody = requestBody.Replace("<base64></base64>", "");
  670. string responseString = String.Empty;
  671. XmlRpcRequest xmlRprcRequest = null;
  672. try
  673. {
  674. xmlRprcRequest = (XmlRpcRequest) (new XmlRpcRequestDeserializer()).Deserialize(requestBody);
  675. }
  676. catch (XmlException)
  677. {
  678. }
  679. if (xmlRprcRequest != null)
  680. {
  681. string methodName = xmlRprcRequest.MethodName;
  682. if (methodName != null)
  683. {
  684. xmlRprcRequest.Params.Add(request.RemoteIPEndPoint); // Param[1]
  685. XmlRpcResponse xmlRpcResponse;
  686. XmlRpcMethod method;
  687. bool methodWasFound;
  688. bool keepAlive = false;
  689. lock (m_rpcHandlers)
  690. {
  691. methodWasFound = m_rpcHandlers.TryGetValue(methodName, out method);
  692. if (methodWasFound)
  693. keepAlive = m_rpcHandlersKeepAlive[methodName];
  694. }
  695. if (methodWasFound)
  696. {
  697. xmlRprcRequest.Params.Add(request.Url); // Param[2]
  698. string xff = "X-Forwarded-For";
  699. string xfflower = xff.ToLower();
  700. foreach (string s in request.Headers.AllKeys)
  701. {
  702. if (s != null && s.Equals(xfflower))
  703. {
  704. xff = xfflower;
  705. break;
  706. }
  707. }
  708. xmlRprcRequest.Params.Add(request.Headers.Get(xff)); // Param[3]
  709. try
  710. {
  711. xmlRpcResponse = method(xmlRprcRequest, request.RemoteIPEndPoint);
  712. }
  713. catch(Exception e)
  714. {
  715. string errorMessage
  716. = String.Format(
  717. "Requested method [{0}] from {1} threw exception: {2} {3}",
  718. methodName, request.RemoteIPEndPoint.Address, e.Message, e.StackTrace);
  719. m_log.ErrorFormat("[BASE HTTP SERVER]: {0}", errorMessage);
  720. // if the registered XmlRpc method threw an exception, we pass a fault-code along
  721. xmlRpcResponse = new XmlRpcResponse();
  722. // Code probably set in accordance with http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php
  723. xmlRpcResponse.SetFault(-32603, errorMessage);
  724. }
  725. // if the method wasn't found, we can't determine KeepAlive state anyway, so lets do it only here
  726. response.KeepAlive = keepAlive;
  727. }
  728. else
  729. {
  730. xmlRpcResponse = new XmlRpcResponse();
  731. // Code set in accordance with http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php
  732. xmlRpcResponse.SetFault(
  733. XmlRpcErrorCodes.SERVER_ERROR_METHOD,
  734. String.Format("Requested method [{0}] not found", methodName));
  735. }
  736. responseString = XmlRpcResponseSerializer.Singleton.Serialize(xmlRpcResponse);
  737. }
  738. else
  739. {
  740. //HandleLLSDRequests(request, response);
  741. response.ContentType = "text/plain";
  742. response.StatusCode = 404;
  743. response.StatusDescription = "Not Found";
  744. response.ProtocolVersion = "HTTP/1.0";
  745. byte[] buf = Encoding.UTF8.GetBytes("Not found");
  746. response.KeepAlive = false;
  747. m_log.ErrorFormat("[BASE HTTP SERVER]: Handler not found for http request {0}", request.RawUrl);
  748. response.SendChunked = false;
  749. response.ContentLength64 = buf.Length;
  750. response.ContentEncoding = Encoding.UTF8;
  751. try
  752. {
  753. response.OutputStream.Write(buf, 0, buf.Length);
  754. }
  755. catch (Exception ex)
  756. {
  757. m_log.Warn("[BASE HTTP SERVER]: Error - " + ex.Message);
  758. }
  759. finally
  760. {
  761. try
  762. {
  763. response.Send();
  764. //response.FreeContext();
  765. }
  766. catch (SocketException e)
  767. {
  768. // This has to be here to prevent a Linux/Mono crash
  769. m_log.WarnFormat("[BASE HTTP SERVER]: XmlRpcRequest issue {0}.\nNOTE: this may be spurious on Linux.", e);
  770. }
  771. catch (IOException e)
  772. {
  773. m_log.Warn("[BASE HTTP SERVER]: XmlRpcRequest issue: " + e.Message);
  774. }
  775. }
  776. return;
  777. //responseString = "Error";
  778. }
  779. }
  780. response.ContentType = "text/xml";
  781. byte[] buffer = Encoding.UTF8.GetBytes(responseString);
  782. response.SendChunked = false;
  783. response.ContentLength64 = buffer.Length;
  784. response.ContentEncoding = Encoding.UTF8;
  785. try
  786. {
  787. response.OutputStream.Write(buffer, 0, buffer.Length);
  788. }
  789. catch (Exception ex)
  790. {
  791. m_log.Warn("[BASE HTTP SERVER]: Error - " + ex.Message);
  792. }
  793. finally
  794. {
  795. try
  796. {
  797. response.Send();
  798. //response.FreeContext();
  799. }
  800. catch (SocketException e)
  801. {
  802. // This has to be here to prevent a Linux/Mono crash
  803. m_log.WarnFormat("[BASE HTTP SERVER]: XmlRpcRequest issue {0}.\nNOTE: this may be spurious on Linux.", e);
  804. }
  805. catch (IOException e)
  806. {
  807. m_log.Warn("[BASE HTTP SERVER]: XmlRpcRequest issue: " + e.Message);
  808. }
  809. }
  810. }
  811. private void HandleLLSDRequests(OSHttpRequest request, OSHttpResponse response)
  812. {
  813. //m_log.Warn("[BASE HTTP SERVER]: We've figured out it's a LLSD Request");
  814. Stream requestStream = request.InputStream;
  815. Encoding encoding = Encoding.UTF8;
  816. StreamReader reader = new StreamReader(requestStream, encoding);
  817. string requestBody = reader.ReadToEnd();
  818. reader.Close();
  819. requestStream.Close();
  820. //m_log.DebugFormat("[OGP]: {0}:{1}", request.RawUrl, requestBody);
  821. response.KeepAlive = true;
  822. OSD llsdRequest = null;
  823. OSD llsdResponse = null;
  824. bool LegacyLLSDLoginLibOMV = (requestBody.Contains("passwd") && requestBody.Contains("mac") && requestBody.Contains("viewer_digest"));
  825. if (requestBody.Length == 0)
  826. // Get Request
  827. {
  828. requestBody = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><llsd><map><key>request</key><string>get</string></map></llsd>";
  829. }
  830. try
  831. {
  832. llsdRequest = OSDParser.Deserialize(requestBody);
  833. }
  834. catch (Exception ex)
  835. {
  836. m_log.Warn("[BASE HTTP SERVER]: Error - " + ex.Message);
  837. }
  838. if (llsdRequest != null)// && m_defaultLlsdHandler != null)
  839. {
  840. LLSDMethod llsdhandler = null;
  841. if (TryGetLLSDHandler(request.RawUrl, out llsdhandler) && !LegacyLLSDLoginLibOMV)
  842. {
  843. // we found a registered llsd handler to service this request
  844. llsdResponse = llsdhandler(request.RawUrl, llsdRequest, request.RemoteIPEndPoint.ToString());
  845. }
  846. else
  847. {
  848. // we didn't find a registered llsd handler to service this request
  849. // check if we have a default llsd handler
  850. if (m_defaultLlsdHandler != null)
  851. {
  852. // LibOMV path
  853. llsdResponse = m_defaultLlsdHandler(llsdRequest, request.RemoteIPEndPoint);
  854. }
  855. else
  856. {
  857. // Oops, no handler for this.. give em the failed message
  858. llsdResponse = GenerateNoLLSDHandlerResponse();
  859. }
  860. }
  861. }
  862. else
  863. {
  864. llsdResponse = GenerateNoLLSDHandlerResponse();
  865. }
  866. byte[] buffer = new byte[0];
  867. if (llsdResponse.ToString() == "shutdown404!")
  868. {
  869. response.ContentType = "text/plain";
  870. response.StatusCode = 404;
  871. response.StatusDescription = "Not Found";
  872. response.ProtocolVersion = "HTTP/1.0";
  873. buffer = Encoding.UTF8.GetBytes("Not found");
  874. }
  875. else
  876. {
  877. // Select an appropriate response format
  878. buffer = BuildLLSDResponse(request, response, llsdResponse);
  879. }
  880. response.SendChunked = false;
  881. response.ContentLength64 = buffer.Length;
  882. response.ContentEncoding = Encoding.UTF8;
  883. response.KeepAlive = true;
  884. try
  885. {
  886. response.OutputStream.Write(buffer, 0, buffer.Length);
  887. }
  888. catch (Exception ex)
  889. {
  890. m_log.Warn("[BASE HTTP SERVER]: Error - " + ex.Message);
  891. }
  892. finally
  893. {
  894. //response.OutputStream.Close();
  895. try
  896. {
  897. response.Send();
  898. response.OutputStream.Flush();
  899. //response.FreeContext();
  900. //response.OutputStream.Close();
  901. }
  902. catch (IOException e)
  903. {
  904. m_log.WarnFormat("[BASE HTTP SERVER]: LLSD IOException {0}.", e);
  905. }
  906. catch (SocketException e)
  907. {
  908. // This has to be here to prevent a Linux/Mono crash
  909. m_log.WarnFormat("[BASE HTTP SERVER]: LLSD issue {0}.\nNOTE: this may be spurious on Linux.", e);
  910. }
  911. }
  912. }
  913. private byte[] BuildLLSDResponse(OSHttpRequest request, OSHttpResponse response, OSD llsdResponse)
  914. {
  915. if (request.AcceptTypes != null && request.AcceptTypes.Length > 0)
  916. {
  917. foreach (string strAccept in request.AcceptTypes)
  918. {
  919. switch (strAccept)
  920. {
  921. case "application/llsd+xml":
  922. case "application/xml":
  923. case "text/xml":
  924. response.ContentType = strAccept;
  925. return OSDParser.SerializeLLSDXmlBytes(llsdResponse);
  926. case "application/llsd+json":
  927. case "application/json":
  928. response.ContentType = strAccept;
  929. return Encoding.UTF8.GetBytes(OSDParser.SerializeJsonString(llsdResponse));
  930. }
  931. }
  932. }
  933. if (!String.IsNullOrEmpty(request.ContentType))
  934. {
  935. switch (request.ContentType)
  936. {
  937. case "application/llsd+xml":
  938. case "application/xml":
  939. case "text/xml":
  940. response.ContentType = request.ContentType;
  941. return OSDParser.SerializeLLSDXmlBytes(llsdResponse);
  942. case "application/llsd+json":
  943. case "application/json":
  944. response.ContentType = request.ContentType;
  945. return Encoding.UTF8.GetBytes(OSDParser.SerializeJsonString(llsdResponse));
  946. }
  947. }
  948. // response.ContentType = "application/llsd+json";
  949. // return Util.UTF8.GetBytes(OSDParser.SerializeJsonString(llsdResponse));
  950. response.ContentType = "application/llsd+xml";
  951. return OSDParser.SerializeLLSDXmlBytes(llsdResponse);
  952. }
  953. /// <summary>
  954. /// Checks if we have an Exact path in the LLSD handlers for the path provided
  955. /// </summary>
  956. /// <param name="path">URI of the request</param>
  957. /// <returns>true if we have one, false if not</returns>
  958. private bool DoWeHaveALLSDHandler(string path)
  959. {
  960. string[] pathbase = path.Split('/');
  961. string searchquery = "/";
  962. if (pathbase.Length < 1)
  963. return false;
  964. for (int i = 1; i < pathbase.Length; i++)
  965. {
  966. searchquery += pathbase[i];
  967. if (pathbase.Length - 1 != i)
  968. searchquery += "/";
  969. }
  970. string bestMatch = null;
  971. lock (m_llsdHandlers)
  972. {
  973. foreach (string pattern in m_llsdHandlers.Keys)
  974. {
  975. if (searchquery.StartsWith(pattern) && searchquery.Length >= pattern.Length)
  976. bestMatch = pattern;
  977. }
  978. }
  979. // extra kicker to remove the default XMLRPC login case.. just in case..
  980. if (path != "/" && bestMatch == "/" && searchquery != "/")
  981. return false;
  982. if (path == "/")
  983. return false;
  984. if (String.IsNullOrEmpty(bestMatch))
  985. {
  986. return false;
  987. }
  988. else
  989. {
  990. return true;
  991. }
  992. }
  993. /// <summary>
  994. /// Checks if we have an Exact path in the HTTP handlers for the path provided
  995. /// </summary>
  996. /// <param name="path">URI of the request</param>
  997. /// <returns>true if we have one, false if not</returns>
  998. private bool DoWeHaveAHTTPHandler(string path)
  999. {
  1000. string[] pathbase = path.Split('/');
  1001. string searchquery = "/";
  1002. if (pathbase.Length < 1)
  1003. return false;
  1004. for (int i = 1; i < pathbase.Length; i++)
  1005. {
  1006. searchquery += pathbase[i];
  1007. if (pathbase.Length - 1 != i)
  1008. searchquery += "/";
  1009. }
  1010. string bestMatch = null;
  1011. //m_log.DebugFormat("[BASE HTTP HANDLER]: Checking if we have an HTTP handler for {0}", searchquery);
  1012. lock (m_HTTPHandlers)
  1013. {
  1014. foreach (string pattern in m_HTTPHandlers.Keys)
  1015. {
  1016. if (searchquery.StartsWith(pattern) && searchquery.Length >= pattern.Length)
  1017. {
  1018. bestMatch = pattern;
  1019. }
  1020. }
  1021. // extra kicker to remove the default XMLRPC login case.. just in case..
  1022. if (path == "/")
  1023. return false;
  1024. if (String.IsNullOrEmpty(bestMatch))
  1025. {
  1026. return false;
  1027. }
  1028. else
  1029. {
  1030. return true;
  1031. }
  1032. }
  1033. }
  1034. private bool TryGetLLSDHandler(string path, out LLSDMethod llsdHandler)
  1035. {
  1036. llsdHandler = null;
  1037. // Pull out the first part of the path
  1038. // splitting the path by '/' means we'll get the following return..
  1039. // {0}/{1}/{2}
  1040. // where {0} isn't something we really control 100%
  1041. string[] pathbase = path.Split('/');
  1042. string searchquery = "/";
  1043. if (pathbase.Length < 1)
  1044. return false;
  1045. for (int i=1; i<pathbase.Length; i++)
  1046. {
  1047. searchquery += pathbase[i];
  1048. if (pathbase.Length-1 != i)
  1049. searchquery += "/";
  1050. }
  1051. // while the matching algorithm below doesn't require it, we're expecting a query in the form
  1052. //
  1053. // [] = optional
  1054. // /resource/UUID/action[/action]
  1055. //
  1056. // now try to get the closest match to the reigstered path
  1057. // at least for OGP, registered path would probably only consist of the /resource/
  1058. string bestMatch = null;
  1059. lock (m_llsdHandlers)
  1060. {
  1061. foreach (string pattern in m_llsdHandlers.Keys)
  1062. {
  1063. if (searchquery.ToLower().StartsWith(pattern.ToLower()))
  1064. {
  1065. if (String.IsNullOrEmpty(bestMatch) || searchquery.Length > bestMatch.Length)
  1066. {
  1067. // You have to specifically register for '/' and to get it, you must specificaly request it
  1068. //
  1069. if (pattern == "/" && searchquery == "/" || pattern != "/")
  1070. bestMatch = pattern;
  1071. }
  1072. }
  1073. }
  1074. if (String.IsNullOrEmpty(bestMatch))
  1075. {
  1076. llsdHandler = null;
  1077. return false;
  1078. }
  1079. else
  1080. {
  1081. llsdHandler = m_llsdHandlers[bestMatch];
  1082. return true;
  1083. }
  1084. }
  1085. }
  1086. private OSDMap GenerateNoLLSDHandlerResponse()
  1087. {
  1088. OSDMap map = new OSDMap();
  1089. map["reason"] = OSD.FromString("LLSDRequest");
  1090. map["message"] = OSD.FromString("No handler registered for LLSD Requests");
  1091. map["login"] = OSD.FromString("false");
  1092. return map;
  1093. }
  1094. /// <summary>
  1095. /// A specific agent handler was provided. Such a handler is expecetd to have an
  1096. /// intimate, and highly specific relationship with the client. Consequently,
  1097. /// nothing is done here.
  1098. /// </summary>
  1099. /// <param name="handler"></param>
  1100. /// <param name="request"></param>
  1101. /// <param name="response"></param>
  1102. private bool HandleAgentRequest(IHttpAgentHandler handler, OSHttpRequest request, OSHttpResponse response)
  1103. {
  1104. // In the case of REST, then handler is responsible for ALL aspects of
  1105. // the request/response handling. Nothing is done here, not even encoding.
  1106. try
  1107. {
  1108. return handler.Handle(request, response);
  1109. }
  1110. catch (Exception e)
  1111. {
  1112. // If the handler did in fact close the stream, then this will blow
  1113. // chunks. So that that doesn't disturb anybody we throw away any
  1114. // and all exceptions raised. We've done our best to release the
  1115. // client.
  1116. try
  1117. {
  1118. m_log.Warn("[HTTP-AGENT]: Error - " + e.Message);
  1119. response.SendChunked = false;
  1120. response.KeepAlive = true;
  1121. response.StatusCode = (int)OSHttpStatusCode.ServerErrorInternalError;
  1122. //response.OutputStream.Close();
  1123. try
  1124. {
  1125. response.Send();
  1126. //response.FreeContext();
  1127. }
  1128. catch (SocketException f)
  1129. {
  1130. // This has to be here to prevent a Linux/Mono crash
  1131. m_log.WarnFormat(
  1132. "[BASE HTTP SERVER]: XmlRpcRequest issue {0}.\nNOTE: this may be spurious on Linux.", f);
  1133. }
  1134. }
  1135. catch(Exception)
  1136. {
  1137. }
  1138. }
  1139. // Indicate that the request has been "handled"
  1140. return true;
  1141. }
  1142. public void HandleHTTPRequest(OSHttpRequest request, OSHttpResponse response)
  1143. {
  1144. // m_log.DebugFormat(
  1145. // "[BASE HTTP SERVER]: HandleHTTPRequest for request to {0}, method {1}",
  1146. // request.RawUrl, request.HttpMethod);
  1147. switch (request.HttpMethod)
  1148. {
  1149. case "OPTIONS":
  1150. response.StatusCode = (int)OSHttpStatusCode.SuccessOk;
  1151. return;
  1152. default:
  1153. HandleContentVerbs(request, response);
  1154. return;
  1155. }
  1156. }
  1157. private void HandleContentVerbs(OSHttpRequest request, OSHttpResponse response)
  1158. {
  1159. // m_log.DebugFormat("[BASE HTTP SERVER]: HandleContentVerbs for request to {0}", request.RawUrl);
  1160. // This is a test. There's a workable alternative.. as this way sucks.
  1161. // We'd like to put this into a text file parhaps that's easily editable.
  1162. //
  1163. // For this test to work, I used the following secondlife.exe parameters
  1164. // "C:\Program Files\SecondLifeWindLight\SecondLifeWindLight.exe" -settings settings_windlight.xml -channel "Second Life WindLight" -set SystemLanguage en-us -loginpage http://10.1.1.2:8002/?show_login_form=TRUE -loginuri http://10.1.1.2:8002 -user 10.1.1.2
  1165. //
  1166. // Even after all that, there's still an error, but it's a start.
  1167. //
  1168. // I depend on show_login_form being in the secondlife.exe parameters to figure out
  1169. // to display the form, or process it.
  1170. // a better way would be nifty.
  1171. Stream requestStream = request.InputStream;
  1172. Encoding encoding = Encoding.UTF8;
  1173. StreamReader reader = new StreamReader(requestStream, encoding);
  1174. string requestBody = reader.ReadToEnd();
  1175. // avoid warning for now
  1176. reader.ReadToEnd();
  1177. reader.Close();
  1178. requestStream.Close();
  1179. Hashtable keysvals = new Hashtable();
  1180. Hashtable headervals = new Hashtable();
  1181. Hashtable requestVars = new Hashtable();
  1182. string host = String.Empty;
  1183. string[] querystringkeys = request.QueryString.AllKeys;
  1184. string[] rHeaders = request.Headers.AllKeys;
  1185. keysvals.Add("body", requestBody);
  1186. keysvals.Add("uri", request.RawUrl);
  1187. keysvals.Add("content-type", request.ContentType);
  1188. keysvals.Add("http-method", request.HttpMethod);
  1189. foreach (string queryname in querystringkeys)
  1190. {
  1191. // m_log.DebugFormat(
  1192. // "[BASE HTTP SERVER]: Got query paremeter {0}={1}", queryname, request.QueryString[queryname]);
  1193. keysvals.Add(queryname, request.QueryString[queryname]);
  1194. requestVars.Add(queryname, keysvals[queryname]);
  1195. }
  1196. foreach (string headername in rHeaders)
  1197. {
  1198. // m_log.Debug("[BASE HTTP SERVER]: " + headername + "=" + request.Headers[headername]);
  1199. headervals[headername] = request.Headers[headername];
  1200. }
  1201. if (headervals.Contains("Host"))
  1202. {
  1203. host = (string)headervals["Host"];
  1204. }
  1205. keysvals.Add("headers", headervals);
  1206. keysvals.Add("querystringkeys", querystringkeys);
  1207. keysvals.Add("requestvars", requestVars);
  1208. // keysvals.Add("form", request.Form);
  1209. if (keysvals.Contains("method"))
  1210. {
  1211. // m_log.Debug("[BASE HTTP SERVER]: Contains Method");
  1212. string method = (string) keysvals["method"];
  1213. // m_log.Debug("[BASE HTTP SERVER]: " + requestBody);
  1214. GenericHTTPMethod requestprocessor;
  1215. bool foundHandler = TryGetHTTPHandler(method, out requestprocessor);
  1216. if (foundHandler)
  1217. {
  1218. Hashtable responsedata1 = requestprocessor(keysvals);
  1219. DoHTTPGruntWork(responsedata1,response);
  1220. //SendHTML500(response);
  1221. }
  1222. else
  1223. {
  1224. // m_log.Warn("[BASE HTTP SERVER]: Handler Not Found");
  1225. SendHTML404(response, host);
  1226. }
  1227. }
  1228. else
  1229. {
  1230. GenericHTTPMethod requestprocessor;
  1231. bool foundHandler = TryGetHTTPHandlerPathBased(request.RawUrl, out requestprocessor);
  1232. if (foundHandler)
  1233. {
  1234. Hashtable responsedata2 = requestprocessor(keysvals);
  1235. DoHTTPGruntWork(responsedata2, response);
  1236. //SendHTML500(response);
  1237. }
  1238. else
  1239. {
  1240. // m_log.Warn("[BASE HTTP SERVER]: Handler Not Found2");
  1241. SendHTML404(response, host);
  1242. }
  1243. }
  1244. }
  1245. private bool TryGetHTTPHandlerPathBased(string path, out GenericHTTPMethod httpHandler)
  1246. {
  1247. httpHandler = null;
  1248. // Pull out the first part of the path
  1249. // splitting the path by '/' means we'll get the following return..
  1250. // {0}/{1}/{2}
  1251. // where {0} isn't something we really control 100%
  1252. string[] pathbase = path.Split('/');
  1253. string searchquery = "/";
  1254. if (pathbase.Length < 1)
  1255. return false;
  1256. for (int i = 1; i < pathbase.Length; i++)
  1257. {
  1258. searchquery += pathbase[i];
  1259. if (pathbase.Length - 1 != i)
  1260. searchquery += "/";
  1261. }
  1262. // while the matching algorithm below doesn't require it, we're expecting a query in the form
  1263. //
  1264. // [] = optional
  1265. // /resource/UUID/action[/action]
  1266. //
  1267. // now try to get the closest match to the reigstered path
  1268. // at least for OGP, registered path would probably only consist of the /resource/
  1269. string bestMatch = null;
  1270. // m_log.DebugFormat(
  1271. // "[BASE HTTP HANDLER]: TryGetHTTPHandlerPathBased() looking for HTTP handler to match {0}", searchquery);
  1272. lock (m_HTTPHandlers)
  1273. {
  1274. foreach (string pattern in m_HTTPHandlers.Keys)
  1275. {
  1276. if (searchquery.ToLower().StartsWith(pattern.ToLower()))
  1277. {
  1278. if (String.IsNullOrEmpty(bestMatch) || searchquery.Length > bestMatch.Length)
  1279. {
  1280. // You have to specifically register for '/' and to get it, you must specifically request it
  1281. if (pattern == "/" && searchquery == "/" || pattern != "/")
  1282. bestMatch = pattern;
  1283. }
  1284. }
  1285. }
  1286. if (String.IsNullOrEmpty(bestMatch))
  1287. {
  1288. httpHandler = null;
  1289. return false;
  1290. }
  1291. else
  1292. {
  1293. if (bestMatch == "/" && searchquery != "/")
  1294. return false;
  1295. httpHandler = m_HTTPHandlers[bestMatch];
  1296. return true;
  1297. }
  1298. }
  1299. }
  1300. internal void DoHTTPGruntWork(Hashtable responsedata, OSHttpResponse response)
  1301. {
  1302. //m_log.Info("[BASE HTTP SERVER]: Doing HTTP Grunt work with response");
  1303. int responsecode = (int)responsedata["int_response_code"];
  1304. string responseString = (string)responsedata["str_response_string"];
  1305. string contentType = (string)responsedata["content_type"];
  1306. if (responsedata.ContainsKey("error_status_text"))
  1307. {
  1308. response.StatusDescription = (string)responsedata["error_status_text"];
  1309. }
  1310. if (responsedata.ContainsKey("http_protocol_version"))
  1311. {
  1312. response.ProtocolVersion = (string)responsedata["http_protocol_version"];
  1313. }
  1314. if (responsedata.ContainsKey("keepalive"))
  1315. {
  1316. bool keepalive = (bool)responsedata["keepalive"];
  1317. response.KeepAlive = keepalive;
  1318. }
  1319. if (responsedata.ContainsKey("reusecontext"))
  1320. response.ReuseContext = (bool) responsedata["reusecontext"];
  1321. // Cross-Origin Resource Sharing with simple requests
  1322. if (responsedata.ContainsKey("access_control_allow_origin"))
  1323. response.AddHeader("Access-Control-Allow-Origin", (string)responsedata["access_control_allow_origin"]);
  1324. //Even though only one other part of the entire code uses HTTPHandlers, we shouldn't expect this
  1325. //and should check for NullReferenceExceptions
  1326. if (string.IsNullOrEmpty(contentType))
  1327. {
  1328. contentType = "text/html";
  1329. }
  1330. // The client ignores anything but 200 here for web login, so ensure that this is 200 for that
  1331. response.StatusCode = responsecode;
  1332. if (responsecode == (int)OSHttpStatusCode.RedirectMovedPermanently)
  1333. {
  1334. response.RedirectLocation = (string)responsedata["str_redirect_location"];
  1335. response.StatusCode = responsecode;
  1336. }
  1337. response.AddHeader("Content-Type", contentType);
  1338. byte[] buffer;
  1339. if (!(contentType.Contains("image")
  1340. || contentType.Contains("x-shockwave-flash")
  1341. || contentType.Contains("application/x-oar")
  1342. || contentType.Contains("application/vnd.ll.mesh")))
  1343. {
  1344. // Text
  1345. buffer = Encoding.UTF8.GetBytes(responseString);
  1346. }
  1347. else
  1348. {
  1349. // Binary!
  1350. buffer = Convert.FromBase64String(responseString);
  1351. }
  1352. response.SendChunked = false;
  1353. response.ContentLength64 = buffer.Length;
  1354. response.ContentEncoding = Encoding.UTF8;
  1355. try
  1356. {
  1357. response.OutputStream.Write(buffer, 0, buffer.Length);
  1358. }
  1359. catch (Exception ex)
  1360. {
  1361. m_log.Warn("[HTTPD]: Error - " + ex.Message);
  1362. }
  1363. finally
  1364. {
  1365. //response.OutputStream.Close();
  1366. try
  1367. {
  1368. response.OutputStream.Flush();
  1369. response.Send();
  1370. //if (!response.KeepAlive && response.ReuseContext)
  1371. // response.FreeContext();
  1372. }
  1373. catch (SocketException e)
  1374. {
  1375. // This has to be here to prevent a Linux/Mono crash
  1376. m_log.WarnFormat("[BASE HTTP SERVER]: XmlRpcRequest issue {0}.\nNOTE: this may be spurious on Linux.", e);
  1377. }
  1378. catch (IOException e)
  1379. {
  1380. m_log.Warn("[BASE HTTP SERVER]: XmlRpcRequest issue: " + e.Message);
  1381. }
  1382. }
  1383. }
  1384. public void SendHTML404(OSHttpResponse response, string host)
  1385. {
  1386. // I know this statuscode is dumb, but the client doesn't respond to 404s and 500s
  1387. response.StatusCode = 404;
  1388. response.AddHeader("Content-type", "text/html");
  1389. string responseString = GetHTTP404(host);
  1390. byte[] buffer = Encoding.UTF8.GetBytes(responseString);
  1391. response.SendChunked = false;
  1392. response.ContentLength64 = buffer.Length;
  1393. response.ContentEncoding = Encoding.UTF8;
  1394. try
  1395. {
  1396. response.OutputStream.Write(buffer, 0, buffer.Length);
  1397. }
  1398. catch (Exception ex)
  1399. {
  1400. m_log.Warn("[BASE HTTP SERVER]: Error - " + ex.Message);
  1401. }
  1402. finally
  1403. {
  1404. //response.OutputStream.Close();
  1405. try
  1406. {
  1407. response.Send();
  1408. //response.FreeContext();
  1409. }
  1410. catch (SocketException e)
  1411. {
  1412. // This has to be here to prevent a Linux/Mono crash
  1413. m_log.WarnFormat("[BASE HTTP SERVER]: XmlRpcRequest issue {0}.\nNOTE: this may be spurious on Linux.", e);
  1414. }
  1415. }
  1416. }
  1417. public void SendHTML500(OSHttpResponse response)
  1418. {
  1419. // I know this statuscode is dumb, but the client doesn't respond to 404s and 500s
  1420. response.StatusCode = (int)OSHttpStatusCode.SuccessOk;
  1421. response.AddHeader("Content-type", "text/html");
  1422. string responseString = GetHTTP500();
  1423. byte[] buffer = Encoding.UTF8.GetBytes(responseString);
  1424. response.SendChunked = false;
  1425. response.ContentLength64 = buffer.Length;
  1426. response.ContentEncoding = Encoding.UTF8;
  1427. try
  1428. {
  1429. response.OutputStream.Write(buffer, 0, buffer.Length);
  1430. }
  1431. catch (Exception ex)
  1432. {
  1433. m_log.Warn("[BASE HTTP SERVER]: Error - " + ex.Message);
  1434. }
  1435. finally
  1436. {
  1437. //response.OutputStream.Close();
  1438. try
  1439. {
  1440. response.Send();
  1441. //response.FreeContext();
  1442. }
  1443. catch (SocketException e)
  1444. {
  1445. // This has to be here to prevent a Linux/Mono crash
  1446. m_log.WarnFormat("[BASE HTTP SERVER] XmlRpcRequest issue {0}.\nNOTE: this may be spurious on Linux.", e);
  1447. }
  1448. }
  1449. }
  1450. public void Start()
  1451. {
  1452. StartHTTP();
  1453. }
  1454. private void StartHTTP()
  1455. {
  1456. try
  1457. {
  1458. //m_httpListener = new HttpListener();
  1459. NotSocketErrors = 0;
  1460. if (!m_ssl)
  1461. {
  1462. //m_httpListener.Prefixes.Add("http://+:" + m_port + "/");
  1463. //m_httpListener.Prefixes.Add("http://10.1.1.5:" + m_port + "/");
  1464. m_httpListener2 = CoolHTTPListener.Create(m_listenIPAddress, (int)m_port);
  1465. m_httpListener2.ExceptionThrown += httpServerException;
  1466. m_httpListener2.LogWriter = httpserverlog;
  1467. // Uncomment this line in addition to those in HttpServerLogWriter
  1468. // if you want more detailed trace information from the HttpServer
  1469. //m_httpListener2.UseTraceLogs = true;
  1470. //m_httpListener2.DisconnectHandler = httpServerDisconnectMonitor;
  1471. }
  1472. else
  1473. {
  1474. //m_httpListener.Prefixes.Add("https://+:" + (m_sslport) + "/");
  1475. //m_httpListener.Prefixes.Add("http://+:" + m_port + "/");
  1476. m_httpListener2 = CoolHTTPListener.Create(IPAddress.Any, (int)m_port, m_cert);
  1477. m_httpListener2.ExceptionThrown += httpServerException;
  1478. m_httpListener2.LogWriter = httpserverlog;
  1479. }
  1480. m_httpListener2.RequestReceived += OnRequest;
  1481. //m_httpListener.Start();
  1482. m_httpListener2.Start(64);
  1483. // Long Poll Service Manager with 3 worker threads a 25 second timeout for no events
  1484. m_PollServiceManager = new PollServiceRequestManager(this, 3, 25000);
  1485. HTTPDRunning = true;
  1486. //HttpListenerContext context;
  1487. //while (true)
  1488. //{
  1489. // context = m_httpListener.GetContext();
  1490. // ThreadPool.UnsafeQueueUserWorkItem(new WaitCallback(HandleRequest), context);
  1491. // }
  1492. }
  1493. catch (Exception e)
  1494. {
  1495. m_log.Error("[BASE HTTP SERVER]: Error - " + e.Message);
  1496. m_log.Error("[BASE HTTP SERVER]: Tip: Do you have permission to listen on port " + m_port + ", " + m_sslport + "?");
  1497. // We want this exception to halt the entire server since in current configurations we aren't too
  1498. // useful without inbound HTTP.
  1499. throw e;
  1500. }
  1501. }
  1502. public void httpServerDisconnectMonitor(IHttpClientContext source, SocketError err)
  1503. {
  1504. switch (err)
  1505. {
  1506. case SocketError.NotSocket:
  1507. NotSocketErrors++;
  1508. break;
  1509. }
  1510. }
  1511. public void httpServerException(object source, Exception exception)
  1512. {
  1513. m_log.ErrorFormat("[BASE HTTP SERVER]: {0} had an exception {1}", source.ToString(), exception.ToString());
  1514. /*
  1515. if (HTTPDRunning)// && NotSocketErrors > 5)
  1516. {
  1517. Stop();
  1518. Thread.Sleep(200);
  1519. StartHTTP();
  1520. m_log.Warn("[HTTPSERVER]: Died. Trying to kick.....");
  1521. }
  1522. */
  1523. }
  1524. public void Stop()
  1525. {
  1526. HTTPDRunning = false;
  1527. try
  1528. {
  1529. m_httpListener2.ExceptionThrown -= httpServerException;
  1530. //m_httpListener2.DisconnectHandler = null;
  1531. m_httpListener2.LogWriter = null;
  1532. m_httpListener2.RequestReceived -= OnRequest;
  1533. m_httpListener2.Stop();
  1534. }
  1535. catch (NullReferenceException)
  1536. {
  1537. m_log.Warn("[BASE HTTP SERVER]: Null Reference when stopping HttpServer.");
  1538. }
  1539. }
  1540. public void RemoveStreamHandler(string httpMethod, string path)
  1541. {
  1542. string handlerKey = GetHandlerKey(httpMethod, path);
  1543. //m_log.DebugFormat("[BASE HTTP SERVER]: Removing handler key {0}", handlerKey);
  1544. lock (m_streamHandlers)
  1545. m_streamHandlers.Remove(handlerKey);
  1546. }
  1547. public void RemoveHTTPHandler(string httpMethod, string path)
  1548. {
  1549. lock (m_HTTPHandlers)
  1550. {
  1551. if (httpMethod != null && httpMethod.Length == 0)
  1552. {
  1553. m_HTTPHandlers.Remove(path);
  1554. return;
  1555. }
  1556. m_HTTPHandlers.Remove(GetHandlerKey(httpMethod, path));
  1557. }
  1558. }
  1559. public void RemovePollServiceHTTPHandler(string httpMethod, string path)
  1560. {
  1561. lock (m_pollHandlers)
  1562. {
  1563. if (m_pollHandlers.ContainsKey(httpMethod))
  1564. {
  1565. m_pollHandlers.Remove(httpMethod);
  1566. }
  1567. }
  1568. RemoveHTTPHandler(httpMethod, path);
  1569. }
  1570. public bool RemoveAgentHandler(string agent, IHttpAgentHandler handler)
  1571. {
  1572. lock (m_agentHandlers)
  1573. {
  1574. IHttpAgentHandler foundHandler;
  1575. if (m_agentHandlers.TryGetValue(agent, out foundHandler) && foundHandler == handler)
  1576. {
  1577. m_agentHandlers.Remove(agent);
  1578. return true;
  1579. }
  1580. }
  1581. return false;
  1582. }
  1583. public void RemoveXmlRPCHandler(string method)
  1584. {
  1585. lock (m_rpcHandlers)
  1586. {
  1587. if (m_rpcHandlers.ContainsKey(method))
  1588. {
  1589. m_rpcHandlers.Remove(method);
  1590. }
  1591. }
  1592. }
  1593. public bool RemoveLLSDHandler(string path, LLSDMethod handler)
  1594. {
  1595. lock (m_llsdHandlers)
  1596. {
  1597. LLSDMethod foundHandler;
  1598. if (m_llsdHandlers.TryGetValue(path, out foundHandler) && foundHandler == handler)
  1599. {
  1600. m_llsdHandlers.Remove(path);
  1601. return true;
  1602. }
  1603. }
  1604. return false;
  1605. }
  1606. public string GetHTTP404(string host)
  1607. {
  1608. string file = Path.Combine(".", "http_404.html");
  1609. if (!File.Exists(file))
  1610. return getDefaultHTTP404(host);
  1611. StreamReader sr = File.OpenText(file);
  1612. string result = sr.ReadToEnd();
  1613. sr.Close();
  1614. return result;
  1615. }
  1616. public string GetHTTP500()
  1617. {
  1618. string file = Path.Combine(".", "http_500.html");
  1619. if (!File.Exists(file))
  1620. return getDefaultHTTP500();
  1621. StreamReader sr = File.OpenText(file);
  1622. string result = sr.ReadToEnd();
  1623. sr.Close();
  1624. return result;
  1625. }
  1626. // Fallback HTTP responses in case the HTTP error response files don't exist
  1627. private static string getDefaultHTTP404(string host)
  1628. {
  1629. return "<HTML><HEAD><TITLE>404 Page not found</TITLE><BODY><BR /><H1>Ooops!</H1><P>The page you requested has been obsconded with by knomes. Find hippos quick!</P><P>If you are trying to log-in, your link parameters should have: &quot;-loginpage http://" + host + "/?method=login -loginuri http://" + host + "/&quot; in your link </P></BODY></HTML>";
  1630. }
  1631. private static string getDefaultHTTP500()
  1632. {
  1633. return "<HTML><HEAD><TITLE>500 Internal Server Error</TITLE><BODY><BR /><H1>Ooops!</H1><P>The server you requested is overun by knomes! Find hippos quick!</P></BODY></HTML>";
  1634. }
  1635. }
  1636. public class HttpServerContextObj
  1637. {
  1638. public IHttpClientContext context = null;
  1639. public IHttpRequest req = null;
  1640. public OSHttpRequest oreq = null;
  1641. public OSHttpResponse oresp = null;
  1642. public HttpServerContextObj(IHttpClientContext contxt, IHttpRequest reqs)
  1643. {
  1644. context = contxt;
  1645. req = reqs;
  1646. }
  1647. public HttpServerContextObj(OSHttpRequest osreq, OSHttpResponse osresp)
  1648. {
  1649. oreq = osreq;
  1650. oresp = osresp;
  1651. }
  1652. }
  1653. /// <summary>
  1654. /// Relays HttpServer log messages to our own logging mechanism.
  1655. /// </summary>
  1656. /// To use this you must uncomment the switch section
  1657. ///
  1658. /// You may also be able to get additional trace information from HttpServer if you uncomment the UseTraceLogs
  1659. /// property in StartHttp() for the HttpListener
  1660. public class HttpServerLogWriter : ILogWriter
  1661. {
  1662. // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  1663. public void Write(object source, LogPrio priority, string message)
  1664. {
  1665. /*
  1666. switch (priority)
  1667. {
  1668. case LogPrio.Trace:
  1669. m_log.DebugFormat("[{0}]: {1}", source, message);
  1670. break;
  1671. case LogPrio.Debug:
  1672. m_log.DebugFormat("[{0}]: {1}", source, message);
  1673. break;
  1674. case LogPrio.Error:
  1675. m_log.ErrorFormat("[{0}]: {1}", source, message);
  1676. break;
  1677. case LogPrio.Info:
  1678. m_log.InfoFormat("[{0}]: {1}", source, message);
  1679. break;
  1680. case LogPrio.Warning:
  1681. m_log.WarnFormat("[{0}]: {1}", source, message);
  1682. break;
  1683. case LogPrio.Fatal:
  1684. m_log.ErrorFormat("[{0}]: FATAL! - {1}", source, message);
  1685. break;
  1686. default:
  1687. break;
  1688. }
  1689. */
  1690. return;
  1691. }
  1692. }
  1693. }