示例#1
0
static void line_callback(pa_ioline *line, const char *s, void *userdata) {
    pa_strbuf *buf;
    pa_cli *c = userdata;
    char *p;

    pa_assert(line);
    pa_assert(c);

    if (!s) {
        pa_log_debug("CLI got EOF from user.");

        if (c->eof_callback)
            c->eof_callback(c, c->userdata);

        return;
    }

    /* Magic command, like they had in AT Hayes Modems! Those were the good days! */
    if (pa_streq(s, "/"))
        s = c->last_line;
    else if (s[0]) {
        pa_xfree(c->last_line);
        c->last_line = pa_xstrdup(s);
    }

    pa_assert_se(buf = pa_strbuf_new());
    c->defer_kill++;
    if (pa_streq(s, "hello")) {
        pa_strbuf_printf(buf, "Welcome to PulseAudio %s! "
            "Use \"help\" for usage information.\n", PACKAGE_VERSION);
        c->interactive = true;
    }
    else
        pa_cli_command_execute_line(c->core, s, buf, &c->fail);
    c->defer_kill--;
    pa_ioline_puts(line, p = pa_strbuf_to_string_free(buf));
    pa_xfree(p);

    if (c->kill_requested) {
        if (c->eof_callback)
            c->eof_callback(c, c->userdata);
    } else if (c->interactive)
        pa_ioline_puts(line, PROMPT);
}
示例#2
0
static int rtsp_exec(pa_rtsp_client *c, const char *cmd,
                        const char *content_type, const char *content,
                        int expect_response,
                        pa_headerlist *headers) {
    pa_strbuf *buf;
    char *hdrs;

    pa_assert(c);
    pa_assert(c->url);
    pa_assert(cmd);
    pa_assert(c->ioline);

    pa_log_debug("Sending command: %s", cmd);

    buf = pa_strbuf_new();
    pa_strbuf_printf(buf, "%s %s RTSP/1.0\r\nCSeq: %d\r\n", cmd, c->url, ++c->cseq);
    if (c->session)
        pa_strbuf_printf(buf, "Session: %s\r\n", c->session);

    /* Add the headers */
    if (headers) {
        hdrs = pa_headerlist_to_string(headers);
        pa_strbuf_puts(buf, hdrs);
        pa_xfree(hdrs);
    }

    if (content_type && content) {
        pa_strbuf_printf(buf, "Content-Type: %s\r\nContent-Length: %d\r\n",
          content_type, (int)strlen(content));
    }

    pa_strbuf_printf(buf, "User-Agent: %s\r\n", c->useragent);

    if (c->headers) {
        hdrs = pa_headerlist_to_string(c->headers);
        pa_strbuf_puts(buf, hdrs);
        pa_xfree(hdrs);
    }

    pa_strbuf_puts(buf, "\r\n");

    if (content_type && content) {
        pa_strbuf_puts(buf, content);
    }

    /* Our packet is created... now we can send it :) */
    hdrs = pa_strbuf_to_string_free(buf);
    /*pa_log_debug("Submitting request:");
    pa_log_debug(hdrs);*/
    pa_ioline_puts(c->ioline, hdrs);
    pa_xfree(hdrs);
    /* The command is sent we can configure the rtsp client structure to handle a new answer */
    c->waiting = 1;
    return 0;
}
示例#3
0
static void line_callback(pa_ioline *line, const char *s, void *userdata) {
    pa_strbuf *buf;
    pa_cli *c = userdata;
    char *p;

    pa_assert(line);
    pa_assert(c);

    if (!s) {
        pa_log_debug("CLI got EOF from user.");

        if (c->eof_callback)
            c->eof_callback(c, c->userdata);

        return;
    }

    /* Magic command, like they had in AT Hayes Modems! Those were the good days! */
    if (pa_streq(s, "/"))
        s = c->last_line;
    else if (s[0]) {
        pa_xfree(c->last_line);
        c->last_line = pa_xstrdup(s);
    }

    pa_assert_se(buf = pa_strbuf_new());
    c->defer_kill++;
    pa_cli_command_execute_line(c->core, s, buf, &c->fail);
    c->defer_kill--;
    pa_ioline_puts(line, p = pa_strbuf_tostring_free(buf));
    pa_xfree(p);

    if (c->kill_requested) {
        if (c->eof_callback)
            c->eof_callback(c, c->userdata);
    } else
        pa_ioline_puts(line, PROMPT);
}
示例#4
0
pa_cli* pa_cli_new(pa_core *core, pa_iochannel *io, pa_module *m) {
    char cname[256];
    pa_cli *c;
    pa_client_new_data data;
    pa_client *client;

    pa_assert(io);

    pa_iochannel_socket_peer_to_string(io, cname, sizeof(cname));

    pa_client_new_data_init(&data);
    data.driver = __FILE__;
    data.module = m;
    pa_proplist_sets(data.proplist, PA_PROP_APPLICATION_NAME, cname);
    client = pa_client_new(core, &data);
    pa_client_new_data_done(&data);

    if (!client)
        return NULL;

    c = pa_xnew(pa_cli, 1);
    c->core = core;
    c->client = client;
    pa_assert_se(c->line = pa_ioline_new(io));

    c->userdata = NULL;
    c->eof_callback = NULL;

    c->client->kill = client_kill;
    c->client->userdata = c;

    pa_ioline_set_callback(c->line, line_callback, c);
    pa_ioline_puts(c->line, "Welcome to PulseAudio! Use \"help\" for usage information.\n"PROMPT);

    c->fail = c->kill_requested = FALSE;
    c->defer_kill = 0;

    c->last_line = NULL;

    return c;
}