diff --git a/src/source-test.c b/src/source-test.c index 42c17ff..898ca32 100644 --- a/src/source-test.c +++ b/src/source-test.c @@ -19,6 +19,7 @@ int main(int argc, char *argv[]) { f2b_config_section_t *section = NULL; f2b_source_t *source = NULL; char buf[1024] = ""; + uint32_t stag; bool reset; if (argc < 3) @@ -54,9 +55,9 @@ int main(int argc, char *argv[]) { while (1) { reset = true; - while (f2b_source_next(source, buf, sizeof(buf), reset)) { + while ((stag = f2b_source_next(source, buf, sizeof(buf), reset)) > 0) { reset = false; - puts(buf); + printf("stag: %08X, line: %s\n", stag, buf); } sleep(1); } diff --git a/src/source.c b/src/source.c index e0402da..8a74bff 100644 --- a/src/source.c +++ b/src/source.c @@ -122,7 +122,7 @@ f2b_source_destroy(f2b_source_t *source) { free(source); } -bool +uint32_t f2b_source_next(f2b_source_t *source, char *buf, size_t bufsize, bool reset) { assert(source != NULL); return source->next(source->cfg, buf, bufsize, reset); diff --git a/src/source.h b/src/source.h index a084dfa..d08e4e5 100644 --- a/src/source.h +++ b/src/source.h @@ -29,7 +29,7 @@ typedef struct f2b_source_t { /** dlsym pointer to handler of @a start command */ bool (*start) (void *cfg); /** dlsym pointer to handler of @a next command */ - bool (*next) (void *cfg, char *buf, size_t bufsize, bool reset); + uint32_t (*next) (void *cfg, char *buf, size_t bufsize, bool reset); /** dlsym pointer to handler of @a stats command */ bool (*stats) (void *cfg, char *buf, size_t bufsize); /** dlsym pointer to handler of @a stop command */ @@ -74,9 +74,9 @@ bool f2b_source_start (f2b_source_t *s); * @param buf Buffer for data * @param bufsize Size of buffer for data * @param reset Reset source internals - * @returns false of no data available, true otherwise with setting @a buf + * @returns >0 on new data available with filling @a buf and 0 on no data/error */ -bool f2b_source_next (f2b_source_t *s, char *buf, size_t bufsize, bool reset); +uint32_t f2b_source_next (f2b_source_t *s, char *buf, size_t bufsize, bool reset); /** * @brief Stop given source * @param s Pointer to source struct diff --git a/src/sources/files.c b/src/sources/files.c index 52ccbff..0490f91 100644 --- a/src/sources/files.c +++ b/src/sources/files.c @@ -196,7 +196,7 @@ stop(cfg_t *cfg) { return true; } -bool +uint32_t next(cfg_t *cfg, char *buf, size_t bufsize, bool reset) { assert(cfg != NULL); assert(buf != NULL); @@ -213,10 +213,10 @@ next(cfg_t *cfg, char *buf, size_t bufsize, bool reset) { continue; } if (file_getline(file, buf, bufsize)) - return true; + return file->stag; } - return false; + return 0; } bool diff --git a/src/sources/portknock.c b/src/sources/portknock.c index 33d15b9..06d01f0 100644 --- a/src/sources/portknock.c +++ b/src/sources/portknock.c @@ -163,7 +163,7 @@ stop(cfg_t *cfg) { return true; } -bool +uint32_t next(cfg_t *cfg, char *buf, size_t bufsize, bool reset) { struct sockaddr_storage addr; socklen_t addrlen; @@ -191,16 +191,16 @@ next(cfg_t *cfg, char *buf, size_t bufsize, bool reset) { close(sock); if (addr.ss_family == AF_INET) { inet_ntop(AF_INET, &(((struct sockaddr_in *) &addr)->sin_addr), buf, bufsize); - return true; + return port->stag; } if (addr.ss_family == AF_INET6) { inet_ntop(AF_INET6, &(((struct sockaddr_in6 *) &addr)->sin6_addr), buf, bufsize); - return true; + return port->stag; } cfg->logcb(error, "can't convert sockaddr to string: unknown AF"); } - return false; + return 0; } bool diff --git a/src/sources/redis.c b/src/sources/redis.c index 49d7215..09b754e 100644 --- a/src/sources/redis.c +++ b/src/sources/redis.c @@ -168,9 +168,9 @@ stop(cfg_t *cfg) { return true; } -bool +uint32_t next(cfg_t *cfg, char *buf, size_t bufsize, bool reset) { - bool gotit = false; + uint32_t res = 0; assert(cfg != NULL); assert(buf != NULL); assert(bufsize > 0); @@ -180,11 +180,11 @@ next(cfg_t *cfg, char *buf, size_t bufsize, bool reset) { if (!cfg->conn || cfg->conn->err) redis_connect(cfg); if (!cfg->conn) - return false; /* reconnect failure */ + return 0; /* reconnect failure */ if (cfg->conn->err) { log_msg(cfg, error, "connection error: %s", cfg->conn->errstr); - return false; + return 0; } redisReply *reply = NULL; @@ -194,7 +194,7 @@ next(cfg_t *cfg, char *buf, size_t bufsize, bool reset) { if (strcmp(reply->element[0]->str, "message") == 0 || strcmp(reply->element[1]->str, cfg->hash) == 0) { strlcpy(buf, reply->element[2]->str, bufsize); - gotit = true; + res = (uint32_t) -1; } else { log_msg(cfg, error, "wrong redis message type: %s", reply->element[0]->str); } @@ -208,7 +208,7 @@ next(cfg_t *cfg, char *buf, size_t bufsize, bool reset) { log_msg(cfg, error, "can't get reply from server %s: %s", cfg->host, cfg->conn->errstr); } - return gotit; + return res; } bool diff --git a/src/sources/source.h b/src/sources/source.h index 806addc..84b5a2e 100644 --- a/src/sources/source.h +++ b/src/sources/source.h @@ -77,7 +77,7 @@ extern bool start(cfg_t *cfg); * @param reset Reset internals to start of list * @returns false if no new data available, or true otherwise with filling @a buf */ -extern bool next(cfg_t *cfg, char *buf, size_t bufsize, bool reset); +extern uint32_t next(cfg_t *cfg, char *buf, size_t bufsize, bool reset); /** * @brief Get statistics for source * @param cfg Module handler