Very simple v5 CONNECT support - no properties.

pull/1022/head
Roger A. Light 7 years ago
parent ccc97d8c96
commit 561513fdd4

@ -263,6 +263,8 @@ int mosquitto_opts_set(struct mosquitto *mosq, enum mosq_opt_t option, void *val
mosq->protocol = mosq_p_mqtt31;
}else if(ival == MQTT_PROTOCOL_V311){
mosq->protocol = mosq_p_mqtt311;
}else if(ival == MQTT_PROTOCOL_V5){
mosq->protocol = mosq_p_mqtt5;
}else{
return MOSQ_ERR_INVAL;
}

@ -60,12 +60,15 @@ int send__connect(struct mosquitto *mosq, uint16_t keepalive, bool clean_session
password = mosq->password;
#endif
if(mosq->protocol == mosq_p_mqtt31){
version = MQTT_PROTOCOL_V31;
headerlen = 12;
if(mosq->protocol == mosq_p_mqtt5){
version = MQTT_PROTOCOL_V5;
headerlen = 11; /* FIXME - this has a fixed property length of 0 */
}else if(mosq->protocol == mosq_p_mqtt311){
version = MQTT_PROTOCOL_V311;
headerlen = 10;
}else if(mosq->protocol == mosq_p_mqtt31){
version = MQTT_PROTOCOL_V31;
headerlen = 12;
}else{
return MOSQ_ERR_INVAL;
}
@ -98,7 +101,7 @@ int send__connect(struct mosquitto *mosq, uint16_t keepalive, bool clean_session
/* Variable header */
if(version == MQTT_PROTOCOL_V31){
packet__write_string(packet, PROTOCOL_NAME_v31, strlen(PROTOCOL_NAME_v31));
}else if(version == MQTT_PROTOCOL_V311){
}else{
packet__write_string(packet, PROTOCOL_NAME, strlen(PROTOCOL_NAME));
}
#if defined(WITH_BROKER) && defined(WITH_BRIDGE)
@ -121,6 +124,11 @@ int send__connect(struct mosquitto *mosq, uint16_t keepalive, bool clean_session
packet__write_byte(packet, byte);
packet__write_uint16(packet, keepalive);
if(mosq->protocol == mosq_p_mqtt5){
/* Write properties */
packet__write_byte(packet, 0); /* FIXME - No properties yet. */
}
/* Payload */
packet__write_string(packet, clientid, strlen(clientid));
if(will){

@ -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;

@ -266,7 +266,7 @@ static int sub__add_recurse(struct mosquitto_db *db, struct mosquitto *context,
if(context->protocol == mosq_p_mqtt31){
return -1;
}else{
/* mqttv311 requires retained messages are resent on
/* mqttv311/mqttv5 requires retained messages are resent on
* resubscribe. */
return 0;
}

Loading…
Cancel
Save