mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
don't link libext against any external libraries
This commit is contained in:
parent
3c48b4f557
commit
025713a46e
17 changed files with 301 additions and 277 deletions
10
include/villas/crypt.h
Normal file
10
include/villas/crypt.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/** Calculate SHA1 hash of complete file \p f and place it into \p sha1.
|
||||
*
|
||||
* @param sha1[out] Must be SHA_DIGEST_LENGTH (20) in size.
|
||||
* @retval 0 Everything was okay.
|
||||
*/
|
||||
int sha1sum(FILE *f, unsigned char *sha1);
|
22
include/villas/json.h
Normal file
22
include/villas/json.h
Normal file
|
@ -0,0 +1,22 @@
|
|||
#pragma once
|
||||
|
||||
#ifdef WITH_JANSSON
|
||||
|
||||
#include <jansson.h>
|
||||
#include <libconfig.h>
|
||||
|
||||
#include "sample.h"
|
||||
|
||||
/* Convert a libconfig object to a libjansson object */
|
||||
json_t * config_to_json(config_setting_t *cfg);
|
||||
|
||||
int json_to_config(json_t *json, config_setting_t *parent);
|
||||
|
||||
int sample_io_json_pack(json_t **j, struct sample *s, int flags);
|
||||
|
||||
int sample_io_json_unpack(json_t *j, struct sample *s, int *flags);
|
||||
|
||||
int sample_io_json_fprint(FILE *f, struct sample *s, int flags);
|
||||
|
||||
int sample_io_json_fscan(FILE *f, struct sample *s, int *flags);
|
||||
#endif
|
|
@ -74,10 +74,3 @@ int sample_io_villas_fscan(FILE *f, struct sample *s, int *flags);
|
|||
|
||||
/* JSON format */
|
||||
|
||||
int sample_io_json_pack(json_t **j, struct sample *s, int flags);
|
||||
|
||||
int sample_io_json_unpack(json_t *j, struct sample *s, int *flags);
|
||||
|
||||
int sample_io_json_fprint(FILE *f, struct sample *s, int flags);
|
||||
|
||||
int sample_io_json_fscan(FILE *f, struct sample *s, int *flags);
|
||||
|
|
|
@ -168,15 +168,6 @@ int cpulist_parse(const char *str, cpu_set_t *set, int fail);
|
|||
*/
|
||||
char * cpulist_create(char *str, size_t len, cpu_set_t *set);
|
||||
|
||||
#ifdef WITH_JANSSON
|
||||
#include <jansson.h>
|
||||
|
||||
/* Convert a libconfig object to a libjansson object */
|
||||
json_t * config_to_json(config_setting_t *cfg);
|
||||
|
||||
#endif
|
||||
int json_to_config(json_t *json, config_setting_t *parent);
|
||||
|
||||
/** Allocate and initialize memory. */
|
||||
void * alloc(size_t bytes);
|
||||
|
||||
|
@ -239,11 +230,4 @@ void rdtsc_sleep(uint64_t nanosecs, uint64_t start);
|
|||
/** Register a exit callback for program termination (SIGINT / SIGKILL). */
|
||||
void signals_init(void (*cb)(int signal, siginfo_t *sinfo, void *ctx));
|
||||
|
||||
/** Calculate SHA1 hash of complete file \p f and place it into \p sha1.
|
||||
*
|
||||
* @param sha1[out] Must be SHA_DIGEST_LENGTH (20) in size.
|
||||
* @retval 0 Everything was okay.
|
||||
*/
|
||||
int sha1sum(FILE *f, unsigned char *sha1);
|
||||
|
||||
pid_t spawn(const char* name, char **argv);
|
||||
|
|
|
@ -13,10 +13,11 @@ LIB_SRCS = $(addprefix lib/nodes/, file.c cbuilder.c shmem.c) \
|
|||
log.c utils.c super_node.c hist.c timing.c pool.c \
|
||||
list.c queue.c queue_signalled.c memory.c advio.c web.c api.c \
|
||||
plugin.c node_type.c stats.c mapping.c sample_io.c shmem.c \
|
||||
json.c crypt.c \
|
||||
)
|
||||
|
||||
LIBEXT_SRCS = $(addprefix lib/, sample.c node.c queue.c queue_signalled.c \
|
||||
memory.c shmem.c utils.c kernel/kernel.c log.c list.c sample_io.c \
|
||||
memory.c shmem.c utils.c kernel/kernel.c log.c list.c \
|
||||
plugin.c timing.c)
|
||||
|
||||
LIB_CFLAGS = $(CFLAGS) -fPIC
|
||||
|
@ -25,7 +26,7 @@ LIB_LDLIBS = $(LDLIBS) -ldl -lrt -Wl,-soname,$(LIB_NAME).so.$(LIB_ABI_VERSION)
|
|||
|
||||
LIBEXT_CFLAGS = $(CFLAGS) -fPIC
|
||||
LIBEXT_LDFLAGS = -shared
|
||||
LIBEXT_LDLIBS = -ljansson -lcrypto -lrt -Wl,-soname,$(LIBEXT_NAME).so.$(LIBEXT_ABI_VERSION)
|
||||
LIBEXT_LDLIBS = -ldl -lrt -Wl,-soname,$(LIBEXT_NAME).so.$(LIBEXT_ABI_VERSION)
|
||||
|
||||
-include lib/hooks/Makefile.inc
|
||||
-include lib/apis/Makefile.inc
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "utils.h"
|
||||
#include "config.h"
|
||||
#include "advio.h"
|
||||
#include "crypt.h"
|
||||
|
||||
#define BAR_WIDTH 60 /**< How wide you want the progress meter to be. */
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "api.h"
|
||||
#include "utils.h"
|
||||
#include "plugin.h"
|
||||
#include "json.h"
|
||||
|
||||
static int api_config(struct api_ressource *h, json_t *args, json_t **resp, struct api_session *s)
|
||||
{
|
||||
|
@ -28,4 +29,4 @@ static struct plugin p = {
|
|||
.api.cb = api_config
|
||||
};
|
||||
|
||||
REGISTER_PLUGIN(&p)
|
||||
REGISTER_PLUGIN(&p)
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "api.h"
|
||||
#include "node.h"
|
||||
#include "utils.h"
|
||||
#include "json.h"
|
||||
|
||||
extern struct list nodes;
|
||||
|
||||
|
@ -49,4 +50,4 @@ static struct plugin p = {
|
|||
.api.cb = api_nodes
|
||||
};
|
||||
|
||||
REGISTER_PLUGIN(&p)
|
||||
REGISTER_PLUGIN(&p)
|
||||
|
|
29
lib/crypt.c
Normal file
29
lib/crypt.c
Normal file
|
@ -0,0 +1,29 @@
|
|||
#include "crypt.h"
|
||||
|
||||
#include <openssl/sha.h>
|
||||
|
||||
int sha1sum(FILE *f, unsigned char *sha1)
|
||||
{
|
||||
SHA_CTX c;
|
||||
char buf[512];
|
||||
ssize_t bytes;
|
||||
long seek;
|
||||
|
||||
seek = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
|
||||
SHA1_Init(&c);
|
||||
|
||||
bytes = fread(buf, 1, 512, f);
|
||||
while (bytes > 0) {
|
||||
SHA1_Update(&c, buf, bytes);
|
||||
bytes = fread(buf, 1, 512, f);
|
||||
}
|
||||
|
||||
SHA1_Final(sha1, &c);
|
||||
|
||||
fseek(f, seek, SEEK_SET);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
220
lib/json.c
Normal file
220
lib/json.c
Normal file
|
@ -0,0 +1,220 @@
|
|||
#include "json.h"
|
||||
|
||||
#ifdef WITH_JANSSON
|
||||
static int json_to_config_type(int type)
|
||||
{
|
||||
switch (type) {
|
||||
case JSON_OBJECT: return CONFIG_TYPE_GROUP;
|
||||
case JSON_ARRAY: return CONFIG_TYPE_LIST;
|
||||
case JSON_STRING: return CONFIG_TYPE_STRING;
|
||||
case JSON_INTEGER: return CONFIG_TYPE_INT64;
|
||||
case JSON_REAL: return CONFIG_TYPE_FLOAT;
|
||||
case JSON_TRUE:
|
||||
case JSON_FALSE:
|
||||
case JSON_NULL: return CONFIG_TYPE_BOOL;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
json_t * config_to_json(config_setting_t *cfg)
|
||||
{
|
||||
switch (config_setting_type(cfg)) {
|
||||
case CONFIG_TYPE_INT: return json_integer(config_setting_get_int(cfg));
|
||||
case CONFIG_TYPE_INT64: return json_integer(config_setting_get_int64(cfg));
|
||||
case CONFIG_TYPE_FLOAT: return json_real(config_setting_get_float(cfg));
|
||||
case CONFIG_TYPE_STRING: return json_string(config_setting_get_string(cfg));
|
||||
case CONFIG_TYPE_BOOL: return json_boolean(config_setting_get_bool(cfg));
|
||||
|
||||
case CONFIG_TYPE_ARRAY:
|
||||
case CONFIG_TYPE_LIST: {
|
||||
json_t *json = json_array();
|
||||
|
||||
for (int i = 0; i < config_setting_length(cfg); i++)
|
||||
json_array_append_new(json, config_to_json(config_setting_get_elem(cfg, i)));
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
case CONFIG_TYPE_GROUP: {
|
||||
json_t *json = json_object();
|
||||
|
||||
for (int i = 0; i < config_setting_length(cfg); i++) {
|
||||
json_object_set_new(json,
|
||||
config_setting_name(config_setting_get_elem(cfg, i)),
|
||||
config_to_json(config_setting_get_elem(cfg, i))
|
||||
);
|
||||
}
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
default:
|
||||
return json_object();
|
||||
}
|
||||
}
|
||||
|
||||
int json_to_config(json_t *json, config_setting_t *parent)
|
||||
{
|
||||
config_setting_t *cfg;
|
||||
int ret, type;
|
||||
|
||||
if (config_setting_is_root(parent)) {
|
||||
if (!json_is_object(json))
|
||||
return -1; /* The root must be an object! */
|
||||
}
|
||||
|
||||
switch (json_typeof(json)) {
|
||||
case JSON_OBJECT: {
|
||||
const char *key;
|
||||
json_t *json_value;
|
||||
|
||||
json_object_foreach(json, key, json_value) {
|
||||
type = json_to_config_type(json_typeof(json_value));
|
||||
|
||||
cfg = config_setting_add(parent, key, type);
|
||||
ret = json_to_config(json_value, cfg);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case JSON_ARRAY: {
|
||||
size_t i;
|
||||
json_t *json_value;
|
||||
|
||||
json_array_foreach(json, i, json_value) {
|
||||
type = json_to_config_type(json_typeof(json_value));
|
||||
|
||||
cfg = config_setting_add(parent, NULL, type);
|
||||
ret = json_to_config(json_value, cfg);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case JSON_STRING:
|
||||
config_setting_set_string(parent, json_string_value(json));
|
||||
break;
|
||||
|
||||
case JSON_INTEGER:
|
||||
config_setting_set_int64(parent, json_integer_value(json));
|
||||
break;
|
||||
|
||||
case JSON_REAL:
|
||||
config_setting_set_float(parent, json_real_value(json));
|
||||
break;
|
||||
|
||||
case JSON_TRUE:
|
||||
case JSON_FALSE:
|
||||
case JSON_NULL:
|
||||
config_setting_set_bool(parent, json_is_true(json));
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sample_io_json_pack(json_t **j, struct sample *s, int flags)
|
||||
{
|
||||
json_error_t err;
|
||||
json_t *json_data = json_array();
|
||||
|
||||
for (int i = 0; i < s->length; i++) {
|
||||
json_t *json_value = sample_get_data_format(s, i)
|
||||
? json_integer(s->data[i].i)
|
||||
: json_real(s->data[i].f);
|
||||
|
||||
json_array_append(json_data, json_value);
|
||||
}
|
||||
|
||||
*j = json_pack_ex(&err, 0, "{ s: { s: [ I, I ], s: [ I, I ], s: [ I, I ] }, s: I, s: o }",
|
||||
"ts",
|
||||
"origin", s->ts.origin.tv_sec, s->ts.origin.tv_nsec,
|
||||
"received", s->ts.received.tv_sec, s->ts.received.tv_nsec,
|
||||
"sent", s->ts.sent.tv_sec, s->ts.sent.tv_nsec,
|
||||
"sequence", s->sequence,
|
||||
"data", json_data);
|
||||
|
||||
if (!*j)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sample_io_json_unpack(json_t *j, struct sample *s, int *flags)
|
||||
{
|
||||
int ret, i;
|
||||
json_t *json_data, *json_value;
|
||||
|
||||
ret = json_unpack(j, "{ s: { s: [ I, I ], s: [ I, I ], s: [ I, I ] }, s: I, s: o }",
|
||||
"ts",
|
||||
"origin", &s->ts.origin.tv_sec, &s->ts.origin.tv_nsec,
|
||||
"received", &s->ts.received.tv_sec, &s->ts.received.tv_nsec,
|
||||
"sent", &s->ts.sent.tv_sec, &s->ts.sent.tv_nsec,
|
||||
"sequence", &s->sequence,
|
||||
"data", &json_data);
|
||||
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
s->length = 0;
|
||||
|
||||
json_array_foreach(json_data, i, json_value) {
|
||||
switch (json_typeof(json_value)) {
|
||||
case JSON_REAL:
|
||||
s->data[i].f = json_real_value(json_value);
|
||||
sample_set_data_format(s, i, SAMPLE_DATA_FORMAT_FLOAT);
|
||||
break;
|
||||
|
||||
case JSON_INTEGER:
|
||||
s->data[i].f = json_integer_value(json_value);
|
||||
sample_set_data_format(s, i, SAMPLE_DATA_FORMAT_INT);
|
||||
break;
|
||||
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
s->length++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sample_io_json_fprint(FILE *f, struct sample *s, int flags)
|
||||
{
|
||||
int ret;
|
||||
json_t *json;
|
||||
|
||||
ret = sample_io_json_pack(&json, s, flags);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = json_dumpf(json, f, 0);
|
||||
|
||||
json_decref(json);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int sample_io_json_fscan(FILE *f, struct sample *s, int *flags)
|
||||
{
|
||||
int ret;
|
||||
json_t *json;
|
||||
json_error_t err;
|
||||
|
||||
json = json_loadf(f, JSON_DISABLE_EOF_CHECK, &err);
|
||||
if (!json)
|
||||
return -1;
|
||||
|
||||
ret = sample_io_json_unpack(json, s, flags);
|
||||
|
||||
json_decref(json);
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
102
lib/sample_io.c
102
lib/sample_io.c
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <ctype.h>
|
||||
|
||||
#include "json.h"
|
||||
#include "sample.h"
|
||||
#include "sample_io.h"
|
||||
#include "timing.h"
|
||||
|
@ -179,104 +180,3 @@ skip: if (fgets(line, sizeof(line), f) == NULL)
|
|||
return sample_io_villas_scan(line, s, fl);
|
||||
}
|
||||
|
||||
#ifdef WITH_JANSSON
|
||||
int sample_io_json_pack(json_t **j, struct sample *s, int flags)
|
||||
{
|
||||
json_error_t err;
|
||||
json_t *json_data = json_array();
|
||||
|
||||
for (int i = 0; i < s->length; i++) {
|
||||
json_t *json_value = sample_get_data_format(s, i)
|
||||
? json_integer(s->data[i].i)
|
||||
: json_real(s->data[i].f);
|
||||
|
||||
json_array_append(json_data, json_value);
|
||||
}
|
||||
|
||||
*j = json_pack_ex(&err, 0, "{ s: { s: [ I, I ], s: [ I, I ], s: [ I, I ] }, s: I, s: o }",
|
||||
"ts",
|
||||
"origin", s->ts.origin.tv_sec, s->ts.origin.tv_nsec,
|
||||
"received", s->ts.received.tv_sec, s->ts.received.tv_nsec,
|
||||
"sent", s->ts.sent.tv_sec, s->ts.sent.tv_nsec,
|
||||
"sequence", s->sequence,
|
||||
"data", json_data);
|
||||
|
||||
if (!*j)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sample_io_json_unpack(json_t *j, struct sample *s, int *flags)
|
||||
{
|
||||
int ret, i;
|
||||
json_t *json_data, *json_value;
|
||||
|
||||
ret = json_unpack(j, "{ s: { s: [ I, I ], s: [ I, I ], s: [ I, I ] }, s: I, s: o }",
|
||||
"ts",
|
||||
"origin", &s->ts.origin.tv_sec, &s->ts.origin.tv_nsec,
|
||||
"received", &s->ts.received.tv_sec, &s->ts.received.tv_nsec,
|
||||
"sent", &s->ts.sent.tv_sec, &s->ts.sent.tv_nsec,
|
||||
"sequence", &s->sequence,
|
||||
"data", &json_data);
|
||||
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
s->length = 0;
|
||||
|
||||
json_array_foreach(json_data, i, json_value) {
|
||||
switch (json_typeof(json_value)) {
|
||||
case JSON_REAL:
|
||||
s->data[i].f = json_real_value(json_value);
|
||||
sample_set_data_format(s, i, SAMPLE_DATA_FORMAT_FLOAT);
|
||||
break;
|
||||
|
||||
case JSON_INTEGER:
|
||||
s->data[i].f = json_integer_value(json_value);
|
||||
sample_set_data_format(s, i, SAMPLE_DATA_FORMAT_INT);
|
||||
break;
|
||||
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
s->length++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sample_io_json_fprint(FILE *f, struct sample *s, int flags)
|
||||
{
|
||||
int ret;
|
||||
json_t *json;
|
||||
|
||||
ret = sample_io_json_pack(&json, s, flags);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = json_dumpf(json, f, 0);
|
||||
|
||||
json_decref(json);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int sample_io_json_fscan(FILE *f, struct sample *s, int *flags)
|
||||
{
|
||||
int ret;
|
||||
json_t *json;
|
||||
json_error_t err;
|
||||
|
||||
json = json_loadf(f, JSON_DISABLE_EOF_CHECK, &err);
|
||||
if (!json)
|
||||
return -1;
|
||||
|
||||
ret = sample_io_json_unpack(json, s, flags);
|
||||
|
||||
json_decref(json);
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
|
@ -22,6 +22,7 @@
|
|||
#include "plugin.h"
|
||||
#include "memory.h"
|
||||
#include "config.h"
|
||||
#include "json.h"
|
||||
|
||||
#include "kernel/rt.h"
|
||||
|
||||
|
|
143
lib/utils.c
143
lib/utils.c
|
@ -221,124 +221,6 @@ char *cpulist_create(char *str, size_t len, cpu_set_t *set)
|
|||
return str;
|
||||
}
|
||||
|
||||
#ifdef WITH_JANSSON
|
||||
static int json_to_config_type(int type)
|
||||
{
|
||||
switch (type) {
|
||||
case JSON_OBJECT: return CONFIG_TYPE_GROUP;
|
||||
case JSON_ARRAY: return CONFIG_TYPE_LIST;
|
||||
case JSON_STRING: return CONFIG_TYPE_STRING;
|
||||
case JSON_INTEGER: return CONFIG_TYPE_INT64;
|
||||
case JSON_REAL: return CONFIG_TYPE_FLOAT;
|
||||
case JSON_TRUE:
|
||||
case JSON_FALSE:
|
||||
case JSON_NULL: return CONFIG_TYPE_BOOL;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
json_t * config_to_json(config_setting_t *cfg)
|
||||
{
|
||||
switch (config_setting_type(cfg)) {
|
||||
case CONFIG_TYPE_INT: return json_integer(config_setting_get_int(cfg));
|
||||
case CONFIG_TYPE_INT64: return json_integer(config_setting_get_int64(cfg));
|
||||
case CONFIG_TYPE_FLOAT: return json_real(config_setting_get_float(cfg));
|
||||
case CONFIG_TYPE_STRING: return json_string(config_setting_get_string(cfg));
|
||||
case CONFIG_TYPE_BOOL: return json_boolean(config_setting_get_bool(cfg));
|
||||
|
||||
case CONFIG_TYPE_ARRAY:
|
||||
case CONFIG_TYPE_LIST: {
|
||||
json_t *json = json_array();
|
||||
|
||||
for (int i = 0; i < config_setting_length(cfg); i++)
|
||||
json_array_append_new(json, config_to_json(config_setting_get_elem(cfg, i)));
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
case CONFIG_TYPE_GROUP: {
|
||||
json_t *json = json_object();
|
||||
|
||||
for (int i = 0; i < config_setting_length(cfg); i++) {
|
||||
json_object_set_new(json,
|
||||
config_setting_name(config_setting_get_elem(cfg, i)),
|
||||
config_to_json(config_setting_get_elem(cfg, i))
|
||||
);
|
||||
}
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
default:
|
||||
return json_object();
|
||||
}
|
||||
}
|
||||
|
||||
int json_to_config(json_t *json, config_setting_t *parent)
|
||||
{
|
||||
config_setting_t *cfg;
|
||||
int ret, type;
|
||||
|
||||
if (config_setting_is_root(parent)) {
|
||||
if (!json_is_object(json))
|
||||
return -1; /* The root must be an object! */
|
||||
}
|
||||
|
||||
switch (json_typeof(json)) {
|
||||
case JSON_OBJECT: {
|
||||
const char *key;
|
||||
json_t *json_value;
|
||||
|
||||
json_object_foreach(json, key, json_value) {
|
||||
type = json_to_config_type(json_typeof(json_value));
|
||||
|
||||
cfg = config_setting_add(parent, key, type);
|
||||
ret = json_to_config(json_value, cfg);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case JSON_ARRAY: {
|
||||
size_t i;
|
||||
json_t *json_value;
|
||||
|
||||
json_array_foreach(json, i, json_value) {
|
||||
type = json_to_config_type(json_typeof(json_value));
|
||||
|
||||
cfg = config_setting_add(parent, NULL, type);
|
||||
ret = json_to_config(json_value, cfg);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case JSON_STRING:
|
||||
config_setting_set_string(parent, json_string_value(json));
|
||||
break;
|
||||
|
||||
case JSON_INTEGER:
|
||||
config_setting_set_int64(parent, json_integer_value(json));
|
||||
break;
|
||||
|
||||
case JSON_REAL:
|
||||
config_setting_set_float(parent, json_real_value(json));
|
||||
break;
|
||||
|
||||
case JSON_TRUE:
|
||||
case JSON_FALSE:
|
||||
case JSON_NULL:
|
||||
config_setting_set_bool(parent, json_is_true(json));
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
void * alloc(size_t bytes)
|
||||
{
|
||||
void *p = malloc(bytes);
|
||||
|
@ -418,31 +300,6 @@ void signals_init(void (*cb)(int signal, siginfo_t *sinfo, void *ctx))
|
|||
sigaction(SIGCHLD, &sa_chld, NULL);
|
||||
}
|
||||
|
||||
int sha1sum(FILE *f, unsigned char *sha1)
|
||||
{
|
||||
SHA_CTX c;
|
||||
char buf[512];
|
||||
ssize_t bytes;
|
||||
long seek;
|
||||
|
||||
seek = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
|
||||
SHA1_Init(&c);
|
||||
|
||||
bytes = fread(buf, 1, 512, f);
|
||||
while (bytes > 0) {
|
||||
SHA1_Update(&c, buf, bytes);
|
||||
bytes = fread(buf, 1, 512, f);
|
||||
}
|
||||
|
||||
SHA1_Final(sha1, &c);
|
||||
|
||||
fseek(f, seek, SEEK_SET);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
pid_t
|
||||
spawn(const char* name, char **argv) {
|
||||
pid_t pid = fork();
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
#include "pool.h"
|
||||
#include "queue_signalled.h"
|
||||
#include "sample.h"
|
||||
#include "sample_io.h"
|
||||
#include "shmem.h"
|
||||
#include "utils.h"
|
||||
|
||||
|
@ -56,8 +55,10 @@ int main(int argc, char* argv[])
|
|||
int avail = sample_alloc(&shared->pool, outsmps, r);
|
||||
if (avail < r)
|
||||
warn("pool underrun (%d/%d)\n", avail, r);
|
||||
for (int i = 0; i < r; i++)
|
||||
sample_io_villas_fprint(stdout, insmps[i], SAMPLE_IO_ALL);
|
||||
for (int i = 0; i < r; i++) {
|
||||
printf("got sample: seq %d recv %ld.%ld\n", insmps[i]->sequence,
|
||||
insmps[i]->ts.received.tv_sec, insmps[i]->ts.received.tv_nsec);
|
||||
}
|
||||
for (int i = 0; i < avail; i++) {
|
||||
outsmps[i]->sequence = insmps[i]->sequence;
|
||||
outsmps[i]->ts = insmps[i]->ts;
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <libconfig.h>
|
||||
|
||||
#include "utils.h"
|
||||
#include "json.h"
|
||||
|
||||
const char *cfg_example = "test : \n"
|
||||
"{\n"
|
||||
|
@ -96,4 +97,4 @@ Test(utils, json_to_config)
|
|||
cr_assert_str_eq(str, cfg_example);
|
||||
|
||||
json_decref(json);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <criterion/criterion.h>
|
||||
|
||||
#include "crypt.h"
|
||||
#include "utils.h"
|
||||
|
||||
/* Simple normality test for 1,2,3s intervals */
|
||||
|
@ -151,4 +152,4 @@ Test(utils, sha1sum)
|
|||
cr_assert_arr_eq(hash, expected, SHA_DIGEST_LENGTH);
|
||||
|
||||
fclose(f);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <jansson.h>
|
||||
#include <libconfig.h>
|
||||
|
||||
#include <villas/json.h>
|
||||
#include <villas/utils.h>
|
||||
|
||||
void usage()
|
||||
|
@ -48,4 +49,4 @@ int main(int argc, char *argv[])
|
|||
config_destroy(&cfg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue