Compare commits
2 Commits
53bce50978
...
52f13a3589
Author | SHA1 | Date | |
---|---|---|---|
52f13a3589 | |||
64bbaccc3a |
@@ -11,6 +11,9 @@ pub use self::contacts::*;
|
|||||||
mod contact_list;
|
mod contact_list;
|
||||||
pub use self::contact_list::*;
|
pub use self::contact_list::*;
|
||||||
|
|
||||||
|
mod escape;
|
||||||
|
use self::escape::escape;
|
||||||
|
|
||||||
mod requests;
|
mod requests;
|
||||||
pub use self::requests::*;
|
pub use self::requests::*;
|
||||||
|
|
||||||
@@ -283,8 +286,8 @@ impl Connection {
|
|||||||
let contacts_iface =
|
let contacts_iface =
|
||||||
telepathy::connection_interface_contacts_server(&f, (), move |_| c_rc3.clone());
|
telepathy::connection_interface_contacts_server(&f, (), move |_| c_rc3.clone());
|
||||||
|
|
||||||
let c_rc4 = c_rc.clone();
|
let _c_rc4 = c_rc.clone();
|
||||||
let contact_list_iface =
|
let _contact_list_iface =
|
||||||
telepathy::connection_interface_contact_list_server(&f, (), move |_| c_rc4.clone());
|
telepathy::connection_interface_contact_list_server(&f, (), move |_| c_rc4.clone());
|
||||||
|
|
||||||
let c_rc5 = c_rc.clone();
|
let c_rc5 = c_rc.clone();
|
||||||
@@ -300,7 +303,7 @@ impl Connection {
|
|||||||
.add(conn_iface)
|
.add(conn_iface)
|
||||||
.add(avatars_iface)
|
.add(avatars_iface)
|
||||||
.add(contacts_iface)
|
.add(contacts_iface)
|
||||||
.add(contact_list_iface)
|
// .add(contact_list_iface)
|
||||||
.add(requests_iface)
|
.add(requests_iface)
|
||||||
.add(simple_presence_iface),
|
.add(simple_presence_iface),
|
||||||
);
|
);
|
||||||
@@ -309,56 +312,3 @@ impl Connection {
|
|||||||
tree
|
tree
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn escape_one(b: u8) -> String {
|
|
||||||
format!("_{:0<2x}", b)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Some non-empty sequence of ASCII letters, digits and underscores
|
|
||||||
fn escape(s: String) -> String {
|
|
||||||
// Special-case the empty string
|
|
||||||
if s.is_empty() {
|
|
||||||
return "_".to_string();
|
|
||||||
}
|
|
||||||
|
|
||||||
let bytes = s.into_bytes();
|
|
||||||
let mut iter = bytes.iter();
|
|
||||||
let mut out = String::new();
|
|
||||||
|
|
||||||
// Only alphanumeric in the first byte
|
|
||||||
let x = *iter.next().expect("Already checked len > 0");
|
|
||||||
let first = match x {
|
|
||||||
b'a'..=b'z' | b'A'..=b'Z' => unsafe { String::from_utf8_unchecked(vec![x]) },
|
|
||||||
_ => escape_one(x),
|
|
||||||
};
|
|
||||||
|
|
||||||
out.push_str(&first);
|
|
||||||
|
|
||||||
for x in iter {
|
|
||||||
let next = match x {
|
|
||||||
b'a'..=b'z' | b'A'..=b'Z' | b'0'..=b'9' => unsafe {
|
|
||||||
String::from_utf8_unchecked(vec![*x])
|
|
||||||
},
|
|
||||||
_ => escape_one(*x),
|
|
||||||
};
|
|
||||||
|
|
||||||
out.push_str(&next);
|
|
||||||
}
|
|
||||||
|
|
||||||
out
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_escape() {
|
|
||||||
assert_eq!(escape("".to_string()), "_");
|
|
||||||
assert_eq!(escape("foo".to_string()), "foo");
|
|
||||||
assert_eq!(escape("foo@bar".to_string()), "foo_40bar");
|
|
||||||
assert_eq!(escape("foo_bar".to_string()), "foo_5fbar");
|
|
||||||
assert_eq!(escape("foo__@__bar".to_string()), "foo_5f_5f_40_5f_5fbar");
|
|
||||||
assert_eq!(escape("1foo".to_string()), "_31foo");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@@ -19,7 +19,7 @@ pub fn connection_interfaces() -> Vec<String> {
|
|||||||
"org.freedesktop.Telepathy.Connection".to_string(),
|
"org.freedesktop.Telepathy.Connection".to_string(),
|
||||||
"org.freedesktop.Telepathy.Connection.Interface.Avatars".to_string(),
|
"org.freedesktop.Telepathy.Connection.Interface.Avatars".to_string(),
|
||||||
"org.freedesktop.Telepathy.Connection.Interface.Contacts".to_string(),
|
"org.freedesktop.Telepathy.Connection.Interface.Contacts".to_string(),
|
||||||
"org.freedesktop.Telepathy.Connection.Interface.ContactList".to_string(),
|
// "org.freedesktop.Telepathy.Connection.Interface.ContactList".to_string(),
|
||||||
"org.freedesktop.Telepathy.Connection.Interface.Requests".to_string(),
|
"org.freedesktop.Telepathy.Connection.Interface.Requests".to_string(),
|
||||||
"org.freedesktop.Telepathy.Connection.Interface.SimplePresence".to_string(),
|
"org.freedesktop.Telepathy.Connection.Interface.SimplePresence".to_string(),
|
||||||
]
|
]
|
||||||
|
@@ -51,7 +51,7 @@ impl telepathy::ConnectionInterfaceContacts for Connection {
|
|||||||
"org.freedesktop.Telepathy.Connection.Interface.Avatars/token".to_string(),
|
"org.freedesktop.Telepathy.Connection.Interface.Avatars/token".to_string(),
|
||||||
Variant(Box::new("".to_string())),
|
Variant(Box::new("".to_string())),
|
||||||
);
|
);
|
||||||
|
/*
|
||||||
// TODO: we need to publish DBUS services on these endpoints
|
// TODO: we need to publish DBUS services on these endpoints
|
||||||
props.insert(
|
props.insert(
|
||||||
"org.freedesktop.Telepathy.Connection.Interface.ContactList/publish".to_string(),
|
"org.freedesktop.Telepathy.Connection.Interface.ContactList/publish".to_string(),
|
||||||
@@ -62,7 +62,7 @@ impl telepathy::ConnectionInterfaceContacts for Connection {
|
|||||||
"org.freedesktop.Telepathy.Connection.Interface.ContactList/subscribe".to_string(),
|
"org.freedesktop.Telepathy.Connection.Interface.ContactList/subscribe".to_string(),
|
||||||
Variant(Box::new(4)),
|
Variant(Box::new(4)),
|
||||||
);
|
);
|
||||||
|
*/
|
||||||
out.insert(*id, props);
|
out.insert(*id, props);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,7 +89,7 @@ impl telepathy::ConnectionInterfaceContacts for Connection {
|
|||||||
Ok(vec![
|
Ok(vec![
|
||||||
"org.freedesktop.Telepathy.Connection".to_string(),
|
"org.freedesktop.Telepathy.Connection".to_string(),
|
||||||
"org.freedesktop.Telepathy.Connection.Interface.Avatars".to_string(),
|
"org.freedesktop.Telepathy.Connection.Interface.Avatars".to_string(),
|
||||||
"org.freedesktop.Telepathy.Connection.Interface.ContactList".to_string(),
|
// "org.freedesktop.Telepathy.Connection.Interface.ContactList".to_string(),
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
52
src/padfoot/connection/escape.rs
Normal file
52
src/padfoot/connection/escape.rs
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
fn escape_one(b: u8) -> String {
|
||||||
|
format!("_{:0<2x}", b)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Some non-empty sequence of ASCII letters, digits and underscores
|
||||||
|
pub fn escape(s: String) -> String {
|
||||||
|
// Special-case the empty string
|
||||||
|
if s.is_empty() {
|
||||||
|
return "_".to_string();
|
||||||
|
}
|
||||||
|
|
||||||
|
let bytes = s.into_bytes();
|
||||||
|
let mut iter = bytes.iter();
|
||||||
|
let mut out = String::new();
|
||||||
|
|
||||||
|
// Only alphanumeric in the first byte
|
||||||
|
let x = *iter.next().expect("Already checked len > 0");
|
||||||
|
let first = match x {
|
||||||
|
b'a'..=b'z' | b'A'..=b'Z' => unsafe { String::from_utf8_unchecked(vec![x]) },
|
||||||
|
_ => escape_one(x),
|
||||||
|
};
|
||||||
|
|
||||||
|
out.push_str(&first);
|
||||||
|
|
||||||
|
for x in iter {
|
||||||
|
let next = match x {
|
||||||
|
b'a'..=b'z' | b'A'..=b'Z' | b'0'..=b'9' => unsafe {
|
||||||
|
String::from_utf8_unchecked(vec![*x])
|
||||||
|
},
|
||||||
|
_ => escape_one(*x),
|
||||||
|
};
|
||||||
|
|
||||||
|
out.push_str(&next);
|
||||||
|
}
|
||||||
|
|
||||||
|
out
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_escape() {
|
||||||
|
assert_eq!(escape("".to_string()), "_");
|
||||||
|
assert_eq!(escape("foo".to_string()), "foo");
|
||||||
|
assert_eq!(escape("foo@bar".to_string()), "foo_40bar");
|
||||||
|
assert_eq!(escape("foo_bar".to_string()), "foo_5fbar");
|
||||||
|
assert_eq!(escape("foo__@__bar".to_string()), "foo_5f_5f_40_5f_5fbar");
|
||||||
|
assert_eq!(escape("1foo".to_string()), "_31foo");
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user