Skip to content

Commit

Permalink
Allow passing in an optional plugin_arg
Browse files Browse the repository at this point in the history
  • Loading branch information
Mygod authored and zonyitoo committed Oct 6, 2020
1 parent 988e69d commit 113f0f6
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/bin/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/bin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ struct SSConfig {
#[serde(skip_serializing_if = "Option::is_none")]
plugin_opts: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
plugin_arg: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
timeout: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
udp_timeout: Option<u64>,
Expand Down Expand Up @@ -422,6 +424,7 @@ impl ServerConfig {
plugin = Some(PluginConfig {
plugin: p.to_owned(),
plugin_opt: vsp.next().map(ToOwned::to_owned),
plugin_arg: None,
})
}
}
Expand Down Expand Up @@ -1210,6 +1213,7 @@ impl Config {
Some(plugin) => Some(PluginConfig {
plugin,
plugin_opt: config.plugin_opts,
plugin_arg: config.plugin_arg,
}),
};

Expand Down Expand Up @@ -1257,6 +1261,7 @@ impl Config {
Some(p) => Some(PluginConfig {
plugin: p,
plugin_opt: svr.plugin_opts,
plugin_arg: None,
}),
};

Expand Down Expand Up @@ -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());
}
_ => {
Expand Down
1 change: 1 addition & 0 deletions src/plugin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ mod ss_plugin;
pub struct PluginConfig {
pub plugin: String,
pub plugin_opt: Option<String>,
pub plugin_arg: Option<String>,
}

/// Mode of Plugin
Expand Down
4 changes: 4 additions & 0 deletions src/plugin/ss_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
1 change: 1 addition & 0 deletions src/relay/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ impl ManagerService {
Some(pp) => Some(PluginConfig {
plugin: pp,
plugin_opt: p.plugin_opt,
plugin_arg: None,
}),
None => None,
},
Expand Down

0 comments on commit 113f0f6

Please sign in to comment.