treewide: add error checking to spa_json_builder_close

There could have been a write error or allocation error while building
the json file that we can detect in spa_json_builder_close().

Error out instead of silently using a truncated JSON.

Use spa_autofree for the memory to make cleanup easier.
This commit is contained in:
Wim Taymans 2026-05-13 18:14:44 +02:00
parent 6d1c242433
commit 4f975d0071
41 changed files with 240 additions and 194 deletions

View file

@ -2,6 +2,7 @@
/* SPDX-FileCopyrightText: Copyright © 2020 Wim Taymans */
/* SPDX-License-Identifier: MIT */
#include <spa/utils/cleanup.h>
#include <spa/utils/string.h>
#include <spa/debug/types.h>
#include <spa/param/audio/format.h>
@ -704,7 +705,7 @@ static int add_int(struct format_info *info, const char *k, struct spa_pod *para
case SPA_CHOICE_Enum:
{
struct spa_json_builder b;
char *ptr;
spa_autofree char *ptr = NULL;
size_t size;
int res;
@ -715,10 +716,10 @@ static int add_int(struct format_info *info, const char *k, struct spa_pod *para
for (i = 1; i < n_values; i++)
spa_json_builder_array_int(&b, values[i]);
spa_json_builder_pop(&b, "]");
spa_json_builder_close(&b);
if ((res = spa_json_builder_close(&b)) < 0)
return res;
pw_properties_set(info->props, k, ptr);
free(ptr);
break;
}
default:

View file

@ -2,6 +2,7 @@
/* SPDX-FileCopyrightText: Copyright © 2022 Wim Taymans <wim.taymans@gmail.com> */
/* SPDX-License-Identifier: MIT */
#include <spa/utils/cleanup.h>
#include <spa/utils/json-builder.h>
#include <pipewire/pipewire.h>
@ -54,7 +55,7 @@ static int module_always_sink_load(struct module *module)
{
struct module_always_sink_data *data = module->user_data;
struct spa_json_builder b;
char *args;
spa_autofree char *args = NULL;
const char *str;
size_t size;
int res;
@ -66,12 +67,12 @@ static int module_always_sink_load(struct module *module)
if ((str = pw_properties_get(module->props, "sink_name")) != NULL)
spa_json_builder_object_string(&b, "sink.name", str);
spa_json_builder_pop(&b, "}");
spa_json_builder_close(&b);
if ((res = spa_json_builder_close(&b)) < 0)
return res;
data->mod = pw_context_load_module(module->impl->context,
"libpipewire-module-fallback-sink",
args, NULL);
free(args);
if (data->mod == NULL)
return -errno;

View file

@ -4,6 +4,7 @@
/* SPDX-License-Identifier: MIT */
#include <spa/param/audio/format-utils.h>
#include <spa/utils/cleanup.h>
#include <spa/utils/json.h>
#include <spa/utils/json-builder.h>
@ -171,7 +172,7 @@ static int module_combine_sink_load(struct module *module)
struct spa_json_builder b;
uint32_t i;
int res;
char *args;
spa_autofree char *args = NULL;
size_t size;
data->core = pw_context_connect(module->impl->context, NULL, 0);
@ -217,12 +218,12 @@ static int module_combine_sink_load(struct module *module)
spa_json_builder_pop(&b, "}");
spa_json_builder_pop(&b, "]");
spa_json_builder_pop(&b, "}");
spa_json_builder_close(&b);
if ((res = spa_json_builder_close(&b)) < 0)
return res;
data->mod = pw_context_load_module(module->impl->context,
"libpipewire-module-combine-stream",
args, NULL);
free(args);
if (data->mod == NULL)
return -errno;

View file

@ -4,6 +4,7 @@
/* SPDX-License-Identifier: MIT */
#include <spa/param/audio/format-utils.h>
#include <spa/utils/cleanup.h>
#include <spa/utils/hook.h>
#include <spa/utils/json-builder.h>
#include <pipewire/pipewire.h>
@ -104,7 +105,7 @@ static int module_echo_cancel_load(struct module *module)
{
struct module_echo_cancel_data *data = module->user_data;
struct spa_json_builder b;
char *args;
spa_autofree char *args = NULL;
size_t size;
int res;
@ -134,12 +135,12 @@ static int module_echo_cancel_load(struct module *module)
pw_properties_serialize_dict(b.f, &data->playback_props->dict, 0);
spa_json_builder_pop(&b, "}");
spa_json_builder_pop(&b, "}");
spa_json_builder_close(&b);
if ((res = spa_json_builder_close(&b)) < 0)
return res;
data->mod = pw_context_load_module(module->impl->context,
"libpipewire-module-echo-cancel",
args, NULL);
free(args);
if (data->mod == NULL)
return -errno;
@ -198,7 +199,7 @@ static int rename_geometry(struct pw_properties *props, const char *pa_key, cons
{
const char *str;
int i = 0, len, res;
char *args;
spa_autofree char *args = NULL;
size_t size;
struct spa_json_builder b;
@ -231,10 +232,10 @@ static int rename_geometry(struct pw_properties *props, const char *pa_key, cons
i++;
}
spa_json_builder_pop(&b, "]");
spa_json_builder_close(&b);
if ((res = spa_json_builder_close(&b)) < 0)
return res;
pw_properties_set(props, pw_key, args);
free(args);
pw_properties_set(props, pa_key, NULL);
return 0;

View file

@ -2,6 +2,7 @@
/* SPDX-FileCopyrightText: Copyright © 2021 Wim Taymans <wim.taymans@gmail.com> */
/* SPDX-License-Identifier: MIT */
#include <spa/utils/cleanup.h>
#include <spa/utils/hook.h>
#include <spa/utils/json-builder.h>
#include <pipewire/pipewire.h>
@ -88,7 +89,7 @@ static int module_jackdbus_detect_load(struct module *module)
{
struct module_jackdbus_detect_data *data = module->user_data;
struct spa_json_builder b;
char *args;
spa_autofree char *args = NULL;
size_t size;
int res;
@ -109,12 +110,12 @@ static int module_jackdbus_detect_load(struct module *module)
pw_properties_serialize_dict(b.f, &data->sink_props->dict, 0);
spa_json_builder_pop(&b, "}");
spa_json_builder_pop(&b, "}");
spa_json_builder_close(&b);
if ((res = spa_json_builder_close(&b)) < 0)
return res;
data->mod = pw_context_load_module(module->impl->context,
"libpipewire-module-jackdbus-detect",
args, NULL);
free(args);
if (data->mod == NULL)
return -errno;

View file

@ -2,6 +2,7 @@
/* SPDX-FileCopyrightText: Copyright © 2021 Wim Taymans <wim.taymans@gmail.com> */
/* SPDX-License-Identifier: MIT */
#include <spa/utils/cleanup.h>
#include <spa/utils/hook.h>
#include <spa/utils/json-builder.h>
#include <spa/param/audio/format-utils.h>
@ -92,7 +93,7 @@ static int module_ladspa_sink_load(struct module *module)
{
struct module_ladspa_sink_data *data = module->user_data;
struct spa_json_builder b;
char *args;
spa_autofree char *args = NULL;
const char *str, *plugin, *label;
size_t size;
int res;
@ -159,12 +160,12 @@ static int module_ladspa_sink_load(struct module *module)
pw_properties_serialize_dict(b.f, &data->playback_props->dict, 0);
spa_json_builder_pop(&b, "}");
spa_json_builder_pop(&b, "}");
spa_json_builder_close(&b);
if ((res = spa_json_builder_close(&b)) < 0)
return res;
data->mod = pw_context_load_module(module->impl->context,
"libpipewire-module-filter-chain",
args, NULL);
free(args);
if (data->mod == NULL)
return -errno;

View file

@ -2,6 +2,7 @@
/* SPDX-FileCopyrightText: Copyright © 2021 Wim Taymans <wim.taymans@gmail.com> */
/* SPDX-License-Identifier: MIT */
#include <spa/utils/cleanup.h>
#include <spa/utils/hook.h>
#include <spa/utils/json-builder.h>
#include <spa/param/audio/format-utils.h>
@ -92,7 +93,7 @@ static int module_ladspa_source_load(struct module *module)
{
struct module_ladspa_source_data *data = module->user_data;
struct spa_json_builder b;
char *args;
spa_autofree char *args = NULL;
const char *str, *plugin, *label;
size_t size;
int res;
@ -159,12 +160,12 @@ static int module_ladspa_source_load(struct module *module)
pw_properties_serialize_dict(b.f, &data->playback_props->dict, 0);
spa_json_builder_pop(&b, "}");
spa_json_builder_pop(&b, "}");
spa_json_builder_close(&b);
if ((res = spa_json_builder_close(&b)) < 0)
return res;
data->mod = pw_context_load_module(module->impl->context,
"libpipewire-module-filter-chain",
args, NULL);
free(args);
if (data->mod == NULL)
return -errno;

View file

@ -4,6 +4,7 @@
/* SPDX-License-Identifier: MIT */
#include <spa/param/audio/format-utils.h>
#include <spa/utils/cleanup.h>
#include <spa/utils/hook.h>
#include <spa/utils/json-builder.h>
#include <pipewire/pipewire.h>
@ -87,7 +88,7 @@ static int module_loopback_load(struct module *module)
{
struct module_loopback_data *data = module->user_data;
struct spa_json_builder b;
char *args;
spa_autofree char *args = NULL;
size_t size;
int res;
@ -108,12 +109,12 @@ static int module_loopback_load(struct module *module)
pw_properties_serialize_dict(b.f, &data->playback_props->dict, 0);
spa_json_builder_pop(&b, "}");
spa_json_builder_pop(&b, "}");
spa_json_builder_close(&b);
if ((res = spa_json_builder_close(&b)) < 0)
return res;
data->mod = pw_context_load_module(module->impl->context,
"libpipewire-module-loopback",
args, NULL);
free(args);
if (data->mod == NULL)
return -errno;

View file

@ -2,6 +2,7 @@
/* SPDX-FileCopyrightText: Copyright © 2021 Wim Taymans <wim.taymans@gmail.com> */
/* SPDX-License-Identifier: MIT */
#include <spa/utils/cleanup.h>
#include <spa/utils/json-builder.h>
#include <pipewire/pipewire.h>
@ -87,7 +88,7 @@ static int module_native_protocol_tcp_prepare(struct module * const module)
struct pw_properties * const props = module->props;
const char *port, *listen, *auth;
struct spa_json_builder b;
char *args;
spa_autofree char *args = NULL;
size_t size;
int res;
@ -111,10 +112,10 @@ static int module_native_protocol_tcp_prepare(struct module * const module)
spa_json_builder_object_string(&b, "client.access", "unrestricted");
spa_json_builder_pop(&b, "}");
spa_json_builder_pop(&b, "]");
spa_json_builder_close(&b);
if ((res = spa_json_builder_close(&b)) < 0)
return res;
pw_properties_set(props, "pulse.tcp", args);
free(args);
d->module = module;

View file

@ -7,6 +7,7 @@
#include <sys/stat.h>
#include <unistd.h>
#include <spa/utils/cleanup.h>
#include <spa/utils/json-builder.h>
#include <pipewire/pipewire.h>
#include <spa/param/audio/format-utils.h>
@ -84,7 +85,7 @@ static int module_pipe_sink_load(struct module *module)
{
struct module_pipesink_data *data = module->user_data;
struct spa_json_builder b;
char *args;
spa_autofree char *args = NULL;
size_t size;
int res;
@ -100,14 +101,13 @@ static int module_pipe_sink_load(struct module *module)
pw_properties_serialize_dict(b.f, &data->stream_props->dict, 0);
spa_json_builder_pop(&b, "}");
spa_json_builder_pop(&b, "}");
spa_json_builder_close(&b);
if ((res = spa_json_builder_close(&b)) < 0)
return res;
data->mod = pw_context_load_module(module->impl->context,
"libpipewire-module-pipe-tunnel",
args, NULL);
free(args);
if (data->mod == NULL)
return -errno;

View file

@ -7,6 +7,7 @@
#include <sys/stat.h>
#include <unistd.h>
#include <spa/utils/cleanup.h>
#include <spa/utils/json-builder.h>
#include <pipewire/pipewire.h>
#include <spa/param/audio/format-utils.h>
@ -82,7 +83,7 @@ static int module_pipe_source_load(struct module *module)
{
struct module_pipesrc_data *data = module->user_data;
struct spa_json_builder b;
char *args;
spa_autofree char *args = NULL;
size_t size;
int res;
@ -98,14 +99,13 @@ static int module_pipe_source_load(struct module *module)
pw_properties_serialize_dict(b.f, &data->stream_props->dict, 0);
spa_json_builder_pop(&b, "}");
spa_json_builder_pop(&b, "}");
spa_json_builder_close(&b);
if ((res = spa_json_builder_close(&b)) < 0)
return res;
data->mod = pw_context_load_module(module->impl->context,
"libpipewire-module-pipe-tunnel",
args, NULL);
free(args);
if (data->mod == NULL)
return -errno;

View file

@ -2,6 +2,7 @@
/* SPDX-FileCopyrightText: Copyright © 2021 Wim Taymans <wim.taymans@gmail.com> */
/* SPDX-License-Identifier: MIT */
#include <spa/utils/cleanup.h>
#include <spa/utils/hook.h>
#include <spa/utils/json-builder.h>
#include <pipewire/pipewire.h>
@ -61,7 +62,7 @@ static int module_raop_discover_load(struct module *module)
{
struct module_raop_discover_data *data = module->user_data;
struct spa_json_builder b;
char *args;
spa_autofree char *args = NULL;
size_t size;
int res;
@ -72,14 +73,13 @@ static int module_raop_discover_load(struct module *module)
if (data->latency_msec > 0)
spa_json_builder_object_uint(&b, "raop.latency.ms", data->latency_msec);
spa_json_builder_pop(&b, "}");
spa_json_builder_close(&b);
if ((res = spa_json_builder_close(&b)) < 0)
return res;
data->mod = pw_context_load_module(module->impl->context,
"libpipewire-module-raop-discover",
args, NULL);
free(args);
if (data->mod == NULL)
return -errno;

View file

@ -3,6 +3,7 @@
/* SPDX-License-Identifier: MIT */
#include <spa/param/audio/format-utils.h>
#include <spa/utils/cleanup.h>
#include <spa/utils/hook.h>
#include <spa/utils/json-builder.h>
#include <pipewire/pipewire.h>
@ -83,7 +84,7 @@ static int module_remap_sink_load(struct module *module)
{
struct module_remap_sink_data *data = module->user_data;
struct spa_json_builder b;
char *args;
spa_autofree char *args = NULL;
size_t size;
int res;
@ -104,12 +105,12 @@ static int module_remap_sink_load(struct module *module)
pw_properties_serialize_dict(b.f, &data->playback_props->dict, 0);
spa_json_builder_pop(&b, "}");
spa_json_builder_pop(&b, "}");
spa_json_builder_close(&b);
if ((res = spa_json_builder_close(&b)) < 0)
return res;
data->mod = pw_context_load_module(module->impl->context,
"libpipewire-module-loopback",
args, NULL);
free(args);
if (data->mod == NULL)
return -errno;

View file

@ -3,6 +3,7 @@
/* SPDX-License-Identifier: MIT */
#include <spa/param/audio/format-utils.h>
#include <spa/utils/cleanup.h>
#include <spa/utils/hook.h>
#include <spa/utils/json-builder.h>
#include <pipewire/pipewire.h>
@ -83,7 +84,7 @@ static int module_remap_source_load(struct module *module)
{
struct module_remap_source_data *data = module->user_data;
struct spa_json_builder b;
char *args;
spa_autofree char *args = NULL;
size_t size;
int res;
@ -104,12 +105,12 @@ static int module_remap_source_load(struct module *module)
pw_properties_serialize_dict(b.f, &data->playback_props->dict, 0);
spa_json_builder_pop(&b, "}");
spa_json_builder_pop(&b, "}");
spa_json_builder_close(&b);
if ((res = spa_json_builder_close(&b)) < 0)
return res;
data->mod = pw_context_load_module(module->impl->context,
"libpipewire-module-loopback",
args, NULL);
free(args);
if (data->mod == NULL)
return -errno;

View file

@ -3,6 +3,7 @@
/* SPDX-FileCopyrightText: Copyright © 2021 Sanchayan Maity <sanchayan@asymptotic.io> */
/* SPDX-License-Identifier: MIT */
#include <spa/utils/cleanup.h>
#include <spa/utils/hook.h>
#include <spa/utils/json-builder.h>
#include <pipewire/pipewire.h>
@ -82,7 +83,7 @@ static int module_roc_sink_input_load(struct module *module)
{
struct module_roc_sink_input_data *data = module->user_data;
struct spa_json_builder b;
char *args;
spa_autofree char *args = NULL;
size_t size;
int res;
@ -98,14 +99,13 @@ static int module_roc_sink_input_load(struct module *module)
pw_properties_serialize_dict(b.f, &data->source_props->dict, 0);
spa_json_builder_pop(&b, "}");
spa_json_builder_pop(&b, "}");
spa_json_builder_close(&b);
if ((res = spa_json_builder_close(&b)) < 0)
return res;
data->mod = pw_context_load_module(module->impl->context,
"libpipewire-module-roc-source",
args, NULL);
free(args);
if (data->mod == NULL)
return -errno;

View file

@ -3,6 +3,7 @@
/* SPDX-FileCopyrightText: Copyright © 2021 Sanchayan Maity <sanchayan@asymptotic.io> */
/* SPDX-License-Identifier: MIT */
#include <spa/utils/cleanup.h>
#include <spa/utils/hook.h>
#include <spa/utils/json-builder.h>
#include <pipewire/pipewire.h>
@ -78,7 +79,7 @@ static int module_roc_sink_load(struct module *module)
{
struct module_roc_sink_data *data = module->user_data;
struct spa_json_builder b;
char *args;
spa_autofree char *args = NULL;
size_t size;
int res;
@ -94,14 +95,13 @@ static int module_roc_sink_load(struct module *module)
pw_properties_serialize_dict(b.f, &data->sink_props->dict, 0);
spa_json_builder_pop(&b, "}");
spa_json_builder_pop(&b, "}");
spa_json_builder_close(&b);
if ((res = spa_json_builder_close(&b)) < 0)
return res;
data->mod = pw_context_load_module(module->impl->context,
"libpipewire-module-roc-sink",
args, NULL);
free(args);
if (data->mod == NULL)
return -errno;

View file

@ -3,6 +3,7 @@
/* SPDX-FileCopyrightText: Copyright © 2021 Sanchayan Maity <sanchayan@asymptotic.io> */
/* SPDX-License-Identifier: MIT */
#include <spa/utils/cleanup.h>
#include <spa/utils/hook.h>
#include <spa/utils/json-builder.h>
#include <pipewire/pipewire.h>
@ -82,7 +83,7 @@ static int module_roc_source_load(struct module *module)
{
struct module_roc_source_data *data = module->user_data;
struct spa_json_builder b;
char *args;
spa_autofree char *args = NULL;
size_t size;
int res;
@ -98,14 +99,13 @@ static int module_roc_source_load(struct module *module)
pw_properties_serialize_dict(b.f, &data->source_props->dict, 0);
spa_json_builder_pop(&b, "}");
spa_json_builder_pop(&b, "}");
spa_json_builder_close(&b);
if ((res = spa_json_builder_close(&b)) < 0)
return res;
data->mod = pw_context_load_module(module->impl->context,
"libpipewire-module-roc-source",
args, NULL);
free(args);
if (data->mod == NULL)
return -errno;

View file

@ -2,6 +2,7 @@
/* SPDX-FileCopyrightText: Copyright © 2022 Wim Taymans <wim.taymans@gmail.com> */
/* SPDX-License-Identifier: MIT */
#include <spa/utils/cleanup.h>
#include <spa/utils/hook.h>
#include <spa/utils/json-builder.h>
#include <pipewire/pipewire.h>
@ -70,7 +71,7 @@ static int module_rtp_recv_load(struct module *module)
{
struct module_rtp_recv_data *data = module->user_data;
struct spa_json_builder b;
char *args;
spa_autofree char *args = NULL;
size_t size;
int res;
@ -97,14 +98,13 @@ static int module_rtp_recv_load(struct module *module)
spa_json_builder_pop(&b, "}");
spa_json_builder_pop(&b, "]");
spa_json_builder_pop(&b, "}");
spa_json_builder_close(&b);
if ((res = spa_json_builder_close(&b)) < 0)
return res;
data->mod = pw_context_load_module(module->impl->context,
"libpipewire-module-rtp-sap",
args, NULL);
free(args);
if (data->mod == NULL)
return -errno;

View file

@ -2,6 +2,7 @@
/* SPDX-FileCopyrightText: Copyright © 2022 Wim Taymans <wim.taymans@gmail.com> */
/* SPDX-License-Identifier: MIT */
#include <spa/utils/cleanup.h>
#include <spa/utils/hook.h>
#include <spa/utils/json-builder.h>
#include <pipewire/pipewire.h>
@ -107,7 +108,7 @@ static int module_rtp_send_load(struct module *module)
{
struct module_rtp_send_data *data = module->user_data;
struct spa_json_builder b;
char *args;
spa_autofree char *args = NULL;
size_t size;
int res;
@ -123,12 +124,12 @@ static int module_rtp_send_load(struct module *module)
pw_properties_serialize_dict(b.f, &data->stream_props->dict, 0);
spa_json_builder_pop(&b, "}");
spa_json_builder_pop(&b, "}");
spa_json_builder_close(&b);
if ((res = spa_json_builder_close(&b)) < 0)
return res;
data->mod = pw_context_load_module(module->impl->context,
"libpipewire-module-rtp-sink",
args, NULL);
free(args);
if (data->mod == NULL)
return -errno;
@ -156,12 +157,12 @@ static int module_rtp_send_load(struct module *module)
spa_json_builder_pop(&b, "}");
spa_json_builder_pop(&b, "]");
spa_json_builder_pop(&b, "}");
spa_json_builder_close(&b);
if ((res = spa_json_builder_close(&b)) < 0)
return res;
data->sap = pw_context_load_module(module->impl->context,
"libpipewire-module-rtp-sap",
args, NULL);
free(args);
if (data->sap == NULL)
return -errno;

View file

@ -2,6 +2,7 @@
/* SPDX-FileCopyrightText: Copyright © 2021 Wim Taymans <wim.taymans@gmail.com> */
/* SPDX-License-Identifier: MIT */
#include <spa/utils/cleanup.h>
#include <spa/utils/json-builder.h>
#include <pipewire/impl.h>
#include <pipewire/pipewire.h>
@ -85,7 +86,7 @@ static int module_simple_protocol_tcp_load(struct module *module)
struct module_simple_protocol_tcp_data *data = module->user_data;
struct impl *impl = module->impl;
struct spa_json_builder b;
char *args;
spa_autofree char *args = NULL;
size_t size;
int res;
@ -95,12 +96,12 @@ static int module_simple_protocol_tcp_load(struct module *module)
spa_json_builder_array_push(&b, "{");
pw_properties_serialize_dict(b.f, &data->module_props->dict, 0);
spa_json_builder_pop(&b, "}");
spa_json_builder_close(&b);
if ((res = spa_json_builder_close(&b)) < 0)
return res;
data->mod = pw_context_load_module(impl->context,
"libpipewire-module-protocol-simple",
args, NULL);
free(args);
if (data->mod == NULL)
return -errno;
@ -187,7 +188,7 @@ static int module_simple_protocol_tcp_prepare(struct module * const module)
{
struct spa_json_builder ab;
char *addr;
spa_autofree char *addr = NULL;
size_t addr_size;
if ((res = spa_json_builder_memstream(&ab, &addr, &addr_size, 0)) < 0)
@ -197,10 +198,10 @@ static int module_simple_protocol_tcp_prepare(struct module * const module)
spa_json_builder_array_stringf(&ab, "tcp:%s%s%s",
listen ? listen : "", listen ? ":" : "", port);
spa_json_builder_pop(&ab, "]");
spa_json_builder_close(&ab);
if ((res = spa_json_builder_close(&ab)) < 0)
goto out;
pw_properties_set(module_props, "server.address", addr);
free(addr);
}
d->module = module;

View file

@ -71,6 +71,7 @@ enum {
#include <stdlib.h>
#include <string.h>
#include <spa/utils/cleanup.h>
#include <spa/utils/defs.h>
#include <spa/utils/dict.h>
#include <spa/utils/string.h>
@ -272,7 +273,7 @@ static int do_extension_stream_restore_write(struct module *module, struct clien
struct volume vol;
bool mute = false;
uint32_t i;
char *ptr;
spa_autofree char *ptr = NULL;
size_t size;
char key[1024];
@ -319,7 +320,8 @@ static int do_extension_stream_restore_write(struct module *module, struct clien
(client->default_sink == NULL || !spa_streq(device_name, client->default_sink)))
spa_json_builder_object_string(&b, "target-node", device_name);
spa_json_builder_pop(&b, "}");
spa_json_builder_close(&b);
if ((bres = spa_json_builder_close(&b)) < 0)
return bres;
}
if (key_from_name(name, key, sizeof(key)) >= 0) {
pw_log_debug("%s -> %s: %s", name, key, ptr);
@ -328,7 +330,6 @@ static int do_extension_stream_restore_write(struct module *module, struct clien
PW_ID_CORE, key, "Spa:String:JSON", "%s", ptr)) < 0)
pw_log_warn("failed to set metadata %s = %s, %s", key, ptr, strerror(-res));
}
free(ptr);
}
return reply_simple_ack(client, tag);

View file

@ -3,6 +3,7 @@
/* SPDX-FileCopyrightText: Copyright © 2021 Pauli Virtanen <pav@iki.fi> */
/* SPDX-License-Identifier: MIT */
#include <spa/utils/cleanup.h>
#include <spa/utils/hook.h>
#include <spa/utils/json-builder.h>
#include <spa/utils/string.h>
@ -144,21 +145,21 @@ static void manager_added(void *data, struct pw_manager_object *o)
{
struct spa_json_builder b;
char *val;
spa_autofree char *val = NULL;
size_t val_size;
if (spa_json_builder_memstream(&b, &val, &val_size, 0) >= 0) {
spa_json_builder_array_push(&b, "{");
spa_json_builder_object_string(&b, "name", name);
spa_json_builder_pop(&b, "}");
spa_json_builder_close(&b);
if (spa_json_builder_close(&b) < 0)
return;
pw_manager_set_metadata(d->manager, d->metadata_default,
PW_ID_CORE,
pw_manager_object_is_sink(o) ? METADATA_CONFIG_DEFAULT_SINK
: METADATA_CONFIG_DEFAULT_SOURCE,
"Spa:String:JSON", "%s", val);
free(val);
}
}
}

View file

@ -3,6 +3,7 @@
/* SPDX-License-Identifier: MIT */
#include <spa/param/audio/format-utils.h>
#include <spa/utils/cleanup.h>
#include <spa/utils/hook.h>
#include <spa/utils/json-builder.h>
@ -86,7 +87,7 @@ static int module_tunnel_sink_load(struct module *module)
{
struct module_tunnel_sink_data *data = module->user_data;
struct spa_json_builder b;
char *args;
spa_autofree char *args = NULL;
size_t size;
int res;
@ -102,12 +103,12 @@ static int module_tunnel_sink_load(struct module *module)
pw_properties_serialize_dict(b.f, &data->stream_props->dict, 0);
spa_json_builder_pop(&b, "}");
spa_json_builder_pop(&b, "}");
spa_json_builder_close(&b);
if ((res = spa_json_builder_close(&b)) < 0)
return res;
data->mod = pw_context_load_module(module->impl->context,
"libpipewire-module-pulse-tunnel",
args, NULL);
free(args);
if (data->mod == NULL)
return -errno;

View file

@ -3,6 +3,7 @@
/* SPDX-License-Identifier: MIT */
#include <spa/param/audio/format-utils.h>
#include <spa/utils/cleanup.h>
#include <spa/utils/hook.h>
#include <spa/utils/json-builder.h>
@ -86,7 +87,7 @@ static int module_tunnel_source_load(struct module *module)
{
struct module_tunnel_source_data *data = module->user_data;
struct spa_json_builder b;
char *args;
spa_autofree char *args = NULL;
size_t size;
int res;
@ -102,12 +103,12 @@ static int module_tunnel_source_load(struct module *module)
pw_properties_serialize_dict(b.f, &data->stream_props->dict, 0);
spa_json_builder_pop(&b, "}");
spa_json_builder_pop(&b, "}");
spa_json_builder_close(&b);
if ((res = spa_json_builder_close(&b)) < 0)
return res;
data->mod = pw_context_load_module(module->impl->context,
"libpipewire-module-pulse-tunnel",
args, NULL);
free(args);
if (data->mod == NULL)
return -errno;

View file

@ -3,6 +3,7 @@
/* SPDX-License-Identifier: MIT */
#include <spa/param/audio/format-utils.h>
#include <spa/utils/cleanup.h>
#include <spa/utils/hook.h>
#include <spa/utils/json-builder.h>
#include <pipewire/pipewire.h>
@ -78,7 +79,7 @@ static int module_virtual_sink_load(struct module *module)
{
struct module_virtual_sink_data *data = module->user_data;
struct spa_json_builder b;
char *args;
spa_autofree char *args = NULL;
size_t size;
int res;
@ -99,12 +100,12 @@ static int module_virtual_sink_load(struct module *module)
pw_properties_serialize_dict(b.f, &data->playback_props->dict, 0);
spa_json_builder_pop(&b, "}");
spa_json_builder_pop(&b, "}");
spa_json_builder_close(&b);
if ((res = spa_json_builder_close(&b)) < 0)
return res;
data->mod = pw_context_load_module(module->impl->context,
"libpipewire-module-loopback",
args, NULL);
free(args);
if (data->mod == NULL)
return -errno;

View file

@ -4,6 +4,7 @@
/* SPDX-License-Identifier: MIT */
#include <spa/param/audio/format-utils.h>
#include <spa/utils/cleanup.h>
#include <spa/utils/hook.h>
#include <spa/utils/json-builder.h>
#include <pipewire/pipewire.h>
@ -81,7 +82,7 @@ static int module_virtual_source_load(struct module *module)
{
struct module_virtual_source_data *data = module->user_data;
struct spa_json_builder b;
char *args;
spa_autofree char *args = NULL;
size_t size;
int res;
@ -102,12 +103,12 @@ static int module_virtual_source_load(struct module *module)
pw_properties_serialize_dict(b.f, &data->playback_props->dict, 0);
spa_json_builder_pop(&b, "}");
spa_json_builder_pop(&b, "}");
spa_json_builder_close(&b);
if ((res = spa_json_builder_close(&b)) < 0)
return res;
data->mod = pw_context_load_module(module->impl->context,
"libpipewire-module-loopback",
args, NULL);
free(args);
if (data->mod == NULL)
return -errno;

View file

@ -2,6 +2,7 @@
/* SPDX-FileCopyrightText: Copyright © 2022 Wim Taymans <wim.taymans@gmail.com> */
/* SPDX-License-Identifier: MIT */
#include <spa/utils/cleanup.h>
#include <spa/utils/json-builder.h>
#include <pipewire/pipewire.h>
@ -65,7 +66,7 @@ static int module_x11_bell_load(struct module *module)
{
struct module_x11_bell_data *data = module->user_data;
struct spa_json_builder b;
char *args;
spa_autofree char *args = NULL;
const char *str;
size_t size;
int res;
@ -83,12 +84,12 @@ static int module_x11_bell_load(struct module *module)
if ((str = pw_properties_get(module->props, "xauthority")) != NULL)
spa_json_builder_object_string(&b, "x11.xauthority", str);
spa_json_builder_pop(&b, "}");
spa_json_builder_close(&b);
if ((res = spa_json_builder_close(&b)) < 0)
return res;
data->mod = pw_context_load_module(module->impl->context,
"libpipewire-module-x11-bell",
args, NULL);
free(args);
if (data->mod == NULL)
return -errno;

View file

@ -2,6 +2,7 @@
/* SPDX-FileCopyrightText: Copyright © 2021 Wim Taymans <wim.taymans@gmail.com> */
/* SPDX-License-Identifier: MIT */
#include <spa/utils/cleanup.h>
#include <spa/utils/hook.h>
#include <spa/utils/json-builder.h>
#include <pipewire/pipewire.h>
@ -64,7 +65,7 @@ static int module_zeroconf_discover_load(struct module *module)
{
struct module_zeroconf_discover_data *data = module->user_data;
struct spa_json_builder b;
char *args;
spa_autofree char *args = NULL;
size_t size;
int res;
@ -75,14 +76,13 @@ static int module_zeroconf_discover_load(struct module *module)
if (data->latency_msec > 0)
spa_json_builder_object_uint(&b, "pulse.latency", data->latency_msec);
spa_json_builder_pop(&b, "}");
spa_json_builder_close(&b);
if ((res = spa_json_builder_close(&b)) < 0)
return res;
data->mod = pw_context_load_module(module->impl->context,
"libpipewire-module-zeroconf-discover",
args, NULL);
free(args);
if (data->mod == NULL)
return -errno;

View file

@ -4825,7 +4825,7 @@ static int do_set_default(struct client *client, uint32_t command, uint32_t tag,
}
struct spa_json_builder b;
char *val;
spa_autofree char *val = NULL;
size_t val_size;
if ((res = spa_json_builder_memstream(&b, &val, &val_size, 0)) < 0)
@ -4834,13 +4834,13 @@ static int do_set_default(struct client *client, uint32_t command, uint32_t tag,
spa_json_builder_array_push(&b, "{");
spa_json_builder_object_string(&b, "name", name);
spa_json_builder_pop(&b, "}");
spa_json_builder_close(&b);
if ((res = spa_json_builder_close(&b)) < 0)
return res;
res = pw_manager_set_metadata(manager, client->metadata_default,
PW_ID_CORE,
sink ? METADATA_CONFIG_DEFAULT_SINK : METADATA_CONFIG_DEFAULT_SOURCE,
"Spa:String:JSON", "%s", val);
free(val);
} else {
res = pw_manager_set_metadata(manager, client->metadata_default,
PW_ID_CORE,