diff --git a/ChangeLog.txt b/ChangeLog.txt index 455a3a76..86ec2c5d 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -26,6 +26,7 @@ Clients: JSON output. - Add `--pretty` option to mosquitto_sub/rr for formatted/unformatted JSON output. +- Add support for v5 property printing to mosquitto_sub/rr in non-JSON mode. 1.6.7 - 20190925 diff --git a/client/client_shared.c b/client/client_shared.c index 79829929..01affcaf 100644 --- a/client/client_shared.c +++ b/client/client_shared.c @@ -57,6 +57,16 @@ static int check_format(const char *str) }else{ if(str[i+1] == '%'){ // Print %, ignore + }else if(str[i+1] == 'A'){ + // MQTT v5 property topic-alias + }else if(str[i+1] == 'C'){ + // MQTT v5 property content-type + }else if(str[i+1] == 'D'){ + // MQTT v5 property correlation-data + }else if(str[i+1] == 'E'){ + // MQTT v5 property message-expiry-interval + }else if(str[i+1] == 'F'){ + // MQTT v5 property payload-format-indicator }else if(str[i+1] == 'I'){ // ISO 8601 date+time }else if(str[i+1] == 'l'){ @@ -67,6 +77,10 @@ static int check_format(const char *str) // payload }else if(str[i+1] == 'q'){ // qos + }else if(str[i+1] == 'R'){ + // MQTT v5 property response-topic + }else if(str[i+1] == 'S'){ + // MQTT v5 property subscription-identifier }else if(str[i+1] == 'r'){ // retain }else if(str[i+1] == 't'){ diff --git a/client/sub_client_output.c b/client/sub_client_output.c index 80840740..d4bcb681 100644 --- a/client/sub_client_output.c +++ b/client/sub_client_output.c @@ -335,6 +335,10 @@ static void formatted_print(const struct mosq_config *lcfg, const struct mosquit char strf[3]; char buf[100]; int rc; + uint8_t i8value; + uint16_t i16value; + uint32_t i32value; + char *binvalue, *strvalue; len = strlen(lcfg->format); @@ -347,6 +351,38 @@ static void formatted_print(const struct mosq_config *lcfg, const struct mosquit fputc('%', stdout); break; + case 'A': + if(mosquitto_property_read_int16(properties, MQTT_PROP_TOPIC_ALIAS, &i16value, false)){ + printf("%d", i16value); + } + break; + + case 'C': + if(mosquitto_property_read_string(properties, MQTT_PROP_CONTENT_TYPE, &strvalue, false)){ + printf("%s", strvalue); + free(strvalue); + } + break; + + case 'D': + if(mosquitto_property_read_binary(properties, MQTT_PROP_CORRELATION_DATA, (void **)&binvalue, &i16value, false)){ + fwrite(binvalue, 1, i16value, stdout); + free(binvalue); + } + break; + + case 'E': + if(mosquitto_property_read_int32(properties, MQTT_PROP_MESSAGE_EXPIRY_INTERVAL, &i32value, false)){ + printf("%d", i32value); + } + break; + + case 'F': + if(mosquitto_property_read_byte(properties, MQTT_PROP_PAYLOAD_FORMAT_INDICATOR, &i8value, false)){ + printf("%d", i8value); + } + break; + case 'I': if(!ti){ if(get_time(&ti, &ns)){ @@ -405,6 +441,13 @@ static void formatted_print(const struct mosq_config *lcfg, const struct mosquit fputc(message->qos + 48, stdout); break; + case 'R': + if(mosquitto_property_read_string(properties, MQTT_PROP_RESPONSE_TOPIC, &strvalue, false)){ + printf("%s", strvalue); + free(strvalue); + } + break; + case 'r': if(message->retain){ fputc('1', stdout); @@ -413,6 +456,12 @@ static void formatted_print(const struct mosq_config *lcfg, const struct mosquit } break; + case 'S': + if(mosquitto_property_read_varint(properties, MQTT_PROP_SUBSCRIPTION_IDENTIFIER, &i32value, false)){ + printf("%d", i32value); + } + break; + case 't': fputs(message->topic, stdout); break; diff --git a/man/mosquitto_rr.1.xml b/man/mosquitto_rr.1.xml index cbb57fe7..f5e11ddf 100644 --- a/man/mosquitto_rr.1.xml +++ b/man/mosquitto_rr.1.xml @@ -667,11 +667,19 @@ MQTT related parameters a literal %. + the MQTT v5 topic-alias property, if present. + the MQTT v5 content-type property, if present. + the MQTT v5 correlation-data property, if present. Note that this + property is specified as binary data, so may produce non-printable characters. + the MQTT v5 message-expiry-interval property, if present. + the MQTT v5 payload-format-indicator property, if present. the length of the payload in bytes. the message id (only relevant for messages with QoS>0). the payload raw bytes (may produce non-printable characters depending on the payload). the message QoS. + the MQTT v5 response-topic property, if present. the retained flag for the message. + the MQTT v5 subscription-identifier property, if present. the message topic. the payload with each byte as a hexadecimal number (lower case). the payload with each byte as a hexadecimal number (upper case). diff --git a/man/mosquitto_sub.1.xml b/man/mosquitto_sub.1.xml index 12af1335..e6d8d2ea 100644 --- a/man/mosquitto_sub.1.xml +++ b/man/mosquitto_sub.1.xml @@ -784,11 +784,19 @@ mosquitto_sub -t 'bbc/#' -T bbc/bbc1 --remove-retained MQTT related parameters a literal %. + the MQTT v5 topic-alias property, if present. + the MQTT v5 content-type property, if present. + the MQTT v5 correlation-data property, if present. Note that this + property is specified as binary data, so may produce non-printable characters. + the MQTT v5 message-expiry-interval property, if present. + the MQTT v5 payload-format-indicator property, if present. the length of the payload in bytes. the message id (only relevant for messages with QoS>0). the payload raw bytes (may produce non-printable characters depending on the payload). the message QoS. + the MQTT v5 response-topic property, if present. the retained flag for the message. + the MQTT v5 subscription-identifier property, if present. the message topic. the payload with each byte as a hexadecimal number (lower case). the payload with each byte as a hexadecimal number (upper case).