Return protocol parameters
This commit is contained in:
@@ -0,0 +1,4 @@
|
|||||||
|
[D-BUS Service]
|
||||||
|
Name=org.freedesktop.Telepathy.ConnectionManager.padfoot
|
||||||
|
Exec=/usr/lib/telepathy/telepathy-padfoot
|
||||||
|
//SystemdService=telepathy-padfoot.service
|
11
share/managers/padfoot.manager
Normal file
11
share/managers/padfoot.manager
Normal 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
|
14
src/main.rs
14
src/main.rs
@@ -4,7 +4,7 @@ mod telepathy;
|
|||||||
//use dbus::tree::{Interface, MTFn, MethodErr};
|
//use dbus::tree::{Interface, MTFn, MethodErr};
|
||||||
use dbus::{
|
use dbus::{
|
||||||
blocking::{stdintf::org_freedesktop_dbus::RequestNameReply, LocalConnection},
|
blocking::{stdintf::org_freedesktop_dbus::RequestNameReply, LocalConnection},
|
||||||
tree::{Factory, Interface, MTFn, Tree},
|
tree::{Factory, MTFn, Tree},
|
||||||
};
|
};
|
||||||
|
|
||||||
use padfoot::{CMData, ConnectionManager};
|
use padfoot::{CMData, ConnectionManager};
|
||||||
@@ -14,8 +14,8 @@ use std::time::Duration;
|
|||||||
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
|
|
||||||
const BUS_NAME: &'static str = "org.freedesktop.Telepathy.ConnectionManager.padfoot";
|
const CM_BUS_NAME: &'static str = "org.freedesktop.Telepathy.ConnectionManager.padfoot";
|
||||||
const OBJECT_PATH: &'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> {
|
fn create_tree(cm: &Arc<ConnectionManager>) -> Tree<MTFn<CMData>, CMData> {
|
||||||
let f = Factory::new_fn();
|
let f = Factory::new_fn();
|
||||||
@@ -29,7 +29,7 @@ fn create_tree(cm: &Arc<ConnectionManager>) -> Tree<MTFn<CMData>, CMData> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
tree = tree.add(
|
tree = tree.add(
|
||||||
f.object_path(OBJECT_PATH, cm.clone())
|
f.object_path(CM_OBJECT_PATH, cm.clone())
|
||||||
.introspectable()
|
.introspectable()
|
||||||
.add(iface),
|
.add(iface),
|
||||||
);
|
);
|
||||||
@@ -45,18 +45,18 @@ fn run() -> Result<()> {
|
|||||||
// Setup DBus connection
|
// Setup DBus connection
|
||||||
let mut c = LocalConnection::new_session()?;
|
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 {
|
match result {
|
||||||
RequestNameReply::Exists => {
|
RequestNameReply::Exists => {
|
||||||
return Err(anyhow!(
|
return Err(anyhow!(
|
||||||
"Another process is already registered on {}",
|
"Another process is already registered on {}",
|
||||||
BUS_NAME
|
CM_BUS_NAME
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
_ => {} // All other responses we can get are a success
|
_ => {} // All other responses we can get are a success
|
||||||
};
|
};
|
||||||
|
|
||||||
println!("Bus registered: {}", BUS_NAME);
|
println!("Bus registered: {}", CM_BUS_NAME);
|
||||||
tree.start_receive(&c);
|
tree.start_receive(&c);
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
@@ -19,22 +19,43 @@ impl dbus::tree::DataType for CMData {
|
|||||||
|
|
||||||
const PROTO: &'static str = "delta";
|
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>>>;
|
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 {
|
impl telepathy::ConnectionManager for ConnectionManager {
|
||||||
fn get_parameters(
|
fn get_parameters(&self, protocol: &str) -> Result<Vec<ParamSpec>, tree::MethodErr> {
|
||||||
&self,
|
if protocol != PROTO {
|
||||||
protocol: &str,
|
return Err(tree::MethodErr::no_arg()); // FIXME: should be NotImplemented?
|
||||||
) -> Result<
|
}
|
||||||
Vec<(
|
|
||||||
String,
|
// TODO: query the protocol for these?
|
||||||
u32,
|
Ok(vec![
|
||||||
String,
|
(
|
||||||
arg::Variant<Box<dyn arg::RefArg + 'static>>,
|
"account".to_string(),
|
||||||
)>,
|
FLAG_REQUIRED,
|
||||||
tree::MethodErr,
|
"s".to_string(),
|
||||||
> {
|
arg::Variant(Box::new("".to_string())),
|
||||||
Err(tree::MethodErr::no_arg()) // FIXME: should be NotImplemented
|
),
|
||||||
|
(
|
||||||
|
"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> {
|
fn list_protocols(&self) -> Result<Vec<String>, tree::MethodErr> {
|
||||||
@@ -43,22 +64,19 @@ impl telepathy::ConnectionManager for ConnectionManager {
|
|||||||
|
|
||||||
fn request_connection(
|
fn request_connection(
|
||||||
&self,
|
&self,
|
||||||
protocol: &str,
|
_protocol: &str,
|
||||||
parameters: HashMap<&str, arg::Variant<Box<dyn arg::RefArg>>>,
|
_parameters: HashMap<&str, arg::Variant<Box<dyn arg::RefArg>>>,
|
||||||
) -> Result<(String, dbus::Path<'static>), tree::MethodErr> {
|
) -> Result<(String, dbus::Path<'static>), tree::MethodErr> {
|
||||||
Err(tree::MethodErr::no_arg())
|
Err(tree::MethodErr::no_arg())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn protocols(&self) -> Result<HashMap<String, Dict>, tree::MethodErr> {
|
fn protocols(&self) -> Result<HashMap<String, Dict>, tree::MethodErr> {
|
||||||
let mut hm = HashMap::new();
|
// If this map is empty or missing, clients SHOULD fall back to
|
||||||
let mut props = Dict::new();
|
// calling ListProtocol and GetParameters
|
||||||
|
Ok(HashMap::new())
|
||||||
hm.insert(PROTO.to_string(), props);
|
|
||||||
|
|
||||||
Ok(hm)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn interfaces(&self) -> Result<Vec<String>, tree::MethodErr> {
|
fn interfaces(&self) -> Result<Vec<String>, tree::MethodErr> {
|
||||||
Err(tree::MethodErr::no_arg())
|
Ok(vec![])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,2 +1 @@
|
|||||||
pub struct Protocol {}
|
pub struct Protocol {}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user