mirror of
https://github.com/eclipse-mosquitto/mosquitto.git
synced 2026-09-23 08:33:48 +08:00
Allow CONTROL messages to set a reason code/string for PUBACK/PUBREC.
This commit is contained in:
+13
-2
@@ -31,6 +31,7 @@ int control__process(struct mosquitto_db *db, struct mosquitto *context, struct
|
||||
struct mosquitto__callback *cb_found;
|
||||
struct mosquitto_evt_control event_data;
|
||||
struct mosquitto__security_options *opts;
|
||||
mosquitto_property *properties = NULL;
|
||||
int rc = MOSQ_ERR_SUCCESS;
|
||||
|
||||
if(db->config->per_listener_settings){
|
||||
@@ -48,15 +49,25 @@ int control__process(struct mosquitto_db *db, struct mosquitto *context, struct
|
||||
event_data.qos = stored->qos;
|
||||
event_data.retain = stored->retain;
|
||||
event_data.properties = stored->properties;
|
||||
event_data.reason_code = MQTT_RC_SUCCESS;
|
||||
event_data.reason_string = NULL;
|
||||
|
||||
rc = cb_found->cb(MOSQ_EVT_CONTROL, &event_data, cb_found->userdata);
|
||||
if(rc){
|
||||
if(context->protocol == mosq_p_mqtt5 && event_data.reason_string){
|
||||
mosquitto_property_add_string(&properties, MQTT_PROP_REASON_STRING, event_data.reason_string);
|
||||
}
|
||||
}
|
||||
free(event_data.reason_string);
|
||||
event_data.reason_string = NULL;
|
||||
}
|
||||
|
||||
if(stored->qos == 1){
|
||||
if(send__puback(context, stored->source_mid, 0, NULL)) rc = 1;
|
||||
if(send__puback(context, stored->source_mid, event_data.reason_code, properties)) rc = 1;
|
||||
}else if(stored->qos == 2){
|
||||
if(send__pubrec(context, stored->source_mid, 0, NULL)) rc = 1;
|
||||
if(send__pubrec(context, stored->source_mid, event_data.reason_code, properties)) rc = 1;
|
||||
}
|
||||
mosquitto_property_free_all(&properties);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -92,20 +92,24 @@ struct mosquitto_evt_control {
|
||||
struct mosquitto *client;
|
||||
const char *topic;
|
||||
const void *payload;
|
||||
const mosquitto_property *properties;
|
||||
char *reason_string;
|
||||
long payloadlen;
|
||||
int qos;
|
||||
uint8_t reason_code;
|
||||
bool retain;
|
||||
const mosquitto_property *properties;
|
||||
};
|
||||
|
||||
struct mosquitto_evt_message {
|
||||
struct mosquitto *client;
|
||||
char *topic;
|
||||
void *payload;
|
||||
mosquitto_property *properties;
|
||||
char *reason_string;
|
||||
long payloadlen;
|
||||
int qos;
|
||||
uint8_t reason_code;
|
||||
bool retain;
|
||||
mosquitto_property *properties;
|
||||
};
|
||||
|
||||
typedef int (*MOSQ_FUNC_generic_callback)(int, void *, void *);
|
||||
|
||||
Reference in New Issue
Block a user