From 559e2438cb100a4530e729adef18c671757cf793 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Wed, 18 Nov 2015 12:27:23 +0000 Subject: [PATCH] Revert "Add support for sending direct messages to clients." This reverts commit 8f54cde293db10a4bf8e3cbe1284817f30e719e9. --- ChangeLog.txt | 2 - man/mosquitto.conf.5.xml | 37 ----------------- mosquitto.conf | 14 ------- src/conf.c | 23 ----------- src/mosquitto_broker.h | 2 - src/read_handle_server.c | 12 +----- src/subs.c | 88 ++++++++++++++-------------------------- 7 files changed, 32 insertions(+), 146 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index d75c7b69..2ca432d3 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -25,8 +25,6 @@ Broker: - Minimum supported libwebsockets version is now 1.3. - Support for Windows XP has been dropped. - Miscellaneous fixes on Windows. -- Add support for sending direct messages to clients through - $CLIENT/direct/, using the allow_direct_messages option. Client library: - Outgoing messages with QoS>1 are no longer retried after a timeout period. diff --git a/man/mosquitto.conf.5.xml b/man/mosquitto.conf.5.xml index 38033e07..d3a8d54b 100644 --- a/man/mosquitto.conf.5.xml +++ b/man/mosquitto.conf.5.xml @@ -163,23 +163,6 @@ Reloaded on reload signal. - - [ true | false ] - - If this option is enabled, messages published to - $CLIENTS/direct/<client - id> will be delivered to the - client with <client - id> directly. It is not possible - to subscribe to any topics under $CLIENTS manually. - This is a non-spec option and should be used with care. - Clients that are not expecting these messages may not - be able to cope with them. See also - . Defaults to - false. - Reloaded on reload signal. - - [ true | false ] @@ -281,26 +264,6 @@ Reloaded on reload signal. - - [ 0 | 1 | 2 | msg ] - - As clients do not subscribe to direct messages - manually, they have no opportunity to set the QoS. This - option allows a global QoS to be set for direct - messages. Choose either 0, - 1, - 2, or - msg - where - msg indicates that the QoS - of the incoming message should be used. Note that - also affects this - setting. The option - must be - true for this option to have - any effect. - Reloaded on reload signal. - - dir diff --git a/mosquitto.conf b/mosquitto.conf index 3f46ebfc..7eed801c 100644 --- a/mosquitto.conf +++ b/mosquitto.conf @@ -118,20 +118,6 @@ # This is a non-standard option explicitly disallowed by the spec. #upgrade_outgoing_qos false -# If this option is enabled, messages published to $CLIENTS/direct/ -# will be delivered to the client with directly. It is not possible -# to subscribe to any topics under $CLIENTS manually. This is a non-spec option -# and should be used with care. Clients that are not expecting these messages -# may not be able to cope with them. See also direct_message_qos. -#allow_direct_messages false - -# As clients do not subscribe to direct messages manually, they have no -# opportunity to set the QoS. This option allows a global QoS to be set for -# direct messages. Choose either 0, 1, 2, or msg - where msg indicates that the -# QoS of the incoming message should be used. Note that upgrade_outgoing_qos -# also affects this setting. -#direct_message_qos 0 - # ================================================================= # Default listener # ================================================================= diff --git a/src/conf.c b/src/conf.c index 36e1deb5..efc10444 100644 --- a/src/conf.c +++ b/src/conf.c @@ -111,7 +111,6 @@ static void config__init_reload(struct mosquitto__config *config) mosquitto__free(config->acl_file); config->acl_file = NULL; config->allow_anonymous = true; - config->allow_direct_messages = false; config->allow_duplicate_messages = false; config->allow_zero_length_clientid = true; config->auto_id_prefix = NULL; @@ -121,7 +120,6 @@ static void config__init_reload(struct mosquitto__config *config) mosquitto__free(config->clientid_prefixes); config->connection_messages = true; config->clientid_prefixes = NULL; - config->direct_message_qos = 0; if(config->log_fptr){ fclose(config->log_fptr); config->log_fptr = NULL; @@ -649,8 +647,6 @@ int config__read_file_core(struct mosquitto__config *config, bool reload, const #endif }else if(!strcmp(token, "allow_anonymous")){ if(conf__parse_bool(&token, "allow_anonymous", &config->allow_anonymous, saveptr)) return MOSQ_ERR_INVAL; - }else if(!strcmp(token, "allow_direct_messages")){ - if(conf__parse_bool(&token, "allow_direct_messages", &config->allow_direct_messages, saveptr)) return MOSQ_ERR_INVAL; }else if(!strcmp(token, "allow_duplicate_messages")){ if(conf__parse_bool(&token, "allow_duplicate_messages", &config->allow_duplicate_messages, saveptr)) return MOSQ_ERR_INVAL; }else if(!strcmp(token, "allow_zero_length_clientid")){ @@ -1102,25 +1098,6 @@ int config__read_file_core(struct mosquitto__config *config, bool reload, const #else log__printf(NULL, MOSQ_LOG_WARNING, "Warning: TLS support not available."); #endif - }else if(!strcmp(token, "direct_message_qos")){ - token = strtok_r(NULL, " ", &saveptr); - if(token){ - if(!strcmp(token, "0")){ - direct_message_qos = 0; - }else if(!strcmp(token, "1")){ - direct_message_qos = 1; - }else if(!strcmp(token, "2")){ - direct_message_qos = 2; - }else if(!strcmp(token, "msg")){ - direct_messag_qos = -1; - }else{ - log__printf(NULL, MOSQ_LOG_ERR, "Error: Invalid direct_message_qos value (%s).", token); - return MOSQ_ERR_INVAL; - } - }else{ - log__printf(NULL, MOSQ_LOG_ERR, "Error: Empty direct_message_qos value in configuration."); - return MOSQ_ERR_INVAL; - } }else if(!strcmp(token, "http_dir")){ #ifdef WITH_WEBSOCKETS if(reload) continue; // Listeners not valid for reloading. diff --git a/src/mosquitto_broker.h b/src/mosquitto_broker.h index d7d3deca..2431bca4 100644 --- a/src/mosquitto_broker.h +++ b/src/mosquitto_broker.h @@ -165,7 +165,6 @@ struct mosquitto__config { char *config_file; char *acl_file; bool allow_anonymous; - bool allow_direct_messages; bool allow_duplicate_messages; bool allow_zero_length_clientid; char *auto_id_prefix; @@ -175,7 +174,6 @@ struct mosquitto__config { char *clientid_prefixes; bool connection_messages; bool daemon; - int direct_message_qos; struct mosquitto__listener default_listener; struct mosquitto__listener *listeners; int listener_count; diff --git a/src/read_handle_server.c b/src/read_handle_server.c index 99ec7b2a..7da5f24d 100644 --- a/src/read_handle_server.c +++ b/src/read_handle_server.c @@ -678,18 +678,8 @@ int handle__subscribe(struct mosquitto_db *db, struct mosquitto *context) sub = sub_mount; } - - if(!strncmp(sub, "$CLIENT/", 7)){ - /* Access denied, never allow subs here. */ - if(context->protocol == mosq_p_mqtt311){ - qos = 0x80; - }else{ - mosquitto__free(sub); - return MOSQ_ERR_PROTOCOL; - } - } - log__printf(NULL, MOSQ_LOG_DEBUG, "\t%s (QoS %d)", sub, qos); + #if 0 /* FIXME * This section has been disabled temporarily. mosquitto_acl_check diff --git a/src/subs.c b/src/subs.c index df91bfcd..9c77094e 100644 --- a/src/subs.c +++ b/src/subs.c @@ -61,40 +61,14 @@ struct sub__token { uint16_t topic_len; }; -static int subs__send_msg(struct mosquitto_db *db, struct mosquitto *context, int sub_qos, int retain, int msg_qos, struct mosquitto_msg_store *stored) -{ - int final_qos; - bool final_retain; - uint16_t mid; - - if(db->config->upgrade_outgoing_qos){ - final_qos = sub_qos; - }else{ - final_qos = (msg_qos > sub_qos)?sub_qos:msg_qos; - } - if(final_qos > 0){ - mid = mosquitto__mid_generate(context); - }else{ - mid = 0; - } - if(context->is_bridge){ - /* If we know the client is a bridge then we should set retain - * even if the message is fresh. If we don't do this, retained - * messages won't be propagated. */ - final_retain = retain; - }else{ - /* Client is not a bridge and this isn't a stale message so - * retain should be false. */ - final_retain = false; - } - return db__message_insert(db, context, mid, mosq_md_out, final_qos, final_retain, stored); -} - static int subs__process(struct mosquitto_db *db, struct mosquitto__subhier *hier, const char *source_id, const char *topic, int qos, int retain, struct mosquitto_msg_store *stored, bool set_retain) { int rc = 0; int rc2; + int client_qos, msg_qos; + uint16_t mid; struct mosquitto__subleaf *leaf; + bool client_retain; leaf = hier->subs; @@ -133,7 +107,33 @@ static int subs__process(struct mosquitto_db *db, struct mosquitto__subhier *hie leaf = leaf->next; continue; }else if(rc2 == MOSQ_ERR_SUCCESS){ - if(subs__send_msg(db, leaf->context, leaf->qos, retain, qos, stored) != 0) return 1; + client_qos = leaf->qos; + + if(db->config->upgrade_outgoing_qos){ + msg_qos = client_qos; + }else{ + if(qos > client_qos){ + msg_qos = client_qos; + }else{ + msg_qos = qos; + } + } + if(msg_qos){ + mid = mosquitto__mid_generate(leaf->context); + }else{ + mid = 0; + } + if(leaf->context->is_bridge){ + /* If we know the client is a bridge then we should set retain + * even if the message is fresh. If we don't do this, retained + * messages won't be propagated. */ + client_retain = retain; + }else{ + /* Client is not a bridge and this isn't a stale message so + * retain should be false. */ + client_retain = false; + } + if(db__message_insert(db, leaf->context, mid, mosq_md_out, msg_qos, client_retain, stored) == 1) rc = 1; }else{ return 1; /* Application error */ } @@ -510,14 +510,11 @@ int sub__remove(struct mosquitto_db *db, struct mosquitto *context, const char * return rc; } - int sub__messages_queue(struct mosquitto_db *db, const char *source_id, const char *topic, int qos, int retain, struct mosquitto_msg_store **stored) { - int rc = MOSQ_ERR_SUCCESS; + int rc = 0; struct mosquitto__subhier *subhier; struct sub__token *tokens = NULL; - struct mosquitto *context; - int sub_qos; assert(db); assert(topic); @@ -530,29 +527,6 @@ int sub__messages_queue(struct mosquitto_db *db, const char *source_id, const ch */ (*stored)->ref_count++; - if(db->config->allow_direct_messages){ - if(!strncmp(UHPA_ACCESS_TOPIC(tokens), "$CLIENT", tokens->topic_len)){ - tokens = tokens->next; - if(tokens && !strncmp(UHPA_ACCESS_TOPIC(tokens), "direct", tokens->topic_len)){ - tokens = tokens->next; - if(tokens && tokens->topic_len > 0){ - HASH_FIND(hh_id, db->contexts_by_id, UHPA_ACCESS_TOPIC(tokens), tokens->topic_len, context); - if(context){ - if(db->config->direct_message_qos == -1){ - sub_qos = qos; - }else{ - sub_qos = db->config->direct_message_qos; - } - rc = subs__send_msg(db, context, sub_qos, retain, qos, *stored); - } - } - } - db__msg_store_deref(db, stored); - sub__topic_tokens_free(tokens); - return rc; - } - } - subhier = db->subs.children; while(subhier){ if(!strcmp(UHPA_ACCESS_TOPIC(subhier), UHPA_ACCESS_TOPIC(tokens))){