interpreter: feed in default namespaces

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2023-07-27 23:52:09 +02:00
parent b7399dc9a5
commit 365f5d60a2

View file

@ -13,12 +13,13 @@
// You should have received a copy of the GNU Affero General Public License // You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::element::ScanElement; use crate::element::{ScanElement, DEFAULT_NS, SCANSION_NS};
use crate::parsers::{parse_spec, Token}; use crate::parsers::{parse_spec, Token};
use crate::types::{Action, Context, Entity, Spec}; use crate::types::{Action, Context, Entity, Spec};
use jid::Jid; use jid::Jid;
use minidom::{Element, Error as MinidomError}; use minidom::{Element, Error as MinidomError};
use rand::{thread_rng, Rng}; use rand::{thread_rng, Rng};
use std::collections::BTreeMap;
#[cfg_attr(test, derive(PartialEq))] #[cfg_attr(test, derive(PartialEq))]
#[derive(Debug)] #[derive(Debug)]
@ -82,16 +83,30 @@ pub fn read_actions(spec: Spec, context: &Context) -> Result<InOutStanza, Minido
.get(&name) .get(&name)
.expect(format!("Name '{}' not found in clients", name).as_str()); .expect(format!("Name '{}' not found in clients", name).as_str());
let elem = s.parse::<Element>()?; let prefixes: BTreeMap<Option<String>, String> = {
inout.receives(ScanElement::new(elem).with_context(Some(&context))); let mut tmp = BTreeMap::new();
tmp.insert(None, String::from(DEFAULT_NS));
tmp.insert(Some(String::from("scansion")), String::from(SCANSION_NS));
tmp
};
let elem = Element::from_reader_with_prefixes(s.as_ref(), prefixes)?;
inout.receives(ScanElement::new(elem).apply_context(&context));
} }
Action::Send(name, s) => { Action::Send(name, s) => {
let _ = context let _ = context
.get(&name) .get(&name)
.expect(format!("Name '{}' not found in clients", name).as_str()); .expect(format!("Name '{}' not found in clients", name).as_str());
let elem = s.parse::<Element>()?; let prefixes: BTreeMap<Option<String>, String> = {
inout.sends(ScanElement::new(elem).with_context(Some(&context))); let mut tmp = BTreeMap::new();
tmp.insert(None, String::from(DEFAULT_NS));
tmp.insert(Some(String::from("scansion")), String::from(SCANSION_NS));
tmp
};
let elem = Element::from_reader_with_prefixes(s.as_ref(), prefixes)?;
inout.sends(ScanElement::new(elem).apply_context(&context));
} }
_ => (), _ => (),
} }