update latest upstream-2021-08-16

This commit is contained in:
Chengyi Zhao 2021-08-15 13:48:23 +08:00
parent efb1080dd6
commit bd71445296
36 changed files with 99 additions and 7357 deletions

3
src/.gitignore vendored
View file

@ -14,7 +14,6 @@ daemon.conf
default.pa
echo-cancel-test
esdcompat
gconf-helper
gsettings-helper
org.freedesktop.pulseaudio.gschema.valid
pacat
@ -26,6 +25,7 @@ pasuspender
pax11publish
pulseaudio
pulseaudio.service
pulseaudio-x11.service
start-pulseaudio-x11
*-orc-gen.[ch]
# tests
@ -49,6 +49,7 @@ flist-test
format-test
get-binary-name-test
gtk-test
hashmap-test
hook-list-test
interpol-test
ipacl-test

File diff suppressed because it is too large Load diff

View file

@ -1 +0,0 @@
../modules/Makefile

View file

@ -1,392 +0,0 @@
PULSE_0 {
global:
pa_ascii_filter;
pa_ascii_valid;
pa_bytes_per_second;
pa_bytes_snprint;
pa_bytes_to_usec;
pa_channel_map_can_balance;
pa_channel_map_can_fade;
pa_channel_map_can_lfe_balance;
pa_channel_map_compatible;
pa_channel_map_equal;
pa_channel_map_has_position;
pa_channel_map_init;
pa_channel_map_init_auto;
pa_channel_map_init_extend;
pa_channel_map_init_mono;
pa_channel_map_init_stereo;
pa_channel_map_mask;
pa_channel_map_parse;
pa_channel_map_snprint;
pa_channel_map_superset;
pa_channel_map_to_name;
pa_channel_map_to_pretty_name;
pa_channel_map_valid;
pa_channel_position_from_string;
pa_channel_position_to_pretty_string;
pa_channel_position_to_string;
pa_channels_valid;
pa_context_add_autoload;
pa_context_connect;
pa_context_disconnect;
pa_context_drain;
pa_context_errno;
pa_context_exit_daemon;
pa_context_get_autoload_info_by_index;
pa_context_get_autoload_info_by_name;
pa_context_get_autoload_info_list;
pa_context_get_card_info_by_index;
pa_context_get_card_info_by_name;
pa_context_get_card_info_list;
pa_context_get_client_info;
pa_context_get_client_info_list;
pa_context_get_index;
pa_context_get_module_info;
pa_context_get_module_info_list;
pa_context_get_protocol_version;
pa_context_get_sample_info_by_index;
pa_context_get_sample_info_by_name;
pa_context_get_sample_info_list;
pa_context_get_server;
pa_context_get_server_info;
pa_context_get_server_protocol_version;
pa_context_get_sink_info_by_index;
pa_context_get_sink_info_by_name;
pa_context_get_sink_info_list;
pa_context_get_sink_input_info;
pa_context_get_sink_input_info_list;
pa_context_get_source_info_by_index;
pa_context_get_source_info_by_name;
pa_context_get_source_info_list;
pa_context_get_source_output_info;
pa_context_get_source_output_info_list;
pa_context_set_port_latency_offset;
pa_context_get_state;
pa_context_get_tile_size;
pa_context_is_local;
pa_context_is_pending;
pa_context_kill_client;
pa_context_kill_sink_input;
pa_context_kill_source_output;
pa_context_load_cookie_from_file;
pa_context_load_module;
pa_context_move_sink_input_by_index;
pa_context_move_sink_input_by_name;
pa_context_move_source_output_by_index;
pa_context_move_source_output_by_name;
pa_context_new;
pa_context_new_with_proplist;
pa_context_play_sample;
pa_context_play_sample_with_proplist;
pa_context_proplist_remove;
pa_context_proplist_update;
pa_context_ref;
pa_context_remove_autoload_by_index;
pa_context_remove_autoload_by_name;
pa_context_remove_sample;
pa_context_rttime_new;
pa_context_rttime_restart;
pa_context_set_card_profile_by_index;
pa_context_set_card_profile_by_name;
pa_context_set_default_sink;
pa_context_set_default_source;
pa_context_set_event_callback;
pa_context_set_name;
pa_context_set_sink_input_mute;
pa_context_set_sink_input_volume;
pa_context_set_sink_mute_by_index;
pa_context_set_sink_mute_by_name;
pa_context_set_sink_port_by_index;
pa_context_set_sink_port_by_name;
pa_context_set_sink_volume_by_index;
pa_context_set_sink_volume_by_name;
pa_context_set_source_output_mute;
pa_context_set_source_output_volume;
pa_context_set_source_mute_by_index;
pa_context_set_source_mute_by_name;
pa_context_set_source_port_by_index;
pa_context_set_source_port_by_name;
pa_context_set_source_volume_by_index;
pa_context_set_source_volume_by_name;
pa_context_set_state_callback;
pa_context_set_subscribe_callback;
pa_context_stat;
pa_context_subscribe;
pa_context_suspend_sink_by_index;
pa_context_suspend_sink_by_name;
pa_context_suspend_source_by_index;
pa_context_suspend_source_by_name;
pa_context_unload_module;
pa_context_unref;
pa_cvolume_avg;
pa_cvolume_avg_mask;
pa_cvolume_channels_equal_to;
pa_cvolume_compatible;
pa_cvolume_compatible_with_channel_map;
pa_cvolume_dec;
pa_cvolume_equal;
pa_cvolume_get_balance;
pa_cvolume_get_fade;
pa_cvolume_get_lfe_balance;
pa_cvolume_get_position;
pa_cvolume_inc;
pa_cvolume_inc_clamp;
pa_cvolume_init;
pa_cvolume_max;
pa_cvolume_max_mask;
pa_cvolume_merge;
pa_cvolume_min;
pa_cvolume_min_mask;
pa_cvolume_remap;
pa_cvolume_scale;
pa_cvolume_scale_mask;
pa_cvolume_set;
pa_cvolume_set_balance;
pa_cvolume_set_fade;
pa_cvolume_set_lfe_balance;
pa_cvolume_set_position;
pa_cvolume_snprint;
pa_cvolume_snprint_verbose;
pa_cvolume_valid;
pa_direction_to_string;
pa_direction_valid;
pa_encoding_from_string;
pa_encoding_to_string;
pa_ext_device_manager_delete;
pa_ext_device_manager_enable_role_device_priority_routing;
pa_ext_device_manager_read;
pa_ext_device_manager_reorder_devices_for_role;
pa_ext_device_manager_set_device_description;
pa_ext_device_manager_set_subscribe_cb;
pa_ext_device_manager_subscribe;
pa_ext_device_manager_test;
pa_ext_device_restore_read_formats;
pa_ext_device_restore_read_formats_all;
pa_ext_device_restore_save_formats;
pa_ext_device_restore_set_subscribe_cb;
pa_ext_device_restore_subscribe;
pa_ext_device_restore_test;
pa_ext_stream_restore_delete;
pa_ext_stream_restore_read;
pa_ext_stream_restore_set_subscribe_cb;
pa_ext_stream_restore_subscribe;
pa_ext_stream_restore_test;
pa_ext_stream_restore_write;
pa_format_info_copy;
pa_format_info_free;
pa_format_info_from_string;
pa_format_info_from_sample_spec;
pa_format_info_get_channel_map;
pa_format_info_get_channels;
pa_format_info_get_prop_type;
pa_format_info_get_prop_int;
pa_format_info_get_prop_int_range;
pa_format_info_get_prop_int_array;
pa_format_info_get_prop_string;
pa_format_info_get_prop_string_array;
pa_format_info_get_rate;
pa_format_info_get_sample_format;
pa_format_info_free_string_array;
pa_format_info_is_compatible;
pa_format_info_is_pcm;
pa_format_info_new;
pa_format_info_set_channel_map;
pa_format_info_set_channels;
pa_format_info_set_prop_int;
pa_format_info_set_prop_int_array;
pa_format_info_set_prop_int_range;
pa_format_info_set_prop_string;
pa_format_info_set_prop_string_array;
pa_format_info_set_rate;
pa_format_info_set_sample_format;
pa_format_info_snprint;
pa_format_info_to_sample_spec;
pa_format_info_valid;
pa_frame_size;
pa_get_binary_name;
pa_get_fqdn;
pa_get_home_dir;
pa_get_host_name;
pa_get_library_version;
pa_gettimeofday;
pa_get_user_name;
pa_glib_mainloop_free;
pa_glib_mainloop_get_api;
pa_glib_mainloop_new;
pa_locale_to_utf8;
pa_mainloop_api_once;
pa_mainloop_dispatch;
pa_mainloop_free;
pa_mainloop_get_api;
pa_mainloop_get_retval;
pa_mainloop_iterate;
pa_mainloop_new;
pa_mainloop_poll;
pa_mainloop_prepare;
pa_mainloop_quit;
pa_mainloop_run;
pa_mainloop_set_poll_func;
pa_mainloop_wakeup;
pa_msleep;
pa_thread_make_realtime;
pa_operation_cancel;
pa_operation_get_state;
pa_operation_ref;
pa_operation_set_state_callback;
pa_operation_unref;
pa_parse_sample_format;
pa_path_get_filename;
pa_proplist_clear;
pa_proplist_contains;
pa_proplist_copy;
pa_proplist_equal;
pa_proplist_free;
pa_proplist_from_string;
pa_proplist_get;
pa_proplist_gets;
pa_proplist_isempty;
pa_proplist_iterate;
pa_proplist_key_valid;
pa_proplist_new;
pa_proplist_set;
pa_proplist_setf;
pa_proplist_setp;
pa_proplist_sets;
pa_proplist_size;
pa_proplist_to_string;
pa_proplist_to_string_sep;
pa_proplist_unset;
pa_proplist_unset_many;
pa_proplist_update;
pa_rtclock_now;
pa_sample_format_is_be;
pa_sample_format_is_le;
pa_sample_format_to_string;
pa_sample_format_valid;
pa_sample_rate_valid;
pa_sample_size;
pa_sample_size_of_format;
pa_sample_spec_equal;
pa_sample_spec_init;
pa_sample_spec_snprint;
pa_sample_spec_valid;
pa_signal_done;
pa_signal_free;
pa_signal_init;
pa_signal_new;
pa_signal_set_destroy;
pa_simple_drain;
pa_simple_flush;
pa_simple_free;
pa_simple_get_latency;
pa_simple_new;
pa_simple_read;
pa_simple_write;
pa_stream_begin_write;
pa_stream_cancel_write;
pa_stream_connect_playback;
pa_stream_connect_record;
pa_stream_connect_upload;
pa_stream_cork;
pa_stream_disconnect;
pa_stream_drain;
pa_stream_drop;
pa_stream_finish_upload;
pa_stream_flush;
pa_stream_get_buffer_attr;
pa_stream_get_channel_map;
pa_stream_get_context;
pa_stream_get_device_index;
pa_stream_get_device_name;
pa_stream_get_format_info;
pa_stream_get_index;
pa_stream_get_latency;
pa_stream_get_monitor_stream;
pa_stream_get_sample_spec;
pa_stream_get_state;
pa_stream_get_time;
pa_stream_get_timing_info;
pa_stream_get_underflow_index;
pa_stream_is_corked;
pa_stream_is_suspended;
pa_stream_new;
pa_stream_new_extended;
pa_stream_new_with_proplist;
pa_stream_peek;
pa_stream_prebuf;
pa_stream_proplist_remove;
pa_stream_proplist_update;
pa_stream_readable_size;
pa_stream_ref;
pa_stream_set_buffer_attr;
pa_stream_set_buffer_attr_callback;
pa_stream_set_event_callback;
pa_stream_set_latency_update_callback;
pa_stream_set_monitor_stream;
pa_stream_set_moved_callback;
pa_stream_set_name;
pa_stream_set_overflow_callback;
pa_stream_set_read_callback;
pa_stream_set_started_callback;
pa_stream_set_state_callback;
pa_stream_set_suspended_callback;
pa_stream_set_underflow_callback;
pa_stream_set_write_callback;
pa_stream_trigger;
pa_stream_unref;
pa_stream_update_sample_rate;
pa_stream_update_timing_info;
pa_stream_writable_size;
pa_stream_write;
pa_stream_write_ext_free;
pa_strerror;
pa_sw_cvolume_divide;
pa_sw_cvolume_divide_scalar;
pa_sw_cvolume_multiply;
pa_sw_cvolume_multiply_scalar;
pa_sw_cvolume_snprint_dB;
pa_sw_volume_divide;
pa_sw_volume_from_dB;
pa_sw_volume_from_linear;
pa_sw_volume_multiply;
pa_sw_volume_snprint_dB;
pa_sw_volume_to_dB;
pa_sw_volume_to_linear;
pa_threaded_mainloop_accept;
pa_threaded_mainloop_free;
pa_threaded_mainloop_get_api;
pa_threaded_mainloop_get_retval;
pa_threaded_mainloop_in_thread;
pa_threaded_mainloop_lock;
pa_threaded_mainloop_new;
pa_threaded_mainloop_once_unlocked;
pa_threaded_mainloop_set_name;
pa_threaded_mainloop_signal;
pa_threaded_mainloop_start;
pa_threaded_mainloop_stop;
pa_threaded_mainloop_unlock;
pa_threaded_mainloop_wait;
pa_timeval_add;
pa_timeval_age;
pa_timeval_cmp;
pa_timeval_diff;
pa_timeval_load;
pa_timeval_store;
pa_timeval_sub;
pa_usec_to_bytes;
pa_utf8_filter;
pa_utf8_to_locale;
pa_utf8_valid;
pa_volume_snprint;
pa_volume_snprint_verbose;
pa_xfree;
pa_xmalloc;
pa_xmalloc0;
pa_xmemdup;
pa_xrealloc;
pa_xstrdup;
pa_xstrndup;
local:
*;
};

View file

@ -1,7 +0,0 @@
all:
$(MAKE) -C ..
clean:
$(MAKE) -C .. clean
.PHONY: all clean

View file

@ -1,133 +0,0 @@
/***
This file is part of PulseAudio.
Copyright 2006 Lennart Poettering
PulseAudio is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2.1 of the License,
or (at your option) any later version.
PulseAudio is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
***/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <gconf/gconf-client.h>
#include <glib.h>
#include <pulsecore/core-util.h>
#define PA_GCONF_ROOT "/system/pulseaudio"
#define PA_GCONF_PATH_MODULES PA_GCONF_ROOT"/modules"
static void handle_module(GConfClient *client, const char *name) {
gchar p[1024];
gboolean enabled, locked;
int i;
pa_snprintf(p, sizeof(p), PA_GCONF_PATH_MODULES"/%s/locked", name);
locked = gconf_client_get_bool(client, p, FALSE);
if (locked)
return;
pa_snprintf(p, sizeof(p), PA_GCONF_PATH_MODULES"/%s/enabled", name);
enabled = gconf_client_get_bool(client, p, FALSE);
printf("%c%s%c", enabled ? '+' : '-', name, 0);
if (enabled) {
for (i = 0; i < 10; i++) {
gchar *n, *a;
pa_snprintf(p, sizeof(p), PA_GCONF_PATH_MODULES"/%s/name%i", name, i);
if (!(n = gconf_client_get_string(client, p, NULL)) || !*n)
break;
pa_snprintf(p, sizeof(p), PA_GCONF_PATH_MODULES"/%s/args%i", name, i);
a = gconf_client_get_string(client, p, NULL);
printf("%s%c%s%c", n, 0, a ? a : "", 0);
g_free(n);
g_free(a);
}
printf("%c", 0);
}
fflush(stdout);
}
static void modules_callback(
GConfClient* client,
guint cnxn_id,
GConfEntry *entry,
gpointer user_data) {
const char *n;
char buf[128];
g_assert(strncmp(entry->key, PA_GCONF_PATH_MODULES"/", sizeof(PA_GCONF_PATH_MODULES)) == 0);
n = entry->key + sizeof(PA_GCONF_PATH_MODULES);
g_strlcpy(buf, n, sizeof(buf));
buf[strcspn(buf, "/")] = 0;
handle_module(client, buf);
}
int main(int argc, char *argv[]) {
GMainLoop *g;
GConfClient *client;
GSList *modules, *m;
#if !GLIB_CHECK_VERSION(2,36,0)
g_type_init();
#endif
if (!(client = gconf_client_get_default()))
goto fail;
gconf_client_add_dir(client, PA_GCONF_ROOT, GCONF_CLIENT_PRELOAD_RECURSIVE, NULL);
gconf_client_notify_add(client, PA_GCONF_PATH_MODULES, modules_callback, NULL, NULL, NULL);
modules = gconf_client_all_dirs(client, PA_GCONF_PATH_MODULES, NULL);
for (m = modules; m; m = m->next) {
char *e = strrchr(m->data, '/');
handle_module(client, e ? e+1 : m->data);
}
g_slist_free(modules);
/* Signal the parent that we are now initialized */
printf("!");
fflush(stdout);
g = g_main_loop_new(NULL, FALSE);
g_main_loop_run(g);
g_main_loop_unref(g);
g_object_unref(G_OBJECT(client));
return 0;
fail:
return 1;
}

View file

@ -1,114 +0,0 @@
/***
This file is part of PulseAudio.
Copyright 2006 Lennart Poettering
PulseAudio is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2.1 of the License,
or (at your option) any later version.
PulseAudio is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
***/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <sys/types.h>
#include <sys/wait.h>
#include <pulsecore/core-error.h>
#include <pulsecore/core-util.h>
#include <pulsecore/start-child.h>
#include "../stdin-util.h"
PA_MODULE_AUTHOR("Lennart Poettering");
PA_MODULE_DESCRIPTION("GConf Adapter");
PA_MODULE_VERSION(PACKAGE_VERSION);
PA_MODULE_LOAD_ONCE(true);
int pa__init(pa_module*m) {
struct userdata *u;
int r;
u = pa_xnew(struct userdata, 1);
u->core = m->core;
u->module = m;
m->userdata = u;
u->module_infos = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, (pa_free_cb_t) module_info_free);
u->pid = (pid_t) -1;
u->fd = -1;
u->fd_type = 0;
u->io_event = NULL;
u->buf_fill = 0;
if ((u->fd = pa_start_child_for_read(
#if defined(__linux__) && defined(HAVE_RUNNING_FROM_BUILD_TREE)
pa_run_from_build_tree() ? PA_BUILDDIR "/gconf-helper" :
#endif
PA_GCONF_HELPER, NULL, &u->pid)) < 0)
goto fail;
u->io_event = m->core->mainloop->io_new(
m->core->mainloop,
u->fd,
PA_IO_EVENT_INPUT,
io_event_cb,
u);
do {
if ((r = handle_event(u)) < 0)
goto fail;
/* Read until the client signalled us that it is ready with
* initialization */
} while (r != 1);
return 0;
fail:
pa__done(m);
return -1;
}
void pa__done(pa_module*m) {
struct userdata *u;
pa_assert(m);
if (!(u = m->userdata))
return;
if (u->pid != (pid_t) -1) {
kill(u->pid, SIGTERM);
for (;;) {
if (waitpid(u->pid, NULL, 0) >= 0)
break;
if (errno != EINTR) {
pa_log("waitpid() failed: %s", pa_cstrerror(errno));
break;
}
}
}
if (u->io_event)
m->core->mainloop->io_free(u->io_event);
if (u->fd >= 0)
pa_close(u->fd);
if (u->module_infos)
pa_hashmap_free(u->module_infos);
pa_xfree(u);
}

View file

@ -1 +0,0 @@
../modules/Makefile

View file

@ -1,614 +0,0 @@
/***
This file is part of PulseAudio.
Copyright 2016 Arun Raghavan <mail@arunraghavan.net>
PulseAudio is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2.1 of the License,
or (at your option) any later version.
PulseAudio is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
***/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <math.h>
#include <pulse/json.h>
#include <pulse/xmalloc.h>
#include <pulsecore/core-util.h>
#include <pulsecore/hashmap.h>
#include <pulsecore/strbuf.h>
#define MAX_NESTING_DEPTH 20 /* Arbitrary number to make sure we don't have a stack overflow */
struct pa_json_object {
pa_json_type type;
union {
int int_value;
double double_value;
bool bool_value;
char *string_value;
pa_hashmap *object_values; /* name -> object */
pa_idxset *array_values; /* objects */
};
};
static const char* parse_value(const char *str, const char *end, pa_json_object **obj, unsigned int depth);
static pa_json_object* json_object_new(void) {
pa_json_object *obj;
obj = pa_xnew0(pa_json_object, 1);
return obj;
}
static bool is_whitespace(char c) {
return c == '\t' || c == '\n' || c == '\r' || c == ' ';
}
static bool is_digit(char c) {
return c >= '0' && c <= '9';
}
static bool is_end(const char c, const char *end) {
if (!end)
return c == '\0';
else {
while (*end) {
if (c == *end)
return true;
end++;
}
}
return false;
}
static const char* consume_string(const char *str, const char *expect) {
while (*expect) {
if (*str != *expect)
return NULL;
str++;
expect++;
}
return str;
}
static const char* parse_null(const char *str, pa_json_object *obj) {
str = consume_string(str, "null");
if (str)
obj->type = PA_JSON_TYPE_NULL;
return str;
}
static const char* parse_boolean(const char *str, pa_json_object *obj) {
const char *tmp;
tmp = consume_string(str, "true");
if (tmp) {
obj->type = PA_JSON_TYPE_BOOL;
obj->bool_value = true;
} else {
tmp = consume_string(str, "false");
if (str) {
obj->type = PA_JSON_TYPE_BOOL;
obj->bool_value = false;
}
}
return tmp;
}
static const char* parse_string(const char *str, pa_json_object *obj) {
pa_strbuf *buf = pa_strbuf_new();
str++; /* Consume leading '"' */
while (*str && *str != '"') {
if (*str != '\\') {
/* We only accept ASCII printable characters. */
if (*str < 0x20 || *str > 0x7E) {
pa_log("Invalid non-ASCII character: 0x%x", (unsigned int) *str);
goto error;
}
/* Normal character, juts consume */
pa_strbuf_putc(buf, *str);
} else {
/* Need to unescape */
str++;
switch (*str) {
case '"':
case '\\':
case '/':
pa_strbuf_putc(buf, *str);
break;
case 'b':
pa_strbuf_putc(buf, '\b' /* backspace */);
break;
case 'f':
pa_strbuf_putc(buf, '\f' /* form feed */);
break;
case 'n':
pa_strbuf_putc(buf, '\n' /* new line */);
break;
case 'r':
pa_strbuf_putc(buf, '\r' /* carriage return */);
break;
case 't':
pa_strbuf_putc(buf, '\t' /* horizontal tab */);
break;
case 'u':
pa_log("Unicode code points are currently unsupported");
goto error;
default:
pa_log("Unexepcted escape value: %c", *str);
goto error;
}
}
str++;
}
if (*str != '"') {
pa_log("Failed to parse remainder of string: %s", str);
goto error;
}
str++;
obj->type = PA_JSON_TYPE_STRING;
obj->string_value = pa_strbuf_to_string_free(buf);
return str;
error:
pa_strbuf_free(buf);
return NULL;
}
static const char* parse_number(const char *str, pa_json_object *obj) {
bool negative = false, has_fraction = false, has_exponent = false, valid = false;
unsigned int integer = 0;
unsigned int fraction = 0;
unsigned int fraction_digits = 0;
int exponent = 0;
if (*str == '-') {
negative = true;
str++;
}
if (*str == '0') {
valid = true;
str++;
goto fraction;
}
while (is_digit(*str)) {
valid = true;
if (integer > ((negative ? INT_MAX : UINT_MAX) / 10)) {
pa_log("Integer overflow while parsing number");
goto error;
}
integer = (integer * 10) + (*str - '0');
str++;
}
fraction:
if (!valid) {
pa_log("Missing digits while parsing number");
goto error;
}
if (*str == '.') {
has_fraction = true;
str++;
valid = false;
while (is_digit(*str)) {
valid = true;
if (fraction > (UINT_MAX / 10)) {
pa_log("Integer overflow while parsing fractional part of number");
goto error;
}
fraction = (fraction * 10) + (*str - '0');
fraction_digits++;
str++;
}
if (!valid) {
pa_log("No digit after '.' while parsing fraction");
goto error;
}
}
if (*str == 'e' || *str == 'E') {
bool exponent_negative = false;
has_exponent = true;
str++;
valid = false;
if (*str == '-') {
exponent_negative = true;
str++;
} else if (*str == '+')
str++;
while (is_digit(*str)) {
valid = true;
if (exponent > (INT_MAX / 10)) {
pa_log("Integer overflow while parsing exponent part of number");
goto error;
}
exponent = (exponent * 10) + (*str - '0');
str++;
}
if (!valid) {
pa_log("No digit in exponent while parsing fraction");
goto error;
}
if (exponent_negative)
exponent *= -1;
}
if (has_fraction || has_exponent) {
obj->type = PA_JSON_TYPE_DOUBLE;
obj->double_value =
(negative ? -1.0 : 1.0) * (integer + (double) fraction / pow(10, fraction_digits)) * pow(10, exponent);
} else {
obj->type = PA_JSON_TYPE_INT;
obj->int_value = (negative ? -1 : 1) * integer;
}
return str;
error:
return NULL;
}
static const char *parse_object(const char *str, pa_json_object *obj, unsigned int depth) {
pa_json_object *name = NULL, *value = NULL;
obj->object_values = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func,
pa_xfree, (pa_free_cb_t) pa_json_object_free);
while (*str != '}') {
str++; /* Consume leading '{' or ',' */
str = parse_value(str, ":", &name, depth + 1);
if (!str || pa_json_object_get_type(name) != PA_JSON_TYPE_STRING) {
pa_log("Could not parse key for object");
goto error;
}
/* Consume the ':' */
str++;
str = parse_value(str, ",}", &value, depth + 1);
if (!str) {
pa_log("Could not parse value for object");
goto error;
}
pa_hashmap_put(obj->object_values, pa_xstrdup(pa_json_object_get_string(name)), value);
pa_json_object_free(name);
name = NULL;
value = NULL;
}
/* Drop trailing '}' */
str++;
/* We now know the value was correctly parsed */
obj->type = PA_JSON_TYPE_OBJECT;
return str;
error:
pa_hashmap_free(obj->object_values);
obj->object_values = NULL;
if (name)
pa_json_object_free(name);
if (value)
pa_json_object_free(value);
return NULL;
}
static const char *parse_array(const char *str, pa_json_object *obj, unsigned int depth) {
pa_json_object *value;
obj->array_values = pa_idxset_new(NULL, NULL);
while (*str != ']') {
str++; /* Consume leading '[' or ',' */
/* Need to chew up whitespaces as a special case to deal with the
* possibility of an empty array */
while (is_whitespace(*str))
str++;
if (*str == ']')
break;
str = parse_value(str, ",]", &value, depth + 1);
if (!str) {
pa_log("Could not parse value for array");
goto error;
}
pa_idxset_put(obj->array_values, value, NULL);
}
/* Drop trailing ']' */
str++;
/* We now know the value was correctly parsed */
obj->type = PA_JSON_TYPE_ARRAY;
return str;
error:
pa_idxset_free(obj->array_values, (pa_free_cb_t) pa_json_object_free);
obj->array_values = NULL;
return NULL;
}
typedef enum {
JSON_PARSER_STATE_INIT,
JSON_PARSER_STATE_FINISH,
} json_parser_state;
static const char* parse_value(const char *str, const char *end, pa_json_object **obj, unsigned int depth) {
json_parser_state state = JSON_PARSER_STATE_INIT;
pa_json_object *o;
pa_assert(str != NULL);
o = json_object_new();
if (depth > MAX_NESTING_DEPTH) {
pa_log("Exceeded maximum permitted nesting depth of objects (%u)", MAX_NESTING_DEPTH);
goto error;
}
while (!is_end(*str, end)) {
switch (state) {
case JSON_PARSER_STATE_INIT:
if (is_whitespace(*str)) {
str++;
} else if (*str == 'n') {
str = parse_null(str, o);
state = JSON_PARSER_STATE_FINISH;
} else if (*str == 't' || *str == 'f') {
str = parse_boolean(str, o);
state = JSON_PARSER_STATE_FINISH;
} else if (*str == '"') {
str = parse_string(str, o);
state = JSON_PARSER_STATE_FINISH;
} else if (is_digit(*str) || *str == '-') {
str = parse_number(str, o);
state = JSON_PARSER_STATE_FINISH;
} else if (*str == '{') {
str = parse_object(str, o, depth);
state = JSON_PARSER_STATE_FINISH;
} else if (*str == '[') {
str = parse_array(str, o, depth);
state = JSON_PARSER_STATE_FINISH;
} else {
pa_log("Invalid JSON string: %s", str);
goto error;
}
if (!str)
goto error;
break;
case JSON_PARSER_STATE_FINISH:
/* Consume trailing whitespaces */
if (is_whitespace(*str)) {
str++;
} else {
goto error;
}
}
}
if (pa_json_object_get_type(o) == PA_JSON_TYPE_INIT) {
/* We didn't actually get any data */
pa_log("No data while parsing json string: '%s' till '%s'", str, pa_strnull(end));
goto error;
}
*obj = o;
return str;
error:
pa_json_object_free(o);
return NULL;
}
pa_json_object* pa_json_parse(const char *str) {
pa_json_object *obj;
str = parse_value(str, NULL, &obj, 0);
if (!str) {
pa_log("JSON parsing failed");
return NULL;
}
if (*str != '\0') {
pa_log("Unable to parse complete JSON string, remainder is: %s", str);
pa_json_object_free(obj);
return NULL;
}
return obj;
}
pa_json_type pa_json_object_get_type(const pa_json_object *obj) {
return obj->type;
}
void pa_json_object_free(pa_json_object *obj) {
switch (pa_json_object_get_type(obj)) {
case PA_JSON_TYPE_INIT:
case PA_JSON_TYPE_INT:
case PA_JSON_TYPE_DOUBLE:
case PA_JSON_TYPE_BOOL:
case PA_JSON_TYPE_NULL:
break;
case PA_JSON_TYPE_STRING:
pa_xfree(obj->string_value);
break;
case PA_JSON_TYPE_OBJECT:
pa_hashmap_free(obj->object_values);
break;
case PA_JSON_TYPE_ARRAY:
pa_idxset_free(obj->array_values, (pa_free_cb_t) pa_json_object_free);
break;
default:
pa_assert_not_reached();
}
pa_xfree(obj);
}
int pa_json_object_get_int(const pa_json_object *o) {
pa_assert(pa_json_object_get_type(o) == PA_JSON_TYPE_INT);
return o->int_value;
}
double pa_json_object_get_double(const pa_json_object *o) {
pa_assert(pa_json_object_get_type(o) == PA_JSON_TYPE_DOUBLE);
return o->double_value;
}
bool pa_json_object_get_bool(const pa_json_object *o) {
pa_assert(pa_json_object_get_type(o) == PA_JSON_TYPE_BOOL);
return o->bool_value;
}
const char* pa_json_object_get_string(const pa_json_object *o) {
pa_assert(pa_json_object_get_type(o) == PA_JSON_TYPE_STRING);
return o->string_value;
}
const pa_json_object* pa_json_object_get_object_member(const pa_json_object *o, const char *name) {
pa_assert(pa_json_object_get_type(o) == PA_JSON_TYPE_OBJECT);
return pa_hashmap_get(o->object_values, name);
}
int pa_json_object_get_array_length(const pa_json_object *o) {
pa_assert(pa_json_object_get_type(o) == PA_JSON_TYPE_ARRAY);
return pa_idxset_size(o->array_values);
}
const pa_json_object* pa_json_object_get_array_member(const pa_json_object *o, int index) {
pa_assert(pa_json_object_get_type(o) == PA_JSON_TYPE_ARRAY);
return pa_idxset_get_by_index(o->array_values, index);
}
bool pa_json_object_equal(const pa_json_object *o1, const pa_json_object *o2) {
int i;
if (pa_json_object_get_type(o1) != pa_json_object_get_type(o2))
return false;
switch (pa_json_object_get_type(o1)) {
case PA_JSON_TYPE_NULL:
return true;
case PA_JSON_TYPE_BOOL:
return o1->bool_value == o2->bool_value;
case PA_JSON_TYPE_INT:
return o1->int_value == o2->int_value;
case PA_JSON_TYPE_DOUBLE:
return PA_DOUBLE_IS_EQUAL(o1->double_value, o2->double_value);
case PA_JSON_TYPE_STRING:
return pa_streq(o1->string_value, o2->string_value);
case PA_JSON_TYPE_ARRAY:
if (pa_json_object_get_array_length(o1) != pa_json_object_get_array_length(o2))
return false;
for (i = 0; i < pa_json_object_get_array_length(o1); i++) {
if (!pa_json_object_equal(pa_json_object_get_array_member(o1, i),
pa_json_object_get_array_member(o2, i)))
return false;
}
return true;
case PA_JSON_TYPE_OBJECT: {
void *state;
const char *key;
const pa_json_object *v1, *v2;
if (pa_hashmap_size(o1->object_values) != pa_hashmap_size(o2->object_values))
return false;
PA_HASHMAP_FOREACH_KV(key, v1, o1->object_values, state) {
v2 = pa_json_object_get_object_member(o2, key);
if (!v2 || !pa_json_object_equal(v1, v2))
return false;
}
return true;
}
default:
pa_assert_not_reached();
}
}

View file

@ -1,53 +0,0 @@
/***
This file is part of PulseAudio.
Copyright 2016 Arun Raghavan <mail@arunraghavan.net>
PulseAudio is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2.1 of the License,
or (at your option) any later version.
PulseAudio is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
***/
#include <stdbool.h>
#define PA_DOUBLE_IS_EQUAL(x, y) (((x) - (y)) < 0.000001 && ((x) - (y)) > -0.000001)
typedef enum {
PA_JSON_TYPE_INIT = 0,
PA_JSON_TYPE_NULL,
PA_JSON_TYPE_INT,
PA_JSON_TYPE_DOUBLE,
PA_JSON_TYPE_BOOL,
PA_JSON_TYPE_STRING,
PA_JSON_TYPE_ARRAY,
PA_JSON_TYPE_OBJECT,
} pa_json_type;
typedef struct pa_json_object pa_json_object;
pa_json_object* pa_json_parse(const char *str);
pa_json_type pa_json_object_get_type(const pa_json_object *obj);
void pa_json_object_free(pa_json_object *obj);
/* All pointer members that are returned are valid while the corresponding object is valid */
int pa_json_object_get_int(const pa_json_object *o);
double pa_json_object_get_double(const pa_json_object *o);
bool pa_json_object_get_bool(const pa_json_object *o);
const char* pa_json_object_get_string(const pa_json_object *o);
const pa_json_object* pa_json_object_get_object_member(const pa_json_object *o, const char *name);
int pa_json_object_get_array_length(const pa_json_object *o);
const pa_json_object* pa_json_object_get_array_member(const pa_json_object *o, int index);
bool pa_json_object_equal(const pa_json_object *o1, const pa_json_object *o2);

View file

@ -1 +0,0 @@
../modules/Makefile

View file

@ -1,53 +0,0 @@
/***
This file is part of PulseAudio.
Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
PulseAudio is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2.1 of the License,
or (at your option) any later version.
PulseAudio is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
***/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef OS_IS_WIN32
#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
#include <winsock2.h>
extern char *pa_win32_get_toplevel(HANDLE handle);
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
WSADATA data;
switch (fdwReason) {
case DLL_PROCESS_ATTACH:
if (!pa_win32_get_toplevel(hinstDLL))
return FALSE;
WSAStartup(MAKEWORD(2, 0), &data);
break;
case DLL_PROCESS_DETACH:
WSACleanup();
break;
}
return TRUE;
}
#endif /* OS_IS_WIN32 */

View file

@ -1 +0,0 @@
../modules/Makefile

View file

@ -1 +0,0 @@
../modules/Makefile