You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

60 lines
1.5 KiB

/* Copyright 2016 Alex 'AdUser' Z (ad_user@runbox.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*/
#include "common.h"
#include "log.h"
#include "config.h"
#include "source.h"
void usage() {
fprintf(stderr, "Usage: source-test <source.conf> <init string>\n");
exit(EXIT_FAILURE);
}
int main(int argc, char *argv[]) {
f2b_config_t config;
f2b_config_section_t *section = NULL;
f2b_source_t *source = NULL;
char buf[1024] = "";
bool reset;
if (argc < 3)
usage();
memset(&config, 0x0, sizeof(config));
if (f2b_config_load(&config, argv[1], false) != true) {
f2b_log_msg(log_fatal, "can't load config");
return EXIT_FAILURE;
}
if (config.sources == NULL) {
f2b_log_msg(log_fatal, "no sources found in config");
return EXIT_FAILURE;
} else {
section = config.sources;
}
if ((source = f2b_source_create(section, argv[2], f2b_log_error_cb)) == NULL) {
f2b_log_msg(log_fatal, "can't create source '%s' with init '%s'", section->name, argv[2]);
return EXIT_FAILURE;
}
if (f2b_source_start(source) == false) {
f2b_log_msg(log_fatal, "source start error: %s", f2b_source_error(source));
exit(EXIT_FAILURE);
}
while (1) {
reset = true;
while (f2b_source_next(source, buf, sizeof(buf), reset)) {
reset = false;
puts(buf);
}
sleep(1);
}
return EXIT_SUCCESS;
}