Return protocol parameters

This commit is contained in:
2020-05-09 11:19:40 +01:00
parent 5328ae9bd6
commit 40ea57a0cc
5 changed files with 62 additions and 30 deletions

View File

@@ -0,0 +1,4 @@
[D-BUS Service]
Name=org.freedesktop.Telepathy.ConnectionManager.padfoot
Exec=/usr/lib/telepathy/telepathy-padfoot
//SystemdService=telepathy-padfoot.service

View File

@@ -0,0 +1,11 @@
[ConnectionManager]
Name = padfoot
BusName = org.freedesktop.Telepathy.ConnectionManager.padfoot
ObjectPath = /org/freedesktop/Telepathy/ConnectionManager/padfoot
[Protocol delta]
param-account = s required
param-password = s required secret
EnglishName=Delta Chat
Icon=delta

View File

@@ -4,7 +4,7 @@ mod telepathy;
//use dbus::tree::{Interface, MTFn, MethodErr};
use dbus::{
blocking::{stdintf::org_freedesktop_dbus::RequestNameReply, LocalConnection},
tree::{Factory, Interface, MTFn, Tree},
tree::{Factory, MTFn, Tree},
};
use padfoot::{CMData, ConnectionManager};
@@ -14,8 +14,8 @@ use std::time::Duration;
use anyhow::{anyhow, Result};
const BUS_NAME: &'static str = "org.freedesktop.Telepathy.ConnectionManager.padfoot";
const OBJECT_PATH: &'static str = "/org/freedesktop/Telepathy/ConnectionManager/padfoot";
const CM_BUS_NAME: &'static str = "org.freedesktop.Telepathy.ConnectionManager.padfoot";
const CM_OBJECT_PATH: &'static str = "/org/freedesktop/Telepathy/ConnectionManager/padfoot";
fn create_tree(cm: &Arc<ConnectionManager>) -> Tree<MTFn<CMData>, CMData> {
let f = Factory::new_fn();
@@ -29,7 +29,7 @@ fn create_tree(cm: &Arc<ConnectionManager>) -> Tree<MTFn<CMData>, CMData> {
});
tree = tree.add(
f.object_path(OBJECT_PATH, cm.clone())
f.object_path(CM_OBJECT_PATH, cm.clone())
.introspectable()
.add(iface),
);
@@ -45,18 +45,18 @@ fn run() -> Result<()> {
// Setup DBus connection
let mut c = LocalConnection::new_session()?;
let result = c.request_name(BUS_NAME, false, false, true)?;
let result = c.request_name(CM_BUS_NAME, false, false, true)?;
match result {
RequestNameReply::Exists => {
return Err(anyhow!(
"Another process is already registered on {}",
BUS_NAME
CM_BUS_NAME
))
}
_ => {} // All other responses we can get are a success
};
println!("Bus registered: {}", BUS_NAME);
println!("Bus registered: {}", CM_BUS_NAME);
tree.start_receive(&c);
loop {

View File

@@ -19,22 +19,43 @@ impl dbus::tree::DataType for CMData {
const PROTO: &'static str = "delta";
pub type ParamSpec = (
String, // Name
u32, // Flags (Conn_Mgr_Param_Flags)
String, // Signature
arg::Variant<Box<dyn arg::RefArg + 'static>>, // Default
);
pub type Dict = HashMap<String, arg::Variant<Box<dyn arg::RefArg + 'static>>>;
// FIXME: these should come from codegen
const FLAG_REQUIRED: u32 = 1;
//const FLAG_REGISTER: u32 = 2;
//const FLAG_HAS_DEFAULT: u32 = 4;
const FLAG_SECRET: u32 = 8;
//const FLAG_DBUS_PROP: u32 = 16;
impl telepathy::ConnectionManager for ConnectionManager {
fn get_parameters(
&self,
protocol: &str,
) -> Result<
Vec<(
String,
u32,
String,
arg::Variant<Box<dyn arg::RefArg + 'static>>,
)>,
tree::MethodErr,
> {
Err(tree::MethodErr::no_arg()) // FIXME: should be NotImplemented
fn get_parameters(&self, protocol: &str) -> Result<Vec<ParamSpec>, tree::MethodErr> {
if protocol != PROTO {
return Err(tree::MethodErr::no_arg()); // FIXME: should be NotImplemented?
}
// TODO: query the protocol for these?
Ok(vec![
(
"account".to_string(),
FLAG_REQUIRED,
"s".to_string(),
arg::Variant(Box::new("".to_string())),
),
(
"password".to_string(),
FLAG_REQUIRED | FLAG_SECRET,
"s".to_string(),
arg::Variant(Box::new("".to_string())),
),
])
}
fn list_protocols(&self) -> Result<Vec<String>, tree::MethodErr> {
@@ -43,22 +64,19 @@ impl telepathy::ConnectionManager for ConnectionManager {
fn request_connection(
&self,
protocol: &str,
parameters: HashMap<&str, arg::Variant<Box<dyn arg::RefArg>>>,
_protocol: &str,
_parameters: HashMap<&str, arg::Variant<Box<dyn arg::RefArg>>>,
) -> Result<(String, dbus::Path<'static>), tree::MethodErr> {
Err(tree::MethodErr::no_arg())
}
fn protocols(&self) -> Result<HashMap<String, Dict>, tree::MethodErr> {
let mut hm = HashMap::new();
let mut props = Dict::new();
hm.insert(PROTO.to_string(), props);
Ok(hm)
// If this map is empty or missing, clients SHOULD fall back to
// calling ListProtocol and GetParameters
Ok(HashMap::new())
}
fn interfaces(&self) -> Result<Vec<String>, tree::MethodErr> {
Err(tree::MethodErr::no_arg())
Ok(vec![])
}
}

View File

@@ -1,2 +1 @@
pub struct Protocol {}