Esempio n. 1
0
static int
_populate_values(void *data, const char *sequence)
{
    struct int_validator_data *mdata = data;
    char *tail;
    const char *it;
    int32_t *val;

    sol_vector_init(&mdata->values, sizeof(int32_t));
    it = sequence;
    do {
        val = sol_vector_append(&mdata->values);
        SOL_NULL_CHECK_GOTO(val, no_memory);

        errno = 0;
        *val = strtol(it, &tail, 10);

        if (errno) {
            SOL_WRN("Failed do convert option 'sequence' to int %s: %d", it, errno);
            return -errno;
        }
        if (it == tail) {
            SOL_WRN("Failed to convert option 'sequence' to int %s", it);
            return -EINVAL;
        }
        it = tail;
    } while (*tail != '\0');

    return 0;

no_memory:
    sol_vector_clear(&mdata->values);
    return -ENOMEM;
}
Esempio n. 2
0
static int
counter_open(struct sol_flow_node *node, void *data, const struct sol_flow_node_options *options)
{
    struct counter_data *mdata = data;

    sol_vector_init(&mdata->map, sizeof(enum state));
    return 0;
}
Esempio n. 3
0
int
process_subprocess_open(struct sol_flow_node *node, void *data, const struct sol_flow_node_options *options)
{
    struct subprocess_data *mdata = data;
    struct sol_flow_node_type_process_subprocess_options *opts =
        (struct sol_flow_node_type_process_subprocess_options *)options;

    SOL_FLOW_NODE_OPTIONS_SUB_API_CHECK(options,
        SOL_FLOW_NODE_TYPE_PROCESS_SUBPROCESS_OPTIONS_API_VERSION,
        -EINVAL);

    mdata->node = node;
    sol_vector_init(&mdata->write_data, sizeof(struct write_data));

    if (pipe2(mdata->pipes.out, O_NONBLOCK | O_CLOEXEC) < 0) {
        SOL_WRN("Failed to create out pipe");
        return -errno;
    }

    if (pipe2(mdata->pipes.in, O_NONBLOCK | O_CLOEXEC) < 0) {
        SOL_WRN("Failed to create in pipe");
        goto in_err;
    }

    if (pipe2(mdata->pipes.err, O_NONBLOCK | O_CLOEXEC) < 0) {
        SOL_WRN("Failed to create err pipe");
        goto err_err;
    }

    mdata->command = strdup(opts->command);
    SOL_NULL_CHECK_GOTO(mdata->command, flags_err);

    if (opts->start) {
        if (setup_watches(mdata) < 0)
            goto watch_err;
        mdata->fork_run = sol_platform_linux_fork_run(on_fork, on_fork_exit, mdata);
        SOL_NULL_CHECK_GOTO(mdata->fork_run, err);
    }

    return 0;

err:
    sol_fd_del(mdata->watches.in);
    sol_fd_del(mdata->watches.err);
watch_err:
    free(mdata->command);
flags_err:
    close(mdata->pipes.err[0]);
    close(mdata->pipes.err[1]);
err_err:
    close(mdata->pipes.in[0]);
    close(mdata->pipes.in[1]);
in_err:
    close(mdata->pipes.out[0]);
    close(mdata->pipes.out[1]);
    return -errno;
}
Esempio n. 4
0
int
int_generator_open(
    struct sol_flow_node *node,
    void *data,
    const struct sol_flow_node_options *options)
{
    struct int_generator_data *mdata = data;
    const struct sol_flow_node_type_test_int_generator_options *opts =
        (const struct sol_flow_node_type_test_int_generator_options *)options;
    const char *it;
    char *tail;
    int32_t *val;

    if (opts->sequence == NULL || *opts->sequence == '\0') {
        SOL_ERR("Option 'sequence' is either NULL or empty.");
        return -EINVAL;
    }
    it = opts->sequence;

    if (opts->interval.val < 0)
        SOL_WRN("Option 'interval' < 0, setting it to 0.");

    mdata->interval = opts->interval.val >= 0 ? opts->interval.val : 0;
    mdata->next_index = 0;

    sol_vector_init(&mdata->values, sizeof(int32_t));
    do {
        val = sol_vector_append(&mdata->values);
        SOL_NULL_CHECK_GOTO(val, no_memory);

        errno = 0;
        *val = strtol(it, &tail, 10);
        if (errno) {
            SOL_WRN("Failed do convert option 'sequence' to int %s: %d", it, errno);
            goto error;
        }
        if (it == tail) {
            SOL_WRN("Failed to convert option 'sequence' to int %s", it);
            errno = -EINVAL;
            goto error;
        }
        it = tail;
    } while (*tail != '\0');

    mdata->timer = sol_timeout_add(mdata->interval, timer_tick, node);
    SOL_NULL_CHECK_GOTO(mdata->timer, error);

    return 0;

no_memory:
    errno = -ENOMEM;
error:
    sol_vector_clear(&mdata->values);
    return errno;
}
inline static struct sol_vector *
_get_line(struct sol_vector *v, uint16_t pos, uint16_t elem_size)
{
    uint16_t i;

    for (i = v->len; i <= pos; i++) {
        struct sol_vector *line = sol_vector_append(v);
        sol_vector_init(line, elem_size);
    }
    return sol_vector_get(v, pos);
}
Esempio n. 6
0
static int
add_ip6_link(uint16_t idx, gnrc_ipv6_netif_t *if_ip6)
{
#if MODULE_GNRC_IPV6_NETIF
    int i;
    struct sol_network_link *link;

    link = sol_vector_append(&links);
    SOL_NULL_CHECK(link, -ENOMEM);

    sol_vector_init(&link->addrs, sizeof(struct sol_network_link_addr));

    SOL_SET_API_VERSION(link->api_version = SOL_NETWORK_LINK_API_VERSION; )
Esempio n. 7
0
int
float_validator_open(
    struct sol_flow_node *node,
    void *data,
    const struct sol_flow_node_options *options)
{
    struct float_validator_data *mdata = data;
    const struct sol_flow_node_type_test_float_validator_options *opts =
        (const struct sol_flow_node_type_test_float_validator_options *)options;
    const char *it;
    char *tail;
    double *val;

    SOL_FLOW_NODE_OPTIONS_SUB_API_CHECK(options,
        SOL_FLOW_NODE_TYPE_TEST_FLOAT_VALIDATOR_OPTIONS_API_VERSION,
        -EINVAL);
    mdata->done = false;

    if (opts->sequence == NULL || *opts->sequence == '\0') {
        SOL_ERR("Option 'sequence' is either NULL or empty.");
        return -EINVAL;
    }

    sol_vector_init(&mdata->values, sizeof(double));
    it = opts->sequence;
    do {
        val = sol_vector_append(&mdata->values);
        SOL_NULL_CHECK_GOTO(val, no_memory);

        *val = sol_util_strtod_n(it, &tail, -1, false);
        if (errno) {
            SOL_WRN("Failed do convert option 'sequence' to double %s: %d", it, errno);
            goto error;
        }
        if (it == tail) {
            SOL_WRN("Failed to convert option 'sequence' to double %s", it);
            errno = EINVAL;
            goto error;
        }
        it = tail;
    } while (*tail != '\0');

    return 0;

no_memory:
    errno = ENOMEM;
error:
    sol_vector_clear(&mdata->values);
    return -errno;
}
static struct sml_ann_bridge *
_sml_ann_bridge_new(struct fann *ann, bool trained)
{
    struct sml_ann_bridge *iann = calloc(1, sizeof(struct sml_ann_bridge));

    if (!iann) {
        sml_critical("Could not create an struct sml_ann_bridge");
        return NULL;
    }
    sol_vector_init(&iann->confidence_intervals, sizeof(Confidence_Interval));
    iann->ann = ann;
    iann->trained = trained;
    iann->last_train_error = NAN;
    return iann;
}
struct sml_fuzzy *
sml_fuzzy_bridge_new(void)
{
    struct sml_fuzzy *fuzzy = (struct sml_fuzzy *) calloc(1, sizeof(struct sml_fuzzy));
    fl::Engine *engine = NULL;

    if (!fuzzy) {
        sml_critical("Failed to create fuzzy");
        return NULL;
    }

    engine = new (std::nothrow) fl::Engine();
    if (!engine)
        goto new_error;

    if (!_create_rule_block(engine)) {
        sml_critical("Could not alloc the rule block");
        goto new_error;
    }

    engine->setName("EngineDefault");
    fuzzy->engine = engine;
    fuzzy->input_list = (struct sml_variables_list*)
        &(engine->inputVariables());
    fuzzy->output_list = (struct sml_variables_list*)
        &(engine->outputVariables());
    sol_vector_init(&fuzzy->input_terms_width, sizeof(struct terms_width));
    sol_vector_init(&fuzzy->output_terms_width, sizeof(struct terms_width));

    return fuzzy;

new_error:
    free(fuzzy);
    delete engine;
    return NULL;
}
SOL_API int
sol_network_init(void)
{
    struct sol_network_link *iface;
    struct sol_network_link_addr *addr;

    iface = sol_vector_append(&links);
    SOL_NULL_CHECK(iface, -ENOMEM);

    sol_vector_init(&iface->addrs, sizeof(struct sol_network_link_addr));

    addr = sol_vector_append(&iface->addrs);
    SOL_NULL_CHECK_GOTO(addr, addr_append_error);

    if (!get_local_address(addr))
        goto get_address_error;

    SOL_SET_API_VERSION(iface->api_version = SOL_NETWORK_LINK_API_VERSION; )
Esempio n. 11
0
int
string_generator_open(
    struct sol_flow_node *node,
    void *data,
    const struct sol_flow_node_options *options)
{
    struct string_generator_data *mdata = data;
    const struct sol_flow_node_type_test_string_generator_options *opts =
        (const struct sol_flow_node_type_test_string_generator_options *)options;

    SOL_FLOW_NODE_OPTIONS_SUB_API_CHECK(options,
        SOL_FLOW_NODE_TYPE_TEST_STRING_GENERATOR_OPTIONS_API_VERSION,
        -EINVAL);
    sol_vector_init(&mdata->values, sizeof(struct sol_str_slice));
    if (opts->sequence == NULL || *opts->sequence == '\0') {
        SOL_ERR("Option 'sequence' is either NULL or empty.");
        return -EINVAL;
    }
    mdata->sequence = strdup(opts->sequence);
    SOL_NULL_CHECK_GOTO(mdata->sequence, no_memory);

    if (opts->interval < 0)
        SOL_WRN("Option 'interval' < 0, setting it to 0.");

    mdata->interval = opts->interval >= 0 ? opts->interval : 0;
    mdata->next_index = 0;

    mdata->values = sol_str_slice_split(sol_str_slice_from_str
            (mdata->sequence), opts->separator, SIZE_MAX);

    mdata->timer = sol_timeout_add(mdata->interval, timer_tick, node);
    SOL_NULL_CHECK_GOTO(mdata->timer, error);

    return 0;

no_memory:
    errno = -ENOMEM;
error:
    sol_vector_clear(&mdata->values);
    return errno;
}
Esempio n. 12
0
SOL_API struct sol_lwm2m_bootstrap_server *
sol_lwm2m_bootstrap_server_new(uint16_t port, const char **known_clients,
    uint16_t num_sec_modes, ...)
{
    struct sol_lwm2m_bootstrap_server *server;
    struct sol_network_link_addr servaddr = { .family = SOL_NETWORK_FAMILY_INET6,
                                              .port = port };
    int r;
    struct sol_lwm2m_security_psk **known_psks = NULL, *cli_psk;
    struct sol_lwm2m_security_rpk *my_rpk = NULL;
    struct sol_blob **known_pub_keys = NULL, *cli_pub_key;
    enum sol_lwm2m_security_mode *sec_modes;
    enum sol_socket_dtls_cipher *cipher_suites;
    uint16_t i, j;
    va_list ap;

    SOL_LOG_INTERNAL_INIT_ONCE;

    SOL_NULL_CHECK(known_clients, NULL);
    SOL_INT_CHECK(num_sec_modes, == 0, NULL);

    va_start(ap, num_sec_modes);

    cipher_suites = calloc(num_sec_modes, sizeof(enum sol_socket_dtls_cipher));
    SOL_NULL_CHECK_GOTO(cipher_suites, err_va_list);

    sec_modes = calloc(num_sec_modes, sizeof(enum sol_lwm2m_security_mode));
    SOL_NULL_CHECK_GOTO(sec_modes, err_cipher_suites);

    for (i = 0; i < num_sec_modes; i++) {
        sec_modes[i] = va_arg(ap, enum sol_lwm2m_security_mode);
        SOL_EXP_CHECK_GOTO(sec_mode_is_repeated(sec_modes[i], sec_modes, i), err_sec_modes);

        switch (sec_modes[i]) {
        case SOL_LWM2M_SECURITY_MODE_PRE_SHARED_KEY:
            known_psks = va_arg(ap, struct sol_lwm2m_security_psk **);
            SOL_NULL_CHECK_GOTO(known_psks, err_sec_modes);

            cipher_suites[i] = SOL_SOCKET_DTLS_CIPHER_PSK_AES128_CCM8;
            break;
        case SOL_LWM2M_SECURITY_MODE_RAW_PUBLIC_KEY:
            my_rpk = va_arg(ap, struct sol_lwm2m_security_rpk *);
            SOL_NULL_CHECK_GOTO(my_rpk, err_sec_modes);
            known_pub_keys = va_arg(ap, struct sol_blob **);
            SOL_NULL_CHECK_GOTO(known_pub_keys, err_sec_modes);

            cipher_suites[i] = SOL_SOCKET_DTLS_CIPHER_ECDHE_ECDSA_AES128_CCM8;
            break;
        case SOL_LWM2M_SECURITY_MODE_CERTIFICATE:
            SOL_WRN("Certificate security mode is not supported yet.");
            goto err_sec_modes;
        case SOL_LWM2M_SECURITY_MODE_NO_SEC:
            SOL_WRN("Bootstrap Server MUST use DTLS.");
            goto err_sec_modes;
        default:
            SOL_WRN("Unknown DTLS Security Mode: %d", sec_modes[i]);
            goto err_sec_modes;
        }
    }

    server = calloc(1, sizeof(struct sol_lwm2m_bootstrap_server));
    SOL_NULL_CHECK_GOTO(server, err_sec_modes);

    //LWM2M Bootstrap Server MUST always use DTLS
    for (i = 0; i < num_sec_modes; i++) {
        if (sec_modes[i] == SOL_LWM2M_SECURITY_MODE_PRE_SHARED_KEY) {
            sol_vector_init(&server->known_psks, sizeof(sol_lwm2m_security_psk));

            for (j = 0; known_psks[j]; j++) {
                cli_psk = sol_vector_append(&server->known_psks);
                SOL_NULL_CHECK_GOTO(cli_psk, err_copy_keys);
                cli_psk->id = sol_blob_ref(known_psks[j]->id);
                cli_psk->key = sol_blob_ref(known_psks[j]->key);
            }
        } else if (sec_modes[i] == SOL_LWM2M_SECURITY_MODE_RAW_PUBLIC_KEY) {
            sol_ptr_vector_init(&server->known_pub_keys);

            for (j = 0; known_pub_keys[j]; j++) {
                r = sol_ptr_vector_append(&server->known_pub_keys,
                    sol_blob_ref(known_pub_keys[j]));
                SOL_INT_CHECK_GOTO(r, < 0, err_copy_keys);
            }

            server->rpk_pair.private_key = sol_blob_ref(my_rpk->private_key);
            server->rpk_pair.public_key = sol_blob_ref(my_rpk->public_key);
        }
    }
Esempio n. 13
0
void
sml_matrix_init(struct sml_matrix *m, uint16_t elem_size)
{
    sol_vector_init(&m->data, sizeof(struct sol_vector));
    m->elem_size = elem_size;
}