forked from eclipse/mosquitto
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support plugin tick callbacks with per_listener_settings enabled
add tests for the plugin tick Signed-off-by: Xavier Dooms <[email protected]>
- Loading branch information
1 parent
3cbe805
commit bff71fd
Showing
5 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Test whether a plugin can subscribe to the tick event | ||
|
||
from mosq_test_helper import * | ||
|
||
def write_config(filename, port, per_listener_settings="false"): | ||
with open(filename, 'w') as f: | ||
f.write("per_listener_settings %s\n" % (per_listener_settings)) | ||
f.write("listener %d\n" % (port)) | ||
f.write("plugin c/auth_plugin_v5_handle_tick.so\n") | ||
f.write("allow_anonymous true\n") | ||
|
||
def do_test(per_listener_settings): | ||
proto_ver = 5 | ||
port = mosq_test.get_port() | ||
conf_file = os.path.basename(__file__).replace('.py', '.conf') | ||
write_config(conf_file, port, per_listener_settings) | ||
|
||
rc = 1 | ||
keepalive = 10 | ||
connect_packet = mosq_test.gen_connect("plugin-tick-test", keepalive=keepalive, username="readwrite", clean_session=False, proto_ver=proto_ver) | ||
connack_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver) | ||
|
||
tick_packet = mosq_test.gen_publish("topic/tick", qos=0, payload="test-message", proto_ver=proto_ver) | ||
|
||
broker = mosq_test.start_broker(filename=os.path.basename(__file__), use_conf=True, port=port) | ||
|
||
try: | ||
sock = mosq_test.do_client_connect(connect_packet, connack_packet, timeout=10, port=port) | ||
|
||
mosq_test.expect_packet(sock, "tick message", tick_packet) | ||
mosq_test.expect_packet(sock, "tick message", tick_packet) | ||
mosq_test.expect_packet(sock, "tick message", tick_packet) | ||
|
||
mosq_test.do_ping(sock) | ||
|
||
rc = 0 | ||
sock.close() | ||
except mosq_test.TestError: | ||
pass | ||
finally: | ||
os.remove(conf_file) | ||
broker.terminate() | ||
broker.wait() | ||
(stdo, stde) = broker.communicate() | ||
if rc: | ||
print(stde.decode('utf-8')) | ||
exit(rc) | ||
|
||
do_test("false") | ||
do_test("true") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <mosquitto.h> | ||
#include <mosquitto_broker.h> | ||
#include <mosquitto_plugin.h> | ||
|
||
static int handle_tick(int event, void *event_data, void *user_data); | ||
|
||
static mosquitto_plugin_id_t *plg_id; | ||
|
||
|
||
int mosquitto_plugin_version(int supported_version_count, const int *supported_versions) | ||
{ | ||
return 5; | ||
} | ||
|
||
int mosquitto_plugin_init(mosquitto_plugin_id_t *identifier, void **user_data, struct mosquitto_opt *auth_opts, int auth_opt_count) | ||
{ | ||
plg_id = identifier; | ||
|
||
mosquitto_callback_register(plg_id, MOSQ_EVT_TICK, handle_tick, NULL, NULL); | ||
|
||
return MOSQ_ERR_SUCCESS; | ||
} | ||
|
||
int mosquitto_plugin_cleanup(void *user_data, struct mosquitto_opt *auth_opts, int auth_opt_count) | ||
{ | ||
mosquitto_callback_unregister(plg_id, MOSQ_EVT_TICK, handle_tick, NULL); | ||
|
||
return MOSQ_ERR_SUCCESS; | ||
} | ||
|
||
int handle_tick(int event, void *event_data, void *user_data) | ||
{ | ||
mosquitto_broker_publish_copy("plugin-tick-test", "topic/tick", strlen("test-message"), "test-message", 0, false, NULL); | ||
return MOSQ_ERR_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters