Skip to content

Commit

Permalink
Fix listener mount_point not being removed on outgoing messages.
Browse files Browse the repository at this point in the history
Closes #2244. Thanks to alflexRH.
  • Loading branch information
ralight committed Aug 22, 2021
1 parent 3334901 commit 723b5d7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
2 changes: 2 additions & 0 deletions ChangeLog.txt
Expand Up @@ -26,6 +26,8 @@ Broker:
v3.1.1 protocol itself rather than an implementation, to be addressed.
- Fix broker not quiting if e.g. the `password_file` is specified as a
directory. Closes #2241.
- Fix listener mount_point not being removed on outgoing messages.
Closes #2244.

Client library:
- If a client uses TLS-PSK then force the default cipher list to use "PSK"
Expand Down
9 changes: 9 additions & 0 deletions lib/send_publish.c
Expand Up @@ -65,6 +65,15 @@ int send__publish(struct mosquitto *mosq, uint16_t mid, const char *topic, uint3
}

#ifdef WITH_BROKER
if(mosq->listener && mosq->listener->mount_point){
len = strlen(mosq->listener->mount_point);
if(len < strlen(topic)){
topic += len;
}else{
/* Invalid topic string. Should never happen, but silently swallow the message anyway. */
return MOSQ_ERR_SUCCESS;
}
}
#ifdef WITH_BRIDGE
if(mosq->bridge && mosq->bridge->topics && mosq->bridge->topic_remapping){
for(i=0; i<mosq->bridge->topic_count; i++){
Expand Down
35 changes: 23 additions & 12 deletions test/broker/10-listener-mount-point.py
Expand Up @@ -4,7 +4,7 @@

def write_config(filename, port1, port2):
with open(filename, 'w') as f:
f.write("port %d\n" % (port1))
f.write("listener %d\n" % (port1))
f.write("allow_anonymous true\n")
f.write("\n")
f.write("listener %d\n" % (port2))
Expand All @@ -31,29 +31,40 @@ def do_test(proto_ver):
write_config(conf_file, port1, port2)

rc = 1
keepalive = 60
connect_packet = mosq_test.gen_connect("test2", keepalive=keepalive, proto_ver=proto_ver)
connack_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver)

mid = 1
subscribe_packet = mosq_test.gen_subscribe(mid, "#", 0, proto_ver=proto_ver)
suback_packet = mosq_test.gen_suback(mid, 0, proto_ver=proto_ver)

publish_packet = mosq_test.gen_publish("mount/test", qos=0, payload="mount point", proto_ver=proto_ver)
# Subscriber for listener with mount point
connect_packet1 = mosq_test.gen_connect("test1", proto_ver=proto_ver)
connack_packet1 = mosq_test.gen_connack(rc=0, proto_ver=proto_ver)
subscribe_packet1 = mosq_test.gen_subscribe(mid, "#", 0, proto_ver=proto_ver)
suback_packet1 = mosq_test.gen_suback(mid, 0, proto_ver=proto_ver)
publish_packet1 = mosq_test.gen_publish("mount/test", qos=0, payload="mount point", proto_ver=proto_ver)

# Subscriber for listener without mount point
connect_packet2 = mosq_test.gen_connect("test2", proto_ver=proto_ver)
connack_packet2 = mosq_test.gen_connack(rc=0, proto_ver=proto_ver)
subscribe_packet2 = mosq_test.gen_subscribe(mid, "#", 0, proto_ver=proto_ver)
suback_packet2 = mosq_test.gen_suback(mid, 0, proto_ver=proto_ver)
publish_packet2 = mosq_test.gen_publish("test", qos=0, payload="mount point", proto_ver=proto_ver)

broker = mosq_test.start_broker(filename=os.path.basename(__file__), use_conf=True, port=port1)

try:
sock = mosq_test.do_client_connect(connect_packet, connack_packet, timeout=20, port=port1)
mosq_test.do_send_receive(sock, subscribe_packet, suback_packet, "suback")
sock1 = mosq_test.do_client_connect(connect_packet1, connack_packet1, timeout=20, port=port1)
mosq_test.do_send_receive(sock1, subscribe_packet1, suback_packet1, "suback1")

sock2 = mosq_test.do_client_connect(connect_packet2, connack_packet2, timeout=20, port=port2)
mosq_test.do_send_receive(sock2, subscribe_packet2, suback_packet2, "suback2")

helper(port2, proto_ver)
# Should have now received a publish command

mosq_test.expect_packet(sock, "publish", publish_packet)
mosq_test.expect_packet(sock1, "publish1", publish_packet1)
mosq_test.expect_packet(sock2, "publish2", publish_packet2)
rc = 0

sock.close()
sock1.close()
sock2.close()
except mosq_test.TestError:
pass
finally:
Expand Down

0 comments on commit 723b5d7

Please sign in to comment.