Skip to content

Commit

Permalink
Make plugin_args array of strings, rename plugin_opt to plugin_opts
Browse files Browse the repository at this point in the history
  • Loading branch information
zonyitoo committed Oct 6, 2020
1 parent 113f0f6 commit a3dfda6
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/bin/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ fn main() {
if let Some(p) = matches.value_of("PLUGIN") {
let plugin = PluginConfig {
plugin: p.to_owned(),
plugin_opt: matches.value_of("PLUGIN_OPT").map(ToOwned::to_owned),
plugin_arg: None,
plugin_opts: matches.value_of("PLUGIN_OPT").map(ToOwned::to_owned),
plugin_args: Vec::new(),
};

sc.set_plugin(plugin);
Expand Down
4 changes: 2 additions & 2 deletions src/bin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ fn main() {
if let Some(p) = matches.value_of("PLUGIN") {
let plugin = PluginConfig {
plugin: p.to_owned(),
plugin_opt: matches.value_of("PLUGIN_OPT").map(ToOwned::to_owned),
plugin_arg: None,
plugin_opts: matches.value_of("PLUGIN_OPT").map(ToOwned::to_owned),
plugin_args: Vec::new(),
};

sc.set_plugin(plugin);
Expand Down
37 changes: 26 additions & 11 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ struct SSConfig {
#[serde(skip_serializing_if = "Option::is_none")]
plugin_opts: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
plugin_arg: Option<String>,
plugin_args: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
timeout: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -130,6 +130,8 @@ struct SSServerExtConfig {
#[serde(skip_serializing_if = "Option::is_none")]
plugin_opts: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
plugin_args: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
timeout: Option<u64>,
}

Expand Down Expand Up @@ -345,7 +347,7 @@ impl ServerConfig {
let mut url = format!("ss://{}@{}", encoded_user_info, self.addr());
if let Some(c) = self.plugin() {
let mut plugin = c.plugin.clone();
if let Some(ref opt) = c.plugin_opt {
if let Some(ref opt) = c.plugin_opts {
plugin += ";";
plugin += opt;
}
Expand Down Expand Up @@ -423,8 +425,8 @@ impl ServerConfig {
Some(p) => {
plugin = Some(PluginConfig {
plugin: p.to_owned(),
plugin_opt: vsp.next().map(ToOwned::to_owned),
plugin_arg: None,
plugin_opts: vsp.next().map(ToOwned::to_owned),
plugin_args: Vec::new(), // SIP002 doesn't have arguments for plugins
})
}
}
Expand Down Expand Up @@ -1212,8 +1214,8 @@ impl Config {
None => None,
Some(plugin) => Some(PluginConfig {
plugin,
plugin_opt: config.plugin_opts,
plugin_arg: config.plugin_arg,
plugin_opts: config.plugin_opts,
plugin_args: config.plugin_args.unwrap_or_default(),
}),
};

Expand Down Expand Up @@ -1260,8 +1262,8 @@ impl Config {
None => None,
Some(p) => Some(PluginConfig {
plugin: p,
plugin_opt: svr.plugin_opts,
plugin_arg: None,
plugin_opts: svr.plugin_opts,
plugin_args: svr.plugin_args.unwrap_or_default(),
}),
};

Expand Down Expand Up @@ -1495,8 +1497,14 @@ impl fmt::Display for Config {
jconf.method = Some(svr.method().to_string());
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.plugin_opts = svr.plugin().and_then(|p| p.plugin_opts.clone());
jconf.plugin_args = svr.plugin().and_then(|p| {
if p.plugin_args.is_empty() {
None
} else {
Some(p.plugin_args.clone())
}
});
jconf.timeout = svr.timeout().map(|t| t.as_secs());
}
_ => {
Expand All @@ -1515,7 +1523,14 @@ impl fmt::Display for Config {
password: svr.password().to_string(),
method: svr.method().to_string(),
plugin: svr.plugin().map(|p| p.plugin.to_string()),
plugin_opts: svr.plugin().and_then(|p| p.plugin_opt.clone()),
plugin_opts: svr.plugin().and_then(|p| p.plugin_opts.clone()),
plugin_args: svr.plugin().and_then(|p| {
if p.plugin_args.is_empty() {
None
} else {
Some(p.plugin_args.clone())
}
}),
timeout: svr.timeout().map(|t| t.as_secs()),
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/plugin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ mod ss_plugin;
#[derive(Debug, Clone)]
pub struct PluginConfig {
pub plugin: String,
pub plugin_opt: Option<String>,
pub plugin_arg: Option<String>,
pub plugin_opts: Option<String>,
pub plugin_args: Vec<String>,
}

/// Mode of Plugin
Expand Down
6 changes: 5 additions & 1 deletion src/plugin/obfs_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub fn plugin_cmd(plugin: &PluginConfig, remote: &ServerAddr, local: &SocketAddr
.arg("--data-dir")
.arg(format!("/tmp/{}_{}_{}", plugin.plugin, remote, local)); // FIXME: Not compatible in Windows

if let Some(ref opt) = plugin.plugin_opt {
if let Some(ref opt) = plugin.plugin_opts {
cmd.args(opt.split(' '));
}

Expand All @@ -51,5 +51,9 @@ pub fn plugin_cmd(plugin: &PluginConfig, remote: &ServerAddr, local: &SocketAddr
.arg(remote.to_string()),
};

if !plugin.plugin_args.is_empty() {
cmd.args(&plugin.plugin_args);
}

cmd
}
11 changes: 6 additions & 5 deletions src/plugin/ss_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ use tokio::process::Command;

pub fn plugin_cmd(plugin: &PluginConfig, remote: &ServerAddr, local: &SocketAddr, _mode: PluginMode) -> Command {
trace!(
"Starting plugin \"{}\", opt: {:?} remote: {}, local: {}",
"Starting plugin \"{}\", opt: {:?}, arg: {:?}, remote: {}, local: {}",
plugin.plugin,
plugin.plugin_opt,
plugin.plugin_opts,
plugin.plugin_args,
remote,
local
);
Expand All @@ -21,12 +22,12 @@ pub fn plugin_cmd(plugin: &PluginConfig, remote: &ServerAddr, local: &SocketAddr
.stdin(Stdio::null())
.kill_on_drop(true);

if let Some(ref opt) = plugin.plugin_opt {
if let Some(ref opt) = plugin.plugin_opts {
cmd.env("SS_PLUGIN_OPTIONS", opt);
}

if let Some(ref arg) = plugin.plugin_arg {
cmd.arg(arg);
if !plugin.plugin_args.is_empty() {
cmd.args(&plugin.plugin_args);
}

cmd
Expand Down
8 changes: 4 additions & 4 deletions src/relay/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ mod protocol {
#[serde(skip_serializing_if = "Option::is_none")]
pub plugin: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub plugin_opt: Option<String>,
pub plugin_opts: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub mode: Option<String>,
}
Expand Down Expand Up @@ -444,8 +444,8 @@ impl ManagerService {
match p.plugin {
Some(pp) => Some(PluginConfig {
plugin: pp,
plugin_opt: p.plugin_opt,
plugin_arg: None,
plugin_opts: p.plugin_opts,
plugin_args: Vec::new(),
}),
None => None,
},
Expand Down Expand Up @@ -519,7 +519,7 @@ impl ManagerService {
password: svr_cfg.password().to_string(),
no_delay: None,
plugin: None,
plugin_opt: None,
plugin_opts: None,
mode: None,
};

Expand Down

0 comments on commit a3dfda6

Please sign in to comment.