@ -183,7 +183,11 @@ int handle__connect(struct mosquitto_db *db, struct mosquitto *context)
}
context - > protocol = mosq_p_mqtt31 ;
} else if ( ! strcmp ( protocol_name , PROTOCOL_NAME ) ) {
if ( ( protocol_version & 0x7F ) ! = PROTOCOL_VERSION_v311 ) {
if ( ( protocol_version & 0x7F ) = = PROTOCOL_VERSION_v311 ) {
context - > protocol = mosq_p_mqtt311 ;
} else if ( ( protocol_version & 0x7F ) = = PROTOCOL_VERSION_v5 ) {
context - > protocol = mosq_p_mqtt5 ;
} else {
if ( db - > config - > connection_messages = = true ) {
log__printf ( NULL , MOSQ_LOG_INFO , " Invalid protocol version %d in CONNECT from %s. " ,
protocol_version , context - > address ) ;
@ -197,7 +201,6 @@ int handle__connect(struct mosquitto_db *db, struct mosquitto *context)
rc = MOSQ_ERR_PROTOCOL ;
goto handle_connect_error ;
}
context - > protocol = mosq_p_mqtt311 ;
} else {
if ( db - > config - > connection_messages = = true ) {
log__printf ( NULL , MOSQ_LOG_INFO , " Invalid protocol \" %s \" in CONNECT from %s. " ,
@ -211,7 +214,7 @@ int handle__connect(struct mosquitto_db *db, struct mosquitto *context)
rc = 1 ;
goto handle_connect_error ;
}
if ( context - > protocol = = mosq_p_mqtt311 ) {
if ( context - > protocol = = mosq_p_mqtt311 | | context - > protocol = = mosq_p_mqtt5 ) {
if ( ( connect_flags & 0x01 ) ! = 0x00 ) {
rc = MOSQ_ERR_PROTOCOL ;
goto handle_connect_error ;
@ -236,6 +239,20 @@ int handle__connect(struct mosquitto_db *db, struct mosquitto *context)
goto handle_connect_error ;
}
if ( protocol_version = = PROTOCOL_VERSION_v5 ) {
/* FIXME */
uint32_t property_len ;
if ( packet__read_varint ( & context - > in_packet , & property_len ) ) {
rc = 1 ;
goto handle_connect_error ;
}
if ( property_len ! = 0 ) {
/* FIXME Temporary fudge because of no property support */
rc = 1 ;
goto handle_connect_error ;
}
}
if ( packet__read_string ( & context - > in_packet , & client_id , & slen ) ) {
rc = 1 ;
goto handle_connect_error ;
@ -246,7 +263,7 @@ int handle__connect(struct mosquitto_db *db, struct mosquitto *context)
send__connack ( context , 0 , CONNACK_REFUSED_IDENTIFIER_REJECTED ) ;
rc = MOSQ_ERR_PROTOCOL ;
goto handle_connect_error ;
} else { /* mqtt311 */
} else { /* mqtt311 /mqtt5 */
mosquitto__free ( client_id ) ;
client_id = NULL ;
@ -348,7 +365,7 @@ int handle__connect(struct mosquitto_db *db, struct mosquitto *context)
}
}
} else {
if ( context - > protocol = = mosq_p_mqtt311 ) {
if ( context - > protocol = = mosq_p_mqtt311 | | context - > protocol = = mosq_p_mqtt5 ) {
if ( will_qos ! = 0 | | will_retain ! = 0 ) {
rc = MOSQ_ERR_PROTOCOL ;
goto handle_connect_error ;
@ -373,7 +390,7 @@ int handle__connect(struct mosquitto_db *db, struct mosquitto *context)
if ( context - > protocol = = mosq_p_mqtt31 ) {
/* Password flag given, but no password. Ignore. */
password_flag = 0 ;
} else if ( context - > protocol = = mosq_p_mqtt311 ) {
} else {
rc = MOSQ_ERR_PROTOCOL ;
goto handle_connect_error ;
}
@ -386,13 +403,13 @@ int handle__connect(struct mosquitto_db *db, struct mosquitto *context)
if ( context - > protocol = = mosq_p_mqtt31 ) {
/* Username flag given, but no username. Ignore. */
username_flag = 0 ;
} else if ( context - > protocol = = mosq_p_mqtt311 ) {
} else {
rc = MOSQ_ERR_PROTOCOL ;
goto handle_connect_error ;
}
}
} else {
if ( context - > protocol = = mosq_p_mqtt311 ) {
if ( context - > protocol = = mosq_p_mqtt311 | | context - > protocol = = mosq_p_mqtt5 ) {
if ( password_flag ) {
/* username_flag == 0 && password_flag == 1 is forbidden */
rc = MOSQ_ERR_PROTOCOL ;
@ -568,7 +585,7 @@ int handle__connect(struct mosquitto_db *db, struct mosquitto *context)
}
}
if ( context - > protocol = = mosq_p_mqtt311 ) {
if ( context - > protocol = = mosq_p_mqtt311 | | context - > protocol = = mosq_p_mqtt5 ) {
if ( clean_session = = 0 ) {
connect_ack | = 0x01 ;
}
@ -664,7 +681,7 @@ int handle__connect(struct mosquitto_db *db, struct mosquitto *context)
if ( context - > username ) {
log__printf ( NULL , MOSQ_LOG_NOTICE , " New client connected from %s as %s (c%d, k%d, u'%s'). " , context - > address , client_id , clean_session , context - > keepalive , context - > username ) ;
} else {
log__printf ( NULL , MOSQ_LOG_NOTICE , " New client connected from %s as %s ( c%d, k%d)." , context - > address , client_id , clean_session , context - > keepalive ) ;
log__printf ( NULL , MOSQ_LOG_NOTICE , " New client connected from %s as %s ( p%d, c%d, k%d)." , context - > address , client_id , context - > protocol , clean_session , context - > keepalive ) ;
}
}
@ -721,7 +738,7 @@ int handle__disconnect(struct mosquitto_db *db, struct mosquitto *context)
return MOSQ_ERR_PROTOCOL ;
}
log__printf ( NULL , MOSQ_LOG_DEBUG , " Received DISCONNECT from %s " , context - > id ) ;
if ( context - > protocol = = mosq_p_mqtt311 ) {
if ( context - > protocol = = mosq_p_mqtt311 | | context - > protocol = = mosq_p_mqtt5 ) {
if ( ( context - > in_packet . command & 0x0F ) ! = 0x00 ) {
do_disconnect ( db , context ) ;
return MOSQ_ERR_PROTOCOL ;