Struct libstrophe::Connection
source · pub struct Connection<'cb, 'cx> { /* private fields */ }
Expand description
Proxy to the underlying xmpp_conn_t
struct.
Most of the methods in this struct mimic the methods of the underlying library. So please see libstrophe docs for connection and handlers plus conn.c and handler.c sources. Only where it’s not the case or there is some additional logic involved then you can see the method description.
This struct implements:
Drop
(xmpp_conn_release).Eq
by comparing internal pointersSend
Implementations§
source§impl<'cb, 'cx> Connection<'cb, 'cx>
impl<'cb, 'cx> Connection<'cb, 'cx>
sourcepub fn flags(&self) -> ConnectionFlags
pub fn flags(&self) -> ConnectionFlags
sourcepub fn set_flags(&mut self, flags: ConnectionFlags) -> Result<()>
pub fn set_flags(&mut self, flags: ConnectionFlags) -> Result<()>
sourcepub fn disable_tls(&mut self)
👎Deprecated
pub fn disable_tls(&mut self)
sourcepub fn is_secured(&self) -> bool
pub fn is_secured(&self) -> bool
sourcepub fn set_keepalive(&mut self, timeout: Duration, interval: Duration)
👎Deprecated: replaced by set_sockopt_callback()
pub fn set_keepalive(&mut self, timeout: Duration, interval: Duration)
sourcepub fn is_connecting(&self) -> bool
pub fn is_connecting(&self) -> bool
sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
sourcepub fn is_disconnected(&self) -> bool
pub fn is_disconnected(&self) -> bool
sourcepub fn set_cafile(&mut self, path: impl AsRef<str>)
pub fn set_cafile(&mut self, path: impl AsRef<str>)
sourcepub fn set_capath(&mut self, path: impl AsRef<str>)
pub fn set_capath(&mut self, path: impl AsRef<str>)
sourcepub fn set_certfail_handler<CB>(&mut self, handler: CB)where
CB: Fn(&TlsCert, &str) -> CertFailResult + Send + Sync + 'static,
pub fn set_certfail_handler<CB>(&mut self, handler: CB)where CB: Fn(&TlsCert, &str) -> CertFailResult + Send + Sync + 'static,
xmpp_conn_set_certfail_handler xmpp_certfail_handler
Callback function receives TlsCert object object and an error message.
sourcepub fn set_client_cert(&mut self, cert_path: &str, key_path: &str)
pub fn set_client_cert(&mut self, cert_path: &str, key_path: &str)
sourcepub fn cert_xmppaddr_num(&self) -> u32
pub fn cert_xmppaddr_num(&self) -> u32
sourcepub fn cert_xmppaddr(&self, n: u32) -> Option<String>
pub fn cert_xmppaddr(&self, n: u32) -> Option<String>
sourcepub fn set_password_callback<CB>(&mut self, handler: Option<CB>)where
CB: Fn(&Connection<'cb, 'cx>, usize) -> Option<String> + Send + 'cb,
pub fn set_password_callback<CB>(&mut self, handler: Option<CB>)where CB: Fn(&Connection<'cb, 'cx>, usize) -> Option<String> + Send + 'cb,
xmpp_conn_set_password_callback xmpp_password_callback
Callback function receives Connection object and maximum allowed length of the password, it returns Some(String)
with password
on success or None in case of error. If the returned String
is longer than maximum allowed length it is ignored and the error
is returned.
sourcepub fn set_sockopt_callback<CB>(&mut self, handler: CB)where
CB: Fn(*mut c_void) -> SockoptResult + Send + Sync + 'static,
pub fn set_sockopt_callback<CB>(&mut self, handler: CB)where CB: Fn(*mut c_void) -> SockoptResult + Send + Sync + 'static,
xmpp_conn_set_sockopt_callback xmpp_sockopt_callback
Callback function receives pointer to a system-dependent socket object. See docs above for more details.
sourcepub fn set_default_sockopt_callback(&mut self)
pub fn set_default_sockopt_callback(&mut self)
Sets default sockopt_callback function that just uses compile-time internal defaults for the socket timeout. Those values can be changed with a deprecated Connection::set_keepalive. If you use that function then you don’t need to call Connection::set_default_sockopt_callback manually because it will be called internally.
sourcepub fn set_password_retries(&mut self, n: u32)
pub fn set_password_retries(&mut self, n: u32)
sourcepub fn get_keyfile(&self) -> Option<&str>
pub fn get_keyfile(&self) -> Option<&str>
sourcepub fn send_queue_len(&self) -> i32
pub fn send_queue_len(&self) -> i32
sourcepub fn send_queue_drop_element(&mut self, which: QueueElement) -> Option<String>
pub fn send_queue_drop_element(&mut self, which: QueueElement) -> Option<String>
sourcepub fn set_sm_state(&mut self, sm_state: SMState) -> Result<()>
pub fn set_sm_state(&mut self, sm_state: SMState) -> Result<()>
sourcepub fn connect_client<CB>(
self,
alt_host: Option<&str>,
alt_port: impl Into<Option<u16>>,
handler: CB
) -> Result<Context<'cx, 'cb>, ConnectClientError<'cb, 'cx>>where
CB: FnMut(&Context<'cx, 'cb>, &mut Connection<'cb, 'cx>, ConnectionEvent<'_, '_>) + Send + 'cb,
pub fn connect_client<CB>( self, alt_host: Option<&str>, alt_port: impl Into<Option<u16>>, handler: CB ) -> Result<Context<'cx, 'cb>, ConnectClientError<'cb, 'cx>>where CB: FnMut(&Context<'cx, 'cb>, &mut Connection<'cb, 'cx>, ConnectionEvent<'_, '_>) + Send + 'cb,
sourcepub fn connect_component<CB>(
self,
host: impl AsRef<str>,
port: impl Into<Option<u16>>,
handler: CB
) -> Result<Context<'cx, 'cb>, ConnectClientError<'cb, 'cx>>where
CB: FnMut(&Context<'cx, 'cb>, &mut Connection<'cb, 'cx>, ConnectionEvent<'_, '_>) + Send + 'cb,
pub fn connect_component<CB>( self, host: impl AsRef<str>, port: impl Into<Option<u16>>, handler: CB ) -> Result<Context<'cx, 'cb>, ConnectClientError<'cb, 'cx>>where CB: FnMut(&Context<'cx, 'cb>, &mut Connection<'cb, 'cx>, ConnectionEvent<'_, '_>) + Send + 'cb,
xmpp_connect_component xmpp_conn_handler
See also connect_client()
for additional info.
sourcepub fn connect_raw<CB>(
self,
alt_host: Option<&str>,
alt_port: impl Into<Option<u16>>,
handler: CB
) -> Result<Context<'cx, 'cb>, ConnectClientError<'cb, 'cx>>where
CB: FnMut(&Context<'cx, 'cb>, &mut Connection<'cb, 'cx>, ConnectionEvent<'_, '_>) + Send + 'cb,
pub fn connect_raw<CB>( self, alt_host: Option<&str>, alt_port: impl Into<Option<u16>>, handler: CB ) -> Result<Context<'cx, 'cb>, ConnectClientError<'cb, 'cx>>where CB: FnMut(&Context<'cx, 'cb>, &mut Connection<'cb, 'cx>, ConnectionEvent<'_, '_>) + Send + 'cb,
xmpp_connect_raw xmpp_conn_handler
See also connect_client()
for additional info.
sourcepub fn open_stream_default(&self) -> Result<()>
pub fn open_stream_default(&self) -> Result<()>
Related to connect_raw()
.
sourcepub fn open_stream(&self, attributes: &HashMap<&str, &str>) -> Result<()>
pub fn open_stream(&self, attributes: &HashMap<&str, &str>) -> Result<()>
Related to connect_raw()
.
sourcepub fn tls_start(&self) -> Result<()>
pub fn tls_start(&self) -> Result<()>
Related to connect_raw()
.
sourcepub fn disconnect(&mut self)
pub fn disconnect(&mut self)
sourcepub fn send_raw_string(&mut self, data: impl AsRef<str>)
pub fn send_raw_string(&mut self, data: impl AsRef<str>)
Be aware that this method performs a lot of allocations internally so you might want to use
send_raw()
instead.
sourcepub fn timed_handler_add<CB>(
&mut self,
handler: CB,
period: Duration
) -> Option<TimedHandlerId<'cb, 'cx, CB>>where
CB: FnMut(&Context<'cx, 'cb>, &mut Connection<'cb, 'cx>) -> HandlerResult + Send + 'cb,
pub fn timed_handler_add<CB>( &mut self, handler: CB, period: Duration ) -> Option<TimedHandlerId<'cb, 'cx, CB>>where CB: FnMut(&Context<'cx, 'cb>, &mut Connection<'cb, 'cx>) -> HandlerResult + Send + 'cb,
xmpp_timed_handler_add xmpp_timed_handler
See Connection::handler_add for additional information.
sourcepub fn timed_handler_delete<CB>(
&mut self,
handler_id: TimedHandlerId<'_, '_, CB>
)where
CB: FnMut(&Context<'cx, 'cb>, &mut Connection<'cb, 'cx>) -> HandlerResult + Send + 'cb,
pub fn timed_handler_delete<CB>( &mut self, handler_id: TimedHandlerId<'_, '_, CB> )where CB: FnMut(&Context<'cx, 'cb>, &mut Connection<'cb, 'cx>) -> HandlerResult + Send + 'cb,
See Connection::handler_delete for additional information.
sourcepub fn timed_handlers_clear(&mut self)
pub fn timed_handlers_clear(&mut self)
See Connection::handlers_clear for additional information.
sourcepub fn id_handler_add<CB>(
&mut self,
handler: CB,
id: impl Into<String>
) -> Option<IdHandlerId<'cb, 'cx, CB>>where
CB: FnMut(&Context<'cx, 'cb>, &mut Connection<'cb, 'cx>, &Stanza) -> HandlerResult + Send + 'cb,
pub fn id_handler_add<CB>( &mut self, handler: CB, id: impl Into<String> ) -> Option<IdHandlerId<'cb, 'cx, CB>>where CB: FnMut(&Context<'cx, 'cb>, &mut Connection<'cb, 'cx>, &Stanza) -> HandlerResult + Send + 'cb,
xmpp_id_handler_add xmpp_handler
See Connection::handler_add for additional information.
sourcepub fn id_handler_delete<CB>(&mut self, handler_id: IdHandlerId<'_, '_, CB>)where
CB: FnMut(&Context<'cx, 'cb>, &mut Connection<'cb, 'cx>, &Stanza) -> HandlerResult + Send + 'cb,
pub fn id_handler_delete<CB>(&mut self, handler_id: IdHandlerId<'_, '_, CB>)where CB: FnMut(&Context<'cx, 'cb>, &mut Connection<'cb, 'cx>, &Stanza) -> HandlerResult + Send + 'cb,
See Connection::handler_delete for additional information.
sourcepub fn id_handlers_clear(&mut self)
pub fn id_handlers_clear(&mut self)
See Connection::handlers_clear for additional information.
sourcepub fn handler_add<CB>(
&mut self,
handler: CB,
ns: Option<&str>,
name: Option<&str>,
typ: Option<&str>
) -> Option<HandlerId<'cb, 'cx, CB>>where
CB: FnMut(&Context<'cx, 'cb>, &mut Connection<'cb, 'cx>, &Stanza) -> HandlerResult + Send + 'cb,
pub fn handler_add<CB>( &mut self, handler: CB, ns: Option<&str>, name: Option<&str>, typ: Option<&str> ) -> Option<HandlerId<'cb, 'cx, CB>>where CB: FnMut(&Context<'cx, 'cb>, &mut Connection<'cb, 'cx>, &Stanza) -> HandlerResult + Send + 'cb,
This function returns HandlerId which is later can be used to remove the handler using Connection::handler_delete.
sourcepub fn handler_delete<CB>(&mut self, handler_id: HandlerId<'_, '_, CB>)where
CB: FnMut(&Context<'cx, 'cb>, &mut Connection<'cb, 'cx>, &Stanza) -> HandlerResult + Send + 'cb,
pub fn handler_delete<CB>(&mut self, handler_id: HandlerId<'_, '_, CB>)where CB: FnMut(&Context<'cx, 'cb>, &mut Connection<'cb, 'cx>, &Stanza) -> HandlerResult + Send + 'cb,
This version of this function accepts HandlerId
returned from add_handler()
function instead of function reference as the underlying
library does. If you can’t keep track of those handles, but still want ability to remove handlers, check handlers_clear()
function.
sourcepub fn handlers_clear(&mut self)
pub fn handlers_clear(&mut self)
Removes all handlers that were set up with handler_add()
. This function does not remove handlers added via id_handler_add()
. You can use
this function if you can’t keep track of specific closure handles returned from handler_add()
, but want to remove handlers anyway.
Trait Implementations§
source§impl<'cb, 'cx> Debug for Connection<'cb, 'cx>
impl<'cb, 'cx> Debug for Connection<'cb, 'cx>
source§impl PartialEq<Connection<'_, '_>> for Connection<'_, '_>
impl PartialEq<Connection<'_, '_>> for Connection<'_, '_>
source§fn eq(&self, other: &Connection<'_, '_>) -> bool
fn eq(&self, other: &Connection<'_, '_>) -> bool
self
and other
values to be equal, and is used
by ==
.