diff --git a/src/modules/module-protocol-native.c b/src/modules/module-protocol-native.c index 84e86d584..72293a7ee 100644 --- a/src/modules/module-protocol-native.c +++ b/src/modules/module-protocol-native.c @@ -65,6 +65,7 @@ struct protocol_data { struct client { struct pw_protocol_client this; + struct pw_properties *properties; struct spa_source *source; struct pw_protocol_native_connection *connection; @@ -406,14 +407,14 @@ static bool add_socket(struct pw_protocol *protocol, struct server *s) } static const char * -get_name(const struct pw_properties *properties) +get_remote(const struct pw_properties *properties) { const char *name = NULL; if (properties) - name = pw_properties_get(properties, "pipewire.core.name"); + name = pw_properties_get(properties, "pipewire.remote.name"); if (name == NULL) - name = getenv("PIPEWIRE_CORE"); + name = getenv("PIPEWIRE_REMOTE"); if (name == NULL) name = "pipewire-0"; return name; @@ -421,6 +422,7 @@ get_name(const struct pw_properties *properties) static int impl_connect(struct pw_protocol_client *client) { + struct client *impl = SPA_CONTAINER_OF(client, struct client, this); struct sockaddr_un addr; socklen_t size; const char *runtime_dir, *name = NULL; @@ -431,7 +433,7 @@ static int impl_connect(struct pw_protocol_client *client) return -1; } - name = get_name(NULL); + name = get_remote(impl->properties); if ((fd = socket(PF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0)) < 0) return -1; @@ -604,6 +606,9 @@ static void impl_destroy(struct pw_protocol_client *client) pw_loop_destroy_source(remote->core->main_loop, impl->flush_event); + if (impl->properties) + pw_properties_free(impl->properties); + spa_list_remove(&client->link); free(impl); } @@ -623,6 +628,8 @@ impl_new_client(struct pw_protocol *protocol, this->protocol = protocol; this->remote = remote; + impl->properties = properties ? pw_properties_copy(properties) : NULL; + this->connect = impl_connect; this->connect_fd = impl_connect_fd; this->disconnect = impl_disconnect; @@ -674,6 +681,20 @@ static const struct spa_loop_control_hooks impl_hooks = { .before = on_before_hook, }; +static const char * +get_name(const struct pw_properties *properties) +{ + const char *name = NULL; + + if (properties) + name = pw_properties_get(properties, "pipewire.core.name"); + if (name == NULL) + name = getenv("PIPEWIRE_CORE"); + if (name == NULL) + name = "pipewire-0"; + return name; +} + static struct pw_protocol_server * impl_add_server(struct pw_protocol *protocol, struct pw_core *core, diff --git a/src/pipewire/properties.c b/src/pipewire/properties.c index 01c9573ae..9a4906b38 100644 --- a/src/pipewire/properties.c +++ b/src/pipewire/properties.c @@ -86,7 +86,7 @@ struct pw_properties *pw_properties_new(const char *key, ...) va_start(varargs, key); while (key != NULL) { value = va_arg(varargs, char *); - add_func(&impl->this, strdup(key), strdup(value)); + add_func(&impl->this, strdup(key), value ? strdup(value) : NULL); key = va_arg(varargs, char *); } va_end(varargs); @@ -112,8 +112,11 @@ struct pw_properties *pw_properties_new_dict(const struct spa_dict *dict) pw_array_init(&impl->items, 16); - for (i = 0; i < dict->n_items; i++) - add_func(&impl->this, strdup(dict->items[i].key), strdup(dict->items[i].value)); + for (i = 0; i < dict->n_items; i++) { + if (dict->items[i].key != NULL) + add_func(&impl->this, strdup(dict->items[i].key), + dict->items[i].value ? strdup(dict->items[i].value) : NULL); + } return &impl->this; } @@ -136,7 +139,7 @@ struct pw_properties *pw_properties_copy(const struct pw_properties *properties) return NULL; pw_array_for_each(item, &impl->items) - add_func(copy, strdup(item->key), strdup(item->value)); + add_func(copy, strdup(item->key), item->value ? strdup(item->value) : NULL); return copy; } @@ -211,11 +214,8 @@ static void do_replace(struct pw_properties *properties, char *key, char *value) clear_item(item); if (value == NULL) { struct spa_dict_item *other = pw_array_get_unchecked(&impl->items, - pw_array_get_len - (&impl->items, - struct spa_dict_item) - - 1, - struct spa_dict_item); + pw_array_get_len(&impl->items, struct spa_dict_item) - 1, + struct spa_dict_item); item->key = other->key; item->value = other->value; impl->items.size -= sizeof(struct spa_dict_item); diff --git a/src/pipewire/remote.c b/src/pipewire/remote.c index c9cfdf305..47cdc1e6a 100644 --- a/src/pipewire/remote.c +++ b/src/pipewire/remote.c @@ -247,7 +247,7 @@ struct pw_remote *pw_remote_new(struct pw_core *core, pw_module_load(core, "libpipewire-module-client-node", NULL); - spa_list_insert(core->remote_list.prev, &this->link); + spa_list_append(&core->remote_list, &this->link); return this;