int pa_client_conf_load(pa_client_conf *c, const char *filename) { FILE *f = NULL; char *fn = NULL; int r = -1; /* Prepare the configuration parse table */ pa_config_item table[] = { { "daemon-binary", pa_config_parse_string, NULL }, { "extra-arguments", pa_config_parse_string, NULL }, { "default-sink", pa_config_parse_string, NULL }, { "default-source", pa_config_parse_string, NULL }, { "default-server", pa_config_parse_string, NULL }, { "autospawn", pa_config_parse_bool, NULL }, { "cookie-file", pa_config_parse_string, NULL }, { "disable-shm", pa_config_parse_bool, NULL }, { NULL, NULL, NULL }, }; table[0].data = &c->daemon_binary; table[1].data = &c->extra_arguments; table[2].data = &c->default_sink; table[3].data = &c->default_source; table[4].data = &c->default_server; table[5].data = &c->autospawn; table[6].data = &c->cookie_file; table[7].data = &c->disable_shm; f = filename ? fopen((fn = pa_xstrdup(filename)), "r") : pa_open_config_file(DEFAULT_CLIENT_CONFIG_FILE, DEFAULT_CLIENT_CONFIG_FILE_USER, ENV_CLIENT_CONFIG_FILE, &fn, "r"); if (!f && errno != EINTR) { pa_log_warn("Failed to open configuration file '%s': %s", fn, pa_cstrerror(errno)); goto finish; } r = f ? pa_config_parse(fn, f, table, NULL) : 0; if (!r) r = pa_client_conf_load_cookie(c); finish: pa_xfree(fn); if (f) fclose(f); return r; }
int pa_client_conf_load(pa_client_conf *c, const char *filename) { FILE *f = NULL; char *fn = NULL; int r = -1; /* Prepare the configuration parse table */ pa_config_item table[] = { { "daemon-binary", pa_config_parse_string, &c->daemon_binary, NULL }, { "extra-arguments", pa_config_parse_string, &c->extra_arguments, NULL }, { "default-sink", pa_config_parse_string, &c->default_sink, NULL }, { "default-source", pa_config_parse_string, &c->default_source, NULL }, { "default-server", pa_config_parse_string, &c->default_server, NULL }, { "autospawn", pa_config_parse_bool, &c->autospawn, NULL }, { "cookie-file", pa_config_parse_string, &c->cookie_file, NULL }, { "disable-shm", pa_config_parse_bool, &c->disable_shm, NULL }, { "enable-shm", pa_config_parse_not_bool, &c->disable_shm, NULL }, { "shm-size-bytes", pa_config_parse_size, &c->shm_size, NULL }, { NULL, NULL, NULL, NULL }, }; if (filename) { if (!(f = fopen(filename, "r"))) { pa_log(_("Failed to open configuration file '%s': %s"), fn, pa_cstrerror(errno)); goto finish; } fn = pa_xstrdup(fn); } else { if (!(f = pa_open_config_file(DEFAULT_CLIENT_CONFIG_FILE, DEFAULT_CLIENT_CONFIG_FILE_USER, ENV_CLIENT_CONFIG_FILE, &fn))) if (errno != ENOENT) goto finish; } r = f ? pa_config_parse(fn, f, table, NULL) : 0; if (!r) r = pa_client_conf_load_cookie(c); finish: pa_xfree(fn); if (f) fclose(f); return r; }
int build_glb_meter_list(FILE *f, pa_config_parser_state *pstate) { int r; struct ele_meter **next_meter; struct meter_register **next_reg; next_meter = &glb_meter; parse_again: r = pa_config_parse(f, pstate); /* r = 1 means a new register is found */ if (r == 1) { struct meter_register *reg; reg = malloc(sizeof(struct meter_register)); fill_parser_state_register(items, reg); *next_reg = reg; next_reg = ®->next; goto parse_again; } /* r = 2 means a new meter is found */ if (r == 2) { struct ele_meter *pmeter; pmeter = malloc(sizeof(struct ele_meter)); fill_parser_state_meter(items, pmeter); *next_meter = pmeter; next_meter = &pmeter->next; next_reg = &pmeter->registers; goto parse_again; } printf("r = %d\n", r); return r; }
int pa_daemon_conf_load(pa_daemon_conf *c, const char *filename) { int r = -1; FILE *f = NULL; struct channel_conf_info ci; pa_config_item table[] = { { "daemonize", pa_config_parse_bool, &c->daemonize, NULL }, { "fail", pa_config_parse_bool, &c->fail, NULL }, { "high-priority", pa_config_parse_bool, &c->high_priority, NULL }, { "realtime-scheduling", pa_config_parse_bool, &c->realtime_scheduling, NULL }, { "disallow-module-loading", pa_config_parse_bool, &c->disallow_module_loading, NULL }, { "allow-module-loading", pa_config_parse_not_bool, &c->disallow_module_loading, NULL }, { "disallow-exit", pa_config_parse_bool, &c->disallow_exit, NULL }, { "allow-exit", pa_config_parse_not_bool, &c->disallow_exit, NULL }, { "use-pid-file", pa_config_parse_bool, &c->use_pid_file, NULL }, { "system-instance", pa_config_parse_bool, &c->system_instance, NULL }, #ifdef HAVE_DBUS { "local-server-type", parse_server_type, c, NULL }, #endif { "no-cpu-limit", pa_config_parse_bool, &c->no_cpu_limit, NULL }, { "cpu-limit", pa_config_parse_not_bool, &c->no_cpu_limit, NULL }, { "disable-shm", pa_config_parse_bool, &c->disable_shm, NULL }, { "enable-shm", pa_config_parse_not_bool, &c->disable_shm, NULL }, { "enable-memfd", pa_config_parse_not_bool, &c->disable_memfd, NULL }, { "flat-volumes", pa_config_parse_bool, &c->flat_volumes, NULL }, { "lock-memory", pa_config_parse_bool, &c->lock_memory, NULL }, { "enable-deferred-volume", pa_config_parse_bool, &c->deferred_volume, NULL }, { "exit-idle-time", pa_config_parse_int, &c->exit_idle_time, NULL }, { "scache-idle-time", pa_config_parse_int, &c->scache_idle_time, NULL }, { "realtime-priority", parse_rtprio, c, NULL }, { "dl-search-path", pa_config_parse_string, &c->dl_search_path, NULL }, { "default-script-file", pa_config_parse_string, &c->default_script_file, NULL }, { "log-target", parse_log_target, c, NULL }, { "log-level", parse_log_level, c, NULL }, { "verbose", parse_log_level, c, NULL }, { "resample-method", parse_resample_method, c, NULL }, { "default-sample-format", parse_sample_format, c, NULL }, { "default-sample-rate", parse_sample_rate, c, NULL }, { "alternate-sample-rate", parse_alternate_sample_rate, c, NULL }, { "default-sample-channels", parse_sample_channels, &ci, NULL }, { "default-channel-map", parse_channel_map, &ci, NULL }, { "default-fragments", parse_fragments, c, NULL }, { "default-fragment-size-msec", parse_fragment_size_msec, c, NULL }, { "deferred-volume-safety-margin-usec", pa_config_parse_unsigned, &c->deferred_volume_safety_margin_usec, NULL }, { "deferred-volume-extra-delay-usec", pa_config_parse_int, &c->deferred_volume_extra_delay_usec, NULL }, { "nice-level", parse_nice_level, c, NULL }, { "avoid-resampling", pa_config_parse_bool, &c->avoid_resampling, NULL }, { "disable-remixing", pa_config_parse_bool, &c->disable_remixing, NULL }, { "enable-remixing", pa_config_parse_not_bool, &c->disable_remixing, NULL }, { "remixing-use-all-sink-channels", pa_config_parse_bool, &c->remixing_use_all_sink_channels, NULL }, { "disable-lfe-remixing", pa_config_parse_bool, &c->disable_lfe_remixing, NULL }, { "enable-lfe-remixing", pa_config_parse_not_bool, &c->disable_lfe_remixing, NULL }, { "lfe-crossover-freq", pa_config_parse_unsigned, &c->lfe_crossover_freq, NULL }, { "load-default-script-file", pa_config_parse_bool, &c->load_default_script_file, NULL }, { "shm-size-bytes", pa_config_parse_size, &c->shm_size, NULL }, { "log-meta", pa_config_parse_bool, &c->log_meta, NULL }, { "log-time", pa_config_parse_bool, &c->log_time, NULL }, { "log-backtrace", pa_config_parse_unsigned, &c->log_backtrace, NULL }, #ifdef HAVE_SYS_RESOURCE_H { "rlimit-fsize", parse_rlimit, &c->rlimit_fsize, NULL }, { "rlimit-data", parse_rlimit, &c->rlimit_data, NULL }, { "rlimit-stack", parse_rlimit, &c->rlimit_stack, NULL }, { "rlimit-core", parse_rlimit, &c->rlimit_core, NULL }, #ifdef RLIMIT_RSS { "rlimit-rss", parse_rlimit, &c->rlimit_rss, NULL }, #endif #ifdef RLIMIT_NOFILE { "rlimit-nofile", parse_rlimit, &c->rlimit_nofile, NULL }, #endif #ifdef RLIMIT_AS { "rlimit-as", parse_rlimit, &c->rlimit_as, NULL }, #endif #ifdef RLIMIT_NPROC { "rlimit-nproc", parse_rlimit, &c->rlimit_nproc, NULL }, #endif #ifdef RLIMIT_MEMLOCK { "rlimit-memlock", parse_rlimit, &c->rlimit_memlock, NULL }, #endif #ifdef RLIMIT_LOCKS { "rlimit-locks", parse_rlimit, &c->rlimit_locks, NULL }, #endif #ifdef RLIMIT_SIGPENDING { "rlimit-sigpending", parse_rlimit, &c->rlimit_sigpending, NULL }, #endif #ifdef RLIMIT_MSGQUEUE { "rlimit-msgqueue", parse_rlimit, &c->rlimit_msgqueue, NULL }, #endif #ifdef RLIMIT_NICE { "rlimit-nice", parse_rlimit, &c->rlimit_nice, NULL }, #endif #ifdef RLIMIT_RTPRIO { "rlimit-rtprio", parse_rlimit, &c->rlimit_rtprio, NULL }, #endif #ifdef RLIMIT_RTTIME { "rlimit-rttime", parse_rlimit, &c->rlimit_rttime, NULL }, #endif #endif { NULL, NULL, NULL, NULL }, }; pa_xfree(c->config_file); c->config_file = NULL; f = filename ? pa_fopen_cloexec(c->config_file = pa_xstrdup(filename), "r") : pa_open_config_file(DEFAULT_CONFIG_FILE, DEFAULT_CONFIG_FILE_USER, ENV_CONFIG_FILE, &c->config_file); if (!f && errno != ENOENT) { pa_log_warn(_("Failed to open configuration file: %s"), pa_cstrerror(errno)); goto finish; } ci.default_channel_map_set = ci.default_sample_spec_set = false; ci.conf = c; r = f ? pa_config_parse(c->config_file, f, table, NULL, true, NULL) : 0; if (r >= 0) { /* Make sure that channel map and sample spec fit together */ if (ci.default_sample_spec_set && ci.default_channel_map_set && c->default_channel_map.channels != c->default_sample_spec.channels) { pa_log_error(_("The specified default channel map has a different number of channels than the specified default number of channels.")); r = -1; goto finish; } else if (ci.default_sample_spec_set) pa_channel_map_init_extend(&c->default_channel_map, c->default_sample_spec.channels, PA_CHANNEL_MAP_DEFAULT); else if (ci.default_channel_map_set) c->default_sample_spec.channels = c->default_channel_map.channels; } finish: if (f) fclose(f); return r; }
static void update_rule(struct rule *r) { char *fn; struct stat st; static pa_config_item table[] = { { "Name", pa_config_parse_string, NULL, "Desktop Entry" }, { "Icon", pa_config_parse_string, NULL, "Desktop Entry" }, { "Type", check_type, NULL, "Desktop Entry" }, { "X-PulseAudio-Properties", parse_properties, NULL, "Desktop Entry" }, { "Categories", parse_categories, NULL, "Desktop Entry" }, { NULL, catch_all, NULL, NULL }, { NULL, NULL, NULL, NULL }, }; pa_bool_t found = FALSE; pa_assert(r); fn = pa_sprintf_malloc(DESKTOPFILEDIR PA_PATH_SEP "%s.desktop", r->process_name); if (stat(fn, &st) == 0) found = TRUE; else { #ifdef DT_DIR DIR *desktopfiles_dir; struct dirent *dir; /* Let's try a more aggressive search, but only one level */ if ((desktopfiles_dir = opendir(DESKTOPFILEDIR))) { while ((dir = readdir(desktopfiles_dir))) { if (dir->d_type != DT_DIR || strcmp(dir->d_name, ".") == 0 || strcmp(dir->d_name, "..") == 0) continue; pa_xfree(fn); fn = pa_sprintf_malloc(DESKTOPFILEDIR PA_PATH_SEP "%s" PA_PATH_SEP "%s.desktop", dir->d_name, r->process_name); if (stat(fn, &st) == 0) { found = TRUE; break; } } closedir(desktopfiles_dir); } #endif } if (!found) { r->good = FALSE; pa_xfree(fn); return; } if (r->good) { if (st.st_mtime == r->mtime) { /* Theoretically the filename could have changed, but if so having the same mtime is very unlikely so not worth tracking it in r */ pa_xfree(fn); return; } pa_log_debug("Found %s (which has been updated since we last checked).", fn); } else pa_log_debug("Found %s.", fn); r->good = TRUE; r->mtime = st.st_mtime; pa_xfree(r->application_name); pa_xfree(r->icon_name); pa_xfree(r->role); r->application_name = r->icon_name = r->role = NULL; if (r->proplist) pa_proplist_clear(r->proplist); table[0].data = &r->application_name; table[1].data = &r->icon_name; if (pa_config_parse(fn, NULL, table, r) < 0) pa_log_warn("Failed to parse .desktop file %s.", fn); pa_xfree(fn); }
static void update_rule(struct rule *r) { char *fn = NULL; struct stat st; static pa_config_item table[] = { { "Name", pa_config_parse_string, NULL, "Desktop Entry" }, { "Icon", pa_config_parse_string, NULL, "Desktop Entry" }, { "Type", check_type, NULL, "Desktop Entry" }, { "X-PulseAudio-Properties", parse_properties, NULL, "Desktop Entry" }, { "Categories", parse_categories, NULL, "Desktop Entry" }, { NULL, catch_all, NULL, NULL }, { NULL, NULL, NULL, NULL }, }; const char *state = NULL; const char *xdg_data_dirs = NULL; char *data_dir = NULL; char *desktop_file_dir = NULL; pa_assert(r); if ((xdg_data_dirs = getenv("XDG_DATA_DIRS"))) { while ((data_dir = pa_split(xdg_data_dirs, ":", &state))) { desktop_file_dir = pa_sprintf_malloc("%s" PA_PATH_SEP "applications", data_dir); pa_xfree(fn); fn = find_desktop_file_in_dir(r, desktop_file_dir, &st); pa_xfree(desktop_file_dir); pa_xfree(data_dir); if (fn) { break; } } } else { fn = find_desktop_file_in_dir(r, DESKTOPFILEDIR, &st); } if (!fn) { r->good = false; return; } if (r->good) { if (st.st_mtime == r->mtime) { /* Theoretically the filename could have changed, but if so having the same mtime is very unlikely so not worth tracking it in r */ pa_xfree(fn); return; } pa_log_debug("Found %s (which has been updated since we last checked).", fn); } else pa_log_debug("Found %s.", fn); r->good = true; r->mtime = st.st_mtime; pa_xfree(r->application_name); pa_xfree(r->icon_name); pa_xfree(r->role); r->application_name = r->icon_name = r->role = NULL; if (r->proplist) pa_proplist_clear(r->proplist); table[0].data = &r->application_name; table[1].data = &r->icon_name; if (pa_config_parse(fn, NULL, table, NULL, false, r) < 0) pa_log_warn("Failed to parse .desktop file %s.", fn); pa_xfree(fn); }