diff options
author | V.Krishn <vkrishn4@gmail.com> | 2019-12-02 22:51:40 +0530 |
---|---|---|
committer | V.Krishn <vkrishn4@gmail.com> | 2019-12-02 22:51:40 +0530 |
commit | 96d809ff25c5d6669c0590c6ffb57fd18b7ca6ef (patch) | |
tree | f3a2737d4d62861ab5e8117cee268453aa109539 | |
parent | 049e4531b8a3aded35f845b5f645d054e4368937 (diff) | |
download | mqtt-dirpub-96d809ff25c5d6669c0590c6ffb57fd18b7ca6ef.tar.bz2 |
add use of formats of -F with --fmask
eg. mosquitto_sub -v -t '#'
-F '/tmp/msgs/@Y/@m@d/%t/@H@M' --fmask "" --nodesuffix 'msg'
some stdout messages are available with -v
-rw-r--r-- | sub_client.c | 9 | ||||
-rw-r--r-- | sub_client_output.c | 41 |
2 files changed, 37 insertions, 13 deletions
diff --git a/sub_client.c b/sub_client.c index 410bce6..a00171e 100644 --- a/sub_client.c +++ b/sub_client.c @@ -56,7 +56,7 @@ void my_signal_handler(int signum) void print_message(struct mosq_config *cfg, const struct mosquitto_message *message); int mkpath(const char *path, mode_t mode); -void _fmask(char *fmask, void *obj); +void _fmask(char *fmask, void *obj, const struct mosquitto_message *message); /* File open with given mode. @@ -107,7 +107,12 @@ void my_message_file_callback(struct mosquitto *mosq, void *obj, const struct mo FILE *fptr = NULL; - _fmask(cfg->fmask, cfg); + if(cfg->format == NULL && strlen(cfg->fmask) >= 1) { + _fmask(cfg->fmask, cfg, message); + } + if(cfg->format && strlen(cfg->fmask) == 0) { /* experimental */ + _fmask(cfg->format, cfg, message); + } char *path, *prog; path = dirname(strdup(cfg->ffmask)); diff --git a/sub_client_output.c b/sub_client_output.c index 83129d7..878aafb 100644 --- a/sub_client_output.c +++ b/sub_client_output.c @@ -37,6 +37,7 @@ Contributors: #endif #include <sys/stat.h> #include <sys/types.h> +#include <fcntl.h> #ifdef __APPLE__ # include <sys/time.h> @@ -547,7 +548,7 @@ static void _setfmask(char *token, void *obj) /* Expand --fmask string options for output filename. */ /* ------------------------------------------------------------- */ -void _fmask(char *fmask, void *obj) +void _fmask(char *fmask, void *obj, const struct mosquitto_message *message) { struct mosq_config *cfg; @@ -560,20 +561,38 @@ void _fmask(char *fmask, void *obj) char *path; path = strdup(fmask); char *to = cfg->ffmask; /* limit 1000 bytes. */ + if(cfg->verbose == 1) { + printf("%s\t", path); /* if verbose (-v) is enabled */ + } - to = stpcpy(to, "/"); - for (str1 = path; ; str1 = NULL) { - token = strtok_r(str1, "/", &saveptr1); - if (token == NULL) - break; - - /* format type */ - _setfmask(token, cfg); - to = stpcpy(to, cfg->ftoken); - to = stpcpy(to, "/"); + to = stpcpy(to, "/"); /* make sure path starts with a slash */ + if(cfg->format == NULL && strlen(cfg->fmask) >= 1) { + for (str1 = path; ; str1 = NULL) { + token = strtok_r(str1, "/", &saveptr1); + if (token == NULL) + break; + + /* format type */ + _setfmask(token, cfg); + to = stpcpy(to, cfg->ftoken); + to = stpcpy(to, "/"); + } + } else { /* experimental */ + char buf[1000] = { 0 }; + fclose(stdout); + stdout = fmemopen(buf, sizeof(buf), "w"); + setbuf(stdout, NULL); + formatted_print(cfg, message); + to = stpcpy(to, buf); + int fd; + fd = open("/dev/tty", O_WRONLY); + stdout = fdopen(fd, "w"); } to[strlen(to)-1] = '\0'; + if(cfg->verbose == 1) { + printf("%s\n", cfg->ffmask); /* if verbose (-v) is enabled */ + } } |