All existing commands read properties.

pull/1022/head
Roger A. Light 7 years ago
parent 723d9c2782
commit eefa7f7604

@ -22,35 +22,46 @@ Contributors:
#include "logging_mosq.h"
#include "memory_mosq.h"
#include "messages_mosq.h"
#include "mqtt_protocol.h"
#include "net_mosq.h"
#include "packet_mosq.h"
#include "property_mosq.h"
#include "read_handle.h"
int handle__connack(struct mosquitto *mosq)
{
uint8_t connect_flags;
uint8_t result;
uint8_t reason_code;
int rc;
struct mqtt5__property *properties = NULL;
assert(mosq);
rc = packet__read_byte(&mosq->in_packet, &connect_flags);
if(rc) return rc;
rc = packet__read_byte(&mosq->in_packet, &result);
rc = packet__read_byte(&mosq->in_packet, &reason_code);
if(rc) return rc;
log__printf(mosq, MOSQ_LOG_DEBUG, "Client %s received CONNACK (%d)", mosq->id, result);
if(mosq->protocol == mosq_p_mqtt5){
rc = property__read_all(CONNACK, &mosq->in_packet, &properties);
if(rc) return rc;
property__free_all(&properties);
}
property__free_all(&properties); /* FIXME - TEMPORARY UNTIL PROPERTIES PROCESSED */
log__printf(mosq, MOSQ_LOG_DEBUG, "Client %s received CONNACK (%d)", mosq->id, reason_code);
pthread_mutex_lock(&mosq->callback_mutex);
if(mosq->on_connect){
mosq->in_callback = true;
mosq->on_connect(mosq, mosq->userdata, result);
mosq->on_connect(mosq, mosq->userdata, reason_code);
mosq->in_callback = false;
}
if(mosq->on_connect_with_flags){
mosq->in_callback = true;
mosq->on_connect_with_flags(mosq, mosq->userdata, result, connect_flags);
mosq->on_connect_with_flags(mosq, mosq->userdata, reason_code, connect_flags);
mosq->in_callback = false;
}
pthread_mutex_unlock(&mosq->callback_mutex);
switch(result){
switch(reason_code){
case 0:
if(mosq->state != mosq_cs_disconnecting){
mosq->state = mosq_cs_connected;

@ -44,10 +44,19 @@ int handle__pubackcomp(struct mosquitto *mosq, const char *type)
{
uint16_t mid;
int rc;
struct mqtt5__property *properties = NULL;
assert(mosq);
rc = packet__read_uint16(&mosq->in_packet, &mid);
if(rc) return rc;
if(mosq->protocol == mosq_p_mqtt5){
rc = property__read_all(PUBACK, &mosq->in_packet, &properties);
if(rc) return rc;
/* Immediately free, we don't do anything with Reason String or User Property at the moment */
property__free_all(&properties);
}
#ifdef WITH_BROKER
log__printf(NULL, MOSQ_LOG_DEBUG, "Received %s from %s (Mid: %d)", type, mosq->id, mid);

@ -23,8 +23,10 @@ Contributors:
#include "mosquitto_internal.h"
#include "logging_mosq.h"
#include "memory_mosq.h"
#include "mqtt_protocol.h"
#include "messages_mosq.h"
#include "packet_mosq.h"
#include "property_mosq.h"
#include "send_mosq.h"
#include "time_mosq.h"
@ -36,6 +38,7 @@ int handle__publish(struct mosquitto *mosq)
int rc = 0;
uint16_t mid;
int slen;
struct mqtt5__property *properties = NULL;
assert(mosq);
@ -67,6 +70,13 @@ int handle__publish(struct mosquitto *mosq)
message->msg.mid = (int)mid;
}
if(mosq->protocol == mosq_p_mqtt5){
rc = property__read_all(PUBLISH, &mosq->in_packet, &properties);
if(rc) return rc;
property__free_all(&properties);
}
property__free_all(&properties); /* FIXME - TEMPORARY UNTIL PROPERTIES PROCESSED */
message->msg.payloadlen = mosq->in_packet.remaining_length - mosq->in_packet.pos;
if(message->msg.payloadlen){
message->msg.payload = mosquitto__calloc(message->msg.payloadlen+1, sizeof(uint8_t));

@ -39,10 +39,19 @@ int handle__pubrec(struct mosquitto *mosq)
{
uint16_t mid;
int rc;
struct mqtt5__property *properties = NULL;
assert(mosq);
rc = packet__read_uint16(&mosq->in_packet, &mid);
if(rc) return rc;
if(mosq->protocol == mosq_p_mqtt5){
rc = property__read_all(PUBREC, &mosq->in_packet, &properties);
if(rc) return rc;
/* Immediately free, we don't do anything with Reason String or User Property at the moment */
property__free_all(&properties);
}
#ifdef WITH_BROKER
log__printf(NULL, MOSQ_LOG_DEBUG, "Received PUBREC from %s (Mid: %d)", mosq->id, mid);

@ -43,6 +43,7 @@ int handle__pubrel(struct mosquitto_db *db, struct mosquitto *mosq)
struct mosquitto_message_all *message = NULL;
#endif
int rc;
struct mqtt5__property *properties = NULL;
assert(mosq);
if(mosq->protocol != mosq_p_mqtt31){
@ -52,6 +53,14 @@ int handle__pubrel(struct mosquitto_db *db, struct mosquitto *mosq)
}
rc = packet__read_uint16(&mosq->in_packet, &mid);
if(rc) return rc;
if(mosq->protocol == mosq_p_mqtt5){
rc = property__read_all(PUBREL, &mosq->in_packet, &properties);
if(rc) return rc;
/* Immediately free, we don't do anything with Reason String or User Property at the moment */
property__free_all(&properties);
}
#ifdef WITH_BROKER
log__printf(NULL, MOSQ_LOG_DEBUG, "Received PUBREL from %s (Mid: %d)", mosq->id, mid);

@ -26,7 +26,9 @@ Contributors:
#include "mosquitto_internal.h"
#include "logging_mosq.h"
#include "memory_mosq.h"
#include "mqtt_protocol.h"
#include "packet_mosq.h"
#include "property_mosq.h"
int handle__suback(struct mosquitto *mosq)
@ -37,6 +39,7 @@ int handle__suback(struct mosquitto *mosq)
int qos_count;
int i = 0;
int rc;
struct mqtt5__property *properties = NULL;
assert(mosq);
#ifdef WITH_BROKER
@ -47,6 +50,13 @@ int handle__suback(struct mosquitto *mosq)
rc = packet__read_uint16(&mosq->in_packet, &mid);
if(rc) return rc;
if(mosq->protocol == mosq_p_mqtt5){
rc = property__read_all(SUBACK, &mosq->in_packet, &properties);
if(rc) return rc;
/* Immediately free, we don't do anything with Reason String or User Property at the moment */
property__free_all(&properties);
}
qos_count = mosq->in_packet.remaining_length - mosq->in_packet.pos;
granted_qos = mosquitto__malloc(qos_count*sizeof(int));
if(!granted_qos) return MOSQ_ERR_NOMEM;

@ -31,6 +31,7 @@ Contributors:
#include "mqtt_protocol.h"
#include "net_mosq.h"
#include "packet_mosq.h"
#include "property_mosq.h"
#include "read_handle.h"
#include "send_mosq.h"
#include "util_mosq.h"
@ -40,6 +41,7 @@ int handle__unsuback(struct mosquitto *mosq)
{
uint16_t mid;
int rc;
struct mqtt5__property *properties = NULL;
assert(mosq);
#ifdef WITH_BROKER
@ -49,6 +51,14 @@ int handle__unsuback(struct mosquitto *mosq)
#endif
rc = packet__read_uint16(&mosq->in_packet, &mid);
if(rc) return rc;
if(mosq->protocol == mosq_p_mqtt5){
rc = property__read_all(UNSUBACK, &mosq->in_packet, &properties);
if(rc) return rc;
/* Immediately free, we don't do anything with Reason String or User Property at the moment */
property__free_all(&properties);
}
#ifndef WITH_BROKER
pthread_mutex_lock(&mosq->callback_mutex);
if(mosq->on_unsubscribe){

@ -28,20 +28,30 @@ Contributors:
int handle__connack(struct mosquitto_db *db, struct mosquitto *context)
{
uint8_t byte;
uint8_t rc;
int rc;
uint8_t connect_acknowledge;
uint8_t reason_code;
int i;
char *notification_topic;
int notification_topic_len;
char notification_payload;
struct mqtt5__property *properties = NULL;
if(!context){
return MOSQ_ERR_INVAL;
}
log__printf(NULL, MOSQ_LOG_DEBUG, "Received CONNACK on connection %s.", context->id);
if(packet__read_byte(&context->in_packet, &byte)) return 1; // Reserved byte, not used
if(packet__read_byte(&context->in_packet, &rc)) return 1;
switch(rc){
if(packet__read_byte(&context->in_packet, &connect_acknowledge)) return 1;
if(packet__read_byte(&context->in_packet, &reason_code)) return 1;
if(context->protocol == mosq_p_mqtt5){
rc = property__read_all(CONNACK, &context->in_packet, &properties);
if(rc) return rc;
property__free_all(&properties);
}
property__free_all(&properties); /* FIXME - TEMPORARY UNTIL PROPERTIES PROCESSED */
switch(reason_code){
case CONNACK_ACCEPTED:
if(context->bridge){
if(context->bridge->notifications){

@ -304,7 +304,7 @@ int handle__connect(struct mosquitto_db *db, struct mosquitto *context)
if(protocol_version == PROTOCOL_VERSION_v5){
rc = property__read_all(CMD_WILL, &context->in_packet, &will_struct->properties);
if(rc) return rc;
property__free_all(&will_struct->properties);
property__free_all(&properties); /* FIXME - TEMPORARY UNTIL PROPERTIES PROCESSED */
}
if(packet__read_string(&context->in_packet, &will_topic, &slen)){
rc = 1;
@ -721,9 +721,20 @@ handle_connect_error:
int handle__disconnect(struct mosquitto_db *db, struct mosquitto *context)
{
int rc;
struct mqtt5__property *properties = NULL;
if(!context){
return MOSQ_ERR_INVAL;
}
if(context->protocol == mosq_p_mqtt5){
rc = property__read_all(DISCONNECT, &context->in_packet, &properties);
if(rc) return rc;
property__free_all(&properties);
}
property__free_all(&properties); /* FIXME - TEMPORARY UNTIL PROPERTIES PROCESSED */
if(context->in_packet.remaining_length != 0){
return MOSQ_ERR_PROTOCOL;
}

@ -43,7 +43,6 @@ int handle__subscribe(struct mosquitto_db *db, struct mosquitto *context)
if(!context) return MOSQ_ERR_INVAL;
log__printf(NULL, MOSQ_LOG_DEBUG, "Received SUBSCRIBE from %s", context->id);
/* FIXME - plenty of potential for memory leaks here */
if(context->protocol != mosq_p_mqtt31){
if((context->in_packet.command&0x0F) != 0x02){

@ -24,18 +24,14 @@ Contributors:
#include "mqtt_protocol.h"
#include "packet_mosq.h"
#include "send_mosq.h"
/*
#include "sys_tree.h"
#include "time_mosq.h"
#include "tls_mosq.h"
#include "util_mosq.h"
*/
int handle__unsubscribe(struct mosquitto_db *db, struct mosquitto *context)
{
uint16_t mid;
char *sub;
int slen;
int rc;
struct mqtt5__property *properties = NULL;
if(!context) return MOSQ_ERR_INVAL;
log__printf(NULL, MOSQ_LOG_DEBUG, "Received UNSUBSCRIBE from %s", context->id);
@ -47,6 +43,13 @@ int handle__unsubscribe(struct mosquitto_db *db, struct mosquitto *context)
}
if(packet__read_uint16(&context->in_packet, &mid)) return 1;
if(context->protocol == mosq_p_mqtt5){
rc = property__read_all(UNSUBSCRIBE, &context->in_packet, &properties);
if(rc) return rc;
/* Immediately free, we don't do anything with User Property at the moment */
property__free_all(&properties);
}
if(context->protocol == mosq_p_mqtt311 || context->protocol == mosq_p_mqtt5){
if(context->in_packet.pos == context->in_packet.remaining_length){
/* No topic specified, protocol error. */

Loading…
Cancel
Save