mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
plugins/ibb: IBB enum not available in the parser anymore
This commit is contained in:
parent
1a8ea2e383
commit
1a9a100bdc
1 changed files with 86 additions and 69 deletions
|
@ -10,7 +10,7 @@ use jid::Jid;
|
||||||
use plugins::stanza::Iq;
|
use plugins::stanza::Iq;
|
||||||
use plugins::disco::DiscoPlugin;
|
use plugins::disco::DiscoPlugin;
|
||||||
use xmpp_parsers::iq::{IqType, IqSetPayload};
|
use xmpp_parsers::iq::{IqType, IqSetPayload};
|
||||||
use xmpp_parsers::ibb::{IBB, Stanza};
|
use xmpp_parsers::ibb::{Open, Data, Close, Stanza};
|
||||||
use xmpp_parsers::stanza_error::{StanzaError, ErrorType, DefinedCondition};
|
use xmpp_parsers::stanza_error::{StanzaError, ErrorType, DefinedCondition};
|
||||||
use xmpp_parsers::ns;
|
use xmpp_parsers::ns;
|
||||||
|
|
||||||
|
@ -86,10 +86,9 @@ impl IbbPlugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_ibb(&self, from: Jid, ibb: IBB) -> Result<(), StanzaError> {
|
fn handle_ibb_open(&self, from: Jid, open: Open) -> Result<(), StanzaError> {
|
||||||
let mut sessions = self.sessions.lock().unwrap();
|
let mut sessions = self.sessions.lock().unwrap();
|
||||||
match ibb {
|
let Open { block_size, sid, stanza } = open;
|
||||||
IBB::Open { block_size, sid, stanza } => {
|
|
||||||
match sessions.entry((from.clone(), sid.clone())) {
|
match sessions.entry((from.clone(), sid.clone())) {
|
||||||
Entry::Vacant(_) => Ok(()),
|
Entry::Vacant(_) => Ok(()),
|
||||||
Entry::Occupied(_) => Err(generate_error(
|
Entry::Occupied(_) => Err(generate_error(
|
||||||
|
@ -107,8 +106,12 @@ impl IbbPlugin {
|
||||||
self.proxy.dispatch(IbbOpen {
|
self.proxy.dispatch(IbbOpen {
|
||||||
session: session,
|
session: session,
|
||||||
});
|
});
|
||||||
},
|
Ok(())
|
||||||
IBB::Data { seq, sid, data } => {
|
}
|
||||||
|
|
||||||
|
fn handle_ibb_data(&self, from: Jid, data: Data) -> Result<(), StanzaError> {
|
||||||
|
let mut sessions = self.sessions.lock().unwrap();
|
||||||
|
let Data { seq, sid, data } = data;
|
||||||
let entry = match sessions.entry((from, sid)) {
|
let entry = match sessions.entry((from, sid)) {
|
||||||
Entry::Occupied(entry) => Ok(entry),
|
Entry::Occupied(entry) => Ok(entry),
|
||||||
Entry::Vacant(_) => Err(generate_error(
|
Entry::Vacant(_) => Err(generate_error(
|
||||||
|
@ -117,7 +120,7 @@ impl IbbPlugin {
|
||||||
"This session doesn’t exist."
|
"This session doesn’t exist."
|
||||||
)),
|
)),
|
||||||
}?;
|
}?;
|
||||||
let mut session = entry.into_mut();
|
let session = entry.into_mut();
|
||||||
if session.stanza != Stanza::Iq {
|
if session.stanza != Stanza::Iq {
|
||||||
return Err(generate_error(
|
return Err(generate_error(
|
||||||
ErrorType::Cancel,
|
ErrorType::Cancel,
|
||||||
|
@ -138,8 +141,12 @@ impl IbbPlugin {
|
||||||
session: session.clone(),
|
session: session.clone(),
|
||||||
data,
|
data,
|
||||||
});
|
});
|
||||||
},
|
Ok(())
|
||||||
IBB::Close { sid } => {
|
}
|
||||||
|
|
||||||
|
fn handle_ibb_close(&self, from: Jid, close: Close) -> Result<(), StanzaError> {
|
||||||
|
let mut sessions = self.sessions.lock().unwrap();
|
||||||
|
let Close { sid } = close;
|
||||||
let entry = match sessions.entry((from, sid)) {
|
let entry = match sessions.entry((from, sid)) {
|
||||||
Entry::Occupied(entry) => Ok(entry),
|
Entry::Occupied(entry) => Ok(entry),
|
||||||
Entry::Vacant(_) => Err(generate_error(
|
Entry::Vacant(_) => Err(generate_error(
|
||||||
|
@ -152,8 +159,6 @@ impl IbbPlugin {
|
||||||
self.proxy.dispatch(IbbClose {
|
self.proxy.dispatch(IbbClose {
|
||||||
session,
|
session,
|
||||||
});
|
});
|
||||||
},
|
|
||||||
}
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,8 +169,20 @@ impl IbbPlugin {
|
||||||
let id = iq.id.unwrap();
|
let id = iq.id.unwrap();
|
||||||
// TODO: use an intermediate plugin to parse this payload.
|
// TODO: use an intermediate plugin to parse this payload.
|
||||||
let payload = match IqSetPayload::try_from(payload) {
|
let payload = match IqSetPayload::try_from(payload) {
|
||||||
Ok(IqSetPayload::IBB(ibb)) => {
|
Ok(IqSetPayload::IbbOpen(open)) => {
|
||||||
match self.handle_ibb(from.clone(), ibb) {
|
match self.handle_ibb_open(from.clone(), open) {
|
||||||
|
Ok(_) => IqType::Result(None),
|
||||||
|
Err(error) => IqType::Error(error),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Ok(IqSetPayload::IbbData(data)) => {
|
||||||
|
match self.handle_ibb_data(from.clone(), data) {
|
||||||
|
Ok(_) => IqType::Result(None),
|
||||||
|
Err(error) => IqType::Error(error),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Ok(IqSetPayload::IbbClose(close)) => {
|
||||||
|
match self.handle_ibb_close(from.clone(), close) {
|
||||||
Ok(_) => IqType::Result(None),
|
Ok(_) => IqType::Result(None),
|
||||||
Err(error) => IqType::Error(error),
|
Err(error) => IqType::Error(error),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue