From 113f0f6db2d7da22cfc03147033afca1cfe6b137 Mon Sep 17 00:00:00 2001 From: Mygod Date: Mon, 5 Oct 2020 05:19:05 +0800 Subject: [PATCH] Allow passing in an optional plugin_arg --- src/bin/local.rs | 1 + src/bin/server.rs | 1 + src/config.rs | 6 ++++++ src/plugin/mod.rs | 1 + src/plugin/ss_plugin.rs | 4 ++++ src/relay/manager.rs | 1 + 6 files changed, 14 insertions(+) diff --git a/src/bin/local.rs b/src/bin/local.rs index 4d8e1c33e93e..bae9b72e57b4 100644 --- a/src/bin/local.rs +++ b/src/bin/local.rs @@ -205,6 +205,7 @@ fn main() { let plugin = PluginConfig { plugin: p.to_owned(), plugin_opt: matches.value_of("PLUGIN_OPT").map(ToOwned::to_owned), + plugin_arg: None, }; sc.set_plugin(plugin); diff --git a/src/bin/server.rs b/src/bin/server.rs index 7f3b04d17390..c9adb010a5b0 100644 --- a/src/bin/server.rs +++ b/src/bin/server.rs @@ -111,6 +111,7 @@ fn main() { let plugin = PluginConfig { plugin: p.to_owned(), plugin_opt: matches.value_of("PLUGIN_OPT").map(ToOwned::to_owned), + plugin_arg: None, }; sc.set_plugin(plugin); diff --git a/src/config.rs b/src/config.rs index 90e3958a75c5..ac2e476ddfa7 100644 --- a/src/config.rs +++ b/src/config.rs @@ -98,6 +98,8 @@ struct SSConfig { #[serde(skip_serializing_if = "Option::is_none")] plugin_opts: Option, #[serde(skip_serializing_if = "Option::is_none")] + plugin_arg: Option, + #[serde(skip_serializing_if = "Option::is_none")] timeout: Option, #[serde(skip_serializing_if = "Option::is_none")] udp_timeout: Option, @@ -422,6 +424,7 @@ impl ServerConfig { plugin = Some(PluginConfig { plugin: p.to_owned(), plugin_opt: vsp.next().map(ToOwned::to_owned), + plugin_arg: None, }) } } @@ -1210,6 +1213,7 @@ impl Config { Some(plugin) => Some(PluginConfig { plugin, plugin_opt: config.plugin_opts, + plugin_arg: config.plugin_arg, }), }; @@ -1257,6 +1261,7 @@ impl Config { Some(p) => Some(PluginConfig { plugin: p, plugin_opt: svr.plugin_opts, + plugin_arg: None, }), }; @@ -1491,6 +1496,7 @@ impl fmt::Display for Config { jconf.password = Some(svr.password().to_string()); jconf.plugin = svr.plugin().map(|p| p.plugin.to_string()); jconf.plugin_opts = svr.plugin().and_then(|p| p.plugin_opt.clone()); + jconf.plugin_arg = svr.plugin().and_then(|p| p.plugin_arg.clone()); jconf.timeout = svr.timeout().map(|t| t.as_secs()); } _ => { diff --git a/src/plugin/mod.rs b/src/plugin/mod.rs index bc07b7a7950a..c13885ae8bb7 100644 --- a/src/plugin/mod.rs +++ b/src/plugin/mod.rs @@ -35,6 +35,7 @@ mod ss_plugin; pub struct PluginConfig { pub plugin: String, pub plugin_opt: Option, + pub plugin_arg: Option, } /// Mode of Plugin diff --git a/src/plugin/ss_plugin.rs b/src/plugin/ss_plugin.rs index 5007f85a97ca..00b56bf9cc73 100644 --- a/src/plugin/ss_plugin.rs +++ b/src/plugin/ss_plugin.rs @@ -25,5 +25,9 @@ pub fn plugin_cmd(plugin: &PluginConfig, remote: &ServerAddr, local: &SocketAddr cmd.env("SS_PLUGIN_OPTIONS", opt); } + if let Some(ref arg) = plugin.plugin_arg { + cmd.arg(arg); + } + cmd } diff --git a/src/relay/manager.rs b/src/relay/manager.rs index c5c007b166d2..e76abe038dfc 100644 --- a/src/relay/manager.rs +++ b/src/relay/manager.rs @@ -445,6 +445,7 @@ impl ManagerService { Some(pp) => Some(PluginConfig { plugin: pp, plugin_opt: p.plugin_opt, + plugin_arg: None, }), None => None, },