emqx / MQTTX

A Powerful and All-in-One MQTT 5.0 client toolbox for Desktop, CLI and WebSocket.

Home Page:https://mqttx.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug] Display list issue when subscribing to multiple topics at once

WMWYT opened this issue · comments

What I Did

I set up an MQTT server to block subscriptions to a specific topic.

What Happened

I wrote a Mosquitto plugin to prevent all clients from subscribing to the "test" topic. When I ran the plugin and server to allow client connections, if I attempted to subscribe to two or more topics at a time and one of them was the "test" topic, then if "test" was the first in the list, all subsequent topics would not appear in the list. However, the server had stored all topics except "test." The client would still receive messages if they were pushed to other topics. If the "test" topic was not first, then the client would display it with the others without any error messages.

Expected

Topics that are correctly subscribed to should appear in the display list, and a notification should indicate which topic(s) were not successfully subscribed to.

Environment

  • OS: Ubuntu 22.04.4 LTS x86_64
  • MQTTX v1.9.9

More detail

mosquitto plugin resource code

#include "config.h"

#include <stdio.h>
#include <string.h>

#include "mosquitto_broker.h"
#include "mosquitto_plugin.h"
#include "mosquitto.h"
#include "mqtt_protocol.h"

static mosquitto_plugin_id_t *plg_id = NULL;

int auth_callback(int event, void *event_data, void *userdata)
{
	UNUSED(event);
	UNUSED(event_data);
	UNUSED(userdata);
	return MOSQ_ERR_SUCCESS;
}

int subscribe_acl_check_callback(int event, void *event_data, void *userdata)
{
	struct mosquitto_evt_acl_check *ed = event_data;

	UNUSED(event);
	UNUSED(userdata);
	
	if(ed->access == MOSQ_ACL_SUBSCRIBE)
	{
		if(!strcmp(ed->topic, "test"))
			return MOSQ_ERR_ACL_DENIED;
	}

	return MOSQ_ERR_SUCCESS;
}

int mosquitto_plugin_version(int supported_version_count, const int *supported_versions)
{
	int i;

	for(i=0; i<supported_version_count; i++){
		if(supported_versions[i] == 5){
			return 5;
		}
	}
	return -1;
}

int mosquitto_plugin_init(mosquitto_plugin_id_t *identifier, void **user_data, struct mosquitto_opt *opts, int opt_count)
{
	UNUSED(user_data);
	UNUSED(opts);
	UNUSED(opt_count);

	plg_id = identifier;
	mosquitto_callback_register(plg_id, MOSQ_EVT_BASIC_AUTH, auth_callback, NULL, NULL);
	mosquitto_callback_register(plg_id, MOSQ_EVT_ACL_CHECK, subscribe_acl_check_callback, NULL, NULL);
	return MOSQ_ERR_SUCCESS;
}

int mosquitto_plugin_cleanup(void *user_data, struct mosquitto_opt *opts, int opt_count)
{
	UNUSED(user_data);
	UNUSED(opts);
	UNUSED(opt_count);

    if(plg_id)
	{
		mosquitto_callback_unregister(plg_id, MOSQ_EVT_BASIC_AUTH, auth_callback, NULL);
    	mosquitto_callback_unregister(plg_id, MOSQ_EVT_ACL_CHECK, subscribe_acl_check_callback, NULL);
	}
    return MOSQ_ERR_SUCCESS;
}

截图 2024-03-17 21-10-35
截图 2024-03-17 21-11-16
截图 2024-03-17 21-11-25
截图 2024-03-17 21-14-25
截图 2024-03-17 21-16-34
截图 2024-03-17 21-16-40

The issue is confirmed as a bug and will be fixed in the next release. Thanks for the feedback.

Thanks for your feedback. It is now available at: https://github.com/emqx/MQTTX/releases/tag/v1.9.10. Welcome to try it.