pub struct Connection<'cb, 'cx> { /* private fields */ }
Expand description
Proxy to the underlying sys::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: replaced by set_flags()
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)
pub fn set_certfail_handler<CB>(&mut self, handler: CB)
xmpp_conn_set_certfail_handler xmpp_certfail_handler
Callback function receives TlsCert 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: CB)
pub fn set_password_callback<CB>(&mut self, handler: 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 clear_password_callback(&mut self) -> usize
pub fn clear_password_callback(&mut self) -> usize
Remove the callback set by Self::set_password_callback()
Returns the amount of the removed handlers.
Sourcepub fn set_sockopt_callback<CB>(&mut self, handler: CB)
pub fn set_sockopt_callback<CB>(&mut self, handler: CB)
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 sm_state(&mut self) -> Option<SMState<'_, '_>>
pub fn sm_state(&mut self) -> Option<SMState<'_, '_>>
Because in the underlying library the output SMState object retains the reference to the Connection we need to prevent modifications to the Connection while a particular instance of SMState is alive.
Sourcepub fn set_sm_callback<CB>(&mut self, handler: CB)
pub fn set_sm_callback<CB>(&mut self, handler: CB)
Sourcepub fn clear_sm_callback(&mut self) -> usize
pub fn clear_sm_callback(&mut self) -> usize
Remove the callback set by Self::set_sm_callback()
Returns the amount of the removed handlers.
Sourcepub fn restore_sm_state(&mut self, sm_state: SerializedSmState) -> Result<()>
pub fn restore_sm_state(&mut self, sm_state: SerializedSmState) -> 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 Self::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 Self::connect_client() for additional info.
Sourcepub fn open_stream_default(&self) -> Result<()>
pub fn open_stream_default(&self) -> Result<()>
Related to Self::connect_raw().
Sourcepub fn open_stream(&self, attributes: &HashMap<&str, &str>) -> Result<()>
pub fn open_stream(&self, attributes: &HashMap<&str, &str>) -> Result<()>
Related to Self::connect_raw().
Sourcepub fn tls_start(&self) -> Result<()>
pub fn tls_start(&self) -> Result<()>
Related to Self::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 Self::send_raw() instead.
Sourcepub fn timed_handler_add<CB>(
&mut self,
handler: CB,
period: Duration,
) -> Option<TimedHandlerId>
pub fn timed_handler_add<CB>( &mut self, handler: CB, period: Duration, ) -> Option<TimedHandlerId>
xmpp_timed_handler_add xmpp_timed_handler
See Self::handler_add for additional information.
Sourcepub fn timed_handler_delete(&mut self, handler_id: TimedHandlerId) -> usize
pub fn timed_handler_delete(&mut self, handler_id: TimedHandlerId) -> usize
See Self::handler_delete() for additional information.
Sourcepub fn timed_handlers_clear(&mut self) -> usize
pub fn timed_handlers_clear(&mut self) -> usize
See Self::handlers_clear() for additional information.
Sourcepub fn id_handler_add<CB>(
&mut self,
handler: CB,
id: impl Into<String>,
) -> Option<IdHandlerId>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>where
CB: FnMut(&Context<'cx, 'cb>, &mut Connection<'cb, 'cx>, &Stanza) -> HandlerResult + Send + 'cb,
xmpp_id_handler_add xmpp_handler
See Self::handler_add() for additional information.
Sourcepub fn id_handler_delete(&mut self, handler_id: IdHandlerId) -> usize
pub fn id_handler_delete(&mut self, handler_id: IdHandlerId) -> usize
See Self::handler_delete() for additional information.
Sourcepub fn id_handlers_clear(&mut self) -> usize
pub fn id_handlers_clear(&mut self) -> usize
See Self::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>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>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 Self::handler_delete().
Sourcepub fn handler_delete(&mut self, handler_id: HandlerId) -> usize
pub fn handler_delete(&mut self, handler_id: HandlerId) -> usize
This version of this function accepts HandlerId returned from [Self::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 Self::handlers_clear() function. Returns the amount of the removed handlers.
Sourcepub fn handlers_clear(&mut self) -> usize
pub fn handlers_clear(&mut self) -> usize
Removes all handlers that were set up with Self::handler_add().
This function does not remove handlers added via Self::id_handler_add(). You can use this function if you can’t keep track of specific closure handles returned from Self::handler_add(), but want to remove handlers anyway. Returns the amount of the removed handlers.