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
30 #include <pulse/proplist.h>
31 #include <pulse/utf8.h>
32 #include <pulse/xmalloc.h>
33 #include <pulse/util.h>
35 #include <pulsecore/core-util.h>
37 #include "proplist-util.h"
39 void pa_init_proplist(pa_proplist
*p
) {
40 #if !HAVE_DECL_ENVIRON
41 extern char **environ
;
50 /* Some applications seem to reset environ to NULL for various
51 * reasons, hence we need to check for this explicitly. See
54 for (e
= environ
; *e
; e
++) {
56 if (pa_startswith(*e
, "PULSE_PROP_")) {
57 size_t kl
= strcspn(*e
+11, "=");
60 if ((*e
)[11+kl
] != '=')
63 if (!pa_utf8_valid(*e
+11+kl
+1))
66 k
= pa_xstrndup(*e
+11, kl
);
68 if (pa_proplist_contains(p
, k
)) {
73 pa_proplist_sets(p
, k
, *e
+11+kl
+1);
79 if ((pp
= getenv("PULSE_PROP"))) {
82 if ((t
= pa_proplist_from_string(pp
))) {
83 pa_proplist_update(p
, PA_UPDATE_MERGE
, t
);
88 if (!pa_proplist_contains(p
, PA_PROP_APPLICATION_PROCESS_ID
)) {
90 pa_snprintf(t
, sizeof(t
), "%lu", (unsigned long) getpid());
91 pa_proplist_sets(p
, PA_PROP_APPLICATION_PROCESS_ID
, t
);
94 if (!pa_proplist_contains(p
, PA_PROP_APPLICATION_PROCESS_USER
)) {
96 if (pa_get_user_name(t
, sizeof(t
))) {
97 char *c
= pa_utf8_filter(t
);
98 pa_proplist_sets(p
, PA_PROP_APPLICATION_PROCESS_USER
, c
);
103 if (!pa_proplist_contains(p
, PA_PROP_APPLICATION_PROCESS_HOST
)) {
105 if (pa_get_host_name(t
, sizeof(t
))) {
106 char *c
= pa_utf8_filter(t
);
107 pa_proplist_sets(p
, PA_PROP_APPLICATION_PROCESS_HOST
, c
);
112 if (!pa_proplist_contains(p
, PA_PROP_APPLICATION_PROCESS_BINARY
)) {
114 if (pa_get_binary_name(t
, sizeof(t
))) {
115 char *c
= pa_utf8_filter(t
);
116 pa_proplist_sets(p
, PA_PROP_APPLICATION_PROCESS_BINARY
, c
);
122 if (!pa_proplist_contains(p
, PA_PROP_APPLICATION_NAME
)) {
125 if ((dl
= dlopen("libglib-2.0", RTLD_NOLOAD
))) {
126 const char *(*_g_get_application_name
)(void);
128 if ((*(void**) &_g_get_application_name
= dlsym(dl
, "g_get_application_name")))
129 pa_proplist_sets(p
, PA_PROP_APPLICATION_NAME
, _g_get_application_name());
136 if (!pa_proplist_contains(p
, PA_PROP_APPLICATION_NAME
)) {
139 if ((t
= pa_proplist_gets(p
, PA_PROP_APPLICATION_PROCESS_BINARY
)))
140 pa_proplist_sets(p
, PA_PROP_APPLICATION_NAME
, t
);
143 if (!pa_proplist_contains(p
, PA_PROP_APPLICATION_LANGUAGE
)) {
146 if ((l
= setlocale(LC_MESSAGES
, NULL
)))
147 pa_proplist_sets(p
, PA_PROP_APPLICATION_LANGUAGE
, l
);
150 if (!pa_proplist_contains(p
, PA_PROP_WINDOW_X11_DISPLAY
)) {
153 if ((t
= getenv("DISPLAY"))) {
154 char *c
= pa_utf8_filter(t
);
155 pa_proplist_sets(p
, PA_PROP_WINDOW_X11_DISPLAY
, c
);
160 if (!pa_proplist_contains(p
, PA_PROP_APPLICATION_PROCESS_MACHINE_ID
)) {
163 if ((m
= pa_machine_id())) {
164 pa_proplist_sets(p
, PA_PROP_APPLICATION_PROCESS_MACHINE_ID
, m
);