Beispiel #1
0
int
byte_validator_process(
    struct sol_flow_node *node,
    void *data,
    uint16_t port,
    uint16_t conn_id,
    const struct sol_flow_packet *packet)
{
    struct byte_validator_data *mdata = data;
    unsigned char *op;
    int r;
    unsigned char val;
    bool match;

    if (mdata->done) {
        sol_flow_send_error_packet(node, ECANCELED,
            "Input stream already deviated from expected data, ignoring packets.");
        return 0;
    }
    r = sol_flow_packet_get_byte(packet, &val);
    SOL_INT_CHECK(r, < 0, r);
    op = sol_vector_get(&mdata->values, mdata->next_index);
    match = val == *op;
    mdata->next_index++;

    if (mdata->next_index == mdata->values.len || !match) {
        sol_flow_send_boolean_packet(node,
            SOL_FLOW_NODE_TYPE_TEST_INT_VALIDATOR__OUT__OUT, match);
        mdata->done = true;
    }
    return 0;
}
Beispiel #2
0
static int
two_port_process(struct sol_flow_node *node, void *data, uint16_t port_in, uint16_t port_out, const struct sol_flow_packet *packet, int (*func)(unsigned char, unsigned char))
{
    struct bitwise_data *mdata = data;
    int r;
    unsigned char in_value;
    unsigned char out_value;

    r = sol_flow_packet_get_byte(packet, &in_value);
    SOL_INT_CHECK(r, < 0, r);

    if (port_in) {
        mdata->in1 = in_value;
        mdata->in1_init = true;
    } else {
        mdata->in0 = in_value;
        mdata->in0_init = true;
    }

    if (!(mdata->in0_init && mdata->in1_init))
        return 0;

    out_value = func(mdata->in0, mdata->in1);

    return sol_flow_send_byte_packet(node, port_out, out_value);
}
Beispiel #3
0
static int
validate_shift(const struct sol_flow_packet *packet)
{
    unsigned char in;
    int r;

    r = sol_flow_packet_get_byte(packet, &in);
    SOL_INT_CHECK(r, < 0, r);
    if (in > (CHAR_BIT - 1))
        return -EINVAL;
    return 0;
}
Beispiel #4
0
static int
byte_writer_process(struct sol_flow_node *node, void *data, uint16_t port, uint16_t conn_id, const struct sol_flow_packet *packet)
{
    struct unix_socket_data *mdata = data;
    uint8_t val;
    int r;

    r = sol_flow_packet_get_byte(packet, &val);
    SOL_INT_CHECK(r, < 0, r);

    return unix_socket_write(mdata->un_socket, &val, sizeof(val));
}
Beispiel #5
0
static int
not_process(struct sol_flow_node *node, void *data, uint16_t port, uint16_t conn_id, const struct sol_flow_packet *packet)
{
    int r;
    unsigned char in_value;
    unsigned char out_value;

    r = sol_flow_packet_get_byte(packet, &in_value);
    SOL_INT_CHECK(r, < 0, r);

    out_value = ~in_value;
    return sol_flow_send_byte_packet(node, SOL_FLOW_NODE_TYPE_BYTE_BITWISE_NOT__OUT__OUT, out_value);
}
Beispiel #6
0
static int
segments_set(struct sol_flow_node *node, void *data, uint16_t port, uint16_t conn_id, const struct sol_flow_packet *packet)
{
    int r;
    unsigned char in_value;

    r = sol_flow_packet_get_byte(packet, &in_value);
    SOL_INT_CHECK(r, < 0, r);

    r = write_byte(data, node, in_value);
    SOL_INT_CHECK(r, < 0, r);

    return 0;
}
Beispiel #7
0
static int
byte_filter_process(struct sol_flow_node *node, void *data, uint16_t port, uint16_t conn_id, const struct  sol_flow_packet *packet)
{
    unsigned char value;
    int r;
    struct byte_filter_data *mdata = data;

    r = sol_flow_packet_get_byte(packet, &value);
    SOL_INT_CHECK(r, < 0, r);

    if (value >= mdata->min && value <= mdata->max ) {
        return sol_flow_send_byte_packet(node, SOL_FLOW_NODE_TYPE_BYTE_FILTER__OUT__OUT, value);
    }
    return 0;
}
Beispiel #8
0
static int
segments_set(struct sol_flow_node *node, void *data, uint16_t port, uint16_t conn_id, const struct sol_flow_packet *packet)
{
    unsigned char byte;
    int r;
    struct segments_ctl_data *mdata = sol_flow_node_get_private_data(node);

    if (mdata->needs_clear) {
        _clear(node);
        mdata->needs_clear = false;
    }

    r = sol_flow_packet_get_byte(packet, &byte);
    SOL_INT_CHECK(r, < 0, r);
    _write_byte(node, _convert_order(byte));

    return 0;
}
Beispiel #9
0
static int
byte_writer_process(struct sol_flow_node *node, void *data, uint16_t port, uint16_t conn_id, const struct sol_flow_packet *packet)
{
    struct ipm_data *mdata = data;
    unsigned char in_value;
    struct sol_blob *blob;
    int r;

    r = sol_flow_packet_get_byte(packet, &in_value);
    SOL_INT_CHECK(r, < 0, r);

    blob = SOL_BLOB_NEW_DUP(in_value);
    SOL_NULL_CHECK(blob, -ENOMEM);

    SEND_BLOB(blob, mdata->id, node);

    return 0;
}
Beispiel #10
0
static int
shift_left_process(struct sol_flow_node *node, void *data, uint16_t port, uint16_t conn_id, const struct sol_flow_packet *packet)
{
    if (port == SOL_FLOW_NODE_TYPE_BYTE_SHIFT_LEFT__IN__SHIFT) {
        int r = validate_shift(packet);

        if (r < 0) {
            int err;
            unsigned char in;

            err = sol_flow_packet_get_byte(packet, &in);
            SOL_INT_CHECK(err, < 0, err);

            sol_flow_send_error_packet(node, -r,
                "Invalid values for a shift left operation: operation: %d. "
                "Maximum is %d", in, (CHAR_BIT - 1));
            return 0;
        }
Beispiel #11
0
static void
inspector_show_packet_value(const struct sol_flow_packet *packet)
{
    const struct sol_flow_packet_type *type = sol_flow_packet_get_type(packet);

    if (type == SOL_FLOW_PACKET_TYPE_EMPTY) {
        fputs("<empty>", stdout);
        return;
    } else if (type == SOL_FLOW_PACKET_TYPE_ANY) {
        fputs("<any>", stdout);
        return;
    } else if (type == SOL_FLOW_PACKET_TYPE_ERROR) {
        int code;
        const char *msg;
        if (sol_flow_packet_get_error(packet, &code, &msg) == 0) {
            fprintf(stdout, "<error:%d \"%s\">", code, msg ? msg : "");
            return;
        }
    } else if (type == SOL_FLOW_PACKET_TYPE_BOOL) {
        bool v;
        if (sol_flow_packet_get_bool(packet, &v) == 0) {
            fprintf(stdout, "<%s>", v ? "true" : "false");
            return;
        }
    } else if (type == SOL_FLOW_PACKET_TYPE_BYTE) {
        unsigned char v;
        if (sol_flow_packet_get_byte(packet, &v) == 0) {
            fprintf(stdout, "<%#x>", v);
            return;
        }
    } else if (type == SOL_FLOW_PACKET_TYPE_IRANGE) {
        struct sol_irange v;
        if (sol_flow_packet_get_irange(packet, &v) == 0) {
            fprintf(stdout, "<val:%d|min:%d|max:%d|step:%d>",
                    v.val, v.min, v.max, v.step);
            return;
        }
    } else if (type == SOL_FLOW_PACKET_TYPE_DRANGE) {
        struct sol_drange v;
        if (sol_flow_packet_get_drange(packet, &v) == 0) {
            fprintf(stdout, "<val:%g|min:%g|max:%g|step:%g>",
                    v.val, v.min, v.max, v.step);
            return;
        }
    } else if (type == SOL_FLOW_PACKET_TYPE_STRING) {
        const char *v;
        if (sol_flow_packet_get_string(packet, &v) == 0) {
            fprintf(stdout, "<\"%s\">", v);
            return;
        }
    } else if (type == SOL_FLOW_PACKET_TYPE_BLOB) {
        struct sol_blob *v;
        if (sol_flow_packet_get_blob(packet, &v) == 0) {
            fprintf(stdout, "<mem=%p|size=%zd|refcnt=%hu|type=%p|parent=%p>",
                    v->mem, v->size, v->refcnt, v->type, v->parent);
            return;
        }
    } else if (type == SOL_FLOW_PACKET_TYPE_JSON_OBJECT) {
        struct sol_blob *v;
        if (sol_flow_packet_get_json_object(packet, &v) == 0) {
            fprintf(stdout, "<%.*s>",
                    SOL_STR_SLICE_PRINT(sol_str_slice_from_blob(v)));
            return;
        }
    } else if (type == SOL_FLOW_PACKET_TYPE_JSON_ARRAY) {
        struct sol_blob *v;
        if (sol_flow_packet_get_json_array(packet, &v) == 0) {
            fprintf(stdout, "<%.*s>",
                    SOL_STR_SLICE_PRINT(sol_str_slice_from_blob(v)));
            return;
        }
    } else if (type == SOL_FLOW_PACKET_TYPE_RGB) {
        struct sol_rgb v;
        if (sol_flow_packet_get_rgb(packet, &v) == 0) {
            fprintf(stdout,
                    "<red=%u|green=%u|blue=%u"
                    "|red_max=%u|green_max=%u|blue_max=%u>",
                    v.red, v.green, v.blue,
                    v.red_max, v.green_max, v.blue_max);
            return;
        }
    } else if (type == SOL_FLOW_PACKET_TYPE_DIRECTION_VECTOR) {
        struct sol_direction_vector v;
        if (sol_flow_packet_get_direction_vector(packet, &v) == 0) {
            fprintf(stdout,
                    "<x=%g|y=%g|z=%g|min=%g|max=%g>",
                    v.x, v.y, v.z, v.min, v.max);
            return;
        }
    } else if (type == SOL_FLOW_PACKET_TYPE_LOCATION) {
        struct sol_location v;
        if (sol_flow_packet_get_location(packet, &v) == 0) {
            fprintf(stdout, "<lat=%g|lon=%g|alt=%g>", v.lat, v.lon, v.alt);
            return;
        }
    } else if (type == SOL_FLOW_PACKET_TYPE_TIMESTAMP) {
        struct timespec v;
        if (sol_flow_packet_get_timestamp(packet, &v) == 0) {
            struct tm cur_time;
            char buf[32];
            tzset();
            if (gmtime_r(&v.tv_sec, &cur_time)) {
                if (strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%SZ",
                             &cur_time) > 0) {
                    fprintf(stdout, "<%s>", buf);
                    return;
                }
            }
        }
    } else if (type == SOL_FLOW_PACKET_TYPE_HTTP_RESPONSE) {
        int code;
        const char *url, *content_type;
        const struct sol_blob *content;
        struct sol_vector headers, cookies;
        if (sol_flow_packet_get_http_response(packet, &code, &url,
                                              &content_type, &content, &cookies, &headers) == 0) {
            fprintf(stdout, "<response_code:%d|content type:%s|url:%s|",
                    code, content_type, url);
            fprintf(stdout, "|cookies: {");
            inpector_print_key_value_array(&cookies);
            fprintf(stdout, "}|headers:{");
            inpector_print_key_value_array(&headers);
            fprintf(stdout,
                    "}|content:{mem=%p|size=%zd|refcnt=%hu|type=%p|parent=%p}>",
                    content->mem, content->size, content->refcnt,
                    content->type, content->parent);
        }
        return;
    }

    fputs("<?>", stdout);
}