Skip to content

Commit

Permalink
crossroads: Do not output descendants on introspection
Browse files Browse the repository at this point in the history
Fixes: #412
  • Loading branch information
diwic committed Jan 3, 2023
1 parent e025d99 commit 76cb265
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
8 changes: 5 additions & 3 deletions dbus-crossroads/src/crossroads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,17 +224,19 @@ impl Crossroads {
(&self.registry, &obj.ifaces)
}

pub (crate) fn get_children(&self, path: &dbus::Path<'static>) -> Vec<&str> {
pub (crate) fn get_children(&self, path: &dbus::Path<'static>, direct_only: bool) -> Vec<&str> {
use std::ops::Bound;
let mut range = self.map.range((Bound::Excluded(path), Bound::Unbounded));
let p2 = path.as_bytes();
let substart = if &p2 == &b"/" { 0 } else { p2.len() };
let mut r = vec!();
let mut r: Vec<&str> = vec!();
while let Some((c, _)) = range.next() {
if !c.as_bytes().starts_with(p2) { break; }
let csub: &str = &c[substart..];
if csub.len() == 0 || csub.as_bytes()[0] != b'/' { continue; }
r.push(&csub[1..]);
let csub1 = &csub[1..];
if direct_only && r.len() > 0 && csub1.as_bytes().starts_with(r[r.len()-1].as_bytes()) { continue; }
r.push(csub1);
};
r
}
Expand Down
4 changes: 2 additions & 2 deletions dbus-crossroads/src/stdimpl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::marker::PhantomData;
use crate::ifacedesc::EMITS_CHANGED;

fn introspect(cr: &Crossroads, path: &dbus::Path<'static>) -> String {
let mut children = cr.get_children(path);
let mut children = cr.get_children(path, true);
let mut childstr = String::new();
children.sort_unstable();
for c in children {
Expand Down Expand Up @@ -347,7 +347,7 @@ fn get_managed_objects(mut ctx: Context, cr: &mut Crossroads, _: ()) -> Option<C
// HashMap<dbus::Path<'static>, IfacePropMap>
let parent = ctx.path();
let children: Vec<dbus::Path<'static>> =
cr.get_children(ctx.path()).into_iter().map(|child_path| {
cr.get_children(ctx.path(), false).into_iter().map(|child_path| {
let mut x = String::from(&**parent);
if !x.ends_with('/') {
x.push_str("/");
Expand Down
1 change: 1 addition & 0 deletions dbus-crossroads/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ fn introspect() {
});
cr.insert("/com/example/sample_object0", &[token], ());
cr.insert("/com/example/sample_object0/child_of_sample_object", &[], ());
cr.insert("/com/example/sample_object0/child_of_sample_object/subchild", &[], ());
cr.insert("/com/example/sample_object0123", &[], ());
cr.insert("/com/example/sample_object0/another_child_of_sample_object", &[], ());

Expand Down

0 comments on commit 76cb265

Please sign in to comment.