diff options
Diffstat (limited to 'src/publish.c')
| -rw-r--r-- | src/publish.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/publish.c b/src/publish.c index cc19502..98cab76 100644 --- a/src/publish.c +++ b/src/publish.c | |||
| @@ -15,6 +15,10 @@ | |||
| 15 | #include "config.h" | 15 | #include "config.h" |
| 16 | #include "mqtt.h" | 16 | #include "mqtt.h" |
| 17 | 17 | ||
| 18 | #ifndef MAX_COMMAND_LENGTH | ||
| 19 | # define MAX_COMMAND_LENGTH 100 | ||
| 20 | #endif | ||
| 21 | |||
| 18 | static bool | 22 | static bool |
| 19 | streq(const char *lhs, const char *rhs) | 23 | streq(const char *lhs, const char *rhs) |
| 20 | { | 24 | { |
| @@ -22,22 +26,22 @@ streq(const char *lhs, const char *rhs) | |||
| 22 | } | 26 | } |
| 23 | 27 | ||
| 24 | static void | 28 | static void |
| 25 | cleanup_app(void) | 29 | application_cleanup(void) |
| 26 | { | 30 | { |
| 27 | mosquitto_lib_cleanup(); | 31 | mosquitto_lib_cleanup(); |
| 28 | } | 32 | } |
| 29 | 33 | ||
| 30 | static void | 34 | static void |
| 31 | init_app(void) | 35 | application_init(void) |
| 32 | { | 36 | { |
| 33 | mosquitto_lib_init(); | 37 | mosquitto_lib_init(); |
| 34 | (void) atexit(cleanup_app); | 38 | (void) atexit(application_cleanup); |
| 35 | } | 39 | } |
| 36 | 40 | ||
| 37 | int | 41 | int |
| 38 | main(void) | 42 | main(void) |
| 39 | { | 43 | { |
| 40 | init_app(); | 44 | application_init(); |
| 41 | 45 | ||
| 42 | struct mosquitto *client = mqtt_connect( | 46 | struct mosquitto *client = mqtt_connect( |
| 43 | NULL, | 47 | NULL, |
| @@ -55,7 +59,7 @@ main(void) | |||
| 55 | for ( bool quit = false; !quit; ) { | 59 | for ( bool quit = false; !quit; ) { |
| 56 | printf("> "); | 60 | printf("> "); |
| 57 | 61 | ||
| 58 | char command[100] = { 0 }; // NOLINT | 62 | char command[MAX_COMMAND_LENGTH]; |
| 59 | if ( fgets(command, sizeof command, stdin) == NULL ) { | 63 | if ( fgets(command, sizeof command, stdin) == NULL ) { |
| 60 | quit = true; | 64 | quit = true; |
| 61 | continue; | 65 | continue; |
| @@ -72,7 +76,7 @@ main(void) | |||
| 72 | } | 76 | } |
| 73 | else if ( streq(command, "send") ) { | 77 | else if ( streq(command, "send") ) { |
| 74 | static const char payload[] = "ich bin ein payload"; | 78 | static const char payload[] = "ich bin ein payload"; |
| 75 | static const char topic[] = "testtopic"; | 79 | static const char topic[] = "testtopic"; |
| 76 | 80 | ||
| 77 | int err = mosquitto_publish( | 81 | int err = mosquitto_publish( |
| 78 | client, | 82 | client, |
