Add support for v5 property printing to mosquitto_sub/rr in non-JSON mode.

This commit is contained in:
Roger A. Light 2019-10-15 15:23:29 +01:00
parent 9e4226622f
commit 59c0bfe6e1
5 changed files with 80 additions and 0 deletions

View File

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

View File

@ -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'){

View File

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

View File

@ -667,11 +667,19 @@
<title>MQTT related parameters</title>
<itemizedlist mark="circle">
<listitem><para><option>%%</option> a literal %.</para></listitem>
<listitem><para><option>%A</option> the MQTT v5 topic-alias property, if present.</para></listitem>
<listitem><para><option>%C</option> the MQTT v5 content-type property, if present.</para></listitem>
<listitem><para><option>%D</option> the MQTT v5 correlation-data property, if present. Note that this
property is specified as binary data, so may produce non-printable characters.</para></listitem>
<listitem><para><option>%E</option> the MQTT v5 message-expiry-interval property, if present.</para></listitem>
<listitem><para><option>%F</option> the MQTT v5 payload-format-indicator property, if present.</para></listitem>
<listitem><para><option>%l</option> the length of the payload in bytes.</para></listitem>
<listitem><para><option>%m</option> the message id (only relevant for messages with QoS>0).</para></listitem>
<listitem><para><option>%p</option> the payload raw bytes (may produce non-printable characters depending on the payload).</para></listitem>
<listitem><para><option>%q</option> the message QoS.</para></listitem>
<listitem><para><option>%R</option> the MQTT v5 response-topic property, if present.</para></listitem>
<listitem><para><option>%r</option> the retained flag for the message.</para></listitem>
<listitem><para><option>%S</option> the MQTT v5 subscription-identifier property, if present.</para></listitem>
<listitem><para><option>%t</option> the message topic.</para></listitem>
<listitem><para><option>%x</option> the payload with each byte as a hexadecimal number (lower case).</para></listitem>
<listitem><para><option>%X</option> the payload with each byte as a hexadecimal number (upper case).</para></listitem>

View File

@ -784,11 +784,19 @@ mosquitto_sub -t 'bbc/#' -T bbc/bbc1 --remove-retained</programlisting>
<title>MQTT related parameters</title>
<itemizedlist mark="circle">
<listitem><para><option>%%</option> a literal %.</para></listitem>
<listitem><para><option>%A</option> the MQTT v5 topic-alias property, if present.</para></listitem>
<listitem><para><option>%C</option> the MQTT v5 content-type property, if present.</para></listitem>
<listitem><para><option>%D</option> the MQTT v5 correlation-data property, if present. Note that this
property is specified as binary data, so may produce non-printable characters.</para></listitem>
<listitem><para><option>%E</option> the MQTT v5 message-expiry-interval property, if present.</para></listitem>
<listitem><para><option>%F</option> the MQTT v5 payload-format-indicator property, if present.</para></listitem>
<listitem><para><option>%l</option> the length of the payload in bytes.</para></listitem>
<listitem><para><option>%m</option> the message id (only relevant for messages with QoS>0).</para></listitem>
<listitem><para><option>%p</option> the payload raw bytes (may produce non-printable characters depending on the payload).</para></listitem>
<listitem><para><option>%q</option> the message QoS.</para></listitem>
<listitem><para><option>%R</option> the MQTT v5 response-topic property, if present.</para></listitem>
<listitem><para><option>%r</option> the retained flag for the message.</para></listitem>
<listitem><para><option>%S</option> the MQTT v5 subscription-identifier property, if present.</para></listitem>
<listitem><para><option>%t</option> the message topic.</para></listitem>
<listitem><para><option>%x</option> the payload with each byte as a hexadecimal number (lower case).</para></listitem>
<listitem><para><option>%X</option> the payload with each byte as a hexadecimal number (upper case).</para></listitem>