Exemplo n.º 1
0
struct vlc_http_msg *vlc_http_msg_get_initial(struct vlc_http_stream *s)
{
    struct vlc_http_msg *m = vlc_http_stream_read_headers(s);
    if (m == NULL)
        vlc_http_stream_close(s, false);
    return m;
}
Exemplo n.º 2
0
struct vlc_http_msg *vlc_http_msg_iterate(struct vlc_http_msg *m)
{
    struct vlc_http_msg *next = vlc_http_stream_read_headers(m->payload);

    m->payload = NULL;
    vlc_http_msg_destroy(m);
    return next;
}
Exemplo n.º 3
0
struct vlc_http_msg *vlc_http_msg_get_initial(struct vlc_http_stream *s)
{
    struct vlc_http_msg *m = vlc_http_stream_read_headers(s);
    if (m == NULL) {
        vlc_http_stream_close(s, false);
        /* LVP added */
        //fprintf(stderr, "LVP msg_get_initial vlc_http_stream_close: called\n");
    }
    return m;
}
Exemplo n.º 4
0
struct vlc_http_msg *vlc_http_msg_iterate(struct vlc_http_msg *m)
{
    struct vlc_http_msg *next = vlc_http_stream_read_headers(m->payload);

    m->payload = NULL;
    vlc_http_msg_destroy(m);

    /* LVP added */
    //fprintf(stderr, "LVP msg_destroy inside of msg_iterate\n");

    return next;
}
Exemplo n.º 5
0
struct vlc_http_msg *vlc_https_request(struct vlc_http_mgr *mgr,
                                       const char *host, unsigned port,
                                       const struct vlc_http_msg *req)
{
    const char *str;
    char *end;

    assert(mgr == NULL);
    assert(!strcmp(host, "www.example.com"));
    assert(port == 8443);

    str = vlc_http_msg_get_method(req);
    assert(!strcmp(str, "GET"));
    str = vlc_http_msg_get_scheme(req);
    assert(!strcmp(str, "https"));
    str = vlc_http_msg_get_authority(req);
    assert(!strcmp(str, "www.example.com:8443"));
    str = vlc_http_msg_get_path(req);
    assert(!strcmp(str, "/dir/file.ext?a=b"));
    str = vlc_http_msg_get_agent(req);
    assert(!strcmp(str, ua));
    str = vlc_http_msg_get_header(req, "Referer");
    assert(str == NULL);
    str = vlc_http_msg_get_header(req, "Accept");
    assert(str == NULL || strstr(str, "*/*") != NULL);
    str = vlc_http_msg_get_header(req, "Accept-Language");
    assert(str == NULL || strstr(str, "*") != NULL);

    str = vlc_http_msg_get_header(req, "Range");
    assert(str != NULL && !strncmp(str, "bytes=", 6)
        && strtoul(str + 6, &end, 10) == offset && *end == '-');

    str = vlc_http_msg_get_header(req, "If-Match");
    if (offset != 0)
        assert(str != NULL && !strcmp(str, "\"foobar42\""));
    else
        assert(str == NULL || strcmp(str, "*") || strcmp(str, "\"foobar42\""));

    return vlc_http_stream_read_headers(&stream);
}
Exemplo n.º 6
0
int main(void)
{
    struct vlc_http_stream *s;
    struct vlc_http_msg *m;
    struct block_t *b;

    /* Dummy */
    conn_create();
    conn_destroy();

    /* Test rejected connection */
    conn_create();
    conn_shutdown(SHUT_RD);
    s = stream_open();
    assert(s == NULL);
    conn_destroy();

    /* Test rejected stream */
    conn_create();
    s = stream_open();
    assert(s != NULL);
    conn_shutdown(SHUT_WR);

    m = vlc_http_stream_read_headers(s);
    assert(m == NULL);
    b = vlc_http_stream_read(s);
    assert(b == NULL);
    m = vlc_http_stream_read_headers(s);
    assert(m == NULL);
    b = vlc_http_stream_read(s);
    assert(b == NULL);
    m = vlc_http_msg_get_initial(s);
    assert(m == NULL);

    s = stream_open();
    assert(s == NULL);
    conn_destroy();

    /* Test garbage */
    conn_create();
    s = stream_open();
    assert(s != NULL);
    conn_send("Go away!\r\n\r\n");
    conn_shutdown(SHUT_WR);

    m = vlc_http_stream_read_headers(s);
    assert(m == NULL);
    b = vlc_http_stream_read(s);
    assert(b == NULL);
    conn_destroy();
    vlc_http_stream_close(s, false);

    /* Test HTTP/1.0 stream */
    conn_create();
    s = stream_open();
    assert(s != NULL);
    conn_send("HTTP/1.0 200 OK\r\n\r\n");
    m = vlc_http_msg_get_initial(s);
    assert(m != NULL);

    conn_send("Hello world!");
    conn_shutdown(SHUT_WR);
    b = vlc_http_msg_read(m);
    assert(b != NULL);
    assert(b->i_buffer == 12);
    assert(!memcmp(b->p_buffer, "Hello world!", 12));
    block_Release(b);
    b = vlc_http_msg_read(m);
    assert(b == NULL);
    vlc_http_msg_destroy(m);
    conn_destroy();

    /* Test HTTP/1.1 with closed connection */
    conn_create();
    s = stream_open();
    assert(s != NULL);
    conn_send("HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n");
    m = vlc_http_msg_get_initial(s);
    assert(m != NULL);

    conn_send("Hello again!");
    conn_shutdown(SHUT_WR);
    b = vlc_http_msg_read(m);
    assert(b != NULL);
    assert(b->i_buffer == 12);
    assert(!memcmp(b->p_buffer, "Hello again!", 12));
    block_Release(b);
    b = vlc_http_msg_read(m);
    assert(b == NULL);
    vlc_http_msg_destroy(m);
    conn_destroy();

    /* Test HTTP/1.1 with chunked transfer encoding */
    conn_create();
    s = stream_open();
    assert(s != NULL);
    conn_send("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n"
              "Content-Length: 1000000\r\n\r\n"); /* length must be ignored */
    m = vlc_http_msg_get_initial(s);
    assert(m != NULL);

    conn_send("C\r\nHello there!\r\n0\r\n\r\n");
    b = vlc_http_msg_read(m);
    assert(b != NULL);
    assert(b->i_buffer == 12);
    assert(!memcmp(b->p_buffer, "Hello there!", 12));
    block_Release(b);
    conn_destroy(); /* test connection release before closing stream */
    b = vlc_http_msg_read(m);
    assert(b == NULL);
    vlc_http_msg_destroy(m);

    /* Test HTTP/1.1 with content length */
    conn_create();
    s = stream_open();
    assert(s != NULL);
    conn_send("HTTP/1.1 200 OK\r\nContent-Length: 8\r\n\r\n");
    m = vlc_http_msg_get_initial(s);
    assert(m != NULL);

    conn_send("Bye bye!");
    b = vlc_http_msg_read(m);
    assert(b != NULL);
    assert(b->i_buffer == 8);
    assert(!memcmp(b->p_buffer, "Bye bye!", 8));
    block_Release(b);
    b = vlc_http_msg_read(m);
    assert(b == NULL);
    vlc_http_msg_destroy(m);
    conn_destroy();

    return 0;
}
Exemplo n.º 7
0
int main(void)
{
    struct vlc_http_stream *s, *s2;
    struct vlc_http_msg *m;
    struct block_t *b;
    uint_fast32_t sid = -1; /* Second guessed stream IDs :-/ */

    conn_create();
    conn_destroy();

    conn_create();
    conn_send(vlc_h2_frame_ping(42));
    conn_expect(PING);

    /* Test rejected stream */
    sid += 2;
    s = stream_open();
    assert(s != NULL);
    conn_expect(HEADERS);
    conn_send(vlc_h2_frame_rst_stream(sid, VLC_H2_REFUSED_STREAM));
    m = vlc_http_stream_read_headers(s);
    assert(m == NULL);
    b = vlc_http_stream_read(s);
    assert(b == NULL);
    vlc_http_stream_close(s, false);
    conn_expect(RST_STREAM);

    /* Test accepted stream */
    sid += 2;
    s = stream_open();
    assert(s != NULL);
    stream_reply(sid, false);
    m = vlc_http_msg_get_initial(s);
    assert(m != NULL);
    vlc_http_msg_destroy(m);

    stream_data(3, "Hello ", false); /* late data */
    stream_data(3, "world!", true);

    conn_expect(HEADERS);
    conn_expect(RST_STREAM);
    conn_expect(RST_STREAM);
    conn_expect(RST_STREAM);

    /* Test continuation then accepted stream */
    sid += 2;
    s = stream_open();
    assert(s != NULL);
    stream_continuation(sid);
    m = vlc_http_msg_get_initial(s);
    assert(m != NULL);
    assert(vlc_http_msg_get_status(m) == 100);
    stream_reply(sid, false);
    m = vlc_http_msg_iterate(m);
    assert(m != NULL);
    stream_data(sid, "Hello ", false);
    stream_data(sid, "world!", true);
    stream_data(sid, "Stray message", false); /* data after EOS */
    b = vlc_http_msg_read(m);
    assert(b != NULL);
    block_Release(b);
    b = vlc_http_msg_read(m);
    assert(b != NULL);
    block_Release(b);
    b = vlc_http_msg_read(m);
    assert(b == NULL);
    vlc_http_msg_destroy(m);

    conn_expect(HEADERS);
    conn_expect(RST_STREAM);
    conn_expect(RST_STREAM);

    /* Test accepted stream after continuation */
    sid += 2;
    s = stream_open();
    assert(s != NULL);
    stream_continuation(sid);
    stream_reply(sid, true);
    sid += 2;
    s2 = stream_open(); /* second stream to enforce test timing/ordering */
    assert(s2 != NULL);
    stream_reply(sid, true);
    m = vlc_http_msg_get_initial(s2);
    assert(m != NULL);
    vlc_http_msg_destroy(m);
    m = vlc_http_msg_get_initial(s);
    assert(m != NULL);
    assert(vlc_http_msg_get_status(m) == 200);
    b = vlc_http_msg_read(m);
    assert(b == NULL);
    vlc_http_msg_destroy(m);

    conn_expect(HEADERS);
    conn_expect(HEADERS);
    conn_expect(RST_STREAM);
    conn_expect(RST_STREAM);

    /* Test nonexistent stream reset */
    conn_send(vlc_h2_frame_rst_stream(sid + 100, VLC_H2_REFUSED_STREAM));

    /* Test multiple streams in non-LIFO order */
    sid += 2;
    s = stream_open();
    assert(s != NULL);
    sid += 2;
    s2 = stream_open();
    assert(s2 != NULL);
    stream_reply(sid, false);
    stream_reply(sid - 2, true);
    stream_data(sid, "Discarded", false); /* not read data */
    m = vlc_http_msg_get_initial(s);
    assert(m != NULL);
    vlc_http_msg_destroy(m);
    m = vlc_http_msg_get_initial(s2);
    assert(m != NULL);
    vlc_http_msg_destroy(m);

    conn_expect(HEADERS);
    conn_expect(HEADERS);
    conn_expect(RST_STREAM);
    conn_expect(RST_STREAM);
    /* might or might not seen one or two extra RST_STREAM now */

    /* Test graceful connection termination */
    sid += 2;
    s = stream_open();
    assert(s != NULL);
    conn_send(vlc_h2_frame_goaway(sid - 2, VLC_H2_NO_ERROR));
    m = vlc_http_stream_read_headers(s);
    assert(m == NULL);

    /* Test stream after connection shut down */
    assert(stream_open() == NULL);

    /* Test releasing connection before stream */
    conn_destroy();
    vlc_http_stream_close(s, false);

    return 0;
}