public FreeswitchServerConnector(IConfigSource config, IHttpServer server, string configName) :
            base(config, server, configName)
        {
            if (configName != String.Empty)
            {
                m_ConfigName = configName;
            }

            IConfig serverConfig = config.Configs[m_ConfigName];

            if (serverConfig == null)
            {
                throw new Exception(String.Format("No section '{0}' in config file", m_ConfigName));
            }

            string freeswitchService = serverConfig.GetString("LocalServiceModule",
                                                              String.Empty);

            if (freeswitchService == String.Empty)
            {
                throw new Exception("No LocalServiceModule in config file");
            }

            Object[] args = new Object[] { config };
            m_FreeswitchService =
                ServerUtils.LoadPlugin <IFreeswitchService>(freeswitchService, args);

            server.AddHTTPHandler(String.Format("{0}/freeswitch-config", m_freeSwitchAPIPrefix), FreeSwitchConfigHTTPHandler);
            server.AddHTTPHandler(String.Format("{0}/region-config", m_freeSwitchAPIPrefix), RegionConfigHTTPHandler);
        }
        public void AddExistingUrlForClient(string SessionID, string url, uint port)
        {
            IHttpServer server = m_registry.RequestModuleInterface<ISimulationBase> ().GetHttpServer (port);

            m_FreeswitchService = m_registry.RequestModuleInterface<IFreeswitchService>();

            server.AddHTTPHandler(String.Format("{0}/freeswitch-config", url), FreeSwitchConfigHTTPHandler);
            server.AddHTTPHandler(String.Format("{0}/region-config", url), RegionConfigHTTPHandler);
        }
示例#3
0
        public void AddExistingUrlForClient(string SessionID, ulong RegionHandle, string url)
        {
            IHttpServer server = m_registry.RequestModuleInterface <ISimulationBase>().GetHttpServer(m_port);

            m_port = server.Port;

            m_FreeswitchService = m_registry.RequestModuleInterface <IFreeswitchService>();

            server.AddHTTPHandler(String.Format("{0}/{1}/freeswitch-config", m_freeSwitchAPIPrefix, UUID.Random()), FreeSwitchConfigHTTPHandler);
            server.AddHTTPHandler(String.Format("{0}/{1}/region-config", m_freeSwitchAPIPrefix, UUID.Random()), RegionConfigHTTPHandler);
        }
        public void PostStart(IConfigSource config, IRegistryCore registry)
        {
            IConfig handlerConfig = config.Configs["Handlers"];
            if (handlerConfig.GetString("FreeswitchInHandler", "") != Name)
                return;
            IHttpServer server = registry.RequestModuleInterface<ISimulationBase>().GetHttpServer((uint)handlerConfig.GetInt("FreeswitchInHandlerPort"));
            m_FreeswitchService = registry.RequestModuleInterface<IFreeswitchService>();

            server.AddHTTPHandler(String.Format("{0}/freeswitch-config", m_freeSwitchAPIPrefix), FreeSwitchConfigHTTPHandler);
            server.AddHTTPHandler(String.Format("{0}/region-config", m_freeSwitchAPIPrefix), RegionConfigHTTPHandler);
        }
示例#5
0
        public string GetUrlForRegisteringClient(string SessionID, ulong RegionHandle)
        {
            string url = "/CAPS/EQMPOSTER" + UUID.Random();

            IHttpServer server = m_registry.RequestModuleInterface <ISimulationBase>().GetHttpServer(m_port);

            m_port = server.Port;

            m_FreeswitchService = m_registry.RequestModuleInterface <IFreeswitchService>();

            server.AddHTTPHandler(String.Format("{0}/{1}/freeswitch-config", m_freeSwitchAPIPrefix, UUID.Random()), FreeSwitchConfigHTTPHandler);
            server.AddHTTPHandler(String.Format("{0}/{1}/region-config", m_freeSwitchAPIPrefix, UUID.Random()), RegionConfigHTTPHandler);
            return(url);
        }
        public FreeswitchServerConnector(IConfigSource config, IHttpServer server) :
                base(config, server)
        {
            IConfig serverConfig = config.Configs["FreeswitchService"];
            if (serverConfig == null)
                throw new Exception("No section 'Server' in config file");

            string freeswitchService = serverConfig.GetString("LocalServiceModule",
                    String.Empty);

            if (freeswitchService == String.Empty)
                throw new Exception("No FreeswitchService in config file");

            Object[] args = new Object[] { config };
            m_FreeswitchService =
                    ServerUtils.LoadPlugin<IFreeswitchService>(freeswitchService, args);

            server.AddStreamHandler(new FreeswitchServerGetHandler(m_FreeswitchService));
        }
        public FreeswitchServerConnector(IConfigSource config, IHttpServer server, string configName) :
                base(config, server, configName)
        {
            if (configName != String.Empty)
                m_ConfigName = configName;

            IConfig serverConfig = config.Configs[m_ConfigName];
            if (serverConfig == null)
                throw new Exception(String.Format("No section '{0}' in config file", m_ConfigName));

            string freeswitchService = serverConfig.GetString("LocalServiceModule",
                    String.Empty);

            if (freeswitchService == String.Empty)
                throw new Exception("No LocalServiceModule in config file");

            Object[] args = new Object[] { config };
            m_FreeswitchService =
                    ServerUtils.LoadPlugin<IFreeswitchService>(freeswitchService, args);

            server.AddStreamHandler(new FreeswitchServerGetHandler(m_FreeswitchService));
        }
示例#8
0
        public void Start(IConfigSource config, IRegistryCore registry)
        {
            IConfig handlerConfig = config.Configs["Handlers"];

            if (handlerConfig.GetString("FreeswitchInHandler", "") != Name)
            {
                return;
            }

            m_registry = registry;
            m_port     = handlerConfig.GetUInt("FreeswitchInHandlerPort");

            if (handlerConfig.GetBoolean("UnsecureUrls", false))
            {
                IHttpServer server = registry.RequestModuleInterface <ISimulationBase>().GetHttpServer(m_port);
                m_port = server.Port;

                m_FreeswitchService = registry.RequestModuleInterface <IFreeswitchService>();

                server.AddHTTPHandler(String.Format("{0}/{1}/freeswitch-config", m_freeSwitchAPIPrefix, UUID.Random()), FreeSwitchConfigHTTPHandler);
                server.AddHTTPHandler(String.Format("{0}/{1}/region-config", m_freeSwitchAPIPrefix, UUID.Random()), RegionConfigHTTPHandler);
            }
            m_registry.RequestModuleInterface <IGridRegistrationService>().RegisterModule(this);
        }
        public string GetUrlForRegisteringClient(string SessionID, uint port)
        {
            string url = String.Format("{0}/{1}", m_freeSwitchAPIPrefix, UUID.Random());

            IHttpServer server = m_registry.RequestModuleInterface<ISimulationBase> ().GetHttpServer (port);

            m_FreeswitchService = m_registry.RequestModuleInterface<IFreeswitchService>();

            server.AddHTTPHandler(url + "/freeswitch-config", FreeSwitchConfigHTTPHandler);
            server.AddHTTPHandler(url + "/region-config", RegionConfigHTTPHandler);
            return url;
        }
        public void AddExistingUrlForClient(string SessionID, ulong RegionHandle, string url)
        {
            IHttpServer server = m_registry.RequestModuleInterface<ISimulationBase>().GetHttpServer(m_port);
            m_port = server.Port;

            m_FreeswitchService = m_registry.RequestModuleInterface<IFreeswitchService>();

            server.AddHTTPHandler(String.Format("{0}/{1}/freeswitch-config", m_freeSwitchAPIPrefix, UUID.Random()), FreeSwitchConfigHTTPHandler);
            server.AddHTTPHandler(String.Format("{0}/{1}/region-config", m_freeSwitchAPIPrefix, UUID.Random()), RegionConfigHTTPHandler);
        }
示例#11
0
        public void AddRegion(Scene scene)
        {
            // We generate these like this: The region's external host name
            // as defined in Regions.ini is a good address to use. It's a
            // dotted quad (or should be!) and it can reach this host from
            // a client. The port is grabbed from the region's HTTP server.
            m_openSimWellKnownHTTPAddress = scene.RegionInfo.ExternalHostName;
            m_freeSwitchServicePort       = MainServer.Instance.Port;

            if (m_Enabled)
            {
                m_FreeswitchService = scene.RequestModuleInterface <IFreeswitchService>();

                try
                {
                    string jsonConfig = m_FreeswitchService.GetJsonConfig();
                    m_log.Debug("[FreeSwitchVoice]: Configuration string: " + jsonConfig);
                    OSDMap map = (OSDMap)OSDParser.DeserializeJson(jsonConfig);

                    m_freeSwitchAPIPrefix          = map["APIPrefix"].AsString();
                    m_freeSwitchRealm              = map["Realm"].AsString();
                    m_freeSwitchSIPProxy           = map["SIPProxy"].AsString();
                    m_freeSwitchAttemptUseSTUN     = map["AttemptUseSTUN"].AsBoolean();
                    m_freeSwitchEchoServer         = map["EchoServer"].AsString();
                    m_freeSwitchEchoPort           = map["EchoPort"].AsInteger();
                    m_freeSwitchDefaultWellKnownIP = map["DefaultWellKnownIP"].AsString();
                    m_freeSwitchDefaultTimeout     = map["DefaultTimeout"].AsInteger();
                    m_freeSwitchUrlResetPassword   = String.Empty;
                    //m_freeSwitchContext = map["Context"].AsString ();

                    if (String.IsNullOrEmpty(m_freeSwitchRealm) ||
                        String.IsNullOrEmpty(m_freeSwitchAPIPrefix))
                    {
                        m_log.Error("[FreeSwitchVoice] plugin mis-configured");
                        m_log.Info("[FreeSwitchVoice] plugin disabled: incomplete configuration");
                        return;
                    }

                    // set up http request handlers for
                    // - prelogin: viv_get_prelogin.php
                    // - signin: viv_signin.php
                    // - buddies: viv_buddy.php
                    // - ???: viv_watcher.php
                    // - signout: viv_signout.php
                    MainServer.Instance.AddHTTPHandler(String.Format("{0}/viv_get_prelogin.php", m_freeSwitchAPIPrefix),
                                                       FreeSwitchSLVoiceGetPreloginHTTPHandler);

                    MainServer.Instance.AddHTTPHandler(String.Format("{0}/freeswitch-config", m_freeSwitchAPIPrefix), FreeSwitchConfigHTTPHandler);

                    // RestStreamHandler h = new
                    // RestStreamHandler("GET",
                    // String.Format("{0}/viv_get_prelogin.php", m_freeSwitchAPIPrefix), FreeSwitchSLVoiceGetPreloginHTTPHandler);
                    //  MainServer.Instance.AddStreamHandler(h);



                    MainServer.Instance.AddHTTPHandler(String.Format("{0}/viv_signin.php", m_freeSwitchAPIPrefix),
                                                       FreeSwitchSLVoiceSigninHTTPHandler);

                    MainServer.Instance.AddHTTPHandler(String.Format("{0}/viv_buddy.php", m_freeSwitchAPIPrefix),
                                                       FreeSwitchSLVoiceBuddyHTTPHandler);

                    m_log.InfoFormat("[FreeSwitchVoice] using FreeSwitch server {0}", m_freeSwitchRealm);

                    m_log.Info("[FreeSwitchVoice] plugin enabled");
                }
                catch (Exception e)
                {
                    m_log.ErrorFormat("[FreeSwitchVoice] plugin initialization failed: {0}", e.Message);
                    m_log.DebugFormat("[FreeSwitchVoice] plugin initialization failed: {0}", e.ToString());
                    return;
                }

                // This here is a region module trying to make a global setting.
                // Not really a good idea but it's Windows only, so I can't test.
                try
                {
                    ServicePointManager.ServerCertificateValidationCallback += CustomCertificateValidation;
                }
                catch (NotImplementedException)
                {
                    try
                    {
#pragma warning disable 0612, 0618
                        // Mono does not implement the ServicePointManager.ServerCertificateValidationCallback yet!  Don't remove this!
                        ServicePointManager.CertificatePolicy = new MonoCert();
#pragma warning restore 0612, 0618
                    }
                    catch (Exception)
                    {
                        // COmmented multiline spam log message
                        //m_log.Error("[FreeSwitchVoice]: Certificate validation handler change not supported.  You may get ssl certificate validation errors teleporting from your region to some SSL regions.");
                    }
                }

                // we need to capture scene in an anonymous method
                // here as we need it later in the callbacks
                scene.EventManager.OnRegisterCaps += delegate(UUID agentID, IHttpServer server)
                {
                    return(OnRegisterCaps(scene, agentID, server));
                };
                //Add this to the OpenRegionSettings module so we can inform the client about it
                IOpenRegionSettingsModule ORSM = scene.RequestModuleInterface <IOpenRegionSettingsModule>();
                if (ORSM != null)
                {
                    ORSM.RegisterGenericValue("Voice", "SLVoice");
                }
            }
        }
示例#12
0
        public void Initialise(IConfigSource config)
        {
            m_Config = config.Configs["FreeSwitchVoice"];

            if (m_Config == null)
            {
                return;
            }

            if (!m_Config.GetBoolean("Enabled", false))
            {
                return;
            }

            try
            {
                string serviceDll = m_Config.GetString("LocalServiceModule",
                                                       String.Empty);

                if (serviceDll == String.Empty)
                {
                    m_log.Error("[FreeSwitchVoice]: No LocalServiceModule named in section FreeSwitchVoice.  Not starting.");
                    return;
                }

                Object[] args = new Object[] { config };
                m_FreeswitchService = ServerUtils.LoadPlugin <IFreeswitchService>(serviceDll, args);

                string jsonConfig = m_FreeswitchService.GetJsonConfig();
                //m_log.Debug("[FreeSwitchVoice]: Configuration string: " + jsonConfig);
                OSDMap map = (OSDMap)OSDParser.DeserializeJson(jsonConfig);

                m_freeSwitchAPIPrefix          = map["APIPrefix"].AsString();
                m_freeSwitchRealm              = map["Realm"].AsString();
                m_freeSwitchSIPProxy           = map["SIPProxy"].AsString();
                m_freeSwitchAttemptUseSTUN     = map["AttemptUseSTUN"].AsBoolean();
                m_freeSwitchEchoServer         = map["EchoServer"].AsString();
                m_freeSwitchEchoPort           = map["EchoPort"].AsInteger();
                m_freeSwitchDefaultWellKnownIP = map["DefaultWellKnownIP"].AsString();
                m_freeSwitchDefaultTimeout     = map["DefaultTimeout"].AsInteger();
                m_freeSwitchUrlResetPassword   = String.Empty;
                //                m_freeSwitchContext = map["Context"].AsString();

                if (String.IsNullOrEmpty(m_freeSwitchRealm) ||
                    String.IsNullOrEmpty(m_freeSwitchAPIPrefix))
                {
                    m_log.Error("[FreeSwitchVoice]: Freeswitch service mis-configured.  Not starting.");
                    return;
                }

                // set up http request handlers for
                // - prelogin: viv_get_prelogin.php
                // - signin: viv_signin.php
                // - buddies: viv_buddy.php
                // - ???: viv_watcher.php
                // - signout: viv_signout.php
                MainServer.Instance.AddHTTPHandler(String.Format("{0}/viv_get_prelogin.php", m_freeSwitchAPIPrefix),
                                                   FreeSwitchSLVoiceGetPreloginHTTPHandler);

                MainServer.Instance.AddHTTPHandler(String.Format("{0}/freeswitch-config", m_freeSwitchAPIPrefix), FreeSwitchConfigHTTPHandler);

                // RestStreamHandler h = new
                // RestStreamHandler("GET",
                // String.Format("{0}/viv_get_prelogin.php", m_freeSwitchAPIPrefix), FreeSwitchSLVoiceGetPreloginHTTPHandler);
                //  MainServer.Instance.AddStreamHandler(h);

                MainServer.Instance.AddHTTPHandler(String.Format("{0}/viv_signin.php", m_freeSwitchAPIPrefix),
                                                   FreeSwitchSLVoiceSigninHTTPHandler);

                MainServer.Instance.AddHTTPHandler(String.Format("{0}/viv_buddy.php", m_freeSwitchAPIPrefix),
                                                   FreeSwitchSLVoiceBuddyHTTPHandler);

                MainServer.Instance.AddHTTPHandler(String.Format("{0}/viv_watcher.php", m_freeSwitchAPIPrefix),
                                                   FreeSwitchSLVoiceWatcherHTTPHandler);

                m_log.InfoFormat("[FreeSwitchVoice]: using FreeSwitch server {0}", m_freeSwitchRealm);

                m_Enabled = true;

                m_log.Info("[FreeSwitchVoice]: plugin enabled");
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("[FreeSwitchVoice]: plugin initialization failed: {0} {1}", e.Message, e.StackTrace);
                return;
            }

            // This here is a region module trying to make a global setting.
            // Not really a good idea but it's Windows only, so I can't test.
            try
            {
                ServicePointManager.ServerCertificateValidationCallback += CustomCertificateValidation;
            }
            catch (NotImplementedException)
            {
                try
                {
#pragma warning disable 0612, 0618
                    // Mono does not implement the ServicePointManager.ServerCertificateValidationCallback yet!  Don't remove this!
                    ServicePointManager.CertificatePolicy = new MonoCert();
#pragma warning restore 0612, 0618
                }
                catch (Exception)
                {
                    // COmmented multiline spam log message
                    //m_log.Error("[FreeSwitchVoice]: Certificate validation handler change not supported.  You may get ssl certificate validation errors teleporting from your region to some SSL regions.");
                }
            }
        }
        public void AddRegion(IScene scene)
        {
            // We generate these like this: The region's external host name
            // as defined in Regions.ini is a good address to use. It's a
            // dotted quad (or should be!) and it can reach this host from
            // a client. The port is grabbed from the region's HTTP server.
            m_openSimWellKnownHTTPAddress = MainServer.Instance.HostName;
            m_freeSwitchServicePort = MainServer.Instance.Port;

            if (m_Enabled)
            {
                m_FreeswitchService = scene.RequestModuleInterface<IFreeswitchService>();

                try
                {
                    string jsonConfig = m_FreeswitchService.GetJsonConfig ();
                    m_log.Debug ("[FreeSwitchVoice]: Configuration string: " + jsonConfig);
                    OSDMap map = (OSDMap)OSDParser.DeserializeJson (jsonConfig);

                    m_freeSwitchAPIPrefix = map["APIPrefix"].AsString ();
                    m_freeSwitchRealm = map["Realm"].AsString ();
                    m_freeSwitchSIPProxy = map["SIPProxy"].AsString ();
                    m_freeSwitchAttemptUseSTUN = map["AttemptUseSTUN"].AsBoolean ();
                    m_freeSwitchEchoServer = map["EchoServer"].AsString ();
                    m_freeSwitchEchoPort = map["EchoPort"].AsInteger ();
                    m_freeSwitchDefaultWellKnownIP = map["DefaultWellKnownIP"].AsString ();
                    m_freeSwitchDefaultTimeout = map["DefaultTimeout"].AsInteger ();
                    m_freeSwitchUrlResetPassword = String.Empty;
                    //m_freeSwitchContext = map["Context"].AsString ();

                    if (String.IsNullOrEmpty (m_freeSwitchRealm) ||
                        String.IsNullOrEmpty (m_freeSwitchAPIPrefix))
                    {
                        m_log.Error ("[FreeSwitchVoice] plugin mis-configured");
                        m_log.Info ("[FreeSwitchVoice] plugin disabled: incomplete configuration");
                        return;
                    }

                    // set up http request handlers for
                    // - prelogin: viv_get_prelogin.php
                    // - signin: viv_signin.php
                    // - buddies: viv_buddy.php
                    // - ???: viv_watcher.php
                    // - signout: viv_signout.php
                    MainServer.Instance.AddHTTPHandler (String.Format ("{0}/viv_get_prelogin.php", m_freeSwitchAPIPrefix),
                                                         FreeSwitchSLVoiceGetPreloginHTTPHandler);

                    MainServer.Instance.AddHTTPHandler (String.Format ("{0}/freeswitch-config", m_freeSwitchAPIPrefix), FreeSwitchConfigHTTPHandler);

                    // RestStreamHandler h = new
                    // RestStreamHandler("GET",
                    // String.Format("{0}/viv_get_prelogin.php", m_freeSwitchAPIPrefix), FreeSwitchSLVoiceGetPreloginHTTPHandler);
                    //  MainServer.Instance.AddStreamHandler(h);

                    MainServer.Instance.AddHTTPHandler (String.Format ("{0}/viv_signin.php", m_freeSwitchAPIPrefix),
                                     FreeSwitchSLVoiceSigninHTTPHandler);

                    MainServer.Instance.AddHTTPHandler (String.Format ("{0}/viv_buddy.php", m_freeSwitchAPIPrefix),
                                     FreeSwitchSLVoiceBuddyHTTPHandler);

                    MainServer.Instance.AddHTTPHandler(String.Format("{0}/viv_watcher.php", m_freeSwitchAPIPrefix),
                                     FreeSwitchSLVoiceWatcherHTTPHandler);

                    m_log.InfoFormat ("[FreeSwitchVoice] using FreeSwitch server {0}", m_freeSwitchRealm);

                    m_log.Info ("[FreeSwitchVoice] plugin enabled");
                }
                catch (Exception e)
                {
                    m_log.ErrorFormat ("[FreeSwitchVoice] plugin initialization failed: {0}", e.Message);
                    m_log.DebugFormat ("[FreeSwitchVoice] plugin initialization failed: {0}", e.ToString ());
                    return;
                }

                // This here is a region module trying to make a global setting.
                // Not really a good idea but it's Windows only, so I can't test.
                try
                {
                    ServicePointManager.ServerCertificateValidationCallback += CustomCertificateValidation;
                }
                catch (NotImplementedException)
                {
                    try
                    {
            #pragma warning disable 0612, 0618
                        // Mono does not implement the ServicePointManager.ServerCertificateValidationCallback yet!  Don't remove this!
                        ServicePointManager.CertificatePolicy = new MonoCert ();
            #pragma warning restore 0612, 0618
                    }
                    catch (Exception)
                    {
                        // COmmented multiline spam log message
                        //m_log.Error("[FreeSwitchVoice]: Certificate validation handler change not supported.  You may get ssl certificate validation errors teleporting from your region to some SSL regions.");
                    }
                }

                // we need to capture scene in an anonymous method
                // here as we need it later in the callbacks
                scene.EventManager.OnRegisterCaps += delegate(UUID agentID, IHttpServer server)
                {
                    return OnRegisterCaps(scene, agentID, server);
                };
                //Add this to the OpenRegionSettings module so we can inform the client about it
                IOpenRegionSettingsModule ORSM = scene.RequestModuleInterface<IOpenRegionSettingsModule>();
                if (ORSM != null)
                    ORSM.RegisterGenericValue("Voice", "SLVoice");
            }
        }
        // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

        //private IFreeswitchService m_FreeswitchService;

        public FreeswitchServerGetHandler(IFreeswitchService service) :
            base("GET", "/api")
        {
            //m_FreeswitchService = service;
        }
        public void Start(IConfigSource config, IRegistryCore registry)
        {
            IConfig handlerConfig = config.Configs["Handlers"];
            if (handlerConfig.GetString("FreeswitchInHandler", "") != Name)
                return;

            m_registry = registry;
            m_port = handlerConfig.GetUInt("FreeswitchInHandlerPort");

            if (handlerConfig.GetBoolean("UnsecureUrls", false))
            {
                IHttpServer server = registry.RequestModuleInterface<ISimulationBase>().GetHttpServer(m_port);
                m_port = server.Port;

                m_FreeswitchService = registry.RequestModuleInterface<IFreeswitchService>();

                server.AddHTTPHandler(String.Format("{0}/{1}/freeswitch-config", m_freeSwitchAPIPrefix, UUID.Random()), FreeSwitchConfigHTTPHandler);
                server.AddHTTPHandler(String.Format("{0}/{1}/region-config", m_freeSwitchAPIPrefix, UUID.Random()), RegionConfigHTTPHandler);
            }
            m_registry.RequestModuleInterface<IGridRegistrationService>().RegisterModule(this);
        }
示例#16
0
        public void Initialise(IConfigSource config)
        {
            m_Config = config.Configs["FreeSwitchVoice"];

            if (m_Config == null)
            {
                return;
            }

            if (!m_Config.GetBoolean("Enabled", false))
            {
                return;
            }

            try
            {
                string serviceDll = m_Config.GetString("LocalServiceModule",
                                                       String.Empty);

                if (serviceDll == String.Empty)
                {
                    m_log.Error("[FreeSwitchVoice]: No LocalServiceModule named in section FreeSwitchVoice.  Not starting.");
                    return;
                }

                Object[] args = new Object[] { config };
                m_FreeswitchService = ServerUtils.LoadPlugin <IFreeswitchService>(serviceDll, args);

                string jsonConfig = m_FreeswitchService.GetJsonConfig();
                //m_log.Debug("[FreeSwitchVoice]: Configuration string: " + jsonConfig);
                OSDMap map = (OSDMap)OSDParser.DeserializeJson(jsonConfig);

                m_freeSwitchAPIPrefix          = map["APIPrefix"].AsString();
                m_freeSwitchRealm              = map["Realm"].AsString();
                m_freeSwitchSIPProxy           = map["SIPProxy"].AsString();
                m_freeSwitchAttemptUseSTUN     = map["AttemptUseSTUN"].AsBoolean();
                m_freeSwitchEchoServer         = map["EchoServer"].AsString();
                m_freeSwitchEchoPort           = map["EchoPort"].AsInteger();
                m_freeSwitchDefaultWellKnownIP = map["DefaultWellKnownIP"].AsString();
                m_freeSwitchDefaultTimeout     = map["DefaultTimeout"].AsInteger();
                m_freeSwitchUrlResetPassword   = String.Empty;
                //                m_freeSwitchContext = map["Context"].AsString();

                if (String.IsNullOrEmpty(m_freeSwitchRealm) ||
                    String.IsNullOrEmpty(m_freeSwitchAPIPrefix))
                {
                    m_log.Error("[FreeSwitchVoice]: Freeswitch service mis-configured.  Not starting.");
                    return;
                }

                // set up http request handlers for
                // - prelogin: viv_get_prelogin.php
                // - signin: viv_signin.php
                // - buddies: viv_buddy.php
                // - ???: viv_watcher.php
                // - signout: viv_signout.php
                MainServer.Instance.AddHTTPHandler(String.Format("{0}/viv_get_prelogin.php", m_freeSwitchAPIPrefix),
                                                   FreeSwitchSLVoiceGetPreloginHTTPHandler);

                MainServer.Instance.AddHTTPHandler(String.Format("{0}/freeswitch-config", m_freeSwitchAPIPrefix), FreeSwitchConfigHTTPHandler);

                // RestStreamHandler h = new
                // RestStreamHandler("GET",
                // String.Format("{0}/viv_get_prelogin.php", m_freeSwitchAPIPrefix), FreeSwitchSLVoiceGetPreloginHTTPHandler);
                //  MainServer.Instance.AddStreamHandler(h);

                MainServer.Instance.AddHTTPHandler(String.Format("{0}/viv_signin.php", m_freeSwitchAPIPrefix),
                                                   FreeSwitchSLVoiceSigninHTTPHandler);

                MainServer.Instance.AddHTTPHandler(String.Format("{0}/viv_buddy.php", m_freeSwitchAPIPrefix),
                                                   FreeSwitchSLVoiceBuddyHTTPHandler);

                MainServer.Instance.AddHTTPHandler(String.Format("{0}/viv_watcher.php", m_freeSwitchAPIPrefix),
                                                   FreeSwitchSLVoiceWatcherHTTPHandler);

                m_log.InfoFormat("[FreeSwitchVoice]: using FreeSwitch server {0}", m_freeSwitchRealm);

                m_Enabled = true;

                m_log.Info("[FreeSwitchVoice]: plugin enabled");
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("[FreeSwitchVoice]: plugin initialization failed: {0} {1}", e.Message, e.StackTrace);
                return;
            }
        }
        // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

        //private IFreeswitchService m_FreeswitchService;

        public FreeswitchServerGetHandler(IFreeswitchService service) :
                base("GET", "/api")
        {
            //m_FreeswitchService = service;
        }
        public void Initialise(IConfigSource config)
        {
            m_Config = config.Configs["FreeSwitchVoice"];

            if (m_Config == null)
                return;

            if (!m_Config.GetBoolean("Enabled", false))
                return;

            try
            {
                string serviceDll = m_Config.GetString("LocalServiceModule",
                        String.Empty);

                if (serviceDll == String.Empty)
                {
                    m_log.Error("[FreeSwitchVoice]: No LocalServiceModule named in section FreeSwitchVoice.  Not starting.");
                    return;
                }

                Object[] args = new Object[] { config };
                m_FreeswitchService = ServerUtils.LoadPlugin<IFreeswitchService>(serviceDll, args);

                string jsonConfig = m_FreeswitchService.GetJsonConfig();
                //m_log.Debug("[FreeSwitchVoice]: Configuration string: " + jsonConfig);
                OSDMap map = (OSDMap)OSDParser.DeserializeJson(jsonConfig);

                m_freeSwitchAPIPrefix = map["APIPrefix"].AsString();
                m_freeSwitchRealm = map["Realm"].AsString();
                m_freeSwitchSIPProxy = map["SIPProxy"].AsString();
                m_freeSwitchAttemptUseSTUN = map["AttemptUseSTUN"].AsBoolean();
                m_freeSwitchEchoServer = map["EchoServer"].AsString();
                m_freeSwitchEchoPort = map["EchoPort"].AsInteger();
                m_freeSwitchDefaultWellKnownIP = map["DefaultWellKnownIP"].AsString();
                m_freeSwitchDefaultTimeout = map["DefaultTimeout"].AsInteger();
                m_freeSwitchUrlResetPassword = String.Empty;
//                m_freeSwitchContext = map["Context"].AsString();

                if (String.IsNullOrEmpty(m_freeSwitchRealm) ||
                    String.IsNullOrEmpty(m_freeSwitchAPIPrefix))
                {
                    m_log.Error("[FreeSwitchVoice]: Freeswitch service mis-configured.  Not starting.");                    
                    return;
                }

                // set up http request handlers for
                // - prelogin: viv_get_prelogin.php
                // - signin: viv_signin.php
                // - buddies: viv_buddy.php
                // - ???: viv_watcher.php
                // - signout: viv_signout.php
                MainServer.Instance.AddHTTPHandler(String.Format("{0}/viv_get_prelogin.php", m_freeSwitchAPIPrefix),
                                                     FreeSwitchSLVoiceGetPreloginHTTPHandler);

                MainServer.Instance.AddHTTPHandler(String.Format("{0}/freeswitch-config", m_freeSwitchAPIPrefix), FreeSwitchConfigHTTPHandler);

                // RestStreamHandler h = new
                // RestStreamHandler("GET",
                // String.Format("{0}/viv_get_prelogin.php", m_freeSwitchAPIPrefix), FreeSwitchSLVoiceGetPreloginHTTPHandler);
                //  MainServer.Instance.AddStreamHandler(h);

                MainServer.Instance.AddHTTPHandler(String.Format("{0}/viv_signin.php", m_freeSwitchAPIPrefix),
                                 FreeSwitchSLVoiceSigninHTTPHandler);

                MainServer.Instance.AddHTTPHandler(String.Format("{0}/viv_buddy.php", m_freeSwitchAPIPrefix),
                                 FreeSwitchSLVoiceBuddyHTTPHandler);
                
                MainServer.Instance.AddHTTPHandler(String.Format("{0}/viv_watcher.php", m_freeSwitchAPIPrefix),
                                 FreeSwitchSLVoiceWatcherHTTPHandler);                

                m_log.InfoFormat("[FreeSwitchVoice]: using FreeSwitch server {0}", m_freeSwitchRealm);

                m_Enabled = true;

                m_log.Info("[FreeSwitchVoice]: plugin enabled");
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("[FreeSwitchVoice]: plugin initialization failed: {0} {1}", e.Message, e.StackTrace);
                return;
            }

            // This here is a region module trying to make a global setting.
            // Not really a good idea but it's Windows only, so I can't test.
            try
            {
                ServicePointManager.ServerCertificateValidationCallback += CustomCertificateValidation;
            }
            catch (NotImplementedException)
            {
                try
                {
#pragma warning disable 0612, 0618
                    // Mono does not implement the ServicePointManager.ServerCertificateValidationCallback yet!  Don't remove this!
                    ServicePointManager.CertificatePolicy = new MonoCert();
#pragma warning restore 0612, 0618
                }
                catch (Exception)
                {
                    // COmmented multiline spam log message
                    //m_log.Error("[FreeSwitchVoice]: Certificate validation handler change not supported.  You may get ssl certificate validation errors teleporting from your region to some SSL regions.");
                }
            }
        }
        public string GetUrlForRegisteringClient(string SessionID, ulong RegionHandle)
        {
            string url = "/CAPS/EQMPOSTER" + UUID.Random();

            IHttpServer server = m_registry.RequestModuleInterface<ISimulationBase>().GetHttpServer(m_port);
            m_port = server.Port;

            m_FreeswitchService = m_registry.RequestModuleInterface<IFreeswitchService>();

            server.AddHTTPHandler(String.Format("{0}/{1}/freeswitch-config", m_freeSwitchAPIPrefix, UUID.Random()), FreeSwitchConfigHTTPHandler);
            server.AddHTTPHandler(String.Format("{0}/{1}/region-config", m_freeSwitchAPIPrefix, UUID.Random()), RegionConfigHTTPHandler);
            return url;
        }