pub trait MosquittoPlugin {
// Required method
fn init(opts: MosquittoOpt<'_>) -> Self;
// Provided methods
fn on_reload(&mut self, opts: MosquittoOpt<'_>) { ... }
fn acl_check(
&mut self,
client: &dyn MosquittoClientContext,
acl: AclCheckAccessLevel,
msg: MosquittoMessage<'_>,
) -> Result<Success, Error> { ... }
fn username_password(
&mut self,
client: &dyn MosquittoClientContext,
username: Option<&str>,
password: Option<&str>,
) -> Result<Success, Error> { ... }
fn on_auth_start(
&mut self,
_client: &dyn MosquittoClientContext,
_method: Option<&str>,
_data: Option<&[u8]>,
) -> Result<Success, Error> { ... }
fn on_auth_continue(
&mut self,
_client: &dyn MosquittoClientContext,
_method: Option<&str>,
_data: Option<&[u8]>,
) -> Result<Success, Error> { ... }
fn on_control(
&mut self,
client: &dyn MosquittoClientContext,
message: MosquittoMessage<'_>,
) { ... }
fn on_message(
&mut self,
client: &dyn MosquittoClientContext,
message: MosquittoMessage<'_>,
) { ... }
fn on_psk(
&mut self,
client: &dyn MosquittoClientContext,
hint: &str,
identity: &str,
key: &str,
max_key_len: i32,
) -> i32 { ... }
fn on_tick(&mut self, now_ns: i64, next_ns: i64, now_s: i32, next_s: i32) { ... }
fn on_disconnect(
&mut self,
client: &dyn MosquittoClientContext,
reason: i32,
) { ... }
}Required Methods§
Sourcefn init(opts: MosquittoOpt<'_>) -> Self
fn init(opts: MosquittoOpt<'_>) -> Self
This will be run once on every startup, or load, and will allocate the structure, to be reconstructed in other calls to the plugin.
This requires unsafe usage due to nature of C calls
Provided Methods§
Sourcefn on_reload(&mut self, opts: MosquittoOpt<'_>)
fn on_reload(&mut self, opts: MosquittoOpt<'_>)
Called when SIGHUP is sent to the broker PID
Sourcefn acl_check(
&mut self,
client: &dyn MosquittoClientContext,
acl: AclCheckAccessLevel,
msg: MosquittoMessage<'_>,
) -> Result<Success, Error>
fn acl_check( &mut self, client: &dyn MosquittoClientContext, acl: AclCheckAccessLevel, msg: MosquittoMessage<'_>, ) -> Result<Success, Error>
Access level checks, default implementation always returns success If all acl checks from all plugins returns defer the action should be allowed. However that doesn’t happen right now, if this returns Err(PluginDefer) for a write the message is not let through.
Sourcefn username_password(
&mut self,
client: &dyn MosquittoClientContext,
username: Option<&str>,
password: Option<&str>,
) -> Result<Success, Error>
fn username_password( &mut self, client: &dyn MosquittoClientContext, username: Option<&str>, password: Option<&str>, ) -> Result<Success, Error>
Username and password checks, default implementation always returns success
Sourcefn on_auth_start(
&mut self,
_client: &dyn MosquittoClientContext,
_method: Option<&str>,
_data: Option<&[u8]>,
) -> Result<Success, Error>
fn on_auth_start( &mut self, _client: &dyn MosquittoClientContext, _method: Option<&str>, _data: Option<&[u8]>, ) -> Result<Success, Error>
Authentication start. Default implementation always returns success. Return Err(Error::AuthContinue(_)) to send auth data to the client.
Sourcefn on_auth_continue(
&mut self,
_client: &dyn MosquittoClientContext,
_method: Option<&str>,
_data: Option<&[u8]>,
) -> Result<Success, Error>
fn on_auth_continue( &mut self, _client: &dyn MosquittoClientContext, _method: Option<&str>, _data: Option<&[u8]>, ) -> Result<Success, Error>
Authentication continue. Default implementation always returns success. Return Err(Error::AuthContinue(_))
to send auth data to the client or Ok(Success).
Sourcefn on_control(
&mut self,
client: &dyn MosquittoClientContext,
message: MosquittoMessage<'_>,
)
fn on_control( &mut self, client: &dyn MosquittoClientContext, message: MosquittoMessage<'_>, )
Tested unsuccessfully. Haven’t gotten this to work yet. Suspect it has something to do with how the mosquitto_callback_register is called with the event_data parameter
Sourcefn on_message(
&mut self,
client: &dyn MosquittoClientContext,
message: MosquittoMessage<'_>,
)
fn on_message( &mut self, client: &dyn MosquittoClientContext, message: MosquittoMessage<'_>, )
Called when a message is sent on the broker. The message has to pass the ACL check otherwise this callback will not be called.
Sourcefn on_psk(
&mut self,
client: &dyn MosquittoClientContext,
hint: &str,
identity: &str,
key: &str,
max_key_len: i32,
) -> i32
fn on_psk( &mut self, client: &dyn MosquittoClientContext, hint: &str, identity: &str, key: &str, max_key_len: i32, ) -> i32
Untested
Sourcefn on_tick(&mut self, now_ns: i64, next_ns: i64, now_s: i32, next_s: i32)
fn on_tick(&mut self, now_ns: i64, next_ns: i64, now_s: i32, next_s: i32)
Called every 100 ms All now_ns, next_ns, now_s, next_s parameters are always zero right now. I’m not sure if it’s a bug on this library’s part or of mosquitto. If you want to keep time you’ll have to measure it yourself right now.
fn on_disconnect(&mut self, client: &dyn MosquittoClientContext, reason: i32)
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.