Skip to content

Commit

Permalink
mosquitto_sub and mosquitto_rr now open stdout in binary mode on Windows
Browse files Browse the repository at this point in the history
This is so binary payloads are not modified when printing.

Thanks to Steve Mullock.
  • Loading branch information
ralight committed Jun 9, 2021
1 parent 5217863 commit 6028d0e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 3 deletions.
7 changes: 7 additions & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
2.0.12 - 2021-07-xx
===================

Clients:
- mosquitto_sub and mosquitto_rr now open stdout in binary mode on Windows
so binary payloads are not modified when printing.

2.0.11 - 2021-06-08
===================

Expand Down
1 change: 1 addition & 0 deletions client/rr_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ int main(int argc, char *argv[])
#endif

mosquitto_lib_init();
output_init();

rc = client_config_load(&cfg, CLIENT_RR, argc, argv);
if(rc){
Expand Down
2 changes: 1 addition & 1 deletion client/sub_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ int main(int argc, char *argv[])

mosquitto_lib_init();

rand_init();
output_init();

rc = client_config_load(&cfg, CLIENT_SUB, argc, argv);
if(rc){
Expand Down
7 changes: 6 additions & 1 deletion client/sub_client_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
#ifdef WIN32
/* For rand_s on Windows */
# define _CRT_RAND_S
# include <fcntl.h>
# include <io.h>
#endif

#include <assert.h>
Expand Down Expand Up @@ -764,7 +766,7 @@ static void formatted_print(const struct mosq_config *lcfg, const struct mosquit
}


void rand_init(void)
void output_init(void)
{
#ifndef WIN32
struct tm *ti = NULL;
Expand All @@ -773,6 +775,9 @@ void rand_init(void)
if(!get_time(&ti, &ns)){
srandom((unsigned int)ns);
}
#else
/* Disable text translation so binary payloads aren't modified */
_setmode(_fileno(stdout), _O_BINARY);
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion client/sub_client_output.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
#include "mosquitto.h"
#include "client_shared.h"

void rand_init(void);
void output_init(void);
void print_message(struct mosq_config *cfg, const struct mosquitto_message *message, const mosquitto_property *properties);

#endif

0 comments on commit 6028d0e

Please sign in to comment.