int pa__init(pa_module*m) {
    pa_iochannel *io;
    pa_modargs *ma;
    int32_t fd = -1;
    int r = -1;
    pa_native_options *options = NULL;

    pa_assert(m);

    if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
        pa_log("Failed to parse module arguments.");
        goto finish;
    }

    if (pa_modargs_get_value_s32(ma, "fd", &fd) < 0 || fd < 0) {
        pa_log("Invalid file descriptor.");
        goto finish;
    }

    m->userdata = pa_native_protocol_get(m->core);

    io = pa_iochannel_new(m->core->mainloop, fd, fd);

    options = pa_native_options_new();
    options->module = m;
    options->auth_anonymous = true;

    pa_native_protocol_connect(m->userdata, io, options);

    r = 0;

finish:
    if (ma)
        pa_modargs_free(ma);

    if (options)
        pa_native_options_unref(options);

    return r;
}
Пример #2
0
void pa__done(pa_module*m) {
    struct userdata *u;

    pa_assert(m);

    if (!(u = m->userdata))
        return;

#if defined(USE_PROTOCOL_SIMPLE)
    if (u->simple_protocol) {
        pa_simple_protocol_disconnect(u->simple_protocol, u->module);
        pa_simple_protocol_unref(u->simple_protocol);
    }
    if (u->simple_options)
        pa_simple_options_unref(u->simple_options);
#elif defined(USE_PROTOCOL_CLI)
    if (u->cli_protocol) {
        pa_cli_protocol_disconnect(u->cli_protocol, u->module);
        pa_cli_protocol_unref(u->cli_protocol);
    }
#elif defined(USE_PROTOCOL_HTTP)
    if (u->http_protocol) {
        char t[256];

#if defined(USE_TCP_SOCKETS)
        if (u->socket_server_ipv4)
            if (pa_socket_server_get_address(u->socket_server_ipv4, t, sizeof(t)))
                pa_http_protocol_remove_server_string(u->http_protocol, t);

#ifdef HAVE_IPV6
        if (u->socket_server_ipv6)
            if (pa_socket_server_get_address(u->socket_server_ipv6, t, sizeof(t)))
                pa_http_protocol_remove_server_string(u->http_protocol, t);
#endif /* HAVE_IPV6 */
#else /* USE_TCP_SOCKETS */
        if (u->socket_server_unix)
            if (pa_socket_server_get_address(u->socket_server_unix, t, sizeof(t)))
                pa_http_protocol_remove_server_string(u->http_protocol, t);
#endif /* USE_PROTOCOL_HTTP */

        pa_http_protocol_disconnect(u->http_protocol, u->module);
        pa_http_protocol_unref(u->http_protocol);
    }
#elif defined(USE_PROTOCOL_NATIVE)
    if (u->native_protocol) {

        char t[256];

#  if defined(USE_TCP_SOCKETS)
        if (u->socket_server_ipv4)
            if (pa_socket_server_get_address(u->socket_server_ipv4, t, sizeof(t)))
                pa_native_protocol_remove_server_string(u->native_protocol, t);

#    ifdef HAVE_IPV6
        if (u->socket_server_ipv6)
            if (pa_socket_server_get_address(u->socket_server_ipv6, t, sizeof(t)))
                pa_native_protocol_remove_server_string(u->native_protocol, t);
#    endif
#  else
        if (u->socket_server_unix)
            if (pa_socket_server_get_address(u->socket_server_unix, t, sizeof(t)))
                pa_native_protocol_remove_server_string(u->native_protocol, t);
#  endif

        pa_native_protocol_disconnect(u->native_protocol, u->module);
        pa_native_protocol_unref(u->native_protocol);
    }
    if (u->native_options)
        pa_native_options_unref(u->native_options);
#else
    if (u->esound_protocol) {
        pa_esound_protocol_disconnect(u->esound_protocol, u->module);
        pa_esound_protocol_unref(u->esound_protocol);
    }
    if (u->esound_options)
        pa_esound_options_unref(u->esound_options);
#endif

#if defined(USE_TCP_SOCKETS)
    if (u->socket_server_ipv4)
        pa_socket_server_unref(u->socket_server_ipv4);
#  ifdef HAVE_IPV6
    if (u->socket_server_ipv6)
        pa_socket_server_unref(u->socket_server_ipv6);
#  endif
#else
    if (u->socket_server_unix)
        pa_socket_server_unref(u->socket_server_unix);

# if defined(USE_PROTOCOL_ESOUND) && !defined(USE_PER_USER_ESOUND_SOCKET)
    if (u->socket_path) {
        char *p = pa_parent_dir(u->socket_path);
        rmdir(p);
        pa_xfree(p);
    }
# endif

    pa_xfree(u->socket_path);
#endif

    pa_xfree(u);
}