[464458] mosquitto_sub: Add option to print the payload in hex.

Bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=464458
pull/139/head
Roger A. Light 11 years ago
parent 90dc6d8c4c
commit 2e05e40350

@ -1,8 +1,13 @@
1.5 - 2015xxxx
==============
Broker:
- Reduce calls to malloc through the use of UHPA.
Client:
- Add -x to mosquitto_sub for printing the payload in hexadecimal format.
1.4.1 - 2015xxxx
================

@ -629,6 +629,11 @@ int client_config_line_proc(struct mosq_config *cfg, int pub_or_sub, int argc, c
goto unknown_option;
}
cfg->verbose = 1;
}else if(!strcmp(argv[i], "-x")){
if(pub_or_sub == CLIENT_PUB){
goto unknown_option;
}
cfg->hex_output = true;
}else{
goto unknown_option;
}

@ -79,6 +79,7 @@ struct mosq_config {
int filter_out_count; /* sub */
bool verbose; /* sub */
bool eol; /* sub */
bool hex_output; /* sub */
int msg_count; /* sub */
#ifdef WITH_SOCKS
char *socks5_host;

@ -33,6 +33,19 @@ Contributors:
bool process_messages = true;
int msg_count = 0;
static void write_payload(const unsigned char *payload, int payloadlen, bool hex)
{
int i;
if(!hex){
fwrite(payload, 1, payloadlen, stdout);
}else{
for(i=0; i<payloadlen; i++){
fprintf(stdout, "%x", payload[i]);
}
}
}
void my_message_callback(struct mosquitto *mosq, void *obj, const struct mosquitto_message *message)
{
struct mosq_config *cfg;
@ -55,7 +68,7 @@ void my_message_callback(struct mosquitto *mosq, void *obj, const struct mosquit
if(cfg->verbose){
if(message->payloadlen){
printf("%s ", message->topic);
fwrite(message->payload, 1, message->payloadlen, stdout);
write_payload(message->payload, message->payloadlen, cfg->hex_output);
if(cfg->eol){
printf("\n");
}
@ -67,7 +80,7 @@ void my_message_callback(struct mosquitto *mosq, void *obj, const struct mosquit
fflush(stdout);
}else{
if(message->payloadlen){
fwrite(message->payload, 1, message->payloadlen, stdout);
write_payload(message->payload, message->payloadlen, cfg->hex_output);
if(cfg->eol){
printf("\n");
}
@ -137,7 +150,7 @@ void print_usage(void)
printf(" [-A bind_address]\n");
#endif
printf(" [-i id] [-I id_prefix]\n");
printf(" [-d] [-N] [--quiet] [-v]\n");
printf(" [-d] [-N] [--quiet] [-v] [-x]\n");
printf(" [-u username [-P password]]\n");
printf(" [--will-topic [--will-payload payload] [--will-qos qos] [--will-retain]]\n");
#ifdef WITH_TLS
@ -175,6 +188,7 @@ void print_usage(void)
printf(" -v : print published messages verbosely.\n");
printf(" -V : specify the version of the MQTT protocol to use when connecting.\n");
printf(" Can be mqttv31 or mqttv311. Defaults to mqttv31.\n");
printf(" -x : print published message payloads as hexadecimal data.\n");
printf(" --help : display this message.\n");
printf(" --quiet : don't print error messages.\n");
printf(" --will-payload : payload for the client Will, which is sent by the broker in case of\n");

@ -32,6 +32,7 @@
<arg><option>-N</option></arg>
<arg><option>--quiet</option></arg>
<arg><option>-v</option></arg>
<arg><option>-x</option></arg>
<arg>
<arg><option>-u</option> <replaceable>username</replaceable></arg>
<arg><option>-P</option> <replaceable>password</replaceable></arg>
@ -455,6 +456,13 @@
the client disconnects unexpectedly.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-x</option></term>
<listitem>
<para>Print published message payloads as hexadecimal
data.</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>

Loading…
Cancel
Save