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:

Implementations§

source§

impl<'cb, 'cx> Connection<'cb, 'cx>

source

pub fn new(ctx: Context<'cx, 'cb>) -> Self

source

pub fn flags(&self) -> ConnectionFlags

source

pub fn set_flags(&mut self, flags: ConnectionFlags) -> Result<()>

source

pub fn jid(&self) -> Option<&str>

source

pub fn bound_jid(&self) -> Option<&str>

source

pub fn set_jid(&mut self, jid: impl AsRef<str>)

source

pub fn pass(&self) -> Option<&str>

source

pub fn set_pass(&mut self, pass: impl AsRef<str>)

source

pub fn disable_tls(&mut self)

👎Deprecated
source

pub fn is_secured(&self) -> bool

source

pub fn set_keepalive(&mut self, timeout: Duration, interval: Duration)

👎Deprecated: replaced by set_sockopt_callback()
source

pub fn is_connecting(&self) -> bool

source

pub fn is_connected(&self) -> bool

source

pub fn is_disconnected(&self) -> bool

source

pub fn set_cafile(&mut self, path: impl AsRef<str>)

source

pub fn set_capath(&mut self, path: impl AsRef<str>)

source

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.

source

pub fn peer_cert(&self) -> Option<TlsCert>

source

pub fn set_client_cert(&mut self, cert_path: &str, key_path: &str)

source

pub fn cert_xmppaddr_num(&self) -> u32

source

pub fn cert_xmppaddr(&self, n: u32) -> Option<String>

source

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.

source

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.

source

pub fn set_default_sockopt_callback(&mut self)

xmpp_sockopt_cb_keepalive

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.

source

pub fn set_password_retries(&mut self, n: u32)

source

pub fn get_keyfile(&self) -> Option<&str>

source

pub fn send_queue_len(&self) -> i32

source

pub fn send_queue_drop_element(&mut self, which: QueueElement) -> Option<String>

source

pub fn sm_state(&mut self) -> Option<SMState>

source

pub fn set_sm_state(&mut self, sm_state: SMState) -> Result<()>

source

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,

source

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,

source

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.

source

pub fn open_stream_default(&self) -> Result<()>

source

pub fn open_stream(&self, attributes: &HashMap<&str, &str>) -> Result<()>

source

pub fn tls_start(&self) -> Result<()>

source

pub fn disconnect(&mut self)

source

pub fn send_raw_string(&mut self, data: impl AsRef<str>)

xmpp_send_raw_string

Be aware that this method performs a lot of allocations internally so you might want to use send_raw() instead.

source

pub fn send_raw(&mut self, data: impl AsRef<[u8]>)

source

pub fn send(&mut self, stanza: &Stanza)

source

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,

source

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,

xmpp_timed_handler_delete

See Connection::handler_delete for additional information.

source

pub fn timed_handlers_clear(&mut self)

See Connection::handlers_clear for additional information.

source

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,

source

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,

xmpp_id_handler_delete

See Connection::handler_delete for additional information.

source

pub fn id_handlers_clear(&mut self)

See Connection::handlers_clear for additional information.

source

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,

xmpp_handler_add xmpp_handler

This function returns HandlerId which is later can be used to remove the handler using Connection::handler_delete.

source

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,

xmpp_handler_delete

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.

source

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>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Drop for Connection<'_, '_>

source§

impl PartialEq<Connection<'_, '_>> for Connection<'_, '_>

source§

fn eq(&self, other: &Connection<'_, '_>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for Connection<'_, '_>

source§

impl Send for Connection<'_, '_>

Auto Trait Implementations§

§

impl<'cb, 'cx> !RefUnwindSafe for Connection<'cb, 'cx>

§

impl<'cb, 'cx> !Sync for Connection<'cb, 'cx>

§

impl<'cb, 'cx> Unpin for Connection<'cb, 'cx>

§

impl<'cb, 'cx> !UnwindSafe for Connection<'cb, 'cx>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.