}
struct CommandStream<'d> {
+ chan: MgmtChannel,
+ d: CommandStreamData<'d>,
+}
+
+struct CommandStreamData<'d> {
euid: Result<Uid, ConnectionEuidDiscoverEerror>,
desc: &'d str,
account: Option<AccountSpecified>,
superuser: Option<AuthorisationSuperuser>,
- chan: MgmtChannel,
}
#[derive(Debug,Clone)]
// ---------- management command implementations
#[throws(ME)]
-fn execute(cs: &mut CommandStream, cmd: MgmtCommand) -> MgmtResponse {
+fn execute(cs: &mut CommandStreamData, cmd: MgmtCommand) -> MgmtResponse {
match cmd {
MC::Noop => Fine,
//#[throws(ME)]
fn execute_game_insn<'cs, 'igr, 'ig: 'igr>(
- cs: &'cs CommandStream,
+ cs: &'cs CommandStreamData,
ag: &'_ mut AccountsGuard,
ig: &'igr mut Unauthorised<InstanceGuard<'ig>, InstanceName>,
update: MgmtGameInstruction,
P: Into<PermSet<TablePermission>>>
(
- cs: &'cs CommandStream,
+ cs: &'cs CommandStreamData,
ag: &AccountsGuard,
ig: &'igr mut Unauthorised<InstanceGuard<'ig>, InstanceName>,
p: P,
fn pieceid_lookup<'igr, 'ig: 'igr, 'cs,
F: FnOnce(&PerPlayerIdMap) -> MGR>
(
- cs: &'cs CommandStream,
+ cs: &'cs CommandStreamData,
ig: &'igr mut Unauthorised<InstanceGuard<'ig>, InstanceName>,
player: PlayerId,
f: F,
fn update_links<'igr, 'ig: 'igr, 'cs,
F: FnOnce(&mut Arc<LinksTable>) -> Result<Html,ME>>
(
- cs: &'cs CommandStream,
+ cs: &'cs CommandStreamData,
ag: &'_ mut AccountsGuard,
ig: &'igr mut Unauthorised<InstanceGuard<'ig>, InstanceName>,
f: F
Fine, None, vec![], ig)
}
- impl<'cs> CommandStream<'cs> {
+ impl<'cs> CommandStreamData<'cs> {
#[throws(MgmtError)]
fn check_acl_manip_player_access<'igr, 'ig: 'igr>(
&self,
#[throws(ME)]
fn execute_for_game<'cs, 'igr, 'ig: 'igr>(
- cs: &'cs CommandStream,
+ cs: &'cs CommandStreamData,
ag: &mut AccountsGuard,
igu: &'igr mut Unauthorised<InstanceGuard<'ig>, InstanceName>,
insns: Vec<MgmtGameInstruction>,
cmd_s.truncate(MAX-3);
cmd_s += "..";
}
- match execute(&mut self, cmd) {
+ match execute(&mut self.d, cmd) {
Ok(resp) => {
info!("command connection {}: executed {}",
- &self.desc, cmd_s);
+ &self.d.desc, cmd_s);
resp
}
Err(error) => {
info!("command connection {}: error {:?} from {}",
- &self.desc, &error, cmd_s);
+ &self.d.desc, &error, cmd_s);
MgmtResponse::Error { error }
}
}
self.chan.write(&resp).context("swrite command stream")?;
}
}
+}
+impl CommandStreamData<'_> {
#[throws(MgmtError)]
fn current_account(&self) -> &AccountSpecified {
self.account.as_ref().ok_or(ME::SpecifyAccount)?
let chan = MgmtChannel::new(conn)?;
- let cs = CommandStream {
+ let d = CommandStreamData {
account: None, desc: &desc,
- chan, euid: euid.map(Uid::from_raw),
+ euid: euid.map(Uid::from_raw),
superuser: None,
};
+ let cs = CommandStream { chan, d };
cs.mainloop()?;
<Result<_,StartupError>>::Ok(())
}
}
-impl CommandStream<'_> {
+impl CommandStreamData<'_> {
#[throws(AuthorisationError)]
fn authorised_uid(&self, wanted: Option<Uid>, xinfo: Option<&str>)
-> Authorisation<Uid> {
}
}
-impl CommandStream<'_> {
+impl CommandStreamData<'_> {
pub fn is_superuser<T:Serialize>(&self) -> Option<Authorisation<T>> {
self.superuser.map(Into::into)
}
p: P,
) -> (&'igr mut InstanceGuard<'ig>, Authorisation<InstanceName>) {
#[throws(MgmtError)]
- fn get_auth(cs: &CommandStream,
+ fn get_auth(cs: &CommandStreamData,
ag: &AccountsGuard,
ig: &mut Unauthorised<InstanceGuard, InstanceName>,
how: PermissionCheckHow,
#[throws(MgmtError)]
fn authorise_for_account(
- cs: &CommandStream,
+ cs: &CommandStreamData,
_accounts: &AccountsGuard,
wanted: &AccountName,
) -> Authorisation<AccountName> {
}
#[throws(MgmtError)]
-fn authorise_by_account(cs: &CommandStream, ag: &AccountsGuard,
+fn authorise_by_account(cs: &CommandStreamData, ag: &AccountsGuard,
wanted: &InstanceName)
-> Authorisation<InstanceName> {
let account = &wanted.account;
}
#[throws(MgmtError)]
-fn authorise_scope_direct(cs: &CommandStream, wanted: &AccountScope)
+fn authorise_scope_direct(cs: &CommandStreamData, wanted: &AccountScope)
-> Authorisation<AccountScope> {
// Usually, use authorise_by_account
do_authorise_scope(cs, wanted)
}
#[throws(AuthorisationError)]
-fn do_authorise_scope(cs: &CommandStream, wanted: &AccountScope)
+fn do_authorise_scope(cs: &CommandStreamData, wanted: &AccountScope)
-> Authorisation<AccountScope> {
if let Some(y) = cs.is_superuser() { return y }