Beispiel #1
0
        public EndPoint GetPluginLocalEndPointIfConfigured(Server server)
        {
            var plugin = _pluginsByServer.GetOrAdd(
                server,
                x => Sip003Plugin.CreateIfConfigured(x, _config.showPluginOutput));

            if (plugin == null)
            {
                return(null);
            }

            try
            {
                if (plugin.StartIfNeeded())
                {
                    logger.Info(
                        $"Started SIP003 plugin for {server.Identifier()} on {plugin.LocalEndPoint} - PID: {plugin.ProcessId}");
                }
            }
            catch (Exception ex)
            {
                logger.Error("Failed to start SIP003 plugin: " + ex.Message);
                throw;
            }

            return(plugin.LocalEndPoint);
        }
Beispiel #2
0
        public void TestSip003Plugin_NoPlugin()
        {
            var NoPlugin = Sip003Plugin.CreateIfConfigured(new Server
            {
                server      = "192.168.100.1",
                server_port = 8888,
                password    = "******",
                method      = "bf-cfb"
            });

            RunPluginSupportTest(
                NoPlugin,
                "",
                "",
                "",
                "192.168.100.1",
                8888);
        }
Beispiel #3
0
        public void TestSip003Plugin_PluginWithArgs()
        {
            var PluginWithArgs = Sip003Plugin.CreateIfConfigured(new Server
            {
                server      = "192.168.100.1",
                server_port = 8888,
                password    = "******",
                method      = "bf-cfb",
                plugin      = fake_plugin,
                plugin_args = "_test"
            });

            RunPluginSupportTest(
                PluginWithArgs,
                fake_plugin,
                "",
                "_test",
                "192.168.100.1",
                8888);
        }
Beispiel #4
0
        private static void RunPluginSupportTest(Sip003Plugin plugin, string pluginName, string pluginOpts, string pluginArgs, string serverAddress, int serverPort)
        {
            if (string.IsNullOrWhiteSpace(pluginName))
            {
                return;
            }

            plugin.StartIfNeeded();

            Process[] processes = Process.GetProcessesByName(pluginName);
            Assert.AreEqual(processes.Length, 1);
            Process p = processes[0];


            var penv = ProcessEnvironment.ReadEnvironmentVariables(p);
            var pcmd = ProcessEnvironment.GetCommandLine(p).Trim();

            pcmd = pcmd.IndexOf(' ') >= 0 ? pcmd.Substring(pcmd.IndexOf(' ') + 1) : "";

            Assert.AreEqual(penv["SS_REMOTE_HOST"], serverAddress);
            Assert.AreEqual(penv["SS_REMOTE_PORT"], serverPort.ToString());
            Assert.AreEqual(penv["SS_LOCAL_HOST"], IPAddress.Loopback.ToString());

            int _ignored;

            Assert.IsTrue(int.TryParse(penv["SS_LOCAL_PORT"], out _ignored));

            Assert.AreEqual(penv["SS_PLUGIN_OPTIONS"], pluginOpts);
            Assert.AreEqual(pcmd, pluginArgs);


            plugin.Dispose();
            for (int i = 0; i < 50; i++)
            {
                if (Process.GetProcessesByName(pluginName).Length == 0)
                {
                    return;
                }
                Thread.Sleep(50);
            }
        }
Beispiel #5
0
        public void TestSip003Plugin_PluginWithOptsAndArgsReplaced()
        {
            var PluginWithOptsAndArgsReplaced = Sip003Plugin.CreateIfConfigured(new Server
            {
                server      = "192.168.100.1",
                server_port = 8888,
                password    = "******",
                method      = "bf-cfb",
                plugin      = fake_plugin,
                plugin_opts = "_option",
                plugin_args = "_test,%SS_REMOTE_HOST%,%SS_PLUGIN_OPTIONS%"
            });

            RunPluginSupportTest(
                PluginWithOptsAndArgsReplaced,
                fake_plugin,
                "_option",
                "_test,192.168.100.1,_option",
                "192.168.100.1",
                8888);
        }
Beispiel #6
0
        public void TestSip003Plugin_PluginWithArgsReplaced()
        {
            var PluginWithArgsReplaced = Sip003Plugin.CreateIfConfigured(
                new Server
            {
                server      = "192.168.100.1",
                server_port = 8888,
                password    = "******",
                method      = "bf-cfb",
                plugin      = fake_plugin,
                plugin_args = "_test,%SS_REMOTE_HOST%"
            },
                false);

            RunPluginSupportTest(
                PluginWithArgsReplaced,
                fake_plugin,
                "",
                "_test,192.168.100.1",
                "192.168.100.1",
                8888);
        }