diff --git a/bin/logger/src/api.c b/bin/logger/src/api.c index 3826f83..032ab62 100644 --- a/bin/logger/src/api.c +++ b/bin/logger/src/api.c @@ -141,6 +141,7 @@ void api_parse_exception(CURLresponse response, char *err, size_t n) { json_tok = json_tokener_new(); json_obj = json_tokener_parse_ex(json_tok, response.data, response.size); + if (json_tok->err == json_tokener_success) { json_obj = json_object_object_get(json_obj, "exception"); diff --git a/bin/logger/src/configuration.c b/bin/logger/src/configuration.c index 7d05f9a..89784dc 100644 --- a/bin/logger/src/configuration.c +++ b/bin/logger/src/configuration.c @@ -123,17 +123,15 @@ void parse_configuration(char *filename, list_t *assocs, options_t *options) { } assoc_t * parse_meter(struct json_object *jso) { - assoc_t *assoc = malloc(sizeof(assoc_t)); list_t json_channels; const meter_type_t *type = NULL; const char *connection = NULL; const char *protocol = NULL; int enabled = TRUE; + int interval = 0; - list_init(&assoc->channels); list_init(&json_channels); - assoc->interval = 0; json_object_object_foreach(jso, key, value) { if (strcmp(key, "enabled") == 0 && check_type(key, value, json_type_boolean)) { @@ -154,7 +152,7 @@ assoc_t * parse_meter(struct json_object *jso) { connection = json_object_get_string(value); } else if (strcmp(key, "interval") == 0 && check_type(key, value, json_type_int)) { - assoc->interval = json_object_get_int(value); + interval = json_object_get_int(value); } else if (strcmp(key, "channels") == 0 && check_type(key, value, json_type_array)) { int len = json_object_array_length(value); @@ -181,12 +179,16 @@ assoc_t * parse_meter(struct json_object *jso) { } else if (enabled == TRUE) { /* init meter */ + assoc_t *assoc = malloc(sizeof(assoc_t)); + assoc->interval = interval; + + list_init(&assoc->channels); meter_init(&assoc->meter, type, connection); print(5, "New meter initialized (protocol=%s, connection=%s, interval=%d)", assoc, protocol, connection, assoc->interval); /* init channels */ - foreach(json_channels, it) { - struct json_object *jso = (struct json_object *) it->data; + struct json_object *jso; + while ((jso = list_pop(&json_channels)) != NULL) { channel_t *ch = parse_channel(jso); if (ch != NULL) { diff --git a/src/obis.c b/src/obis.c index 72adfa8..2ba3892 100644 --- a/src/obis.c +++ b/src/obis.c @@ -141,7 +141,7 @@ int obis_compare(obis_id_t a, obis_id_t b) { return 1; } } - + return 0; /* equal */ } diff --git a/src/sml.c b/src/sml.c index 8f068fe..ca7b513 100644 --- a/src/sml.c +++ b/src/sml.c @@ -134,15 +134,16 @@ int meter_sml_open_socket(const char *node, const char *service) { struct addrinfo *ais; int fd, res; - getaddrinfo(node, service, NULL, &ais); - memcpy(&sin, ais->ai_addr, ais->ai_addrlen); - fd = socket(PF_INET, SOCK_STREAM, 0); if (fd < 0) { fprintf(stderr, "error: socket(): %s\n", strerror(errno)); return -1; } + getaddrinfo(node, service, NULL, &ais); + memcpy(&sin, ais->ai_addr, ais->ai_addrlen); + freeaddrinfo(ais); + res = connect(fd, (struct sockaddr *) &sin, sizeof(sin)); if (res < 0) { fprintf(stderr, "error: connect(%s, %s): %s\n", node, service, strerror(errno));