2 This file is part of PulseAudio.
4 Copyright 2008 Lennart Poettering
6 PulseAudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
11 PulseAudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
31 #include <crt_externs.h>
32 #define environ (*_NSGetEnviron())
33 #elif !HAVE_DECL_ENVIRON
34 extern char **environ;
37 #include <pulse/gccmacro.h>
38 #include <pulse/proplist.h>
39 #include <pulse/utf8.h>
40 #include <pulse/xmalloc.h>
41 #include <pulse/util.h>
43 #include <pulsecore/core-util.h>
45 #if defined(HAVE_GLIB) && defined(PA_GCC_WEAKREF)
47 static G_CONST_RETURN gchar* _g_get_application_name(void) PA_GCC_WEAKREF(g_get_application_name);
50 #if defined(HAVE_GTK) && defined(PA_GCC_WEAKREF)
51 #pragma GCC diagnostic ignored "-Wstrict-prototypes"
54 static G_CONST_RETURN gchar* _gtk_window_get_default_icon_name(void) PA_GCC_WEAKREF(gtk_window_get_default_icon_name);
55 static Display *_gdk_display PA_GCC_WEAKREF(gdk_display);
58 #include "proplist-util.h"
60 static void add_glib_properties(pa_proplist *p) {
62 #if defined(HAVE_GLIB) && defined(PA_GCC_WEAKREF)
64 if (!pa_proplist_contains(p, PA_PROP_APPLICATION_NAME))
65 if (_g_get_application_name) {
68 /* We ignore the tiny race condition here. */
70 if ((t = _g_get_application_name()))
71 pa_proplist_sets(p, PA_PROP_APPLICATION_NAME, t);
77 static void add_gtk_properties(pa_proplist *p) {
79 #if defined(HAVE_GTK) && defined(PA_GCC_WEAKREF)
81 if (!pa_proplist_contains(p, PA_PROP_APPLICATION_ICON_NAME))
82 if (_gtk_window_get_default_icon_name) {
85 /* We ignore the tiny race condition here. */
87 if ((t = _gtk_window_get_default_icon_name()))
88 pa_proplist_sets(p, PA_PROP_APPLICATION_ICON_NAME, t);
91 if (!pa_proplist_contains(p, PA_PROP_WINDOW_X11_DISPLAY))
92 if (&_gdk_display && _gdk_display) {
95 /* We ignore the tiny race condition here. */
97 if ((t = DisplayString(_gdk_display)))
98 pa_proplist_sets(p, PA_PROP_WINDOW_X11_DISPLAY, t);
104 void pa_init_proplist(pa_proplist *p) {
112 /* Some applications seem to reset environ to NULL for various
113 * reasons, hence we need to check for this explicitly. See
116 for (e = environ; *e; e++) {
118 if (pa_startswith(*e, "PULSE_PROP_")) {
123 if (pa_startswith(*e, "PULSE_PROP_OVERRIDE_")) {
131 kl = strcspn(*e+skip, "=");
133 if ((*e)[skip+kl] != '=')
136 k = pa_xstrndup(*e+skip, kl);
138 if (!pa_streq(k, "OVERRIDE"))
139 if (override || !pa_proplist_contains(p, k))
140 pa_proplist_sets(p, k, *e+skip+kl+1);
146 if ((pp = getenv("PULSE_PROP"))) {
149 if ((t = pa_proplist_from_string(pp))) {
150 pa_proplist_update(p, PA_UPDATE_MERGE, t);
155 if ((pp = getenv("PULSE_PROP_OVERRIDE"))) {
158 if ((t = pa_proplist_from_string(pp))) {
159 pa_proplist_update(p, PA_UPDATE_REPLACE, t);
164 if (!pa_proplist_contains(p, PA_PROP_APPLICATION_PROCESS_ID)) {
166 pa_snprintf(t, sizeof(t), "%lu", (unsigned long) getpid());
167 pa_proplist_sets(p, PA_PROP_APPLICATION_PROCESS_ID, t);
170 if (!pa_proplist_contains(p, PA_PROP_APPLICATION_PROCESS_USER)) {
173 if ((u = pa_get_user_name_malloc())) {
174 pa_proplist_sets(p, PA_PROP_APPLICATION_PROCESS_USER, u);
179 if (!pa_proplist_contains(p, PA_PROP_APPLICATION_PROCESS_HOST)) {
182 if ((h = pa_get_host_name_malloc())) {
183 pa_proplist_sets(p, PA_PROP_APPLICATION_PROCESS_HOST, h);
188 if (!pa_proplist_contains(p, PA_PROP_APPLICATION_PROCESS_BINARY)) {
191 if ((t = pa_get_binary_name_malloc())) {
192 char *c = pa_utf8_filter(t);
193 pa_proplist_sets(p, PA_PROP_APPLICATION_PROCESS_BINARY, c);
199 add_glib_properties(p);
200 add_gtk_properties(p);
202 if (!pa_proplist_contains(p, PA_PROP_APPLICATION_NAME)) {
205 if ((t = pa_proplist_gets(p, PA_PROP_APPLICATION_PROCESS_BINARY)))
206 pa_proplist_sets(p, PA_PROP_APPLICATION_NAME, t);
209 if (!pa_proplist_contains(p, PA_PROP_APPLICATION_LANGUAGE)) {
212 if ((l = setlocale(LC_MESSAGES, NULL)))
213 pa_proplist_sets(p, PA_PROP_APPLICATION_LANGUAGE, l);
216 if (!pa_proplist_contains(p, PA_PROP_WINDOW_X11_DISPLAY)) {
219 if ((t = getenv("DISPLAY"))) {
220 char *c = pa_utf8_filter(t);
221 pa_proplist_sets(p, PA_PROP_WINDOW_X11_DISPLAY, c);
226 if (!pa_proplist_contains(p, PA_PROP_APPLICATION_PROCESS_MACHINE_ID)) {
229 if ((m = pa_machine_id())) {
230 pa_proplist_sets(p, PA_PROP_APPLICATION_PROCESS_MACHINE_ID, m);
235 if (!pa_proplist_contains(p, PA_PROP_APPLICATION_PROCESS_SESSION_ID)) {
238 if ((s = pa_session_id())) {
239 pa_proplist_sets(p, PA_PROP_APPLICATION_PROCESS_SESSION_ID, s);
245 char *pa_proplist_get_stream_group(pa_proplist *p, const char *prefix, const char *cache) {
252 if (cache && (r = pa_proplist_gets(p, cache)))
253 return pa_xstrdup(r);
258 if ((r = pa_proplist_gets(p, PA_PROP_MEDIA_ROLE)))
259 t = pa_sprintf_malloc("%s-by-media-role:%s", prefix, r);
260 else if ((r = pa_proplist_gets(p, PA_PROP_APPLICATION_ID)))
261 t = pa_sprintf_malloc("%s-by-application-id:%s", prefix, r);
262 else if ((r = pa_proplist_gets(p, PA_PROP_APPLICATION_NAME)))
263 t = pa_sprintf_malloc("%s-by-application-name:%s", prefix, r);
264 else if ((r = pa_proplist_gets(p, PA_PROP_MEDIA_NAME)))
265 t = pa_sprintf_malloc("%s-by-media-name:%s", prefix, r);
267 t = pa_sprintf_malloc("%s-fallback:%s", prefix, r);
270 pa_proplist_sets(p, cache, t);