示例#1
0
static char *direntry_get_path (direntry_t *de)
{
    string_buffer_t *path = string_buffer_new();


    direntry_get_path_inner(de, path);


    return string_buffer_commit(path);
}
示例#2
0
const char* ShaderNode_compile(ShaderNode _sn)
{
#ifndef USE_RECOMPILE
	string_buffer_new(STRING_BUFFER_SIZE);
	EString tmp = _compile_links(_sn);
	sbuf_printf("%s( %s );", _sn->node_name, tmp);
	EString_delete(tmp);
	return EString_new(get_string_buffer);
#else
	return _recompile(_sn);
#endif
}
static void receive_advert(
    const int socket,
    struct sockaddr *sa,
    const socklen_t socklen_in,
    void * const addr_src,
    const size_t host_len,
    new_indexnode_event_t packet_received_cb,
    void *packet_received_ctxt
)
{
    char host[host_len];
    char buf[1024];
    char *port, *fs2protocol, *id;
    string_buffer_t *buffer = string_buffer_new();
    int recv_rc;
    socklen_t socklen;


    /* For UDP it is specified that recv*() will return the whole packet in one
     * go. It is not correct to keep calling recv*() to get more of the message;
     * this isn't a stream. If the message is too big for the buffer it's simply
     * truncated. Usually silently, but by passing in MSG_TRUNC one gets the
     * real length of the message back, even if it has to be truncated. This
     * allows us to assert that our buffer is big enough. We've had to take a
     * guess because advert packets are variable length, but it's an assertion
     * because 1024 really should be enough */

    errno = 0;
    recv_rc = recvfrom(socket, buf, sizeof(buf) - 1, MSG_TRUNC, sa, &socklen);
    assert(recv_rc <= (int)sizeof(buf) - 1);

    if (recv_rc >= 0)
    {
        assert(socklen == socklen_in);
        buf[recv_rc] = '\0';
        string_buffer_append(buffer, strdup(buf));

        if (!parse_advert_packet(string_buffer_peek(buffer), &port, &fs2protocol, &id) &&
            inet_ntop(AF_INET, addr_src, host, sizeof(host) - 1))
        {
            packet_received_cb(packet_received_ctxt, strdup(host), port, fs2protocol, id);
        }
    }
    else
    {
        trace_warn("failed to recvfrom() and indexnode advert packet: %s\n", strerror(errno));
    }


    string_buffer_delete(buffer);
}
示例#4
0
size_t read_line(int socket, STRING_BUFFER_PTR *string_buffer_ptr) {

    // If input is invalid then just error out.
    //
    if (NULL == string_buffer_ptr){
        return 0;
    }

    // We are getting a new "line" so wack the old one if it exists.
    //
    if (*string_buffer_ptr){
        string_buffer_reset(*string_buffer_ptr);
    }
    else{
        *string_buffer_ptr = string_buffer_new();
    }

    // Now we read in the data:
    //
    char c = '\0';

    while (c != '\n') {
        ssize_t n = recv(socket, &c, 1, 0);

        if (n > 0) {
            if (c == '\r') {
                n = recv(socket, &c, 1, MSG_PEEK);

                if ((n > 0) && (c == '\n')) {
                    recv(socket, &c, 1, 0);
                }
                else {
                    c = '\n';
                }
            }

            string_buffer_append_char(*string_buffer_ptr, c);
        }
        else {
            c = '\n';
        }
    }

    return string_buffer_c_string_length(*string_buffer_ptr);
}
示例#5
0
dino_http_method parse_method_url(dino_http_data_t *http) {
    // Should not happen:
    //
    if (NULL == http) {
        return http_invalid;
    }

    // Read in the data:
    //
    STRING_BUFFER_PTR string_buffer_ptr = NULL;

    if (0 == read_line(http->socket, &string_buffer_ptr)) {
        string_buffer_delete(string_buffer_ptr, true);
        return http_invalid;
    }

    // Obtain the method
    //
    char method[32];
    memory_clear(method, sizeof(method));
    int offset = 0;

    const char *line = string_buffer_c_string(string_buffer_ptr);

    for (int i = 0; !isspace(line[i]) && (i < sizeof(method)); i++) {
        method[i] = line[i];
        offset++;
    }

    http->request.method = map_string_to_http_method(method);

    if (http_invalid == http->request.method) {
        string_buffer_delete(string_buffer_ptr, true);
        return http_invalid;
    }

    // Fetch the URL
    //
    const char *query = line + offset;
    STRING_BUFFER_PTR buffer_url = string_buffer_new();

    // Skip over the ' 's and the tabs
    //
    while (*query != '\0' && (*query == ' ' || *query == '\t')) {
        ++query;
    }

    while (*query != '\0' && *query != '?' && *query != ' ' && *query != '\t') {
        string_buffer_append_char(buffer_url, *query);
        query++;
    }

    http->request.url = buffer_url;

    if (*query == '?') {
        // Move off of '?'
        //
        query++;

        offset = 0;

        STRING_BUFFER_PTR buffer_params = string_buffer_new();

        while (!isspace(*query) && *query != 0) {
            string_buffer_append_char(buffer_params, *query);
            offset++;
            query++;
        }

        // Parse the URL parameters
        //
        char *break_token = NULL;

        for (char *param = strtok_r(string_buffer_c_string(buffer_params), "&", &break_token);
             param;
             param = strtok_r(NULL, "&", &break_token))
        {
            char *break_token_2 = NULL;
            char *key = strtok_r(param, "=", &break_token_2);
            char *value = strtok_r(NULL, "=", &break_token_2);

            dino_strmap_add(http->request.params_map, key, value);
        }

        string_buffer_delete(buffer_params, true);
    }

    string_buffer_delete(string_buffer_ptr, true);
    return http->request.method;
}