]> code.delx.au - pulseaudio/blob - src/pulsecore/proplist-util.c
Merge commit 'coling/master'
[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
29 #include <pulse/proplist.h>
30 #include <pulse/utf8.h>
31 #include <pulse/xmalloc.h>
32 #include <pulse/util.h>
33
34 #include <pulsecore/core-util.h>
35
36 #include "proplist-util.h"
37
38 void pa_init_proplist(pa_proplist *p) {
39 int a, b;
40 #if !HAVE_DECL_ENVIRON
41 extern char **environ;
42 #endif
43 char **e;
44
45 pa_assert(p);
46
47 for (e = environ; *e; e++) {
48
49 if (pa_startswith(*e, "PULSE_PROP_")) {
50 size_t kl = strcspn(*e+11, "=");
51 char *k;
52
53 if ((*e)[11+kl] != '=')
54 continue;
55
56 if (!pa_utf8_valid(*e+11+kl+1))
57 continue;
58
59 k = pa_xstrndup(*e+11, kl);
60
61 if (pa_proplist_contains(p, k)) {
62 pa_xfree(k);
63 continue;
64 }
65
66 pa_proplist_sets(p, k, *e+11+kl+1);
67 pa_xfree(k);
68 }
69 }
70
71 if (!pa_proplist_contains(p, PA_PROP_APPLICATION_PROCESS_ID)) {
72 char t[32];
73 pa_snprintf(t, sizeof(t), "%lu", (unsigned long) getpid());
74 pa_proplist_sets(p, PA_PROP_APPLICATION_PROCESS_ID, t);
75 }
76
77 if (!pa_proplist_contains(p, PA_PROP_APPLICATION_PROCESS_USER)) {
78 char t[64];
79 if (pa_get_user_name(t, sizeof(t))) {
80 char *c = pa_utf8_filter(t);
81 pa_proplist_sets(p, PA_PROP_APPLICATION_PROCESS_USER, c);
82 pa_xfree(c);
83 }
84 }
85
86 if (!pa_proplist_contains(p, PA_PROP_APPLICATION_PROCESS_HOST)) {
87 char t[64];
88 if (pa_get_host_name(t, sizeof(t))) {
89 char *c = pa_utf8_filter(t);
90 pa_proplist_sets(p, PA_PROP_APPLICATION_PROCESS_HOST, c);
91 pa_xfree(c);
92 }
93 }
94
95 a = pa_proplist_contains(p, PA_PROP_APPLICATION_PROCESS_BINARY);
96 b = pa_proplist_contains(p, PA_PROP_APPLICATION_NAME);
97
98 if (!a || !b) {
99 char t[PATH_MAX];
100 if (pa_get_binary_name(t, sizeof(t))) {
101 char *c = pa_utf8_filter(t);
102
103 if (!a)
104 pa_proplist_sets(p, PA_PROP_APPLICATION_PROCESS_BINARY, c);
105 if (!b)
106 pa_proplist_sets(p, PA_PROP_APPLICATION_NAME, c);
107
108 pa_xfree(c);
109 }
110 }
111
112 if (!pa_proplist_contains(p, PA_PROP_APPLICATION_LANGUAGE)) {
113 const char *l;
114
115 if ((l = setlocale(LC_MESSAGES, NULL)))
116 pa_proplist_sets(p, PA_PROP_APPLICATION_LANGUAGE, l);
117 }
118 }