Process session-expiry-interval on CONNECT and DISCONNECT.
Add test to check for invalid values.pull/1072/head
parent
34e7da426c
commit
d5108956bf
@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
Copyright (c) 2018 Roger Light <roger@atchoo.org>
|
||||||
|
|
||||||
|
All rights reserved. This program and the accompanying materials
|
||||||
|
are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
|
||||||
|
The Eclipse Public License is available at
|
||||||
|
http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
and the Eclipse Distribution License is available at
|
||||||
|
http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
|
||||||
|
Contributors:
|
||||||
|
Roger Light - initial implementation and documentation.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "mosquitto_broker_internal.h"
|
||||||
|
#include "mqtt_protocol.h"
|
||||||
|
#include "property_mosq.h"
|
||||||
|
|
||||||
|
/* Process the incoming properties, we should be able to assume that only valid
|
||||||
|
* properties for CONNECT are present here. */
|
||||||
|
int property__process_connect(struct mosquitto *context, mosquitto_property *props)
|
||||||
|
{
|
||||||
|
mosquitto_property *p;
|
||||||
|
|
||||||
|
p = props;
|
||||||
|
|
||||||
|
while(p){
|
||||||
|
if(p->identifier == MQTT_PROP_SESSION_EXPIRY_INTERVAL){
|
||||||
|
context->session_expiry_interval = p->value.i32;
|
||||||
|
}
|
||||||
|
p = p->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
return MOSQ_ERR_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Process the incoming properties, we should be able to assume that only valid
|
||||||
|
* properties for DISCONNECT are present here. */
|
||||||
|
int property__process_disconnect(struct mosquitto *context, mosquitto_property *props)
|
||||||
|
{
|
||||||
|
mosquitto_property *p;
|
||||||
|
|
||||||
|
p = props;
|
||||||
|
|
||||||
|
while(p){
|
||||||
|
if(p->identifier == MQTT_PROP_SESSION_EXPIRY_INTERVAL){
|
||||||
|
if(context->session_expiry_interval == 0 && p->value.i32 != 0){
|
||||||
|
return MOSQ_ERR_PROTOCOL;
|
||||||
|
}
|
||||||
|
context->session_expiry_interval = p->value.i32;
|
||||||
|
}
|
||||||
|
p = p->next;
|
||||||
|
}
|
||||||
|
return MOSQ_ERR_SUCCESS;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,39 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
# Test whether sending a non zero session expiry interval in DISCONNECT after
|
||||||
|
# having sent a zero session expiry interval is treated correctly in MQTT v5.
|
||||||
|
|
||||||
|
from mosq_test_helper import *
|
||||||
|
|
||||||
|
rc = 1
|
||||||
|
|
||||||
|
keepalive = 10
|
||||||
|
props = mqtt5_props.gen_uint32_prop(mqtt5_props.PROP_SESSION_EXPIRY_INTERVAL, 0)
|
||||||
|
props = mqtt5_props.prop_finalise(props)
|
||||||
|
connect_packet = mosq_test.gen_connect("test", proto_ver=5, keepalive=keepalive, properties=props)
|
||||||
|
|
||||||
|
connack_packet = mosq_test.gen_connack(rc=0, proto_ver=5)
|
||||||
|
|
||||||
|
props = mqtt5_props.gen_uint32_prop(mqtt5_props.PROP_SESSION_EXPIRY_INTERVAL, 1)
|
||||||
|
props = mqtt5_props.prop_finalise(props)
|
||||||
|
disconnect_client_packet = mosq_test.gen_disconnect(proto_ver=5, properties=props)
|
||||||
|
|
||||||
|
disconnect_server_packet = mosq_test.gen_disconnect(proto_ver=5, reason_code=130)
|
||||||
|
|
||||||
|
port = mosq_test.get_port()
|
||||||
|
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)
|
||||||
|
|
||||||
|
try:
|
||||||
|
sock = mosq_test.do_client_connect(connect_packet, connack_packet, port=port)
|
||||||
|
mosq_test.do_send_receive(sock, disconnect_client_packet, disconnect_server_packet, "disconnect")
|
||||||
|
sock.close()
|
||||||
|
rc = 0
|
||||||
|
finally:
|
||||||
|
broker.terminate()
|
||||||
|
broker.wait()
|
||||||
|
(stdo, stde) = broker.communicate()
|
||||||
|
if rc:
|
||||||
|
print(stde)
|
||||||
|
|
||||||
|
exit(rc)
|
||||||
|
|
Loading…
Reference in New Issue