int pa__init(pa_module*m) { struct userdata *u; pa_modargs *ma = NULL; char *hn, *un; int error; if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { pa_log("Failed to parse module arguments."); goto fail; } m->userdata = u = pa_xnew(struct userdata, 1); u->core = m->core; u->module = m; u->native = pa_native_protocol_get(u->core); u->avahi_poll = pa_avahi_poll_new(m->core->mainloop); u->services = pa_hashmap_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func); u->sink_new_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_PUT], PA_HOOK_LATE, (pa_hook_cb_t) device_new_or_changed_cb, u); u->sink_changed_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_PROPLIST_CHANGED], PA_HOOK_LATE, (pa_hook_cb_t) device_new_or_changed_cb, u); u->sink_unlink_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_UNLINK], PA_HOOK_LATE, (pa_hook_cb_t) device_unlink_cb, u); u->source_new_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_PUT], PA_HOOK_LATE, (pa_hook_cb_t) device_new_or_changed_cb, u); u->source_changed_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_PROPLIST_CHANGED], PA_HOOK_LATE, (pa_hook_cb_t) device_new_or_changed_cb, u); u->source_unlink_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_UNLINK], PA_HOOK_LATE, (pa_hook_cb_t) device_unlink_cb, u); u->main_entry_group = NULL; un = pa_get_user_name_malloc(); hn = pa_get_host_name_malloc(); u->service_name = pa_truncate_utf8(pa_sprintf_malloc("%s@%s", un, hn), AVAHI_LABEL_MAX-1); pa_xfree(un); pa_xfree(hn); if (!(u->client = avahi_client_new(u->avahi_poll, AVAHI_CLIENT_NO_FAIL, client_callback, u, &error))) { pa_log("avahi_client_new() failed: %s", avahi_strerror(error)); goto fail; } pa_modargs_free(ma); return 0; fail: pa__done(m); if (ma) pa_modargs_free(ma); return -1; }
int pa__init(pa_module*m) { struct userdata *u; pa_modargs *ma = NULL; char *hn, *un; if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { pa_log("Failed to parse module arguments."); goto fail; } m->userdata = u = pa_xnew0(struct userdata, 1); u->core = m->core; u->module = m; u->native = pa_native_protocol_get(u->core); u->services = pa_hashmap_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func); u->sink_new_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_PUT], PA_HOOK_LATE, (pa_hook_cb_t) device_new_or_changed_cb, u); u->sink_changed_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_PROPLIST_CHANGED], PA_HOOK_LATE, (pa_hook_cb_t) device_new_or_changed_cb, u); u->sink_unlink_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_UNLINK], PA_HOOK_LATE, (pa_hook_cb_t) device_unlink_cb, u); u->source_new_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_PUT], PA_HOOK_LATE, (pa_hook_cb_t) device_new_or_changed_cb, u); u->source_changed_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_PROPLIST_CHANGED], PA_HOOK_LATE, (pa_hook_cb_t) device_new_or_changed_cb, u); u->source_unlink_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SOURCE_UNLINK], PA_HOOK_LATE, (pa_hook_cb_t) device_unlink_cb, u); un = pa_get_user_name_malloc(); hn = pa_get_host_name_malloc(); u->service_name = pa_truncate_utf8(pa_sprintf_malloc("%s@%s", un, hn), kDNSServiceMaxDomainName-1); pa_xfree(un); pa_xfree(hn); publish_all_services(u); pa_modargs_free(ma); return 0; fail: pa__done(m); if (ma) pa_modargs_free(ma); return -1; }
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; }
int pa__init(pa_module*m) { pa_modargs *ma = NULL; struct userdata *u = NULL; #if defined(USE_TCP_SOCKETS) uint32_t port = IPV4_PORT; pa_bool_t port_fallback = TRUE; const char *listen_on; #else int r; #endif #if defined(USE_PROTOCOL_NATIVE) || defined(USE_PROTOCOL_HTTP) char t[256]; #endif pa_assert(m); if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { pa_log("Failed to parse module arguments"); goto fail; } m->userdata = u = pa_xnew0(struct userdata, 1); u->module = m; #if defined(USE_PROTOCOL_SIMPLE) u->simple_protocol = pa_simple_protocol_get(m->core); u->simple_options = pa_simple_options_new(); if (pa_simple_options_parse(u->simple_options, m->core, ma) < 0) goto fail; u->simple_options->module = m; #elif defined(USE_PROTOCOL_CLI) u->cli_protocol = pa_cli_protocol_get(m->core); #elif defined(USE_PROTOCOL_HTTP) u->http_protocol = pa_http_protocol_get(m->core); #elif defined(USE_PROTOCOL_NATIVE) u->native_protocol = pa_native_protocol_get(m->core); u->native_options = pa_native_options_new(); if (pa_native_options_parse(u->native_options, m->core, ma) < 0) goto fail; u->native_options->module = m; #else u->esound_protocol = pa_esound_protocol_get(m->core); u->esound_options = pa_esound_options_new(); if (pa_esound_options_parse(u->esound_options, m->core, ma) < 0) goto fail; u->esound_options->module = m; #endif #if defined(USE_TCP_SOCKETS) if (pa_in_system_mode() || pa_modargs_get_value(ma, "port", NULL)) port_fallback = FALSE; if (pa_modargs_get_value_u32(ma, "port", &port) < 0 || port < 1 || port > 0xFFFF) { pa_log("port= expects a numerical argument between 1 and 65535."); goto fail; } listen_on = pa_modargs_get_value(ma, "listen", NULL); if (listen_on) { # ifdef HAVE_IPV6 u->socket_server_ipv6 = pa_socket_server_new_ipv6_string(m->core->mainloop, listen_on, (uint16_t) port, port_fallback, TCPWRAP_SERVICE); # endif u->socket_server_ipv4 = pa_socket_server_new_ipv4_string(m->core->mainloop, listen_on, (uint16_t) port, port_fallback, TCPWRAP_SERVICE); } else { # ifdef HAVE_IPV6 u->socket_server_ipv6 = pa_socket_server_new_ipv6_any(m->core->mainloop, (uint16_t) port, port_fallback, TCPWRAP_SERVICE); # endif u->socket_server_ipv4 = pa_socket_server_new_ipv4_any(m->core->mainloop, (uint16_t) port, port_fallback, TCPWRAP_SERVICE); } # ifdef HAVE_IPV6 if (!u->socket_server_ipv4 && !u->socket_server_ipv6) # else if (!u->socket_server_ipv4) # endif goto fail; if (u->socket_server_ipv4) pa_socket_server_set_callback(u->socket_server_ipv4, socket_server_on_connection_cb, u); # ifdef HAVE_IPV6 if (u->socket_server_ipv6) pa_socket_server_set_callback(u->socket_server_ipv6, socket_server_on_connection_cb, u); # endif #else # if defined(USE_PROTOCOL_ESOUND) # if defined(USE_PER_USER_ESOUND_SOCKET) u->socket_path = pa_sprintf_malloc("/tmp/.esd-%lu/socket", (unsigned long) getuid()); # else u->socket_path = pa_xstrdup("/tmp/.esd/socket"); # endif /* This socket doesn't reside in our own runtime dir but in * /tmp/.esd/, hence we have to create the dir first */ if (pa_make_secure_parent_dir(u->socket_path, pa_in_system_mode() ? 0755U : 0700U, (uid_t)-1, (gid_t)-1) < 0) { pa_log("Failed to create socket directory '%s': %s\n", u->socket_path, pa_cstrerror(errno)); goto fail; } # else if (!(u->socket_path = pa_runtime_path(pa_modargs_get_value(ma, "socket", UNIX_SOCKET)))) { pa_log("Failed to generate socket path."); goto fail; } # endif if ((r = pa_unix_socket_remove_stale(u->socket_path)) < 0) { pa_log("Failed to remove stale UNIX socket '%s': %s", u->socket_path, pa_cstrerror(errno)); goto fail; } else if (r > 0) pa_log_info("Removed stale UNIX socket '%s'.", u->socket_path); if (!(u->socket_server_unix = pa_socket_server_new_unix(m->core->mainloop, u->socket_path))) goto fail; pa_socket_server_set_callback(u->socket_server_unix, socket_server_on_connection_cb, u); #endif #if defined(USE_PROTOCOL_NATIVE) # 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_add_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_add_server_string(u->native_protocol, t); # endif # else if (pa_socket_server_get_address(u->socket_server_unix, t, sizeof(t))) pa_native_protocol_add_server_string(u->native_protocol, t); # endif #endif #if defined(USE_PROTOCOL_HTTP) #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_add_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_add_server_string(u->http_protocol, t); #endif /* HAVE_IPV6 */ #else /* USE_TCP_SOCKETS */ if (pa_socket_server_get_address(u->socket_server_unix, t, sizeof(t))) pa_http_protocol_add_server_string(u->http_protocol, t); #endif /* USE_TCP_SOCKETS */ #endif /* USE_PROTOCOL_HTTP */ if (ma) pa_modargs_free(ma); return 0; fail: if (ma) pa_modargs_free(ma); pa__done(m); return -1; }
int pa__init(pa_module*m) { struct userdata *u; pa_modargs *ma = NULL; char *mid, *sid; char hx[PA_NATIVE_COOKIE_LENGTH*2+1]; const char *t; int screen; pa_assert(m); if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { pa_log("failed to parse module arguments"); goto fail; } m->userdata = u = pa_xnew(struct userdata, 1); u->core = m->core; u->module = m; u->protocol = pa_native_protocol_get(m->core); u->id = NULL; u->auth_cookie = NULL; u->x11_client = NULL; u->x11_wrapper = NULL; u->hook_slot = pa_hook_connect(&pa_native_protocol_hooks(u->protocol)[PA_NATIVE_HOOK_SERVERS_CHANGED], PA_HOOK_NORMAL, servers_changed_cb, u); if (!(u->auth_cookie = pa_auth_cookie_get(m->core, pa_modargs_get_value(ma, "cookie", PA_NATIVE_COOKIE_FILE), true, PA_NATIVE_COOKIE_LENGTH))) goto fail; if (!(u->x11_wrapper = pa_x11_wrapper_get(m->core, pa_modargs_get_value(ma, "display", NULL)))) goto fail; screen = DefaultScreen(pa_x11_wrapper_get_display(u->x11_wrapper)); mid = pa_machine_id(); u->id = pa_sprintf_malloc("%lu@%s/%lu", (unsigned long) getuid(), mid, (unsigned long) getpid()); pa_xfree(mid); pa_x11_set_prop(pa_x11_wrapper_get_xcb_connection(u->x11_wrapper), screen, "PULSE_ID", u->id); if ((sid = pa_session_id())) { pa_x11_set_prop(pa_x11_wrapper_get_xcb_connection(u->x11_wrapper), screen, "PULSE_SESSION_ID", sid); pa_xfree(sid); } publish_servers(u, pa_native_protocol_servers(u->protocol)); if ((t = pa_modargs_get_value(ma, "source", NULL))) pa_x11_set_prop(pa_x11_wrapper_get_xcb_connection(u->x11_wrapper), screen, "PULSE_SOURCE", t); if ((t = pa_modargs_get_value(ma, "sink", NULL))) pa_x11_set_prop(pa_x11_wrapper_get_xcb_connection(u->x11_wrapper), screen, "PULSE_SINK", t); pa_x11_set_prop(pa_x11_wrapper_get_xcb_connection(u->x11_wrapper), screen, "PULSE_COOKIE", pa_hexstr(pa_auth_cookie_read(u->auth_cookie, PA_NATIVE_COOKIE_LENGTH), PA_NATIVE_COOKIE_LENGTH, hx, sizeof(hx))); u->x11_client = pa_x11_client_new(u->x11_wrapper, NULL, x11_kill_cb, u); pa_modargs_free(ma); return 0; fail: if (ma) pa_modargs_free(ma); pa__done(m); return -1; }