123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- using log4net;
- using System;
- using System.Net;
- using System.Reflection;
- using Nini.Config;
- namespace OpenSim.Services.Connectors
- {
- public class HeloServicesConnector
- {
- private static readonly ILog m_log =
- LogManager.GetLogger(
- MethodBase.GetCurrentMethod().DeclaringType);
- private string m_ServerURI = String.Empty;
- public HeloServicesConnector()
- {
- }
- public HeloServicesConnector(string serverURI)
- {
- try
- {
- Uri uri;
- if (!serverURI.EndsWith("="))
- {
-
- uri = new Uri(serverURI);
- m_ServerURI = serverURI.TrimEnd('/') + "/helo/";
- }
- else
- {
-
-
-
- uri = new Uri(serverURI + "xxx");
- if (uri.Query == string.Empty)
- m_ServerURI = serverURI.TrimEnd('/') + "/helo/";
- else
- {
- serverURI = serverURI + "xxx";
- m_ServerURI = serverURI.Replace(uri.Query, "");
- m_ServerURI = m_ServerURI.TrimEnd('/') + "/helo/";
- }
- }
- }
- catch (UriFormatException)
- {
- m_log.WarnFormat("[HELO SERVICE]: Malformed URL {0}", serverURI);
- }
- }
- public virtual string Helo()
- {
- if (String.IsNullOrEmpty(m_ServerURI))
- {
- m_log.WarnFormat("[HELO SERVICE]: Unable to invoke HELO due to malformed URL");
- return String.Empty;
- }
- HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(m_ServerURI);
-
-
- try
- {
- using (WebResponse response = req.GetResponse())
- {
- if (response.Headers.Get("X-Handlers-Provided") == null)
- return string.Empty;
- return response.Headers.Get("X-Handlers-Provided");
- }
- }
- catch (Exception e)
- {
- m_log.DebugFormat("[HELO SERVICE]: Unable to perform HELO request to {0}: {1}", m_ServerURI, e.Message);
- }
-
- return string.Empty;
- }
- }
- }
|