fixes
This commit is contained in:
parent
97e6348412
commit
433f69ed74
@ -24,12 +24,12 @@ typedef struct {
|
|||||||
t_receiverHandle receiveHandle;
|
t_receiverHandle receiveHandle;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char *influxUser;
|
const char *influxUser;
|
||||||
char *influxPass;
|
const char *influxPass;
|
||||||
char *influxServer;
|
const char *influxServer;
|
||||||
uint16_t influxPort;
|
uint16_t influxPort;
|
||||||
char *influxDatabase;
|
const char *influxDatabase;
|
||||||
char *influxMeasurement;
|
const char *influxMeasurement;
|
||||||
} t_forwarderHandle;
|
} t_forwarderHandle;
|
||||||
|
|
||||||
t_forwarderHandle forwarderHandle = {
|
t_forwarderHandle forwarderHandle = {
|
||||||
@ -51,8 +51,8 @@ int readConfig(config_t *cfg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int initReceiver(config_t *cfg, t_receiverHandle *handle) {
|
int initReceiver(config_t *cfg, t_receiverHandle *handle) {
|
||||||
devicesConfig = config_lookup(&cfg, "devices");
|
handle->devicesConfig = config_lookup(cfg, "devices");
|
||||||
if (devicesConfig == NULL) {
|
if (handle->devicesConfig == NULL) {
|
||||||
logmsg(LOG_ERR, "receiver: no devices configuration found");
|
logmsg(LOG_ERR, "receiver: no devices configuration found");
|
||||||
exit(-2);
|
exit(-2);
|
||||||
}
|
}
|
||||||
@ -77,10 +77,11 @@ int initReceiver(config_t *cfg, t_receiverHandle *handle) {
|
|||||||
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||||
servaddr.sin_port = htons(receivePort);
|
servaddr.sin_port = htons(receivePort);
|
||||||
|
|
||||||
if (-1 == bind(receiveSockFd, (const struct sockaddr *) &servaddr, sizeof(servaddr))) {
|
if (-1 == bind(handle->receiveSockFd, (const struct sockaddr *) &servaddr, sizeof(servaddr))) {
|
||||||
logmsg(LOG_ERR, "unable to bind receive: %d", errno);
|
logmsg(LOG_ERR, "unable to bind receive: %d", errno);
|
||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void deinitReceiver(t_receiverHandle *handle) {
|
void deinitReceiver(t_receiverHandle *handle) {
|
||||||
@ -146,23 +147,30 @@ int receiveAndVerifyMinuteBuffer(t_receiverHandle *handle, t_minuteBuffer *buf)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int initForwarder(config_t *cfg, t_forwarderHandle *handle) {
|
int initForwarder(config_t *cfg, t_forwarderHandle *handle) {
|
||||||
config_lookup_string(cfg, "influxUser", handle->influxUser);
|
config_lookup_string(cfg, "influxUser", &(handle->influxUser));
|
||||||
config_lookup_string(cfg, "influxPass", handle->influxPass);
|
config_lookup_string(cfg, "influxPass", &(handle->influxPass));
|
||||||
config_lookup_string(cfg, "influxServer", handle->influxServer);
|
config_lookup_string(cfg, "influxServer", &(handle->influxServer));
|
||||||
config_lookup_int(cfg, "influxPort", &(handle->influxPort));
|
config_lookup_string(cfg, "influxDatabase", &(handle->influxDatabase));
|
||||||
config_lookup_string(cfg, "influxDatabase", handle->influxDatabase);
|
config_lookup_string(cfg, "influxMeasurement", &(handle->influxMeasurement));
|
||||||
config_lookup_string(cfg, "influxMeasurement", handle->influxMeasurement);
|
|
||||||
|
int influxPort = 8086;
|
||||||
|
config_lookup_int(cfg, "influxPort", &influxPort);
|
||||||
|
if (influxPort < 1 || influxPort > 65535) {
|
||||||
|
logmsg(LOG_ERR, "illegal influx port configured");
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
handle->influxPort = influxPort;
|
||||||
|
|
||||||
if (! handle->influxServer) {
|
if (! handle->influxServer) {
|
||||||
logmsg("no influxServer configured");
|
logmsg(LOG_ERR, "no influxServer configured");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (! handle->influxDatabase) {
|
if (! handle->influxDatabase) {
|
||||||
logmsg("no influxDatabase configured");
|
logmsg(LOG_ERR, "no influxDatabase configured");
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
if (! handle->influxMeasurement) {
|
if (! handle->influxMeasurement) {
|
||||||
logmsg("no influxMeasurement configured");
|
logmsg(LOG_ERR, "no influxMeasurement configured");
|
||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,12 +205,13 @@ int main() {
|
|||||||
while (1) {
|
while (1) {
|
||||||
t_minuteBuffer buf;
|
t_minuteBuffer buf;
|
||||||
|
|
||||||
if (receiveAndVerifyMinuteBuffer(&receiveHandle &buf) < 0) {
|
if (receiveAndVerifyMinuteBuffer(&receiveHandle, &buf) < 0) {
|
||||||
logmsg(LOG_ERR, "error in receiveAndVerify");
|
logmsg(LOG_ERR, "error in receiveAndVerify");
|
||||||
} else {
|
continue;
|
||||||
if (forwardMinuteBuffer(&forwarderHandle, &buf) < 0) {
|
}
|
||||||
logmsg(LOG_ERR, "error in send");
|
|
||||||
}
|
if (forwardMinuteBuffer(&forwarderHandle, &buf) < 0) {
|
||||||
|
logmsg(LOG_ERR, "error in send");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user