]> code.delx.au - pulseaudio/blob - src/pulsecore/proplist-util.c
set PA_PROP_WINDOW_X11_DISPLAY from :0.0 and initialize PA_PROP_APPLICATION_PROCESS_M...
[pulseaudio] / src / pulsecore / proplist-util.c
1 /***
2 This file is part of PulseAudio.
3
4 Copyright 2008 Lennart Poettering
5
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.
10
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.
15
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
19 USA.
20 ***/
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <string.h>
27 #include <locale.h>
28 #include <dlfcn.h>
29
30 #include <pulse/proplist.h>
31 #include <pulse/utf8.h>
32 #include <pulse/xmalloc.h>
33 #include <pulse/util.h>
34
35 #include <pulsecore/core-util.h>
36
37 #include "proplist-util.h"
38
39 void pa_init_proplist(pa_proplist *p) {
40 #if !HAVE_DECL_ENVIRON
41 extern char **environ;
42 #endif
43 char **e;
44
45 pa_assert(p);
46
47 if (environ) {
48
49 /* Some applications seem to reset environ to NULL for various
50 * reasons, hence we need to check for this explicitly. See
51 * rhbz #473080 */
52
53 for (e = environ; *e; e++) {
54
55 if (pa_startswith(*e, "PULSE_PROP_")) {
56 size_t kl = strcspn(*e+11, "=");
57 char *k;
58
59 if ((*e)[11+kl] != '=')
60 continue;
61
62 if (!pa_utf8_valid(*e+11+kl+1))
63 continue;
64
65 k = pa_xstrndup(*e+11, kl);
66
67 if (pa_proplist_contains(p, k)) {
68 pa_xfree(k);
69 continue;
70 }
71
72 pa_proplist_sets(p, k, *e+11+kl+1);
73 pa_xfree(k);
74 }
75 }
76 }
77
78 if (!pa_proplist_contains(p, PA_PROP_APPLICATION_PROCESS_ID)) {
79 char t[32];
80 pa_snprintf(t, sizeof(t), "%lu", (unsigned long) getpid());
81 pa_proplist_sets(p, PA_PROP_APPLICATION_PROCESS_ID, t);
82 }
83
84 if (!pa_proplist_contains(p, PA_PROP_APPLICATION_PROCESS_USER)) {
85 char t[64];
86 if (pa_get_user_name(t, sizeof(t))) {
87 char *c = pa_utf8_filter(t);
88 pa_proplist_sets(p, PA_PROP_APPLICATION_PROCESS_USER, c);
89 pa_xfree(c);
90 }
91 }
92
93 if (!pa_proplist_contains(p, PA_PROP_APPLICATION_PROCESS_HOST)) {
94 char t[64];
95 if (pa_get_host_name(t, sizeof(t))) {
96 char *c = pa_utf8_filter(t);
97 pa_proplist_sets(p, PA_PROP_APPLICATION_PROCESS_HOST, c);
98 pa_xfree(c);
99 }
100 }
101
102 if (!pa_proplist_contains(p, PA_PROP_APPLICATION_PROCESS_BINARY)) {
103 char t[PATH_MAX];
104 if (pa_get_binary_name(t, sizeof(t))) {
105 char *c = pa_utf8_filter(t);
106 pa_proplist_sets(p, PA_PROP_APPLICATION_PROCESS_BINARY, c);
107 pa_xfree(c);
108 }
109 }
110
111 #ifdef RTLD_NOLOAD
112 if (!pa_proplist_contains(p, PA_PROP_APPLICATION_NAME)) {
113 void *dl;
114
115 if ((dl = dlopen("libglib-2.0", RTLD_NOLOAD))) {
116 const char *(*_g_get_application_name)(void);
117
118 if ((*(void**) &_g_get_application_name = dlsym(dl, "g_get_application_name")))
119 pa_proplist_sets(p, PA_PROP_APPLICATION_NAME, _g_get_application_name());
120
121 dlclose(dl);
122 }
123 }
124 #endif
125
126 if (!pa_proplist_contains(p, PA_PROP_APPLICATION_NAME)) {
127 const char *t;
128
129 if ((t = pa_proplist_gets(p, PA_PROP_APPLICATION_PROCESS_BINARY)))
130 pa_proplist_sets(p, PA_PROP_APPLICATION_NAME, t);
131 }
132
133 if (!pa_proplist_contains(p, PA_PROP_APPLICATION_LANGUAGE)) {
134 const char *l;
135
136 if ((l = setlocale(LC_MESSAGES, NULL)))
137 pa_proplist_sets(p, PA_PROP_APPLICATION_LANGUAGE, l);
138 }
139
140 if (!pa_proplist_contains(p, PA_PROP_WINDOW_X11_DISPLAY)) {
141 const char *t;
142
143 if ((t = getenv("DISPLAY"))) {
144 char *c = pa_utf8_filter(t);
145 pa_proplist_sets(p, PA_PROP_WINDOW_X11_DISPLAY, c);
146 pa_xfree(c);
147 }
148 }
149
150 if (!pa_proplist_contains(p, PA_PROP_APPLICATION_PROCESS_MACHINE_ID)) {
151 char *m;
152
153 if ((m = pa_machine_id())) {
154 pa_proplist_sets(p, PA_PROP_APPLICATION_PROCESS_MACHINE_ID, m);
155 pa_xfree(m);
156 }
157 }
158 }